def test_ipv4_multiple_lines_confg(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='nxos') intf1 = Interface(name='Ethernet3/7', device=dev1, \ aliases=['PE1_1']) vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Apply configuration intf1.description = 'multiple lines config' ipv4a = IPv4Addr(device=dev1) ipv4a.ipv4 = IPv4Address('192.168.1.1') ipv4a.prefix_length = '24' intf1.add_ipv4addr(ipv4a) ipv4b = IPv4Addr(device=dev1) ipv4b.ipv4 = IPv4Address('192.168.1.2') ipv4b.prefix_length = '24' ipv4b.ipv4_secondary = True intf1.add_ipv4addr(ipv4b) intf1.shutdown = False # make intf2 as L3 interface intf1.switchport_enable = False # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet3/7', ' description multiple lines config', ' no shutdown', ' no switchport', ' ip address 192.168.1.1/24', ' ip address 192.168.1.2/24 secondary', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={'switchport_enable': True, 'description': True, 'shutdown': True}) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface Ethernet3/7', ' no description', ' shutdown', ' switchport', ' exit' ]))
def configure_subinterfaces_for_vlan_range(device, interface, vlan_id_start, vlan_id_step, vlan_id_count, network_start, network_step, host_address_step, netmask, ospf_network_type=None): """ Configures multiple subinterfaces looping through vlan range Args: device ('obj'): Device to use interface ('str'): Physical interface to configure vlan_id_start ('int'): Start of vlan range vlan_id_step ('int'): Size of vlan range step vlan_id_count ('int'): How many steps for vlan range netmask ('str'): Netmask to configure network_start ('str'): Start of network network_step ('str'): Size of network step ospf_network_type ('str'): Ospf network type to configure Raises: SubCommandFailure Returns: list of configured interfaces """ cmds = [] vlan_id = vlan_id_start network = IPv4Address(network_start) interfaces = [] for i in range(vlan_id_count): interfaces.append('{interface}.{vlan_id}'.format(interface=interface, vlan_id=vlan_id)) ip_address = network + int(IPv4Address(host_address_step)) cmds.extend([ 'interface {interface}.{vlan_id}'.format(interface=interface, vlan_id=vlan_id), 'encapsulation dot1q {vlan_id}'.format(vlan_id=vlan_id), 'ip address {ip_address} {netmask}'.format(ip_address=ip_address, netmask=netmask) ]) if ospf_network_type: cmds.append('ip ospf network {ospf_network_type}'.format( ospf_network_type=ospf_network_type)) cmds.append('exit') vlan_id += vlan_id_step network += int(IPv4Address(network_step)) device.configure(cmds) return interfaces
def test_init(self): rte_min = BgpIpv4UnicastRoute('0.0.0.0/0') rte_max = BgpIpv4UnicastRoute('255.255.255.255/32') rte = BgpIpv4UnicastRoute('1.2.3.4') self.assertIs(rte.af, AddressFamily.ipv4_unicast) self.assertEqual(rte.type, rte.Type.ip) self.assertEqual(rte.ip, IPv4Address('1.2.3.4')) self.assertEqual(rte.ip_network, IPv4Network('1.2.3.4/32')) self.assertEqual(rte.prefix_length, 32) self.assertEqual(str(rte), '1.2.3.4/32') rte2 = BgpIpv4UnicastRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpIpv4UnicastRoute('1.2.3.0/24') self.assertIs(rte.af, AddressFamily.ipv4_unicast) self.assertEqual(rte.type, rte.Type.ip) self.assertEqual(rte.ip, IPv4Address('1.2.3.0')) self.assertEqual(rte.prefix_length, 24) self.assertEqual(rte.ip_network, IPv4Network('1.2.3.0/24')) self.assertEqual(str(rte), '1.2.3.0/24') rte2 = BgpIpv4UnicastRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2)
def config_interface_subinterface_and_secondary_addresses( device, interface, sub_interface_num, ip_address, prefix, encap_type, start, end, ): """ Configure sub-interface and secondary addresses on device Args: device (`obj`): Device object interface (`str`): Interface name sub_interface_num (`int`): Subinterface to be added to interface name ip_address(`str`): IP addressed to be configured on interface prefix(`str`): prefix to be used in configuration encap_type (`str`): Encapsulation type start (`int`): start number on ip end (`int`): end number on ip Returns: None Raises: SubCommandFailure """ # interface {interface}.999 # encapsulation dot1Q 999 # ip address 10.4.0.1 255.255.255.0 # ip address 1.1.x.1 255.255.255.0 secondary (x -> 1 to 15) name = interface + "." + str(sub_interface_num) sub_intf = Interface(device=device, name=name) sub_intf.eth_encap_type1 = encap_type sub_intf.eth_encap_val1 = sub_interface_num ipv4a = IPv4Addr(device=device) ipv4a.ipv4 = IPv4Address(ip_address.format(x=start)) ipv4a.prefix_length = prefix sub_intf.add_ipv4addr(ipv4a) for x in range(end - start): ipv4b = IPv4Addr(device=device) ipv4b.ipv4 = IPv4Address(ip_address.format(x=x + 1)) ipv4b.prefix_length = prefix ipv4b.ipv4_secondary = True sub_intf.add_ipv4addr(ipv4b) try: config = str(sub_intf.build_config(apply=False)) sub_intf.build_config() except Exception as e: log.error(str(e)) raise Exception("Failed to config \n {}".format(config)) return config
def test_create(self): esi = ESI.create_type_0('1:2:3:4:5:6:7:8:9') self.assertEqual(esi, ESI((0, 1, 2, 3, 4, 5, 6, 7, 8, 9))) self.assertEqual(esi.value, 0x010203040506070809) esi = ESI.create_type_1('1:2:3:4:5:6', 0x0708) self.assertEqual(esi, ESI((1, 1, 2, 3, 4, 5, 6, 7, 8, 0))) self.assertEqual(esi.system_mac, MAC('1:2:3:4:5:6')) self.assertEqual(esi.port_key, 0x0708) esi = ESI.create_type_2('1:2:3:4:5:6', 0x0708) self.assertEqual(esi, ESI((2, 1, 2, 3, 4, 5, 6, 7, 8, 0))) self.assertEqual(esi.root_bridge_mac, MAC('1:2:3:4:5:6')) self.assertEqual(esi.root_bridge_priority, 0x0708) esi = ESI.create_type_3('1:2:3:4:5:6', 0x070809) self.assertEqual(esi, ESI((3, 1, 2, 3, 4, 5, 6, 7, 8, 9))) self.assertEqual(esi.system_mac, MAC('1:2:3:4:5:6')) self.assertEqual(esi.local_discriminator, 0x070809) esi = ESI.create_type_4('1.2.3.4', 0x05060708) self.assertEqual(esi, ESI((4, 1, 2, 3, 4, 5, 6, 7, 8, 0))) self.assertEqual(esi.router_id, IPv4Address('1.2.3.4')) self.assertEqual(esi.local_discriminator, 0x05060708) esi = ESI.create_type_5(0x01020304, 0x05060708) self.assertEqual(esi, ESI((5, 1, 2, 3, 4, 5, 6, 7, 8, 0))) self.assertEqual(esi.asn, 0x01020304) self.assertEqual(esi.local_discriminator, 0x05060708)
def create_type_4(cls, router_id, local_discriminator): return cls( (4,) + tuple(IPv4Address(router_id).packed) + tuple(int(local_discriminator).to_bytes(4, 'big')) + (0,) )
def configure_mcast_group(self, conf_obj, **kwargs): for x in self.__dict__['keys']: mcast_group = IPv4Address(x['mcast']) mcast_group_value = mcast_group.__dict__['_ip'] + 1 t = struct.pack("!L", mcast_group_value) new_mcast_group = socket.inet_ntoa(t) self.keys[0]['mcast'] = new_mcast_group conf_obj.nve_vni_mcast_group = new_mcast_group conf_obj.build_config()
def configure_mcast_group(self, conf_obj, **kwargs): for x in self.__dict__['keys']: # supporting python 3.6 try: mcast_group = x['mcast'] mcast_group_value = struct.unpack('>L',socket.inet_aton(mcast_group))[0]+1 except Exception as e: mcast_group = IPv4Address(x['mcast']) mcast_group_value = mcast_group.__dict__['_ip']+1 t = struct.pack("!L", mcast_group_value) new_mcast_group = socket.inet_ntoa(t) self.keys[0]['mcast'] = new_mcast_group conf_obj.nve_vni_mcast_group = new_mcast_group conf_obj.build_config()
def configure_intf_ip(self, conf_obj, ip, mask, **kwargs): ipv4 = IPv4Addr(device=kwargs['device']) ipv4.ipv4 = IPv4Address(ip) ipv4.prefix_length = mask conf_obj.add_ipv4addr(ipv4) conf_obj.build_config()
def test_all_ethernet(self): testbed = Testbed() Genie.testbed = Testbed() dev1 = Device(name='PE1', os='iosxe') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/1') vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Defining attributes section intf1.description = 'test desc' intf1.enabled = True intf1.link_up_down_trap_enable = True intf1.mtu = 500 intf1.vrf = vrf intf1.vrf_downstream = 'vrf_downstream_test' intf1.mac_address = 'aaaa.bbbb.cccc' intf1.bandwidth = 768 intf1.link_status = True intf1.load_interval = 30 intf1.encapsulation = 'dot1q' intf1.first_dot1q = '20' intf1.second_dot1q = '30' ipv4a = IPv4Addr(device=dev1) ipv4a.ipv4 = IPv4Address('192.168.1.1') ipv4a.prefix_length = '24' intf1.add_ipv4addr(ipv4a) ipv4b = IPv4Addr(device=dev1) ipv4b.ipv4 = IPv4Address('192.168.1.2') ipv4b.prefix_length = '24' ipv4b.ipv4_secondary = True intf1.add_ipv4addr(ipv4b) ipv6a = IPv6Addr(device=dev1) ipv6a.ipv6 = IPv6Address('2001:db1:1::1') ipv6a.ipv6_prefix_length = '64' intf1.add_ipv6addr(ipv6a) ipv6b = IPv6Addr(device=dev1) ipv6b.ipv6 = IPv6Address('2001:db1:2::2') ipv6b.ipv6_prefix_length = '64' intf1.add_ipv6addr(ipv6b) ipv6b.ipv6_anycast = True intf1.dhcp = True intf1.dhcp_client_id = '10' intf1.dhcp_hostname = 'dhcp-host' intf1.unnumbered_intf_ref = 'GigabitEthernet0/0/2.20' intf1.ipv6_unnumbered_intf_ref = 'GigabitEthernet0/0/3.100' intf1.ipv6_enabled = True intf1.ipv6_autoconf = True intf1.ipv6_autoconf_default = True intf1.medium = "broadcast" intf1.delay = 100 intf1.port_speed = '1000' intf1.auto_negotiate = True intf1.duplex_mode = "full" intf1.flow_control_receive = True intf1.flow_control_send = False # Check config cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' encapsulation dot1q 20 second-dot1q 30', ' vrf forwarding test downstream vrf_downstream_test', ' description test desc', ' bandwidth 768', ' mtu 500', ' no shutdown', ' snmp trap link-status', ' logging event link-status', ' load-interval 30', ' ipv6 enable', ' ipv6 address autoconfig default', ' ip unnumbered GigabitEthernet0/0/2.20', ' ipv6 unnumbered GigabitEthernet0/0/3.100', ' speed 1000', ' negotiation auto', ' duplex full', ' flowcontrol receive on', ' flowcontrol send off', ' ip address dhcp client-id 10 hostname dhcp-host', ' medium broadcast', ' delay 100', ' ip address 192.168.1.1 255.255.255.0', ' ip address 192.168.1.2 255.255.255.0 secondary', ' ipv6 address 2001:db1:1::1/64', ' ipv6 address 2001:db1:2::2/64 anycast', ' mac-address aaaa.bbbb.cccc', ' exit', ])) # Check unconfig without attribtues uncfg = intf1.build_unconfig(apply=False) self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'default interface GigabitEthernet0/0/1', 'interface GigabitEthernet0/0/1', 'shutdown', ])) # Check ipv4 unconfig uncfg = intf1.build_unconfig(apply=False, attributes="ipv4addr") self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no ip address 192.168.1.1 255.255.255.0', ' no ip address 192.168.1.2 255.255.255.0 secondary', ' exit', ])) # Check encapsulation unconfig uncfg = intf1.build_unconfig(apply=False, attributes={ "encapsulation": None, "first_dot1q": None }) self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no encapsulation dot1q', ' exit', ]))
def router_id(self): if self.type == 4: return IPv4Address('.'.join( str(octet) for octet in self.bytes[0:4])) raise AttributeError
def traffic_config(self, **kwargs): # Supports l3_length try: kwargs['l2_length'] = kwargs.pop('frame_size') except KeyError: pass try: kwargs['l2_length'] = kwargs.pop('packet_len') except KeyError: pass if 'l2_length' in kwargs or 'l2_length_min' in kwargs: l2_encap = kwargs.get('l2_encap', '') if l2_encap in ( 'ethernet_ii', 'ethernet_ii_vlan', 'ethernet_ii_unicast_mpls', 'ethernet_ii_multicast_mpls', 'ethernet_ii_vlan_unicast_mpls', 'ethernet_ii_vlan_multicast_mpls', 'ethernet_ii_pppoe', 'ethernet_ii_vlan_pppoe', 'ethernet_ii_qinq_pppoe', ): # L2 = ETH(14) [VLAN(n*4)] [MPLS(n*4)] [PPPoE(6) PPP(2)] L3 FCS(4) l2_hdr_len = 18 # ETH(14) ... FCS(4) if 'vlan' in l2_encap or 'qinq' in l2_encap: if 'vlan_id2' in kwargs or 'vlan_id_outer' in kwargs: l2_hdr_len += 8 # VLAN(2*4) else: l2_hdr_len += 4 # VLAN(4) if 'mpls' in l2_encap: l2_hdr_len += len( self.tcl.cast_list( kwargs['mpls_labels'])) * 4 # MPLS(n*4) if 'pppoe' in l2_encap: l2_hdr_len += 8 # PPPoE(6) PPP(2) elif l2_encap in ( 'ethernet_mac_in_mac', 'atm_snap', 'atm_snap_802.3snap', 'atm_snap_802.3snap_nofcs', 'atm_snap_ethernet_ii', 'atm_snap_ppp', 'atm_snap_pppoe', 'atm_llcsnap', 'atm_vc_mux', 'atm_vc_mux_802.3snap', 'atm_vc_mux_802.3snap_nofcs', 'atm_vc_mux_ethernet_ii', 'atm_vc_mux_ppp', 'atm_vc_mux_pppoe', 'atm_mpls', 'hdlc_unicast', 'hdlc_broadcast', 'hdlc_unicast_mpls', 'hdlc_multicast_mpls', 'ppp_link', 'cisco_framerelay', 'ietf_framerelay', 'eth', 'raw_l2', ): # TODO l2_hdr_len = 18 else: # TODO l2_hdr_len = 18 try: kwargs['l3_length'] = int(kwargs['l2_length']) - l2_hdr_len except KeyError: pass try: kwargs['l3_length_min'] = int( kwargs['l2_length_min']) - l2_hdr_len except KeyError: pass try: kwargs['l3_length_max'] = int( kwargs['l2_length_max']) - l2_hdr_len except KeyError: pass try: kwargs['l3_length_step'] = int(kwargs['l2_length_step']) except KeyError: pass kwargs.pop('l2_length', None) kwargs.pop('l2_length_min', None) kwargs.pop('l2_length_max', None) kwargs.pop('l2_length_step', None) # IPv4/IPv6 steps have to be in IP format try: kwargs['ip_src_step'] = str(IPv4Address(kwargs['ip_src_step'])) except KeyError: pass try: kwargs['ip_dst_step'] = str(IPv4Address(kwargs['ip_dst_step'])) except KeyError: pass try: kwargs['ipv6_src_step'] = str( IPv6Address(kwargs['ipv6_src_step'])) except KeyError: pass try: kwargs['ipv6_dst_step'] = str( IPv6Address(kwargs['ipv6_dst_step'])) except KeyError: pass # MAC steps have to be in MAC format try: kwargs['mac_src_step'] = str(MAC(kwargs['mac_src_step'])) except KeyError: pass try: kwargs['mac_dst_step'] = str(MAC(kwargs['mac_dst_step'])) except KeyError: pass try: kwargs['mac_src2_step'] = str(MAC(kwargs['mac_src2_step'])) except KeyError: pass try: kwargs['mac_dst2_step'] = str(MAC(kwargs['mac_dst2_step'])) except KeyError: pass # Pagent HLTAPI does not support l3_protocol=none, not sending it is equivalent. if kwargs.get('l3_protocol', None) == 'none': del kwargs['l3_protocol'] # Pagent HLTAPI does not support l4_protocol=none, not sending it is equivalent. if kwargs.get('l4_protocol', None) == 'none': del kwargs['l4_protocol'] # Pagent does not support -mac_discovery_gw kwargs.pop('mac_discovery_gw', None) # Pagent does not support -name kwargs.pop('name', None) # Pagent only supports -mpls_labels in this format: <label>,<cos>,<bottom>,<ttl> if 'mpls_labels' in kwargs: mpls_labels = self.tcl.cast_list(kwargs['mpls_labels'], item_cast=tclstr) for i, mpls_label in enumerate(mpls_labels): try: mpls_label = int(mpls_label) except ValueError: continue else: mpls_label = '{mpls_label},{cos},{bottom},{ttl}'.format( mpls_label=mpls_label, cos=0, bottom=int(i == len(mpls_labels) - 1), ttl=0) mpls_labels[i] = mpls_label # Pagent does not support -gateway and -ipv6_gateway kwargs.pop('gateway', None) kwargs.pop('ipv6_gateway', None) # Pagent does not support -mpls_labels_mode, support is equivalent to "fixed" if kwargs.get('mpls_labels_mode', None) == 'fixed': del kwargs['mpls_labels_mode'] # -type is Agilent-specific. Default should be "stream"; Anything else is not supported. if kwargs.get('type', None) == 'stream': del kwargs['type'] # -dut_type is Agilent-specific. kwargs.pop('dut_type', None) # Pagent does not support -dest_port_list kwargs.pop('dest_port_list', None) hltkl = self.pyats_connection.traffic_config(**kwargs) if kwargs.get('mode', None) == 'remove' \ and 'port_handle' in kwargs \ and 'stream_id' in kwargs: pagent_stream_ids_var = self.tcl.vars.byref( '::Pagent::_Tgn_Info', array_index=kwargs['port_handle']) if pagent_stream_ids_var.exists(): # Workaround a bug in Pagent where -mode remove does not # "forget" the stream IDs associated with a port pagent_stream_ids = self.tcl.cast_list( pagent_stream_ids_var.get_obj(), item_cast=tclstr) kwarg_stream_ids = set( self.tcl.cast_list(kwargs['stream_id'], item_cast=tclstr)) pagent_stream_ids = [ stream_id for stream_id in pagent_stream_ids if stream_id not in kwarg_stream_ids ] if pagent_stream_ids: pagent_stream_ids_var.set(pagent_stream_ids) else: # If left empty, commands such as traffic_control -action # poll may return failure. pagent_stream_ids_var.unset() return hltkl
def test_init(self): Genie.testbed = Testbed() dev1 = Device(name='PE1', os='iosxr') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1') intf2 = Interface(device=dev1, name='GigabitEthernet0/0/0/2') dev2 = Device(name='PE2', os='iosxr') intf3 = Interface(device=dev2, name='GigabitEthernet0/0/0/3') intf4 = Interface(device=dev2, name='GigabitEthernet0/0/0/4') tgen = Device(testbed=Genie.testbed, name='TGEN', os='spirent') intf5 = Interface(device=tgen, name='1/1', intf_mode='ethernet') intf6 = Interface(device=tgen, name='1/2', intf_mode='ethernet') Link(name='PE1-TGEN-1', interfaces=(intf1, intf5)) Link(name='PE1-PE2-1', interfaces=(intf2, intf3)) Link(name='PE2-TGEN-1', interfaces=(intf4, intf6)) with self.assertRaises(AttributeError): stream1 = Stream() stream1 = Stream(source=intf5, destination=intf6) self.assertIs(stream1.source_tgen_interface, intf5) self.assertIs(stream1.device, tgen) self.assertIs(stream1.testbed, Genie.testbed) self.assertTypedEqual(stream1.tgen_handle, None) self.assertTypedEqual(stream1.source, intf5) self.assertTypedEqual(stream1.source_instance, None) self.assertTypedEqual(stream1.source_count, 1) self.assertTypedEqual(stream1.destination, intf6) self.assertTypedEqual(stream1.destination_instance, None) self.assertTypedEqual(stream1.destination_count, 1) self.assertTypedEqual(stream1.destination_tgen_interfaces, frozenset([stream1.destination])) self.assertTypedEqual(stream1.layer2_protocol, Stream.Layer2Protocol.ethernet_ii) self.assertTypedEqual(stream1.source_mac_address, None) self.assertTypedEqual(stream1.source_mac_address_count, 0) self.assertTypedEqual(stream1.source_mac_address_step, None) self.assertTypedEqual(stream1.destination_mac_address, MAC('ffff.ffff.ffff')) self.assertTypedEqual(stream1.destination_mac_address_count, 1) self.assertTypedEqual(stream1.destination_mac_address_step, 1) self.assertTypedEqual(stream1.eth_encap_val1, None) self.assertTypedEqual(stream1.eth_encap_count1, 0) self.assertTypedEqual(stream1.eth_encap_step1, None) self.assertTypedEqual(stream1.eth_encap_range1, range(0)) self.assertTypedEqual(stream1.eth_encap_val2, None) self.assertTypedEqual(stream1.eth_encap_count2, 0) self.assertTypedEqual(stream1.eth_encap_step2, None) self.assertTypedEqual(stream1.eth_encap_range2, range(0)) self.assertTypedEqual(stream1.mpls_labels, ()) self.assertTypedEqual(stream1.ip_version, None) self.assertIs(stream1.layer3_protocol, None) self.assertTypedEqual(stream1.source_ip, None) self.assertTypedEqual(stream1.source_ip_count, 0) self.assertTypedEqual(stream1.source_ip_step, None) self.assertTypedEqual(stream1.destination_ip, None) self.assertTypedEqual(stream1.destination_ip_count, 0) self.assertTypedEqual(stream1.destination_ip_step, None) self.assertIs(stream1.layer4_protocol, None) self.assertTypedEqual(stream1.bandwidth, 10) self.assertIs(stream1.bandwidth_units, Stream.BandwidthUnits.kbps) self.assertTypedEqual(stream1.frame_length, 512) self.assertTypedEqual(stream1.frame_length_mode, Stream.FrameLengthMode.l2) self.assertTypedEqual(stream1.name, None) self.assertTypedEqual(stream1.obj_state, 'active') self.assertTypedEqual(stream1.sub_stream_increments, typedset(Stream.SubStreamIncrement, ())) intf1.mac_address = 'baad.baad.beef' intf5.mac_address = 'aaaa.bbbb.cccc' intf5.eth_encap_val1 = 1001 stream1.eth_encap_range2 = range(2000, 3000, 2) intf5.ipv4 = '1.2.3.1/24' intf6.ipv4 = '1.2.3.2/24' self.assertIs(stream1.source_tgen_interface, intf5) self.assertIs(stream1.device, tgen) self.assertIs(stream1.testbed, Genie.testbed) self.assertTypedEqual(stream1.tgen_handle, None) self.assertTypedEqual(stream1.source, intf5) self.assertTypedEqual(stream1.source_instance, None) self.assertTypedEqual(stream1.source_count, 1) self.assertTypedEqual(stream1.destination, intf6) self.assertTypedEqual(stream1.destination_instance, None) self.assertTypedEqual(stream1.destination_count, 1) self.assertTypedEqual(stream1.destination_tgen_interfaces, frozenset([stream1.destination])) self.assertTypedEqual(stream1.layer2_protocol, Stream.Layer2Protocol.ethernet_ii) self.assertTypedEqual(stream1.source_mac_address, MAC('aaaa.bbbb.cccc')) self.assertTypedEqual(stream1.source_mac_address_count, 1) self.assertTypedEqual(stream1.source_mac_address_step, 1) self.assertTypedEqual(stream1.destination_mac_address, MAC('ffff.ffff.ffff')) self.assertTypedEqual(stream1.destination_mac_address_count, 1) self.assertTypedEqual(stream1.destination_mac_address_step, 1) self.assertTypedEqual(stream1.eth_encap_val1, 1001) self.assertTypedEqual(stream1.eth_encap_count1, 1) self.assertTypedEqual(stream1.eth_encap_step1, 1) self.assertTypedEqual(stream1.eth_encap_range1, range(1001, 1002)) self.assertTypedEqual(stream1.eth_encap_val2, 2000) self.assertTypedEqual(stream1.eth_encap_count2, 500) self.assertTypedEqual(stream1.eth_encap_step2, 2) self.assertTypedEqual(stream1.eth_encap_range2, range(2000, 3000, 2)) self.assertTypedEqual(stream1.mpls_labels, ()) self.assertTypedEqual(stream1.ip_version, 4) self.assertIs(stream1.layer3_protocol, Stream.Layer3Protocol.ipv4) self.assertTypedEqual(stream1.source_ip, IPv4Address('1.2.3.1')) self.assertTypedEqual(stream1.source_ip_count, 1) self.assertTypedEqual(stream1.source_ip_step, 1) self.assertTypedEqual(stream1.destination_ip, IPv4Address('1.2.3.2')) self.assertTypedEqual(stream1.destination_ip_count, 1) self.assertTypedEqual(stream1.destination_ip_step, 1) self.assertIs(stream1.layer4_protocol, None) self.assertTypedEqual(stream1.bandwidth, 10) self.assertIs(stream1.bandwidth_units, Stream.BandwidthUnits.kbps) self.assertTypedEqual(stream1.frame_length, 512) self.assertTypedEqual(stream1.frame_length_mode, Stream.FrameLengthMode.l2) self.assertTypedEqual(stream1.name, None) self.assertTypedEqual(stream1.obj_state, 'active') self.assertTypedEqual(stream1.sub_stream_increments, typedset(Stream.SubStreamIncrement, ()))
def traffic_config(self, **kwargs): if 'name' in kwargs: assert '.' not in kwargs['name'], \ 'Ixia stream names are used as stream IDs in Tcl keyed ' \ 'lists and should not contain "." characters: {}' \ .format(kwargs['name']) # Supports frame_size or l3_length try: kwargs['frame_size'] = kwargs.pop('packet_len') except KeyError: pass try: kwargs['frame_size'] = kwargs.pop('l2_length') except KeyError: pass # IPv4/IPv6 steps have to be in IP format try: kwargs['ip_src_step'] = str(IPv4Address(kwargs['ip_src_step'])) except KeyError: pass try: kwargs['ip_dst_step'] = str(IPv4Address(kwargs['ip_dst_step'])) except KeyError: pass try: kwargs['ipv6_src_step'] = str( IPv6Address(kwargs['ipv6_src_step'])) except KeyError: pass try: kwargs['ipv6_dst_step'] = str( IPv6Address(kwargs['ipv6_dst_step'])) except KeyError: pass # Legacy API accepts MAC steps can be in either MAC or integer format and internally converts to integer. # ixnetwork_540 API accepts only MAC steps in MAC format. try: kwargs['mac_src_step'] = str(MAC(kwargs['mac_src_step'])) except KeyError: pass try: kwargs['mac_dst_step'] = str(MAC(kwargs['mac_dst_step'])) except KeyError: pass try: kwargs['mac_src2_step'] = str(MAC(kwargs['mac_src2_step'])) except KeyError: pass try: kwargs['mac_dst2_step'] = str(MAC(kwargs['mac_dst2_step'])) except KeyError: pass try: kwargs['arp_src_hw_step'] = str(MAC(kwargs['arp_src_hw_step'])) except KeyError: pass try: kwargs['arp_dst_hw_step'] = str(MAC(kwargs['arp_dst_hw_step'])) except KeyError: pass # Ixia HLTAPI does not support l3_protocol=none, not sending it is equivalent. if kwargs.get('l3_protocol', None) == 'none': del kwargs['l3_protocol'] # Ixia HLTAPI does not support l4_protocol=none, not sending it is equivalent. if kwargs.get('l4_protocol', None) == 'none': del kwargs['l4_protocol'] # Ixia HLTAPI does not support mac_discovery_gw kwargs.pop('mac_discovery_gw', None) kwargs.pop('mac_discovery_gw_count', None) kwargs.pop('mac_discovery_gw_step', None) # Enable tracking if kwargs.get('mode', None) == 'create': kwargs.setdefault('track_by', 'traffic_item') # Extra Ixia options for MPLS if 'mpls_labels' in kwargs: kwargs.setdefault('mpls_labels_mode', 'fixed') kwargs.setdefault('mpls', 'enable') # Extra Ixia vlan toggle if kwargs.get('mode', None) == 'create' and 'vlan_id' in kwargs: kwargs.setdefault('vlan', 'enable') # -type is Agilent-specific. Default should be "stream"; Anything else is not supported. if kwargs.get('type', None) == 'stream': del kwargs['type'] # -dut_type is Agilent-specific. kwargs.pop('dut_type', None) # Ixia uses -port_handle2 instead of -dest_port_list (for unidirectional streams) if 'dest_port_list' in kwargs: kwargs.setdefault('port_handle2', kwargs.pop('dest_port_list')) hltkl = self.pyats_connection.traffic_config(**kwargs) return hltkl
def test_init(self): rte_min = BgpL2vpnEvpnRoute('[1][0.0.0.0.0][0]') rte_max = BgpL2vpnEvpnRoute( '[5][65535][128][ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]') rte = BgpL2vpnEvpnRoute('[1][1.2.3.4.5][3]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.ethernet_ad) self.assertEqual(rte.esi, ESI('0.1.0.2.0.3.0.4.0.5')) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, 3) self.assertEqual(rte.mac_length, 0) self.assertEqual(rte.mac, None) self.assertEqual(rte.ip_length, 0) self.assertEqual(rte.ip, None) self.assertEqual(rte.prefix_length, 120) self.assertEqual(str(rte), '[1][0001.0002.0003.0004.0005][3]/120') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[1][100:1][1.2.3.4.5][3]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.ethernet_ad) self.assertEqual(rte.esi, ESI('0.1.0.2.0.3.0.4.0.5')) self.assertEqual(rte.rd, RouteDistinguisher('100:1')) self.assertEqual(rte.eth_tag, 3) self.assertEqual(rte.mac_length, 0) self.assertEqual(rte.mac, None) self.assertEqual(rte.ip_length, 0) self.assertEqual(rte.ip, None) self.assertEqual(rte.prefix_length, 184) self.assertEqual(str(rte), '[1][100:1][0001.0002.0003.0004.0005][3]/184') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[2][3][48][a.b.c][0]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.mac) self.assertEqual(rte.esi, None) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, 3) self.assertEqual(rte.mac_length, 48) self.assertEqual(rte.mac, MAC('a.b.c')) self.assertEqual(rte.ip_length, 0) self.assertEqual(rte.ip, None) self.assertEqual(rte.prefix_length, 104) self.assertEqual(str(rte), '[2][3][48][000a.000b.000c][0]/104') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[2][3][48][a.b.c][32][1.2.3.4]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.mac) self.assertEqual(rte.esi, None) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, 3) self.assertEqual(rte.mac_length, 48) self.assertEqual(rte.mac, MAC('a.b.c')) self.assertEqual(rte.ip_length, 32) self.assertEqual(rte.ip, IPv4Address('1.2.3.4')) self.assertEqual(rte.prefix_length, 136) self.assertEqual(str(rte), '[2][3][48][000a.000b.000c][32][1.2.3.4]/136') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[2][3][48][a.b.c][128][1::2]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.mac) self.assertEqual(rte.esi, None) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, 3) self.assertEqual(rte.mac_length, 48) self.assertEqual(rte.mac, MAC('a.b.c')) self.assertEqual(rte.ip_length, 128) self.assertEqual(rte.ip, IPv6Address('1::2')) self.assertEqual(rte.prefix_length, 232) self.assertEqual(str(rte), '[2][3][48][000a.000b.000c][128][1::2]/232') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[3][3][32][1.2.3.4]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.inclusive_multicast) self.assertEqual(rte.esi, None) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, 3) self.assertEqual(rte.mac_length, 0) self.assertEqual(rte.mac, None) self.assertEqual(rte.ip_length, 32) self.assertEqual(rte.ip, IPv4Address('1.2.3.4')) self.assertEqual(rte.prefix_length, 80) self.assertEqual(str(rte), '[3][3][32][1.2.3.4]/80') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[3][3][128][1::2]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.inclusive_multicast) self.assertEqual(rte.esi, None) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, 3) self.assertEqual(rte.mac_length, 0) self.assertEqual(rte.mac, None) self.assertEqual(rte.ip_length, 128) self.assertEqual(rte.ip, IPv6Address('1::2')) self.assertEqual(rte.prefix_length, 176) self.assertEqual(str(rte), '[3][3][128][1::2]/176') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[4][1.2.3.4.5]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.ethernet_segment) self.assertEqual(rte.esi, ESI('0.1.0.2.0.3.0.4.0.5')) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, None) self.assertEqual(rte.mac_length, 0) self.assertEqual(rte.mac, None) self.assertEqual(rte.ip_length, 0) self.assertEqual(rte.ip, None) self.assertEqual(rte.prefix_length, 88) self.assertEqual(str(rte), '[4][0001.0002.0003.0004.0005]/88') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[4][1.2.3.4.5][32][1.2.3.4]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.ethernet_segment) self.assertEqual(rte.esi, ESI('0.1.0.2.0.3.0.4.0.5')) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, None) self.assertEqual(rte.mac_length, 0) self.assertEqual(rte.mac, None) self.assertEqual(rte.ip_length, 32) self.assertEqual(rte.ip, IPv4Address('1.2.3.4')) self.assertEqual(rte.prefix_length, 120) self.assertEqual(str(rte), '[4][0001.0002.0003.0004.0005][32][1.2.3.4]/120') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[4][1.2.3.4.5][128][1::2]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.ethernet_segment) self.assertEqual(rte.esi, ESI('0.1.0.2.0.3.0.4.0.5')) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, None) self.assertEqual(rte.mac_length, 0) self.assertEqual(rte.mac, None) self.assertEqual(rte.ip_length, 128) self.assertEqual(rte.ip, IPv6Address('1::2')) self.assertEqual(rte.prefix_length, 216) self.assertEqual(str(rte), '[4][0001.0002.0003.0004.0005][128][1::2]/216') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[5][3][32][1.2.3.4]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.ip) self.assertEqual(rte.esi, None) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, 3) self.assertEqual(rte.mac_length, 0) self.assertEqual(rte.mac, None) self.assertEqual(rte.ip_length, 32) self.assertEqual(rte.ip, IPv4Address('1.2.3.4')) self.assertEqual(rte.prefix_length, 80) self.assertEqual(str(rte), '[5][3][32][1.2.3.4]/80') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[5][3][24][1.2.3.0]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.ip) self.assertEqual(rte.esi, None) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, 3) self.assertEqual(rte.mac_length, 0) self.assertEqual(rte.mac, None) self.assertEqual(rte.ip_length, 24) self.assertEqual(rte.ip, IPv4Address('1.2.3.0')) self.assertEqual(rte.prefix_length, 80) self.assertEqual(str(rte), '[5][3][24][1.2.3.0]/80') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2) rte = BgpL2vpnEvpnRoute('[5][3][128][1::2]') self.assertIs(rte.af, AddressFamily.l2vpn_evpn) self.assertEqual(rte.type, rte.Type.ip) self.assertEqual(rte.esi, None) self.assertEqual(rte.rd, None) self.assertEqual(rte.eth_tag, 3) self.assertEqual(rte.mac_length, 0) self.assertEqual(rte.mac, None) self.assertEqual(rte.ip_length, 128) self.assertEqual(rte.ip, IPv6Address('1::2')) self.assertEqual(rte.prefix_length, 176) self.assertEqual(str(rte), '[5][3][128][1::2]/176') rte2 = BgpL2vpnEvpnRoute(rte) self.assertEqual(rte, rte2) self.assertTrue(rte_min < rte < rte_max) self.assertFalse(rte != rte2)