diff options
author | imarom <imarom@cisco.com> | 2017-01-22 16:20:45 +0200 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2017-01-22 16:20:45 +0200 |
commit | 904eacd9be1230efb7ae0ab7997ec131b588ec8a (patch) | |
tree | 8e4bcd1b1a5f683efdb8f3eeb962acefc3201961 /scripts/automation/regression/CPlatform.py | |
parent | d2f1c8451e2e8ffc47b208f68f9b16697d706d60 (diff) | |
parent | b81cdb6c2d6d118c1c346e7c8dae6a5e747d867d (diff) |
Merge branch 'master' into capture
Signed-off-by: imarom <imarom@cisco.com>
Conflicts:
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py
src/main_dpdk.cpp
Diffstat (limited to 'scripts/automation/regression/CPlatform.py')
-rwxr-xr-x | scripts/automation/regression/CPlatform.py | 186 |
1 files changed, 118 insertions, 68 deletions
diff --git a/scripts/automation/regression/CPlatform.py b/scripts/automation/regression/CPlatform.py index 606235a6..332f700a 100755 --- a/scripts/automation/regression/CPlatform.py +++ b/scripts/automation/regression/CPlatform.py @@ -19,45 +19,82 @@ class CPlatform(object): self.needed_image_path = None self.tftp_cfg = None self.config_history = { 'basic_if_config' : False, 'tftp_server_config' : False } + self.client_vlan = "100" + self.server_vlan = "200" - def configure_basic_interfaces(self, mtu = 9050): + def configure_basic_interfaces(self, mtu = 9050, vlan=False): cache = CCommandCache() for dual_if in self.if_mngr.get_dual_if_list(): client_if_command_set = [] server_if_command_set = [] + client_if_command_set_vlan = [] + server_if_command_set_vlan = [] + + client_if_name = dual_if.client_if.get_name() + server_if_name = dual_if.server_if.get_name() + + if vlan: + client_if_name_vlan = client_if_name + "." + self.client_vlan + server_if_name_vlan = server_if_name + "." + self.server_vlan + client_if_command_set_vlan.append('encapsulation dot1Q {vlan}'. format(vlan = self.client_vlan)); + server_if_command_set_vlan.append('encapsulation dot1Q {vlan}'. format(vlan = self.server_vlan)); client_if_command_set.append ('mac-address {mac}'.format( mac = dual_if.client_if.get_src_mac_addr()) ) client_if_command_set.append ('mtu %s' % mtu) - client_if_command_set.append ('ip address {ip} 255.255.255.0'.format( ip = dual_if.client_if.get_ipv4_addr() )) - client_if_command_set.append ('ipv6 address {ip}/64'.format( ip = dual_if.client_if.get_ipv6_addr() )) - cache.add('IF', client_if_command_set, dual_if.client_if.get_name()) + client_ip_command = 'ip address {ip} 255.255.255.0'.format( ip = dual_if.client_if.get_ipv4_addr() ) + client_ipv6_command = 'ipv6 address {ip}/64'.format( ip = dual_if.client_if.get_ipv6_addr() ) + if vlan: + client_if_command_set_vlan.append (client_ip_command) + client_if_command_set_vlan.append (client_ipv6_command) + else: + client_if_command_set.append (client_ip_command) + client_if_command_set.append (client_ipv6_command) + + cache.add('IF', client_if_command_set, client_if_name) + if vlan: + cache.add('IF', client_if_command_set_vlan, client_if_name_vlan) server_if_command_set.append ('mac-address {mac}'.format( mac = dual_if.server_if.get_src_mac_addr()) ) server_if_command_set.append ('mtu %s' % mtu) - server_if_command_set.append ('ip address {ip} 255.255.255.0'.format( ip = dual_if.server_if.get_ipv4_addr() )) - server_if_command_set.append ('ipv6 address {ip}/64'.format( ip = dual_if.server_if.get_ipv6_addr() )) - cache.add('IF', server_if_command_set, dual_if.server_if.get_name()) + server_ip_command = 'ip address {ip} 255.255.255.0'.format( ip = dual_if.server_if.get_ipv4_addr() ) + server_ipv6_command = 'ipv6 address {ip}/64'.format( ip = dual_if.server_if.get_ipv6_addr() ) + if vlan: + server_if_command_set_vlan.append (server_ip_command) + server_if_command_set_vlan.append (server_ipv6_command) + else: + server_if_command_set.append (server_ip_command) + server_if_command_set.append (server_ipv6_command) + + cache.add('IF', server_if_command_set, server_if_name) + if vlan: + cache.add('IF', server_if_command_set_vlan, server_if_name_vlan) self.cmd_link.run_single_command(cache) self.config_history['basic_if_config'] = True - - - def configure_basic_filtered_interfaces(self, intf_list, mtu = 9050): + def configure_basic_filtered_interfaces(self, intf_list, mtu = 9050, vlan = False): cache = CCommandCache() for intf in intf_list: if_command_set = [] + if_command_set_vlan = [] if_command_set.append ('mac-address {mac}'.format( mac = intf.get_src_mac_addr()) ) if_command_set.append ('mtu %s' % mtu) - if_command_set.append ('ip address {ip} 255.255.255.0'.format( ip = intf.get_ipv4_addr() )) - if_command_set.append ('ipv6 address {ip}/64'.format( ip = intf.get_ipv6_addr() )) + ip_commands = ['ip address {ip} 255.255.255.0'.format( ip = intf.get_ipv4_addr() ), + 'ipv6 address {ip}/64'.format( ip = intf.get_ipv6_addr() )] + if vlan: + if_command_set_vlan.extend(ip_commands) + else: + if_command_set.extend(ip_commands) cache.add('IF', if_command_set, intf.get_name()) + if vlan: + if_name = intf.get_name() + '.' + (self.client_vlan if intf.is_client() else self.server_vlan) + cache.add('IF', if_command_set_vlan, if_name) self.cmd_link.run_single_command(cache) @@ -74,8 +111,9 @@ class CPlatform(object): if i < 4: continue raise Exception('Could not load clean config, response: %s' % res) + break - def config_pbr (self, mode = 'config'): + def config_pbr (self, mode = 'config', vlan = False): idx = 1 unconfig_str = '' if mode=='config' else 'no ' @@ -93,30 +131,30 @@ class CPlatform(object): if dual_if.is_duplicated(): # define the relevant VRF name pre_commit_set.add('{mode}ip vrf {dup}'.format( mode = unconfig_str, dup = dual_if.get_vrf_name()) ) - + # assign VRF to interfaces, config interfaces with relevant route-map client_if_command_set.append ('{mode}ip vrf forwarding {dup}'.format( mode = unconfig_str, dup = dual_if.get_vrf_name()) ) - client_if_command_set.append ('{mode}ip policy route-map {dup}_{p1}_to_{p2}'.format( + client_if_command_set.append ('{mode}ip policy route-map {dup}_{p1}_to_{p2}'.format( mode = unconfig_str, - dup = dual_if.get_vrf_name(), + dup = dual_if.get_vrf_name(), p1 = 'p'+str(idx), p2 = 'p'+str(idx+1) ) ) server_if_command_set.append ('{mode}ip vrf forwarding {dup}'.format( mode = unconfig_str, dup = dual_if.get_vrf_name()) ) - server_if_command_set.append ('{mode}ip policy route-map {dup}_{p2}_to_{p1}'.format( + server_if_command_set.append ('{mode}ip policy route-map {dup}_{p2}_to_{p1}'.format( mode = unconfig_str, - dup = dual_if.get_vrf_name(), + dup = dual_if.get_vrf_name(), p1 = 'p'+str(idx), p2 = 'p'+str(idx+1) ) ) # config route-map routing conf_t_command_set.append('{mode}route-map {dup}_{p1}_to_{p2} permit 10'.format( mode = unconfig_str, - dup = dual_if.get_vrf_name(), + dup = dual_if.get_vrf_name(), p1 = 'p'+str(idx), p2 = 'p'+str(idx+1) ) ) if mode == 'config': conf_t_command_set.append('set ip next-hop {next_hop}'.format( next_hop = client_net_next_hop) ) conf_t_command_set.append('{mode}route-map {dup}_{p2}_to_{p1} permit 10'.format( mode = unconfig_str, - dup = dual_if.get_vrf_name(), + dup = dual_if.get_vrf_name(), p1 = 'p'+str(idx), p2 = 'p'+str(idx+1) ) ) if mode == 'config': conf_t_command_set.append('set ip next-hop {next_hop}'.format( @@ -127,21 +165,21 @@ class CPlatform(object): if dual_if.client_if.get_dest_mac(): conf_t_command_set.append('{mode}arp vrf {dup} {next_hop} {dest_mac} arpa'.format( mode = unconfig_str, - dup = dual_if.get_vrf_name(), - next_hop = server_net_next_hop, + dup = dual_if.get_vrf_name(), + next_hop = server_net_next_hop, dest_mac = dual_if.client_if.get_dest_mac())) if dual_if.server_if.get_dest_mac(): conf_t_command_set.append('{mode}arp vrf {dup} {next_hop} {dest_mac} arpa'.format( - mode = unconfig_str, - dup = dual_if.get_vrf_name(), - next_hop = client_net_next_hop, + mode = unconfig_str, + dup = dual_if.get_vrf_name(), + next_hop = client_net_next_hop, dest_mac = dual_if.server_if.get_dest_mac())) else: # config interfaces with relevant route-map - client_if_command_set.append ('{mode}ip policy route-map {p1}_to_{p2}'.format( + client_if_command_set.append ('{mode}ip policy route-map {p1}_to_{p2}'.format( mode = unconfig_str, p1 = 'p'+str(idx), p2 = 'p'+str(idx+1) ) ) - server_if_command_set.append ('{mode}ip policy route-map {p2}_to_{p1}'.format( + server_if_command_set.append ('{mode}ip policy route-map {p2}_to_{p1}'.format( mode = unconfig_str, p1 = 'p'+str(idx), p2 = 'p'+str(idx+1) ) ) @@ -164,17 +202,22 @@ class CPlatform(object): if dual_if.client_if.get_dest_mac(): conf_t_command_set.append('{mode}arp {next_hop} {dest_mac} arpa'.format( mode = unconfig_str, - next_hop = server_net_next_hop, + next_hop = server_net_next_hop, dest_mac = dual_if.client_if.get_dest_mac())) if dual_if.server_if.get_dest_mac(): conf_t_command_set.append('{mode}arp {next_hop} {dest_mac} arpa'.format( mode = unconfig_str, - next_hop = client_net_next_hop, + next_hop = client_net_next_hop, dest_mac = dual_if.server_if.get_dest_mac())) # assign generated config list to cache - cache.add('IF', server_if_command_set, dual_if.server_if.get_name()) - cache.add('IF', client_if_command_set, dual_if.client_if.get_name()) + client_if_name = dual_if.client_if.get_name() + server_if_name = dual_if.server_if.get_name() + if vlan: + client_if_name += "." + self.client_vlan + server_if_name += "." + self.server_vlan + cache.add('IF', server_if_command_set, server_if_name) + cache.add('IF', client_if_command_set, client_if_name) cache.add('CONF', conf_t_command_set) idx += 2 @@ -186,12 +229,12 @@ class CPlatform(object): # deploy the configs (order is important!) self.cmd_link.run_command( [pre_commit_cache, cache] ) if self.config_history['basic_if_config']: - # in this case, duplicated interfaces will lose its ip address. + # in this case, duplicated interfaces will lose its ip address. # re-config IPv4 addresses - self.configure_basic_filtered_interfaces(self.if_mngr.get_duplicated_if() ) + self.configure_basic_filtered_interfaces(self.if_mngr.get_duplicated_if(), vlan = vlan) - def config_no_pbr (self): - self.config_pbr(mode = 'unconfig') + def config_no_pbr (self, vlan = False): + self.config_pbr(mode = 'unconfig', vlan = vlan) def config_static_routing (self, stat_route_obj, mode = 'config'): @@ -241,13 +284,13 @@ class CPlatform(object): conf_t_command_set.append( "{mode}ip route vrf {dup} {next_net} {dest_mask} {next_hop}".format( mode = unconfig_str, - dup = dual_if.get_vrf_name(), + dup = dual_if.get_vrf_name(), next_net = client_net, dest_mask = stat_route_obj.client_mask, next_hop = client_net_next_hop)) conf_t_command_set.append( "{mode}ip route vrf {dup} {next_net} {dest_mask} {next_hop}".format( mode = unconfig_str, - dup = dual_if.get_vrf_name(), + dup = dual_if.get_vrf_name(), next_net = server_net, dest_mask = stat_route_obj.server_mask, next_hop = server_net_next_hop)) @@ -256,14 +299,14 @@ class CPlatform(object): if dual_if.client_if.get_dest_mac(): conf_t_command_set.append('{mode}arp vrf {dup} {next_hop} {dest_mac} arpa'.format( mode = unconfig_str, - dup = dual_if.get_vrf_name(), - next_hop = server_net_next_hop, + dup = dual_if.get_vrf_name(), + next_hop = server_net_next_hop, dest_mac = dual_if.client_if.get_dest_mac())) if dual_if.server_if.get_dest_mac(): conf_t_command_set.append('{mode}arp vrf {dup} {next_hop} {dest_mac} arpa'.format( - mode = unconfig_str, - dup = dual_if.get_vrf_name(), - next_hop = client_net_next_hop, + mode = unconfig_str, + dup = dual_if.get_vrf_name(), + next_hop = client_net_next_hop, dest_mac = dual_if.server_if.get_dest_mac())) # assign generated interfaces config list to cache @@ -286,12 +329,12 @@ class CPlatform(object): if dual_if.client_if.get_dest_mac(): conf_t_command_set.append('{mode}arp {next_hop} {dest_mac} arpa'.format( mode = unconfig_str, - next_hop = server_net_next_hop, + next_hop = server_net_next_hop, dest_mac = dual_if.client_if.get_dest_mac())) if dual_if.server_if.get_dest_mac(): conf_t_command_set.append('{mode}arp {next_hop} {dest_mac} arpa'.format( mode = unconfig_str, - next_hop = client_net_next_hop, + next_hop = client_net_next_hop, dest_mac = dual_if.server_if.get_dest_mac())) # bump up to the next client network address @@ -309,9 +352,9 @@ class CPlatform(object): # deploy the configs (order is important!) self.cmd_link.run_command( [pre_commit_cache, cache] ) if self.config_history['basic_if_config']: - # in this case, duplicated interfaces will lose its ip address. + # in this case, duplicated interfaces will lose its ip address. # re-config IPv4 addresses - self.configure_basic_filtered_interfaces(self.if_mngr.get_duplicated_if() ) + self.configure_basic_filtered_interfaces(self.if_mngr.get_duplicated_if()) def config_no_static_routing (self, stat_route_obj = None): @@ -424,7 +467,7 @@ class CPlatform(object): def config_zbf (self, mode = 'config'): cache = CCommandCache() pre_commit_cache = CCommandCache() - conf_t_command_set = [] + conf_t_command_set = [] # toggle all duplicate interfaces down self.toggle_duplicated_intf(action = 'down') @@ -460,7 +503,7 @@ class CPlatform(object): def config_no_zbf (self): cache = CCommandCache() - conf_t_command_set = [] + conf_t_command_set = [] # define security zones and security service policy to be applied on the interfaces conf_t_command_set.append('no zone-pair security in2out source z_in destination z_out') @@ -485,7 +528,7 @@ class CPlatform(object): # self.__toggle_interfaces(dup_ifs) - def config_ipv6_pbr (self, mode = 'config'): + def config_ipv6_pbr (self, mode = 'config', vlan=False): idx = 1 unconfig_str = '' if mode=='config' else 'no ' cache = CCommandCache() @@ -496,7 +539,7 @@ class CPlatform(object): for dual_if in self.if_mngr.get_dual_if_list(): client_if_command_set = [] server_if_command_set = [] - + client_net_next_hop = misc_methods.get_single_net_client_addr(dual_if.server_if.get_ipv6_addr(), {'7':1}, ip_type = 'ipv6' ) server_net_next_hop = misc_methods.get_single_net_client_addr(dual_if.client_if.get_ipv6_addr(), {'7':1}, ip_type = 'ipv6' ) client_net_next_hop_v4 = misc_methods.get_single_net_client_addr(dual_if.server_if.get_ipv4_addr() ) @@ -510,22 +553,22 @@ class CPlatform(object): prefix = 'ipv6_' + dual_if.get_vrf_name() else: prefix = 'ipv6' - + # config interfaces with relevant route-map - client_if_command_set.append ('{mode}ipv6 policy route-map {pre}_{p1}_to_{p2}'.format( + client_if_command_set.append ('{mode}ipv6 policy route-map {pre}_{p1}_to_{p2}'.format( mode = unconfig_str, - pre = prefix, + pre = prefix, p1 = 'p'+str(idx), p2 = 'p'+str(idx+1) ) ) - server_if_command_set.append ('{mode}ipv6 policy route-map {pre}_{p2}_to_{p1}'.format( + server_if_command_set.append ('{mode}ipv6 policy route-map {pre}_{p2}_to_{p1}'.format( mode = unconfig_str, - pre = prefix, + pre = prefix, p1 = 'p'+str(idx), p2 = 'p'+str(idx+1) ) ) # config global arp to interfaces net address and vrf if dual_if.client_if.get_ipv6_dest_mac(): conf_t_command_set.append('{mode}ipv6 neighbor {next_hop} {intf} {dest_mac}'.format( mode = unconfig_str, - next_hop = server_net_next_hop, + next_hop = server_net_next_hop, intf = dual_if.client_if.get_name(), dest_mac = dual_if.client_if.get_ipv6_dest_mac())) # For latency packets (which are IPv4), we need to configure also static ARP @@ -561,17 +604,24 @@ class CPlatform(object): conf_t_command_set.append('exit') # assign generated config list to cache - cache.add('IF', server_if_command_set, dual_if.server_if.get_name()) - cache.add('IF', client_if_command_set, dual_if.client_if.get_name()) + client_if_name = dual_if.client_if.get_name() + server_if_name = dual_if.server_if.get_name() + if vlan: + client_if_name += "." + self.client_vlan + server_if_name += "." + self.server_vlan + + cache.add('IF', server_if_command_set, server_if_name) + cache.add('IF', client_if_command_set, client_if_name) + idx += 2 cache.add('CONF', conf_t_command_set) - + # deploy the configs (order is important!) self.cmd_link.run_command( [cache] ) - def config_no_ipv6_pbr (self): - self.config_ipv6_pbr(mode = 'unconfig') + def config_no_ipv6_pbr (self, vlan = False): + self.config_ipv6_pbr(mode = 'unconfig', vlan = vlan) # show methods def get_cpu_util (self): @@ -679,7 +729,7 @@ class CPlatform(object): parsed_info = CShowParser.parse_show_image_version(response) self.running_image = parsed_info return parsed_info - + def check_image_existence (self, img_name): """ check_image_existence(self, img_name) -> boolean @@ -716,7 +766,7 @@ class CPlatform(object): # tmp_tftp_config = external_tftp_config if external_tftp_config is not None else self.tftp_server_config self.tftp_cfg = device_cfg_obj.get_tftp_info() cache = CCommandCache() - + command = "ip tftp source-interface {intf}".format( intf = device_cfg_obj.get_mgmt_interface() ) cache.add('CONF', command ) self.cmd_link.run_single_command(cache) @@ -737,12 +787,12 @@ class CPlatform(object): """ if not self.check_image_existence(img_filename): # check if this image isn't already saved in platform #tmp_tftp_config = external_tftp_config if external_tftp_config is not None else self.tftp_cfg - + if self.config_history['tftp_server_config']: # make sure a TFTP configuration has been loaded cache = CCommandCache() if self.running_image is None: self.get_running_image_details() - + command = "copy tftp://{tftp_ip}/{img_path}/{image} bootflash:".format( tftp_ip = self.tftp_cfg['ip_address'], img_path = self.tftp_cfg['images_path'], @@ -795,7 +845,7 @@ class CPlatform(object): An image file to compare router running image Compares image name to router running image, returns match result. - + """ if self.running_image is None: self.get_running_image_details() @@ -839,7 +889,7 @@ class CPlatform(object): i = 0 sleep_time = 30 # seconds - try: + try: cache = CCommandCache() cache.add('EXEC', ['reload','n\r','\r'] ) @@ -861,7 +911,7 @@ class CPlatform(object): raise TimeoutError('Platform failed to reload after reboot for over {minutes} minutes!'.format(minutes = round(1 + i * sleep_time / 60))) else: i += 1 - + time.sleep(30) self.reload_connection(device_cfg_obj) progress_thread.join() |