def test_init_vpls(self):

        testbed = Genie.testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='iosxe')
        lo1 = Interface(device=dev1, name='Loopback0', ipv4='101.0.0.1/32')
        intf1 = Interface(device=dev1,
                          name='GigabitEthernet0/0/1',
                          ipv4='10.1.0.1/24')
        intf2 = Interface(device=dev1,
                          name='GigabitEthernet0/0/2',
                          ipv4='10.2.0.1/24')
        dev2 = Device(testbed=testbed, name='PE2', os='iosxe')
        lo2 = Interface(device=dev2, name='Loopback0', ipv4='102.0.0.1/32')
        intf3 = Interface(device=dev2,
                          name='GigabitEthernet0/0/3',
                          ipv4='10.1.0.2/24')
        intf4 = Interface(device=dev2,
                          name='GigabitEthernet0/0/4',
                          ipv4='10.2.0.2/24')
        link1 = Link(testbed=testbed, name='link1', interfaces=(intf1, intf3))
        link2 = Link(testbed=testbed, name='link2', interfaces=(intf2, intf4))
        dev3 = Device(testbed=testbed, name='PE3', os='iosxe')

        bd1 = BridgeDomain(name='200')
        dev1.add_feature(bd1)
        dev2.add_feature(bd1)

        self.assertCountEqual(bd1.pseudowires, [])
        nbr1 = bd1.create_pseudowire_neighbor(device=dev1, ip=lo2.ipv4.ip)
        nbr2 = bd1.device_attr[dev2].create_pseudowire_neighbor(ip=lo1.ipv4.ip)
        pw1 = Pseudowire(neighbors=(nbr1, nbr2), pw_id=1)
        self.assertCountEqual(bd1.pseudowires, [pw1])
        self.assertCountEqual(bd1.pseudowire_neighbors, [nbr1, nbr2])
        self.assertCountEqual(bd1.device_attr[dev1].pseudowires, [pw1])
        self.assertCountEqual(bd1.device_attr[dev1].pseudowire_neighbors,
                              [nbr1])
        self.assertCountEqual(bd1.device_attr[dev2].pseudowires, [pw1])
        self.assertCountEqual(bd1.device_attr[dev2].pseudowire_neighbors,
                              [nbr2])
        self.assertCountEqual(bd1.device_attr[dev3].pseudowires, [])
        self.assertCountEqual(bd1.device_attr[dev3].pseudowire_neighbors, [])
        self.assertCountEqual(bd1.segments, [pw1])
        self.assertCountEqual(bd1.device_attr[dev1].segments, [pw1])
        self.assertCountEqual(bd1.device_attr[dev2].segments, [pw1])
        self.assertCountEqual(bd1.device_attr[dev3].segments, [])

        cfgs = bd1.build_config(apply=False)
        self.assertMultiLineDictEqual(
            cfgs, {
                dev1.name: '\n'.join([
                    'bridge-domain 200',
                    ' exit',
                ]),
                dev2.name: '\n'.join([
                    'bridge-domain 200',
                    ' exit',
                ]),
            })
    def test_init(self):

        # import pdb; pdb.set_trace()
        testbed = Genie.testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='iosxr')
        intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1')
        intf2 = Interface(device=dev1, name='GigabitEthernet0/0/0/2')
        dev2 = Device(testbed=testbed, name='PE2', os='iosxr')
        intf3 = Interface(device=dev2, name='GigabitEthernet0/0/0/3')
        intf4 = Interface(device=dev2, name='GigabitEthernet0/0/0/4')
        link1 = Link(testbed=testbed, name='link1', interfaces=(intf1, intf3))
        link2 = Link(testbed=testbed, name='link2', interfaces=(intf2, intf4))

        with self.assertRaises(TypeError):
            bd1 = BridgeDomain()

        with self.assertRaises(TypeError):
            bd1 = BridgeDomain(group_name='bg1')

        bd1 = BridgeDomain(name='bd1', group_name='mybg1')
        self.assertEqual(bd1.name, 'bd1')
        self.assertEqual(bd1.group_name, 'mybg1')

        bd1 = BridgeDomain(name='bd1')
        self.assertEqual(bd1.name, 'bd1')
        self.assertEqual(bd1.group_name, 'bd1g')

        self.assertCountEqual(bd1.devices, [])
        self.assertCountEqual(bd1.interfaces, [])
        self.assertCountEqual(bd1.vnis, [])
        self.assertCountEqual(bd1.vfis, [])
        self.assertCountEqual(bd1.evis, [])
        self.assertCountEqual(bd1.segments, [])
        self.assertCountEqual(bd1.link.interfaces, [])

        dev1.add_feature(bd1)
        self.assertCountEqual(bd1.devices, [dev1])
        self.assertCountEqual(bd1.interfaces, [])
        self.assertCountEqual(bd1.vnis, [])
        self.assertCountEqual(bd1.vfis, [])
        self.assertCountEqual(bd1.evis, [])
        self.assertCountEqual(bd1.segments, [])
        self.assertCountEqual(bd1.link.interfaces, [])

        cfgs = bd1.build_config(apply=False)
        self.assertCountEqual(cfgs.keys(), [dev1.name])
        self.assertMultiLineEqual(
            str(cfgs[dev1.name]), '\n'.join([
                'l2vpn',
                ' bridge group bd1g',
                '  bridge-domain bd1',
                '   exit',
                '  exit',
                ' exit',
            ]))

        bd1.add_interface(intf1)
        intf1.l2transport.enabled = True
        self.assertCountEqual(bd1.interfaces, [intf1])
        self.assertCountEqual(bd1.devices, [dev1])
        self.assertCountEqual(bd1.vnis, [])
        self.assertCountEqual(bd1.vfis, [])
        self.assertCountEqual(bd1.evis, [])
        self.assertCountEqual(bd1.segments, [intf1])
        # Links under Genie Interface object is deprecated
        # Placed the below workaround to bypass the Unittest (commented out)
        # self.assertCountEqual(bd1.link.interfaces, [intf3])
        self.assertCountEqual(bd1.device_attr[dev1].interfaces, [intf1])
        self.assertCountEqual(bd1.device_attr[dev2].interfaces, [])
        self.assertCountEqual(bd1.device_attr[dev1].segments, [intf1])
        self.assertCountEqual(bd1.device_attr[dev2].segments, [])

        cfgs = bd1.build_config(apply=False)
        self.assertCountEqual(cfgs.keys(), [dev1.name])
        self.assertMultiLineEqual(
            str(cfgs[dev1.name]), '\n'.join([
                'l2vpn',
                ' bridge group bd1g',
                '  bridge-domain bd1',
                '   interface GigabitEthernet0/0/0/1',
                '    exit',
                '   exit',
                '  exit',
                ' exit',
            ]))
