summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-11-19 13:01:39 +0200
committerimarom <imarom@cisco.com>2015-11-19 13:01:39 +0200
commitf3d60d71ccd9275ac42b7c9dc619cc6797e1fb12 (patch)
tree794882ccfc100a276642f97b357c7b3757e94e2e
parent76248b13906f575f709ed2270d63ec41131f4bdf (diff)
parent9c69a86ed94732196c2b62209f61da783cda1386 (diff)
Merge branch 'master' of csi-sceasr-b45:/auto/proj-pcube-b/apps/PL-b/tools/repo//trex-core
-rw-r--r--.gitignore1
-rw-r--r--scripts/automation/trex_control_plane/client/trex_async_client.py5
-rwxr-xr-xscripts/automation/trex_control_plane/client/trex_stateless_client.py57
-rwxr-xr-xscripts/automation/trex_control_plane/console/trex_console.py70
-rw-r--r--scripts/exp/stl_simple_prog4-0-ex.erfbin0 -> 3344 bytes
-rw-r--r--src/gtest/trex_stateless_gtest.cpp83
6 files changed, 174 insertions, 42 deletions
diff --git a/.gitignore b/.gitignore
index 183484fb..fcc5135f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,6 +24,7 @@ scripts/exp/stl_single_stream-0.erf
scripts/exp/stl_simple_prog1-0.erf
scripts/exp/stl_simple_prog2-0.erf
scripts/exp/stl_simple_prog3-0.erf
+scripts/exp/stl_simple_prog4-0.erf
diff --git a/scripts/automation/trex_control_plane/client/trex_async_client.py b/scripts/automation/trex_control_plane/client/trex_async_client.py
index d13513bf..31bec93f 100644
--- a/scripts/automation/trex_control_plane/client/trex_async_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_async_client.py
@@ -151,16 +151,17 @@ class TrexAsyncStatsManager():
class CTRexAsyncClient():
- def __init__ (self, port):
+ def __init__ (self, server, port):
self.port = port
+ self.server = server
self.raw_snapshot = {}
self.stats = TrexAsyncStatsManager()
- self.tr = "tcp://localhost:{0}".format(self.port)
+ self.tr = "tcp://{0}:{1}".format(self.server, self.port)
print "\nConnecting To ZMQ Publisher At {0}".format(self.tr)
self.active = True
diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
index db4199c6..699f0af2 100755
--- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
@@ -139,8 +139,7 @@ class CStreamsDB(object):
# describes a single port
-class Port:
-
+class Port(object):
STATE_DOWN = 0
STATE_IDLE = 1
STATE_STREAMS = 2
@@ -156,14 +155,14 @@ class Port:
self.streams = {}
- def err (self, msg):
+ def err(self, msg):
return RC_ERR("port {0} : {1}".format(self.port_id, msg))
- def ok (self):
+ def ok(self):
return RC_OK()
# take the port
- def acquire (self, force = False):
+ def acquire(self, force = False):
params = {"port_id": self.port_id,
"user": self.user,
"force": force}
@@ -178,7 +177,7 @@ class Port:
# release the port
- def release (self):
+ def release(self):
params = {"port_id": self.port_id,
"handler": self.handler}
@@ -190,25 +189,24 @@ class Port:
else:
return self.err(rc.data)
- def is_acquired (self):
+ def is_acquired(self):
return (self.handler != None)
- def is_active (self):
- return (self.state == self.STATE_TX ) or (self.state == self.STATE_PAUSE)
-
- def sync (self, sync_data):
+ def is_active(self):
+ return(self.state == self.STATE_TX ) or (self.state == self.STATE_PAUSE)
+ def sync(self, sync_data):
self.handler = sync_data['handler']
-
- if sync_data['state'] == "DOWN":
+ port_state = sync_data['state'].upper()
+ if port_state == "DOWN":
self.state = self.STATE_DOWN
- elif sync_data['state'] == "IDLE":
+ elif port_state == "IDLE":
self.state = self.STATE_IDLE
- elif sync_data['state'] == "STREAMS":
+ elif port_state == "STREAMS":
self.state = self.STATE_STREAMS
- elif sync_data['state'] == "TX":
+ elif port_state == "TX":
self.state = self.STATE_TX
- elif sync_data['state'] == "PAUSE":
+ elif port_state == "PAUSE":
self.state = self.STATE_PAUSE
else:
raise Exception("port {0}: bad state received from server '{1}'".format(self.port_id, sync_data['state']))
@@ -217,14 +215,14 @@ class Port:
# return TRUE if write commands
- def is_port_writeable (self):
- # operations on port can be done on state idle or state sreams
+ def is_port_writable (self):
+ # operations on port can be done on state idle or state streams
return ((self.state == self.STATE_IDLE) or (self.state == self.STATE_STREAMS))
# add stream to the port
def add_stream (self, stream_id, stream_obj):
- if not self.is_port_writeable():
+ if not self.is_port_writable():
return self.err("Please stop port before attempting to add streams")
@@ -332,13 +330,14 @@ class CTRexStatelessClient(object):
self.user = username
self.comm_link = CTRexStatelessClient.CCommLink(server, sync_port, virtual)
self.verbose = False
+ self.ports = []
self._conn_handler = {}
self._active_ports = set()
self._system_info = None
self._server_version = None
self.__err_log = None
- self._async_client = CTRexAsyncClient(async_port)
+ self._async_client = CTRexAsyncClient(server, async_port)
self.streams_db = CStreamsDB()
@@ -378,7 +377,7 @@ class CTRexStatelessClient(object):
############ boot up section ################
# connection sequence
- def connect (self):
+ def connect(self):
self.connected = False
@@ -394,7 +393,7 @@ class CTRexStatelessClient(object):
self.system_info = data
- # cache supported cmds
+ # cache supported commands
rc, data = self.transmit("get_supported_cmds")
if not rc:
return RC_ERR(data)
@@ -402,8 +401,7 @@ class CTRexStatelessClient(object):
self.supported_cmds = data
# create ports
- self.ports = []
- for port_id in xrange(0, self.get_port_count()):
+ for port_id in xrange(self.get_port_count()):
self.ports.append(Port(port_id, self.user, self.transmit))
# acquire all ports
@@ -485,7 +483,6 @@ class CTRexStatelessClient(object):
return RC_ERR(data)
for port_info in data:
-
rc = self.ports[port_info['port_id']].sync(port_info)
if rc.bad():
return rc
@@ -619,23 +616,23 @@ class CTRexStatelessClient(object):
######################### Console (high level) API #########################
- def cmd_ping (self):
+ def cmd_ping(self):
rc = self.ping()
rc.annotate("Pinging the server on '{0}' port '{1}': ".format(self.get_connection_ip(), self.get_connection_port()))
return rc
- def cmd_connect (self):
+ def cmd_connect(self):
rc = self.connect()
rc.annotate()
return rc
- def cmd_disconnect (self):
+ def cmd_disconnect(self):
rc = self.disconnect()
rc.annotate()
return rc
# reset
- def cmd_reset (self):
+ def cmd_reset(self):
# sync with the server
diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py
index 7cb65fa6..ea2f5f12 100755
--- a/scripts/automation/trex_control_plane/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/console/trex_console.py
@@ -23,6 +23,7 @@ import json
import ast
import argparse
import random
+import readline
import string
import os
import sys
@@ -36,18 +37,69 @@ import trex_status
import parsing_opts
-__version__ = "1.0"
+__version__ = "1.1"
+
+
+class TRexGeneralCmd(cmd.Cmd):
+ def __init__(self):
+ cmd.Cmd.__init__(self)
+ # configure history behaviour
+ self._history_file_dir = "/tmp/trex/console/"
+ self._history_file = self.get_history_file_full_path()
+ readline.set_history_length(100)
+ # load history, if any
+ self.load_console_history()
+
+
+ def get_console_identifier(self):
+ return self.__class__.__name__
+
+ def get_history_file_full_path(self):
+ return "{dir}{filename}.hist".format(dir=self._history_file_dir,
+ filename=self.get_console_identifier())
+
+ def load_console_history(self):
+ if os.path.exists(self._history_file):
+ readline.read_history_file(self._history_file)
+ return
+
+ def save_console_history(self):
+ if not os.path.exists(self._history_file_dir):
+ os.makedirs(self._history_file_dir)
+ # os.mknod(self._history_file)
+ readline.write_history_file(self._history_file)
+ return
+
+ def emptyline(self):
+ """Called when an empty line is entered in response to the prompt.
+
+ This overriding is such that when empty line is passed, **nothing happens**.
+ """
+ return
+
+ def completenames(self, text, *ignored):
+ """
+ This overriding is such that a space is added to name completion.
+ """
+ dotext = 'do_'+text
+ return [a[3:]+' ' for a in self.get_names() if a.startswith(dotext)]
+
+ def precmd(self, line):
+ # before doing anything, save history snapshot of the console
+ # this is done before executing the command in case of ungraceful application exit
+ self.save_console_history()
+ return line
#
# main console object
-class TRexConsole(cmd.Cmd):
+class TRexConsole(TRexGeneralCmd):
"""Trex Console"""
- def __init__(self, stateless_client, acquire_all_ports = True, verbose = False):
- cmd.Cmd.__init__(self)
-
+ def __init__(self, stateless_client, acquire_all_ports=True, verbose=False):
self.stateless_client = stateless_client
+ TRexGeneralCmd.__init__(self)
+
self.verbose = verbose
self.acquire_all_ports = acquire_all_ports
@@ -60,11 +112,9 @@ class TRexConsole(cmd.Cmd):
################### internal section ########################
- # a cool hack - i stole this function and added space
- def completenames(self, text, *ignored):
- dotext = 'do_'+text
- return [a[3:]+' ' for a in self.get_names() if a.startswith(dotext)]
-
+ def get_console_identifier(self):
+ return "{context}_{server}".format(context=self.__class__.__name__,
+ server=self.stateless_client.get_system_info()['hostname'])
def register_main_console_methods(self):
main_names = set(self.trex_console.get_names()).difference(set(dir(self.__class__)))
diff --git a/scripts/exp/stl_simple_prog4-0-ex.erf b/scripts/exp/stl_simple_prog4-0-ex.erf
new file mode 100644
index 00000000..62da4682
--- /dev/null
+++ b/scripts/exp/stl_simple_prog4-0-ex.erf
Binary files differ
diff --git a/src/gtest/trex_stateless_gtest.cpp b/src/gtest/trex_stateless_gtest.cpp
index 65bafe83..432c7382 100644
--- a/src/gtest/trex_stateless_gtest.cpp
+++ b/src/gtest/trex_stateless_gtest.cpp
@@ -225,6 +225,89 @@ TEST_F(basic_stl, load_pcap_file) {
+TEST_F(basic_stl, simple_prog4) {
+
+ CBasicStl t1;
+ CParserOption * po =&CGlobalInfo::m_options;
+ po->preview.setVMode(7);
+ po->preview.setFileWrite(true);
+ po->out_file ="exp/stl_simple_prog4";
+
+ TrexStreamsCompiler compile;
+
+
+ std::vector<TrexStream *> streams;
+
+
+ /* stream0 */
+ TrexStream * stream0 = new TrexStream(TrexStream::stCONTINUOUS, 0,300);
+ stream0->set_pps(1.0);
+ stream0->m_enabled = true;
+ stream0->m_self_start = true;
+
+ CPcapLoader pcap;
+ pcap.load_pcap_file("cap2/udp_64B.pcap",0);
+ pcap.update_ip_src(0x10000000);
+ pcap.clone_packet_into_stream(stream0);
+ streams.push_back(stream0);
+
+
+ /* stream1 */
+ TrexStream * stream1 = new TrexStream(TrexStream::stSINGLE_BURST, 0,100);
+ stream1->set_pps(1.0);
+ stream1->set_single_burst(5);
+ stream1->m_enabled = true;
+ stream1->m_self_start = true;
+ stream1->m_next_stream_id=200;
+
+ pcap.load_pcap_file("cap2/udp_64B.pcap",0);
+ pcap.update_ip_src(0x10000001);
+ pcap.clone_packet_into_stream(stream1);
+
+ streams.push_back(stream1);
+
+
+ /* stream1 */
+
+ TrexStream * stream2 = new TrexStream(TrexStream::stMULTI_BURST, 0,200);
+ stream2->set_pps(1.0);
+ stream2->m_isg_usec = 1000000; /*time betwean stream 1 to stream 2 */
+ stream2->m_enabled = true;
+ stream2->m_self_start = false;
+ stream2->set_multi_burst(5,
+ 3,
+ 2000000.0);
+
+ // next stream is 100 - loop
+ stream2->m_next_stream_id=100;
+
+
+ pcap.load_pcap_file("cap2/udp_64B.pcap",0);
+ pcap.update_ip_src(0x10000002);
+ pcap.clone_packet_into_stream(stream2);
+ streams.push_back(stream2);
+
+
+ TrexStreamsCompiledObj comp_obj(0,1.0);
+
+ EXPECT_TRUE(compile.compile(streams, comp_obj) );
+
+ TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone(), 20.0 );
+
+
+ t1.m_msg = lpstart;
+
+ bool res=t1.init();
+
+ delete stream0 ;
+ delete stream1 ;
+ delete stream2 ;
+
+ EXPECT_EQ_UINT32(1, res?1:0)<< "pass";
+}
+
+
+
TEST_F(basic_stl, simple_prog3) {
CBasicStl t1;