Ejemplo n.º 1
0
    def test_IsisPerAddrFamily(self):

        isis = Isis("core")
        self.link.add_feature(isis)

        # per address family ISIS
        isis.device_attr['PE1'].address_family_attr[
            'ipv4 unicast'].metric_style = "wide"
        isis.device_attr['PE1'].address_family_attr[
            'ipv4 unicast'].mpls_te_level = Isis.IsType.level_1
        isis.device_attr['PE1'].address_family_attr[
            'ipv4 unicast'].mpls_te_rtrid = self.intf1
        isis.device_attr['PE1'].address_family_attr[
            'ipv4 unicast'].redistribute_connected = True

        isis.device_attr['PE2'].address_family_attr[
            'ipv4 unicast'].metric_style = "narrow"
        isis.device_attr['PE2'].address_family_attr[
            'ipv4 unicast'].mpls_te_level = Isis.IsType.level_2
        isis.device_attr['PE2'].address_family_attr[
            'ipv4 unicast'].mpls_te_rtrid = self.intf2

        cfg1 = isis.build_config(apply=False)
        #print("\nPE1 config\n" + str(cfg1['PE1']))
        #print("\nPE2 config\n" + str(cfg1['PE2']))
        self.assertMultiLineEqual(
            str(cfg1['PE1']), '\n'.join([
                'router isis core',
                ' net 47.6B8D.854F.FFFF.4F2D.4CD8.00',
                ' address-family ipv4 unicast',
                '  metric-style wide',
                '  mpls traffic-eng level-1',
                '  mpls traffic-eng router-id GigabitEthernet0/0/0/1',
                '  redistribute connected',
                '  exit',
                ' interface GigabitEthernet0/0/0/1',
                '  address-family ipv4 unicast',
                '   exit',
                '  exit',
                ' exit',
            ]))
        self.assertMultiLineEqual(
            str(cfg1['PE2']), '\n'.join([
                'router isis core',
                ' net 47.6B8D.854F.FFFF.D624.1D62.00',
                ' address-family ipv4 unicast',
                '  metric-style narrow',
                '  mpls traffic-eng level-2-only',
                '  mpls traffic-eng router-id GigabitEthernet0/0/0/2',
                '  exit',
                ' interface GigabitEthernet0/0/0/2',
                '  address-family ipv4 unicast',
                '   exit',
                '  exit',
                ' exit',
            ]))
Ejemplo n.º 2
0
    def test_NET(self):

        isis = Isis("core")

        self.assertEqual(isis.system_id, None)
        self.assertEqual(isis.device_attr[self.dev1].system_id,
                         'FFFF.4F2D.4CD8')  # "PE1"
        self.assertEqual(isis.device_attr[self.dev2].system_id,
                         'FFFF.D624.1D62')  # "PE2"
        isis.system_id = '0000.0000.0001'
        self.assertEqual(isis.device_attr[self.dev1].system_id,
                         '0000.0000.0001')
        self.assertEqual(isis.device_attr[self.dev2].system_id,
                         '0000.0000.0001')
        del isis.system_id
        self.assertEqual(isis.system_id, None)
        self.assertEqual(isis.device_attr[self.dev1].system_id,
                         'FFFF.4F2D.4CD8')  # "PE1"
        self.assertEqual(isis.device_attr[self.dev2].system_id,
                         'FFFF.D624.1D62')  # "PE2"

        self.assertEqual(isis.area_address, '47.6B8D.854F')  # "core"
        self.assertEqual(isis.device_attr[self.dev1].area_address,
                         '47.6B8D.854F')  # "core"
        self.assertEqual(isis.device_attr[self.dev2].area_address,
                         '47.6B8D.854F')  # "core"
        isis.area_address = '47.0000.0000'
        self.assertEqual(isis.area_address, '47.0000.0000')
        self.assertEqual(isis.device_attr[self.dev1].area_address,
                         '47.0000.0000')
        self.assertEqual(isis.device_attr[self.dev2].area_address,
                         '47.0000.0000')
        isis.area_address = None
        self.assertEqual(isis.area_address, None)
        self.assertEqual(isis.device_attr[self.dev1].area_address,
                         '47.4F2D.4CD8')  # "PE1"
        self.assertEqual(isis.device_attr[self.dev2].area_address,
                         '47.D624.1D62')  # "PE2"
        del isis.area_address
        self.assertEqual(isis.area_address, '47.6B8D.854F')  # "core"
        self.assertEqual(isis.device_attr[self.dev1].area_address,
                         '47.6B8D.854F')  # "core"
        self.assertEqual(isis.device_attr[self.dev2].area_address,
                         '47.6B8D.854F')  # "core"

        self.assertEqual(isis.device_attr[self.dev1].net_id,
                         '47.6B8D.854F.FFFF.4F2D.4CD8.00')  # "core"."PE1".00
        self.assertEqual(isis.device_attr[self.dev2].net_id,
                         '47.6B8D.854F.FFFF.D624.1D62.00')  # "core"."PE2".00
