def compare_yamls(yaml1, yaml2): validate_type('yaml1', yaml1, str) validate_type('yaml2', yaml2, str) i = 0 for line1, line2 in zip(yaml1.strip().split('\n'), yaml2.strip().split('\n')): i += 1 assert line1 == line2, 'yamls are not equal starting from line %s:\n%s\n Golden <-> Generated\n%s' % (i, line1.strip(), line2.strip())
def compare_yamls(yaml1, yaml2): validate_type('yaml1', yaml1, str) validate_type('yaml2', yaml2, str) i = 0 for line1, line2 in zip(yaml1.strip().split('\n'), yaml2.strip().split('\n')): i += 1 if line1 != line2: raise Exception('yamls are not equal starting from line %s:\n%s\n\t<->\n%s' % (i, line1.strip(), line2.strip()))
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 dummy_stream=False): """ Stream object :parameters: name : string Name of the stream. Required if this stream is dependent on another stream, and another stream needs to refer to this stream by name. packet : STLPktBuilder see :class: `trex_stl_lib.trex_stl_packet_builder_scapy.STLPktBuilder` Template packet and field engine program. Example: packet = STLPktBuilder(pkt = base_pkt/pad) mode : :class:`trex_stl_lib.trex_stl_streams.STLTXCont` or : class:`trex_stl_lib.trex_stl_streams.STLTXSingleBurst` or : class:`trex_stl_lib.trex_stl_streams.STLTXMultiBurst` enabled : bool Indicates whether the stream is enabled. self_start : bool If False, another stream activates it. isg : float Inter-stream gap in usec. Time to wait until the stream sends the first packet. flow_stats : :class:`trex_stl_lib.trex_stl_streams.STLFlowStats` Per stream statistic object. See: STLFlowStats next : string Name of the stream to activate. stream_id : For use by HLTAPI. action_count : uint16_t If there is a next stream, number of loops before stopping. Default: 0(unlimited). random_seed: uint16_t If given, the seed for this stream will be this value. Useful if you need a deterministic random value. mac_src_override_by_pkt : bool Template packet sets src MAC. mac_dst_override_mode=None : STLStreamDstMAC_xx Template packet sets dst MAC. dummy_stream : bool For delay purposes, will not be sent. """ # type checking validate_type('mode', mode, STLTXMode) validate_type('packet', packet, (type(None), CTrexPktBuilderInterface)) validate_type('flow_stats', flow_stats, (type(None), STLFlowStatsInterface)) validate_type('enabled', enabled, bool) validate_type('self_start', self_start, bool) validate_type('isg', isg, (int, float)) validate_type('stream_id', stream_id, (type(None), int)) validate_type('random_seed', random_seed, int) validate_type('dummy_stream', dummy_stream, bool) if (type(mode) == STLTXCont) and (next is not 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 # save for easy construct code from stream object self.mac_src_override_by_pkt = mac_src_override_by_pkt 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 is None: int_mac_src_override_by_pkt = 0 if packet: if packet.is_default_src_mac() is 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 is None: int_mac_dst_override_mode = 0 if packet: if packet.is_default_dst_mac() is False: int_mac_dst_override_mode = STLStreamDstMAC_PKT else: int_mac_dst_override_mode = int(mac_dst_override_mode) self.is_default_mac = not (int_mac_src_override_by_pkt or int_mac_dst_override_mode) self.fields['flags'] = (int_mac_src_override_by_pkt & 1) + \ ((int_mac_dst_override_mode & 3) << 1) + (int(dummy_stream) << 3) 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 = STLPktBuilder(pkt=Ether() / IP()) if dummy_stream: self.packet_desc = 'Dummy' 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()
def __init__(self, pps=None, bps_L1=None, bps_L2=None, percentage=None): """ Speed can be given in packets per second(pps), L2/L1 bps, or port percent Use only one unit. you can enter pps =10000 oe bps_L1=10 :parameters: pps : float Packets per second bps_L1 : float Bits per second L1(with IPG) bps_L2 : float Bits per second L2(Ethernet-FCS) percentage : float Link interface percent(0-100). Example: 10 is 10% of the port link setup .. code-block:: python # STLTXMode Example mode = STLTXCont(pps = 10) mode = STLTXCont(bps_L1 = 10000000) #10mbps L1 mode = STLTXCont(bps_L2 = 10000000) #10mbps L2 mode = STLTXCont(percentage = 10) #10% """ args = [pps, bps_L1, bps_L2, percentage] # default if all([x is None for x in args]): pps = 1.0 else: verify_exclusive_arg(args) self.fields = {'rate': {}} if pps is not None: validate_type('pps', pps, [float, int]) self.fields['rate']['type'] = 'pps' self.fields['rate']['value'] = pps elif bps_L1 is not None: validate_type('bps_L1', bps_L1, [float, int]) self.fields['rate']['type'] = 'bps_L1' self.fields['rate']['value'] = bps_L1 elif bps_L2 is not None: validate_type('bps_L2', bps_L2, [float, int]) self.fields['rate']['type'] = 'bps_L2' self.fields['rate']['value'] = bps_L2 elif percentage is not None: validate_type('percentage', percentage, [float, int]) if not (percentage > 0 and percentage <= 100): raise STLArgumentError('percentage', percentage) self.fields['rate']['type'] = 'percentage' self.fields['rate']['value'] = percentage
def add_profile(self, client_id, filename, **k): validate_type('filename', filename, str) profile = STLProfile.load(filename, **k) self.add_streams(client_id, profile.get_streams())