Exemple #3
0
    def test_init(self):

        testbed = Genie.testbed = Testbed()
        dev1 = Device(testbed=testbed, name='PE1', os='iosxe')
        intf1 = Interface(device=dev1, name='GigabitEthernet0/0/1')
        intf2 = Interface(device=dev1, name='GigabitEthernet0/0/2')
        dev2 = Device(testbed=testbed, name='PE2', os='iosxe')
        intf3 = Interface(device=dev2, name='GigabitEthernet0/0/3')
        intf4 = Interface(device=dev2, name='GigabitEthernet0/0/4')
        link1 = Link(testbed=testbed, name='link1', interfaces=(intf1, intf3))
        link2 = Link(testbed=testbed, name='link2', interfaces=(intf2, intf4))

        bd1 = BridgeDomain(name='200')
        self.assertEqual(bd1.name, '200')

        self.assertCountEqual(bd1.devices, [])
        self.assertCountEqual(bd1.interfaces, [])
        self.assertCountEqual(bd1.vnis, [])
        self.assertCountEqual(bd1.vfis, [])
        self.assertCountEqual(bd1.evis, [])
        self.assertCountEqual(bd1.segments, [])
        self.assertCountEqual(bd1.link.interfaces, [])

        dev1.add_feature(bd1)
        self.assertCountEqual(bd1.devices, [dev1])
        self.assertCountEqual(bd1.interfaces, [])
        self.assertCountEqual(bd1.vnis, [])
        self.assertCountEqual(bd1.vfis, [])
        self.assertCountEqual(bd1.evis, [])
        self.assertCountEqual(bd1.segments, [])
        self.assertCountEqual(bd1.link.interfaces, [])

        cfgs = bd1.build_config(apply=False)
        self.assertCountEqual(cfgs.keys(), [dev1.name])
        self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([
            'bridge-domain 200',
            ' exit',
        ]))

        efp = Interface(device=dev1,
                        name='GigabitEthernet0/0/1.20',
                        service_instance=20)
        efp.encapsulation = 'dot1q'
        efp.rewrite_ingress = 'pop 1 symmetric'

        bd1.add_segment(efp)
        self.assertCountEqual(bd1.interfaces, [efp])
        self.assertCountEqual(bd1.devices, [dev1])
        self.assertCountEqual(bd1.vnis, [])
        self.assertCountEqual(bd1.vfis, [])
        self.assertCountEqual(bd1.evis, [])
        self.assertCountEqual(bd1.segments, [efp])
        self.assertCountEqual(bd1.device_attr[dev1].interfaces, [efp])
        self.assertCountEqual(bd1.device_attr[dev2].interfaces, [])
        self.assertCountEqual(bd1.device_attr[dev1].segments, [efp])
        self.assertCountEqual(bd1.device_attr[dev2].segments, [])

        cfgs = bd1.build_config(apply=False)
        self.assertCountEqual(cfgs.keys(), [dev1.name])
        self.assertMultiLineEqual(
            str(cfgs[dev1.name]), '\n'.join([
                'bridge-domain 200',
                ' member GigabitEthernet0/0/1 service-instance 20',
                ' exit',
            ]))