diff options
Diffstat (limited to 'scripts/automation/trex_control_plane/unit_tests')
8 files changed, 952 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/unit_tests/__init__.py b/scripts/automation/trex_control_plane/unit_tests/__init__.py new file mode 100755 index 00000000..d3f5a12f --- /dev/null +++ b/scripts/automation/trex_control_plane/unit_tests/__init__.py @@ -0,0 +1 @@ +
diff --git a/scripts/automation/trex_control_plane/unit_tests/client_launching_test.py b/scripts/automation/trex_control_plane/unit_tests/client_launching_test.py new file mode 100755 index 00000000..42d79af5 --- /dev/null +++ b/scripts/automation/trex_control_plane/unit_tests/client_launching_test.py @@ -0,0 +1,31 @@ +#!/router/bin/python +from control_plane_general_test import CControlPlaneGeneral_Test +from Client.trex_client import CTRexClient + +import socket +from nose.tools import assert_raises + + +class CClientLaunching_Test(CControlPlaneGeneral_Test): + def __init__(self): + super(CClientLaunching_Test, self).__init__() + pass + + def setUp(self): + pass + + def test_wrong_hostname(self): + # self.tmp_server = CTRexClient('some-invalid-hostname') + assert_raises (socket.gaierror, CTRexClient, 'some-invalid-hostname' ) + + # perform this test only if server is down, but server machine is up + def test_refused_connection(self): + assert_raises (socket.error, CTRexClient, 'trex-dan') # Assuming 'trex-dan' server is down! otherwise test fails + + + def test_verbose_mode(self): + tmp_client = CTRexClient(self.trex_server_name, verbose = True) + pass + + def tearDown(self): + pass diff --git a/scripts/automation/trex_control_plane/unit_tests/control_plane_general_test.py b/scripts/automation/trex_control_plane/unit_tests/control_plane_general_test.py new file mode 100755 index 00000000..32ad5243 --- /dev/null +++ b/scripts/automation/trex_control_plane/unit_tests/control_plane_general_test.py @@ -0,0 +1,72 @@ +#!/router/bin/python + +__copyright__ = "Copyright 2015" + +""" +Name: + control_plane_general_test.py + + +Description: + + This script creates the functionality to test the performance of the TRex traffic generator control plane. + The scenarios assumes a WORKING server is listening and processing the requests. + +:: + + Topology: + + -------- -------- + | | | | + | Client | <-----JSON-RPC------> | Server | + | | | | + -------- -------- + +""" +from nose.plugins import Plugin +# import misc_methods +import sys +import os +# from CPlatformUnderTest import * +# from CPlatform import * +import termstyle +import threading +from common.trex_exceptions import * +from Client.trex_client import CTRexClient +# import Client.outer_packages +# import Client.trex_client + +TREX_SERVER = None + +class CTRexCP(): + trex_server = None + +def setUpModule(module): + pass + +def tearDownModule(module): + pass + + +class CControlPlaneGeneral_Test(object):#(unittest.TestCase): + """This class defines the general testcase of the control plane service""" + def __init__ (self): + self.trex_server_name = 'csi-kiwi-02' + self.trex = CTRexClient(self.trex_server_name) + pass + + def setUp(self): + # initialize server connection for single client + # self.server = CTRexClient(self.trex_server) + pass + + ######################################################################## + #### DO NOT ADD TESTS TO THIS FILE #### + #### Added tests here will held once for EVERY test sub-class #### + ######################################################################## + + def tearDown(self): + pass + + def check_for_trex_crash(self): + pass diff --git a/scripts/automation/trex_control_plane/unit_tests/control_plane_unit_test.py b/scripts/automation/trex_control_plane/unit_tests/control_plane_unit_test.py new file mode 100755 index 00000000..1120256c --- /dev/null +++ b/scripts/automation/trex_control_plane/unit_tests/control_plane_unit_test.py @@ -0,0 +1,73 @@ +#!/router/bin/python + +__copyright__ = "Copyright 2014" + + + +import os +import sys +import nose_outer_packages +import nose +from nose.plugins import Plugin +from rednose import RedNose +import termstyle +import control_plane_general_test + +class TRexCPConfiguringPlugin(Plugin): + def options(self, parser, env = os.environ): + super(TRexCPConfiguringPlugin, self).options(parser, env) + parser.add_option('-t', '--trex-server', action='store', + dest='trex_server', default='trex-dan', + help='Specify TRex server hostname. This server will be used to test control-plane functionality.') + + def configure(self, options, conf): + if options.trex_server: + self.trex_server = options.trex_server + + def begin (self): + # initialize CTRexCP global testing class, to be used by and accessible all tests + print "assigned trex_server name" + control_plane_general_test.CTRexCP.trex_server = self.trex_server + + def finalize(self, result): + pass + + + +if __name__ == "__main__": + + # setting defaults. By default we run all the test suite + specific_tests = False + disableLogCapture = False + long_test = False + report_dir = "reports" + + nose_argv= sys.argv + ['-s', '-v', '--exe', '--rednose', '--detailed-errors'] + + try: + result = nose.run(argv = nose_argv, addplugins = [RedNose(), TRexCPConfiguringPlugin()]) + if (result == True): + print termstyle.green(""" + ..::''''::.. + .;'' ``;. + :: :: :: :: + :: :: :: :: + :: :: :: :: + :: .:' :: :: `:. :: + :: : : :: + :: `:. .:' :: + `;..``::::''..;' + ``::,,,,::'' + + ___ ___ __________ + / _ \/ _ | / __/ __/ / + / ___/ __ |_\ \_\ \/_/ + /_/ /_/ |_/___/___(_) + + """) + sys.exit(0) + else: + sys.exit(-1) + + finally: + pass
\ No newline at end of file diff --git a/scripts/automation/trex_control_plane/unit_tests/functional_test.py b/scripts/automation/trex_control_plane/unit_tests/functional_test.py new file mode 100755 index 00000000..30836985 --- /dev/null +++ b/scripts/automation/trex_control_plane/unit_tests/functional_test.py @@ -0,0 +1,160 @@ +#!/router/bin/python +from control_plane_general_test import CControlPlaneGeneral_Test +from Client.trex_client import CTRexClient + +import socket +from nose.tools import assert_raises, assert_equal, assert_not_equal +from common.trex_status_e import TRexStatus +from common.trex_exceptions import * +from enum import Enum +import time + + +class CTRexStartStop_Test(CControlPlaneGeneral_Test): + def __init__(self): + super(CTRexStartStop_Test, self).__init__() + self.valid_start_params = dict( c = 4, + m = 1.1, + d = 100, + f = 'avl/sfr_delay_10_1g.yaml', + nc = True, + p = True, + l = 1000) + + def setUp(self): + pass + + def test_mandatory_param_error(self): + start_params = dict( c = 4, + m = 1.1, + d = 70, + # f = 'avl/sfr_delay_10_1g.yaml', <-- f (mandatory) is not provided on purpose + nc = True, + p = True, + l = 1000) + + assert_raises(TypeError, self.trex.start_trex, **start_params) + + def test_parameter_name_error(self): + ret = self.trex.start_trex( c = 4, + wrong_key = 1.1, # <----- This key does not exists in TRex API + d = 70, + f = 'avl/sfr_delay_10_1g.yaml', + nc = True, + p = True, + l = 1000) + + time.sleep(5) + + # check for failure status + run_status = self.trex.get_running_status() + assert isinstance(run_status, dict) + assert_equal (run_status['state'], TRexStatus.Idle ) + assert_equal (run_status['verbose'], "TRex run failed due to wrong input parameters, or due to reachability issues.") + assert_raises(TRexError, self.trex.get_running_info) + + def test_too_early_sample(self): + ret = self.trex.start_trex(**self.valid_start_params) + + assert ret==True + # issue get_running_info() too soon, without any(!) sleep + run_status = self.trex.get_running_status() + assert isinstance(run_status, dict) + assert_equal (run_status['state'], TRexStatus.Starting ) + assert_raises(TRexWarning, self.trex.get_running_info) + + ret = self.trex.stop_trex() + assert ret==True # make sure stop succeeded + assert self.trex.is_running() == False + + def test_start_sampling_on_time(self): + ret = self.trex.start_trex(**self.valid_start_params) + assert ret==True + time.sleep(6) + + run_status = self.trex.get_running_status() + assert isinstance(run_status, dict) + assert_equal (run_status['state'], TRexStatus.Running ) + + run_info = self.trex.get_running_info() + assert isinstance(run_info, dict) + ret = self.trex.stop_trex() + assert ret==True # make sure stop succeeded + assert self.trex.is_running() == False + + def test_start_more_than_once_same_user(self): + assert self.trex.is_running() == False # first, make sure TRex is not running + ret = self.trex.start_trex(**self.valid_start_params) # start 1st TRex run + assert ret == True # make sure 1st run submitted successfuly + # time.sleep(1) + assert_raises(TRexInUseError, self.trex.start_trex, **self.valid_start_params) # try to start TRex again + + ret = self.trex.stop_trex() + assert ret==True # make sure stop succeeded + assert self.trex.is_running() == False + + def test_start_more_than_once_different_users(self): + assert self.trex.is_running() == False # first, make sure TRex is not running + ret = self.trex.start_trex(**self.valid_start_params) # start 1st TRex run + assert ret == True # make sure 1st run submitted successfuly + # time.sleep(1) + + tmp_trex = CTRexClient(self.trex_server_name) # initialize another client connecting same server + assert_raises(TRexInUseError, tmp_trex.start_trex, **self.valid_start_params) # try to start TRex again + + ret = self.trex.stop_trex() + assert ret==True # make sure stop succeeded + assert self.trex.is_running() == False + + def test_simultaneous_sampling(self): + assert self.trex.is_running() == False # first, make sure TRex is not running + tmp_trex = CTRexClient(self.trex_server_name) # initialize another client connecting same server + ret = self.trex.start_trex(**self.valid_start_params) # start TRex run + assert ret == True # make sure 1st run submitted successfuly + + time.sleep(6) + # now, sample server from both clients + while (self.trex.is_running()): + info_1 = self.trex.get_running_info() + info_2 = tmp_trex.get_running_info() + + # make sure samples are consistent + if self.trex.get_result_obj().is_valid_hist(): + assert tmp_trex.get_result_obj().is_valid_hist() == True + if self.trex.get_result_obj().is_done_warmup(): + assert tmp_trex.get_result_obj().is_done_warmup() == True + # except TRexError as inst: # TRex might have stopped between is_running result and get_running_info() call + # # hence, ingore that case + # break + + assert self.trex.is_running() == False + + def test_fast_toggling(self): + assert self.trex.is_running() == False + for i in range(20): + ret = self.trex.start_trex(**self.valid_start_params) # start TRex run + assert ret == True + assert self.trex.is_running() == False # we expect the status to be 'Starting' + ret = self.trex.stop_trex() + assert ret == True + assert self.trex.is_running() == False + pass + + + def tearDown(self): + pass + +class CBasicQuery_Test(CControlPlaneGeneral_Test): + def __init__(self): + super(CBasicQuery_Test, self).__init__() + pass + + def setUp(self): + pass + + def test_is_running(self): + assert self.trex.is_running() == False + + + def tearDown(self): + pass diff --git a/scripts/automation/trex_control_plane/unit_tests/nose_outer_packages.py b/scripts/automation/trex_control_plane/unit_tests/nose_outer_packages.py new file mode 100755 index 00000000..b5b78db7 --- /dev/null +++ b/scripts/automation/trex_control_plane/unit_tests/nose_outer_packages.py @@ -0,0 +1,27 @@ +#!/router/bin/python + +import sys,site +import platform,os + +CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) +ROOT_PATH = os.path.abspath(os.path.join(CURRENT_PATH, os.pardir)) # path to trex_control_plane directory +PATH_TO_PYTHON_LIB = os.path.abspath(os.path.join(ROOT_PATH, 'python_lib')) + + +TEST_MODULES = ['nose-1.3.4', + 'rednose-0.4.1', + 'termstyle' + ] + +def import_test_modules (): + sys.path.append(ROOT_PATH) + import_module_list(TEST_MODULES) + +def import_module_list (modules_list): + assert(isinstance(modules_list, list)) + for p in modules_list: + full_path = os.path.join(PATH_TO_PYTHON_LIB, p) + fix_path = os.path.normcase(full_path) #CURRENT_PATH+p) + site.addsitedir(full_path) + +import_test_modules() diff --git a/scripts/automation/trex_control_plane/unit_tests/sock.py b/scripts/automation/trex_control_plane/unit_tests/sock.py new file mode 100755 index 00000000..29248e3e --- /dev/null +++ b/scripts/automation/trex_control_plane/unit_tests/sock.py @@ -0,0 +1,552 @@ +import os +import dpkt +import struct +import socket +import sys +import argparse; + + +H_SCRIPT_VER = "0.1" + +class sock_driver(object): + args=None; + + +def nl (buf): + return ( struct.unpack('>I', buf)[0]); + +def dump_tuple (t): + for obj in t: + print hex(obj),",", + +class CFlowRec: + def __init__ (self): + self.is_init_dir=False; + self.bytes=0; + self.data=None; + + def __str__ (self): + if self.is_init_dir : + s=" client " + else: + s=" server " + s+= " %d " %(self.bytes) + return (s); + + + +class CPcapFileReader: + def __init__ (self,file_name): + self.file_name=file_name; + self.tuple=None; + self.swap=False; + self.info=[]; + + def dump_info (self): + for obj in self.info: + print obj + #print "'",obj.data,"'" + + def is_client_side (self,swap): + if self.swap ==swap: + return (True); + else: + return (False); + + def add_server(self,server,data): + r=CFlowRec(); + r.is_init_dir =False; + r.bytes = server + r.data=data + self.info.append(r); + + def add_client(self,client,data): + r=CFlowRec(); + r.is_init_dir =True; + r.bytes = client + r.data=data + self.info.append(r); + + def check_tcp_flow (self): + f = open(self.file_name) + pcap = dpkt.pcap.Reader(f) + for ts, buf in pcap: + eth = dpkt.ethernet.Ethernet(buf) + ip = eth.data + tcp = ip.data + if ip.p != 6 : + raise Exception("not a TCP flow .."); + if tcp.flags != dpkt.tcp.TH_SYN : + raise Exception("first packet should be with SYN"); + break; + f.close(); + + def check_one_flow (self): + cnt=1 + client=0; + server=0; + client_data='' + server_data='' + is_c=False # the direction + is_s=False + f = open(self.file_name) + pcap = dpkt.pcap.Reader(f) + for ts, buf in pcap: + eth = dpkt.ethernet.Ethernet(buf) + ip = eth.data + tcp = ip.data + pld = tcp.data; + + pkt_swap=False + if nl(ip.src) > nl(ip.dst): + pkt_swap=True + tuple= (nl(ip.dst),nl(ip.src), tcp.dport ,tcp.sport,ip.p ); + else: + tuple= (nl(ip.src),nl(ip.dst) ,tcp.sport,tcp.dport,ip.p ); + + if self.tuple == None: + self.swap=pkt_swap + self.tuple=tuple + else: + if self.tuple != tuple: + raise Exception("More than one flow - can't process this flow"); + + + print " %5d," % (cnt), + if self.is_client_side (pkt_swap): + print "client", + if len(pld) >0 : + if is_c==False: + is_c=True + if is_s: + self.add_server(server,server_data); + server=0; + server_data='' + is_s=False; + + client+=len(pld); + client_data=client_data+pld; + else: + if len(pld) >0 : + if is_s==False: + is_s=True + if is_c: + self.add_client(client,client_data); + client=0; + client_data='' + is_c=False; + + server+=len(pld) + server_data=server_data+pld; + + print "server", + print " %5d" % (len(pld)), + dump_tuple (tuple) + print + + cnt=cnt+1 + + if is_c: + self.add_client(client,client_data); + if is_s: + self.add_server(server,server_data); + + f.close(); + + +class CClientServerCommon(object): + + def __init__ (self): + pass; + + def send_info (self,data): + print "server send %d bytes" % (len(data)) + self.connection.sendall(data) + + def rcv_info (self,msg_size): + print "server wait for %d bytes" % (msg_size) + + bytes_recd = 0 + while bytes_recd < msg_size: + chunk = self.connection.recv(min(msg_size - bytes_recd, 2048)) + if chunk == '': + raise RuntimeError("socket connection broken") + bytes_recd = bytes_recd + len(chunk) + + + def process (self,is_server): + pcapinfo=self.pcapr.info + for obj in pcapinfo: + if is_server: + if obj.is_init_dir: + self.rcv_info (obj.bytes); + else: + self.send_info (obj.data); + else: + if obj.is_init_dir: + self.send_info (obj.data); + else: + self.rcv_info (obj.bytes); + + self.connection.close(); + self.connection = None + + +class CServer(CClientServerCommon) : + def __init__ (self,pcapr,port): + super(CServer, self).__init__() + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + + server_address = ('', port) + print 'starting up on %s port %s' % server_address + sock.bind(server_address) + sock.listen(1) + + self.pcapr=pcapr; # save the info + + while True: + # Wait for a connection + print 'waiting for a connection' + connection, client_address = sock.accept() + + try: + print 'connection from', client_address + self.connection = connection; + + self.process(True); + finally: + if self.connection : + self.connection.close() + self.connection = None + + +class CClient(CClientServerCommon): + def __init__ (self,pcapr,ip,port): + super(CClient, self).__init__() + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + #sock.setsockopt(socket.SOL_SOCKET,socket.TCP_MAXSEG,300) + server_address = (ip, port) + print 'connecting to %s port %s' % server_address + + sock.connect(server_address) + self.connection=sock; + self.pcapr=pcapr; # save the info + + try: + + self.process(False); + finally: + if self.connection : + self.connection.close() + self.connection = None + + +def test_file_load (): + pcapr= CPcapFileReader("delay_10_http_browsing_0.pcap") + pcapr.check_tcp_flow () + pcapr.check_one_flow () + pcapr.dump_info(); + + +def process_options (): + parser = argparse.ArgumentParser(usage=""" + sock [-s|-c] -f file_name + + """, + description="offline process a pcap file", + epilog=" written by hhaim"); + + parser.add_argument("-f", dest="file_name", + help=""" the file name to process """, + required=True) + + parser.add_argument('-c', action='store_true', + help='client side') + + parser.add_argument('-s', action='store_true', + help='server side ') + + parser.add_argument('--fix-time', action='store_true', + help='fix_time ') + + parser.add_argument('--port', type=int, default=1000, + help='server_port ') + + parser.add_argument('--ip', default='127.0.0.1', + help='socket ip ') + + parser.add_argument('--debug', action='store_true', + help='debug mode') + + parser.add_argument('--version', action='version', + version=H_SCRIPT_VER ) + + + + sock_driver.args = parser.parse_args(); + + if sock_driver.args.fix_time : + return ; + if (sock_driver.args.c ^ sock_driver.args.s) ==0: + raise Exception ("you must set either client or server mode"); + +def load_pcap_file (): + pcapr= CPcapFileReader(sock_driver.args.file_name) + pcapr.check_tcp_flow () + pcapr.check_one_flow () + pcapr.dump_info(); + return pcapr + +def run_client_side (): + pcapr=load_pcap_file () + socket_client = CClient(pcapr,sock_driver.args.ip,sock_driver.args.port); + + +def run_server_side (): + pcapr=load_pcap_file () + socket_server = CServer(pcapr,sock_driver.args.port); + + +class CPktWithTime: + def __init__ (self,pkt,ts): + self.pkt=pkt; + self.ts=ts + def __cmp__ (self,other): + return cmp(self.ts,other.ts); + + def __repr__ (self): + s=" %x:%d" %(self.pkt,self.ts) + return s; + + +class CPcapFixTime: + def __init__ (self,in_file_name, + out_file_name): + self.in_file_name = in_file_name; + self.out_file_name = out_file_name; + self.tuple=None; + self.swap=False; + self.rtt =0; + self.rtt_syn_ack_ack =0; # ack on the syn ack + self.pkts=[] + + def calc_rtt (self): + f = open(self.in_file_name) + pcap = dpkt.pcap.Reader(f) + cnt=0; + first_time_set=False; + first_time=0; + last_syn_time=0; + rtt=0; + rtt_syn_ack_ack=0; + + for ts, buf in pcap: + eth = dpkt.ethernet.Ethernet(buf) + ip = eth.data + tcp = ip.data + + if first_time_set ==False: + first_time=ts; + first_time_set=True; + else: + rtt=ts-first_time; + + if ip.p != 6 : + raise Exception("not a TCP flow .."); + + if cnt==0 or cnt==1: + if (tcp.flags & dpkt.tcp.TH_SYN) != dpkt.tcp.TH_SYN : + raise Exception("first packet should be with SYN"); + + if cnt==1: + last_syn_time=ts; + + if cnt==2: + rtt_syn_ack_ack=ts-last_syn_time; + + if cnt > 1 : + break; + cnt = cnt +1; + + f.close(); + self.rtt_syn_ack_ack = rtt_syn_ack_ack; + return (rtt); + + def is_client_side (self,swap): + if self.swap ==swap: + return (True); + else: + return (False); + + def calc_timing (self): + self.rtt=self.calc_rtt (); + + def fix_timing (self): + + rtt=self.calc_rtt (); + print "RTT is %f msec" % (rtt*1000) + + if (rtt/2)*1000<5: + raise Exception ("RTT is less than 5msec, you should replay it"); + + time_to_center=rtt/4; + + f = open(self.in_file_name) + fo = open(self.out_file_name,"wb") + pcap = dpkt.pcap.Reader(f) + pcap_out = dpkt.pcap.Writer(fo) + + for ts, buf in pcap: + eth = dpkt.ethernet.Ethernet(buf) + ip = eth.data + tcp = ip.data + pld = tcp.data; + + pkt_swap=False + if nl(ip.src) > nl(ip.dst): + pkt_swap=True + tuple= (nl(ip.dst),nl(ip.src), tcp.dport ,tcp.sport,ip.p ); + else: + tuple= (nl(ip.src),nl(ip.dst) ,tcp.sport,tcp.dport,ip.p ); + + if self.tuple == None: + self.swap=pkt_swap + self.tuple=tuple + else: + if self.tuple != tuple: + raise Exception("More than one flow - can't process this flow"); + + if self.is_client_side (pkt_swap): + self.pkts.append(CPktWithTime( buf,ts+time_to_center)); + else: + self.pkts.append(CPktWithTime( buf,ts-time_to_center)); + + self.pkts.sort(); + for pkt in self.pkts: + pcap_out.writepkt(pkt.pkt, pkt.ts) + + f.close() + fo.close(); + + + +def main (): + process_options () + + if sock_driver.args.fix_time: + pcap = CPcapFixTime(sock_driver.args.file_name ,sock_driver.args.file_name+".fix.pcap") + pcap.fix_timing () + + if sock_driver.args.c: + run_client_side (); + + if sock_driver.args.s: + run_server_side (); + + +files_to_convert=[ +'citrix_0', +'exchange_0', +'http_browsing_0', +'http_get_0', +'http_post_0', +'https_0', +'mail_pop_0', +'mail_pop_1', +'mail_pop_2', +'oracle_0', +'rtsp_0', +'smtp_0', +'smtp_1', +'smtp_2' +]; + + +#files_to_convert=[ +#'http_browsing_0', +#]; + +def test_pcap_file (): + for file in files_to_convert: + fn='tun_'+file+'.pcap'; + fno='_tun_'+file+'_fixed.pcap'; + print "convert ",fn + pcap = CPcapFixTime(fn,fno) + pcap.fix_timing () + + + + +class CPcapFileState: + def __init__ (self,file_name): + self.file_name = file_name + self.is_one_tcp_flow = False; + self.is_rtt_valid = False; + self.rtt=0; + self.rtt_ack=0; + + def calc_stats (self): + file = CPcapFileReader(self.file_name); + try: + file.check_tcp_flow() + file.check_one_flow () + self.is_one_tcp_flow = True; + except Exception : + self.is_one_tcp_flow = False; + + print self.is_one_tcp_flow + if self.is_one_tcp_flow : + pcap= CPcapFixTime(self.file_name,""); + try: + pcap.calc_timing () + print "rtt : %d %d \n" % (pcap.rtt*1000,pcap.rtt_syn_ack_ack*1000); + if (pcap.rtt*1000) > 10 and (pcap.rtt_syn_ack_ack*1000) >0.0 and (pcap.rtt_syn_ack_ack*1000) <2.0 : + self.is_rtt_valid = True + self.rtt = pcap.rtt*1000; + self.rtt_ack =pcap.rtt_syn_ack_ack*1000; + except Exception : + pass; + + +def test_pcap_file (file_name): + p= CPcapFileState(file_name) + p.calc_stats(); + if p.is_rtt_valid: + return True + else: + return False + +def iterate_tree_files (dirwalk,path_to): + fl=open("res.csv","w+"); + cnt=0; + cnt_valid=0 + for root, _, files in os.walk(dirwalk): + for f in files: + fullpath = os.path.join(root, f) + p= CPcapFileState(fullpath) + p.calc_stats(); + + valid=test_pcap_file (fullpath) + s='%s,%d,%d,%d \n' %(fullpath,p.is_rtt_valid,p.rtt,p.rtt_ack) + cnt = cnt +1 ; + if p.is_rtt_valid: + cnt_valid = cnt_valid +1; + diro=path_to+"/"+root; + fo = os.path.join(diro, f) + os.system("mkdir -p "+ diro); + pcap = CPcapFixTime(fullpath,fo) + pcap.fix_timing () + + print s + fl.write(s); + print " %d %% %d valids \n" % (100*cnt_valid/cnt,cnt); + fl.close(); + +path_code="/scratch/tftp/pFidelity/pcap_repository" + +iterate_tree_files (path_code,"output") +#test_pcap_file () +#test_pcap_file () +#main(); + diff --git a/scripts/automation/trex_control_plane/unit_tests/test.py b/scripts/automation/trex_control_plane/unit_tests/test.py new file mode 100755 index 00000000..dac765d6 --- /dev/null +++ b/scripts/automation/trex_control_plane/unit_tests/test.py @@ -0,0 +1,36 @@ +from mininet.topo import Topo +from mininet.link import TCLink +from mininet.net import Mininet +from mininet.node import CPULimitedHost +from mininet.link import TCLink +from mininet.util import dumpNodeConnections +from mininet.log import setLogLevel + +class MyTopo( Topo ): + "Simple topology example." + + def __init__( self ): + "Create custom topo." + + # Initialize topology + Topo.__init__( self ) + + # Add hosts and switches + leftHost = self.addHost( 'h1' ) + rightHost = self.addHost( 'h2' ) + Switch = self.addSwitch( 's1' ) + + # Add links + self.addLink( leftHost, Switch ,bw=10, delay='5ms') + self.addLink( Switch, rightHost ) + + +topos = { 'mytopo': ( lambda: MyTopo() ) } + +# 1. http server example +# +#mininet> h1 python -m SimpleHTTPServer 80 & +#mininet> h2 wget -O - h1 +# 2. limit mss example +#decrease the MTU ifconfig eth0 mtu 488 + |