def validate_init(before, after): mylinks = tntapi.parse_network_links(before) t1 = tntapi.parse_network_nodes(before) t2 = tntapi.parse_network_nodes(after) delta = tntapi.get_network_counters_delta(before, after) testsuiteapi.print_state(before, after) after = tntapi.strip_namespaces(after) #validate no counters were incremented for node in {"analyzer"}: for if_name in {"ge0", "ge1", "xe0", "xe1"}: interface = delta[node][if_name] for v in dir(interface): if not v[0].startswith( '_') and not v == 'count' and not v == 'index': value = getattr(interface, v) if (value != None and value != 0): print node + ":" + if_name + "." + v + "=" + str(value) assert (0) for node in {"local", "remote"}: for if_name in {"xe0", "ge15", "ge0"}: interface = delta[node][if_name] for v in dir(interface): if not v[0].startswith( '_') and not v == 'count' and not v == 'index': value = getattr(interface, v) if (value != None and value != 0): print node + ":" + if_name + "." + v + "=" + str(value) assert (0)
def get_traffic_stats(dst_node, dst_node_interface, src_node, src_node_interface, before, after, delta, my_test_time, frame_size, interframe_gap, frames_per_burst, interburst_gap, total_frames): global args before=tntapi.strip_namespaces(before) after=tntapi.strip_namespaces(after) #generated_octets=1.0*delta[src_node][src_node_interface].out_octets #generated_pkts=generated_octets/(frame_size-4) generated_pkts = total_frames generated_octets = total_frames*frame_size #assert(delta[src_node][src_node_interface].out_unicast_pkts==generated_pkts) #assert(generated_octets>0) print("generated_octets="+str(generated_octets)) testframe_pkts_nodes = after.xpath("""node[node-id='%s']/data/interfaces/interface[name='%s']/traffic-analyzer/state/testframe-stats/testframe-pkts"""%(dst_node, dst_node_interface)) if(len(testframe_pkts_nodes) == 1): rx_testframe_pkts=1.0*get_delta_counter(before,after,dst_node,"""/interfaces/interface[name='%s']/traffic-analyzer/state/testframe-stats/testframe-pkts"""%(dst_node_interface)) # assert(rx_testframe_pkts>0) else: rx_testframe_pkts=None assert(0) sequence_errors_nodes = after.xpath("""node[node-id='%s']/data/interfaces/interface[name='%s']/traffic-analyzer/state/testframe-stats/sequence-errors"""%(dst_node, dst_node_interface)) if(len(sequence_errors_nodes) == 1): sequence_errors=get_delta_counter(before,after,dst_node,"""/interfaces/interface[name='%s']/traffic-analyzer/state/testframe-stats/sequence-errors"""%(dst_node_interface)) else: sequence_errors=None rx_in_pkts=1.0*long(after.xpath("""node[node-id='%s']/data/interfaces/interface[name='%s']/traffic-analyzer/state/pkts"""%(dst_node, dst_node_interface))[0].text) latency_nodes = after.xpath("""node[node-id='%s']/data/interfaces/interface[name='%s']/traffic-analyzer/state/testframe-stats/latency"""%(dst_node, dst_node_interface)) if(len(latency_nodes) == 1): latency_min = long(after.xpath("node[node-id='%s']/data/interfaces/interface[name='%s']/traffic-analyzer/state/testframe-stats/latency/min"%(dst_node, dst_node_interface))[0].text) latency_max = long(after.xpath("node[node-id='%s']/data/interfaces/interface[name='%s']/traffic-analyzer/state/testframe-stats/latency/max"%(dst_node, dst_node_interface))[0].text) #latency_average = long(after.xpath("node[node-id='%s']/data/interfaces/interface[name='%s']/traffic-analyzer/state/testframe-stats/latency/average"%(dst_node, dst_node_interface))[0].text) latency_average=None else: latency_min=None latency_max=None latency_average=None return (rx_in_pkts, rx_testframe_pkts, generated_pkts, sequence_errors, latency_min, latency_max, latency_average)
def validate_step_common(before, after, step, with_sm, with_gst): mylinks = tntapi.parse_network_links(before) t1 = tntapi.parse_network_nodes(before) t2 = tntapi.parse_network_nodes(after) delta = tntapi.get_network_counters_delta(before,after) testsuiteapi.print_state(before, after) after=tntapi.strip_namespaces(after) print("#1.1 - Asserts for step_%d."%(step)) if(with_sm): assert(delta["analyzer"]['xe0'].testframe_payload_errors==0) latency_min=after.xpath("node[node-id='analyzer']/data/interfaces-state/interface[name='xe0']/traffic-analyzer/testframe-stats/latency/min")[0].text latency_max=after.xpath("node[node-id='analyzer']/data/interfaces-state/interface[name='xe0']/traffic-analyzer/testframe-stats/latency/max")[0].text pdv=int(latency_max)-int(latency_min) print("SM LAT_MIN=%d ns"%(int(latency_min))) print("SM LAT_MAX=%d ns"%(int(latency_max))) print("SM PDV=%d ns"%(pdv)) assert(delta["analyzer"]['xe0'].out_pkts>=1000000) sum=0; for interface in {"ge0", "ge1", "ge2", "ge3", "ge4", "ge5", "ge6", "ge7", "ge8", "ge9"}: sum=sum+delta["local"][interface].fusion_ep_to_np1_sm_buf_overflows sum=sum+delta["local"][interface].fusion_np1_to_ep_sm_drop_reinsert_buf_overflows print("sum(fusion_ep_to_np1_sm_buf_overflows+fusion_np1_to_ep_sm_drop_reinsert_buf_overflows)=%d"%(sum)) if(step>=2): assert(delta["analyzer"]['xe0'].out_pkts==delta["analyzer"]['xe0'].in_pkts+sum) #assert(delta["analyzer"]['xe0'].testframe_sequence_errors==sum) else: assert(delta["analyzer"]['xe0'].out_pkts==delta["analyzer"]['xe0'].in_pkts) assert(sum==0) assert(delta["analyzer"]['xe0'].testframe_sequence_errors<=1) if(with_gst): assert(delta["analyzer"]['ge0'].testframe_payload_errors==0) assert(delta["analyzer"]['ge0'].out_pkts>=1000000) assert(delta["analyzer"]['ge0'].in_pkts>=1000000) assert((delta["analyzer"]['ge0'].in_pkts+delta["local"]['ge15'].fusion_np_tx_gst_multicast_contentions)==delta["analyzer"]['ge0'].out_pkts) sum=0; for interface in {"ge1", "ge2", "ge3", "ge4", "ge5", "ge6", "ge7", "ge8", "ge9"}: sum=sum+delta["local"][interface].fusion_ep_to_np0_gst_multicast_contentions print("sum(fusion_ep_to_np0_gst_multicast_contentions)=%d"%(sum)) assert(step==2 or delta["analyzer"]['ge0'].out_pkts==(sum/(step-2))) latency_min=after.xpath("node[node-id='analyzer']/data/interfaces-state/interface[name='ge0']/traffic-analyzer/testframe-stats/latency/min")[0].text latency_max=after.xpath("node[node-id='analyzer']/data/interfaces-state/interface[name='ge0']/traffic-analyzer/testframe-stats/latency/max")[0].text pdv=int(latency_max)-int(latency_min) print("GST LAT_MIN=%d ns"%(int(latency_min))) print("GST LAT_MAX=%d ns"%(int(latency_max))) print("GST PDV=%d ns"%(pdv)) assert(pdv<400) print("OK!")
def validate_traffic_on(node_name, interface_name, before, after, delta, my_test_time, load_percent, frame_size, interframe_gap, frames_per_burst, interburst_gap): global test_time after = tntapi.strip_namespaces(after) speed_bits_per_sec = long( after.xpath("node[node-id='" + node_name + "']/data/interfaces-state/interface[name='" + interface_name + "']/speed")[0].text) print "speed(bits/sec)=" + str(speed_bits_per_sec) print "speed(bytes/sec)=" + str(speed_bits_per_sec / 8) generated_octets = 1.0 * delta[node_name][interface_name].out_octets assert (generated_octets > 0) generated_pkts = 1.0 * delta[node_name][interface_name].out_pkts assert (generated_pkts > 0) assert ((generated_pkts * frame_size) == generated_octets) generated_octets_expected = (load_percent * test_time * speed_bits_per_sec / (8 * 100)) print("Generated octets per sec=" + str(generated_octets / test_time)) print("Expected octets per sec=" + str(generated_octets_expected / test_time)) ratio = generated_octets / generated_octets_expected if (ratio > 1): print( "Generated %(r).4f times MORE: generated=%(g)d and expected=%(e)d" % { 'r': ratio, 'g': generated_octets, 'e': generated_octets_expected }) if (ratio > (110.0 / 100)): print("Error: >10% precision deviation.") elif (ratio < 1): print( "Generated %(r).4f times LESS: generated=%(g)d and expected=%(e)d" % { 'r': 1 / ratio, 'g': generated_octets, 'e': generated_octets_expected }) if (ratio < (90.0 / 100)): print("Error: >10% precision deviation.") else: print("Generated EXACTLY: generated=%(g)s and expected=%(e)s" % { 'g': generated_octets, 'e': generated_octets_expected }) return float(100 * generated_octets / (my_test_time * speed_bits_per_sec / 8))
def validate_step_1(before, after): mylinks = tntapi.parse_network_links(before) t1 = tntapi.parse_network_nodes(before) t2 = tntapi.parse_network_nodes(after) delta = tntapi.get_network_counters_delta(before, after) testsuiteapi.print_state(before, after) after = tntapi.strip_namespaces(after) print("#1.1 - Validate all packets are received at their destinations.") assert (delta["analyzer"]["ge0"].in_unicast_pkts == 0 ) #total-frames not always implemented assert (delta["analyzer"]["ge1"].in_unicast_pkts == 0 ) #total-frames not always implemented assert (delta["analyzer"]["xe0"].out_unicast_pkts >= 1000000) assert (delta["analyzer"]["xe1"].out_unicast_pkts >= 1000000) assert (delta["analyzer"]["xe1"].out_unicast_pkts - delta["analyzer"]["xe0"].in_unicast_pkts == delta["local"] ["ge0"].fusion_np1_to_ep_sm_drop_reinsert_buf_overflows) assert (delta["analyzer"]["xe0"].out_unicast_pkts - delta["analyzer"]["xe1"].in_unicast_pkts == delta["remote"] ["ge0"].fusion_np1_to_ep_sm_drop_reinsert_buf_overflows) pkt_loss_remote_local = 100 * float( delta["analyzer"]["xe1"].out_unicast_pkts - delta["analyzer"] ["xe0"].in_unicast_pkts) / delta["analyzer"]["xe1"].out_unicast_pkts print("pkt_loss_remote_local=%f" % (pkt_loss_remote_local)) assert (pkt_loss_remote_local < 0.5) pkt_loss_local_remote = 100 * float( delta["analyzer"]["xe0"].out_unicast_pkts - delta["analyzer"] ["xe1"].in_unicast_pkts) / delta["analyzer"]["xe0"].out_unicast_pkts print("pkt_loss_local_remote=%f" % (pkt_loss_local_remote)) assert (pkt_loss_local_remote < 0.5) print( "#1.2 - Validate there are no testframe payload errors and testframe sequence errors are <=1." ) assert (delta["analyzer"]["xe0"].testframe_pkts == delta["analyzer"] ["xe0"].in_unicast_pkts) assert (delta["analyzer"]["xe0"].testframe_sequence_errors <= ( delta["local"]["ge0"].fusion_np1_to_ep_sm_drop_reinsert_buf_overflows + 1)) assert (delta["analyzer"]["xe0"].testframe_payload_errors == 0) assert (delta["analyzer"]["xe1"].testframe_pkts == delta["analyzer"] ["xe1"].in_unicast_pkts) assert ( delta["analyzer"]["xe1"].testframe_sequence_errors <= (delta["remote"]["ge0"].fusion_np1_to_ep_sm_drop_reinsert_buf_overflows + 1)) assert (delta["analyzer"]["xe1"].testframe_payload_errors == 0) return (pkt_loss_remote_local, pkt_loss_local_remote)
def validate_step_common(before, after, step): mylinks = tntapi.parse_network_links(before) t1 = tntapi.parse_network_nodes(before) t2 = tntapi.parse_network_nodes(after) delta = tntapi.get_network_counters_delta(before, after) testsuiteapi.print_state(before, after) after = tntapi.strip_namespaces(after) print("#1.1 - Asserts for step_%d." % (step)) if (step == 2): interfaces_off = {"ge5", "ge6", "ge7", "ge8", "ge9"} interfaces_on = {"ge0", "ge1", "ge2", "ge3", "ge4"} else: interfaces_off = {} interfaces_on = { "ge0", "ge1", "ge2", "ge3", "ge4", "ge5", "ge6", "ge7", "ge8", "ge9" } total_expected_xe0 = 0 for if_name in interfaces_on: print("Checking on: " + if_name) assert (delta["remote"][if_name].out_pkts >= 1000000) assert (delta["remote"][if_name].out_pkts == delta["remote"] [if_name].in_pkts) assert ( (delta["remote"][if_name].in_pkts - delta["local"][if_name].out_pkts) == ( delta["remote"][if_name].fusion_ep_to_np1_sm_buf_overflows + delta["local"] [if_name].fusion_np1_to_ep_sm_drop_reinsert_buf_overflows)) if (step == 2): assert (delta["remote"][if_name].fusion_ep_to_np1_sm_buf_overflows > 0) else: assert (delta["remote"][if_name].fusion_ep_to_np1_sm_buf_overflows == 0) total_expected_xe0 = total_expected_xe0 + delta["local"][ if_name].out_pkts #assert(total_expected_xe0==delta["local"]["xe0"].out_pkts) for if_name in interfaces_off: print("Checking off: " + if_name) assert (delta["local"][if_name].out_pkts == 0) print("Reults!") time.sleep(10)
def validate_step_2_4(before, after, name): mylinks = tntapi.parse_network_links(before) t1 = tntapi.parse_network_nodes(before) t2 = tntapi.parse_network_nodes(after) delta = tntapi.get_network_counters_delta(before,after) testsuiteapi.print_state(before, after) after=tntapi.strip_namespaces(after) print("#x.1 - Verify all packets are forwarded to their destinations.") assert(delta["analyzer"][name].out_unicast_pkts>=1000000) #total-frames not always implemented assert(delta["analyzer"]["ge0"].in_unicast_pkts==delta["analyzer"][name].out_unicast_pkts) latency_to_ge0=after.xpath("node[node-id='analyzer']/data/interfaces-state/interface[name='ge0']/traffic-analyzer/testframe-stats/latency/min")[0].text return int(latency_to_ge0)
def validate_step_1(before, after): mylinks = tntapi.parse_network_links(before) t1 = tntapi.parse_network_nodes(before) t2 = tntapi.parse_network_nodes(after) delta = tntapi.get_network_counters_delta(before,after) testsuiteapi.print_state(before, after) after=tntapi.strip_namespaces(after) print("#1.1 - Validate all analyzer interfaces have oper-status=up.") for node in {"analyzer"}: for if_name in {"ge0", "ge1", "xe0", "xe1"}: print "Checking %(node)s[%(if_name)s]"%{'node':node, 'if_name':if_name} oper_status=after.xpath("node[node-id='%(node)s']/data/interfaces-state/interface[name='%(if_name)s']/oper-status"%{'node':node, 'if_name':if_name})[0].text assert(oper_status=='up') print("#1.2 - Validate no counters are being incremented.") #validate no counters were incremented for node in {"analyzer"}: for if_name in {"ge0", "ge1", "xe0", "xe1"}: interface = delta[node][if_name] for v in dir(interface): if not v[0].startswith('_') and not v=='count' and not v=='index': value = getattr(interface,v) if(value!=None and value!=0): print node + ":" + if_name + "." + v + "=" + str(value) assert(0) for node in {"local", "remote"}: for if_name in {"xe0", "ge15", "ge0"}: interface = delta[node][if_name] for v in dir(interface): if not v[0].startswith('_') and not v=='count' and not v=='index': value = getattr(interface,v) if(value!=None and value!=0): print node + ":" + if_name + "." + v + "=" + str(value) assert(0)
def validate_traffic_on(node_name, interface_name, before, after, delta, my_test_time, load_percent, frame_size, interframe_gap, frames_per_burst, interburst_gap): global test_time global args print("validate_traffic_on %s" % (interface_name)) before = tntapi.strip_namespaces(before) after = tntapi.strip_namespaces(after) speed_bits_per_sec = long( after.xpath("node[node-id='" + node_name + "']/data/interfaces-state/interface[name='" + interface_name + "']/speed")[0].text) print "speed(bits/sec)=" + str(speed_bits_per_sec) print "speed(bytes/sec)=" + str(speed_bits_per_sec / 8) if (args.direction == 'ingress'): generated_pkts = 1.0 * delta[node_name][ interface_name].generated_ingress_pkts generated_octets = frame_size * generated_pkts else: generated_octets = 1.0 * delta[node_name][interface_name].out_octets #assert(delta[node_name][interface_name].out_multicast_pkts==0) #assert(delta[node_name][interface_name].out_unicast_pkts>0) generated_pkts = generated_octets / (frame_size - 4) print generated_pkts print delta[node_name][interface_name].out_unicast_pkts assert (delta[node_name][interface_name].out_unicast_pkts == generated_pkts) assert (generated_octets > 0) print("generated_octets=" + str(generated_octets)) if (args.test_internal_loopback == 'true'): looped_back_octets = 1.0 * delta[node_name][interface_name].in_octets print("looped_back_octets=" + str(looped_back_octets)) assert (looped_back_octets == generated_octets) if (args.test_analyzer == 'true'): if (args.direction == 'ingress'): analyzed_pkts = 1.0 * get_delta_counter( before, after, node_name, """/interfaces/interface[name='%s']/traffic-analyzer-egress/state/testframe-stats/testframe-pkts""" % (interface_name)) else: analyzed_pkts = 1.0 * get_delta_counter( before, after, node_name, """/interfaces/interface[name='%s']/traffic-analyzer/state/testframe-stats/testframe-pkts""" % (interface_name)) print("generated_pkts=" + str(generated_pkts)) print("analyzed_pkts=" + str(analyzed_pkts)) assert (generated_pkts == analyzed_pkts) generated_octets_expected = (load_percent * test_time * speed_bits_per_sec / (8 * 100)) print("Generated octets per sec=" + str(generated_octets / test_time)) print("Expected octets per sec=" + str(generated_octets_expected / test_time)) ratio = generated_octets / generated_octets_expected if (ratio > 1): print( "Generated %(r).4f times MORE: generated=%(g)d and expected=%(e)d" % { 'r': ratio, 'g': generated_octets, 'e': generated_octets_expected }) if (ratio > (110.0 / 100)): print("Error: >10% precision deviation.") elif (ratio < 1): print( "Generated %(r).4f times LESS: generated=%(g)d and expected=%(e)d" % { 'r': 1 / ratio, 'g': generated_octets, 'e': generated_octets_expected }) if (ratio < (90.0 / 100)): print("Error: >10% precision deviation.") else: print("Generated EXACTLY: generated=%(g)s and expected=%(e)s" % { 'g': generated_octets, 'e': generated_octets_expected }) return float(100 * generated_octets / (test_time * speed_bits_per_sec / 8))
def main(): before_config = etree.parse(sys.argv[1]) before_networks = before_config.xpath('/nc:config/nd:networks', namespaces=namespaces)[0] before_network = before_networks.xpath('nd:network', namespaces=namespaces)[0] after_config = etree.parse(sys.argv[2]) after_networks = after_config.xpath('/nc:config/nd:networks', namespaces=namespaces)[0] after_network = after_networks.xpath('nd:network', namespaces=namespaces)[0] t1 = tntapi.parse_network_nodes(before_network) t2 = tntapi.parse_network_nodes(after_network) delta = tntapi.get_network_counters_delta(before_network, after_network) before = tntapi.strip_namespaces(before_network) after = tntapi.strip_namespaces(after_network) print("1. Period:") print( "+------------+---------------------+---------------------+--------------+" ) print( "| node | start | stop | period |" ) print( "+------------+---------------------+---------------------+--------------+" ) node_period = {} nodes = after.xpath('node') for node in nodes: node_id = node.xpath('node-id')[0].text datetime_before = before.xpath( "node[node-id='%s']/data/system-state/clock/current-datetime" % (node_id)) datetime_after = after.xpath( "node[node-id='%s']/data/system-state/clock/current-datetime" % (node_id)) if (len(datetime_before) == 1 and len(datetime_after) == 1): dt_before = datetime.strptime(datetime_before[0].text[:19], '%Y-%m-%dT%H:%M:%S') dt_after = datetime.strptime(datetime_after[0].text[:19], '%Y-%m-%dT%H:%M:%S') node_period[node_id] = (dt_after - dt_before).total_seconds() #print("node:%s supports /system-state/clock/current-datetime calculated %f sec as period"%(node_id,node_period[node_id])) print("| %-10s | %s | %s | %+12s |" % (node_id, datetime_before[0].text[:19], datetime_after[0].text[:19], "%.3f" % node_period[node_id])) else: node_period[node_id] = period_default #print("node:%s does not support /system-state/clock/current-datetime using %f sec as period"%(node_id,node_period[node_id])) print( "+------------+---------------------+---------------------+--------------+" ) print("2. Data transfer rate:") print("+------------+--------------+-------+") print("| if name | MB/s | % |") print("+------------+--------------+-------+") rate = float(delta["middle"]["xe0"].in_octets) / (node_period["middle"]) print("| %s.%s | %9.0f | %3.0f |" % ("middle", "xe0", rate / (1024 * 1024), 100 * rate / (100000000000 / 8))) rate = float(delta["remote"]["xe0"].in_octets) / (node_period["remote"]) print("| %s.%s | %9.0f | %3.0f |" % ("remote", "xe0", rate / (1024 * 1024), 100 * rate / (100000000000 / 8))) print("+------------+--------------+-------+") print("") print("3. Timing:") print( "+-----------+--------------+-------------+--------------+---------------+" ) print( "| if name | delay-min | delay-max | PDV | samples |" ) print( "+-----------+--------------+-------------+--------------+---------------+" ) analyzer_enabled_ifs = ["ge1", "ge2", "ge3", "ge4"] for analyzer_enabled_if in analyzer_enabled_ifs: latency_max = int( after.xpath( "node[node-id='local']/data/interfaces-state/interface[name='%s']/traffic-analyzer/testframe-stats/latency/max" % (analyzer_enabled_if))[0].text) latency_min = int( after.xpath( "node[node-id='local']/data/interfaces-state/interface[name='%s']/traffic-analyzer/testframe-stats/latency/min" % (analyzer_enabled_if))[0].text) samples = int( after.xpath( "node[node-id='local']/data/interfaces-state/interface[name='%s']/traffic-analyzer/testframe-stats/latency/samples" % (analyzer_enabled_if))[0].text) print("| local.%s | %9d ns | %9d ns| %9d ns | %10d |" % (analyzer_enabled_if, latency_min, latency_max, latency_max - latency_min, samples)) print( "+-----------+--------------+-------------+--------------+---------------+" ) return 0
def main(): before_config = etree.parse(sys.argv[1]) before_networks = before_config.xpath('/nc:config/nd:networks', namespaces=namespaces)[0] before_network = before_networks.xpath('nd:network', namespaces=namespaces)[0] after_config = etree.parse(sys.argv[2]) after_networks = after_config.xpath('/nc:config/nd:networks', namespaces=namespaces)[0] after_network = after_networks.xpath('nd:network', namespaces=namespaces)[0] t1 = tntapi.parse_network_nodes(before_network) t2 = tntapi.parse_network_nodes(after_network) delta = tntapi.get_network_counters_delta(before_network, after_network) before = tntapi.strip_namespaces(before_network) after = tntapi.strip_namespaces(after_network) print("1. Period:") print( "+------------+---------------------+---------------------+--------------+" ) print( "| node | start | stop | period |" ) print( "+------------+---------------------+---------------------+--------------+" ) node_period = {} nodes = after.xpath('node') periods = tntapi.get_datetime_delta(before, after) for node in nodes: node_id = node.xpath('node-id')[0].text if (periods[node_id] != None): node_period[node_id] = periods[node_id] datetime_before = before.xpath( "node[node-id='%s']/data/system-state/clock/current-datetime" % (node_id)) datetime_after = after.xpath( "node[node-id='%s']/data/system-state/clock/current-datetime" % (node_id)) assert (len(datetime_before) == 1 and len(datetime_after) == 1) dt_before = datetime.strptime(datetime_before[0].text[:19], '%Y-%m-%dT%H:%M:%S') dt_after = datetime.strptime(datetime_after[0].text[:19], '%Y-%m-%dT%H:%M:%S') #node_period[node_id] = (dt_after-dt_before).total_seconds() #print("node:%s supports /system-state/clock/current-datetime calculated %f sec as period"%(node_id,node_period[node_id])) print("| %-10s | %s | %s | %+12s |" % (node_id, datetime_before[0].text[:19], datetime_after[0].text[:19], "%.3f" % node_period[node_id])) else: node_period[node_id] = period_default #print("node:%s does not support /system-state/clock/current-datetime using %f sec as period"%(node_id,node_period[node_id])) print( "+------------+---------------------+---------------------+--------------+" ) # ... TODO ietf-interfaces counters bandwidt ... return 0
def trial(network, conns, yconns, test_time=60, frame_size=1500, interframe_gap=20, interburst_gap=0, frames_per_burst=0, src_node=[], src_node_interface=[], dst_node=[], dst_node_interface=[], src_mac_address=[], dst_mac_address=[], frame_data=[], testframe_type=[]): global args filter ="" #"""<filter type="xpath" select="/*[local-name()='interfaces-state' or local-name()='interfaces']/interface/*[local-name()='traffic-analyzer' or local-name()='oper-status' or local-name()='statistics' or local-name()='speed']"/>""" config_idle={} print(dst_node) result=yangcli(yconns[dst_node],"""replace /interfaces/interface[name='%(name)s'] -- type=ethernetCsmacd"""%{'name':dst_node_interface}) ok = result.xpath('./ok') assert(len(ok)==1) ok=yangcli(yconns[src_node],"""replace /interfaces/interface[name='%(name)s'] -- type=ethernetCsmacd"""%{'name':src_node_interface}).xpath('./ok') assert(len(ok)==1) tntapi.network_commit(conns) ok=yangcli(yconns[dst_node],"""create /interfaces/interface[name='%(name)s']/traffic-analyzer"""%{'name':dst_node_interface}).xpath('./ok') assert(len(ok)==1) tntapi.network_commit(conns) if(frames_per_burst>0): my_burst_config="""frames-per-burst=%(frames-per-burst)d interburst-gap=%(interburst-gap)d""" % {'frames-per-burst':frames_per_burst,'interburst-gap':interburst_gap-8} else: my_burst_config="" generator_direction_suffix='' analyzer_direction_suffix='' state_before = tntapi.network_get_state(network, conns, filter=filter) state_before_wo_ns=tntapi.strip_namespaces(state_before) #speed=1000000000 # 1Gb speed = long(state_before_wo_ns.xpath("node[node-id='%s']/data/interfaces-state/interface[name='%s']/speed"%(src_node, src_node_interface))[0].text) if(frames_per_burst == 0): total_frames = int(math.floor(test_time*speed/((interframe_gap+frame_size)*8))) else: total_frames = int(math.floor(frames_per_burst*test_time*speed/(((frames_per_burst-1)*interframe_gap+frames_per_burst*frame_size+interburst_gap)*8))) testframe = "" if(testframe_type != []): testframe = "testframe-type=%s" % testframe_type print """create /interfaces/interface[name="%(name)s"]/traffic-generator -- frame-size=%(frame-size)d interframe-gap=%(interframe-gap)d total-frames=%(total-frames)s %(burst)s frame-data=%(frame-data)s %(testframe)s""" % {'name':src_node_interface,'frame-size':frame_size, 'interframe-gap':interframe_gap, 'burst':my_burst_config, 'total-frames':total_frames, 'frame-data':frame_data, 'testframe':testframe} ok=yangcli(yconns[src_node],"""create /interfaces/interface[name="%(name)s"]/traffic-generator -- frame-size=%(frame-size)d interframe-gap=%(interframe-gap)d total-frames=%(total-frames)s %(burst)s frame-data=%(frame-data)s %(testframe)s""" % {'name':src_node_interface,'frame-size':frame_size, 'interframe-gap':interframe_gap, 'burst':my_burst_config, 'total-frames':total_frames, 'frame-data':frame_data, 'testframe':testframe}).xpath('./ok') assert(len(ok)==1) state_before = tntapi.network_get_state(network, conns, filter=filter) tntapi.network_commit(conns) print("Waiting " + str(test_time) + " sec. ..." ) time.sleep(test_time+1) print("Stopping generators ...") ok=yangcli(yconns[src_node],"""delete /interfaces/interface[name='%(name)s']/traffic-generator"""%{'name':src_node_interface}).xpath('./ok') assert(len(ok)==1) tntapi.network_commit(conns) print("Done.") time.sleep(2) state_after = tntapi.network_get_state(network, conns, filter=filter) t1 = tntapi.parse_network_nodes(state_before) t2 = tntapi.parse_network_nodes(state_after) delta = tntapi.get_network_counters_delta(state_before,state_after) tntapi.print_state_ietf_interfaces_statistics_delta(network, state_before, state_after) (rx_in_pkts, rx_testframe_pkts, generated_pkts, sequence_errors, latency_min, latency_max, latency_average)=get_traffic_stats(dst_node, dst_node_interface, src_node, src_node_interface, state_before, state_after, delta, test_time, frame_size, interframe_gap, frames_per_burst, interburst_gap, total_frames) print("Disabling analyzer.") ok=yangcli(yconns[dst_node],"""delete /interfaces/interface[name='%(name)s']/traffic-analyzer%(analyzer-direction-suffix)s"""%{'name':dst_node_interface, 'analyzer-direction-suffix':analyzer_direction_suffix}).xpath('./ok') assert(len(ok)==1) tntapi.network_commit(conns) return (rx_in_pkts, rx_testframe_pkts, generated_pkts, sequence_errors, latency_min, latency_max, latency_average)