Ejemplo n.º 3
0
    def setUp(self):
        pass

        testbed = Genie.testbed = Testbed()
        self.dev1 = Device(testbed=testbed, name='PE1', os='iosxe')
        self.dev2 = Device(testbed=testbed, name='PE2', os='iosxe')
        self.intf1 = Interface(name='GigabitEthernet0/0/1', device=self.dev1)
        self.intf2 = Interface(name='GigabitEthernet0/0/2', device=self.dev2)

        self.link = Link(name='1_2_1', testbed=testbed)
        self.link.connect_interface(interface=self.intf1)
        self.link.connect_interface(interface=self.intf2)
        self.assertSetEqual(set(self.link.find_interfaces()),
                            set([self.intf1, self.intf2]))
        self.assertSetEqual(set(self.dev1.find_interfaces()),
                            set([self.intf1]))
        self.assertSetEqual(set(self.dev2.find_interfaces()),
                            set([self.intf2]))

        isis = Isis("core")
        self.assertSetEqual(set(isis.devices), set([]))
        self.assertSetEqual(set(isis.links), set([]))

        self.link.add_feature(isis)
        for intf_iter in self.link.interfaces:
            intf_iter.add_feature(isis)
        self.assertCountEqual(isis.devices, [self.dev1, self.dev2])
        self.assertSetEqual(set(isis.links), set([self.link]))
        self.assertSetEqual(set(isis.interfaces), set([self.intf1,
                                                       self.intf2]))
Ejemplo n.º 4
0
    def test_init(self):

        isis = Isis("core")
        self.assertCountEqual(isis.devices, [])
        self.assertCountEqual(isis.interfaces, [])
        self.assertCountEqual(isis.links, [])

        self.link.add_feature(isis)
        for intf_iter in self.link.interfaces:
            intf_iter.add_feature(isis)
        self.assertCountEqual(isis._devices_with_feature(),
                              [self.dev1, self.dev2])
        self.assertCountEqual(isis._interfaces_with_feature(),
                              [self.intf1, self.intf2])
        self.assertCountEqual(isis._links_with_feature(), [self.link])
        self.assertCountEqual(isis.devices, [self.dev1, self.dev2])
        self.assertCountEqual(isis.interfaces, [self.intf1, self.intf2])
        self.assertCountEqual(isis.links, [self.link])
