Exemplo n.º 1
0
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)

    print("#1.1 - Validate no counters are being incremented.")
    #validate no counters were incremented
    for node in {"local", "middle"}:
        for if_name in {
                "ge0", "ge1", "ge2", "ge3", "ge4", "ge5", "ge6", "ge7", "ge8",
                "ge9"
        }:
            interface = delta[node][if_name]
            increment = 0
            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)
                        increment = increment + 1
        if (increment == 0):
            print node + ":" + if_name + " has no incremented counters"
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)

	print("#1.1 - Validate all analyzer interfaces have oper-status=up.")
	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)
	for node in {"middle"}:
		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)
Exemplo n.º 4
0
def print_state(before, after):
    print("Printing state ...")
    t1 = tntapi.parse_network_nodes(before)
    t2 = tntapi.parse_network_nodes(after)
    delta = tntapi.get_network_counters_delta(before, after)

    print("local=1;remote=2")
    print(
        "xe0=1;xe1=2;ge0=3;ge1=4;ge2=5;ge3=6;ge4=7;ge5=8;ge6=9;ge7=10;ge8=11;ge9=12;ge15=18;"
    )

    #print all non-zero deltas

    #print all non-zero deltas
    for node in {"local", "remote"}:
        for if_name in {
                "xe0", "ge15", "ge0", "ge1", "ge2", "ge3", "ge4", "ge5", "ge1",
                "ge6", "ge7", "ge8", "ge9"
        }:
            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 v + "(" + node + "," + if_name + ")=" + str(
                            value) + ";"
Exemplo n.º 5
0
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!")
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
def print_state_ietf_interfaces_statistics_delta(network, before, after):
    import tntapi
    print("Printing state ...")
    t1 = tntapi.parse_network_nodes(before)
    t2 = tntapi.parse_network_nodes(after)
    delta = tntapi.get_network_counters_delta(before, after)

    i = 1
    line = ""
    node_dict = dict()
    tp_dict = dict()
    nodes = network.xpath('nd:node', namespaces=namespaces)
    for node in nodes:
        node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
        node_dict[node_id] = 1
        termination_points = node.xpath('./nt:termination-point',
                                        namespaces=namespaces)
        for termination_point in termination_points:
            tp_id = termination_point.xpath('nt:tp-id',
                                            namespaces=namespaces)[0].text
            if tp_id not in tp_dict:
                tp_dict[tp_id] = 1

    line = ""
    i = 1
    for node in sorted(node_dict):
        line = line + "%s=%d;" % (node, i)
        i = i + 1
    print(line)  #e.g. "local=1;remote=2;analyzer=3;"

    line = ""
    i = 1
    for tp in sorted(tp_dict):
        line = line + "%s=%d;" % (tp, i)
        i = i + 1
    print(line)  #e.g. #"xe0=1;xe1=2;ge0=3;"

    #print all non-zero deltas
    for node in node_dict:
        for if_name in tp_dict.keys():
            if if_name not in delta[node]:
                continue
            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 v + "(" + node + "," + if_name + ")=" + str(
                            value) + ";"
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
def validate_step1(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)

    print("#1.1 - Asserts for step_1.")

    assert (delta["analyzer"]["xe0"].out_unicast_pkts >= 1000000)
    assert (delta["analyzer"]["xe1"].out_unicast_pkts >= 1000000)
    assert (delta["analyzer"]["ge0"].in_unicast_pkts >= 1000000)
    assert (
        delta["local"]["ge0"].fusion_ep_to_np0_gst_multicast_contentions == 0)
    #	assert(delta["analyzer"]["ge0"].in_unicast_pkts==delta["analyzer"]["xe0"].out_unicast_pkts+delta["analyzer"]["xe1"].out_unicast_pkts-delta["local"]["ge15"].fusion_np_tx_gst_multicast_contentions)

    #latency_to_xe0=after.xpath("node[node-id='analyzer']/data/interfaces-state/interface[name='xe0']/traffic-analyzer/testframe-stats/latency/min")[0].text

    local_pkts_sent = delta["analyzer"]["xe0"].out_unicast_pkts
    remote_pkts_sent = delta["analyzer"]["xe1"].out_unicast_pkts
    total_pkts_received = delta["analyzer"]["ge0"].in_unicast_pkts
    contentions = delta["local"]["ge15"].fusion_np_tx_gst_multicast_contentions
    return local_pkts_sent, remote_pkts_sent, total_pkts_received, contentions
