# import sth import time from sys import argv filename, device, port1, port2 = argv port_list = [port1, port2] port_handle = [] #Config the parameters for the logging test_sta = sth.test_config( log='1', logfile='HLTAPI_FCoE_Traffic_logfile', vendorlogfile='HLTAPI_FCoE_Traffic_stcExport', vendorlog='1', hltlog='1', hltlogfile='HLTAPI_FCoE_Traffic_hltExport', hlt2stcmappingfile='HHLTAPI_FCoE_Traffic_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1. Reserve and connect chassis ports ########################################
Booked_ports, Interface_config, Stream_config, Spirent_Test_Infra, Stream_Name = get_data( ) Number_of_ports = Spirent_Test_Infra['Number_of_ports'] Number_of_streams_per_Port = Spirent_Test_Infra['Number_of_streams_per_Port'] Total_Number_of_stream = Spirent_Test_Infra['Total_Number_of_stream'] Initial_MAC_address = Spirent_Test_Infra['Initial_MAC_address'] ############################################################## #Creation of Spirent Test config with log file ############################################################## test_sta = sth.test_config( log='1', logfile='SteamConfig-WithPercentageTraffic_logfile', vendorlogfile='SteamConfig-WithPercentageTraffic_stcExport', vendorlog='1', hltlog='1', hltlogfile='SteamConfig-WithPercentageTraffic_hltExport', hlt2stcmappingfile='SteamConfig-WithPercentageTraffic_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if (status == '0'): print("run sth.test_config failed") print(test_sta) ############################################################## #config the parameters for optimization and parsing ############################################################## test_ctrl_sta = sth.test_control(action='enable')
# import sth import time from sys import argv filename, device, port1, port2 = argv port_list = [port1, port2] port_handle = [] #Config the parameters for the logging test_sta = sth.test_config( log='1', logfile='HLTAPI_EOAM_Topology_ITUT_Y1731_VLAN_logfile', vendorlogfile='HLTAPI_EOAM_Topology_ITUT_Y1731_VLAN_stcExport', vendorlog='1', hltlog='1', hltlogfile='HLTAPI_EOAM_Topology_ITUT_Y1731_VLAN_hltExport', hlt2stcmappingfile='HHLTAPI_EOAM_Topology_ITUT_Y1731_VLAN_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1. Reserve and connect chassis ports ########################################
import re from pprint import pprint list1 = ['128','512','1518','9100'] list2 = ['60','70','80','90','100'] ############################################################## #config the parameters for the logging ############################################################## test_sta = sth.test_config ( log = '0', logfile = 'ELINE_RFC_Test_logfile', vendorlogfile = 'ELINE_RFC_Test_stcExport', vendorlog = '0', hltlog = '1', hltlogfile = 'ELINE_RFC_Test_hltExport', hlt2stcmappingfile = 'ELINE_RFC_Test_hlt2StcMapping', hlt2stcmapping = '1', log_level = '0'); status = test_sta['status'] if (status == '0') : print("run sth.test_config failed") print(test_sta) else: print("***** run sth.test_config successfully") ############################################################## #config the parameters for optimization and parsing
# Run sample: # c:>python HLTAPI_InterfaceConfig_Port_Load.py 10.61.44.2 3/1 3/3 import sth import time from sys import argv filename,device,port1,port2 = argv port_list = [port1,port2] port_handle = [] #Config the parameters for the logging test_sta = sth.test_config ( log = '1', logfile = 'HLTAPI_InterfaceConfig_Port_Load_logfile', vendorlogfile = 'HLTAPI_InterfaceConfig_Port_Load_stcExport', vendorlog = '1', hltlog = '1', hltlogfile = 'HLTAPI_InterfaceConfig_Port_Load_hltExport', hlt2stcmappingfile = 'HHLTAPI_InterfaceConfig_Port_Load_hlt2StcMapping', hlt2stcmapping = '1', log_level = '7') status = test_sta['status'] if status == '0' : print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1. Reserve and connect chassis ports
import time print "**************************************************starttime:\n" print (time.strftime("%H:%M:%S")) import sth from sys import argv filename,device,port1,port2 = argv port_list = [port1,port2] port_handle = [] #Config the parameters for the logging test_sta = sth.test_config ( log = '1', logfile = 'HLTAPI_RFC3918_logfile', vendorlogfile = 'HLTAPI_RFC3918_stcExport', vendorlog = '1', hltlog = '1', hltlogfile = 'HLTAPI_RFC3918_hltExport', hlt2stcmappingfile = 'HLTAPI_RFC3918_hlt2StcMapping', hlt2stcmapping = '1', log_level = '7') status = test_sta['status'] if status == '0' : print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1. Reserve and connect chassis ports
def dip(): ############################################################## #config the parameters for the logging ############################################################## test_sta = sth.test_config ( log = '1', logfile = 'dip2_logfile', vendorlogfile = 'dip2_stcExport', vendorlog = '1', hltlog = '1', hltlogfile = 'dip2_hltExport', hlt2stcmappingfile = 'dip2_hlt2StcMapping', hlt2stcmapping = '1', log_level = '7'); status = test_sta['status'] if (status == '0') : print("run sth.test_config failed") print(test_sta) else: print("***** run sth.test_config successfully") ############################################################## #config the parameters for optimization and parsing ############################################################## test_ctrl_sta = sth.test_control ( action = 'enable'); status = test_ctrl_sta['status'] if (status == '0') : print("run sth.test_control failed") print(test_ctrl_sta) else: print("***** run sth.test_control successfully") ############################################################## #connect to chassis and reserve port list ############################################################## i = 0 device = "10.91.113.124" port_list = ['11/8','4/6'] port_handle = [] intStatus = sth.connect ( device = device, port_list = port_list, break_locks = 1, offline = 0 ) status = intStatus['status'] if (status == '1') : for port in port_list : port_handle.append(intStatus['port_handle'][device][port]) print("\n reserved ports",port,":", port_handle[i]) i += 1 else : print("\nFailed to retrieve port handle!\n") print(port_handle) ############################################################## #interface config ############################################################## int_ret0 = sth.interface_config ( mode = 'config', port_handle = port_handle[0], create_host = 'false', intf_mode = 'ethernet', phy_mode = 'fiber', scheduling_mode = 'RATE_BASED', port_loadunit = 'PERCENT_LINE_RATE', port_load = '10', enable_ping_response = '0', control_plane_mtu = '1500', flow_control = 'false', speed = 'ether1000', data_path_mode = 'normal', autonegotiation = '1'); status = int_ret0['status'] if (status == '0') : print("run sth.interface_config failed") print(int_ret0) else: print("***** run sth.interface_config successfully") int_ret1 = sth.interface_config ( mode = 'config', port_handle = port_handle[1], create_host = 'false', intf_mode = 'ethernet', phy_mode = 'fiber', scheduling_mode = 'RATE_BASED', port_loadunit = 'PERCENT_LINE_RATE', port_load = '10', enable_ping_response = '0', control_plane_mtu = '1500', flow_control = 'false', speed = 'ether1000', data_path_mode = 'normal', autonegotiation = '1'); status = int_ret1['status'] if (status == '0') : print("run sth.interface_config failed") print(int_ret1) else: print("***** run sth.interface_config successfully") ############################################################## #create device and config the protocol on it ############################################################## #start to create the device: Device 1 device_ret0 = sth.emulation_device_config ( mode = 'create', ip_version = 'ipv4', encapsulation = 'ethernet_ii_vlan', port_handle = port_handle[0], vlan_user_pri = '7', vlan_cfi = '0', vlan_id = '20', vlan_tpid = '33024', vlan_id_repeat_count = '0', vlan_id_step = '0', router_id = '192.0.0.5', count = '1', enable_ping_response = '1', mac_addr = '00:10:94:00:00:05', mac_addr_step = '00:00:00:00:00:01', intf_ip_addr = '192.168.10.1', intf_prefix_len = '24', resolve_gateway_mac = 'true', gateway_ip_addr = '192.168.10.2', gateway_ip_addr_step = '0.0.0.0', intf_ip_addr_step = '0.0.0.1'); status = device_ret0['status'] if (status == '0') : print("run sth.emulation_device_config failed") print(device_ret0) else: print("***** run sth.emulation_device_config successfully") #start to create the device: Device 2 device_ret1 = sth.emulation_device_config ( mode = 'create', ip_version = 'ipv4', encapsulation = 'ethernet_ii_vlan', port_handle = port_handle[1], vlan_user_pri = '7', vlan_cfi = '0', vlan_id = '20', vlan_tpid = '33024', vlan_id_repeat_count = '0', vlan_id_step = '0', router_id = '192.0.0.6', count = '1', enable_ping_response = '1', mac_addr = '00:10:94:00:00:06', mac_addr_step = '00:00:00:00:00:01', intf_ip_addr = '192.168.10.2', intf_prefix_len = '24', resolve_gateway_mac = 'true', gateway_ip_addr = '192.168.10.1', gateway_ip_addr_step = '0.0.0.0', intf_ip_addr_step = '0.0.0.1'); status = device_ret1['status'] if (status == '0') : print("run sth.emulation_device_config failed") print(device_ret1) else: print("***** run sth.emulation_device_config successfully") ############################################################## #create traffic ############################################################## src_hdl = device_ret0['handle'].split()[0] dst_hdl = device_ret1['handle'].split()[0] streamblock_ret1 = sth.traffic_config ( mode = 'create', port_handle = port_handle[0], emulation_src_handle = src_hdl, emulation_dst_handle = dst_hdl, l3_protocol = 'ipv4', ip_id = '0', ip_ttl = '255', ip_hdr_length = '5', ip_protocol = '253', ip_fragment_offset = '0', ip_mbz = '0', ip_precedence = '6', ip_tos_field = '0', enable_control_plane = '0', l3_length = '9100', name = 'StreamBlock_18-3', fill_type = 'constant', fcs_error = '0', fill_value = '0', frame_size = '9100', traffic_state = '1', high_speed_result_analysis = '1', length_mode = 'fixed', dest_port_list = ['port2','port1'], tx_port_sending_traffic_to_self_en = 'false', disable_signature = '0', enable_stream_only_gen = '1', pkts_per_burst = '1', inter_stream_gap_unit = 'bytes', inter_stream_gap = '12', rate_mbps = '50', mac_discovery_gw = '192.168.10.2'); status = streamblock_ret1['status'] if (status == '0') : print("run sth.traffic_config failed") print(streamblock_ret1) else: print("***** run sth.traffic_config successfully") src_hdl = device_ret1['handle'].split()[0] dst_hdl = device_ret0['handle'].split()[0] streamblock_ret2 = sth.traffic_config ( mode = 'create', port_handle = port_handle[1], emulation_src_handle = src_hdl, emulation_dst_handle = dst_hdl, l3_protocol = 'ipv4', ip_id = '0', ip_ttl = '255', ip_hdr_length = '5', ip_protocol = '253', ip_fragment_offset = '0', ip_mbz = '0', ip_precedence = '6', ip_tos_field = '0', enable_control_plane = '0', l3_length = '9100', name = 'StreamBlock_18-4', fill_type = 'constant', fcs_error = '0', fill_value = '0', frame_size = '9100', traffic_state = '1', high_speed_result_analysis = '1', length_mode = 'fixed', dest_port_list = ['port2','port1'], tx_port_sending_traffic_to_self_en = 'false', disable_signature = '0', enable_stream_only_gen = '1', pkts_per_burst = '1', inter_stream_gap_unit = 'bytes', inter_stream_gap = '12', rate_mbps = '50', mac_discovery_gw = '192.168.10.1'); status = streamblock_ret2['status'] if (status == '0') : print("run sth.traffic_config failed") print(streamblock_ret2) else: print("***** run sth.traffic_config successfully") #config part is finished ############################################################## #start devices ############################################################## ############################################################## #start traffic ############################################################## traffic_ctrl_ret = sth.traffic_control ( port_handle = [port_handle[0],port_handle[1]], action = 'run', duration = '30'); status = traffic_ctrl_ret['status'] if (status == '0') : print("run sth.traffic_control failed") print(traffic_ctrl_ret) else: print("***** run sth.traffic_control successfully") ############################################################## #start to get the device results ############################################################## ############################################################## #start to get the traffic results ############################################################## traffic_results_ret = sth.traffic_stats ( port_handle = [port_handle[0],port_handle[1]], mode = 'all'); status = traffic_results_ret['status'] if (status == '0') : print("run sth.traffic_stats failed") print(traffic_results_ret) else: print("***** run sth.traffic_stats successfully, and results is:") print(traffic_results_ret) ############################################################## #clean up the session, release the ports reserved and cleanup the dbfile ############################################################## cleanup_sta = sth.cleanup_session ( port_handle = [port_handle[0],port_handle[1]], clean_dbfile = '1'); status = cleanup_sta['status'] if (status == '0') : print("run sth.cleanup_session failed") print(cleanup_sta) else: print("***** run sth.cleanup_session successfully") print("**************Finish***************") result = SpirentResult(traffic_results_ret, port_list) return result
import sys import yaml import re from pprint import pprint from netmiko import Netmiko import datetime ############################################################## #config the parameters for the logging ############################################################## test_sta = sth.test_config(log='0', logfile='repair_logfile', vendorlogfile='repair_stcExport', vendorlog='0', hltlog='1', hltlogfile='repair_hltExport', hlt2stcmappingfile='repair_hlt2StcMapping', hlt2stcmapping='1', log_level='0') status = test_sta['status'] if (status == '0'): print("run sth.test_config failed") print(test_sta) else: print("***** run sth.test_config successfully") ############################################################## #config the parameters for optimization and parsing ##############################################################
# Run sample: # c:>python HLTAPI_OSPFv2_topylogy_enhance.py 10.61.44.2 3/1 3/3 import sth import time from sys import argv filename, device, port1, port2 = argv port_list = [port1, port2] port_handle = [] #Config the parameters for the logging test_sta = sth.test_config(log='1', logfile='ospf_enhance_logfile', vendorlogfile='ospf_enhance_stcExport', vendorlog='1', hltlog='1', hltlogfile='iospf_enhance_hltExport', hlt2stcmappingfile='ospf_enhance_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1. Reserve and connect chassis ports ########################################
name = port print "Saving capture to : " + name sth.invoke( 'stc::perform SaveSelectedCaptureData -CaptureProxyId %s -filename %s.pcap' % (captureHnd, name)) fileNameList.append('%s.pcap' % name) print "Save file Name list = %s" % fileNameList return fileNameList #Config the parameters for the logging test_sta = sth.test_config( log='1', logfile='HLTAPI_sip_proxy_server_logfile', vendorlogfile='HLTAPI_sip_proxy_server_stcExport', vendorlog='1', hltlog='1', hltlogfile='HLTAPI_sip_proxy_server_hltExport', hlt2stcmappingfile='HLTAPI_sip_proxy_server_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1. Reserve and connect chassis ports ########################################
def spi2(): Booked_ports, Interface_config, Stream_config, Spirent_Test_Infra = spirent_items( ) test_sta = sth.test_config( log='1', logfile='SteamConfig-WithPercentageTraffic_logfile', vendorlogfile='SteamConfig-WithPercentageTraffic_stcExport', vendorlog='1', hltlog='1', hltlogfile='SteamConfig-WithPercentageTraffic_hltExport', hlt2stcmappingfile='SteamConfig-WithPercentageTraffic_hlt2StcMapping', hlt2stcmapping='1', log_level='7') Number_of_ports = Spirent_Test_Infra['Number_of_ports'] status = test_sta['status'] if (status == '0'): print("run sth.test_config failed") print(test_sta) ############################################################## #config the parameters for optimization and parsing ############################################################## test_ctrl_sta = sth.test_control(action='enable') status = test_ctrl_sta['status'] if (status == '0'): print("run sth.test_control failed") print(test_ctrl_sta) ############################################################## #connect to chassis and reserve port list ############################################################## i = 0 device = "10.91.113.124" port_list = list(Booked_ports.values()) port_handle = [] intStatus = sth.connect(device=device, port_list=port_list, break_locks=1, offline=0) status = intStatus['status'] if (status == '1'): for port in port_list: port_handle.append(intStatus['port_handle'][device][port]) i += 1 else: print("\nFailed to retrieve port handle!\n") print(port_handle) ############################################################## #interface config ############################################################## Interface_config['port_handle'] = port_handle[0] int_ret0 = sth.interface_config(**Interface_config) status = int_ret0['status'] if (status == '0'): print("run sth.interface_config failed") print(int_ret0) Interface_config['port_handle'] = port_handle[1] int_ret1 = sth.interface_config(**Interface_config) status = int_ret1['status'] if (status == '0'): print("run sth.interface_config failed") print(int_ret0) ############################################################## #stream config ############################################################## Stream_config['port_handle'] = port_handle[0] Stream_config['dest_port_list'] = port_handle[1] Stream_config['name'] = 'Stream From 9-3 to 9-4' streamblock_ret1 = sth.traffic_config(**Stream_config) status = streamblock_ret1['status'] if (status == '0'): print("run sth.traffic_config failed") print(streamblock_ret1) Stream_config['port_handle'] = port_handle[1] Stream_config['dest_port_list'] = port_handle[0] Stream_config['name'] = 'Stream From 9-4 to 9-3' streamblock_ret1 = sth.traffic_config(**Stream_config) status = streamblock_ret1['status'] if (status == '0'): print("run sth.traffic_config failed") print(streamblock_ret1) ############################################################# #start traffic ############################################################## print("Traffic Started") traffic_ctrl_ret = sth.traffic_control( port_handle=[port_handle[0], port_handle[1]], action='run', duration='30') status = traffic_ctrl_ret['status'] if (status == '0'): print("run sth.traffic_control failed") print(traffic_ctrl_ret) print("Test Traffic Stopped now adding delay before collecting stats") time.sleep(10) print("Traffic collection started") ############################################################## #start to get the traffic results ############################################################## traffic_results_ret = sth.traffic_stats( port_handle=[port_handle[0], port_handle[1]], mode='all') status = traffic_results_ret['status'] if (status == '0'): print("run sth.traffic_stats failed") print(traffic_results_ret) # ############################################################## # #Get required values from Stats # ############################################################## # Streams_rx_stat = [] # Streams_tx_stat = [] # for i in range(1,Number_of_ports+1): # Port_Index = 'port'+ str(i) # Stream_Index = 'streamblock' + str(i) # Streams_rx_stats = traffic_results_ret[Port_Index]['stream'][Stream_Index]['rx'] # Streams_tx_stats = traffic_results_ret[Port_Index]['stream'][Stream_Index]['tx'] # Streams_rx_stat.append(int(Streams_rx_stats['total_pkt_bytes'])) # Streams_tx_stat.append(int(Streams_tx_stats['total_pkt_bytes'])) # # if((Streams_tx_stat[0] == Streams_rx_stat[1]) and (Streams_tx_stat[1] == Streams_rx_stat[0])): # print("Great Test Case is passed") # print("streamblock1 TX = ", Streams_tx_stat[0], "streamblock1 RX = ", Streams_rx_stat[0], "streamblock2 TX = ", Streams_tx_stat[1], "streamblock2 RX = ", Streams_rx_stat[1]) # # stats = "streamblock1 TX = ", Streams_tx_stat[0], "streamblock1 RX = ", Streams_rx_stat[0], "streamblock2 TX = ", Streams_tx_stat[1], "streamblock2 RX = ", Streams_rx_stat[1] # status = "Great Test Case is passed\n" + str(stats) # return status # # else: # print("Oops Tst Case Failed") # print("streamblock1 TX = ", Streams_tx_stat[0], "streamblock1 RX = ", Streams_rx_stat[0], "streamblock2 TX = ", Streams_tx_stat[1], "streamblock2 RX = ", Streams_rx_stat[1]) # # stats = "streamblock1 TX = ", Streams_tx_stat[0], "streamblock1 RX = ", Streams_rx_stat[0], "streamblock2 TX = ", Streams_tx_stat[1], "streamblock2 RX = ", Streams_rx_stat[1] # status = "Oops Tst Case Failed" + str(stats) # return status # Stream1_packet_loss_in_msec = ((Streams_tx_stat[0] - Streams_rx_stat[1]) / 1000) # Stream2_packet_loss_in_msec = ((Streams_tx_stat[1] - Streams_rx_stat[0]) / 1000) ############################################################## #Get required values from Stats ############################################################## result = SpirentResult(traffic_results_ret, port_list) return result
def spi1(): ############################################################## #config the parameters for the logging ############################################################## test_sta = sth.test_config( log='1', logfile='BasciTraffic_logfile', vendorlogfile='BasciTraffic_stcExport', vendorlog='1', hltlog='1', hltlogfile='BasciTraffic_hltExport', hlt2stcmappingfile='BasciTraffic_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if (status == '0'): print("run sth.test_config failed") print(test_sta) else: print("***** run sth.test_config successfully") ############################################################## #config the parameters for optimization and parsing ############################################################## test_ctrl_sta = sth.test_control(action='enable') status = test_ctrl_sta['status'] if (status == '0'): print("run sth.test_control failed") print(test_ctrl_sta) else: print("***** run sth.test_control successfully") ############################################################## #connect to chassis and reserve port list ############################################################## i = 0 device = "10.91.113.124" port_list = ['8/5', '8/6'] port_handle = [] intStatus = sth.connect(device=device, port_list=port_list, break_locks=1, offline=0) status = intStatus['status'] if (status == '1'): for port in port_list: port_handle.append(intStatus['port_handle'][device][port]) print("\n reserved ports", port, ":", port_handle[i]) i += 1 else: print("\nFailed to retrieve port handle!\n") print(port_handle) ############################################################## #interface config ############################################################## int_ret0 = sth.interface_config(mode='config', port_handle=port_handle[0], create_host='false', intf_mode='ethernet', phy_mode='fiber', scheduling_mode='RATE_BASED', port_loadunit='FRAMES_PER_SECOND', port_load='1000', enable_ping_response='0', control_plane_mtu='1500', flow_control='false', speed='ether1000', data_path_mode='normal', autonegotiation='1') status = int_ret0['status'] if (status == '0'): print("run sth.interface_config failed") print(int_ret0) else: print("***** run sth.interface_config successfully") int_ret1 = sth.interface_config(mode='config', port_handle=port_handle[1], create_host='false', intf_mode='ethernet', phy_mode='fiber', scheduling_mode='RATE_BASED', port_loadunit='FRAMES_PER_SECOND', port_load='1000', enable_ping_response='0', control_plane_mtu='1500', flow_control='false', speed='ether1000', data_path_mode='normal', autonegotiation='1') status = int_ret1['status'] if (status == '0'): print("run sth.interface_config failed") print(int_ret1) else: print("***** run sth.interface_config successfully") ############################################################## #create device and config the protocol on it ############################################################## #start to create the device: ar1-100 device_ret0 = sth.emulation_device_config( mode='create', ip_version='ipv4', encapsulation='ethernet_ii_vlan', port_handle=port_handle[0], vlan_user_pri='7', vlan_cfi='0', vlan_id='100', vlan_tpid='33024', vlan_id_repeat_count='0', vlan_id_step='0', router_id='192.0.0.3', count='1', enable_ping_response='1', mac_addr='00:10:94:00:00:03', mac_addr_step='00:00:00:00:00:01', intf_ip_addr='172.16.146.0', intf_prefix_len='31', resolve_gateway_mac='true', gateway_ip_addr='172.16.146.1', gateway_ip_addr_step='0.0.0.0', gateway_mac='00:a7:42:16:5f:23', intf_ip_addr_step='0.0.0.1') status = device_ret0['status'] if (status == '0'): print("run sth.emulation_device_config failed") print(device_ret0) else: print("***** run sth.emulation_device_config successfully") #start to create the device: ar6-100 device_ret1 = sth.emulation_device_config( mode='create', ip_version='ipv4', encapsulation='ethernet_ii_vlan', port_handle=port_handle[1], vlan_user_pri='7', vlan_cfi='0', vlan_id='100', vlan_tpid='33024', vlan_id_repeat_count='0', vlan_id_step='0', router_id='192.0.0.4', count='1', enable_ping_response='1', mac_addr='00:10:94:00:00:04', mac_addr_step='00:00:00:00:00:01', intf_ip_addr='172.17.146.0', intf_prefix_len='31', resolve_gateway_mac='true', gateway_ip_addr='172.17.146.1', gateway_ip_addr_step='0.0.0.0', gateway_mac='00:a7:42:36:12:8f', intf_ip_addr_step='0.0.0.1') status = device_ret1['status'] if (status == '0'): print("run sth.emulation_device_config failed") print(device_ret1) else: print("***** run sth.emulation_device_config successfully") #start to create the device: ar1-101 device_ret2 = sth.emulation_device_config( mode='create', ip_version='ipv4', encapsulation='ethernet_ii_vlan', port_handle=port_handle[0], vlan_user_pri='7', vlan_cfi='0', vlan_id='101', vlan_tpid='33024', vlan_id_repeat_count='0', vlan_id_step='0', router_id='192.0.0.5', count='1', enable_ping_response='1', mac_addr='00:10:94:00:00:05', mac_addr_step='00:00:00:00:00:01', intf_ip_addr='172.18.146.0', intf_prefix_len='31', resolve_gateway_mac='true', gateway_ip_addr='172.18.146.1', gateway_ip_addr_step='0.0.0.0', gateway_mac='00:a7:42:16:5f:23', intf_ip_addr_step='0.0.0.1') status = device_ret2['status'] if (status == '0'): print("run sth.emulation_device_config failed") print(device_ret2) else: print("***** run sth.emulation_device_config successfully") #start to create the device: ar1-111 L2 device_ret3 = sth.emulation_device_config( mode='create', ip_version='ipv4', encapsulation='ethernet_ii_vlan', port_handle=port_handle[0], vlan_user_pri='5', vlan_cfi='0', vlan_id='111', vlan_tpid='33024', vlan_id_repeat_count='0', vlan_id_step='0', router_id='192.0.0.6', count='1', enable_ping_response='1', mac_addr='00:11:11:00:00:01', mac_addr_step='00:00:00:00:00:01', intf_ip_addr='192.168.111.10', intf_prefix_len='24', resolve_gateway_mac='true', gateway_ip_addr='192.168.111.2', gateway_ip_addr_step='0.0.0.0', gateway_mac='00:10:94:00:00:07', intf_ip_addr_step='0.0.0.1') status = device_ret3['status'] if (status == '0'): print("run sth.emulation_device_config failed") print(device_ret3) else: print("***** run sth.emulation_device_config successfully") #start to create the device: ar6-111 L2 device_ret4 = sth.emulation_device_config( mode='create', ip_version='ipv4', encapsulation='ethernet_ii_vlan', port_handle=port_handle[1], vlan_user_pri='5', vlan_cfi='0', vlan_id='111', vlan_tpid='33024', vlan_id_repeat_count='0', vlan_id_step='0', router_id='192.0.0.7', count='1', enable_ping_response='1', mac_addr='00:10:94:00:00:07', mac_addr_step='00:00:00:00:00:01', intf_ip_addr='192.168.111.2', intf_prefix_len='24', resolve_gateway_mac='true', gateway_ip_addr='192.168.111.10', gateway_ip_addr_step='0.0.0.0', gateway_mac='00:11:11:00:00:01', intf_ip_addr_step='0.0.0.1') status = device_ret4['status'] if (status == '0'): print("run sth.emulation_device_config failed") print(device_ret4) else: print("***** run sth.emulation_device_config successfully") #start to create the device: ar1-110 L2 device_ret5 = sth.emulation_device_config( mode='create', ip_version='ipv4', encapsulation='ethernet_ii_vlan', port_handle=port_handle[0], vlan_user_pri='3', vlan_cfi='0', vlan_id='110', vlan_tpid='33024', vlan_id_repeat_count='0', vlan_id_step='0', router_id='192.0.0.6', count='1', enable_ping_response='1', mac_addr='00:10:94:00:00:06', mac_addr_step='00:00:00:00:00:01', intf_ip_addr='110.168.110.111', intf_prefix_len='24', resolve_gateway_mac='true', gateway_ip_addr='110.168.110.112', gateway_ip_addr_step='0.0.0.0', gateway_mac='00:10:94:00:00:07', intf_ip_addr_step='0.0.0.1') status = device_ret5['status'] if (status == '0'): print("run sth.emulation_device_config failed") print(device_ret5) else: print("***** run sth.emulation_device_config successfully") #start to create the device: ar6-110 L2 device_ret6 = sth.emulation_device_config( mode='create', ip_version='ipv4', encapsulation='ethernet_ii_vlan', port_handle=port_handle[1], vlan_user_pri='3', vlan_cfi='0', vlan_id='110', vlan_tpid='33024', vlan_id_repeat_count='0', vlan_id_step='0', router_id='192.0.0.7', count='1', enable_ping_response='1', mac_addr='00:10:94:00:00:07', mac_addr_step='00:00:00:00:00:01', intf_ip_addr='110.168.110.112', intf_prefix_len='24', resolve_gateway_mac='true', gateway_ip_addr='110.168.110.111', gateway_ip_addr_step='0.0.0.0', gateway_mac='00:10:94:00:00:06', intf_ip_addr_step='0.0.0.1') status = device_ret6['status'] if (status == '0'): print("run sth.emulation_device_config failed") print(device_ret6) else: print("***** run sth.emulation_device_config successfully") #start to create the device: ar6-112 L2 device_ret7 = sth.emulation_device_config( mode='create', ip_version='ipv4', encapsulation='ethernet_ii_vlan', port_handle=port_handle[1], vlan_user_pri='3', vlan_cfi='0', vlan_id='112', vlan_tpid='33024', vlan_id_repeat_count='0', vlan_id_step='0', router_id='192.0.0.7', count='1', enable_ping_response='1', mac_addr='00:10:94:00:00:07', mac_addr_step='00:00:00:00:00:01', intf_ip_addr='112.112.12.1', intf_prefix_len='24', resolve_gateway_mac='true', gateway_ip_addr='112.112.12.2', gateway_ip_addr_step='0.0.0.0', gateway_mac='00:12:94:00:00:06', intf_ip_addr_step='0.0.0.1') status = device_ret7['status'] if (status == '0'): print("run sth.emulation_device_config failed") print(device_ret7) else: print("***** run sth.emulation_device_config successfully") #start to create the device: ar1-112 L2 device_ret8 = sth.emulation_device_config( mode='create', ip_version='ipv4', encapsulation='ethernet_ii_vlan', port_handle=port_handle[0], vlan_user_pri='3', vlan_cfi='0', vlan_id='112', vlan_tpid='33024', vlan_id_repeat_count='0', vlan_id_step='0', router_id='192.0.0.6', count='1', enable_ping_response='1', mac_addr='00:12:94:00:00:06', mac_addr_step='00:00:00:00:00:01', intf_ip_addr='112.112.12.2', intf_prefix_len='24', resolve_gateway_mac='true', gateway_ip_addr='112.112.12.1', gateway_ip_addr_step='0.0.0.0', gateway_mac='00:10:94:00:00:07', intf_ip_addr_step='0.0.0.1') status = device_ret8['status'] if (status == '0'): print("run sth.emulation_device_config failed") print(device_ret8) else: print("***** run sth.emulation_device_config successfully") #start to create the device: ar1-113 L2 device_ret9 = sth.emulation_device_config( mode='create', ip_version='ipv4', encapsulation='ethernet_ii_vlan', port_handle=port_handle[0], vlan_user_pri='3', vlan_cfi='0', vlan_id='113', vlan_tpid='33024', vlan_id_repeat_count='0', vlan_id_step='0', router_id='192.0.0.6', count='1', enable_ping_response='1', mac_addr='00:12:94:00:00:06', mac_addr_step='00:00:00:00:00:01', intf_ip_addr='13.113.13.2', intf_prefix_len='24', resolve_gateway_mac='true', gateway_ip_addr='13.113.13.1', gateway_ip_addr_step='0.0.0.0', gateway_mac='00:10:94:00:00:07', intf_ip_addr_step='0.0.0.1') status = device_ret9['status'] if (status == '0'): print("run sth.emulation_device_config failed") print(device_ret9) else: print("***** run sth.emulation_device_config successfully") #start to create the device: ar6-113 L2 device_ret10 = sth.emulation_device_config( mode='create', ip_version='ipv4', encapsulation='ethernet_ii_vlan', port_handle=port_handle[1], vlan_user_pri='3', vlan_cfi='0', vlan_id='113', vlan_tpid='33024', vlan_id_repeat_count='0', vlan_id_step='0', router_id='192.0.0.7', count='1', enable_ping_response='1', mac_addr='00:10:94:00:00:07', mac_addr_step='00:00:00:00:00:01', intf_ip_addr='13.113.13.1', intf_prefix_len='24', resolve_gateway_mac='true', gateway_ip_addr='13.113.13.2', gateway_ip_addr_step='0.0.0.0', gateway_mac='00:12:94:00:00:06', intf_ip_addr_step='0.0.0.1') status = device_ret10['status'] if (status == '0'): print("run sth.emulation_device_config failed") print(device_ret10) else: print("***** run sth.emulation_device_config successfully") ############################################################## #create traffic ############################################################## src_hdl = device_ret0['handle'].split()[0] dst_hdl = device_ret1['handle'].split()[0] streamblock_ret1 = sth.traffic_config( mode='create', port_handle=port_handle[0], emulation_src_handle=src_hdl, emulation_dst_handle=dst_hdl, l3_protocol='ipv4', ip_id='0', ip_ttl='255', ip_hdr_length='5', ip_protocol='253', ip_fragment_offset='0', ip_dscp='10', enable_control_plane='0', l3_length='1500', name='ar1-100_B3', fill_type='constant', fcs_error='0', fill_value='0', frame_size='1500', traffic_state='1', high_speed_result_analysis='1', length_mode='fixed', dest_port_list=['port2', 'port1'], tx_port_sending_traffic_to_self_en='false', disable_signature='0', enable_stream_only_gen='1', pkts_per_burst='1', inter_stream_gap_unit='bytes', burst_loop_count='30', transmit_mode='continuous', inter_stream_gap='12', rate_pps='1000', mac_discovery_gw='172.16.146.1') status = streamblock_ret1['status'] if (status == '0'): print("run sth.traffic_config failed") print(streamblock_ret1) else: print("***** run sth.traffic_config successfully") src_hdl = device_ret1['handle'].split()[0] dst_hdl = device_ret0['handle'].split()[0] streamblock_ret2 = sth.traffic_config( mode='create', port_handle=port_handle[1], emulation_src_handle=src_hdl, emulation_dst_handle=dst_hdl, l3_protocol='ipv4', ip_id='0', ip_ttl='255', ip_hdr_length='5', ip_protocol='253', ip_fragment_offset='0', ip_dscp='10', enable_control_plane='0', l3_length='1500', name='ar6-100_B3', fill_type='constant', fcs_error='0', fill_value='0', frame_size='1500', traffic_state='1', high_speed_result_analysis='1', length_mode='fixed', dest_port_list=['port2', 'port1'], tx_port_sending_traffic_to_self_en='false', disable_signature='0', enable_stream_only_gen='1', pkts_per_burst='1', inter_stream_gap_unit='bytes', burst_loop_count='30', transmit_mode='continuous', inter_stream_gap='12', rate_pps='1000', mac_discovery_gw='172.17.146.1') status = streamblock_ret2['status'] if (status == '0'): print("run sth.traffic_config failed") print(streamblock_ret2) else: print("***** run sth.traffic_config successfully") #config part is finished ############################################################## #start devices ############################################################## ############################################################## #start traffic ############################################################## traffic_ctrl_ret = sth.traffic_control( port_handle=[port_handle[0], port_handle[1]], action='run', duration='30') status = traffic_ctrl_ret['status'] if (status == '0'): print("run sth.traffic_control failed") print(traffic_ctrl_ret) else: print("***** run sth.traffic_control successfully") ############################################################## #start to get the device results ############################################################## time.sleep(30) ############################################################## #start to get the traffic results ############################################################## traffic_results_ret = sth.traffic_stats( port_handle=[port_handle[0], port_handle[1]], mode='all') status = traffic_results_ret['status'] if (status == '0'): print("run sth.traffic_stats failed") print(traffic_results_ret) else: print("***** run sth.traffic_stats successfully, and results is:") print(traffic_results_ret) ############################################################## #clean up the session, release the ports reserved and cleanup the dbfile ############################################################## cleanup_sta = sth.cleanup_session( port_handle=[port_handle[0], port_handle[1]], clean_dbfile='1') status = cleanup_sta['status'] if (status == '0'): print("run sth.cleanup_session failed") print(cleanup_sta) else: print("***** run sth.cleanup_session successfully") print("**************Finish***************") result = SpirentResult(traffic_results_ret, port_list) return result
def Spirent_MAC_Transperancy_Traffic_Testing_For_EVPN_Service(): Booked_ports, Interface_config, Stream_config, Spirent_Test_Infra, Stream_Name = get_spirent_data( ) Number_of_ports = Spirent_Test_Infra['Number_of_ports'] Number_of_streams_per_Port = Spirent_Test_Infra[ 'Number_of_streams_per_Port'] Total_Number_of_stream = Spirent_Test_Infra['Total_Number_of_stream'] Initial_MAC_address = Spirent_Test_Infra['Initial_MAC_address'] ############################################################## # Creation of Spirent Test config with log file ############################################################## test_sta = sth.test_config( log='1', logfile='SteamConfig-WithPercentageTraffic_logfile', vendorlogfile='SteamConfig-WithPercentageTraffic_stcExport', vendorlog='1', hltlog='1', hltlogfile='SteamConfig-WithPercentageTraffic_hltExport', hlt2stcmappingfile='SteamConfig-WithPercentageTraffic_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if (status == '0'): print("run sth.test_config failed") ############################################################## # config the parameters for optimization and parsing ############################################################## test_ctrl_sta = sth.test_control(action='enable') status = test_ctrl_sta['status'] if (status == '0'): print("run sth.test_control failed") ############################################################## # connect to chassis and reserve port list ############################################################## i = 0 device = "10.91.113.124" port_list = list(Booked_ports.values()) Streams = list(Stream_Name.values()) port_handle = [] intStatus = sth.connect(device=device, port_list=port_list, break_locks=1, offline=0) status = intStatus['status'] if (status == '1'): for port in port_list: port_handle.append(intStatus['port_handle'][device][port]) i += 1 else: print("\nFailed to retrieve port handle!\n") # print(port_handle) print(port_handle) ############################################################## # Spirent Ports configuration ############################################################## for i in range(len(port_list)): int_ret0 = sth.interface_config(mode='config', port_handle=port_handle[i], create_host='false', intf_mode='ethernet', phy_mode='fiber', scheduling_mode='RATE_BASED', port_loadunit='PERCENT_LINE_RATE', port_load='50', enable_ping_response='0', control_plane_mtu='1500', flow_control='false', speed='ether1000', data_path_mode='normal', autonegotiation='1') status = int_ret0['status'] if (status == '0'): print("run sth.interface_config failed") # print(int_ret0) ############################################################## # create traffic ############################################################## streamblock_ret1 = sth.traffic_config( mode='create', port_handle=port_handle[0], l2_encap='ethernet_ii', l3_protocol='ipv4', ip_id='0', ip_src_addr='192.85.1.2', ip_dst_addr='192.0.0.1', ip_ttl='255', ip_hdr_length='5', ip_protocol='253', ip_fragment_offset='0', ip_mbz='0', ip_precedence='0', ip_tos_field='0', mac_dst_mode='increment', mac_dst_repeat_count='0', mac_dst_count='50', mac_src_count='50', mac_src_mode='increment', mac_src_repeat_count='0', mac_src='00:10:94:00:00:02', mac_dst='00:00:01:00:00:01', enable_control_plane='0', l3_length='4982', name='StreamBlock_11', fill_type='constant', fcs_error='0', fill_value='0', frame_size='2000', traffic_state='1', high_speed_result_analysis='1', length_mode='fixed', dest_port_list=port_handle[1], tx_port_sending_traffic_to_self_en='false', disable_signature='0', enable_stream_only_gen='1', pkts_per_burst='1', inter_stream_gap_unit='bytes', burst_loop_count='6000', transmit_mode='continuous', inter_stream_gap='12', rate_mbps='800', mac_discovery_gw='192.85.1.1', enable_stream='false') status = streamblock_ret1['status'] if (status == '0'): print("run sth.traffic_config failed") print(streamblock_ret1) else: print("***** run sth.traffic_config successfully") streamblock_ret2 = sth.traffic_config( mode='create', port_handle=port_handle[1], l2_encap='ethernet_ii', l3_protocol='ipv4', ip_id='0', ip_src_addr='192.85.1.2', ip_dst_addr='192.0.0.1', ip_ttl='255', ip_hdr_length='5', ip_protocol='253', ip_fragment_offset='0', ip_mbz='0', ip_precedence='0', ip_tos_field='0', mac_dst_mode='increment', mac_dst_repeat_count='0', mac_dst_count='50', mac_src_count='50', mac_src_mode='increment', mac_src_repeat_count='0', mac_src='00:00:01:00:00:01', mac_dst='00:10:94:00:00:02', enable_control_plane='0', l3_length='4982', name='StreamBlock_12', fill_type='constant', fcs_error='0', fill_value='0', frame_size='5000', traffic_state='1', high_speed_result_analysis='1', length_mode='fixed', dest_port_list=port_handle[0], tx_port_sending_traffic_to_self_en='false', disable_signature='0', enable_stream_only_gen='1', pkts_per_burst='1', inter_stream_gap_unit='bytes', burst_loop_count='6000', transmit_mode='continuous', inter_stream_gap='12', rate_mbps='800', mac_discovery_gw='192.85.1.1', enable_stream='false') status = streamblock_ret2['status'] if (status == '0'): print("run sth.traffic_config failed") print(streamblock_ret2) else: print("***** run sth.traffic_config successfully") # config part is finished ############################################################# # start traffic ############################################################## print("Traffic Started First Time") traffic_ctrl_ret = sth.traffic_control( port_handle=[port_handle[0], port_handle[1]], action='run', duration='30') time.sleep(60) print("After Aging Timer") traffic_ctrl_ret = sth.traffic_control( port_handle=[port_handle[0], port_handle[1]], action='clear_stats') print("Delay before Second Traffic Started Second Time") time.sleep(60) print("Traffic Started Second Time") traffic_ctrl_ret = sth.traffic_control( port_handle=[port_handle[0], port_handle[1]], action='run', duration='10') status = traffic_ctrl_ret['status'] if (status == '0'): print("run sth.traffic_control failed") # print(traffic_ctrl_ret) print("Test Traffic Stopped now adding delay before collecting stats") time.sleep(70) print("Traffic collection started") ############################################################## # start to get the traffic results ############################################################## traffic_results_ret = sth.traffic_stats( port_handle=[port_handle[0], port_handle[1]], mode='all') print("Traffic collection stopped") status = traffic_results_ret['status'] if (status == '0'): print("run sth.traffic_stats failed") pprint(traffic_results_ret) cleanup_sta = sth.cleanup_session( port_handle=[port_handle[0], port_handle[1]], clean_dbfile='1') print("Port Cleanedup") ############################################################## # Get required values from Stats ############################################################## traffic_result = str(traffic_results_ret) # regex to get rx, tx and streams from traffic_results_ret RX = '(streamblock\d+)\S+\s+\S+(rx)\S+\s+\S+total_pkt_bytes\S+\s+\S(\d+)' TX = '(streamblock\d+).*?(tx)\S+\s+\S+total_pkt_bytes\S+\s+\S(\d+)' StreamBlock = 'streamblock\d+' print('Spirent Ports= ' + str(port_list) + '\nTotal Ports= ' + str(len(port_list))) PortStatus = 'Spirent Ports= ' + str(port_list) + '\nTotal Ports= ' + str( len(port_list)) StreamBlock = re.findall(StreamBlock, traffic_result) print('Stream Configured= ' + str(StreamBlock) + '\nTotal Streams= ' + str(len(StreamBlock))) StreamStatus = 'Stream Configured= ' + str( StreamBlock) + '\nTotal Streams= ' + str(len(StreamBlock)) rx_stats = re.findall(RX, traffic_result) tx_stats = re.findall(TX, traffic_result) print('rx_stats= ' + str(rx_stats)) print('tx_stats= ' + str(tx_stats)) stats = 'rx_stats= ' + str(rx_stats) + '\ntx_stats= ' + str(tx_stats) StreamResult = [] for i in range(0, len(StreamBlock)): if rx_stats[i][2] == tx_stats[i][2]: print(str(rx_stats[i][0] + ' = pass')) StreamResult.append('pass') else: print(str(rx_stats[i][0] + ' = fail')) StreamResult.append('fail') print(str(StreamResult)) OverallStatus = '\n' + PortStatus + '\n' + StreamStatus + '\n' + stats + '\n' + str( StreamResult) # print(OverallStatus) return OverallStatus
name = port print "Saving capture to : " + name sth.invoke( 'stc::perform SaveSelectedCaptureData -CaptureProxyId %s -filename %s.pcap' % (captureHnd, name)) fileNameList.append('%s.pcap' % name) print "Save file Name list = %s" % fileNameList return fileNameList #Config the parameters for the logging test_sta = sth.test_config( log='1', logfile='HLTAPI_MPLS_Martini_PWE_Multiple_CE_logfile', vendorlogfile='HLTAPI_MPLS_Martini_PWE_Multiple_CE_stcExport', vendorlog='1', hltlog='1', hltlogfile='HLTAPI_MPLS_Martini_PWE_Multiple_CE_hltExport', hlt2stcmappingfile='HHLTAPI_MPLS_Martini_PWE_Multiple_CE_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1.Reserve and connect chassis ports ########################################
# c:>python HLTAPI_EOAM_MSG_802.1AG_VLAN.py 10.61.44.2 3/1 3/3 # import sth import time from sys import argv filename, device, port1, port2 = argv port_list = [port1, port2] port_handle = [] #Config the parameters for the logging test_sta = sth.test_config( log='1', logfile='HLTAPI_EOAM_MSG_802.1AG_VLAN_logfile', vendorlogfile='HLTAPI_EOAM_MSG_802.1AG_VLAN_stcExport', vendorlog='1', hltlog='1', hltlogfile='HLTAPI_EOAM_MSG_802.1AG_VLAN_hltExport', hlt2stcmappingfile='HHLTAPI_EOAM_MSG_802.1AG_VLAN_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1. Reserve and connect chassis ports ########################################
# c:>python HLTAPI_IGMP_Querier.py 10.61.44.2 3/1 3/3 import sth import time from sys import argv filename, device, port1, port2 = argv port_list = [port1, port2] port_handle = [] captureFlag = 0 #Config the parameters for the logging test_sta = sth.test_config( log='1', logfile='HLTAPI_Igmp_Querier_logfile', vendorlogfile='HLTAPI_Igmp_Querier_stcExport', vendorlog='1', hltlog='1', hltlogfile='HLTAPI_Igmp_Querier_hltExport', hlt2stcmappingfile='HLTAPI_Igmp_Querier_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1. Reserve and connect chassis ports ########################################
print " " else: print "%s Properties" % lbl print "================" handle_list = sth.invoke('stc::get %s' % handle) handle_list1 = handle_list.split(" -") for i in handle_list1: print i #Config the parameters for the logging test_sta = sth.test_config( log='1', logfile='HLTAPI_PIM_HighScale_logfile', vendorlogfile='HLTAPI_PIM_HighScale_stcExport', vendorlog='1', hltlog='1', hltlogfile='HLTAPI_PIM_HighScale_hltExport', hlt2stcmappingfile='HLTAPI_PIM_HighScale_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1. Reserve and connect chassis ports ########################################
# c:>python HLTAPI_PPPox_IPv6_Traffic.py 10.61.44.2 3/1 3/3 import sth import time from sys import argv filename, device, port1, port2 = argv port_list = [port1, port2] port_handle = [] #Config the parameters for the logging test_sta = sth.test_config( log='1', logfile='pppoe_ipv6_traffic_logfile', vendorlogfile='pppoe_ipv6_traffic_stcExport', vendorlog='1', hltlog='1', hltlogfile='pppoe_ipv6_traffic_hltExport', hlt2stcmappingfile='pppoe_ipv6_traffic_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## #Step1. Reserve and connect chassis ports ########################################
# c:\>python HLTAPI_IGMPoPPPoE.py 10.61.44.2 1/1 1/2 import sth import time from sys import argv filename, device, port1, port2 = argv port_list = [port1, port2] port_handle = [] #Config the parameters for the logging test_sta = sth.test_config( log='1', logfile='HLTAPI_IGMPoPPPoE_logfile', vendorlogfile='HLTAPI_IGMPoPPPoE_stcExport', vendorlog='1', hltlog='1', hltlogfile='HLTAPI_IGMPoPPPoE_hltExport', hlt2stcmappingfile='HHLTAPI_IGMPoPPPoE_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1. Reserve and connect chassis ports ########################################
def Port_Init(self): Spirent_Test_Infrastructure = Get_Spirent_Config() Number_of_ports = Spirent_Test_Infrastructure['Number_of_ports'] ############################################################## # Creation of Spirent Test config with log file ############################################################## test_sta = sth.test_config( log='1', logfile='SteamConfig-WithPercentageTraffic_logfile', vendorlogfile='SteamConfig-WithPercentageTraffic_stcExport', vendorlog='1', hltlog='1', hltlogfile='SteamConfig-WithPercentageTraffic_hltExport', hlt2stcmappingfile= 'SteamConfig-WithPercentageTraffic_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if (status == '0'): print("run sth.test_config failed") ############################################################## # config the parameters for optimization and parsing ############################################################## test_ctrl_sta = sth.test_control(action='enable') status = test_ctrl_sta['status'] if (status == '0'): print("run sth.test_control failed") ############################################################## # connect to chassis and reserve port list ############################################################## i = 0 device = Spirent_Test_Infrastructure['Spirent_Chassis_ip'] port_list = list(Spirent_Test_Infrastructure['Port_Values'].values()) self.port_list = port_list port_speed = list(Spirent_Test_Infrastructure['Port_Speed'].values()) port_mode = list(Spirent_Test_Infrastructure['Port_Phy_Mode'].values()) intStatus = sth.connect(device=device, port_list=port_list, break_locks=1, offline=0) status = intStatus['status'] if (status == '1'): for port in port_list: self.port_handle.append(intStatus['port_handle'][device][port]) i += 1 else: print("\nFailed to retrieve port handle!\n") # print(self.port_handle) print(self.port_handle) ############################################################## # Spirent Ports configuration ############################################################## for i in range(len(port_list)): if port_mode[i] == 'copper': int_ret0 = sth.interface_config( mode='config', port_handle=self.port_handle[i], create_host='false', intf_mode='ethernet', phy_mode=port_mode[i], scheduling_mode='RATE_BASED', port_loadunit='PERCENT_LINE_RATE', port_load='50', enable_ping_response='0', control_plane_mtu='1500', speed=port_speed[i], autonegotiation='1', duplex='full') status = int_ret0['status'] if (status == '0'): print("run sth.interface_config failed") # print(int_ret0) else: int_ret0 = sth.interface_config( mode='config', port_handle=self.port_handle[i], create_host='false', intf_mode='ethernet', phy_mode=port_mode[i], scheduling_mode='RATE_BASED', port_loadunit='PERCENT_LINE_RATE', port_load='50', enable_ping_response='0', control_plane_mtu='1500', flow_control='false', speed=port_speed[i], data_path_mode='normal', autonegotiation='1') status = int_ret0['status'] if (status == '0'): print("run sth.interface_config failed")
def Execute_Loopback_Test(self): def command_ouput(self, interface_name_list, device_list): print("**** statistic of traffic on both devices") for uni_port, device in zip(interface_name_list, device_list): net_connect = Netmiko(**device) command = 'show policy-map interface {}.{} | utility egrep "Match\|input\|output\|Drop"'.format( uni_port, self.sub_interface) command_ouput = net_connect.send_command("show run hostname") command_ouput += net_connect.send_command(command) print(command_ouput) net_connect.disconnect() def clear_QOS_ouput(self, interface_name_list, device_list): print("**** clearing statistic on both devices") for uni_port, device in zip(interface_name_list, device_list): net_connect = Netmiko(**device) command = 'clear qos counters interface {}.{}'.format( uni_port, self.sub_interface) command_ouput = net_connect.send_command(command) print(command_ouput) net_connect.disconnect() def Command_Creation(self, filename, item1, item2, inter_exter, loop_id, **interface_name): if inter_exter == 'internal': dict_to_render = { 'main_inf': interface_name['deviceB'], 'sub_if': self.sub_interface, 'internal_external': inter_exter, 'Loop_id': loop_id } else: dict_to_render = { 'main_inf': interface_name['deviceA'], 'sub_if': self.sub_interface, 'internal_external': inter_exter, 'Loop_id': loop_id } with open(filename, 'r') as f: Temp = f.read() failure_command = Template(Temp).render(**dict_to_render) f.close() file_open = open( self.file_path + "/Loopback_Commands/" + str(item1) + "_Loop_" + str(inter_exter) + "_" + str(item2) + "_command.txt", 'w+') file_open.write(failure_command) file_open.write('\n') file_open.close() def netmiko_Set_config(self, item1, inter_exter): if inter_exter == 'internal': net_connect = Netmiko(**self.deviceB) print('***** log in to device {}'.format(self.deviceB['host'])) else: net_connect = Netmiko(**self.deviceA) print('***** log in to device {}'.format(self.deviceA['host'])) f = open( self.file_path + "/Loopback_Commands/" + str(item1) + "_Loop_" + str(inter_exter) + "_Set_command.txt", 'r') f2 = f.readlines() clear_QOS_ouput(self, self.interface_name_list, self.device_list) output = net_connect.send_config_set(f2) net_connect.commit() net_connect.exit_config_mode() print(output) command = "show ethernet loopback active | include ID" show_output = net_connect.send_command(command) if item1 == "L2": show_output_list = show_output.split(" ") loop_id_to_render = show_output_list[-1] if loop_id_to_render != "1": print("**** doing rendering one more time") Command_Creation(self, location, item1, item2, inter_exter, loop_id_to_render, **self.interface_name) net_connect.disconnect() def netmiko_Release_config(self, item1, inter_exter): if inter_exter == 'internal': net_connect = Netmiko(**self.deviceB) print('***** log in to device {}'.format(self.deviceB['host'])) else: net_connect = Netmiko(**self.deviceA) print('***** log in to device {}'.format(self.deviceA['host'])) f = open( self.file_path + "/Loopback_Commands/" + str(item1) + "_Loop_" + str(inter_exter) + "_Release_command.txt", 'r') f2 = f.readlines() time.sleep(15) command_ouput(self, self.interface_name_list, self.device_list) output = net_connect.send_config_set(f2) net_connect.commit() net_connect.exit_config_mode() print(output) net_connect.disconnect() def spirent_traffic(self, steam_name, item1, inter_exter): stream = steam_name['stream_id'] traffic_ctrl_ret = sth.traffic_control(stream_handle=[stream], action='run', traffic_start_mode='sync', duration='30') status = traffic_ctrl_ret['status'] if (status == '0'): print("run sth.traffic_control failed") print(traffic_ctrl_ret) else: print("***** run sth.traffic started successfully") traffic_results_ret = sth.traffic_stats( port_handle=[port_handle[0], port_handle[1]], mode='all') status = traffic_results_ret['status'] if (status == '0'): print("run sth.traffic_stats failed") print(traffic_results_ret) else: print( "***** run sth.traffic_stats successfully, and results is:" ) pprint(traffic_results_ret) # pprint(traffic_results_ret1) deviceA_tx = traffic_results_ret[ port_handle[0]]['aggregate']['tx']['pkt_count'] deviceA_rx = traffic_results_ret[ port_handle[0]]['aggregate']['rx']['pkt_count'] deviceB_tx = traffic_results_ret[ port_handle[1]]['aggregate']['tx']['pkt_count'] deviceB_rx = traffic_results_ret[ port_handle[1]]['aggregate']['rx']['pkt_count'] if deviceA_rx == deviceA_tx: print("***************** " + str(item1) + " " + str(inter_exter) + "Test has Passed") print("**** No of Rx packets on deviceA are: " + str(deviceA_rx)) print("**** No of Tx packets on deviceA are: " + str(deviceA_tx)) test_result = 'Passed' elif deviceB_rx == deviceA_tx: print("***************** " + str(item1) + " " + str(inter_exter) + "Test has failed") print("**** No of Rx packets on deviceB are: " + str(deviceB_rx)) print("**** No of Tx packets on deviceA are: " + str(deviceA_tx)) print("**** No of Rx packets on deviceA are: " + str(deviceA_rx)) print("**** No of Tx packets on deviceB are: " + str(deviceB_tx)) test_result = 'Fail' # It was mentioned as 'Failed' else: print("something wrong") test_result = 'something wrong' dict_name = '{}_{}_result'.format(item1, inter_exter) dict_local = {} dict_local['deviceA_tx'] = deviceA_tx dict_local['deviceA_rx'] = deviceA_rx dict_local['deviceB_tx'] = deviceB_tx dict_local['deviceB_rx'] = deviceB_rx dict_local['result'] = test_result dict_local['Traffic_rate'] = self.traffic_rate self.dict_result[dict_name] = dict_local traffic_ctrl_ret = sth.traffic_control( port_handle=[port_handle[0], port_handle[1]], action='clear_stats') if self.serv_type == "PP": pass elif self.serv_type == "PPLLF": self.sub_interface = None else: pass for k, v in self.interface_name.items(): self.interface_name_list.append(v) ############################################################## # config the parameters for the logging ############################################################## test_sta = sth.test_config( log='0', logfile='Loopback_logfile', vendorlogfile='Loopback_stcExport', vendorlog='0', hltlog='1', hltlogfile='Loopback_hltExport', hlt2stcmappingfile='Loopback_hlt2StcMapping', hlt2stcmapping='1', log_level='0') status = test_sta['status'] if (status == '0'): print("run sth.test_config failed") print(test_sta) else: print("***** run sth.test_config successfully") ############################################################## # config the parameters for optimization and parsing ############################################################## test_ctrl_sta = sth.test_control(action='enable') status = test_ctrl_sta['status'] if (status == '0'): print("run sth.test_control failed") print(test_ctrl_sta) else: print("***** run sth.test_control successfully") ############################################################## # connect to chassis and reserve port list ############################################################## i = 0 device = "10.91.113.124" port_handle = [] intStatus = sth.connect(device=device, port_list=self.port_list, break_locks=1, offline=0) status = intStatus['status'] if (status == '1'): for port in self.port_list: port_handle.append(intStatus['port_handle'][device][port]) print("\n reserved ports", port, ":", port_handle[i]) i += 1 else: print("\nFailed to retrieve port handle!\n") print(port_handle) ############################################################## # interface config ############################################################## if self.port_speed == "ether1000": for i in range(2): interface = 'int_ret_{}'.format(i) interface = sth.interface_config( mode='config', port_handle=port_handle[i], create_host='false', intf_mode='ethernet', phy_mode=self.copper_fiber, scheduling_mode='RATE_BASED', port_loadunit='PERCENT_LINE_RATE', port_load='10', enable_ping_response='0', control_plane_mtu='1500', flow_control='false', speed=self.port_speed, data_path_mode='normal', autonegotiation='1') status = interface['status'] if (status == '0'): print("run sth.interface_config failed") print(interface) else: print( '***** run sth.interface_config deviceA_{} successfully with 1G speed' .format(i)) else: for i in range(2): interface = 'int_ret_{}'.format(i) interface = sth.interface_config( mode='config', port_handle=port_handle[i], create_host='false', intf_mode='ethernet', phy_mode=self.copper_fiber, scheduling_mode='RATE_BASED', port_loadunit='PERCENT_LINE_RATE', port_load='10', enable_ping_response='0', control_plane_mtu='1500', flow_control='false', speed=self.port_speed, data_path_mode='normal', autonegotiation='1', duplex='full') status = interface['status'] if (status == '0'): print("run sth.interface_config failed") print(interface) else: print( '***** run sth.interface_config deviceA_{} successfully with 10G speed' .format(i)) if self.serv_type == "FF" or self.serv_type == "PP": streamblock_retFF = sth.traffic_config( mode='create', port_handle=port_handle[0], l2_encap='ethernet_ii_vlan', mac_src=self.mac['SMAC'], mac_dst=self.mac['DMAC'], vlan_cfi='0', vlan_tpid='33024', vlan_id=self.F_vlan, vlan_user_priority='2', enable_control_plane='0', l3_length='9078', name='StreamBlock_F-F', fill_type='constant', fcs_error='0', fill_value='0', frame_size='9100', traffic_state='1', high_speed_result_analysis='1', length_mode='fixed', tx_port_sending_traffic_to_self_en='false', disable_signature='0', enable_stream_only_gen='1', pkts_per_burst='1', inter_stream_gap_unit='bytes', burst_loop_count='30', transmit_mode='continuous', inter_stream_gap='12', rate_mbps=self.traffic_rate) status = streamblock_retFF['status'] if (status == '0'): print("run sth.traffic_config failed") print(streamblock_retFF) else: print( "***** run sth.traffic_config StreamBlock_F-F on DeviceA successfully" ) elif self.serv_type == "XX": streamblock_retXX = sth.traffic_config( mode='create', port_handle=port_handle[0], l2_encap='ethernet_ii_vlan', mac_src=self.mac['SMAC'], mac_dst=self.mac['DMAC'], vlan_outer_cfi='0', vlan_outer_tpid='33024', vlan_outer_user_priority='2', vlan_id_outer=self.deviceA_X_VLAN, vlan_cfi='0', vlan_tpid='33024', vlan_id=self.deviceB_X_VLAN, vlan_user_priority='2', enable_control_plane='0', l3_length='9074', name='StreamBlock_X-X', fill_type='constant', fcs_error='0', fill_value='0', frame_size='9100', traffic_state='1', high_speed_result_analysis='1', length_mode='fixed', tx_port_sending_traffic_to_self_en='false', disable_signature='0', enable_stream_only_gen='1', pkts_per_burst='1', inter_stream_gap_unit='bytes', burst_loop_count='30', transmit_mode='continuous', inter_stream_gap='12', rate_mbps=self.traffic_rate) status = streamblock_retXX['status'] if (status == '0'): print("run sth.traffic_config failed") print(streamblock_retXX) else: print( "***** run sth.traffic_config StreamBlock_X-X on DeviceA successfully" ) elif self.serv_type == "YF": streamblock_retYF = sth.traffic_config( mode='create', port_handle=port_handle[0], l2_encap='ethernet_ii_vlan', mac_src=self.mac['SMAC'], mac_dst=self.mac['DMAC'], vlan_outer_cfi='0', vlan_outer_tpid='34984', vlan_outer_user_priority='2', vlan_id_outer=self.deviceA_Y_VLAN[0], vlan_cfi='0', vlan_tpid='33024', vlan_id=self.deviceA_Y_VLAN[1], vlan_user_priority='2', enable_control_plane='0', l3_length='9074', name='StreamBlock_Y-F', fill_type='constant', fcs_error='0', fill_value='0', frame_size='9100', traffic_state='1', high_speed_result_analysis='1', length_mode='fixed', tx_port_sending_traffic_to_self_en='false', disable_signature='0', enable_stream_only_gen='1', pkts_per_burst='1', inter_stream_gap_unit='bytes', burst_loop_count='30', transmit_mode='continuous', inter_stream_gap='12', rate_mbps=self.traffic_rate) status = streamblock_retYF['status'] if (status == '0'): print("run sth.traffic_config failed") print(streamblock_retYF) else: print( "***** run sth.traffic_config StreamBlock_Y-F on deviceA successfully" ) else: print("No streams are created") ############################################################## # start devices ############################################################## for item1 in self.List1: if item1 == "L2": inter_exter_list = ['internal', 'external'] else: inter_exter_list = ['internal', 'external', 'line'] for inter_exter in inter_exter_list: for item2 in self.List2: location = self.file_path + "/Loopback_Template/" + "tem_" + item1 + "_Loop_" + item2 + "_command.j2" Command_Creation(self, location, item1, item2, inter_exter, self.loop_id, **self.interface_name) print("**** Templateing Done for " + str(item1) + " " + str(inter_exter) + " & " + str(item2) + " command") for item1 in self.List1: if item1 == "L2": inter_exter_list = ['internal', 'external'] else: inter_exter_list = ['internal', 'external', 'line'] for inter_exter in inter_exter_list: print("**** perform " + str(item1) + " " + str(inter_exter) + " Loop ") netmiko_Set_config(self, item1, inter_exter) if self.serv_type == "FF" or self.serv_type == "PP": spirent_traffic(self, streamblock_retFF, item1, inter_exter) elif self.serv_type == "XX": spirent_traffic(self, streamblock_retXX, item1, inter_exter) elif self.serv_type == "YF": spirent_traffic(self, streamblock_retYF, item1, inter_exter) else: print("something wrong, streams can not be started") print("**** Release " + str(item1) + " " + str(inter_exter) + " Loop ") netmiko_Release_config(self, item1, inter_exter) time.sleep(30) ############################################################## # clean up the session, release the ports reserved and cleanup the dbfile ############################################################## cleanup_sta = sth.cleanup_session( port_handle=[port_handle[0], port_handle[1]], clean_dbfile='1') status = cleanup_sta['status'] if (status == '0'): print("run sth.cleanup_session failed") print(cleanup_sta) else: print("***** run sth.cleanup_session successfully") print("**************Finish***************") print(json.dumps(self.dict_result, indent=4)) Final_Result = [] for result in self.dict_result.values(): Final_Result.append(result["result"]) return (Final_Result)
# Run sample: # c:\>python HLTAPI_ISIS_SR.py 10.61.44.2 1/1 1/2 import sth import time from sys import argv filename, device, port1, port2 = argv port_list = [port1, port2] port_handle = [] #Config the parameters for the logging test_sta = sth.test_config(log='1', logfile='isis_logfile', vendorlogfile='isis_stcExport', vendorlog='1', hltlog='1', hltlogfile='isis_hltExport', hlt2stcmappingfile='isis_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## # Step1. Reserve and connect chassis ports ########################################
# Run sample: # c:\>python HLTAPI_NOKIA_CUSTOMIZE_HEADER.py 10.61.44.2 1/1 import sth import time from sys import argv filename, device, port1 = argv port_list = [port1] port_handle = [] #Config the parameters for the logging test_sta = sth.test_config( log='1', logfile='nokia_customize_header_logfile', vendorlogfile='nokia_customize_header_stcExport', vendorlog='1', hltlog='1', hltlogfile='nokia_customize_header_hltExport', hlt2stcmappingfile='nokia_customize_header_hlt2StcMapping', hlt2stcmapping='1', log_level='7') status = test_sta['status'] if status == '0': print "run sth.test_config failed" print test_sta else: print "***** run sth.test_config successfully" ######################################## #Step1. Reserve and connect chassis ports ########################################