Ejemplo n.º 5
0
    def test_IsisPerInterface(self):

        isis = Isis("core")
        self.link.add_feature(isis)
        for intf_iter in self.link.interfaces:
            intf_iter.add_feature(isis)

        # per interface ISIS
        isis.device_attr['PE1'].interface_attr[self.intf1].passive = True
        isis.device_attr['PE1'].interface_attr[self.intf1].shutdown = True

        isis.device_attr['PE2'].interface_attr[
            self.intf2].point_to_point = True

        cfg1 = isis.build_config(apply=False)
        #print("\nPE1 config\n" + str(cfg1['PE1']))
        #print("\nPE2 config\n" + str(cfg1['PE2']))
        self.assertMultiLineEqual(
            str(cfg1['PE1']), '\n'.join([
                'router isis core',
                ' net 47.6B8D.854F.FFFF.4F2D.4CD8.00',
                ' address-family ipv4 unicast',
                '  exit',
                ' interface GigabitEthernet0/0/0/1',
                '  passive',
                '  shutdown',
                '  address-family ipv4 unicast',
                '   exit',
                '  exit',
                ' exit',
            ]))
        self.assertMultiLineEqual(
            str(cfg1['PE2']), '\n'.join([
                'router isis core',
                ' net 47.6B8D.854F.FFFF.D624.1D62.00',
                ' address-family ipv4 unicast',
                '  exit',
                ' interface GigabitEthernet0/0/0/2',
                '  point-to-point',
                '  address-family ipv4 unicast',
                '   exit',
                '  exit',
                ' exit',
            ]))
Ejemplo n.º 6
0
    def test_IsisGlobal(self):
        isis = Isis("core")
        self.link.add_feature(isis)

        # Global ISIS config
        isis.nsr = True

        # override default for both devices
        isis.is_type = Isis.IsType.level_1
        isis.device_attr['PE1'].is_type = Isis.IsType.level_1_2
        isis.device_attr['PE2'].is_type = Isis.IsType.level_2

        # use no default
        isis.device_attr['PE1'].nsf = Isis.Nsf.ietf
        isis.device_attr['PE2'].nsf = Isis.Nsf.cisco

        # override default for one device
        val = 1
        isis.device_attr['PE1'].net_id = "00.0000.0000.000{}.00".format(val)
        val += 1
        isis.device_attr['PE2'].net_id = "00.0000.0000.000{}.00".format(val)

        cfg1 = isis.build_config(apply=False)

        self.assertCountEqual(cfg1.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(cfg1['PE1']), '\n'.join([
                'router isis core',
                ' is-type level-1-2',
                ' nsf ietf',
                ' nsr',
                ' net 00.0000.0000.0001.00',
                ' exit',
                'interface GigabitEthernet0/0/1',
                ' ip router isis core',
                ' exit',
            ]))
        self.assertMultiLineEqual(
            str(cfg1['PE2']), '\n'.join([
                'router isis core',
                ' is-type level-2-only',
                ' nsf cisco',
                ' nsr',
                ' net 00.0000.0000.0002.00',
                ' exit',
                'interface GigabitEthernet0/0/2',
                ' ip router isis core',
                ' exit',
            ]))

        uncfg1 = isis.build_unconfig(apply=False)

        self.assertCountEqual(uncfg1.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(uncfg1['PE1']), '\n'.join([
                'no router isis core',
                'interface GigabitEthernet0/0/1',
                ' no ip router isis core',
                ' exit',
            ]))
        self.assertMultiLineEqual(
            str(uncfg1['PE2']), '\n'.join([
                'no router isis core',
                'interface GigabitEthernet0/0/2',
                ' no ip router isis core',
                ' exit',
            ]))

        partial_cfg1 = isis.build_config(apply=False,
                                         attributes='device_attr__PE1__nsf')
        self.assertCountEqual(partial_cfg1.keys(), ['PE1'])
        self.assertMultiLineEqual(
            str(partial_cfg1['PE1']), '\n'.join([
                'router isis core',
                ' nsf ietf',
                ' exit',
            ]))
