Пример #1
0
    def __init__ (self,
                  name = None,
                  packet = None,
                  mode = STLTXCont(pps = 1),
                  enabled = True,
                  self_start = True,
                  isg = 0.0,
                  rx_stats = None,
                  next = None,
                  stream_id = None,
                  action_count = 0,
                  random_seed =0,
                  mac_src_override_by_pkt=None,
                  mac_dst_override_mode=None    #see  STLStreamDstMAC_xx
                  ):

        # type checking
        validate_type('mode', mode, STLTXMode)
        validate_type('packet', packet, (NoneType, CTrexPktBuilderInterface))
        validate_type('enabled', enabled, bool)
        validate_type('self_start', self_start, bool)
        validate_type('isg', isg, (int, float))
        validate_type('stream_id', stream_id, (NoneType, int))
        validate_type('random_seed',random_seed,int);

        if (type(mode) == STLTXCont) and (next != None):
            raise STLError("continuous stream cannot have a next stream ID")

        # tag for the stream and next - can be anything
        self.name = name
        self.next = next

        self.id = stream_id


        self.fields = {}

        int_mac_src_override_by_pkt = 0;
        int_mac_dst_override_mode   = 0;


        if mac_src_override_by_pkt == None:
            int_mac_src_override_by_pkt=0
            if packet :
                if packet.is_def_src_mac ()==False:
                    int_mac_src_override_by_pkt=1

        else:
            int_mac_src_override_by_pkt = int(mac_src_override_by_pkt);

        if mac_dst_override_mode == None:
            int_mac_dst_override_mode   = 0;
            if packet :
                if packet.is_def_dst_mac ()==False:
                    int_mac_dst_override_mode=STLStreamDstMAC_PKT
        else:
            int_mac_dst_override_mode = int(mac_dst_override_mode);


        self.fields['flags'] = (int_mac_src_override_by_pkt&1) +  ((int_mac_dst_override_mode&3)<<1)

        self.fields['action_count'] = action_count

        # basic fields
        self.fields['enabled'] = enabled
        self.fields['self_start'] = self_start
        self.fields['isg'] = isg

        if random_seed !=0 :
            self.fields['random_seed'] = random_seed # optional

        # mode
        self.fields['mode'] = mode.to_json()
        self.mode_desc      = str(mode)


        # packet
        self.fields['packet'] = {}
        self.fields['vm'] = {}

        if not packet:
            packet = CScapyTRexPktBuilder(pkt = Ether()/IP())

        # packet builder
        packet.compile()

        # packet and VM
        self.fields['packet'] = packet.dump_pkt()
        self.fields['vm']     = packet.get_vm_data()

        self.pkt = base64.b64decode(self.fields['packet']['binary'])

        # this is heavy, calculate lazy
        self.packet_desc = None

        if not rx_stats:
            self.fields['rx_stats'] = STLRxStats.defaults()
        else:
            self.fields['rx_stats'] = rx_stats.to_json()
Пример #2
0
    def __init__ (self,
                  name = None,
                  packet = None,
                  mode = STLTXCont(1),
                  enabled = True,
                  self_start = True,
                  isg = 0.0,
                  rx_stats = None,
                  next = None,
                  stream_id = None):

        # type checking
        if not isinstance(mode, STLTXMode):
            raise STLArgumentError('mode', mode)

        if packet and not isinstance(packet, CTrexPktBuilderInterface):
            raise STLArgumentError('packet', packet)

        if not isinstance(enabled, bool):
            raise STLArgumentError('enabled', enabled)

        if not isinstance(self_start, bool):
            raise STLArgumentError('self_start', self_start)

        if not isinstance(isg, (int, float)):
            raise STLArgumentError('isg', isg)

        if (type(mode) == STLTXCont) and (next != None):
            raise STLError("continuous stream cannot have a next stream ID")

        # tag for the stream and next - can be anything
        self.name = name
        self.next = next

        # ID
        self.set_id(stream_id)
        self.set_next_id(None)

        self.fields = {}

        # basic fields
        self.fields['enabled'] = enabled
        self.fields['self_start'] = self_start
        self.fields['isg'] = isg

        # mode
        self.fields['mode'] = mode.to_json()
        self.mode_desc      = str(mode)

        self.fields['packet'] = {}
        self.fields['vm'] = {}

        if not packet:
            packet = CScapyTRexPktBuilder(pkt = Ether()/IP())

        # packet builder
        packet.compile()

        # packet and VM
        self.fields['packet'] = packet.dump_pkt()
        self.fields['vm']     = packet.get_vm_data()
        self.packet_desc      = packet.pkt_layers_desc()

        if not rx_stats:
            self.fields['rx_stats'] = {}
            self.fields['rx_stats']['enabled'] = False
        else:
            self.fields['rx_stats'] = rx_stats
