def test_ipv6_multiple_lines_confg(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='nxos') intf1 = Interface(name='Ethernet3/7', device=dev1, \ aliases=['PE1_1']) vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Apply configuration intf1.description = 'multiple lines config' ipv6a = IPv6Addr(device=dev1) ipv6a.ipv6 = IPv6Address('2001:db1:1::1') ipv6a.ipv6_prefix_length = '64' intf1.add_ipv6addr(ipv6a) ipv6b = IPv6Addr(device=dev1) ipv6b.ipv6 = IPv6Address('2001:db1:2::2') ipv6b.ipv6_prefix_length = '64' intf1.add_ipv6addr(ipv6b) intf1.shutdown = False # make intf2 as L3 interface intf1.switchport_enable = False # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface Ethernet3/7', ' description multiple lines config', ' no shutdown', ' no switchport', ' ipv6 address 2001:db1:1::1/64', ' ipv6 address 2001:db1:2::2/64', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'default interface Ethernet3/7', ]))
def test_ipv6_multiple_lines_confg(self): # For failures self.maxDiff = None # Set Genie Tb testbed = Testbed() Genie.testbed = testbed # Device dev1 = Device(name='PE1', testbed=testbed, os='iosxr') intf1 = Interface(name='GigabitEthernet0/0/0/0', device=dev1, \ aliases=['PE1_1']) vrf = Vrf(name='test', testbed=testbed) dev1.add_feature(vrf) # Apply configuration intf1.description = 'multiple lines config' intf1.enabled = False ipv6a = IPv6Addr(device=dev1) ipv6a.ipv6 = IPv6Address('2001:db1:1::1') ipv6a.ipv6_prefix_length = '64' intf1.add_ipv6addr(ipv6a) ipv6b = IPv6Addr(device=dev1) ipv6b.ipv6 = IPv6Address('2001:db1:2::2') ipv6b.ipv6_prefix_length = '64' intf1.add_ipv6addr(ipv6b) # Build config cfgs = intf1.build_config(apply=False) # Check config build correctly self.assertMultiLineEqual( str(cfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/0', ' ipv6 address 2001:db1:1::1/64', ' ipv6 address 2001:db1:2::2/64', ' description multiple lines config', ' shutdown', ' exit' ])) # Build unconfig uncfgs = intf1.build_unconfig(apply=False, attributes={'ipv6addr':None}) # Check config build correctly self.assertMultiLineEqual( str(uncfgs), '\n'.join([ 'interface GigabitEthernet0/0/0/0', ' no ipv6 address 2001:db1:1::1/64', ' no ipv6 address 2001:db1:2::2/64', ' exit' ]))
def configure_intf_ipv6(self, conf_obj, ip, mask, **kwargs): # add old ipv6 attributes in conf_object # for remove the original ipv6 configurations ipv6 = IPv6Addr(device=kwargs['device']) for ipInfo in self.keys.values(): if 'ip' in ipInfo: ipv6.ipv6 = IPv6Address(ipInfo['ip']) if 'mask' in ipInfo: ipv6.ipv6_prefix_length = ipInfo['mask'] conf_obj.add_ipv6addr(ipv6) # remove all existing ipv6 configurations conf_obj.build_unconfig(attributes={'ipv6addr': None}) # clear the used attribtues conf_obj.ipv6addr.clear() # configure new ipv6 address ipv6 = IPv6Addr(device=kwargs['device']) ipv6.ipv6 = IPv6Address(ip) ipv6.ipv6_prefix_length = mask conf_obj.add_ipv6addr(ipv6) conf_obj.build_config()
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_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_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', ]))