Ejemplo n.º 7
0
    def test_IsisPerInterface(self):

        isis = Isis("core")
        self.link.add_feature(isis)
        for intf_iter in self.link.interfaces:
            intf_iter.add_feature(isis)

        val = 1
        isis.device_attr['PE1'].net_id = "00.0000.0000.000{}.00".format(val)
        val += 1
        isis.device_attr['PE2'].net_id = "00.0000.0000.000{}.00".format(val)

        # per interface ISIS
        isis.device_attr['PE1'].interface_attr[self.intf1].passive = True
        isis.device_attr['PE1'].interface_attr[self.intf1].metric = 20
        isis.device_attr['PE2'].interface_attr[
            self.intf2].point_to_point = True

        cfg1 = isis.build_config(apply=False)

        self.assertMultiLineEqual(
            str(cfg1['PE1']), '\n'.join([
                'router isis core',
                ' net 00.0000.0000.0001.00',
                ' passive-interface GigabitEthernet0/0/1',
                ' exit',
                'interface GigabitEthernet0/0/1',
                ' ip router isis core',
                ' isis metric 20',
                ' exit',
            ]))
        self.assertMultiLineEqual(
            str(cfg1['PE2']), '\n'.join([
                'router isis core',
                ' net 00.0000.0000.0002.00',
                ' exit',
                'interface GigabitEthernet0/0/2',
                ' ip router isis core',
                ' isis network point-to-point',
                ' exit',
            ]))

        isis.address_families = set(
            [AddressFamily.ipv4_unicast, AddressFamily.ipv6_unicast])

        cfg2 = isis.build_config(apply=False)

        self.assertMultiLineEqual(
            str(cfg2['PE1']), '\n'.join([
                'router isis core',
                ' net 00.0000.0000.0001.00',
                ' passive-interface GigabitEthernet0/0/1',
                ' exit',
                'interface GigabitEthernet0/0/1',
                ' ip router isis core',
                ' ipv6 router isis core',
                ' isis metric 20',
                ' exit',
            ]))
        self.assertMultiLineEqual(
            str(cfg2['PE2']), '\n'.join([
                'router isis core',
                ' net 00.0000.0000.0002.00',
                ' exit',
                'interface GigabitEthernet0/0/2',
                ' ip router isis core',
                ' ipv6 router isis core',
                ' isis network point-to-point',
                ' exit',
            ]))

        partial_cfg21 = isis.build_config(
            apply=False,
            attributes='device_attr__*__interface_attr__*__metric')
        self.assertMultiLineEqual(
            str(partial_cfg21['PE1']), '\n'.join([
                'interface GigabitEthernet0/0/1',
                ' isis metric 20',
                ' exit',
            ]))

        partial_cfg22 = isis.build_config(
            apply=False,
            attributes=
            'device_attr__*__interface_attr__*__address_family_attr__ipv6 unicast'
        )
        self.assertMultiLineEqual(
            str(partial_cfg22['PE1']), '\n'.join([
                'interface GigabitEthernet0/0/1',
                ' ipv6 router isis core',
                ' exit',
            ]))
