def test_init(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxr') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1') intf2 = Interface(device=dev1, name='GigabitEthernet0/0/0/2') dev2 = Device(testbed=testbed, name='PE2', os='iosxr') intf3 = Interface(device=dev2, name='GigabitEthernet0/0/0/3') intf4 = Interface(device=dev2, name='GigabitEthernet0/0/0/4') with self.assertRaises(TypeError): evi1 = Evi() with self.assertRaises(TypeError): evi1 = Evi(device=dev1) with self.assertRaises(TypeError): evi1 = Evi(evi_id=1) with self.assertRaises(AssertionError): evi1 = Evi(device=dev1, evi_id=1) evpn = Evpn() self.assertSetEqual(evpn.evis, set()) dev2.add_feature(evpn) with self.assertRaises(AssertionError): evi1 = Evi(device=dev1, evi_id=1) dev1.add_feature(evpn) evi1 = Evi(device=dev1, evi_id=1) self.assertIs(evi1.testbed, testbed) self.assertIsInstance(evpn.evis, typedset) self.assertSetEqual(evpn.evis, set([evi1])) self.assertIs(type(evpn.device_attr[dev1].evis), types.GeneratorType) self.assertCountEqual(evpn.device_attr[dev1].evis, [evi1]) self.assertCountEqual(evpn.device_attr[dev2].evis, []) self.assertIsNotNone(evi1.bgp) with self.assertRaises(AttributeError): evi1.bgp = None self.assertIsNotNone(evi1.load_balancing) with self.assertRaises(AttributeError): evi1.load_balancing = None self.assertFalse(evi1.load_balancing.enabled) evpn.load_balancing.enabled = True self.assertTrue(evi1.load_balancing.enabled) with self.assertRaises(AttributeError): del evi1.load_balancing.enabled evi1.load_balancing.enabled = False self.assertFalse(evi1.load_balancing.enabled) del evi1.load_balancing.enabled self.assertTrue(evi1.load_balancing.enabled) cfgs = evpn.build_config(apply=False) self.assertDictEqual( cfgs, { dev1.name: '\n'.join([ 'evpn', ' evi 1', ' load-balancing', ' exit', ' exit', ' load-balancing', ' exit', ' exit', ]), dev2.name: '\n'.join([ 'evpn', ' load-balancing', ' exit', ' exit', ]), }) dev2.remove_feature(evpn) cfgs = evpn.build_config(apply=False) self.assertDictEqual( cfgs, { dev1.name: '\n'.join([ 'evpn', ' evi 1', ' load-balancing', ' exit', ' exit', ' load-balancing', ' exit', ' exit', ]), }) evi1.load_balancing.enabled = False cfgs = evpn.build_config(apply=False) self.assertDictEqual( cfgs, { dev1.name: '\n'.join([ 'evpn', ' evi 1', ' exit', ' load-balancing', ' exit', ' exit', ]), }) # XXXJST # cfg = evi1.build_config(apply=False) # self.assertMultiLineEqual(cfg, '\n'.join([ # 'evpn', # ' evi 1', # ' exit', # ' exit', # ])) cfg = evi1.build_config(apply=False) self.assertMultiLineEqual(str(cfg), '\n'.join([ 'evi 1', ' exit', ]))
def test_lisp_config(self): # For failures self.maxDiff = None # Set testbed Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') # Create Interface object intf1 = Interface(name='GigabitEthernet1', device=dev1) # Create LISP object lisp1 = Lisp() # DeviceAttributes # InterfaceAttributes lisp1.device_attr[dev1].intf_attr[ intf1].if_mobility_liveness_test_disabled = True # DeviceAttributes # InterfaceAttributes # MobilityDynamicEidAttributes lisp1.device_attr[dev1].intf_attr[intf1].mobility_dynamic_eid_attr[ 'wired'] lisp1.device_attr[dev1].intf_attr[intf1].mobility_dynamic_eid_attr[ 'wired_v6'] # DeviceAttributes # RouterInstanceAttributes lisp1.device_attr[dev1].router_instance_attr[0] # DeviceAttributes # RouterInstanceAttributes # LocatorSetAttributes lisp1.device_attr[dev1].router_instance_attr[0].locator_set_attr[ 'RLOC1'] lisp1.device_attr[dev1].router_instance_attr[0].locator_set_attr[ 'RLOC2'] lisp1.device_attr[dev1].router_instance_attr[0].locator_set_attr[ 'RLOC3'] # DeviceAttributes # RouterInstanceAttributes # LocatorSetAttributes # InterfaceAttributes # InterfaceTypeAttributes lisp1.device_attr[dev1].router_instance_attr[0].locator_set_attr[ 'RLOC1'].locator_set_intf_attr[ 'Loopback1'].locator_set_intf_type_attr[ 'ipv4'].ls_priority = 10 lisp1.device_attr[dev1].router_instance_attr[0].locator_set_attr[ 'RLOC1'].locator_set_intf_attr[ 'Loopback1'].locator_set_intf_type_attr['ipv4'].ls_weight = 30 lisp1.device_attr[dev1].router_instance_attr[0].locator_set_attr[ 'RLOC2'].locator_set_intf_attr[ 'Loopback2'].locator_set_intf_type_attr['ipv4'] lisp1.device_attr[dev1].router_instance_attr[0].locator_set_attr[ 'RLOC2'].locator_set_intf_attr[ 'Loopback3'].locator_set_intf_type_attr['ipv4'] lisp1.device_attr[dev1].router_instance_attr[0].locator_set_attr[ 'RLOC2'].locator_set_intf_attr[ 'Loopback4'].locator_set_intf_type_attr['ipv6'] # DeviceAttributes # RouterInstanceAttributes # ServiceAttributes lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv4'].itr_enabled = True lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv4'].etr_enabled = True lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv4'].proxy_etr_enabled = True lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv6'].ms_enabled = True lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv6'].mr_enabled = True lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv6'].encapsulation = 'vxlan' # DeviceAttributes # RouterInstanceAttributes # ServiceAttributes # ItrMrAttributes lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv4'].itr_mr_attr['4.4.4.4'] lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv4'].itr_mr_attr['13.13.13.13'] lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv4'].itr_mr_attr['16.16.16.16'] # DeviceAttributes # RouterInstanceAttributes # ServiceAttributes # EtrMsAttributes lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv6'].etr_ms_attr['4.4.4.4'].etr_auth_key = 'cisco123' lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv6'].etr_ms_attr['4.4.4.4'].etr_proxy_reply = True lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv4'].etr_ms_attr['5.5.5.5'].etr_auth_key = 'roZes123' lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv4'].etr_ms_attr['5.5.5.5'].etr_auth_key_type = 'hmac-sha-1-96' lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv6'].etr_ms_attr['6.6.6.6'].etr_auth_key = 'test123' lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv6'].etr_ms_attr[ '6.6.6.6'].etr_auth_key_type = 'hmac-sha-256-128' # DeviceAttributes # RouterInstanceAttributes # ServiceAttributes # ProxyItrAttributes lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv6'].proxy_attr['10.10.10.10'] lisp1.device_attr[dev1].router_instance_attr[0].service_attr[ 'ipv6'].proxy_attr['20.20.20.20'] # DeviceAttributes # RouterInstanceAttributes # InstanceAttributes # DynamicEidAttributes # DbMappingAttributes lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].dynamic_eid_attr['192'].db_mapping_attr['172.168.0.0/24'] lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].dynamic_eid_attr['192'].db_mapping_attr[ '192.168.0.0/24'].etr_dyn_eid_rlocs = 'RLOC' # DeviceAttributes # RouterInstanceAttributes # InstanceAttributes # ServiceAttributes lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv4'] lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv6'].etr_eid_vrf = 'red' # DeviceAttributes # RouterInstanceAttributes # InstanceAttributes # ServiceAttributes # DbMappingAttributes lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv4'].service_db_mapping_attr[ '172.168.0.0/24'] lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv6'].service_db_mapping_attr[ '192.168.0.0/24'].etr_eid_rlocs = 'RLOC2' # DeviceAttributes # RouterInstanceAttributes # InstanceAttributes # ServiceAttributes # UsePetrAttributes lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv4'].use_petr_attr[ '15.15.15.15'].etr_use_petr_priority = 10 lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv4'].use_petr_attr[ '15.15.15.15'].etr_use_petr_weight = 20 lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv4'].use_petr_attr[ '16.16.16.16'].etr_use_petr_priority = 20 lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv4'].use_petr_attr[ '16.16.16.16'].etr_use_petr_weight = 50 lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv6'].use_petr_attr[ '22.22.22.22'].etr_use_petr_priority = 20 lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv6'].use_petr_attr[ '22.22.22.22'].etr_use_petr_weight = 30 lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv6'].use_petr_attr[ '13.13.13.13'].etr_use_petr_priority = 30 lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv6'].use_petr_attr[ '13.13.13.13'].etr_use_petr_weight = 60 # DeviceAttributes # RouterInstanceAttributes # InstanceAttributes # ServiceAttributes # MapCacheAttributes lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv4'].map_cache_attr['10.1.1.0/24'] lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv6'].map_cache_attr['12.1.1.0/24'] lisp1.device_attr[dev1].router_instance_attr[0].instance_id_attr[ '101'].inst_service_attr['ipv6'].map_cache_attr[ '20.1.1.0/24'].itr_mc_map_request = True # DeviceAttributes # RouterInstanceAttributes # SiteAttributes lisp1.device_attr[dev1].router_instance_attr[0].site_attr['xtr1'] lisp1.device_attr[dev1].router_instance_attr[0].site_attr[ 'xtr2'].ms_site_auth_key = 'cisco123' # DeviceAttributes # RouterInstanceAttributes # SiteAttributes # InstanceIdAttributes # EidRecordAttributes lisp1.device_attr[dev1].router_instance_attr[0].site_attr[ 'xtr1'].site_inst_id_attr['101'].eid_record_attr['88.88.88.0/24'] lisp1.device_attr[dev1].router_instance_attr[0].site_attr[ 'xtr1'].site_inst_id_attr['102'].eid_record_attr[ '89.89.89.0/24'].ms_eid_accept_more_specifics = True # DeviceAttributes # RouterInstanceAttributes # ExtranetAttributes lisp1.device_attr[dev1].router_instance_attr[0].extranet_attr[ 'ext1'].extranet_inst_id_attr['101'].eid_record_provider_attr[ '5.5.5.0/24'].ms_extranet_provider_bidir = True lisp1.device_attr[dev1].router_instance_attr[0].extranet_attr[ 'ext1'].extranet_inst_id_attr['101'].eid_record_subscriber_attr[ '6.6.6.0/24'].ms_extranet_subscriber_bidir = True lisp1.device_attr[dev1].router_instance_attr[0].extranet_attr[ 'ext2'].extranet_inst_id_attr['102'].eid_record_subscriber_attr[ '7.7.7.0/24'] lisp1.device_attr[dev1].router_instance_attr[0].extranet_attr[ 'ext2'].extranet_inst_id_attr['102'].eid_record_subscriber_attr[ '8.8.8.0/24'].ms_extranet_subscriber_bidir = True # Add LISP to the device dev1.add_feature(lisp1) # Build config cfgs = lisp1.build_config(apply=False) # Check config strings built correctly self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'interface GigabitEthernet1', ' no lisp mobility liveness test', ' lisp mobility wired', ' lisp mobility wired_v6', ' exit', 'router lisp 0', ' locator-set RLOC1', ' IPv4-interface Loopback1 priority 10 weight 30', ' exit', ' locator-set RLOC2', ' IPv4-interface Loopback2', ' IPv4-interface Loopback3', ' IPv6-interface Loopback4', ' exit', ' locator-set RLOC3', ' exit', ' service ipv4', ' itr', ' etr', ' proxy-etr', ' encapsulation lisp', ' itr map-resolver 13.13.13.13', ' itr map-resolver 16.16.16.16', ' itr map-resolver 4.4.4.4', ' etr map-resolver 5.5.5.5 key roZes123 hash-function sha1', ' exit', ' service ipv6', ' map-server', ' map-resolver', ' encapsulation vxlan', ' etr map-resolver 4.4.4.4 key cisco123', ' etr map-resolver 4.4.4.4 proxy-reply', ' etr map-resolver 6.6.6.6 key test123 hash-function sha2', ' proxy-itr 10.10.10.10', ' proxy-itr 20.20.20.20', ' exit', ' instance-id 101', ' dynamic-eid 192', ' datbase-mapping 172.168.0.0/24', ' datbase-mapping 192.168.0.0/24 locator-set RLOC', ' exit', ' service ipv4', ' eid-table default', ' datbase-mapping 172.168.0.0/24', ' use-petr 15.15.15.15 instance-id 101 priority 10 weight 20', ' use-petr 16.16.16.16 instance-id 101 priority 20 weight 50', ' map-cache 10.1.1.0/24', ' exit', ' service ipv6', ' eid-table vrf red', ' datbase-mapping 192.168.0.0/24 locator-set RLOC2', ' use-petr 13.13.13.13 instance-id 101 priority 30 weight 60', ' use-petr 22.22.22.22 instance-id 101 priority 20 weight 30', ' map-cache 12.1.1.0/24', ' map-cache 20.1.1.0/24 map-request', ' exit', ' exit', ' site xtr1', ' eid-record instance-id 101 88.88.88.0/24', ' eid-record instance-id 102 89.89.89.0/24 accept-more-specifics', ' exit', ' site xtr2', ' authentication-key cisco123', ' exit', ' extranet ext1', ' eid-record-provider instance-id 101 5.5.5.0/24 bidirectional', ' eid-record-subscriber instance-id 101 6.6.6.0/24 bidirectional', ' exit', ' extranet ext2', ' eid-record-subscriber instance-id 102 7.7.7.0/24', ' eid-record-subscriber instance-id 102 8.8.8.0/24 bidirectional', ' exit', ' exit', ])) # Unconfig lisp_uncfg = lisp1.build_unconfig(apply=False) # Check unconfig strings built correctly self.assertMultiLineEqual( str(lisp_uncfg[dev1.name]), '\n'.join([ 'interface GigabitEthernet1', ' lisp mobility liveness test', ' no lisp mobility wired', ' no lisp mobility wired_v6', ' exit', 'no router lisp 0', ]))
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_cfg(self): tb = Genie.testbed = Testbed() dev = Device(testbed=tb, name='PE1', os='nxos') rip = Rip(instance_id=1) rip.add_force_vrf(None) dev.add_feature(rip) rip.device_attr['PE1'] output = rip.build_config(apply=False) self.assertMultiLineDictEqual(output, {'PE1': 'feature rip\n' 'router rip 1\n' ' address-family ipv4 unicast\n' ' exit\n' ' exit' }) vrf1 = Vrf('vrf1') intf1 = Interface(device=dev, name='Ethernet0/0', vrf=vrf1) intf1.add_feature(rip) rip.address_families |= {AddressFamily.ipv6_unicast} rip.shutdown = False rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].maximum_paths = 2 rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].default_metric = 1 rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].distance = 120 rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_direct_rmap\ = 'rmap1' rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_static_rmap\ = 'rmap2' rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv4 unicast'].redistribute_lisp_rmap\ = 'rmap3' rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].maximum_paths = 7 rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].default_metric = 3 rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].distance = 120 rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_direct_rmap\ = 'rmap4' rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_static_rmap\ = 'rmap5' rip.device_attr['PE1'].vrf_attr[None].address_family_attr['ipv6 unicast'].redistribute_lisp_rmap\ = 'rmap6' rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\ maximum_paths = 10 rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\ default_metric = 7 rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\ distance = 127 rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\ redistribute_direct_rmap = 'rmap14' rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\ redistribute_static_rmap = 'rmap15' rip.device_attr['PE1'].vrf_attr['vrf1'].address_family_attr['ipv6 unicast'].\ redistribute_lisp_rmap = 'rmap16' # rip.build_config(apply=False) output = rip.build_config(apply=False) expected_output = {'PE1': '''\ router rip 1 no shutdown address-family ipv4 unicast default-metric 1 distance 120 maximum-paths 2 redistribute lisp route-map rmap3 redistribute direct route-map rmap1 redistribute static route-map rmap2 exit address-family ipv6 unicast default-metric 3 distance 120 maximum-paths 7 redistribute lisp route-map rmap6 redistribute direct route-map rmap4 redistribute static route-map rmap5 exit vrf vrf1 address-family ipv4 unicast exit address-family ipv6 unicast default-metric 7 distance 127 maximum-paths 10 redistribute lisp route-map rmap16 redistribute direct route-map rmap14 redistribute static route-map rmap15 exit exit exit'''} self.maxDiff = None self.assertMultiLineDictEqual(output, expected_output) # Set a mock dev.cli = Mock() dev.configure = Mock() dev.add_feature(rip) # Mock config output = rip.build_config(apply=True)
def test_EthernetInterface(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') dev2 = Device(testbed=testbed, name='P1', os='nxos') intf1 = Interface(name='Ethernet0/0/1', device=dev1) intf2 = Interface(name='Ethernet0/0/2', device=dev2) # Defining attributes section intf1.ipv4 = '201.0.12.1' intf1.ipv4.netmask = '255.255.255.0' intf1.speed = 1000 intf1.shutdown = False # make intf1 as L3 interface intf1.switchport_enable = False intf1.mtu = 500 intf1.ipv6 = '2001::12:1' cfg = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg), '\n'.join([ 'interface Ethernet0/0/1', ' mtu 500', ' no shutdown', ' no switchport', ' ip address 201.0.12.1 255.255.255.0', ' ipv6 address 2001::12:1/128', ' speed 1000', ' exit', ])) uncfg = intf1.build_unconfig(apply=False, attributes={ 'ipv6': True, 'ipv4': True }) self.assertMultiLineEqual( str(uncfg), '\n'.join([ 'interface Ethernet0/0/1', ' no ip address', ' no ipv6 address', ' exit', ])) partial_uncfg = intf1.build_unconfig(apply=False, attributes="mtu") self.assertMultiLineEqual( str(partial_uncfg), '\n'.join([ 'interface Ethernet0/0/1', ' no mtu', ' exit', ])) # make intf2 as L2 interface intf2.switchport_enable = True intf2.switchport_mode = L2_type.TRUNK intf2.sw_trunk_allowed_vlan = '200-201' cfg2 = intf2.build_config(apply=False) self.assertMultiLineEqual( str(cfg2), '\n'.join([ 'interface Ethernet0/0/2', ' switchport', ' switchport mode trunk', ' switchport trunk allowed vlan 200-201', ' exit', ]))
def test_basic_uncfg(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxr') dev2 = Device(testbed=testbed, name='PE2', os='iosxr') intf1 = Interface(name='GigabitEthernet0/0/1', device=dev1) intf2 = Interface(name='GigabitEthernet0/0/2', device=dev2) intf3 = Interface(name='GigabitEthernet0/0/3', device=dev1) link = Link(name='1_2_1', testbed=testbed) link.connect_interface(interface=intf1) link.connect_interface(interface=intf2) vlan = Vlan() link.add_feature(vlan) # Defining attributes section vlan.device_attr[dev1] vlan.device_attr[dev2] vlan.device_attr[dev1].interface_attr[intf1] vlan.device_attr[dev1].interface_attr[intf1].eth_encap_type1 = 'dot1q' vlan.device_attr[dev1].interface_attr[intf1].eth_encap_val1 = 2 vlan.device_attr[dev1].interface_attr[ intf1].eth_encap_type2 = 'second-dot1q' vlan.device_attr[dev1].interface_attr[intf1].eth_encap_val2 = 5 # Unconfig testing # Set a mock dev1.cli = Mock() dev1.configure = Mock() dev2.cli = Mock() dev2.configure = Mock() dev1.add_feature(vlan) dev2.add_feature(vlan) # Mock config output = vlan.build_config(apply=True) uncfg = vlan.build_unconfig(apply=False) self.assertMultiLineEqual( str(uncfg['PE1']), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no encapsulation dot1q 2 second-dot1q 5', ' exit', ])) all_vlan_interface_uncfg = vlan.build_unconfig(apply=False, attributes={'device_attr':\ {'*':{'interface_attr':'*'}}}) self.assertCountEqual(all_vlan_interface_uncfg.keys(), ['PE1', 'PE2']) self.assertMultiLineEqual( str(all_vlan_interface_uncfg['PE1']), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no encapsulation dot1q 2 second-dot1q 5', ' exit', ])) partial_vlan_interface_uncfg = vlan.build_unconfig(apply=False, attributes={'device_attr':\ {'*':{'interface_attr':\ {'*':"eth_encap_type1"}}}}) self.assertCountEqual(partial_vlan_interface_uncfg.keys(), ['PE1', 'PE2']) self.assertMultiLineEqual( str(partial_vlan_interface_uncfg['PE1']), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no encapsulation dot1q 2 second-dot1q 5', ' exit', ]))
def test_basic_uncfg(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') dev2 = Device(testbed=testbed, name='PE2', os='nxos') intf1 = Interface(name='Ethernet0/0/1', device=dev1, layer=Layer.L3) intf2 = Interface(name='Ethernet0/0/2', device=dev2, layer=Layer.L2) link = Link(name='1_2_1', testbed=testbed) link.connect_interface(interface=intf1) link.connect_interface(interface=intf2) vlan = Vlan() link.add_feature(vlan) vlan.vlan_id = 100 access_map_id = 'ed' vlan_configuration_id = '3' vlan.device_attr[dev1] vlan.device_attr[dev2] vlan.device_attr[dev1].access_map_attr[access_map_id] vlan.device_attr[dev2].access_map_attr[access_map_id] vlan.device_attr[dev1].interface_attr[intf1] vlan.device_attr[dev2].interface_attr[intf2] vlan.device_attr[dev2].interface_attr[intf2].switchport_mode = \ L2_type.TRUNK vlan.device_attr[dev2].interface_attr[intf2].sw_trunk_allowed_vlan = \ '200-201' vlan.device_attr[dev1].vlan_configuration_attr[vlan_configuration_id] vlan.device_attr[dev2].vlan_configuration_attr[vlan_configuration_id] # Defining attributes section vlan.shutdown = False with self.assertRaises(ValueError): vlan.media = 'invalid' vlan.media = 'enet' self.assertIs(type(vlan.media), Vlan.Media) vlan.egress_port_channel_load_balance_random = True vlan.device_attr[dev1].access_map_action = 'drop' vlan.datalink_flow_monitor = True # Unconfig testing # Set a mock dev1.cli = Mock() dev1.configure = Mock() dev2.cli = Mock() dev2.configure = Mock() dev1.add_feature(vlan) dev2.add_feature(vlan) # Mock config output = vlan.build_config(apply=True) uncfg1 = vlan.build_unconfig(apply=False) self.assertCountEqual(uncfg1.keys(), ['PE1', 'PE2']) self.assertMultiLineEqual( str(uncfg1['PE1']), '\n'.join([ 'no vlan 100', 'no vlan access-map ed', 'no vlan configuration 3', ])) self.assertMultiLineEqual( str(uncfg1['PE2']), '\n'.join([ 'no vlan 100', 'no vlan access-map ed', 'no vlan configuration 3', 'interface Ethernet0/0/2', ' no switchport mode trunk', ' no switchport trunk allowed vlan 200-201', ' exit', ])) partial_uncfg1 = vlan.build_unconfig(apply=False, attributes={'device_attr': \ {'*': "media"}}) self.assertCountEqual(partial_uncfg1.keys(), ['PE1', 'PE2']) self.assertMultiLineEqual( str(partial_uncfg1['PE1']), '\n'.join([ 'vlan 100', ' no media enet', ' exit', ])) partial_unconfigure = vlan.build_unconfig(apply=False, attributes={'device_attr': \ {'*': {'access_map_attr': \ {'*': "access_map_action"}}}}) self.assertCountEqual(partial_unconfigure.keys(), ['PE1', 'PE2']) self.assertMultiLineEqual( str(partial_unconfigure['PE1']), '\n'.join([ 'vlan access-map ed', ' no action drop', ' exit', ])) all_vlan_interface_uncfg = vlan.build_unconfig(apply=False, attributes={ \ 'device_attr': {'*': { \ 'interface_attr': '*'}}}) self.assertCountEqual(all_vlan_interface_uncfg.keys(), ['PE1', 'PE2']) self.assertMultiLineEqual( str(all_vlan_interface_uncfg['PE2']), '\n'.join([ 'interface Ethernet0/0/2', ' no switchport mode trunk', ' no switchport trunk allowed vlan 200-201', ' exit', ])) partial_vlan_interface_uncfg = vlan.build_unconfig(apply=False, attributes={ \ 'device_attr': {'*': \ {'interface_attr': \ { '*': "sw_trunk_allowed_vlan"}}}}) self.assertCountEqual(partial_vlan_interface_uncfg.keys(), ['PE1', 'PE2']) self.assertMultiLineEqual( str(partial_vlan_interface_uncfg['PE2']), '\n'.join([ 'interface Ethernet0/0/2', ' no switchport trunk allowed vlan 200-201', ' 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 = testbed 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', ]))
def test_ospf_config1(self): # 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_init(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxr') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1') intf2 = Interface(device=dev1, name='GigabitEthernet0/0/0/2') dev2 = Device(testbed=testbed, name='PE2', os='iosxr') intf3 = Interface(device=dev2, name='GigabitEthernet0/0/0/3') intf4 = Interface(device=dev2, name='GigabitEthernet0/0/0/4') Genie.testbed = None with self.assertRaises(TypeError): l2vpn = L2vpn() l2vpn = L2vpn(testbed=testbed) self.assertIs(l2vpn.testbed, testbed) Genie.testbed = testbed l2vpn = L2vpn() self.assertIs(l2vpn.testbed, testbed) self.assertIsNone(getattr(dev1, 'l2vpn', None)) dev1.add_feature(l2vpn) self.assertIs(dev1.l2vpn, l2vpn) cfgs = l2vpn.build_config(apply=False) self.assertMultiLineDictEqual( cfgs, { dev1.name: '\n'.join([ 'l2vpn', ' exit', ]), }) dev2.add_feature(l2vpn) self.assertIs(dev2.l2vpn, l2vpn) cfgs = l2vpn.build_config(apply=False) self.assertMultiLineDictEqual( cfgs, { dev1.name: '\n'.join([ 'l2vpn', ' exit', ]), dev2.name: '\n'.join([ 'l2vpn', ' exit', ]), }) l2vpn.device_attr[dev1].router_id = '100.0.0.1' l2vpn.device_attr[dev2].router_id = '100.0.0.2' #l2vpn.recovery_timer = 100 #l2vpn.device_attr[dev1].recovery_timer = 200 #l2vpn.peering_timer = 300 cfgs = l2vpn.build_config(apply=False) self.assertMultiLineDictEqual( cfgs, { dev1.name: '\n'.join([ 'l2vpn', ' router-id 100.0.0.1', ' exit', ]), dev2.name: '\n'.join([ 'l2vpn', ' router-id 100.0.0.2', ' exit', ]), })
def test_cfg(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 = testbed 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 af_name = 'vpnv4 unicast' af_name2 = 'link-state' bgp.device_attr[dev1] bgp.device_attr[dev1].enabled = True bgp.device_attr[dev1].vrf_attr[None].always_compare_med = True bgp.device_attr[dev1].vrf_attr[None].maxas_limit = 10 bgp.device_attr[dev1].vrf_attr[None].prefix_peer_timeout = 10 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_default_metric = True bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name]\ .af_default_metric_value = 0 bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name]\ .af_advertise_l2_evpn = True bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name] \ .af_default_information_originate = True neighbor_id = intf4.ipv4 bgp.device_attr[dev1].vrf_attr[None].add_neighbor(neighbor_id) bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id] bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id]. \ nbr_fall_over_bfd = True bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id]. \ nbr_shutdown = True nbr_af_name = 'ipv4 unicast' bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id]. \ address_family_attr[nbr_af_name] bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id]. \ address_family_attr[nbr_af_name].nbr_af_allowas_in = True bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id]. \ address_family_attr[nbr_af_name].nbr_af_suppress_inactive = True dev1.add_feature(bgp) cfgs = bgp.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'feature bgp', 'router bgp 100', ' bestpath always-compare-med', ' maxas-limit 10', ' timers prefix-peer-timeout 10', ' neighbor 10.2.0.2', ' bfd', ' shutdown', ' address-family ipv4 unicast', ' allowas-in', ' suppress-inactive', ' exit', ' exit', ' address-family link-state', ' exit', ' address-family vpnv4 unicast', ' default-metric 0', ' default-information originate', ' dampening', ' retain route-target all', ' advertise l2vpn evpn', ' exit', ' exit', ])) bgp.device_attr[dev1].protocol_shutdown = True partial_cfg1 = bgp.build_config( apply=False, attributes={'device_attr': \ {'*': "enabled", '*': "protocol_shutdown"}}) self.assertCountEqual(partial_cfg1.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_cfg1[dev1.name]), '\n'. \ join([ 'router bgp 100', ' shutdown', ' exit', ]))
def test_init(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxr') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1') intf2 = Interface(device=dev1, name='GigabitEthernet0/0/0/2') dev2 = Device(testbed=testbed, name='PE2', os='iosxr') intf3 = Interface(device=dev2, name='GigabitEthernet0/0/0/3') intf4 = Interface(device=dev2, name='GigabitEthernet0/0/0/4') link1 = Link(testbed=testbed, name='link1', interfaces=(intf1, intf3)) link2 = Link(testbed=testbed, name='link2', interfaces=(intf2, intf4)) with self.assertRaises(TypeError): bd1 = BridgeDomain() with self.assertRaises(TypeError): bd1 = BridgeDomain(group_name='bg1') bd1 = BridgeDomain(name='bd1', group_name='mybg1') self.assertEqual(bd1.name, 'bd1') self.assertEqual(bd1.group_name, 'mybg1') bd1 = BridgeDomain(name='bd1') self.assertEqual(bd1.name, 'bd1') self.assertEqual(bd1.group_name, 'bd1g') self.assertCountEqual(bd1.devices, []) self.assertCountEqual(bd1.interfaces, []) self.assertCountEqual(bd1.vnis, []) self.assertCountEqual(bd1.vfis, []) self.assertCountEqual(bd1.evis, []) self.assertCountEqual(bd1.segments, []) self.assertCountEqual(bd1.link.interfaces, []) dev1.add_feature(bd1) self.assertCountEqual(bd1.devices, [dev1]) self.assertCountEqual(bd1.interfaces, []) self.assertCountEqual(bd1.vnis, []) self.assertCountEqual(bd1.vfis, []) self.assertCountEqual(bd1.evis, []) self.assertCountEqual(bd1.segments, []) self.assertCountEqual(bd1.link.interfaces, []) cfgs = bd1.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'l2vpn', ' bridge group bd1g', ' bridge-domain bd1', ' exit', ' exit', ' exit', ])) bd1.add_interface(intf1) intf1.l2transport.enabled = True self.assertCountEqual(bd1.interfaces, [intf1]) self.assertCountEqual(bd1.devices, [dev1]) self.assertCountEqual(bd1.vnis, []) self.assertCountEqual(bd1.vfis, []) self.assertCountEqual(bd1.evis, []) self.assertCountEqual(bd1.segments, [intf1]) # Links under Genie Interface object is deprecated # Placed the below workaround to bypass the Unittest (commented out) # self.assertCountEqual(bd1.link.interfaces, [intf3]) self.assertCountEqual(bd1.device_attr[dev1].interfaces, [intf1]) self.assertCountEqual(bd1.device_attr[dev2].interfaces, []) self.assertCountEqual(bd1.device_attr[dev1].segments, [intf1]) self.assertCountEqual(bd1.device_attr[dev2].segments, []) cfgs = bd1.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.assertMultiLineEqual( str(cfgs[dev1.name]), '\n'.join([ 'l2vpn', ' bridge group bd1g', ' bridge-domain bd1', ' interface GigabitEthernet0/0/0/1', ' exit', ' exit', ' exit', ' exit', ]))
def create_new_device(self, testbed, device_data, proxy_set, device_name): '''Create a new device object based on given data to add to testbed Args: testbed ('testbed'): testbed that new device will be added to device_data ('dict'): information about device to be created proxy_set ('list'): set of proxies used by other devices in testbed device_name ('str'): name of device that is being created Returns: new device object to be added to testbed ''' # filter to strip out the numbers from an interface to create a type name # example: ethernet0/3 becomes ethernet interface_filter = re.compile(r'[a-zA-Z]+') connections = {} # get credentials of finder device to use as new device credentials finder = device_data['finder'] finder_dev = testbed.devices[finder[0]] credentials = finder_dev.credentials if self._telnet_connect: protocol = 'telnet' else: protocol = 'ssh' if self._cred_prompt: credentials = self._prompt_credentials(device_name) # create connections for the management addresses in the device list for count, ip in enumerate(device_data['ip']): if self.validIPAddress(ip): if count == 0: for proxy in proxy_set: # create connection using possible proxies connections[proxy] = { 'protocol': protocol, 'ip': ip, 'proxy': proxy } connections['default'] = {'protocol': protocol, 'ip': ip} else: for proxy in proxy_set: # create connection using possible proxies connections['Variant {} {}'.format(count, proxy)] = { 'protocol': protocol, 'ip': ip, 'proxy': proxy } connections['Variant {}'.format(count)] = { 'protocol': protocol, 'ip': ip } # if there is an interface ip, create a proxy connection # using the discovery device if device_data['finder'][1] and self.validIPAddress( device_data['finder'][1]): for ip in device_data['finder'][1]: finder_proxy = self.write_proxy_chain(finder[0], testbed, credentials, ip) connections['finder_proxy'] = { 'protocol': protocol, 'ip': ip, 'proxy': finder_proxy } # create the new device dev_obj = Device(device_name, os=device_data['os'], credentials=credentials, type='device', connections=connections, custom={'abstraction': { 'order': ['os'] }}) # create and add the interfaces for the new device for interface in device_data['ports']: type_name = interface_filter.match(interface) interface_a = Interface(interface, type=type_name[0].lower()) interface_a.device = dev_obj return dev_obj
def test_basic_uncfg(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) intf3 = Interface(name='Vlan100', device=dev1) vlan = Vlan() for dev in testbed.devices: dev.connections = Mock() dev.connections = {'netconf': NetconfConnectionInfo()} vlan.device_attr[dev1].vlan_id = 100 vlan.device_attr[dev2].vlan_id = 300 # Unconfig testing # Set a mock dev1.configure = Mock() dev2.configure = Mock() dev1.add_feature(vlan) dev2.add_feature(vlan) # Mock config uncfg1 = vlan.build_unconfig(apply=False) self.assertCountEqual(uncfg1.keys(), ['PE1', 'PE2']) compare = "" for i in uncfg1['PE1']: compare += str(i) # A case has been already raised by JB so the unconfig for yang works as expected. # Currently, retruned xml for yang unconfig is exactly the same for the unconfig one. self.assertMultiLineEqual( compare, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <vlan xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <vlan-list xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-vlan">\n' ' <id>100</id>\n' ' </vlan-list>\n' ' </vlan>\n' ' </config>\n' '</edit-config>\n' ])) compare = "" for i in uncfg1['PE2']: compare += str(i) self.assertMultiLineEqual( compare, '\n'.join([ '<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">\n' ' <target>\n' ' <running></running>\n' ' </target>\n' ' <config>\n' ' <vlan xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">\n' ' <vlan-list xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-vlan">\n' ' <id>300</id>\n' ' </vlan-list>\n' ' </vlan>\n' ' </config>\n' '</edit-config>\n' ]))
def test_uncfg(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') 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='iosxe') 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 = testbed bgp = Bgp(bgp_id=100) self.assertIs(bgp.testbed, testbed) Genie.testbed = testbed bgp = Bgp(bgp_id=100) self.assertIs(bgp.testbed, Genie.testbed) self.assertIs(bgp.testbed, testbed) dev1.add_feature(bgp) uncfgs = bgp.build_unconfig(apply=False) self.assertCountEqual(uncfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(uncfgs[dev1.name]), '\n'.join([ 'no router bgp 100', ])) # 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_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 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 bgp 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 bgp always-compare-med', ' no address-family link-state', ' no address-family vpnv4 unicast', ' no neighbor 10.2.0.2', ' no address-family ipv4 unicast vrf vrf1', ' exit', ])) partial_uncfg3 = bgp.build_unconfig( apply=False, attributes={'device_attr':\ {'*': {'vrf_attr':\ {'*': {'neighbor_attr':\ {'*':"nbr_fall_over_bfd"}}}}}}) self.assertCountEqual(partial_uncfg3.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg3[dev1.name]), '\n'.\ join([ 'router bgp 100', ' address-family ipv4 unicast vrf vrf1', ' no neighbor 10.2.0.2 fall-over bfd', ' exit', ' exit', ])) # Defining neighbor address family 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_uncfg4 = bgp.build_unconfig( apply=False, attributes={'device_attr': {'*': {'vrf_attr': {'*': {'neighbor_attr':\ {'*': {'address_family_attr':\ {'*':"nbr_af_allowas_in"}}}}}}}}) self.assertCountEqual(partial_uncfg4.keys(), [dev1.name]) self.assertMultiLineEqual(str(partial_uncfg4[dev1.name]), '\n'.\ join([ 'router bgp 100', ' address-family ipv4 unicast vrf vrf1', ' no neighbor 10.2.0.2 activate', ' no neighbor 10.2.0.2 allowas-in', ' exit', ' 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 bgp dampening', ' exit', ' exit', ]))
def test_InterfaceSwitchport(self): Genie.testbed = Testbed() dev1 = Device(name='PE1', os='iosxe') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/1') # Do not set switchport - default # Check config cfg1 = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg1), '\n'.join([ 'interface GigabitEthernet0/0/1', ' exit', ])) # Set switchport to True intf1.switchport = True # Check config cfg2 = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg2), '\n'.join([ 'interface GigabitEthernet0/0/1', ' switchport', ' exit', ])) # Check unconfig uncfg2 = intf1.build_unconfig(apply=False, attributes="switchport") self.assertMultiLineEqual( str(uncfg2), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no switchport', ' exit', ])) # Set switchport to False intf1.switchport = False # Check config cfg3 = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg3), '\n'.join([ 'interface GigabitEthernet0/0/1', ' no switchport', ' exit', ])) # Check unconfig uncfg3 = intf1.build_unconfig(apply=False, attributes="switchport") self.assertMultiLineEqual( str(uncfg3), '\n'.join([ 'interface GigabitEthernet0/0/1', ' switchport', ' exit', ])) # test full switchport related configuration intf1.switchport_enable = True intf1.switchport_mode = "access" intf1.access_vlan = "100" intf1.trunk_vlans = "all" intf1.trunk_add_vlans = "100" intf1.trunk_remove_vlans = "100-200" intf1.native_vlan = "1" cfg1 = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg1), '\n'.join([ 'interface GigabitEthernet0/0/1', ' switchport', ' switchport mode access', ' switchport trunk allowed vlan all', ' switchport trunk native vlan 1', ' switchport access vlan 100', ' switchport trunk allowed vlan add 100', ' switchport trunk allowed vlan remove 100-200', ' exit', ]))
def test_mcast_config(self): # For failures self.maxDiff = None # VRF configuration vrf1 = Vrf('VRF1') self.mld.device_attr[self.dev1].require_router_alert = True mld1 = self.mld.device_attr[self.dev1].vrf_attr[vrf1] ssm1 = Ssm(device=self.dev1) ssm1.ssm_group_range = 'ff31::1/128' ssm1.ssm_source_addr = '2001:db8:1:1::1' mld1.add_ssm(ssm1) ssm2 = Ssm(device=self.dev1) ssm2.ssm_group_range = 'ff32::1/128' ssm2.ssm_source_addr = '2001:db8:1:1::1' mld1.add_ssm(ssm2) # Interface configuration intf1_obj = Interface(device=self.dev1, name='Ethernet2/2') intf1_obj.vrf = vrf1 intf1 = intf1_obj.name self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .enable = True self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .robustness_variable = 7 self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .group_policy = 'test2' self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .immediate_leave = True self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .max_groups = 6400 self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .query_interval = 366 self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .query_max_response_time = 15 self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .version = 2 # join and static groups configuration mld_intf1 = self.mld.device_attr[ self.dev1].vrf_attr[vrf1].interface_attr[intf1] join_group1 = MldGroup(device=self.dev1) join_group1.join_group = 'fffe::1' join_group2 = MldGroup(device=self.dev1) join_group2.join_group = 'ff30::1' join_group2.join_group_source_addr = '2001:db8:0:abcd::1' static_group1 = MldGroup(device=self.dev1) static_group1.static_group = 'fffe::2' static_group2 = MldGroup(device=self.dev1) static_group2.static_group = 'ff30::2' static_group2.static_group_source_addr = '2001:db8:0:abcd::2' mld_intf1.add_groups(join_group1) mld_intf1.add_groups(join_group2) mld_intf1.add_groups(static_group1) mld_intf1.add_groups(static_group2) vrf2 = Vrf('default') mld2 = self.mld.device_attr[self.dev1].vrf_attr[vrf2] ssm1 = Ssm(device=self.dev1) ssm1.ssm_group_range = 'ff31::1/128' ssm1.ssm_source_addr = '2001:db8:1:1::1' mld2.add_ssm(ssm1) ssm2 = Ssm(device=self.dev1) ssm2.ssm_group_range = 'ff31::1/128' ssm2.ssm_source_addr = '2001:db8:1:1::2' mld2.add_ssm(ssm2) # Interface configuration intf2_obj = Interface(device=self.dev1, name='Ethernet2/1') ipv6a = IPv6Addr(device=self.dev1) ipv6a.ipv6 = '2001:db1:1:1::1' ipv6a.ipv6_prefix_length = '64' intf2_obj.add_ipv6addr(ipv6a) intf2 = intf2_obj.name self.mld.device_attr[self.dev1].vrf_attr[vrf2].interface_attr[intf2]\ .enable = True # join and static groups configuration mld_intf1 = self.mld.device_attr[ self.dev1].vrf_attr[vrf2].interface_attr[intf2] join_group = MldGroup(device=self.dev1) join_group.join_group = 'ff30::1' join_group.join_group_source_addr = '2001:db8:0:abcd::1' static_group = MldGroup(device=self.dev1) static_group.static_group = 'fffe::2' mld_intf1.add_groups(join_group) mld_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/2', ' vrf member VRF1', ' exit', ])) intf_cfgs = intf2_obj.build_config(apply=False) self.assertMultiLineEqual( str(intf_cfgs), '\n'.join([ 'interface Ethernet2/1', ' ipv6 address 2001:db1:1:1::1/64', ' exit', ])) # Build mld configuration cfgs = self.mld.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'ipv6 mld ssm-translate ff31::1/128 2001:db8:1:1::1', 'ipv6 mld ssm-translate ff31::1/128 2001:db8:1:1::2', 'interface Ethernet2/1', ' ipv6 pim sparse-mode', ' ipv6 mld join-group ff30::1 source 2001:db8:0:abcd::1', ' ipv6 mld static-oif fffe::2', ' exit', 'vrf context VRF1', ' ipv6 mld ssm-translate ff31::1/128 2001:db8:1:1::1', ' ipv6 mld ssm-translate ff32::1/128 2001:db8:1:1::1', ' exit', 'interface Ethernet2/2', ' ipv6 pim sparse-mode', ' ipv6 mld access-group test2', ' ipv6 mld immediate-leave', ' ipv6 mld state-limit 6400', ' ipv6 mld query-interval 366', ' ipv6 mld query-max-response-time 15', ' ipv6 mld robustness-variable 7', ' ipv6 mld version 2', ' ipv6 mld join-group ff30::1 source 2001:db8:0:abcd::1', ' ipv6 mld static-oif ff30::2 source 2001:db8:0:abcd::2', ' ipv6 mld join-group fffe::1', ' ipv6 mld static-oif fffe::2', ' exit', ])) # Build unconfig cfgs = self.mld.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no ipv6 mld ssm-translate ff31::1/128 2001:db8:1:1::1', 'no ipv6 mld ssm-translate ff31::1/128 2001:db8:1:1::2', 'interface Ethernet2/1', ' no ipv6 pim sparse-mode', ' no ipv6 mld join-group ff30::1 source 2001:db8:0:abcd::1', ' no ipv6 mld static-oif fffe::2', ' exit', 'no vrf context VRF1', 'interface Ethernet2/2', ' no ipv6 pim sparse-mode', ' no ipv6 mld access-group test2', ' no ipv6 mld immediate-leave', ' no ipv6 mld state-limit 6400', ' no ipv6 mld query-interval 366', ' no ipv6 mld query-max-response-time 15', ' no ipv6 mld robustness-variable 7', ' no ipv6 mld version 2', ' no ipv6 mld join-group ff30::1 source 2001:db8:0:abcd::1', ' no ipv6 mld static-oif ff30::2 source 2001:db8:0:abcd::2', ' no ipv6 mld join-group fffe::1', ' no ipv6 mld static-oif fffe::2', ' exit', ])) # Build unconfig with attribute cfgs = self.mld.build_unconfig(apply=False, attributes={ 'device_attr': { self.dev1: { '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([ 'interface Ethernet2/1', ' no ipv6 pim sparse-mode', ' exit', 'vrf context VRF1', ' no ipv6 mld ssm-translate ff31::1/128 2001:db8:1:1::1', ' no ipv6 mld ssm-translate ff32::1/128 2001:db8:1:1::1', ' exit', ]))
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_nve_interface_ir(self): # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='BL1', testbed=testbed, os='nxos') intf1 = Interface(name='nve1', device=dev1) # Apply configuration intf1.nve_host_reachability_protocol = 'bgp' intf1.nve_adv_virtual_rmac = True intf1.nve_src_intf_loopback = 'loopback1' intf1.nve_multisite_bgw_intf = 'loopback100' vni_map = {} vnis_map = {} vnis_map['nve_vni_suppress_arp'] = False vnis_map['nve_vni_ir'] = True vnis_map['nve_vni_multisite_ingress_replication'] = True vnis_map['nve_vni_ir_proto'] = 'bgp' vnis_map['nve_vni_suppress_arp'] = True vnis_map['nve_vni'] = '1001-1100' vni_map['1001-1100'] = vnis_map intf1.vni_map = vni_map intf1.nve_src_intf_holddown = 30 intf1.nve_global_suppress_arp = True intf1.nve_global_ir_proto = 'bgp' intf1.nve_global_mcast_group_l2 = '229.0.0.1' # Build config cfgs = intf1.build_config(apply=False, attributes={ 'nve_host_reachability_protocol': 'bgp', 'nve_global_suppress_arp': True, 'nve_global_ir_proto': 'bgp', 'nve_global_mcast_group_l2': intf1.nve_global_mcast_group_l2, 'nve_adv_virtual_rmac': True, 'nve_src_intf_loopback': 'loopback1', 'nve_src_intf_holddown': 30, 'nve_multisite_bgw_intf': 'loopback100', 'vni_map': vnis_map }) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface nve1', ' host-reachability protocol bgp', ' global suppress-arp', ' global ingress-replication protocol bgp', ' global mcast-group 229.0.0.1 L2', ' advertise virtual-rmac', ' source-interface loopback1', ' source-interface hold-down-time 30', ' multisite border-gateway interface loopback100', ' member vni 1001-1100', ' suppress-arp', ' ingress-replication protocol bgp', ' multisite ingress-replication', ' exit', ' exit' ])) dev1 = Device(name='BL1', testbed=testbed, os='nxos') intf1 = Interface(name='nve1', device=dev1) vnis_map = {} vnis_map['nve_vni'] = '1001-1100' vni_map['1001-1100'] = vnis_map intf1.vni_map = vni_map # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={'vni_map': vni_map}) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join(['interface nve1', ' no member vni 1001-1100', ' exit'])) # Apply configuration intf1.nve_host_reachability_protocol = 'bgp' intf1.nve_global_suppress_arp = True intf1.nve_global_mcast_group_l2 = '229.0.0.1' intf1.nve_src_intf_holddown = 30 vni_map = {} vnis_map = {} vni_map['nve_vni_multisite_ingress_replication'] = True vni_map['nve_vni_ir'] = True vni_map['nve_vni_ir_proto'] = 'bgp' vni_map['nve_vni_suppress_arp'] = True vni_map['nve_vni'] = '1001-1100' vnis_map['1001-1100'] = vni_map intf1.vni_map = vnis_map #uncfgs = intf1.build_unconfig(apply=False) # Build unconfig # uncfgs = intf1.build_unconfig(apply=False) # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={ 'nve_host_reachability_protocol': 'bgp', 'nve_src_intf_holddown': 30, 'global_suppress_arp': True, 'nve_global_mcast_group_l2': '229.0.0.1', 'vni_map': vnis_map }) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface nve1', ' no host-reachability protocol bgp', ' no global mcast-group L2', ' no source-interface hold-down-time 30', ' member vni 1001-1100', ' no suppress-arp', ' no ingress-replication protocol bgp', ' no multisite ingress-replication', ' exit', ' exit' ]))
def test_lag_interafce(self): Genie.testbed = Testbed() dev1 = Device(name='PE1', os='iosxe') intf1 = Interface(device=dev1, name='GigabitEthernet1/0/1') intf2 = Interface(device=dev1, name='GigabitEthernet1/0/2') intf3 = Interface(device=dev1, name='Port-channel10') # lacp intf1.lag_bundle_id = 10 intf1.lag_activity = 'active' intf1.lag_lacp_port_priority = 30 # pagp intf2.lag_bundle_id = 20 intf2.lag_activity = 'auto' intf2.lag_non_silent = True intf2.lag_pagp_port_priority = 50 # virtual lagInterface intf3.lag_lacp_system_priority = 100 intf3.lag_lacp_max_bundle = 20 intf3.lag_lacp_min_bundle = 15 # error assigned attributes, shouldn't in the configuration intf2.lag_lacp_max_bundle = 123 # Check config cfg1 = intf1.build_config(apply=False) self.assertMultiLineEqual( str(cfg1), '\n'.join([ 'interface GigabitEthernet1/0/1', ' channel-group 10 mode active', ' lacp port-priority 30', ' exit', ])) cfg2 = intf2.build_config(apply=False) self.assertMultiLineEqual( str(cfg2), '\n'.join([ 'interface GigabitEthernet1/0/2', ' channel-group 20 mode auto non-silent', ' pagp port-priority 50', ' exit', ])) cfg3 = intf3.build_config(apply=False) self.assertMultiLineEqual( str(cfg3), '\n'.join([ 'lacp system-priority 100', 'interface Port-channel10', ' lacp max-bundle 20', ' lacp min-bundle 15', ' exit', ])) # Check unconfig uncfg1 = intf1.build_unconfig(apply=False) self.assertMultiLineEqual( str(uncfg1), '\n'.join([ 'default interface GigabitEthernet1/0/1', 'interface GigabitEthernet1/0/1', 'shutdown', ])) uncfg2 = intf2.build_unconfig(apply=False) self.assertMultiLineEqual( str(uncfg2), '\n'.join([ 'default interface GigabitEthernet1/0/2', 'interface GigabitEthernet1/0/2', 'shutdown', ])) # Check unconfig with attributes uncfg1 = intf1.build_unconfig(apply=False, attributes={ 'lag_activity': None, 'lag_bundle_id': None }) self.assertMultiLineEqual( str(uncfg1), '\n'.join([ 'interface GigabitEthernet1/0/1', ' no channel-group 10 mode active', ' exit', ])) uncfg2 = intf2.build_unconfig(apply=False, attributes="lag_pagp_port_priority") self.assertMultiLineEqual( str(uncfg2), '\n'.join([ 'interface GigabitEthernet1/0/2', ' no pagp port-priority 50', ' exit', ]))
def test_basic_cfg(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='nxos') dev2 = Device(testbed=testbed, name='PE2', os='nxos') intf1 = Interface(name='Ethernet0/0/1', device=dev1, layer=Layer.L3) intf2 = Interface(name='Ethernet0/0/2', device=dev2, layer=Layer.L2) link = Link(name='1_2_1', testbed=testbed) link.connect_interface(interface=intf1) link.connect_interface(interface=intf2) vlan = Vlan() link.add_feature(vlan) vlan.vlan_id = 100 access_map_id = 'ed' vlan_configuration_id = '3' vlan.device_attr[dev1] vlan.device_attr[dev2] vlan.device_attr[dev1].interface_attr[intf1] vlan.device_attr[dev2].interface_attr[intf2] vlan.device_attr[dev2].interface_attr[intf2].switchport_mode = \ L2_type.TRUNK vlan.device_attr[dev2].interface_attr[intf2].sw_trunk_allowed_vlan = \ '200-201' vlan.device_attr[dev1].access_map_attr[access_map_id] vlan.device_attr[dev2].access_map_attr[access_map_id] vlan.device_attr[dev1].vlan_configuration_attr[vlan_configuration_id] vlan.device_attr[dev2].vlan_configuration_attr[vlan_configuration_id] # Defining attributes section vlan.shutdown = False with self.assertRaises(ValueError): vlan.media = 'invalid' vlan.media = 'enet' self.assertIs(type(vlan.media), Vlan.Media) vlan.egress_load_balance = True vlan.device_attr[dev1].access_map_action = 'drop' vlan.datalink_flow_monitor = True intf1.ipv4 = '201.0.12.1' intf1.ipv4.netmask = '255.255.255.0' intf1.speed = 1000 intf1.mtu = 500 intf1.ipv6 = '2001::12:1' cfg1 = vlan.build_config(apply=False) cfg2 = intf1.build_config(apply=False) self.assertCountEqual(cfg1.keys(), ['PE1', 'PE2']) self.assertMultiLineEqual( str(cfg1['PE1']), '\n'.join([ 'vlan 100', ' media enet', ' no shutdown', ' exit', 'vlan access-map ed', ' action drop', ' exit', 'vlan configuration 3', ' egress port-channel load-balance random', ' exit', 'interface Ethernet0/0/1', ' mtu 500', ' ip address 201.0.12.1 255.255.255.0', ' ipv6 address 2001::12:1/128', ' speed 1000', ' exit', ])) self.assertMultiLineEqual( str(cfg1['PE2']), '\n'.join([ 'vlan 100', ' media enet', ' no shutdown', ' exit', 'vlan access-map ed', ' exit', 'vlan configuration 3', ' egress port-channel load-balance random', ' exit', 'interface Ethernet0/0/2', ' switchport mode trunk', ' switchport trunk allowed vlan 200-201', ' exit', ])) self.assertMultiLineEqual( str(cfg2), '\n'.join([ 'interface Ethernet0/0/1', ' mtu 500', ' ip address 201.0.12.1 255.255.255.0', ' ipv6 address 2001::12:1/128', ' speed 1000', ' exit', ]))
def test_cfg(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') 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='iosxe') 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(): bgp = Bgp(bgp_id=100) self.assertIs(bgp.testbed, testbed) Genie.testbed = testbed bgp = Bgp(bgp_id=100) self.assertIs(bgp.testbed, Genie.testbed) self.assertIs(bgp.testbed, testbed) # Defining attributes af_name = 'ipv4 unicast' af_name2 = 'link-state' 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_label_allocation_mode = 'per-vrf' bgp.device_attr[dev1].vrf_attr[None].address_family_attr[af_name].\ af_dampening = True neighbor_id = intf4.ipv4 bgp.device_attr[dev1].vrf_attr[None].add_neighbor(neighbor_id) bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id] bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id].\ nbr_remote_as = 200 bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id].\ nbr_fall_over_bfd = True bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id].\ nbr_shutdown = True bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id].\ nbr_update_source = 'loopback0' bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id].\ nbr_remove_private_as = True bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id].\ nbr_remove_private_as_af_name = 'ipv4 unicast' nbr_af_name = 'ipv4 multicast' bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name] bgp.device_attr[dev1].vrf_attr[None].neighbor_attr[neighbor_id].\ address_family_attr[nbr_af_name].nbr_af_allowas_in = True 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', ' bgp always-compare-med', ' neighbor 10.2.0.2 fall-over bfd', ' neighbor 10.2.0.2 remote-as 200', ' address-family ipv4 unicast', ' neighbor 10.2.0.2 remove-private-as', ' exit', ' neighbor 10.2.0.2 shutdown', ' neighbor 10.2.0.2 update-source loopback0', ' address-family ipv4 multicast', ' neighbor 10.2.0.2 activate', ' neighbor 10.2.0.2 allowas-in', ' exit', ' address-family ipv4 unicast', ' bgp dampening', ' exit', ' address-family link-state', ' exit', ' exit', 'mpls label mode vrf default protocol bgp-vpnv4 per-vrf', ]))
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_init(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/1', ipv4='10.1.0.1/24') intf2 = Interface(device=dev1, name='GigabitEthernet0/0/2', ipv4='10.2.0.1/24') dev2 = Device(testbed=testbed, name='PE2', os='iosxe') intf3 = Interface(device=dev2, name='GigabitEthernet0/0/3', ipv4='10.1.0.2/24') intf4 = Interface(device=dev2, name='GigabitEthernet0/0/4', ipv4='10.2.0.2/24') vrf1 = Vrf(name='vrf1') vrf2 = Vrf(name='a') with self.assertNoWarnings(): bgp = Bgp(asn=100) self.assertIs(bgp.testbed, testbed) Genie.testbed = testbed bgp = Bgp(asn=100) self.assertIs(bgp.testbed, Genie.testbed) self.assertIs(bgp.testbed, testbed) dev1.add_feature(bgp) cfgs = bgp.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([ 'router bgp 100', ' address-family ipv4 unicast', ' exit', ' exit', ])) dev2.add_feature(bgp) cfgs = bgp.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name, dev2.name]) self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([ 'router bgp 100', ' address-family ipv4 unicast', ' exit', ' exit', ])) self.assertMultiLineEqual(str(cfgs[dev2.name]), '\n'.join([ 'router bgp 100', ' address-family ipv4 unicast', ' exit', ' exit', ])) bgp.device_attr[dev1].add_neighbor(intf3.ipv4) bgp.device_attr[dev1].add_vrf(vrf1) bgp.device_attr[dev1].vrf_attr[vrf1].add_neighbor(intf4.ipv4) bgp.device_attr[dev1].vrf_attr[vrf1].neighbor_attr[intf4.ipv4].\ address_family_attr['ipv4 unicast'].activate = True bgp.device_attr[dev1].add_vrf(vrf2) cfgs = bgp.build_config(apply=False) self.assertCountEqual(cfgs.keys(), [dev1.name, dev2.name]) self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([ 'router bgp 100', ' neighbor 10.1.0.2 remote-as 100', ' address-family ipv4 unicast', ' exit', ' address-family ipv4 unicast vrf a', ' exit', ' neighbor 10.2.0.2 remote-as 100', ' address-family ipv4 unicast vrf vrf1', ' neighbor 10.2.0.2 activate', ' exit', ' address-family ipv4 unicast vrf vrf1', ' exit', ' exit', ])) self.assertMultiLineEqual(str(cfgs[dev2.name]), '\n'.join([ 'router bgp 100', ' address-family ipv4 unicast', ' exit', ' exit', ])) cfgs = bgp.build_config(apply=False, attributes='device_attr__PE1__vrf_attr__default') self.assertCountEqual(cfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([ 'router bgp 100', ' neighbor 10.1.0.2 remote-as 100', ' address-family ipv4 unicast', ' exit', ' exit', ])) cfgs = bgp.build_config(apply=False, attributes={ 'device_attr': { '*': (), }, }) self.assertCountEqual(cfgs.keys(), [dev1.name, dev2.name]) self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([ 'router bgp 100', ' exit', ])) self.assertMultiLineEqual(str(cfgs[dev2.name]), '\n'.join([ 'router bgp 100', ' exit', ])) cfgs = bgp.build_config(apply=False, attributes={ 'device_attr': { 'PE1': 'vrf_attr__default', }, }) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([ 'router bgp 100', ' neighbor 10.1.0.2 remote-as 100', ' address-family ipv4 unicast', ' exit', ' exit', ])) cfgs = bgp.build_config(apply=False, attributes={ 'device_attr': { 'PE1': 'vrf_attr__default__neighbor_attr__10.1.0.2', }, }) self.assertCountEqual(cfgs.keys(), [dev1.name]) self.assertMultiLineEqual(str(cfgs[dev1.name]), '\n'.join([ 'router bgp 100', ' neighbor 10.1.0.2 remote-as 100', ' exit', ]))
def test_init_vpls(self): testbed = Genie.testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxr') lo1 = Interface(device=dev1, name='Loopback0', ipv4='101.0.0.1/32') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1', ipv4='10.1.0.1/24') intf2 = Interface(device=dev1, name='GigabitEthernet0/0/0/2', ipv4='10.2.0.1/24') dev2 = Device(testbed=testbed, name='PE2', os='iosxr') lo2 = Interface(device=dev2, name='Loopback0', ipv4='102.0.0.1/32') intf3 = Interface(device=dev2, name='GigabitEthernet0/0/0/3', ipv4='10.1.0.2/24') intf4 = Interface(device=dev2, name='GigabitEthernet0/0/0/4', ipv4='10.2.0.2/24') link1 = Link(testbed=testbed, name='link1', interfaces=(intf1, intf3)) link2 = Link(testbed=testbed, name='link2', interfaces=(intf2, intf4)) dev3 = Device(testbed=testbed, name='PE3', os='iosxr') bd1 = BridgeDomain(name='bd1') dev1.add_feature(bd1) dev2.add_feature(bd1) self.assertCountEqual(bd1.pseudowires, []) nbr1 = bd1.create_pseudowire_neighbor(device=dev1, ip=lo2.ipv4.ip) nbr2 = bd1.device_attr[dev2].create_pseudowire_neighbor(ip=lo1.ipv4.ip) pw1 = Pseudowire(neighbors=(nbr1, nbr2), pw_id=1) self.assertCountEqual(bd1.pseudowires, [pw1]) self.assertCountEqual(bd1.pseudowire_neighbors, [nbr1, nbr2]) self.assertCountEqual(bd1.device_attr[dev1].pseudowires, [pw1]) self.assertCountEqual(bd1.device_attr[dev1].pseudowire_neighbors, [nbr1]) self.assertCountEqual(bd1.device_attr[dev2].pseudowires, [pw1]) self.assertCountEqual(bd1.device_attr[dev2].pseudowire_neighbors, [nbr2]) self.assertCountEqual(bd1.device_attr[dev3].pseudowires, []) self.assertCountEqual(bd1.device_attr[dev3].pseudowire_neighbors, []) self.assertCountEqual(bd1.segments, [pw1]) self.assertCountEqual(bd1.device_attr[dev1].segments, [pw1]) self.assertCountEqual(bd1.device_attr[dev2].segments, [pw1]) self.assertCountEqual(bd1.device_attr[dev3].segments, []) cfgs = bd1.build_config(apply=False) self.assertMultiLineDictEqual( cfgs, { dev1.name: '\n'.join([ 'l2vpn', ' bridge group bd1g', ' bridge-domain bd1', ' neighbor 102.0.0.1 pw-id 1', ' exit', ' exit', ' exit', ' exit', ]), dev2.name: '\n'.join([ 'l2vpn', ' bridge group bd1g', ' bridge-domain bd1', ' neighbor 101.0.0.1 pw-id 1', ' exit', ' exit', ' exit', ' exit', ]), })
def test_cfg2(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') 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', ipv6='2001::1') dev2 = Device(testbed=testbed, name='PE2', os='iosxe') 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 = testbed bgp = Bgp(bgp_id=100) self.assertIs(bgp.testbed, testbed) Genie.testbed = testbed bgp = Bgp(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].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 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( ['router bgp 100', ' bgp cluster-id 150', ' address-family ipv6 unicast', ' bgp dampening 1 10 30 2', ' bgp nexthop route-map test', ' exit', ' address-family ipv4 unicast vrf vrf1', ' neighbor 10.2.0.1 dont-capability-negotiate four-octets-as', ' exit', ' template peer-session PEER-SESSION', ' fall-over bfd', ' exit', ' template peer-policy PEER-POLICY', ' allowas-in', ' exit', ' exit', ]))
def test_init(self): Genie.testbed = Testbed() dev1 = Device(name='PE1', os='iosxr') with self.assertRaises(TypeError): intf1 = Interface() with self.assertRaises(TypeError): intf1 = Interface(device=dev1) intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1') intf1.device = None # forget it! #ats_dev1 = AtsDevice(name='PE1') ats_dev1 = None ats_intf1 = AtsInterface(device=ats_dev1, name='GigabitEthernet0/0/0/1', os='iosxr', type='ethernet') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1') self.assertTrue(isinstance(intf1, Interface)) self.assertTrue(isinstance(intf1, xbuInterface)) self.assertTrue(isinstance(intf1, iosxrInterface)) self.assertTrue(isinstance(intf1, geniePhysicalInterface)) self.assertTrue(isinstance(intf1, xbuPhysicalInterface)) self.assertTrue(isinstance(intf1, iosxrPhysicalInterface)) #self.assertTrue(isinstance(intf1, EthernetInterface)) self.assertTrue(isinstance(intf1, xbuEthernetInterface)) self.assertTrue(isinstance(intf1, iosxrEthernetInterface)) intf2 = Interface(device=intf1.device, name=intf1.name + '.1') self.assertTrue(isinstance(intf2, Interface)) self.assertTrue(isinstance(intf2, xbuInterface)) self.assertTrue(isinstance(intf2, iosxrInterface)) self.assertTrue(isinstance(intf2, genieVirtualInterface)) self.assertTrue(isinstance(intf2, xbuVirtualInterface)) self.assertTrue(isinstance(intf2, iosxrVirtualInterface)) #self.assertTrue(isinstance(intf2, genieSubInterface)) self.assertTrue(isinstance(intf2, xbuSubInterface)) self.assertTrue(isinstance(intf2, iosxrSubInterface)) self.assertEqual(intf1.ipv4, None) self.assertEqual(intf1.ipv6, None) self.assertEqual(intf1.mac_address, None) self.assertEqual(intf1.burnin_mac_address, None) self.assertEqual(intf1.effective_mac_address, None) intf1.ipv4 = '1.2.3.4/24' self.assertEqual(intf1.ipv4, IPv4Interface('1.2.3.4/24')) self.assertTrue(isinstance(intf1.ipv4, IPv4Interface)) intf1.ipv4 = None self.assertIs(intf1.ipv4, None) with self.assertRaises(ValueError): intf1.ipv4 = 'abc' if False: # TODO -- Setting without a prefix uses 32 bits! with self.assertRaises(ValueError): intf1.ipv4 = '1.2.3.4' else: intf1.ipv4 = '1.2.3.4' self.assertEqual(intf1.ipv4, IPv4Interface('1.2.3.4/32')) intf1.ipv6 = '1234::1/80' self.assertEqual(intf1.ipv6, IPv6Interface('1234::1/80')) self.assertTrue(isinstance(intf1.ipv6, IPv6Interface)) intf1.burnin_mac_address = 'a.b.c' self.assertTrue(isinstance(intf1.burnin_mac_address, MAC)) self.assertEqual(intf1.mac_address, None) self.assertEqual(intf1.burnin_mac_address, MAC('a.b.c')) self.assertEqual(intf1.effective_mac_address, intf1.burnin_mac_address) del intf1.burnin_mac_address intf1.mac_address = 'a.b.c2' self.assertTrue(isinstance(intf1.mac_address, MAC)) self.assertEqual(intf1.mac_address, MAC('a.b.c2')) self.assertEqual(intf1.burnin_mac_address, None) self.assertEqual(intf1.effective_mac_address, intf1.mac_address) del intf1.mac_address intf1.mac_address = 'a.b.c3' intf1.burnin_mac_address = 'a.b.c4' self.assertEqual(intf1.mac_address, MAC('a.b.c3')) self.assertEqual(intf1.burnin_mac_address, MAC('a.b.c4')) self.assertEqual(intf1.effective_mac_address, intf1.mac_address) del intf1.mac_address del intf1.burnin_mac_address
def test_cfg3(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxe') 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', ipv6='2001::1') dev2 = Device(testbed=testbed, name='PE2', os='iosxe') 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 = testbed bgp = Bgp(bgp_id=100) self.assertIs(bgp.testbed, testbed) Genie.testbed = testbed bgp = Bgp(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].peer_policy_attr[pp_name].pp_as_override =\ True bgp.device_attr[dev2].peer_session_attr[ps_name].ps_remote_as=\ 12 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_client_to_client_reflection = True nbr_af_name = 'ipv6 unicast' neighbor_id2 = intf2.ipv6 bgp.device_attr[dev2].vrf_attr[vrf1].neighbor_attr[neighbor_id2].\ address_family_attr[nbr_af_name] bgp.device_attr[dev2].vrf_attr[vrf1].neighbor_attr[neighbor_id2].\ address_family_attr[nbr_af_name].\ nbr_af_maximum_prefix_max_prefix_no = 300000 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( ['router bgp 100', ' bgp cluster-id 150', ' address-family ipv6 unicast', ' bgp client-to-client reflection', ' exit', ' address-family ipv6 unicast vrf vrf1', ' neighbor 2001::1 activate', ' neighbor 2001::1 maximum-prefix 300000', ' exit', ' template peer-session PEER-SESSION', ' remote-as 12', ' exit', ' template peer-policy PEER-POLICY', ' as-override', ' exit', ' exit', ]))
def test_init(self): Genie.testbed = testbed = Testbed() dev1 = Device(testbed=testbed, name='PE1', os='iosxr') intf1 = Interface(device=dev1, name='GigabitEthernet0/0/0/1') intf2 = Interface(device=dev1, name='GigabitEthernet0/0/0/2') dev2 = Device(testbed=testbed, name='PE2', os='iosxr') intf3 = Interface(device=dev2, name='GigabitEthernet0/0/0/3') intf4 = Interface(device=dev2, name='GigabitEthernet0/0/0/4') with self.assertNoWarnings(): nve1 = Interface(device=dev1, name='nve1') with self.assertRaises(TypeError): vni1 = Vni() with self.assertRaises(TypeError): vni1 = Vni(vni_id=1) with self.assertRaises(TypeError): vni1 = Vni(nve=nve1) vni1 = Vni(nve=nve1, vni_id=1) with self.assertRaises(ValueError): vni2 = Vni(nve=nve1, vni_id=1) vni2 = Vni(nve=nve1, vni_id=2) cfg = vni1.build_config(apply=False) self.assertMultiLineEqual(str(cfg), '\n'.join([ "interface nve1", " member vni 1", " exit", " exit", ])) cfg = nve1.build_config(apply=False) self.assertMultiLineEqual(str(cfg), '\n'.join([ "interface nve1", " member vni 1", " exit", " member vni 2", " exit", " exit", ])) cfg = nve1.build_config(apply=False, attributes='vnis__2') self.assertMultiLineEqual(str(cfg), '\n'.join([ "interface nve1", " member vni 2", " exit", " exit", ])) cfg = nve1.build_config(apply=False, attributes={ 'vnis': 2, }) self.assertMultiLineEqual(str(cfg), '\n'.join([ "interface nve1", " member vni 2", " exit", " exit", ])) cfg = nve1.build_config(apply=False, attributes={ 'vnis': { vni2: (), }, }) self.assertMultiLineEqual(str(cfg), '\n'.join([ "interface nve1", " member vni 2", " exit", " exit", ]))
def test_mcast_config(self): # For failures self.maxDiff = None # VRF configuration vrf1 = Vrf('VRF1') self.mld.device_attr[ self.dev1].vrf_attr[vrf1].global_max_groups = 63999 mld1 = self.mld.device_attr[self.dev1].vrf_attr[vrf1] ssm1 = Ssm(device=self.dev1) ssm1.ssm_group_policy = 'test' ssm1.ssm_source_addr = '2001:DB8:1:1::1' mld1.add_ssm(ssm1) # Interface configuration intf1_obj = Interface(device=self.dev1, name='GigabitEthernet2') intf1_obj.vrf = vrf1 intf1 = intf1_obj.name self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .enable = True self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .group_policy = 'test2' self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .max_groups = 6400 self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .query_interval = 366 self.mld.device_attr[self.dev1].vrf_attr[vrf1].interface_attr[intf1]\ .query_max_response_time = 16 # join and static groups configuration mld_intf1 = self.mld.device_attr[ self.dev1].vrf_attr[vrf1].interface_attr[intf1] join_group1 = MldGroup(device=self.dev1) join_group1.join_group = 'FF25:2::1' join_group2 = MldGroup(device=self.dev1) join_group2.join_group = 'FF15:1::1' join_group2.join_group_source_addr = '2001:DB8:2:2::2' static_group1 = MldGroup(device=self.dev1) static_group1.static_group = 'FF45:1::1' static_group2 = MldGroup(device=self.dev1) static_group2.static_group = 'FF35:1::1' static_group2.static_group_source_addr = '2001:DB8:3:3::3' mld_intf1.add_groups(join_group1) mld_intf1.add_groups(join_group2) mld_intf1.add_groups(static_group1) mld_intf1.add_groups(static_group2) vrf2 = Vrf('default') self.mld.device_attr[ self.dev1].vrf_attr[vrf2].global_max_groups = 63999 mld2 = self.mld.device_attr[self.dev1].vrf_attr[vrf2] ssm1 = Ssm(device=self.dev1) ssm1.ssm_group_policy = 'test' ssm1.ssm_source_addr = '2001:DB8:1:1::1' mld2.add_ssm(ssm1) # Interface configuration intf2_obj = Interface(device=self.dev1, name='GigabitEthernet1') ipv6a = IPv6Addr(device=self.dev1) ipv6a.ipv6 = '2001:DB8:1:1::1' ipv6a.ipv6_prefix_length = '64' intf2_obj.add_ipv6addr(ipv6a) intf2 = intf2_obj.name self.mld.device_attr[self.dev1].vrf_attr[vrf2].interface_attr[intf2]\ .enable = True # join and static groups configuration mld_intf1 = self.mld.device_attr[ self.dev1].vrf_attr[vrf2].interface_attr[intf2] join_group = MldGroup(device=self.dev1) join_group.join_group = 'FF15:1::1' join_group.join_group_source_addr = '2001:DB8:2:2::2' static_group = MldGroup(device=self.dev1) static_group.static_group = 'FF45:1::1' mld_intf1.add_groups(join_group) mld_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 GigabitEthernet2', ' vrf forwarding VRF1', ' exit', ])) intf_cfgs = intf2_obj.build_config(apply=False) self.assertMultiLineEqual( str(intf_cfgs), '\n'.join([ 'interface GigabitEthernet1', ' ipv6 address 2001:db8:1:1::1/64', ' exit', ])) # Build mld configuration cfgs = self.mld.build_config(apply=False) # Check config built correctly self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'ipv6 mld state-limit 63999', 'ipv6 mld ssm-map enable', 'ipv6 mld ssm-map static test 2001:DB8:1:1::1', 'interface GigabitEthernet1', ' ipv6 mld router', ' ipv6 mld join-group FF15:1::1 2001:DB8:2:2::2', ' ipv6 mld static-group FF45:1::1', ' exit', 'ipv6 mld vrf VRF1 state-limit 63999', 'ipv6 mld vrf VRF1 ssm-map enable', 'ipv6 mld vrf VRF1 ssm-map static test 2001:DB8:1:1::1', 'interface GigabitEthernet2', ' ipv6 mld router', ' ipv6 mld access-group test2', ' ipv6 mld limit 6400', ' ipv6 mld query-interval 366', ' ipv6 mld query-max-response-time 16', ' ipv6 mld join-group FF15:1::1 2001:DB8:2:2::2', ' ipv6 mld join-group FF25:2::1', ' ipv6 mld static-group FF35:1::1 2001:DB8:3:3::3', ' ipv6 mld static-group FF45:1::1', ' exit', ])) # Build unconfig cfgs = self.mld.build_unconfig(apply=False) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'no ipv6 mld state-limit 63999', 'no ipv6 mld ssm-map enable', 'no ipv6 mld ssm-map static test 2001:DB8:1:1::1', 'interface GigabitEthernet1', ' no ipv6 mld router', ' no ipv6 mld join-group FF15:1::1 2001:DB8:2:2::2', ' no ipv6 mld static-group FF45:1::1', ' exit', 'no ipv6 mld vrf VRF1 state-limit 63999', 'no ipv6 mld vrf VRF1 ssm-map enable', 'no ipv6 mld vrf VRF1 ssm-map static test 2001:DB8:1:1::1', 'interface GigabitEthernet2', ' no ipv6 mld router', ' no ipv6 mld access-group test2', ' no ipv6 mld limit 6400', ' no ipv6 mld query-interval 366', ' no ipv6 mld query-max-response-time 16', ' no ipv6 mld join-group FF15:1::1 2001:DB8:2:2::2', ' no ipv6 mld join-group FF25:2::1', ' no ipv6 mld static-group FF35:1::1 2001:DB8:3:3::3', ' no ipv6 mld static-group FF45:1::1', ' exit', ])) # Build unconfig with attribute cfgs = self.mld.build_unconfig( apply=False, attributes={ 'device_attr': { self.dev1: { 'vrf_attr': { vrf1: { 'global_max_groups': None, 'ssm': { ssm1: None } }, vrf2: { 'interface_attr': { 'GigabitEthernet1': { 'enable': True } } } } } } }) # Check config correctly unconfigured self.assertMultiLineEqual( str(cfgs[self.dev1.name]), '\n'.join([ 'interface GigabitEthernet1', ' no ipv6 mld router', ' exit', 'no ipv6 mld vrf VRF1 state-limit 63999', 'no ipv6 mld vrf VRF1 ssm-map enable', 'no ipv6 mld vrf VRF1 ssm-map static test 2001:DB8:1:1::1', ]))