Exemplo n.º 11
0
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(network,
             conns,
             yconns,
             inks,
             load_percent=99,
             frame_size=1500,
             interframe_gap=12,
             frames_per_burst=0,
             interburst_gap=0):
    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 = {}
    nodes = network.xpath('nd:node', namespaces=namespaces)
    for node in nodes:
        node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
        config = ""
        print node_id

        termination_points = node.xpath('./nt:termination-point',
                                        namespaces=namespaces)
        for termination_point in termination_points:
            tp_id = termination_point.xpath('nt:tp-id',
                                            namespaces=namespaces)[0].text
            if (not is_interface_test_enabled(node_id, tp_id)):
                continue
            ok = yangcli(
                yconns[node_id],
                """replace /interfaces/interface[name='%(name)s'] -- type=ethernetCsmacd"""
                % {
                    'name': tp_id
                }).xpath('./ok')
            assert (len(ok) == 1)

    tntapi.network_commit(conns)

    state_before = tntapi.network_get_state(network, conns, filter=filter)
    print("Waiting " + "5" + " sec. ...")
    time.sleep(5)
    print("Done.")
    state_after = tntapi.network_get_state(network, conns, filter=filter)

    mylinks = tntapi.parse_network_links(state_before)
    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)

    for node in nodes:
        node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
        termination_points = node.xpath('./nt:termination-point',
                                        namespaces=namespaces)
        for termination_point in termination_points:
            tp_id = termination_point.xpath('nt:tp-id',
                                            namespaces=namespaces)[0].text
            if (not is_interface_test_enabled(node_id, tp_id)):
                continue
            validate_traffic_off(node_id, tp_id, state_before, state_after,
                                 delta, frame_size)

    load = float(load_percent) / 100
    print "ifg=" + str(interframe_gap)

    if (args.test_internal_loopback == "true"):
        print("Enabling internal loopbacks.")
        for node in nodes:
            node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
            termination_points = node.xpath('./nt:termination-point',
                                            namespaces=namespaces)
            for termination_point in termination_points:
                tp_id = termination_point.xpath('nt:tp-id',
                                                namespaces=namespaces)[0].text
                if (not is_interface_test_enabled(node_id, tp_id)):
                    continue
                ok = yangcli(
                    yconns[node_id],
                    """merge /interfaces/interface[name='%(name)s'] -- loopback=internal"""
                    % {
                        'name': tp_id
                    }).xpath('./ok')
                assert (len(ok) == 1)

        tntapi.network_commit(conns)

    if (args.test_analyzer == "true"):
        print("Enabling analyzer.")
        for node in nodes:
            node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
            termination_points = node.xpath('./nt:termination-point',
                                            namespaces=namespaces)
            for termination_point in termination_points:
                tp_id = termination_point.xpath('nt:tp-id',
                                                namespaces=namespaces)[0].text
                if (not is_interface_test_enabled(node_id, tp_id)):
                    continue
                if (args.direction == 'ingress'):
                    ok = yangcli(
                        yconns[node_id],
                        """create /interfaces/interface[name='%(name)s']/traffic-analyzer-egress"""
                        % {
                            'name': tp_id
                        }).xpath('./ok')
                else:
                    ok = yangcli(
                        yconns[node_id],
                        """create /interfaces/interface[name='%(name)s']/traffic-analyzer"""
                        % {
                            'name': tp_id
                        }).xpath('./ok')
                assert (len(ok) == 1)

        tntapi.network_commit(conns)

    for node in nodes:
        node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
        config = ""

        termination_points = node.xpath('./nt:termination-point',
                                        namespaces=namespaces)
        for termination_point in termination_points:
            tp_id = termination_point.xpath('nt:tp-id',
                                            namespaces=namespaces)[0].text
            if (not is_interface_test_enabled(node_id, tp_id)):
                continue
            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 = ""

            if (args.direction == 'ingress'):
                generator_direction_suffix = '-ingress'
                analyzer_direction_suffix = '-egress'
            else:
                generator_direction_suffix = ''
                analyzer_direction_suffix = ''

            ok = yangcli(
                yconns[node_id],
                """create /interfaces/interface[name='%(name)s']/traffic-generator%(generator-direction-suffix)s -- ether-type=%(ether-type)d frame-size=%(frame-size)d interframe-gap=%(interframe-gap)d %(burst)s"""
                % {
                    'name': tp_id,
                    'generator-direction-suffix': generator_direction_suffix,
                    'frame-size': frame_size,
                    'ether-type': 0x1234,
                    'interframe-gap': interframe_gap - 8,
                    'burst': my_burst_config
                }).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)

    print("Stopping generators ...")
    for node in nodes:
        node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
        config = ""

        termination_points = node.xpath('./nt:termination-point',
                                        namespaces=namespaces)
        for termination_point in termination_points:
            tp_id = termination_point.xpath('nt:tp-id',
                                            namespaces=namespaces)[0].text
            if (not is_interface_test_enabled(node_id, tp_id)):
                continue
            ok = yangcli(
                yconns[node_id],
                """delete /interfaces/interface[name='%(name)s']/traffic-generator%(generator-direction-suffix)s"""
                % {
                    'name': tp_id,
                    'generator-direction-suffix': generator_direction_suffix
                }).xpath('./ok')
            assert (len(ok) == 1)

    tntapi.network_commit(conns)
    print("Done.")

    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)

    load_generated = {}
    for node in nodes:
        node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
        termination_points = node.xpath('./nt:termination-point',
                                        namespaces=namespaces)
        for termination_point in termination_points:
            tp_id = termination_point.xpath('nt:tp-id',
                                            namespaces=namespaces)[0].text
            if (not is_interface_test_enabled(node_id, tp_id)):
                continue
            load_generated[node_id, tp_id] = validate_traffic_on(
                node_id, tp_id, state_before, state_after, delta, test_time,
                load_percent, frame_size, interframe_gap, frames_per_burst,
                interburst_gap)

    if (args.test_analyzer == "true"):
        print("Disabling analyzer.")
        for node in nodes:
            node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
            termination_points = node.xpath('./nt:termination-point',
                                            namespaces=namespaces)
            for termination_point in termination_points:
                tp_id = termination_point.xpath('nt:tp-id',
                                                namespaces=namespaces)[0].text
                if (not is_interface_test_enabled(node_id, tp_id)):
                    continue
                ok = yangcli(
                    yconns[node_id],
                    """delete /interfaces/interface[name='%(name)s']/traffic-analyzer%(analyzer-direction-suffix)s"""
                    % {
                        'name': tp_id,
                        'analyzer-direction-suffix': analyzer_direction_suffix
                    }).xpath('./ok')
                assert (len(ok) == 1)

        tntapi.network_commit(conns)

    if (args.test_internal_loopback == "true"):
        print("Disabling internal loopbacks.")
        for node in nodes:
            node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
            termination_points = node.xpath('./nt:termination-point',
                                            namespaces=namespaces)
            for termination_point in termination_points:
                tp_id = termination_point.xpath('nt:tp-id',
                                                namespaces=namespaces)[0].text
                if (not is_interface_test_enabled(node_id, tp_id)):
                    continue
                ok = yangcli(
                    yconns[node_id],
                    """delete /interfaces/interface[name='%(name)s']/loopback"""
                    % {
                        'name': tp_id
                    }).xpath('./ok')
                assert (len(ok) == 1)

        tntapi.network_commit(conns)

    return (load_percent, load_generated)