Ejemplo n.º 8
0
    def test_IsisPerAddrFamily(self):

        isis = Isis("core")
        self.link.add_feature(isis)

        val = 1
        isis.device_attr['PE1'].net_id = "00.0000.0000.000{}.00".format(val)
        val += 1
        isis.device_attr['PE2'].net_id = "00.0000.0000.000{}.00".format(val)

        # per address family ISIS
        isis.device_attr['PE1'].address_family_attr[
            'ipv4 unicast'].metric_style = "wide"
        isis.device_attr['PE1'].address_family_attr[
            'ipv4 unicast'].mpls_te_level = Isis.IsType.level_1
        isis.device_attr['PE1'].address_family_attr[
            'ipv4 unicast'].mpls_te_rtrid = self.intf1

        isis.device_attr['PE2'].address_family_attr[
            'ipv4 unicast'].metric_style = "narrow"
        isis.device_attr['PE2'].address_family_attr[
            'ipv4 unicast'].mpls_te_level = Isis.IsType.level_2
        isis.device_attr['PE2'].address_family_attr[
            'ipv4 unicast'].mpls_te_rtrid = self.intf2

        cfg1 = isis.build_config(apply=False)

        self.assertMultiLineEqual(
            str(cfg1['PE1']), '\n'.join([
                'router isis core',
                ' net 00.0000.0000.0001.00',
                ' metric-style wide',
                ' mpls traffic-eng level-1',
                ' mpls traffic-eng router-id GigabitEthernet0/0/1',
                ' exit',
                'interface GigabitEthernet0/0/1',
                ' ip router isis core',
                ' exit',
            ]))
        self.assertMultiLineEqual(
            str(cfg1['PE2']), '\n'.join([
                'router isis core',
                ' net 00.0000.0000.0002.00',
                ' metric-style narrow',
                ' mpls traffic-eng level-2',
                ' mpls traffic-eng router-id GigabitEthernet0/0/2',
                ' exit',
                'interface GigabitEthernet0/0/2',
                ' ip router isis core',
                ' exit',
            ]))

        isis.address_families = set(
            [AddressFamily.ipv4_unicast, AddressFamily.ipv6_unicast])
        isis.device_attr['PE1'].address_family_attr[
            'ipv6 unicast'].metric_style = "wide"
        isis.device_attr['PE2'].address_family_attr[
            'ipv6 unicast'].metric_style = "narrow"

        cfg2 = isis.build_config(apply=False)

        self.assertMultiLineEqual(
            str(cfg2['PE1']), '\n'.join([
                'router isis core',
                ' net 00.0000.0000.0001.00',
                ' metric-style wide',
                ' mpls traffic-eng level-1',
                ' mpls traffic-eng router-id GigabitEthernet0/0/1',
                ' address-family ipv6 unicast',
                '  metric-style wide',
                '  exit',
                ' exit',
                'interface GigabitEthernet0/0/1',
                ' ip router isis core',
                ' ipv6 router isis core',
                ' exit',
            ]))

        self.assertMultiLineEqual(
            str(cfg2['PE2']), '\n'.join([
                'router isis core',
                ' net 00.0000.0000.0002.00',
                ' metric-style narrow',
                ' mpls traffic-eng level-2',
                ' mpls traffic-eng router-id GigabitEthernet0/0/2',
                ' address-family ipv6 unicast',
                '  metric-style narrow',
                '  exit',
                ' exit',
                'interface GigabitEthernet0/0/2',
                ' ip router isis core',
                ' ipv6 router isis core',
                ' exit',
            ]))

        uncfg2 = isis.build_unconfig(apply=False)
        self.assertMultiLineEqual(
            str(uncfg2['PE1']), '\n'.join([
                'no router isis core',
                'interface GigabitEthernet0/0/1',
                ' no ip router isis core',
                ' no ipv6 router isis core',
                ' exit',
            ]))

        self.assertMultiLineEqual(
            str(uncfg2['PE2']), '\n'.join([
                'no router isis core',
                'interface GigabitEthernet0/0/2',
                ' no ip router isis core',
                ' no ipv6 router isis core',
                ' exit',
            ]))

        partial_uncfg2 = isis.build_unconfig(
            apply=False, attributes='device_attr__*__address_family_attr__*')

        self.assertMultiLineEqual(
            str(partial_uncfg2['PE1']), '\n'.join([
                'router isis core',
                ' no metric-style wide',
                ' no mpls traffic-eng level-1',
                ' no mpls traffic-eng router-id GigabitEthernet0/0/1',
                ' no address-family ipv4 unicast',
                ' no address-family ipv6 unicast',
                ' exit',
            ]))

        self.assertMultiLineEqual(
            str(partial_uncfg2['PE2']), '\n'.join([
                'router isis core',
                ' no metric-style narrow',
                ' no mpls traffic-eng level-2',
                ' no mpls traffic-eng router-id GigabitEthernet0/0/2',
                ' no address-family ipv4 unicast',
                ' no address-family ipv6 unicast',
                ' exit',
            ]))

        partial_cfg21 = isis.build_config(
            apply=False,
            attributes=
            'device_attr__PE1__address_family_attr__ipv4 unicast__metric_style'
        )
        self.assertMultiLineEqual(
            str(partial_cfg21['PE1']), '\n'.join([
                'router isis core',
                ' metric-style wide',
                ' exit',
            ]))

        partial_uncfg21 = isis.build_unconfig(
            apply=False,
            attributes=
            'device_attr__PE1__address_family_attr__ipv4 unicast__metric_style'
        )
        self.assertMultiLineEqual(
            str(partial_uncfg21['PE1']), '\n'.join([
                'router isis core',
                ' no metric-style wide',
                ' exit',
            ]))

        partial_cfg22 = isis.build_config(
            apply=False,
            attributes=
            'device_attr__PE1__address_family_attr__ipv6 unicast__metric_style'
        )
        self.assertMultiLineEqual(
            str(partial_cfg22['PE1']), '\n'.join([
                'router isis core',
                ' address-family ipv6 unicast',
                '  metric-style wide',
                '  exit',
                ' exit',
            ]))

        partial_uncfg22 = isis.build_unconfig(
            apply=False,
            attributes=
            'device_attr__PE1__address_family_attr__ipv6 unicast__metric_style'
        )
        self.assertMultiLineEqual(
            str(partial_uncfg22['PE1']), '\n'.join([
                'router isis core',
                ' address-family ipv6 unicast',
                '  no metric-style wide',
                '  exit',
                ' exit',
            ]))