Пример #3
0
    def __init__ (self,
                  name = None,
                  packet = None,
                  mode = STLTXCont(pps = 1),
                  enabled = True,
                  self_start = True,
                  isg = 0.0,
                  flow_stats = None,
                  next = None,
                  stream_id = None,
                  action_count = 0,
                  random_seed =0,
                  mac_src_override_by_pkt=None,
                  mac_dst_override_mode=None    #see  STLStreamDstMAC_xx
                  ):
        """ 
        Stream object 

        :parameters:

                  name  : string 
                       The name of the stream. Needed if this stream is dependent on another stream and another stream need to refer to this stream by its name.

                  packet :  STLPktBuilder 
                       The template packet and field engine program e.g. packet = STLPktBuilder(pkt = base_pkt/pad) 

                  mode : STLTXCont or STLTXSingleBurst or STLTXMultiBurst

                  enabled : bool 
                      if the stream is enabled. 

                  self_start : bool 
                      In case it is False another stream will activate it

                  isg : float 
                     Inter stream gap in usec. time to wait until stream will send the first packet  

                  flow_stats : STLFlowStats
                      Per stream statistic object see STLFlowStats

                  next : string 
                      The name of the stream to activate 
                    
                  stream_id :
                        for HLTAPI usage 

                  action_count : uint16_t
                        In case there is a next stream how many loops until stopping. Default is zero, which mean unlimited

                  random_seed: uint16_t 
                       If given the seed for this stream will be this value. Good in case you need a deterministic random value 
                        
                  mac_src_override_by_pkt : bool 
                        Template packet will set src MAC 

                  mac_dst_override_mode=None : STLStreamDstMAC_xx
                        Template packet will set dst MAC 


        :return:
          None

        :raises:
          None

        """


        # type checking
        validate_type('mode', mode, STLTXMode)
        validate_type('packet', packet, (NoneType, CTrexPktBuilderInterface))
        validate_type('enabled', enabled, bool)
        validate_type('self_start', self_start, bool)
        validate_type('isg', isg, (int, float))
        validate_type('stream_id', stream_id, (NoneType, int))
        validate_type('random_seed',random_seed,int);

        if (type(mode) == STLTXCont) and (next != None):
            raise STLError("continuous stream cannot have a next stream ID")

        # tag for the stream and next - can be anything
        self.name = name
        self.next = next

        self.mac_src_override_by_pkt = mac_src_override_by_pkt # save for easy construct code from stream object
        self.mac_dst_override_mode = mac_dst_override_mode
        self.id = stream_id


        self.fields = {}

        int_mac_src_override_by_pkt = 0;
        int_mac_dst_override_mode   = 0;


        if mac_src_override_by_pkt == None:
            int_mac_src_override_by_pkt=0
            if packet :
                if packet.is_default_src_mac ()==False:
                    int_mac_src_override_by_pkt=1

        else:
            int_mac_src_override_by_pkt = int(mac_src_override_by_pkt);

        if mac_dst_override_mode == None:
            int_mac_dst_override_mode   = 0;
            if packet :
                if packet.is_default_dst_mac ()==False:
                    int_mac_dst_override_mode=STLStreamDstMAC_PKT
        else:
            int_mac_dst_override_mode = int(mac_dst_override_mode);


        self.fields['flags'] = (int_mac_src_override_by_pkt&1) +  ((int_mac_dst_override_mode&3)<<1)

        self.fields['action_count'] = action_count

        # basic fields
        self.fields['enabled'] = enabled
        self.fields['self_start'] = self_start
        self.fields['isg'] = isg

        if random_seed !=0 :
            self.fields['random_seed'] = random_seed # optional

        # mode
        self.fields['mode'] = mode.to_json()
        self.mode_desc      = str(mode)


        # packet
        self.fields['packet'] = {}
        self.fields['vm'] = {}

        if not packet:
            packet = CScapyTRexPktBuilder(pkt = Ether()/IP())

        self.scapy_pkt_builder = packet
        # packet builder
        packet.compile()

        # packet and VM
        self.fields['packet'] = packet.dump_pkt()
        self.fields['vm']     = packet.get_vm_data()

        self.pkt = base64.b64decode(self.fields['packet']['binary'])

        # this is heavy, calculate lazy
        self.packet_desc = None

        if not flow_stats:
            self.fields['flow_stats'] = STLFlowStats.defaults()
        else:
            self.fields['flow_stats'] = flow_stats.to_json()
Пример #4
0
    def __init__(self,
                 name=None,
                 packet=None,
                 mode=STLTXCont(1),
                 enabled=True,
                 self_start=True,
                 isg=0.0,
                 rx_stats=None,
                 next=None,
                 stream_id=None):

        # type checking
        if not isinstance(mode, STLTXMode):
            raise STLArgumentError('mode', mode)

        if packet and not isinstance(packet, CTrexPktBuilderInterface):
            raise STLArgumentError('packet', packet)

        if not isinstance(enabled, bool):
            raise STLArgumentError('enabled', enabled)

        if not isinstance(self_start, bool):
            raise STLArgumentError('self_start', self_start)

        if not isinstance(isg, (int, float)):
            raise STLArgumentError('isg', isg)

        if (type(mode) == STLTXCont) and (next != None):
            raise STLError("continuous stream cannot have a next stream ID")

        # tag for the stream and next - can be anything
        self.name = name
        self.next = next

        # ID
        self.set_id(stream_id)
        self.set_next_id(None)

        self.fields = {}

        # basic fields
        self.fields['enabled'] = enabled
        self.fields['self_start'] = self_start
        self.fields['isg'] = isg

        # mode
        self.fields['mode'] = mode.to_json()
        self.mode_desc = str(mode)

        self.fields['packet'] = {}
        self.fields['vm'] = {}

        if not packet:
            packet = CScapyTRexPktBuilder(pkt=Ether() / IP())

        # packet builder
        packet.compile()

        # packet and VM
        self.fields['packet'] = packet.dump_pkt()
        self.fields['vm'] = packet.get_vm_data()
        self.packet_desc = packet.pkt_layers_desc()

        if not rx_stats:
            self.fields['rx_stats'] = {}
            self.fields['rx_stats']['enabled'] = False
        else:
            self.fields['rx_stats'] = rx_stats