def test_init(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe', context='yang') dev2 = Device(testbed=testbed, name='PE2', os='iosxe', context='yang') intf1 = Interface(name='GigabitEthernet0/0/1', device=dev1) intf2 = Interface(name='GigabitEthernet0/0/2', device=dev2) link = Link(name='1_2_1', testbed=testbed) link.connect_interface(interface=intf1) link.connect_interface(interface=intf2) self.assertSetEqual(set(link.find_interfaces()), set([intf1, intf2])) self.assertSetEqual(set(dev1.find_interfaces()), set([intf1])) self.assertSetEqual(set(dev2.find_interfaces()), set([intf2])) vrf = Vrf(name='test') self.assertSetEqual(set(vrf.devices), set([])) self.assertSetEqual(set(vrf.interfaces), set([])) intf1.vrf = vrf intf2.vrf = vrf dev1.add_feature(vrf) dev2.add_feature(vrf) self.assertCountEqual(vrf.devices, [dev1, dev2]) self.assertSetEqual(set(vrf.interfaces), set([intf1, intf2])) with self.assertRaises(AttributeError): vrf.address_families = set([AddressFamily.ipv8_unicast])
def test_4_per_af(self): vrf = Vrf(name='vrf1') self.dev1.add_feature(vrf) vrf.address_families |= {AddressFamily.ipv6_unicast} vrf.device_attr['PE1'].address_family_attr[ 'ipv4 unicast'].export_route_targets = [ RouteTarget.ImportExport('100:200', stitching=True), ] cfgs = vrf.build_config(apply=False) self.assertMultiLineDictEqual( cfgs, { self.dev1.name: '\n'.join([ 'vrf vrf1', ' address-family ipv4 unicast', ' export route-target 100:200 stitching', ' exit', ' address-family ipv6 unicast', ' exit', ' exit', ]), })
def test_8_per_vrf_per_neighbor(self): ldp = Ldp() self.link.add_feature(ldp) vrf = Vrf(name='vrf1') ldp.add_force_vrf(vrf) nbr1 = IPv4LsrNeighbor('1.2.3.4:0') nbr2 = IPv4LsrNeighbor('1.2.3.5:0') nbr3 = IPv4LsrNeighbor('1.2.3.6:0') ldp.device_attr['PE1'].vrf_attr['vrf1'].neighbors = [nbr1, nbr2, nbr3] ldp.device_attr['PE1'].vrf_attr['vrf1'].neighbor_attr[ '1.2.3.5:0'].password = '******' ldp.device_attr['PE1'].vrf_attr['vrf1'].neighbor_attr[ '1.2.3.6:0'].password = '******' # ==Test per vrf per neighbor config== out = ldp.build_config(apply=False) self.assertMultiLineEqual( str(out['PE1']), '\n'.join([ 'mpls label protocol ldp', 'mpls ip', 'mpls ldp neighbor vrf vrf1 1.2.3.5 password blah22', 'mpls ldp neighbor vrf vrf1 1.2.3.6 password 060506324F41', 'interface GigabitEthernet0/0/1', ' mpls ip', ' exit', ]))
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 test_switchport_enable_config(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) # make intf2 as L2 interface intf1.switchport_enable = True # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join(['interface Ethernet3/7', ' switchport', ' exit'])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'default interface Ethernet3/7', ]))
def test_cfg_vxlan_rewrite_mvpn(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') bgp = Bgp(bgp_id=100) # Defining attributes af_name = 'ipv4 mvpn' vrf = Vrf('default') self.assertIs(bgp.testbed, testbed) dev1.add_feature(bgp) neighbor_id = '10.0.0.1' bgp.device_attr[dev1].vrf_attr[vrf].neighbor_attr[neighbor_id].\ nbr_peer_type = Bgp.NBR_PEER_TYPE.fabric_border_leaf bgp.device_attr[dev1].vrf_attr[vrf].neighbor_attr[neighbor_id].address_family_attr[af_name]. \ nbr_af_rewrite_mvpn_rt_asn = True bgp.device_attr[dev1] 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', ' neighbor 10.0.0.1', ' peer-type fabric-border-leaf', ' address-family ipv4 mvpn', ' rewrite-rt-asn', ' exit', ' exit', ' exit', ])) uncfgs2 = bgp.build_unconfig( apply=False, attributes={'device_attr': {'*': {'vrf_attr': {'*': {'neighbor_attr': \ {'*': {"nbr_peer_type":None, 'address_family_attr': \ {'*': "nbr_af_rewrite_mvpn_rt_asn"}, }}}}}}}) self.assertCountEqual(uncfgs2.keys(), [dev1.name]) self.maxDiff = None self.assertMultiLineEqual( str(uncfgs2[dev1.name]), '\n'.join([ 'router bgp 100', ' neighbor 10.0.0.1', ' no peer-type fabric-border-leaf', ' address-family ipv4 mvpn', ' no rewrite-rt-asn', ' exit', ' exit', ' exit', ]))
def test_init(self): tb = Genie.testbed = Testbed() dev = Device(testbed=tb, name='PE1', os='nxos') rip = Rip(instance_id=10) rip.add_force_vrf(None) dev.add_feature(rip) vrf = Vrf(name='myVrf') dev.add_feature(vrf) self.assertEqual(rip.instance_id, 10) self.assertTrue(isinstance(rip.device_attr, SubAttributesDict)) self.assertTrue(isinstance(rip.device_attr['dev1'].vrf_attr[None].address_family_attr, SubAttributesDict)) # Let's try multilevel rip.mega = 'work' rip.device_attr['myDevice'].value = 'success' rip.device_attr['myDevice'].vrf_attr[None].address_family_attr['ipv4 unicast'].maximum_paths = 3 rip.device_attr['myDevice'].vrf_attr['myVrf'].\ address_family_attr['ipv6 unicast'].distance = 120 self.assertEqual(rip.device_attr['myDevice'].vrf_attr['myVrf'].\ address_family_attr['ipv6 unicast'].distance, 120) self.assertEqual(rip.mega, 'work') self.assertEqual(rip.device_attr['myDevice'].mega, 'work') self.assertEqual(rip.device_attr['fake'].mega, 'work') self.assertEqual( rip.device_attr['myDevice'].vrf_attr[None].address_family_attr['ipv4 unicast'].mega, 'work') self.assertEqual( rip.device_attr['myDevice'].vrf_attr[None].address_family_attr['ipv6 unicast'].mega, 'work') self.assertEqual(rip.device_attr['myDevice'].value, 'success') self.assertEqual( rip.device_attr['myDevice'].vrf_attr[None].address_family_attr['ipv4 unicast'].value, 'success') self.assertEqual( rip.device_attr['myDevice'].vrf_attr[None].address_family_attr['ipv6 unicast'].value, 'success') self.assertEqual( rip.device_attr['myDevice'].vrf_attr[None].address_family_attr['ipv4 unicast'].maximum_paths, 3) with self.assertRaises(AttributeError): rip.value with self.assertRaises(ValueError): rip.device_attr['myDevice'].vrf_attr[None].address_family_attr['ipv8'].value,'success' with self.assertRaises(KeyError): rip.device_attr['myDevice'].vrf_attr[None].address_family_attr['ipv6 flowspec'].value,'success' self.assertEqual(\ rip.device_attr['myDevice'].vrf_attr[None].address_family_attr['ipv6 unicast'].maximum_paths, None) # Test unknown argument which is not defined in rip object or its # parent with self.assertRaises(AttributeError): rip.device_attr['myDevice'].ff
def test_single_line_config(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='iosxr') intf1 = Interface(name='GigabitEthernet0/0/0/0', device=dev1, aliases=['PE1_1']) subif1 = Interface(name='GigabitEthernet0/0/0/1.10', device=dev1, aliases=['PE1_1']) vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Apply configuration intf1.description = 'test' intf1.enabled = True intf1.mtu = 1492 intf1.vrf = vrf intf1.mac_address = 'aabb.ccdd.eeff' intf1.bandwidth = 8192 intf1.load_interval = 33 intf1.unnumbered_intf_ref = 'GigabitEthernet0/0/0/1.10' intf1.ipv6_autoconf = True intf1.medium = 'p2p' # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/0', ' bandwidth 8192', ' description test', ' vrf test', ' ipv4 point-to-point', ' ipv4 unnumbered GigabitEthernet0/0/0/1.10', ' ipv6 address autoconfig', ' load-interval 33', ' mtu 1492', ' no shutdown', ' mac-address aabb.ccdd.eeff', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'no interface GigabitEthernet0/0/0/0', ]))
def setUp(self): Genie.testbed = testbed = Testbed() self.dev1 = Device(testbed=testbed, name='PE1', os='iosxr') self.intf1 = Interface(device=self.dev1, name='GigabitEthernet0/0/0/1', ipv4='10.1.0.1/24') self.intf2 = Interface(device=self.dev1, name='GigabitEthernet0/0/0/2', ipv4='10.2.0.1/24') self.dev2 = Device(testbed=testbed, name='PE2', os='iosxr') self.intf3 = Interface(device=self.dev2, name='GigabitEthernet0/0/0/3', ipv4='10.1.0.2/24') self.intf4 = Interface(device=self.dev2, name='GigabitEthernet0/0/0/4', ipv4='10.2.0.2/24') self.vrf1 = Vrf(name='vrf1') self.vrf2 = Vrf(name='default')
def test_ipv6_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='iosxr') intf1 = Interface(name='GigabitEthernet0/0/0/0', device=dev1, \ aliases=['PE1_1']) vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Apply configuration intf1.description = 'multiple lines config' intf1.enabled = False 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) # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/0', ' ipv6 address 2001:db1:1::1/64', ' ipv6 address 2001:db1:2::2/64', ' description multiple lines config', ' shutdown', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={'ipv6addr':None}) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/0', ' no ipv6 address 2001:db1:1::1/64', ' no ipv6 address 2001:db1:2::2/64', ' exit' ]))
def test_ipv6_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' 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) 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', ' ipv6 address 2001:db1:1::1/64', ' ipv6 address 2001:db1:2::2/64', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'default interface Ethernet3/7', ]))
def test_ospf_config2(self): # For failures self.maxDiff = None # Set testbed Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') # Create VRF objects vrf0 = Vrf('default') # Create OSPF object ospf1 = Ospf() # Add OSPF configurations to vrf default ospf1.device_attr[dev1].vrf_attr[vrf0].instance = '1' ospf1.device_attr[dev1].vrf_attr[vrf0].enable = True ospf1.device_attr[dev1].vrf_attr[vrf0].router_id = '1.1.1.1' ospf1.device_attr[dev1].vrf_attr[vrf0].pref_all = 115 # Add OSPF to the device dev1.add_feature(ospf1) # Build config cfgs = ospf1.build_config(apply=False) # Check config strings built correctly self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'router ospf 1', ' no shutdown', ' router-id 1.1.1.1', ' distance 115', ' exit', ])) # Unconfigure router-id ospf_uncfg = ospf1.build_unconfig( apply=False, attributes={ 'device_attr': { dev1.name: 'vrf_attr__default__router_id', } }) # Check unconfig strings built correctly self.assertMultiLineEqual( str(ospf_uncfg[dev1.name]), '\n'.join([ 'router ospf 1', ' no router-id 1.1.1.1', ' exit', ]))
def test_ospf_device_build_config(self): # Set testbed Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') # Create VRF objects vrf0 = Vrf('default') # Create OSPF object ospf1 = Ospf() # Add OSPF configurations to vrf default ospf1.device_attr[dev1].vrf_attr[vrf0].instance = '30' ospf1.device_attr[dev1].vrf_attr[vrf0].pref_all = 115 ospf1.device_attr[dev1].vrf_attr[vrf0].nsr_enable = True # Add OSPF to the device dev1.add_feature(ospf1) # Build config cfgs = dev1.build_config(apply=False) # Check config strings built correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'router ospf 30', ' distance 115', ' nsr', ' exit', ])) # Unconfigure nsr ospf_uncfg = dev1.build_unconfig( apply=False, attributes={ 'ospf': { 'device_attr': { dev1.name: 'vrf_attr__default__nsr_enable', } } }) # Check unconfig strings built correctly self.assertMultiLineEqual( str(ospf_uncfg), '\n'.join([ 'router ospf 30', ' no nsr', ' exit', ]))
def test_remove_vrf_af(self): # Add a device to it tb = Genie.testbed = Testbed() dev1 = Device(testbed=tb, name='dev1', os='nxos') dev2 = Device(testbed=tb, name='dev2', os='nxos') vrf1 = Vrf(name='blue') intf1 = Interface(device=dev1, name='Ethernet0/0', vrf=vrf1) rip = Rip(instance_id=5) rip.add_force_vrf(None) dev1.add_feature(rip) dev2.add_feature(rip) intf1.add_feature(rip) # Configure rip rip.device_attr['dev1'].vrf_attr['blue'].address_family_attr['ipv4 unicast'].distance = 5 output = rip.build_config(apply=False) self.assertMultiLineDictEqual(output, {'dev1': 'feature rip\n' 'router rip 5\n' ' address-family ipv4 unicast\n' ' exit\n' ' vrf blue\n' ' address-family ipv4 unicast\n' ' distance 5\n' ' exit\n' ' exit\n' ' exit', 'dev2': 'feature rip\n' 'router rip 5\n' ' address-family ipv4 unicast\n' ' exit\n' ' exit'}) output = rip.build_unconfig(\ attributes='device_attr__dev1__vrf_attr__blue__address_family_attr__ipv4 unicast', apply=False) self.assertMultiLineDictEqual(output, {'dev1': 'router rip 5\n' ' vrf blue\n' ' no address-family ipv4 unicast\n' ' exit\n' ' exit'})
def test_multiple_pim_static_rp_config(self): # For failures self.maxDiff = None # shorten the line dev1 = self.dev1 # VRF configuration vrf = Vrf('default') # == bsr static rp === # -- bsr static rp intf -- # Pim object pim = Pim() dev1.add_feature(pim) rp1 = RPAddressGroup(device=self.dev1) rp1.static_rp_address = '2.2.2.2' rp2 = RPAddressGroup(device=self.dev1) rp2.static_rp_address = '3.3.3.3' rp2.static_rp_group_list = 'rp_group_list' rp3 = RPAddressGroup(device=self.dev1) rp3.static_rp_address = '4.4.4.4' rp3.static_rp_group_list = 'rp_group_list' rp3.static_rp_override = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr[ 'ipv4'].add_static_rp(rp1) pim.device_attr[dev1].vrf_attr[vrf].address_family_attr[ 'ipv4'].add_static_rp(rp2) pim.device_attr[dev1].vrf_attr[vrf].address_family_attr[ 'ipv4'].add_static_rp(rp3) # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'ip pim rp-address 2.2.2.2', 'ip pim rp-address 3.3.3.3 rp_group_list', 'ip pim rp-address 4.4.4.4 rp_group_list override', ]))
def test_pim_bsr_config(self): # For failures self.maxDiff = None # shorten the line dev1 = self.dev1 # VRF configuration vrf = Vrf('default') # == bsr rp === # Pim object pim = Pim() dev1.add_feature(pim) pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_candidate_interface = 'Ethernet1/1' # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'ip pim bsr forward listen', 'ip pim bsr-candidate Ethernet1/1', ])) # Pim object pim = Pim() dev1.add_feature(pim) pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_candidate_interface = 'Ethernet1/1' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_candidate_hash_mask_length = 30 # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'ip pim bsr forward listen', 'ip pim bsr-candidate Ethernet1/1 hash-len 30', ])) # Pim object pim = Pim() dev1.add_feature(pim) pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_candidate_interface = 'Ethernet1/1' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_candidate_priority = 200 # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'ipv6 pim bsr forward listen', 'ipv6 pim bsr-candidate Ethernet1/1 priority 200', ])) # == bsr rp intf route-map === # Pim object pim = Pim() dev1.add_feature(pim) # VRF configuration vrf = Vrf('red') pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_rp_candidate_interface = 'Ethernet1/1' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_rp_candidate_route_map = 'test' # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'vrf context red', ' ipv6 pim bsr forward listen', ' ipv6 pim rp-candidate Ethernet1/1 route-map test', ' exit', ])) # == auto-rp intf prefix-list with interval bidir=== # Pim object pim = Pim() dev1.add_feature(pim) # VRF configuration vrf = Vrf('red') pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_interface = 'Ethernet1/1' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_prefix_list = 'LALALLA' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_interval = 60 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_bidir = True # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'vrf context red', ' ip pim bsr forward listen', ' ip pim rp-candidate Ethernet1/1 prefix-list LALALLA interval 60 bidir', ' exit', ]))
def test_pim_auto_rp_config(self): # For failures self.maxDiff = None # shorten the line dev1 = self.dev1 # VRF configuration vrf = Vrf('default') # == auto-rp lack of information === # Pim object pim = Pim() dev1.add_feature(pim) pim.device_attr[dev1].enabled_pim = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_rp_group = '1.1.1.1' # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'feature pim', ])) # == auto-rp intf group-list === # Pim object pim = Pim() dev1.add_feature(pim) # Apply configuration pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_intf = 'Ethernet1/1' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_group_list = '239.0.0.0/24' # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'ip pim send-rp-announce Ethernet1/1 group-list 239.0.0.0/24', ])) # == auto-rp group route-map with interval === # Pim object pim = Pim() dev1.add_feature(pim) # VRF configuration vrf = Vrf('red') # Apply configuration pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_rp_group = '1.1.1.1' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_route_map = 'test' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_interval = 30 # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'vrf context red', ' ip pim send-rp-announce 1.1.1.1 route-map test interval 30', ' exit', ])) # == auto-rp intf prefix-list with interval bidir=== # Pim object pim = Pim() dev1.add_feature(pim) # VRF configuration vrf = Vrf('red') # Apply configuration pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ auto_rp = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_intf = 'Ethernet1/1' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_prefix_list = 'test' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_scope = 10 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_bidir = True # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'vrf context red', ' ip pim auto-rp rp-candidate Ethernet1/1 prefix-list test scope 10 bidir', ' exit', ])) # == auto-rp discovery=== # Pim object pim = Pim() dev1.add_feature(pim) # VRF configuration vrf = Vrf('default') pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_discovery = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_discovery_intf = 'Ethernet1/1' # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'ip pim send-rp-discovery Ethernet1/1', ]))
def test_pim_full_config(self): # For failures self.maxDiff = None # shorten the line dev1 = self.dev1 # Pim object pim = Pim() dev1.add_feature(pim) # Apply configuration pim.device_attr[dev1].enabled = True # VRF configuration vrf1 = Vrf('default') pim.device_attr[self.dev1].vrf_attr[vrf1] vrf2 = Vrf('red') pim.device_attr[self.dev1].vrf_attr[vrf2] for vrf, intf in {vrf1: 'Ethernet1/1', vrf2: 'Ethernet2/1'}.items(): # == auto-rp === pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ auto_rp = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_rp_group = '1.1.1.1' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_route_map = 'test' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_scope = 20 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_interval = 60 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_announce_bidir = True # == auto-rp discovery=== pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ auto_rp_discovery = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_discovery_intf = intf pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ send_rp_discovery_scope = 20 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ autorp_listener = True # == bsr candidate === pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_candidate_interface = intf pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_candidate_hash_mask_length = 20 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_candidate_priority = 20 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_candidate_interface = intf pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_candidate_hash_mask_length = 20 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_candidate_priority = 20 # == bsr rp-candidate === pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_interface = intf pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_group_list = '239.0.0.0/24' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_route_map = 'test' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_prefix_list = 'LLAL' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_priority = 10 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_interval = 60 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_bidir = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ bsr_rp_candidate_priority = 10 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_rp_candidate_interface = intf pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_rp_candidate_group_list = 'ff1e:abcd:def1::0/64' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_rp_candidate_route_map = 'test' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_rp_candidate_prefix_list = 'LLAL' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_rp_candidate_priority = 10 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ bsr_rp_candidate_interval = 60 # == static RP === rp1 = RPAddressGroup(device=self.dev1) rp1.static_rp_address = '1.1.1.1' rp1.static_rp_group_list = '239.0.0.0/24' rp1.static_rp_route_map = 'test' rp1.static_rp_prefix_list = 'LLAL' rp1.static_rp_bidir = True rp1.static_rp_override = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr[ 'ipv4'].add_static_rp(rp1) rp2 = RPAddressGroup(device=self.dev1) rp2.static_rp_address = '2001:db8:1:1::1' rp2.static_rp_group_list = 'ff1e:abcd:def1::0/64' rp2.static_rp_route_map = 'test' rp2.static_rp_prefix_list = 'LLAL' rp2.static_rp_override = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr[ 'ipv6'].add_static_rp(rp2) # == static rp register === pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ accept_register = 'regist_name' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ accept_register_prefix_list = 'test' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ accept_register = 'regist_name' # not ipv6 supported pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ accept_register_prefix_list = 'test' # log-neighbor-changes pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ log_neighbor_changes = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ log_neighbor_changes = True # register_source pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ register_source = intf # not ipv6 supported pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ register_source = intf # == sg-expiry-timer == pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ sg_expiry_timer = 182 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ sg_expiry_timer_infinity = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ sg_expiry_timer_sg_list = 'sg_name' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ sg_expiry_timer_prefix_list = 'prefix_name' # == spt-threshold == pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ spt_switch_infinity = 'infinity' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ spt_switch_policy = 'abcde' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ spt_switch_infinity = 'infinity' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ spt_switch_policy = 'abcde' # == interface == # ---- mode ---------- pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ interface_attr[intf].mode = 'sparse-mode' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ interface_attr[intf].boundary = 'abc' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ interface_attr[intf].boundary_in = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ interface_attr[intf].mode = 'sparse-mode' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ interface_attr[intf].boundary = 'abc' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ interface_attr[intf].boundary_in = True # ---- jp-policy ---------- pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ interface_attr[intf].boundary = 'test' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ interface_attr[intf].boundary_in = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ interface_attr[intf].boundary_out = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ interface_attr[intf].boundary = 'test' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ interface_attr[intf].boundary_in = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ interface_attr[intf].boundary_out = True # ---- border ---------- pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ interface_attr[intf].bsr_border = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ interface_attr[intf].bsr_border = True # ---- hello-interval ---------- pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ interface_attr[intf].hello_interval = 30000 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ interface_attr[intf].hello_interval = 30000 # ---- dr-priority ---------- pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ interface_attr[intf].dr_priority = 777 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ interface_attr[intf].dr_priority = 777 # ---- neighbor-policy ---------- pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ interface_attr[intf].neighbor_filter = 'pim_neighbor_policy' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ interface_attr[intf].neighbor_filter_prefix_list = 'test' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ interface_attr[intf].neighbor_filter = 'pim_neighbor_policy' # not supported pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv6'].\ interface_attr[intf].neighbor_filter_prefix_list = 'test' # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'feature pim', 'feature pim6', 'ip pim auto-rp rp-candidate 1.1.1.1 route-map test interval 60 scope 20 bidir', 'ip pim auto-rp mapping-agent Ethernet1/1 scope 20', 'ip pim auto-rp forward listen', 'ip pim bsr forward listen', 'ip pim bsr-candidate Ethernet1/1 hash-len 20 priority 20', 'ip pim bsr forward listen', 'ip pim rp-candidate Ethernet1/1 group-list 239.0.0.0/24 priority 10 interval 60 bidir', 'ip pim register-policy regist_name', 'ip pim register-policy prefix-list test', 'ip pim log-neighbor-changes', 'ip pim register-source Ethernet1/1', 'ip pim sg-expiry-timer 182 prefix-list prefix_name', 'ip pim sg-expiry-timer 182 sg-list sg_name', 'ip pim sg-expiry-timer infinity prefix-list prefix_name', 'ip pim sg-expiry-timer infinity sg-list sg_name', 'ip pim spt-threshold infinity group-list abcde', 'ip pim rp-address 1.1.1.1 group-list 239.0.0.0/24 bidir', 'interface Ethernet1/1', ' ip pim sparse-mode', ' ip pim jp-policy test in', ' ip pim jp-policy test out', ' ip pim border', ' ip pim hello-interval 30000', ' ip pim dr-priority 777', ' ip pim neighbor-policy pim_neighbor_policy', ' ip pim neighbor-policy prefix-list test', ' exit', 'ipv6 pim bsr forward listen', 'ipv6 pim bsr-candidate Ethernet1/1 hash-len 20 priority 20', 'ipv6 pim bsr forward listen', 'ipv6 pim rp-candidate Ethernet1/1 group-list ff1e:abcd:def1::0/64 priority 10 interval 60', 'ipv6 pim register-policy regist_name', 'ipv6 pim log-neighbor-changes', 'ipv6 pim spt-threshold infinity group-list abcde', 'ipv6 pim rp-address 2001:db8:1:1::1 group-list ff1e:abcd:def1::0/64 override', 'interface Ethernet1/1', ' ipv6 pim sparse-mode', ' ipv6 pim jp-policy test in', ' ipv6 pim jp-policy test out', ' ipv6 pim border', ' ipv6 pim hello-interval 30000', ' ipv6 pim dr-priority 777', ' ipv6 pim neighbor-policy pim_neighbor_policy', ' exit', 'vrf context red', ' ip pim auto-rp rp-candidate 1.1.1.1 route-map test interval 60 scope 20 bidir', ' ip pim auto-rp mapping-agent Ethernet2/1 scope 20', ' ip pim auto-rp forward listen', ' ip pim bsr forward listen', ' ip pim bsr-candidate Ethernet2/1 hash-len 20 priority 20', ' ip pim bsr forward listen', ' ip pim rp-candidate Ethernet2/1 group-list 239.0.0.0/24 priority 10 interval 60 bidir', ' ip pim register-policy regist_name', ' ip pim register-policy prefix-list test', ' ip pim log-neighbor-changes', ' ip pim register-source Ethernet2/1', ' ip pim sg-expiry-timer 182 prefix-list prefix_name', ' ip pim sg-expiry-timer 182 sg-list sg_name', ' ip pim sg-expiry-timer infinity prefix-list prefix_name', ' ip pim sg-expiry-timer infinity sg-list sg_name', ' ip pim spt-threshold infinity group-list abcde', ' ip pim rp-address 1.1.1.1 group-list 239.0.0.0/24 bidir', ' exit', 'interface Ethernet2/1', ' ip pim sparse-mode', ' ip pim jp-policy test in', ' ip pim jp-policy test out', ' ip pim border', ' ip pim hello-interval 30000', ' ip pim dr-priority 777', ' ip pim neighbor-policy pim_neighbor_policy', ' ip pim neighbor-policy prefix-list test', ' exit', 'vrf context red', ' ipv6 pim bsr forward listen', ' ipv6 pim bsr-candidate Ethernet2/1 hash-len 20 priority 20', ' ipv6 pim bsr forward listen', ' ipv6 pim rp-candidate Ethernet2/1 group-list ff1e:abcd:def1::0/64 priority 10 interval 60', ' ipv6 pim register-policy regist_name', ' ipv6 pim log-neighbor-changes', ' ipv6 pim spt-threshold infinity group-list abcde', ' ipv6 pim rp-address 2001:db8:1:1::1 group-list ff1e:abcd:def1::0/64 override', ' exit', 'interface Ethernet2/1', ' ipv6 pim sparse-mode', ' ipv6 pim jp-policy test in', ' ipv6 pim jp-policy test out', ' ipv6 pim border', ' ipv6 pim hello-interval 30000', ' ipv6 pim dr-priority 777', ' ipv6 pim neighbor-policy pim_neighbor_policy', ' exit', ])) cfgs = pim.build_unconfig(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'no feature pim', 'no feature pim6', ])) cfgs = pim.build_unconfig( apply=False, attributes={ 'device_attr': { self.dev1: { 'vrf_attr': { 'default': { 'address_family_attr': { 'ipv4': { 'register_source': None } } }, 'red': { 'address_family_attr': { 'ipv6': { 'interface_attr': { 'Ethernet2/1': { 'mode': None } } } } } } } } }) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'no ip pim register-source Ethernet1/1', 'interface Ethernet2/1', ' no ipv6 pim sparse-mode', ' exit', ]))
def test_uncfg(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') intf1 = Interface(device=dev1, name='Ethernet0/0/1', ipv4='10.1.0.1/24') intf2 = Interface(device=dev1, name='Ethernet0/0/2', ipv4='10.2.0.1/24') dev2 = Device(testbed=testbed, name='PE2', os='nxos') intf3 = Interface(device=dev2, name='Ethernet0/0/3', ipv4='10.1.0.2/24', ipv6='2001:111:222::/64') intf4 = Interface(device=dev2, name='Ethernet0/0/4', ipv4='10.2.0.2/24') 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,bgp_id=100) self.assertIs(bgp.testbed, testbed) Genie.testbed = testbed bgp = Bgp(asn=100,bgp_id=100) self.assertIs(bgp.testbed, Genie.testbed) self.assertIs(bgp.testbed, testbed) dev1.add_feature(bgp) bgp.device_attr[dev1].enabled = True uncfgs = bgp.build_unconfig(apply=False) self.assertCountEqual(uncfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(uncfgs[dev1.name]), '\n'.join([ 'no feature bgp', ])) # Defining attributes af_name = 'vpnv4 unicast' af_name2 = 'link-state' vrf_id = 'vrf1' vrf1 = Vrf(vrf_id) bgp.device_attr[dev1] bgp.device_attr[dev1].vrf_attr[None].always_compare_med = True bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name] bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name2] bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_retain_rt_all = True bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_dampening = True bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_dampening_half_life_time = 1 bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_dampening_reuse_time = 10 bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_dampening_suppress_time = 30 bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_dampening_max_suppress_time = 2 neighbor_id = intf4.ipv4 bgp.device_attr[dev1].vrf_attr[vrf1].add_neighbor(neighbor_id) bgp.device_attr[dev1].vrf_attr[vrf1].neighbor_attr[neighbor_id] bgp.device_attr[dev1].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ nbr_fall_over_bfd = True nbr_af_name = 'ipv4 unicast' bgp.device_attr[dev1].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name] bgp.device_attr[dev1].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name].nbr_af_allowas_in = True partial_uncfg1 = bgp.build_unconfig( apply=False, attributes={'device_attr':\ {'*':{'vrf_attr':\ {'*':"always_compare_med"}}}}) self.assertCountEqual(partial_uncfg1.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg1[dev1.name]), '\n'.\ join([ 'router bgp 100', ' no bestpath always-compare-med', ' exit', ])) partial_uncfg2 = bgp.build_unconfig(\ apply=False, attributes={'device_attr':\ {'*':{'vrf_attr':'*'}}}) self.assertCountEqual(partial_uncfg2.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg2[dev1.name]), '\n'.\ join([ 'router bgp 100', ' no bestpath always-compare-med', ' no address-family link-state', ' no address-family vpnv4 unicast', ' no vrf vrf1', ' exit', ])) partial_uncfg3 = bgp.build_unconfig( apply=False, attributes={'device_attr': {'*': {'vrf_attr': {'*': {'neighbor_attr':\ {'*': {'address_family_attr':\ {'*':"nbr_af_allowas_in"}}}}}}}}) self.assertCountEqual(partial_uncfg3.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg3[dev1.name]), '\n'.\ join([ 'router bgp 100', ' vrf vrf1', ' neighbor 10.2.0.2', ' address-family ipv4 unicast', ' no allowas-in', ' exit', ' exit', ' exit', ' exit', ])) bgp.device_attr[dev1].protocol_shutdown = True partial_uncfg4 = bgp.build_unconfig( apply=False, attributes={'device_attr':\ {'*':"protocol_shutdown"}}) self.assertCountEqual(partial_uncfg4.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg4[dev1.name]), '\n'.\ join([ 'router bgp 100', ' no shutdown', ' exit', ])) partial_uncfg5 = bgp.build_unconfig(\ apply=False, attributes={'device_attr':\ {'*':\ {'vrf_attr':\ {'*':\ {'address_family_attr':\ {'*':\ "af_dampening"}}}}}}) self.assertCountEqual(partial_uncfg5.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg5[dev1.name]), '\n'.\ join([ 'router bgp 100', ' address-family vpnv4 unicast', ' no dampening', ' exit', ' exit', ])) bgp.device_attr[dev1].enabled = False uncfgs = bgp.build_unconfig(apply=False) self.assertCountEqual(uncfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(uncfgs[dev1.name]), '\n'.join([ 'no router bgp 100', ])) bgp.device_attr[dev1].enabled = True uncfgs = bgp.build_unconfig(apply=False) self.assertCountEqual(uncfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(uncfgs[dev1.name]), '\n'.join([ 'no feature bgp', ]))
def test_single_line_config(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']) intf2 = Interface(name='Ethernet3/9', device=dev1, aliases=['PE1_2']) subif1 = Interface(name='Ethernet3/6.10', device=dev1, aliases=['PE1_1']) vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Apply configuration intf1.description = 'test' intf1.enabled = False # intf1.shutdown = False intf1.link_up_down_trap_enable = True intf1.mtu = 1492 intf1.vrf = vrf intf1.mac_address = 'aabb.ccdd.eeff' intf1.bandwidth = 8192 intf1.link_status = True intf1.load_interval = 33 intf1.dhcp = True intf1.unnumbered_intf_ref = 'Ethernet3/6.10' intf1.ipv6_autoconf = True intf1.switchport_mode = 'access' intf1.medium = 'p2p' intf1.delay = 11 intf1.access_vlan = '19' intf1.auto_negotiate = False # make intf2 as L2 interface intf1.switchport_enable = True intf2.enabled = True intf2.switchport_enable = True intf2.switchport_mode = 'trunk' intf2.trunk_add_vlans = '1,2,3' # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet3/7', ' medium p2p', ' bandwidth 8192', ' delay 11', ' description test', ' mtu 1492', ' shutdown', ' snmp trap link-status', ' vrf member test', ' logging event port link-status', ' ip address dhcp', ' ip unnumbered Ethernet3/6.10', ' ipv6 address autoconfig', ' switchport', ' switchport mode access', ' load-interval 33', ' mac-address aabb.ccdd.eeff', ' switchport access vlan 19', ' no speed', ' no duplex', ' exit' ])) cfgs = intf2.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet3/9', ' no shutdown', ' switchport', ' switchport mode trunk', ' switchport trunk allowed vlan add 1,2,3', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={ 'mtu': True, 'enabled': True }) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join( ['interface Ethernet3/7', ' no mtu', ' no shutdown', ' exit'])) uncfgs = intf2.build_unconfig(apply=False, attributes={'trunk_add_vlans': True}) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface Ethernet3/9', ' switchport trunk allowed vlan remove 1,2,3', ' exit' ]))
def test_ospfv3_non_default_vrf_config(self): # For failures self.maxDiff = None # Set testbed Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') # Create VRF objects vrf1 = Vrf('VRF1') # Create Interface object intf1 = Interface(name='Ethernet1/1', device=dev1) # Create OSPF object ospfv3_1 = Ospfv3() ospfv3_1.device_attr[dev1].enabled = True # Add OSPF configuration to vrf VRF1 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].instance = '30' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].inst_shutdown = False ospfv3_1.device_attr[dev1].vrf_attr[vrf1].router_id = '3.3.3.3' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].passive_interface = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].log_adjacency_changes = True ospfv3_1.device_attr[dev1].vrf_attr[ vrf1].log_adjacency_changes_detail = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_arrival = 30 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_group_pacing = 40 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_start_time = 50 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_hold_time = 60 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_max_time = 70 # Add graceful restart configuration to vrf default gr1 = GracefulRestart(device=dev1) gr1.gr_enable = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr1) # Add graceful restart configuration to vrf default gr2 = GracefulRestart(device=dev1) gr2.gr_enable = True gr2.gr_restart_interval = 100 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr2) # # Add graceful restart configuration to vrf default gr3 = GracefulRestart(device=dev1) gr3.gr_enable = True gr3.gr_helper_enable = False ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr3) # # Add graceful restart configuration to vrf default gr4 = GracefulRestart(device=dev1) gr4.gr_enable = True gr4.gr_planned_only = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr4) # Add area configuration to vrf default ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].area_type = 'stub' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].nosummary = False # Add area configuration to vrf default ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].area_type = 'nssa' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].nosummary = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].nssa_default_info_originate = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].nssa_route_map = 'test_route_map' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].nssa_translate_always = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '2'].nssa_translate_supressfa = True # address_family attributes ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].default_metric = 100 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_bgp_id = 100 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_bgp_route_map = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_rip_id = 'rip-nxos' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_rip_route_map = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_direct = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_direct_route_map = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_static = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_static_route_map = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_isis_id = 'ABC' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_isis_route_map = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].default_originate = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].default_originate_routemap = 'test' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_max_prefix = 12 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_max_prefix_thld = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].redist_max_prefix_warn_only = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].spf_start_time = 100 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].spf_hold_time = 200 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].spf_max_time = 300 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].table_map = 'test' # Add area default cost configuration to vrf default ad1 = AreaDefaultCost(device=dev1) ad1.af_area_id = '2' ad1.area_def_cost = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_areacost_key(ad1) # # Add area routemap direction to vrf default arm1 = AreaRouteMap(device=dev1) arm1.routemap_area_id = '2' arm1.ar_route_map_in = 'test_in' arm1.ar_route_map_out = 'test_out' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_arearoutemap_key(arm1) # Add summary address configuration to vrf default sa1 = SummaryAddress(device=dev1) sa1.summary_address_prefix = '2001:db1:1::1/64' sa1.summary_address_not_advertise = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_sumadd_key(sa1) # Add summary address configuration to vrf default sa2 = SummaryAddress(device=dev1) sa2.summary_address_prefix = '2001:db2:2::2/64' sa2.summary_address_tag = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_sumadd_key(sa2) # Add area range configuration to vrf default ar1 = AreaRange(device=dev1) ar1.range_area_id = '2' ar1.area_range_prefix = '2001:bd12:2::2/64' ar1.area_range_not_advertise = True ar1.area_range_cost = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_arearange_key(ar1) # virtual link attributes ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '7'].virtual_link_attr['ospfv3_vl1'].vl_router_id = '7.7.7.7' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '7'].virtual_link_attr['ospfv3_vl1'].vl_hello_interval = 55 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '7'].virtual_link_attr['ospfv3_vl1'].vl_dead_interval = 65 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '7'].virtual_link_attr['ospfv3_vl1'].vl_retransmit_interval = 75 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '7'].virtual_link_attr['ospfv3_vl1'].vl_transmit_delay = 85 # Add interface configuration to VRF default ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_admin_control = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_secondaries = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_cost = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_type = 'point-to-point' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_passive = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_priority = 110 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_hello_interval = 50 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_dead_interval = 60 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_retransmit_interval = 70 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_transmit_delay = 70 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_mtu_ignore = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_instance = 60 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_protocol_shutdown = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '0'].interface_attr[intf1].if_multi_area = 10 dev1.add_feature(ospfv3_1) # Build config cfgs = ospfv3_1.build_config(apply=False) # Check config strings built correctly self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'feature ospfv3', 'router ospfv3 30', ' vrf VRF1', ' router-id 3.3.3.3', ' passive-interface default', ' log-adjacency-changes detail', ' timers lsa-arrival 30', ' timers lsa-group-pacing 40', ' timers throttle lsa 50 60 70', ' graceful-restart', ' graceful-restart grace-period 100', ' graceful-restart helper-disable', ' graceful-restart planned-only', ' address-family ipv6 unicast', ' default-information originate True route-map test', ' default-metric 100', ' redistribute bgp 100 route-map test', ' redistribute direct route-map test', ' redistribute static route-map test', ' redistribute isis ABC route-map test', ' redistribute rip rip-nxos route-map test', ' redistribute maximum-prefix 12 10 warning-only', ' table-map test', ' timers throttle lsa 100 200 300', ' area 2 default-cost 10', ' area 2 filter-list route-map test_in in', ' area 2 filter-list route-map test_out out', ' summary-address 2001:db1:1::1/64 not-advertise', ' summary-address 2001:db2:2::2/64 tag 10', ' area 2 range 2001:bd12:2::2/64 not-advertise cost 10', ' exit', ' area 1 stub', ' area 2 nssa no-summary default-information-originate route-map test_route_map', ' area 2 nssa translate type7 always suppress-fa', ' area 7 virtual-link 7.7.7.7', ' hello-interval 55', ' dead-interval 65', ' retransmit-interval 75', ' transmit-delay 85', ' exit', ' exit', ' exit', 'interface Ethernet1/1', ' ipv6 router ospfv3 30 area 0', ' ospfv3 cost 10', ' ospfv3 network point-to-point', ' ospfv3 passive-interface', ' ospfv3 priority 110', ' ospfv3 hello-interval 50', ' ospfv3 dead-interval 60', ' ospfv3 retransmit-interval 70', ' ospfv3 mtu-ignore', ' ospfv3 instance 60', ' ospfv3 shutdown', ' ospfv3 transmit-delay 70', ' ipv6 router ospfv3 30 multi-area 10', ' exit' ])) # Unconfig ospfv3_uncfg = ospfv3_1.build_unconfig(apply=False) # Check unconfig strings built correctly self.assertMultiLineEqual(str(ospfv3_uncfg[dev1.name]), '\n'.join([ 'no feature ospfv3', ]))
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 test_ospf_config1(self): # For failures self.maxDiff = None # Set testbed Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') # Create VRF objects vrf0 = Vrf('default') vrf1 = Vrf('VRF1') vrf2 = Vrf('VRF2') # Create Interface object intf1 = Interface(name='GigabitEthernet1', device=dev1) # Create OSPF object ospf1 = Ospf() # Add OSPF configurations to vrf default ospf1.device_attr[dev1].vrf_attr[vrf0].instance = '30' ospf1.device_attr[dev1].vrf_attr[vrf0].enable = True ospf1.device_attr[dev1].vrf_attr[vrf0].router_id = '3.3.3.3' ospf1.device_attr[dev1].vrf_attr[vrf0].pref_all = 115 ospf1.device_attr[dev1].vrf_attr[vrf0].nsr_enable = True ospf1.device_attr[dev1].vrf_attr[vrf0].ldp_autoconfig = True ospf1.device_attr[dev1].vrf_attr[ vrf0].ldp_auto_config_area_id = '0.0.0.0' ospf1.device_attr[dev1].vrf_attr[vrf0].ldp_igp_sync = True ospf1.device_attr[dev1].vrf_attr[vrf0].redist_bgp_id = 100 ospf1.device_attr[dev1].vrf_attr[vrf0].redist_bgp_metric = 555 ospf1.device_attr[dev1].vrf_attr[vrf0].redist_bgp_metric_type = '1' ospf1.device_attr[dev1].vrf_attr[vrf0].redist_bgp_nssa_only = True ospf1.device_attr[dev1].vrf_attr[vrf0].redist_bgp_route_map = 'test' ospf1.device_attr[dev1].vrf_attr[vrf0].redist_bgp_subnets = True ospf1.device_attr[dev1].vrf_attr[vrf0].redist_bgp_tag = 12 ospf1.device_attr[dev1].vrf_attr[vrf0].redist_connected = True ospf1.device_attr[dev1].vrf_attr[vrf0].redist_connected_metric = 12 ospf1.device_attr[dev1].vrf_attr[ vrf0].redist_connected_route_policy = 'test' ospf1.device_attr[dev1].vrf_attr[vrf0].redist_static = True ospf1.device_attr[dev1].vrf_attr[vrf0].redist_static_metric = 12 ospf1.device_attr[dev1].vrf_attr[ vrf0].redist_static_route_policy = 'test' ospf1.device_attr[dev1].vrf_attr[vrf0].redist_isis = 'ABC' ospf1.device_attr[dev1].vrf_attr[vrf0].redist_isis_metric = 12 ospf1.device_attr[dev1].vrf_attr[ vrf0].redist_isis_route_policy = 'test' ospf1.device_attr[dev1].vrf_attr[vrf0].redist_max_prefix = 12 ospf1.device_attr[dev1].vrf_attr[vrf0].redist_max_prefix_thld = 10 ospf1.device_attr[dev1].vrf_attr[ vrf0].redist_max_prefix_warn_only = True ospf1.device_attr[dev1].vrf_attr[vrf0].bfd_enable = True ospf1.device_attr[dev1].vrf_attr[vrf0].bfd_strict_mode = True ospf1.device_attr[dev1].vrf_attr[vrf0].log_adjacency_changes = True ospf1.device_attr[dev1].vrf_attr[ vrf0].log_adjacency_changes_detail = True ospf1.device_attr[dev1].vrf_attr[ vrf0].adjacency_stagger_initial_number = 10 ospf1.device_attr[dev1].vrf_attr[ vrf0].adjacency_stagger_maximum_number = 100 ospf1.device_attr[dev1].vrf_attr[vrf0].auto_cost_enable = True ospf1.device_attr[dev1].vrf_attr[vrf0].spf_paths = 15 ospf1.device_attr[dev1].vrf_attr[vrf0].spf_start = 600 ospf1.device_attr[dev1].vrf_attr[vrf0].spf_hold = 700 ospf1.device_attr[dev1].vrf_attr[vrf0].spf_maximum = 800 ospf1.device_attr[dev1].vrf_attr[vrf0].spf_lsa_start = 600 ospf1.device_attr[dev1].vrf_attr[vrf0].spf_lsa_hold = 700 ospf1.device_attr[dev1].vrf_attr[vrf0].spf_lsa_maximum = 800 ospf1.device_attr[dev1].vrf_attr[vrf0].db_ctrl_max_lsa = 123 ospf1.device_attr[dev1].vrf_attr[vrf0].default_originate = True ospf1.device_attr[dev1].vrf_attr[vrf0].default_originate_always = True ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr[ '0'].area_te_enable = True ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_admin_control = True ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_cost = 10 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_type = 'point-to-point' ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_passive = True ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_demand_circuit = True ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_priority = 110 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_bfd_enable = True ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_bfd_interval = 999 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_bfd_min_interval = 999 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_bfd_multiplier = 7 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_hello_interval = 50 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_dead_interval = 60 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_retransmit_interval = 70 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_lls = True ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_ttl_sec_enable = True ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_ttl_sec_hops = 25 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_auth_trailer_key_chain = 'montreal' ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_auth_trailer_key_crypto_algorithm = 'md5' ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_auth_trailer_key = 'quebec' ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_mtu_ignore = True ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].if_prefix_suppression = True # Add interface static neighbor configuration to OSPF static_nbr1 = InterfaceStaticNeighbor(device=dev1) static_nbr1.if_static_neighbor = '10.10.10.10' static_nbr1.if_static_cost = 20 static_nbr1.if_static_poll_interval = 60 static_nbr1.if_static_priority = 110 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].add_staticnbr_key(static_nbr1) static_nbr2 = InterfaceStaticNeighbor(device=dev1) static_nbr2.if_static_neighbor = '20.20.20.20' static_nbr2.if_static_cost = 30 static_nbr2.if_static_poll_interval = 120 static_nbr2.if_static_priority = 113 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].add_staticnbr_key(static_nbr2) static_nbr3 = InterfaceStaticNeighbor(device=dev1) static_nbr3.if_static_neighbor = '30.30.30.30' static_nbr3.if_static_cost = 40 static_nbr3.if_static_poll_interval = 150 static_nbr3.if_static_priority = 115 ospf1.device_attr[dev1].vrf_attr[vrf0].area_attr['0'].interface_attr[ intf1].add_staticnbr_key(static_nbr3) # Add OSPF configurations to vrf VRF1 ospf1.device_attr[dev1].vrf_attr[vrf1].instance = '10' ospf1.device_attr[dev1].vrf_attr[vrf1].enable = True ospf1.device_attr[dev1].vrf_attr[vrf1].router_id = '1.1.1.1' ospf1.device_attr[dev1].vrf_attr[vrf1].pref_intra_area = 112 ospf1.device_attr[dev1].vrf_attr[vrf1].pref_inter_area = 113 ospf1.device_attr[dev1].vrf_attr[vrf1].pref_external = 114 ospf1.device_attr[dev1].vrf_attr[vrf1].auto_cost_enable = True ospf1.device_attr[dev1].vrf_attr[ vrf1].auto_cost_reference_bandwidth = 60 ospf1.device_attr[dev1].vrf_attr[ vrf1].auto_cost_bandwidth_unit = 'gbps' ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].area_te_enable = True ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].area_type = 'stub' ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].default_cost = 1111 ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].virtual_link_attr['OSPF_VL0'].vl_router_id = '7.7.7.7' ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].virtual_link_attr['OSPF_VL0'].vl_hello_interval = 55 ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].virtual_link_attr['OSPF_VL0'].vl_dead_interval = 65 ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].virtual_link_attr['OSPF_VL0'].vl_retransmit_interval = 75 ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].virtual_link_attr['OSPF_VL0'].vl_transmit_delay = 85 ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].virtual_link_attr['OSPF_VL0'].vl_ttl_sec_hops = 167 ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].virtual_link_attr[ 'OSPF_VL0'].vl_auth_trailer_key_chain = 'ottawa' ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].virtual_link_attr[ 'OSPF_VL0'].vl_auth_trailer_key_crypto_algorithm = 'simple' ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].virtual_link_attr['OSPF_VL0'].vl_auth_trailer_key = 'anything' ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr['1'].sham_link_attr[ 'OSPF_SL0'].sl_local_id = '11.11.11.11' ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr['1'].sham_link_attr[ 'OSPF_SL0'].sl_remote_id = '12.12.12.12' ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr['1'].sham_link_attr[ 'OSPF_SL0'].sl_ttl_sec_hops = 10 ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr['1'].sham_link_attr[ 'OSPF_SL1'].sl_local_id = '15.15.15.15' ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr['1'].sham_link_attr[ 'OSPF_SL1'].sl_remote_id = '16.16.16.16' ospf1.device_attr[dev1].vrf_attr[vrf1].area_attr['1'].sham_link_attr[ 'OSPF_SL1'].sl_cost = 50 # Add OSPF configurations to vrf VRF2 ospf1.device_attr[dev1].vrf_attr[vrf2].instance = '20' ospf1.device_attr[dev1].vrf_attr[vrf2].enable = True ospf1.device_attr[dev1].vrf_attr[vrf2].router_id = '2.2.2.2' ospf1.device_attr[dev1].vrf_attr[vrf2].auto_cost_enable = False ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].area_te_enable = True ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].area_type = 'nssa' ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr['2'].summary = False ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].default_cost = 1111 ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].virtual_link_attr['OSPF_VL1'].vl_router_id = '8.8.8.8' ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].virtual_link_attr['OSPF_VL1'].vl_hello_interval = 56 ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].virtual_link_attr['OSPF_VL1'].vl_dead_interval = 66 ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].virtual_link_attr['OSPF_VL1'].vl_retransmit_interval = 76 ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].virtual_link_attr['OSPF_VL1'].vl_transmit_delay = 86 ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].virtual_link_attr['OSPF_VL1'].vl_ttl_sec_hops = 168 ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].virtual_link_attr[ 'OSPF_VL1'].vl_auth_trailer_key_chain = 'toronto' ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].virtual_link_attr[ 'OSPF_VL1'].vl_auth_trailer_key_crypto_algorithm = 'md5' ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].virtual_link_attr['OSPF_VL1'].vl_auth_trailer_key = 'anything' # Add graceful restart configuration to OSPF gr1 = GracefulRestart(device=dev1) gr1.gr_enable = True gr1.gr_type = 'cisco' gr1.gr_helper_enable = False ospf1.device_attr[dev1].vrf_attr[vrf2].add_gr_key(gr1) gr2 = GracefulRestart(device=dev1) gr2.gr_enable = True gr2.gr_type = 'ietf' gr2.gr_helper_strict_lsa_checking = True ospf1.device_attr[dev1].vrf_attr[vrf2].add_gr_key(gr2) gr3 = GracefulRestart(device=dev1) gr3.gr_enable = True gr3.gr_type = 'ietf' gr3.gr_restart_interval = 50 ospf1.device_attr[dev1].vrf_attr[vrf2].add_gr_key(gr3) # Add stub router configuration to OSPF sr1 = StubRouter(device=dev1) sr1.stub_router_always = True sr1.stub_router_include_stub = True sr1.stub_router_summary_lsa = True sr1.stub_router_external_lsa = True ospf1.device_attr[dev1].vrf_attr[vrf2].add_sr_key(sr1) sr2 = StubRouter(device=dev1) sr2.stub_router_on_startup = 50 sr2.stub_router_include_stub = True sr2.stub_router_summary_lsa = True sr2.stub_router_external_lsa = True ospf1.device_attr[dev1].vrf_attr[vrf2].add_sr_key(sr2) # Add area network configuration to OSPF an1 = AreaNetwork(device=dev1) an1.area_network = '192.168.1.0' an1.area_network_wildcard = '0.0.0.0' ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].add_areanetwork_key(an1) an2 = AreaNetwork(device=dev1) an2.area_network = '192.168.1.1' an2.area_network_wildcard = '0.0.0.255' ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].add_areanetwork_key(an2) # Add area range configuration to OSPF ar1 = AreaRange(device=dev1) ar1.area_range_prefix = '1.1.1.1/24' ar1.area_range_advertise = False ar1.area_range_cost = 10 ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].add_arearange_key(ar1) ar2 = AreaRange(device=dev1) ar2.area_range_prefix = '2.2.2.2 255.255.255.255' ar2.area_range_advertise = True ospf1.device_attr[dev1].vrf_attr[vrf2].area_attr[ '2'].add_arearange_key(ar2) # Add OSPF to the device dev1.add_feature(ospf1) # Build config cfgs = ospf1.build_config(apply=False) # Check config strings built correctly self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'router ospf 30', ' no shutdown', ' router-id 3.3.3.3', ' distance 115', ' nsr', ' mpls ldp autoconfig area 0.0.0.0', ' mpls ldp sync', ' redistribute bgp 100 metric 555 metric-type 1 subnets nssa-only tag 12 route-map test', ' redistribute connected metric 12 route-map test', ' redistribute static metric 12 route-map test', ' redistribute isis ABC metric 12 route-map test', ' redistribute maximum-prefix 12 10 warning-only', ' bfd all-interfaces strict-mode', ' log-adjacency-changes detail', ' adjacency stagger 10 100', ' auto-cost', ' maximum-paths 15', ' timers throttle spf 600 700 800', ' timers throttle lsa 600 700 800', ' max-lsa 123', ' default-information originate always', ' mpls traffic-eng area 0', ' passive-interface GigabitEthernet1', ' neighbor 10.10.10.10 cost 20 poll-interval 60 priority 110', ' neighbor 20.20.20.20 cost 30 poll-interval 120 priority 113', ' neighbor 30.30.30.30 cost 40 poll-interval 150 priority 115', ' exit', 'router ospf 10 vrf VRF1', ' no shutdown', ' router-id 1.1.1.1', ' distance ospf intra-area 112 inter-area 113 external 114', ' auto-cost reference-bandwidth 60000', ' mpls traffic-eng area 1', ' area 1 stub', ' area 1 default-cost 1111', ' area 1 virtual-link 7.7.7.7', ' area 1 virtual-link 7.7.7.7 hello-interval 55', ' area 1 virtual-link 7.7.7.7 dead-interval 65', ' area 1 virtual-link 7.7.7.7 retransmit-interval 75', ' area 1 virtual-link 7.7.7.7 transmit-delay 85', ' area 1 virtual-link 7.7.7.7 ttl-security hops 167', ' area 1 virtual-link 7.7.7.7 authentication key-chain ottawa', ' area 1 virtual-link 7.7.7.7 authentication', ' area 1 virtual-link 7.7.7.7 authentication-key anything', ' area 1 sham-link 11.11.11.11 12.12.12.12', ' area 1 sham-link 11.11.11.11 12.12.12.12 ttl-security hops 10', ' area 1 sham-link 15.15.15.15 16.16.16.16', ' area 1 sham-link 15.15.15.15 16.16.16.16 cost 50', ' exit', 'router ospf 20 vrf VRF2', ' no shutdown', ' router-id 2.2.2.2', ' nsf cisco helper disable', ' nsf ietf restart-interval 50', ' nsf ietf helper strict-lsa-checking', ' no auto-cost', ' max-metric router-lsa external-lsa include-stub summary-lsa on-startup 50', ' max-metric router-lsa external-lsa include-stub summary-lsa', ' network 192.168.1.0 0.0.0.0 area 2', ' network 192.168.1.1 0.0.0.255 area 2', ' mpls traffic-eng area 2', ' area 2 nssa no-summary', ' area 2 default-cost 1111', ' area 2 range 1.1.1.1 255.255.255.0 not-advertise cost 10', ' area 2 range 2.2.2.2 255.255.255.255 advertise', ' area 2 virtual-link 8.8.8.8', ' area 2 virtual-link 8.8.8.8 hello-interval 56', ' area 2 virtual-link 8.8.8.8 dead-interval 66', ' area 2 virtual-link 8.8.8.8 retransmit-interval 76', ' area 2 virtual-link 8.8.8.8 transmit-delay 86', ' area 2 virtual-link 8.8.8.8 ttl-security hops 168', ' area 2 virtual-link 8.8.8.8 authentication key-chain toronto', ' area 2 virtual-link 8.8.8.8 authentication message-digest', ' area 2 virtual-link 8.8.8.8 message-digest-key 1 md5 anything', ' exit', 'interface GigabitEthernet1', ' ip ospf 30 area 0', ' ip ospf cost 10', ' ip ospf network point-to-point', ' ip ospf demand-circuit', ' ip ospf priority 110', ' ip ospf bfd', ' bfd interval 999 min_rx 999 multiplier 7', ' ip ospf hello-interval 50', ' ip ospf dead-interval 60', ' ip ospf retransmit-interval 70', ' ip ospf lls', ' ip ospf ttl-security hops 25', ' ip ospf authentication key-chain montreal', ' ip ospf authentication message-digest', ' ip ospf message-digest-key 1 md5 quebec', ' ip ospf mtu-ignore', ' ip ospf prefix-suppression', ' exit', ])) # Unconfig ospf_uncfg = ospf1.build_unconfig(apply=False) # Check unconfig strings built correctly self.assertMultiLineEqual( str(ospf_uncfg[dev1.name]), '\n'.join([ 'no router ospf 30', 'no router ospf 10 vrf VRF1', 'no router ospf 20 vrf VRF2', ]))
def test_pim_static_rp_config(self): # For failures self.maxDiff = None # shorten the line dev1 = self.dev1 # VRF configuration vrf = Vrf('default') # == bsr static rp === # -- bsr static rp intf -- # Pim object pim = Pim() dev1.add_feature(pim) rp1 = RPAddressGroup(device=self.dev1) rp1.static_rp_address = '2.2.2.2' rp1.static_rp_group_list = '224.0.0.0/4' rp2 = RPAddressGroup(device=self.dev1) rp2.static_rp_address = '3.3.3.3' rp2.static_rp_group_list = '224.0.0.0/4' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr[ 'ipv4'].add_static_rp(rp1) pim.device_attr[dev1].vrf_attr[vrf].address_family_attr[ 'ipv4'].add_static_rp(rp2) # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'ip pim rp-address 2.2.2.2 group-list 224.0.0.0/4', 'ip pim rp-address 3.3.3.3 group-list 224.0.0.0/4', ])) # == bsr static rp intf route-map === # Pim object pim = Pim() dev1.add_feature(pim) rp1 = RPAddressGroup(device=self.dev1) rp1.static_rp_address = '1.1.1.1' rp1.static_rp_route_map = 'test' pim.device_attr[dev1].vrf_attr[vrf].address_family_attr[ 'ipv4'].add_static_rp(rp1) # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'ip pim rp-address 1.1.1.1 route-map test', ])) # == bsr static rp intf group-list ipv6 === # Pim object pim = Pim() dev1.add_feature(pim) rp1 = RPAddressGroup(device=self.dev1) rp1.static_rp_address = '1:1::1:1' rp1.static_rp_group_list = 'ff00::/8' rp1.static_rp_override = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr[ 'ipv6'].add_static_rp(rp1) # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'ipv6 pim rp-address 1:1::1:1 group-list ff00::/8 override', ]))
def test_pim_sg_expiry_timer_config(self): # For failures self.maxDiff = None # shorten the line dev1 = self.dev1 # VRF configuration vrf = Vrf('default') # == sg_expiry_timer === # Pim object pim = Pim() dev1.add_feature(pim) pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ sg_expiry_timer = 181 # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'ip pim sg-expiry-timer 181', ])) # == sg_expiry_timer_infinity === # Pim object pim = Pim() dev1.add_feature(pim) # VRF configuration vrf = Vrf('blue') pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ sg_expiry_timer_infinity = True # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'vrf context blue', ' ip pim sg-expiry-timer infinity', ' exit', ])) # == sg_expiry_timer sg_expiry_timer_sg_list === # Pim object pim = Pim() dev1.add_feature(pim) # VRF configuration vrf = Vrf('VRF1') pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ sg_expiry_timer = 200 pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ sg_expiry_timer_sg_list = 'test' # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'vrf context VRF1', ' ip pim sg-expiry-timer 200 sg-list test', ' exit', ])) # == sg_expiry_timer_infinity sg_expiry_timer_prefix_list === # Pim object pim = Pim() dev1.add_feature(pim) # VRF configuration vrf = Vrf('default') pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ sg_expiry_timer_infinity = True pim.device_attr[dev1].vrf_attr[vrf].address_family_attr['ipv4'].\ sg_expiry_timer_prefix_list = 'test' # Build config cfgs = pim.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.\ join([ 'ip pim sg-expiry-timer infinity prefix-list test', ]))
def test_mcast_config(self): # For failures self.maxDiff = None # VRF configuration vrf1 = Vrf('VRF1') self.igmp.device_attr[self.dev1].require_router_alert = True igmp1 = self.igmp.device_attr[self.dev1].vrf_attr[vrf1] ssm1 = Ssm(device=self.dev1) ssm1.ssm_group_range = '239.1.1.0/24' ssm1.ssm_source_addr = '1.1.1.1' igmp1.add_ssm(ssm1) ssm2 = Ssm(device=self.dev1) ssm2.ssm_group_range = '239.1.1.0/24' ssm2.ssm_source_addr = '2.2.2.2' igmp1.add_ssm(ssm2) # Interface configuration intf1_obj = Interface(device=self.dev1, name='Ethernet2/4') intf1_obj.vrf = vrf1 intf1 = intf1_obj.name self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .enable = True self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .robustness_variable = 7 self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .group_policy = 'test2' self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .immediate_leave = True self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .max_groups = 10 self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .query_interval = 133 self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .query_max_response_time = 15 self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .version = 3 # join and static groups configuration igmp_intf1 = self.igmp.device_attr[ self.dev1].vrf_attr[vrf1].interface_attr[intf1] join_group1 = IgmpGroup(device=self.dev1) join_group1.join_group = '239.1.1.1' join_group2 = IgmpGroup(device=self.dev1) join_group2.join_group = '239.3.3.3' join_group2.join_group_source_addr = '1.1.1.1' join_group3 = IgmpGroup(device=self.dev1) join_group3.join_group = '239.2.2.2' static_group1 = IgmpGroup(device=self.dev1) static_group1.static_group = '239.5.5.5' static_group2 = IgmpGroup(device=self.dev1) static_group2.static_group = '239.6.6.6' static_group2.static_group_source_addr = '2.2.2.1' static_group3 = IgmpGroup(device=self.dev1) static_group3.static_group = '239.6.6.6' static_group3.static_group_source_addr = '2.2.2.2' igmp_intf1.add_groups(join_group1) igmp_intf1.add_groups(join_group2) igmp_intf1.add_groups(join_group3) igmp_intf1.add_groups(static_group1) igmp_intf1.add_groups(static_group2) igmp_intf1.add_groups(static_group3) vrf2 = Vrf('default') igmp2 = self.igmp.device_attr[self.dev1].vrf_attr[vrf2] ssm1 = Ssm(device=self.dev1) ssm1.ssm_group_range = '239.1.2.0/24' ssm1.ssm_source_addr = '3.3.3.3' igmp2.add_ssm(ssm1) ssm2 = Ssm(device=self.dev1) ssm2.ssm_group_range = '239.1.1.0/24' ssm2.ssm_source_addr = '3.3.3.3' igmp2.add_ssm(ssm2) # Interface configuration intf2_obj = Interface(device=self.dev1, name='Ethernet2/1') ipv4a = IPv4Addr(device=self.dev1) ipv4a.ipv4 = '20.1.2.1' ipv4a.prefix_length = '24' intf2_obj.add_ipv4addr(ipv4a) intf2 = intf2_obj.name self.igmp.device_attr[self.dev1].vrf_attr[vrf2].interface_attr[intf2]\ .enable = True # join and static groups configuration igmp_intf1 = self.igmp.device_attr[ self.dev1].vrf_attr[vrf2].interface_attr[intf2] join_group = IgmpGroup(device=self.dev1) join_group.join_group = '239.3.3.3' join_group.join_group_source_addr = '1.1.1.1' static_group = IgmpGroup(device=self.dev1) static_group.static_group = '239.5.5.5' igmp_intf1.add_groups(join_group) igmp_intf1.add_groups(static_group) # Build interface config for none-default vrfs intf_cfgs = intf1_obj.build_config(apply=False) self.assertMultiLineEqual( str(intf_cfgs), '\n'.join([ 'interface Ethernet2/4', ' vrf member VRF1', ' exit', ])) intf_cfgs = intf2_obj.build_config(apply=False) self.assertMultiLineEqual( str(intf_cfgs), '\n'.join([ 'interface Ethernet2/1', ' ip address 20.1.2.1/24', ' exit', ])) # Build igmp configuration cfgs = self.igmp.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'ip igmp enforce-router-alert', 'ip igmp ssm-translate 239.1.1.0/24 3.3.3.3', 'ip igmp ssm-translate 239.1.2.0/24 3.3.3.3', 'interface Ethernet2/1', ' ip pim sparse-mode', ' ip igmp join-group 239.3.3.3 source 1.1.1.1', ' ip igmp static-oif 239.5.5.5', ' exit', 'vrf context VRF1', ' ip igmp ssm-translate 239.1.1.0/24 1.1.1.1', ' ip igmp ssm-translate 239.1.1.0/24 2.2.2.2', ' exit', 'interface Ethernet2/4', ' ip pim sparse-mode', ' ip igmp access-group test2', ' ip igmp immediate-leave', ' ip igmp state-limit 10', ' ip igmp query-interval 133', ' ip igmp query-max-response-time 15', ' ip igmp robustness-variable 7', ' ip igmp version 3', ' ip igmp join-group 239.1.1.1', ' ip igmp join-group 239.2.2.2', ' ip igmp join-group 239.3.3.3 source 1.1.1.1', ' ip igmp static-oif 239.5.5.5', ' ip igmp static-oif 239.6.6.6 source 2.2.2.1', ' ip igmp static-oif 239.6.6.6 source 2.2.2.2', ' exit', ])) # Build unconfig cfgs = self.igmp.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no ip igmp enforce-router-alert', 'no ip igmp ssm-translate 239.1.1.0/24 3.3.3.3', 'no ip igmp ssm-translate 239.1.2.0/24 3.3.3.3', 'interface Ethernet2/1', ' no ip pim sparse-mode', ' no ip igmp join-group 239.3.3.3 source 1.1.1.1', ' no ip igmp static-oif 239.5.5.5', ' exit', 'no vrf context VRF1', 'interface Ethernet2/4', ' no ip pim sparse-mode', ' no ip igmp access-group test2', ' no ip igmp immediate-leave', ' no ip igmp state-limit 10', ' no ip igmp query-interval 133', ' no ip igmp query-max-response-time 15', ' no ip igmp robustness-variable 7', ' no ip igmp version 3', ' no ip igmp join-group 239.1.1.1', ' no ip igmp join-group 239.2.2.2', ' no ip igmp join-group 239.3.3.3 source 1.1.1.1', ' no ip igmp static-oif 239.5.5.5', ' no ip igmp static-oif 239.6.6.6 source 2.2.2.1', ' no ip igmp static-oif 239.6.6.6 source 2.2.2.2', ' exit', ])) # Build unconfig with attribute cfgs = self.igmp.build_unconfig(apply=False, attributes={ 'device_attr': { self.dev1: { 'require_router_alert': True, 'vrf_attr': { vrf1: { 'ssm': None, }, vrf2: { 'interface_attr': { 'Ethernet2/1': { 'enable': True } } } } } } }) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no ip igmp enforce-router-alert', 'interface Ethernet2/1', ' no ip pim sparse-mode', ' exit', 'vrf context VRF1', ' no ip igmp ssm-translate 239.1.1.0/24 1.1.1.1', ' no ip igmp ssm-translate 239.1.1.0/24 2.2.2.2', ' exit', ]))
def test_ospfv3_partial_config_unconfig(self): # For failures self.maxDiff = None # Set testbed Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') # Create VRF objects vrf1 = Vrf('VRF1') # Create Interface object intf1 = Interface(name='Ethernet1/1', device=dev1) # Create OSPF object ospfv3_1 = Ospfv3() ospfv3_1.device_attr[dev1].enabled = True # Add OSPF configuration to vrf default ospfv3_1.device_attr[dev1].vrf_attr[vrf1].instance = '30' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].inst_shutdown = False ospfv3_1.device_attr[dev1].vrf_attr[vrf1].router_id = '3.3.3.3' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].passive_interface = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].log_adjacency_changes = True ospfv3_1.device_attr[dev1].vrf_attr[ vrf1].log_adjacency_changes_detail = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_arrival = 30 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_group_pacing = 40 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_start_time = 50 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_hold_time = 60 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].lsa_max_time = 70 # Add graceful restart configuration to vrf vrf1 gr1 = GracefulRestart(device=dev1) gr1.gr_enable = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr1) # Add graceful restart configuration to vrf vrf1 gr2 = GracefulRestart(device=dev1) gr2.gr_enable = True gr2.gr_restart_interval = 100 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr2) # # Add graceful restart configuration to vrf vrf1 gr3 = GracefulRestart(device=dev1) gr3.gr_enable = True gr3.gr_helper_enable = False ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr3) # # Add graceful restart configuration to vrf vrf1 gr4 = GracefulRestart(device=dev1) gr4.gr_enable = True gr4.gr_planned_only = True ospfv3_1.device_attr[dev1].vrf_attr[vrf1].add_gr_key(gr4) # Add area configuration to vrf vrf1 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].area_type = 'stub' ospfv3_1.device_attr[dev1].vrf_attr[vrf1].area_attr[ '1'].nosummary = True # Add summary address configuration to vrf vrf1 sa2 = SummaryAddress(device=dev1) sa2.summary_address_prefix = '2001:db2:2::2/64' sa2.summary_address_tag = 10 ospfv3_1.device_attr[dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6 unicast'].add_sumadd_key(sa2) dev1.add_feature(ospfv3_1) # Build config cfgs = ospfv3_1.build_config(apply=False) # Check config strings built correctly self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'feature ospfv3', 'router ospfv3 30', ' vrf VRF1', ' router-id 3.3.3.3', ' passive-interface default', ' log-adjacency-changes detail', ' timers lsa-arrival 30', ' timers lsa-group-pacing 40', ' timers throttle lsa 50 60 70', ' graceful-restart', ' graceful-restart grace-period 100', ' graceful-restart helper-disable', ' graceful-restart planned-only', ' address-family ipv6 unicast', ' summary-address 2001:db2:2::2/64 tag 10', ' exit', ' area 1 stub no-summary', ' exit', ' exit' ])) # change partial config - router_id ospfv3_1.device_attr[dev1].vrf_attr[vrf1].router_id = '7.7.7.7' partial_cfg1 = ospfv3_1.build_config(apply=False, attributes={ 'device_attr': { '*': { 'vrf_attr': { '*': "router_id" } } } }) self.assertCountEqual(partial_cfg1.keys(), [dev1.name]) self.assertMultiLineEqual( str(partial_cfg1[dev1.name]), '\n'.join([ 'router ospfv3 30', ' vrf VRF1', ' router-id 7.7.7.7', ' exit', ' exit', ])) # remove cfg - area 1 stub partial_uncfg1 = ospfv3_1.build_unconfig(apply=False, attributes={ 'device_attr': { '*': { 'vrf_attr': { '*': "lsa_arrival" } } } }) self.assertMultiLineEqual( str(partial_uncfg1[dev1.name]), '\n'.join([ 'router ospfv3 30', ' vrf VRF1', ' no timers lsa-arrival 30', ' exit', ' exit', ])) # # remove a single attribute from a specific gr key partial_uncfg2 = ospfv3_1.build_unconfig( apply=False, attributes={ 'device_attr': { '*': { 'vrf_attr': { '*': { 'gr_keys': { gr4: { 'gr_enable': None } } } } } } }) self.assertMultiLineEqual( str(partial_uncfg2[dev1.name]), '\n'.join([ 'router ospfv3 30', ' vrf VRF1', ' no graceful-restart', ' exit', ' exit', ])) # remove all grace full restart multiline configs partial_uncfg3 = ospfv3_1.build_unconfig( apply=False, attributes={'device_attr': { '*': { 'vrf_attr': { '*': 'gr_keys' } } }}) self.assertMultiLineEqual( str(partial_uncfg3[dev1.name]), '\n'.join([ 'router ospfv3 30', ' vrf VRF1', ' no graceful-restart', ' no graceful-restart grace-period 100', ' no graceful-restart helper-disable', ' no graceful-restart planned-only', ' exit', ' exit', ]))
def test_mcast_config(self): # For failures self.maxDiff = None # Create VRFs vrf1 = Vrf('red') self.mcast.device_attr[self.dev1].vrf_attr[vrf1] self.mcast.device_attr[ self.dev1].vrf_attr[None].address_family_attr['ipv4'].enable = True self.mcast.device_attr[ self.dev1].vrf_attr[None].address_family_attr['ipv6'].enable = True self.mcast.device_attr[self.dev1].vrf_attr[ 'default'].address_family_attr['ipv4'].multipath = True self.mcast.device_attr[self.dev1].vrf_attr[ 'default'].address_family_attr['ipv6'].multipath = True self.mcast.device_attr[ self.dev1].vrf_attr[vrf1].address_family_attr['ipv4'].enable = True self.mcast.device_attr[ self.dev1].vrf_attr[vrf1].address_family_attr['ipv6'].enable = True intf1_obj = Interface(device=self.dev1, name='GigabitEthernet0/0/0/0') self.mcast.device_attr[self.dev1].vrf_attr[vrf1].address_family_attr['ipv6'].\ interface_attr[intf1_obj.name].if_enable = True # ipv4 config under VRF1 # vrf1 ip mroute config mroute1a = Mroute(device=self.dev1) mroute1a.mroute_address = '192.1.1.1' mroute1a.mroute_prefix_mask = 32 mroute1a.mroute_interface_name = 'GigabitEthernet0/0/0/2' mroute1a.mroute_neighbor_address = '172.30.10.13' mroute1c = Mroute(device=self.dev1) mroute1c.mroute_address = '192.1.1.10' mroute1c.mroute_prefix_mask = 32 mroute1c.mroute_interface_name = 'GigabitEthernet0/0/0/1' mroute1c.mroute_neighbor_address = '172.30.10.14' # Add mroute to mcast config self.mcast.device_attr[self.dev1].vrf_attr[vrf1].address_family_attr[ 'ipv4'].add_mroute(mroute1a) self.mcast.device_attr[self.dev1].vrf_attr[vrf1].address_family_attr[ 'ipv4'].add_mroute(mroute1c) # ipv6 config under VRF1 # vrf1 ipv6 mroute config mroute1b = Mroute(device=self.dev1) mroute1b.mroute_address = '129::' mroute1b.mroute_prefix_mask = 128 mroute1b.mroute_interface_name = 'GigabitEthernet0/0/0/2' mroute1b.mroute_neighbor_address = '140::' # Add mroute to mcast config self.mcast.device_attr[self.dev1].vrf_attr[vrf1].address_family_attr[ 'ipv6'].add_mroute(mroute1b) # ipv4 config under top level # default vrf ip mroute config mroute2a = Mroute(device=self.dev1) mroute2a.mroute_address = '192.168.3.1' mroute2a.mroute_prefix_mask = 32 mroute2a.mroute_interface_name = 'GigabitEthernet0/0/0/5' mroute2a.mroute_neighbor_address = '172.30.10.20' self.mcast.device_attr[self.dev1].vrf_attr[ 'default'].address_family_attr['ipv4'].add_mroute(mroute2a) # ipv6 config under top level # default vrf ipv6 mroute config mroute2b = Mroute(device=self.dev1) mroute2b.mroute_address = '126::' mroute2b.mroute_prefix_mask = 128 mroute2b.mroute_interface_name = 'GigabitEthernet0/0/0/5' mroute2b.mroute_neighbor_address = '150::' # Add mroute to mcast config self.mcast.device_attr[self.dev1].vrf_attr[ 'default'].address_family_attr['ipv6'].add_mroute(mroute2b) # Build config cfgs = self.mcast.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'multicast-routing', ' address-family ipv4', ' interface all enable', ' multipath', ' static-rpf 192.168.3.1 32 GigabitEthernet0/0/0/5 172.30.10.20', ' exit', ' address-family ipv6', ' interface all enable', ' multipath', ' static-rpf 126:: 128 GigabitEthernet0/0/0/5 150::', ' exit', ' vrf red', ' address-family ipv4', ' interface all enable', ' static-rpf 192.1.1.1 32 GigabitEthernet0/0/0/2 172.30.10.13', ' static-rpf 192.1.1.10 32 GigabitEthernet0/0/0/1 172.30.10.14', ' exit', ' address-family ipv6', ' interface all enable', ' static-rpf 129:: 128 GigabitEthernet0/0/0/2 140::', ' interface GigabitEthernet0/0/0/0', ' enable', ' exit', ' exit', ' exit', ' exit', ])) # Build unconfig cfgs = self.mcast.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ # Top level - IPv4 'no multicast-routing', ])) cfgs = self.mcast.build_unconfig( apply=False, attributes={ 'device_attr': { self.dev1: { 'vrf_attr': { 'default': { 'address_family_attr': { 'ipv4': { 'enable': None } } }, 'red': { 'address_family_attr': { 'ipv4': { 'mroutes': None } } } } } } }) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'multicast-routing', ' address-family ipv4', ' no interface all enable', ' exit', ' vrf red', ' address-family ipv4', ' no static-rpf 192.1.1.1 32 GigabitEthernet0/0/0/2 172.30.10.13', ' no static-rpf 192.1.1.10 32 GigabitEthernet0/0/0/1 172.30.10.14', ' exit', ' exit', ' exit', ]))
def test_mcast_config(self): # For failures self.maxDiff = None # VRF configuration vrf1 = Vrf('default') self.igmp.device_attr[self.dev1].require_router_alert = True igmp1 = self.igmp.device_attr[self.dev1].vrf_attr[vrf1] ssm1 = Ssm(device=self.dev1) ssm1.ssm_group_policy = 'test' ssm1.ssm_source_addr = '1.1.1.1' igmp1.add_ssm(ssm1) ssm2 = Ssm(device=self.dev1) ssm2.ssm_group_policy = 'test' ssm2.ssm_source_addr = '2.2.2.2' igmp1.add_ssm(ssm2) # Interface configuration intf1 = 'GigabitEthernet0/0/0/0' self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .enable = True self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .robustness_variable = 7 self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .group_policy = 'test2' self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .max_groups = 10 self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .query_interval = 133 self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .query_max_response_time = 12 self.igmp.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .version = 3 # join and static groups configuration igmp_intf1 = self.igmp.device_attr[ self.dev1].vrf_attr[vrf1].interface_attr[intf1] join_group1 = IgmpGroup(device=self.dev1) join_group1.join_group = '239.1.1.1' join_group2 = IgmpGroup(device=self.dev1) join_group2.join_group = '239.3.3.3' join_group2.join_group_source_addr = '1.1.1.1' join_group3 = IgmpGroup(device=self.dev1) join_group3.join_group = '239.2.2.2' static_group1 = IgmpGroup(device=self.dev1) static_group1.static_group = '239.5.5.5' static_group2 = IgmpGroup(device=self.dev1) static_group2.static_group = '239.6.6.6' static_group2.static_group_source_addr = '2.2.2.1' static_group3 = IgmpGroup(device=self.dev1) static_group3.static_group = '239.6.6.6' static_group3.static_group_source_addr = '2.2.2.2' igmp_intf1.add_groups(join_group1) igmp_intf1.add_groups(join_group2) igmp_intf1.add_groups(join_group3) igmp_intf1.add_groups(static_group1) igmp_intf1.add_groups(static_group2) igmp_intf1.add_groups(static_group3) # vrf2 = Vrf('VRF1') vrf2 = 'VRF1' igmp2 = self.igmp.device_attr[self.dev1].vrf_attr[vrf2] ssm3 = Ssm(device=self.dev1) ssm3.ssm_group_policy = 'test1' ssm3.ssm_source_addr = '3.3.3.3' igmp2.add_ssm(ssm3) ssm4 = Ssm(device=self.dev1) ssm4.ssm_group_policy = 'test1' ssm4.ssm_source_addr = '3.3.3.3' igmp2.add_ssm(ssm4) intf2_obj = Interface(device=self.dev1, name='GigabitEthernet0/0/0/3') intf2 = intf2_obj.name self.igmp.device_attr[self.dev1].vrf_attr[vrf2].interface_attr[intf2]\ .enable = True self.igmp.device_attr[self.dev1].vrf_attr[vrf2].interface_attr[intf2]\ .robustness_variable = 5 self.igmp.device_attr[self.dev1].vrf_attr[vrf2].interface_attr[intf2]\ .group_policy = 'test_policy' # join and static groups configuration igmp_intf1 = self.igmp.device_attr[ self.dev1].vrf_attr[vrf2].interface_attr[intf2] join_group = IgmpGroup(device=self.dev1) join_group.join_group = '239.3.3.3' join_group.join_group_source_addr = '1.1.1.1' static_group = IgmpGroup(device=self.dev1) static_group.static_group = '239.5.5.5' igmp_intf1.add_groups(join_group) igmp_intf1.add_groups(static_group) # Build igmp configuration cfgs = self.igmp.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router igmp', ' ssm map static 1.1.1.1 test', ' ssm map static 2.2.2.2 test', ' robustness-count 7', ' interface GigabitEthernet0/0/0/0', ' router enable', ' access-group test2', ' maximum groups-per-interface 10', ' query-interval 133', ' query-max-response-time 12', ' version 3', ' join-group 239.1.1.1', ' join-group 239.2.2.2', ' join-group 239.3.3.3 1.1.1.1', ' static-group 239.5.5.5', ' static-group 239.6.6.6 2.2.2.1', ' static-group 239.6.6.6 2.2.2.2', ' exit', ' vrf VRF1', ' ssm map static 3.3.3.3 test1', ' robustness-count 5', ' interface GigabitEthernet0/0/0/3', ' router enable', ' access-group test_policy', ' join-group 239.3.3.3 1.1.1.1', ' static-group 239.5.5.5', ' exit', ' exit', ' exit' ])) # Build unconfig cfgs = self.igmp.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual(str(cfgs[self.dev1.name]), '\n'.join([ 'no router igmp', ])) # Build unconfig with attribute cfgs = self.igmp.build_unconfig( apply=False, attributes={ 'device_attr': { self.dev1: { 'vrf_attr': { vrf1: { 'ssm': { ssm1: None } }, vrf2: { 'interface_attr': { 'GigabitEthernet0/0/0/3': { 'enable': True } } } } } } }) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'router igmp', ' no ssm map static 1.1.1.1 test', ' vrf VRF1', ' interface GigabitEthernet0/0/0/3', ' no router enable', ' exit', ' exit', ' exit' ]))
def test_cfg2(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') intf1 = Interface(device=dev1, name='Ethernet0/0/1', ipv4='10.1.0.1/24') intf2 = Interface(device=dev1, name='Ethernet0/0/2', ipv4='10.2.0.1/24') dev2 = Device(testbed=testbed, name='PE2', os='nxos') intf3 = Interface(device=dev2, name='Ethernet0/0/3', ipv4='10.1.0.2/24', ipv6='2001:111:222::/64') intf4 = Interface(device=dev2, name='Ethernet0/0/4', ipv4='10.2.0.2/24') 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,bgp_id=100) self.assertIs(bgp.testbed, testbed) Genie.testbed = testbed bgp = Bgp(asn=100,bgp_id=100) self.assertIs(bgp.testbed, Genie.testbed) self.assertIs(bgp.testbed, testbed) # Defining attributes vrf_id = 'vrf1' vrf1 = Vrf(vrf_id) pp_name = 'PEER-POLICY' ps_name = 'PEER-SESSION' bgp.device_attr[dev2].enabled = True bgp.device_attr[dev2].peer_policy_attr[pp_name].pp_allowas_in =\ True bgp.device_attr[dev2].peer_session_attr[ps_name].ps_fall_over_bfd=\ True bgp.device_attr[dev2].vrf_attr[None].cluster_id = '150' af_name = 'ipv6 unicast' bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name] bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_nexthop_route_map = 'test' bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_dampening = True bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_dampening_half_life_time = 1 bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_dampening_reuse_time = 10 bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_dampening_suppress_time = 30 bgp.device_attr[dev2].vrf_attr[None].address_family_attr[af_name].\ af_dampening_max_suppress_time = 2 neighbor_id = intf2.ipv4 bgp.device_attr[dev2].vrf_attr[vrf1].add_neighbor(neighbor_id) bgp.device_attr[dev2].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ nbr_suppress_four_byte_as_capability = True nbr_af_name = 'vpnv6 unicast' bgp.device_attr[dev2].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name] bgp.device_attr[dev2].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name].\ nbr_af_maximum_prefix_max_prefix_no = 300000 bgp.device_attr[dev2].vrf_attr[vrf1].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name].nbr_af_default_originate = True dev2.add_feature(bgp) cfgs = bgp.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev2.name]) self.maxDiff = None self.assertEqual(str(cfgs[dev2.name]), '\n'.join( ['feature bgp', 'router bgp 100', ' cluster-id 150', ' address-family ipv6 unicast', ' dampening 1 10 30 2', ' nexthop route-map test', ' exit', ' vrf vrf1', ' neighbor 10.2.0.1', ' capability suppress 4-byte-as', ' address-family vpnv6 unicast', ' maximum-prefix 300000', ' default-originate', ' exit', ' exit', ' exit', ' template peer-session PEER-SESSION', ' bfd', ' exit', ' template peer-policy PEER-POLICY', ' allowas-in', ' exit', ' exit', ])) partial_uncfg1 = bgp.build_unconfig(apply=False, attributes={\ 'device_attr':\ {dev2.name:\ {'vrf_attr':\ {'vrf1':\ {'neighbor_attr':\ {'10.2.0.1':\ {'address_family_attr':\ {'vpnv6 unicast':\ {'nbr_af_default_originate': None}}}}}}}}}) self.assertCountEqual(partial_uncfg1.keys(), [dev2.name]) self.assertMultiLineEqual(str(partial_uncfg1[dev2.name]), '\n'.\ join([ 'router bgp 100', ' vrf vrf1', ' neighbor 10.2.0.1', ' address-family vpnv6 unicast', ' no default-originate', ' exit', ' exit', ' exit', ' exit', ]))