Пример #1
0
    def test_TunnelTeInterface(self):

        Genie.testbed = Testbed()
        dev1 = Device(name='PE1', os='iosxr')
        lo0 = Interface(device=dev1, name='Loopback0')
        intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1')
        intf2 = Interface(device=dev1, name='GigabitEthernet0/0/0/2')

        intf1.ipv4 = '1.2.3.4/32'
        tun3 = Interface(device=dev1, name='tunnel-te101')
        self.assertEqual(tun3.interface_number, 101)
        tun3.destination = intf1.ipv4.ip
        tun3.autoroute_announce = True
        tun3.ipv4_unnumbered_interface = dev1.interfaces['Loopback0']
        tun3.auto_bw_adj_threshold_pct = 1
        tun3.add_path_option(1)
        tun3.path_option_attr[1].dynamic = True
        tun3.add_path_option(2)
        tun3.path_option_attr[2].explicit_name = "exp_PE2_P1_PE1"
        cfg = tun3.build_config(apply=False)
        self.assertMultiLineEqual(
            str(cfg), '\n'.join([
                'interface tunnel-te101',
                ' destination 1.2.3.4',
                ' autoroute announce',
                ' auto-bw adjustment-threshold 1',
                ' ipv4 unnumbered Loopback0',
                ' path-option 1 dynamic',
                ' path-option 2 explicit name exp_PE2_P1_PE1',
                ' exit',
            ]))
    def test_TunnelTeInterface(self):
        Genie.testbed = Testbed()
        dev1 = Device(name='PE1', os='iosxe')
        lo0 = Interface(device=dev1, name='Loopback0')
        intf1 = Interface(device=dev1, name='GigabitEthernet0/0/1')
        intf2 = Interface(device=dev1, name='GigabitEthernet0/0/2')
        intf1.ipv4 = '1.2.3.4/32'
        tun3 = Interface(device=dev1,
                         name='Tunnel101',
                         tunnel_mode='mpls traffic-eng')
        # tun3 = TunnelTeInterface(device=dev1, name='Tunnel101')
        self.assertTrue(isinstance(tun3, TunnelTeInterface))
        self.assertEqual(tun3.interface_number, 101)
        tun3.destination = intf1.ipv4.ip
        tun3.autoroute_announce = True
        tun3.ipv4_unnumbered_interface = dev1.interfaces['Loopback0']
        tun3.add_path_option(1)
        tun3.path_option_attr[1].dynamic = True
        tun3.add_path_option(2)
        tun3.path_option_attr[2].explicit_name = "exp_PE2_P1_PE1"
        cfg = tun3.build_config(apply=False)
        self.assertMultiLineEqual(
            str(cfg), '\n'.join([
                'interface Tunnel101',
                ' tunnel mode mpls traffic-eng',
                ' ip unnumbered Loopback0',
                ' tunnel destination 1.2.3.4',
                ' tunnel mpls traffic-eng autoroute announce',
                ' tunnel mpls traffic-eng path-option 1 dynamic',
                ' tunnel mpls traffic-eng path-option 2 explicit name exp_PE2_P1_PE1',
                ' exit',
            ]))

        uncfg = tun3.build_unconfig(apply=False)
        self.assertMultiLineEqual(str(uncfg), '\n'.join([
            'no interface Tunnel101',
        ]))

        partial_uncfg = tun3.build_unconfig(apply=False,
                                            attributes='autoroute_announce')
        self.assertMultiLineEqual(
            str(partial_uncfg), '\n'.join([
                'interface Tunnel101',
                ' no tunnel mpls traffic-eng autoroute announce',
                ' exit',
            ]))

        partial_cfg1 = tun3.build_config(apply=False,
                                         attributes='path_option_attr__2')
        self.assertMultiLineEqual(
            str(partial_cfg1), '\n'.join([
                'interface Tunnel101',
                ' tunnel mpls traffic-eng path-option 2 explicit name exp_PE2_P1_PE1',
                ' exit',
            ]))