Ejemplo n.º 9
0
    def test_init(self):

        Genie.testbed = testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='iosxr')
        intf1 = Interface(device=dev1,
                          name='GigabitEthernet0/0/0/1',
                          ipv4='10.1.0.1/24')
        intf2 = Interface(device=dev1,
                          name='GigabitEthernet0/0/0/2',
                          ipv4='10.2.0.1/24')
        dev2 = Device(testbed=testbed, name='PE2', os='iosxr')
        intf3 = Interface(device=dev2,
                          name='GigabitEthernet0/0/0/3',
                          ipv4='10.1.0.2/24')
        intf4 = Interface(device=dev2,
                          name='GigabitEthernet0/0/0/4',
                          ipv4='10.2.0.2/24')
        vrf1 = Vrf(name='vrf1')
        vrf2 = Vrf(name='a')  # must be < 'default'

        with self.assertNoWarnings():

            Genie.testbed = None
            with self.assertRaises(TypeError):
                bgp = Bgp()
            with self.assertRaises(TypeError):
                bgp = Bgp(testbed=testbed)
            Genie.testbed = testbed
            with self.assertRaises(TypeError):
                bgp = Bgp()
            bgp = Bgp(asn=100)
            self.assertIs(bgp.testbed, testbed)
            Genie.testbed = testbed
            bgp = Bgp(asn=100)
            self.assertIs(bgp.testbed, Genie.testbed)
            self.assertIs(bgp.testbed, testbed)

            dev1.add_feature(bgp)

            cfgs = bgp.build_config(apply=False)
            self.assertCountEqual(cfgs.keys(), [dev1.name])
            self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([
                'router bgp 100',
                ' exit',
            ]))

            dev2.add_feature(bgp)

            cfgs = bgp.build_config(apply=False)
            self.assertCountEqual(cfgs.keys(), [dev1.name, dev2.name])
            self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([
                'router bgp 100',
                ' exit',
            ]))
            self.assertMultiLineEqual(str(cfgs[dev2.name]), '\n'.join([
                'router bgp 100',
                ' exit',
            ]))

            ospf1 = Ospf(pid=1)
            isis1 = Isis(pid=1)
            rtepol1 = RoutePolicy(name='rtepol1')
            bgp.redistributes = (
                'connected',
                Redistribution(ospf1, metric=20),
                Redistribution(isis1, route_policy=rtepol1),
            )
            bgp.device_attr[dev1].address_family_attr['ipv4 unicast']
            bgp.device_attr[dev2].address_family_attr['ipv4 unicast']

            cfgs = bgp.build_config(apply=False)
            self.assertCountEqual(cfgs.keys(), [dev1.name, dev2.name])
            self.assertMultiLineEqual(
                str(cfgs[dev1.name]), '\n'.join([
                    'router bgp 100',
                    ' address-family ipv4 unicast',
                    '  redistribute connected',
                    '  redistribute ospf 1 metric 20',
                    '  redistribute isis 1 route-policy rtepol1',
                    '  exit',
                    ' exit',
                ]))
            self.assertMultiLineEqual(
                str(cfgs[dev2.name]), '\n'.join([
                    'router bgp 100',
                    ' address-family ipv4 unicast',
                    '  redistribute connected',
                    '  redistribute ospf 1 metric 20',
                    '  redistribute isis 1 route-policy rtepol1',
                    '  exit',
                    ' exit',
                ]))

            del bgp.redistributes

            bgp.device_attr[dev1].add_neighbor(intf3.ipv4)
            bgp.device_attr[dev1].neighbor_attr[intf3.ipv4].\
                address_family_attr['ipv4 unicast']
            bgp.device_attr[dev1].add_vrf(vrf1)
            bgp.device_attr[dev1].vrf_attr[vrf1].address_family_attr[
                'ipv4 unicast']
            bgp.device_attr[dev1].vrf_attr[vrf1].add_neighbor(intf4.ipv4)
            bgp.device_attr[dev1].vrf_attr[vrf1].neighbor_attr[intf4.ipv4].\
                address_family_attr['ipv4 unicast']
            bgp.device_attr[dev1].add_vrf(vrf2)
            bgp.device_attr[dev1].vrf_attr[vrf2].address_family_attr[
                'ipv4 unicast']

            cfgs = bgp.build_config(apply=False)
            self.assertCountEqual(cfgs.keys(), [dev1.name, dev2.name])
            self.assertMultiLineEqual(
                str(cfgs[dev1.name]), '\n'.join([
                    'router bgp 100',
                    ' address-family ipv4 unicast',
                    '  exit',
                    ' neighbor 10.1.0.2',
                    '  remote-as 100',
                    '  address-family ipv4 unicast',
                    '   exit',
                    '  exit',
                    ' vrf a',
                    '  address-family ipv4 unicast',
                    '   exit',
                    '  exit',
                    ' vrf vrf1',
                    '  address-family ipv4 unicast',
                    '   exit',
                    '  neighbor 10.2.0.2',
                    '   remote-as 100',
                    '   address-family ipv4 unicast',
                    '    exit',
                    '   exit',
                    '  exit',
                    ' exit',
                ]))
            self.assertMultiLineEqual(
                str(cfgs[dev2.name]), '\n'.join([
                    'router bgp 100',
                    ' address-family ipv4 unicast',
                    '  exit',
                    ' exit',
                ]))

            cfgs = bgp.build_config(
                apply=False, attributes='device_attr__PE1__vrf_attr__default')
            self.assertCountEqual(cfgs.keys(), [dev1.name])
            self.assertMultiLineEqual(
                str(cfgs[dev1.name]), '\n'.join([
                    'router bgp 100',
                    ' address-family ipv4 unicast',
                    '  exit',
                    ' neighbor 10.1.0.2',
                    '  remote-as 100',
                    '  address-family ipv4 unicast',
                    '   exit',
                    '  exit',
                    ' exit',
                ]))

            cfgs = bgp.build_config(apply=False,
                                    attributes={
                                        'device_attr': {
                                            '*': (),
                                        },
                                    })
            self.assertCountEqual(cfgs.keys(), [dev1.name, dev2.name])
            self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([
                'router bgp 100',
                ' exit',
            ]))
            self.assertMultiLineEqual(str(cfgs[dev2.name]), '\n'.join([
                'router bgp 100',
                ' exit',
            ]))

            cfgs = bgp.build_config(apply=False,
                                    attributes={
                                        'device_attr': {
                                            'PE1': 'vrf_attr__default',
                                        },
                                    })
            self.assertCountEqual(cfgs.keys(), [dev1.name])
            self.assertMultiLineEqual(
                str(cfgs[dev1.name]), '\n'.join([
                    'router bgp 100',
                    ' address-family ipv4 unicast',
                    '  exit',
                    ' neighbor 10.1.0.2',
                    '  remote-as 100',
                    '  address-family ipv4 unicast',
                    '   exit',
                    '  exit',
                    ' exit',
                ]))

            cfgs = bgp.build_config(
                apply=False,
                attributes={
                    'device_attr': {
                        'PE1': 'vrf_attr__default__neighbor_attr__10.1.0.2',
                    },
                })
            self.assertCountEqual(cfgs.keys(), [dev1.name])
            self.assertMultiLineEqual(
                str(cfgs[dev1.name]), '\n'.join([
                    'router bgp 100',
                    ' neighbor 10.1.0.2',
                    '  remote-as 100',
                    '  address-family ipv4 unicast',
                    '   exit',
                    '  exit',
                    ' exit',
                ]))
