Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
 def create_type_2(cls, root_bridge_mac, root_bridge_priority):
     return cls(
         (2,)
         + tuple(MAC(root_bridge_mac).packed)
         + tuple(int(root_bridge_priority).to_bytes(2, 'big'))
         + (0,)
     )
Ejemplo n.º 3
0
 def create_type_1(cls, system_mac, port_key):
     return cls(
         (1,)
         + tuple(MAC(system_mac).packed)
         + tuple(int(port_key).to_bytes(2, 'big'))
         + (0,)
     )
Ejemplo n.º 4
0
 def create_type_3(cls, system_mac, local_discriminator):
     return cls((3, ) + tuple(MAC(system_mac).packed) +
                tuple(int(local_discriminator).to_bytes(3, 'big')))
Ejemplo n.º 5
0
 def root_bridge_mac(self):
     if self.type == 2:
         return MAC(':'.join(str(octet) for octet in self.bytes[0:6]))
     raise AttributeError
Ejemplo n.º 6
0
 def system_mac(self):
     if self.type == 1:
         return MAC(':'.join(str(octet) for octet in self.bytes[0:6]))
     if self.type == 3:
         return MAC(':'.join(str(octet) for octet in self.bytes[0:6]))
     raise AttributeError
Ejemplo n.º 7
0
    def test_init(self):

        Genie.testbed = Testbed()
        dev1 = Device(name='PE1', os='iosxr')

        with self.assertRaises(TypeError):
            intf1 = Interface()
        with self.assertRaises(TypeError):
            intf1 = Interface(device=dev1)
        intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1')
        intf1.device = None  # forget it!

        #ats_dev1 = AtsDevice(name='PE1')
        ats_dev1 = None
        ats_intf1 = AtsInterface(device=ats_dev1,
                                 name='GigabitEthernet0/0/0/1',
                                 os='iosxr',
                                 type='ethernet')
        intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1')

        self.assertTrue(isinstance(intf1, Interface))
        self.assertTrue(isinstance(intf1, xbuInterface))
        self.assertTrue(isinstance(intf1, iosxrInterface))
        self.assertTrue(isinstance(intf1, geniePhysicalInterface))
        self.assertTrue(isinstance(intf1, xbuPhysicalInterface))
        self.assertTrue(isinstance(intf1, iosxrPhysicalInterface))
        #self.assertTrue(isinstance(intf1, EthernetInterface))
        self.assertTrue(isinstance(intf1, xbuEthernetInterface))
        self.assertTrue(isinstance(intf1, iosxrEthernetInterface))

        intf2 = Interface(device=intf1.device, name=intf1.name + '.1')

        self.assertTrue(isinstance(intf2, Interface))
        self.assertTrue(isinstance(intf2, xbuInterface))
        self.assertTrue(isinstance(intf2, iosxrInterface))
        self.assertTrue(isinstance(intf2, genieVirtualInterface))
        self.assertTrue(isinstance(intf2, xbuVirtualInterface))
        self.assertTrue(isinstance(intf2, iosxrVirtualInterface))
        #self.assertTrue(isinstance(intf2, genieSubInterface))
        self.assertTrue(isinstance(intf2, xbuSubInterface))
        self.assertTrue(isinstance(intf2, iosxrSubInterface))

        self.assertEqual(intf1.ipv4, None)
        self.assertEqual(intf1.ipv6, None)
        self.assertEqual(intf1.mac_address, None)
        self.assertEqual(intf1.burnin_mac_address, None)
        self.assertEqual(intf1.effective_mac_address, None)

        intf1.ipv4 = '1.2.3.4/24'
        self.assertEqual(intf1.ipv4, IPv4Interface('1.2.3.4/24'))
        self.assertTrue(isinstance(intf1.ipv4, IPv4Interface))

        intf1.ipv4 = None
        self.assertIs(intf1.ipv4, None)

        with self.assertRaises(ValueError):
            intf1.ipv4 = 'abc'
        if False:
            # TODO -- Setting without a prefix uses 32 bits!
            with self.assertRaises(ValueError):
                intf1.ipv4 = '1.2.3.4'
        else:
            intf1.ipv4 = '1.2.3.4'
            self.assertEqual(intf1.ipv4, IPv4Interface('1.2.3.4/32'))

        intf1.ipv6 = '1234::1/80'
        self.assertEqual(intf1.ipv6, IPv6Interface('1234::1/80'))
        self.assertTrue(isinstance(intf1.ipv6, IPv6Interface))

        intf1.burnin_mac_address = 'a.b.c'
        self.assertTrue(isinstance(intf1.burnin_mac_address, MAC))
        self.assertEqual(intf1.mac_address, None)
        self.assertEqual(intf1.burnin_mac_address, MAC('a.b.c'))
        self.assertEqual(intf1.effective_mac_address, intf1.burnin_mac_address)
        del intf1.burnin_mac_address

        intf1.mac_address = 'a.b.c2'
        self.assertTrue(isinstance(intf1.mac_address, MAC))
        self.assertEqual(intf1.mac_address, MAC('a.b.c2'))
        self.assertEqual(intf1.burnin_mac_address, None)
        self.assertEqual(intf1.effective_mac_address, intf1.mac_address)
        del intf1.mac_address

        intf1.mac_address = 'a.b.c3'
        intf1.burnin_mac_address = 'a.b.c4'
        self.assertEqual(intf1.mac_address, MAC('a.b.c3'))
        self.assertEqual(intf1.burnin_mac_address, MAC('a.b.c4'))
        self.assertEqual(intf1.effective_mac_address, intf1.mac_address)
        del intf1.mac_address
        del intf1.burnin_mac_address
Ejemplo n.º 8
0
        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
Ejemplo n.º 9
0
    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, ()))
Ejemplo n.º 10
0
        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
Ejemplo n.º 11
0
    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)