Exemplo n.º 13
0
def validate(network,
             conns,
             yconns,
             inks,
             load_percent=99,
             frame_size=1500,
             interframe_gap=12,
             frames_per_burst=0,
             interburst_gap=0):
    filter = """<filter type="xpath" select="/interfaces-state/interface/*[local-name()='traffic-analyzer' or local-name()='oper-status' or local-name()='statistics' or local-name()='speed']"/>"""
    #	config_idle="""
    #<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    #</config>
    #"""
    config_idle = {}
    nodes = network.xpath('nd:node', namespaces=namespaces)
    for node in nodes:
        node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
        config = ""

        termination_points = node.xpath('./nt:termination-point',
                                        namespaces=namespaces)
        for termination_point in termination_points:
            tp_id = termination_point.xpath('nt:tp-id',
                                            namespaces=namespaces)[0].text
            ok = yangcli(
                yconns[node_id],
                """replace /interfaces/interface[name='%(name)s'] -- type=ethernetCsmacd"""
                % {
                    'name': tp_id
                }).xpath('./ok')
            assert (len(ok) == 1)

    tntapi.network_commit(conns)

    state_before = tntapi.network_get_state(network, conns, filter=filter)
    print("Waiting " + "5" + " sec. ...")
    time.sleep(5)
    print("Done.")
    state_after = tntapi.network_get_state(network, conns, filter=filter)

    mylinks = tntapi.parse_network_links(state_before)
    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)

    for node in nodes:
        node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
        termination_points = node.xpath('./nt:termination-point',
                                        namespaces=namespaces)
        for termination_point in termination_points:
            tp_id = termination_point.xpath('nt:tp-id',
                                            namespaces=namespaces)[0].text
            validate_traffic_off(node_id, tp_id, state_before, state_after,
                                 delta)

    load = float(load_percent) / 100
    print "ifg=" + str(interframe_gap)

    for node in nodes:
        node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
        config = ""

        termination_points = node.xpath('./nt:termination-point',
                                        namespaces=namespaces)
        for termination_point in termination_points:
            tp_id = termination_point.xpath('nt:tp-id',
                                            namespaces=namespaces)[0].text
            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 = ""

            ok = yangcli(
                yconns[node_id],
                """create /interfaces/interface[name='%(name)s']/traffic-generator -- frame-size=%(frame-size)d interframe-gap=%(interframe-gap)d %(burst)s"""
                % {
                    'name': tp_id,
                    'frame-size': frame_size,
                    'interframe-gap': interframe_gap - 8,
                    'burst': my_burst_config
                }).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)

    print("Stopping generators ...")
    for node in nodes:
        node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
        config = ""

        termination_points = node.xpath('./nt:termination-point',
                                        namespaces=namespaces)
        for termination_point in termination_points:
            tp_id = termination_point.xpath('nt:tp-id',
                                            namespaces=namespaces)[0].text
            ok = yangcli(
                yconns[node_id],
                """replace /interfaces/interface[name='%(name)s'] -- type=ethernetCsmacd"""
                % {
                    'name': tp_id
                }).xpath('./ok')
            assert (len(ok) == 1)

    tntapi.network_commit(conns)
    print("Done.")

    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)

    load_generated = {}
    for node in nodes:
        node_id = node.xpath('nd:node-id', namespaces=namespaces)[0].text
        termination_points = node.xpath('./nt:termination-point',
                                        namespaces=namespaces)
        for termination_point in termination_points:
            tp_id = termination_point.xpath('nt:tp-id',
                                            namespaces=namespaces)[0].text
            load_generated[node_id, tp_id] = validate_traffic_on(
                node_id, tp_id, state_before, state_after, delta, test_time,
                load_percent, frame_size, interframe_gap, frames_per_burst,
                interburst_gap)

    return (load_percent, load_generated)
Exemplo n.º 14
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')
    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
Exemplo n.º 15
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
Exemplo n.º 16
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)