Ejemplo n.º 10
0
    def test_IsisGlobal(self):

        isis = Isis("core")
        self.link.add_feature(isis)

        self.assertCountEqual(isis.devices, [self.dev1, self.dev2])
        self.assertCountEqual(isis.interfaces, [self.intf1, self.intf2])
        self.assertCountEqual(isis.links, [self.link])

        # Global ISIS config
        isis.nsr = True
        isis.nsf_lifetime = 5

        # override default for both devices
        isis.is_type = Isis.IsType.level_1
        isis.device_attr['PE1'].is_type = Isis.IsType.level_1_2
        isis.device_attr['PE2'].is_type = Isis.IsType.level_2

        # use no default
        isis.device_attr['PE1'].nsf = Isis.Nsf.ietf
        isis.device_attr['PE2'].nsf = Isis.Nsf.cisco

        # override default for one device
        isis.lsp_mtu = 1400
        isis.device_attr['PE1'].lsp_mtu = 1500
        val = 1
        isis.device_attr['PE1'].net_id = "00.0000.0000.000{}.00".format(val)
        val += 1
        isis.device_attr['PE2'].net_id = "00.0000.0000.000{}.00".format(val)

        cfg1 = isis.build_config(apply=False)
        #print("\nPE1 config\n" + str(cfg1['PE1']))
        #print("\nPE2 config\n" + str(cfg1['PE2']))

        self.assertCountEqual(cfg1.keys(), ['PE1', 'PE2'])
        self.assertMultiLineEqual(
            str(cfg1['PE1']), '\n'.join([
                'router isis core',
                ' is-type level-1-2',
                ' lsp-mtu 1500',
                ' net 00.0000.0000.0001.00',
                ' nsf ietf',
                ' nsf lifetime 5',
                ' nsr',
                ' address-family ipv4 unicast',
                '  exit',
                ' interface GigabitEthernet0/0/0/1',
                '  address-family ipv4 unicast',
                '   exit',
                '  exit',
                ' exit',
            ]))
        self.assertMultiLineEqual(
            str(cfg1['PE2']), '\n'.join([
                'router isis core',
                ' is-type level-2-only',
                ' lsp-mtu 1400',
                ' net 00.0000.0000.0002.00',
                ' nsf cisco',
                ' nsf lifetime 5',
                ' nsr',
                ' address-family ipv4 unicast',
                '  exit',
                ' interface GigabitEthernet0/0/0/2',
                '  address-family ipv4 unicast',
                '   exit',
                '  exit',
                ' exit',
            ]))