added dpkt package, initial stateless client implementation
authorDan Klein <[email protected]>
Wed, 26 Aug 2015 11:27:43 +0000 (14:27 +0300)
committerDan Klein <[email protected]>
Wed, 26 Aug 2015 11:27:43 +0000 (14:27 +0300)
102 files changed:
external_libs/python/dpkt-1.8.6.2/AUTHORS [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/AUTHORS with 100% similarity]
external_libs/python/dpkt-1.8.6.2/CHANGES [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/CHANGES with 100% similarity]
external_libs/python/dpkt-1.8.6.2/LICENSE [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/LICENSE with 100% similarity]
external_libs/python/dpkt-1.8.6.2/MANIFEST.in [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/MANIFEST.in with 100% similarity]
external_libs/python/dpkt-1.8.6.2/PKG-INFO [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/PKG-INFO with 100% similarity]
external_libs/python/dpkt-1.8.6.2/README.md [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/README.md with 100% similarity]
external_libs/python/dpkt-1.8.6.2/README.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/README.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/Makefile [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/Makefile with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/api/api_auto.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/api/api_auto.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/api/index.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/api/index.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/authors.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/authors.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/badges.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/badges.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/changelog.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/changelog.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/conf.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/conf.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/contributing.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/contributing.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/examples.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/examples.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/index.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/index.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/installation.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/installation.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/license.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/license.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/plans.rst [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/plans.rst with 100% similarity]
external_libs/python/dpkt-1.8.6.2/docs/requirements.txt [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/docs/requirements.txt with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt.egg-info/PKG-INFO [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt.egg-info/PKG-INFO with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt.egg-info/SOURCES.txt [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt.egg-info/SOURCES.txt with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt.egg-info/dependency_links.txt [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt.egg-info/dependency_links.txt with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt.egg-info/not-zip-safe [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt.egg-info/not-zip-safe with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt.egg-info/top_level.txt [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt.egg-info/top_level.txt with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/__init__.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/__init__.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/ah.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/ah.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/aim.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/aim.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/aoe.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/aoe.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/aoeata.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/aoeata.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/aoecfg.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/aoecfg.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/arp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/arp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/asn1.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/asn1.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/bgp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/bgp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/cdp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/cdp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/crc32c.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/crc32c.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/decorators.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/decorators.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/dhcp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/dhcp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/diameter.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/diameter.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/dns.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/dns.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/dpkt.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/dpkt.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/dtp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/dtp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/esp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/esp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/ethernet.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/ethernet.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/gre.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/gre.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/gzip.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/gzip.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/h225.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/h225.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/hsrp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/hsrp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/http.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/http.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/icmp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/icmp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/icmp6.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/icmp6.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/ieee80211.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/ieee80211.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/igmp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/igmp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/ip.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/ip.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/ip6.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/ip6.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/ipx.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/ipx.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/llc.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/llc.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/loopback.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/loopback.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/mrt.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/mrt.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/netbios.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/netbios.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/netflow.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/netflow.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/ntp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/ntp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/ospf.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/ospf.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/pcap.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/pcap.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/pim.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/pim.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/pmap.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/pmap.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/ppp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/ppp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/pppoe.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/pppoe.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/qq.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/qq.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/radiotap.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/radiotap.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/radius.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/radius.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/rfb.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/rfb.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/rip.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/rip.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/rpc.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/rpc.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/rtp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/rtp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/rx.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/rx.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/sccp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/sccp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/sctp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/sctp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/sip.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/sip.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/sll.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/sll.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/smb.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/smb.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/snoop.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/snoop.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/ssl.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/ssl.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/ssl_ciphersuites.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/ssl_ciphersuites.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/stp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/stp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/stun.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/stun.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/tcp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/tcp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/telnet.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/telnet.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/tftp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/tftp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/tns.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/tns.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/tpkt.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/tpkt.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/udp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/udp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/vrrp.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/vrrp.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/dpkt/yahoo.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/dpkt/yahoo.py with 100% similarity]
external_libs/python/dpkt-1.8.6.2/setup.cfg [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/setup.cfg with 100% similarity]
external_libs/python/dpkt-1.8.6.2/setup.py [moved from scripts/automation/trex_control_plane/python_lib/dpkt-1.8.6.2/setup.py with 100% similarity]
scripts/automation/trex_control_plane/client/trex_stateless_client.py [new file with mode: 0644]
scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py
scripts/automation/trex_control_plane/client_utils/outer_packages.py
scripts/automation/trex_control_plane/client_utils/packet_builder.py [new file with mode: 0644]
scripts/automation/trex_control_plane/examples/interactive_stateless.py

diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
new file mode 100644 (file)
index 0000000..670eda1
--- /dev/null
@@ -0,0 +1,58 @@
+#!/router/bin/python
+
+try:
+    # support import for Python 2
+    import outer_packages
+except ImportError:
+    # support import for Python 3
+    import client.outer_packages
+from client_utils.jsonrpc_client import JsonRpcClient
+
+
+
+class CTRexStatelessClient(object):
+    """docstring for CTRexStatelessClient"""
+    def __init__(self, server="localhost", port=5050, virtual=False):
+        super(CTRexStatelessClient, self).__init__()
+        self.tx_link = CTRexStatelessClient.CTxLink(server, port, virtual)
+
+
+    def transmit(self, method_name, params = {}):
+        return self.tx_link.transmit(method_name, params)
+
+
+
+    class CTxLink(object):
+        """describes the connectivity of the stateless client method"""
+        def __init__(self, server="localhost", port=5050, virtual=False):
+            super(CTRexStatelessClient.CTxLink, self).__init__()
+            self.virtual = virtual
+            self.server = server
+            self.port = port
+            self.rpc_link = JsonRpcClient(self.server, self.port)
+            if not self.virtual:
+                self.rpc_link.connect()
+
+        def transmit(self, method_name, params = {}):
+            if self.virtual:
+                print "Transmitting virtually over tcp://{server}:{port}".format(
+                    server=self.server,
+                    port=self.port)
+                id, msg = self.rpc_link.create_jsonrpc_v2(method_name, params)
+                print msg
+                return
+            else:
+                return self.rpc_link.invoke_rpc_method(method_name, params)
+
+
+
+
+
+class CTRexVM(object):
+    """docstring for CTRexVM"""
+    def __init__(self, arg):
+        super(CTRexVM, self).__init__()
+        self.arg = arg
+
+if __name__ == "__main__":
+    pass
index 1631c49..89ac912 100644 (file)
@@ -34,16 +34,16 @@ class JsonRpcClient(object):
         print "[verbose] " + msg
 
 
-    def create_jsonrpc_v2 (self, method_name, params = {}, id = None):
+    def create_jsonrpc_v2 (self, method_name, params = {}):
         msg = {}
         msg["jsonrpc"] = "2.0"
         msg["method"]  = method_name
 
         msg["params"] = params
 
-        msg["id"] = id
+        msg["id"] = self.id_gen.next()
 
-        return json.dumps(msg)
+        return id, json.dumps(msg)
 
     def invoke_rpc_method (self, method_name, params = {}, block = False):
         rc, msg = self._invoke_rpc_method(method_name, params, block)
@@ -56,8 +56,7 @@ class JsonRpcClient(object):
         if not self.connected:
             return False, "Not connected to server"
 
-        id = self.id_gen.next()
-        msg = self.create_jsonrpc_v2(method_name, params, id = id)
+        id, msg = self.create_jsonrpc_v2(method_name, params)
 
         self.verbose_msg("Sending Request To Server:\n\n" + self.pretty_json(msg) + "\n")
 
@@ -180,7 +179,8 @@ class JsonRpcClient(object):
 
     def __del__(self):
         print "Shutting down RPC client\n"
-        self.context.destroy(linger=0)
+        if hasattr(self, "context"):
+            self.context.destroy(linger=0)
 
 if __name__ == "__main__":
     pass
index 53cce99..81672c9 100644 (file)
@@ -9,7 +9,9 @@ ROOT_PATH           = os.path.abspath(os.path.join(CURRENT_PATH, os.pardir))
 PATH_TO_PYTHON_LIB  = os.path.abspath(os.path.join(ROOT_PATH, os.pardir, os.pardir,
                                                    os.pardir, 'external_libs', 'python'))
 
-CLIENT_UTILS_MODULES = ['zmq']
+CLIENT_UTILS_MODULES = ['zmq',
+                        'dpkt-1.8.6.2'
+                        ]
 
 
 def import_client_utils_modules():
diff --git a/scripts/automation/trex_control_plane/client_utils/packet_builder.py b/scripts/automation/trex_control_plane/client_utils/packet_builder.py
new file mode 100644 (file)
index 0000000..c33444a
--- /dev/null
@@ -0,0 +1,11 @@
+#!/router/bin/python
+
+
+import outer_packages
+import dpkt
+
+class CTRexPktBuilder(object):
+    """docstring for CTRexPktBuilder"""
+    def __init__(self, arg):
+        super(CTRexPktBuilder, self).__init__()
+        self.arg = arg
\ No newline at end of file
index c0fc51a..016888d 100644 (file)
@@ -1,14 +1,17 @@
 #!/router/bin/python
 
 import trex_root_path
-from client.trex_client import *
+from client.trex_stateless_client import *
 from common.trex_exceptions import *
 import cmd
-from python_lib.termstyle import termstyle
+from termstyle import termstyle
+# import termstyle
 import os
 from argparse import ArgumentParser
 import socket
 import errno
+import ast
+import json
 
 
 class InteractiveStatelessTRex(cmd.Cmd):
@@ -17,10 +20,12 @@ class InteractiveStatelessTRex(cmd.Cmd):
                              \nType help to view available pre-defined scenarios\n(c) All rights reserved.\n")
     prompt = '> '
 
-    def __init__(self, verbose_mode=False):
+    def __init__(self, trex_host, trex_port, virtual, verbose):
         cmd.Cmd.__init__(self)
-        self.verbose = verbose_mode
-        self.trex = None
+
+        self.verbose = verbose
+        self.virtual = virtual
+        self.trex = CTRexStatelessClient(trex_host, trex_port, self.virtual)
         self.DEFAULT_RUN_PARAMS = dict(m=1.5,
                                        nc=True,
                                        p=True,
@@ -29,6 +34,47 @@ class InteractiveStatelessTRex(cmd.Cmd):
                                        l=1000)
         self.run_params = dict(self.DEFAULT_RUN_PARAMS)
 
+    def do_transmit(self, line):
+        """Transmits a request over using a given link to server.\
+        \nuse: transmit [method_name] [method_params]"""
+        if line == "":
+            print "\nUsage: [method name] [param dict as string]\n"
+            print "Example: rpc test_add {'x': 12, 'y': 17}\n"
+            return
+
+        args = line.split(' ', 1)   # args will have max length of 2
+        method_name = args[0]
+        params = None
+        bad_parse = False
+
+        try:
+            params = ast.literal_eval(args[1])
+            if not isinstance(params, dict):
+                bad_parse = True
+        except ValueError as e1:
+            bad_parse = True
+        except SyntaxError as e2:
+            bad_parse = True
+
+        if bad_parse:
+            print "\nValue should be a valid dict: '{0}'".format(args[1])
+            print "\nUsage: [method name] [param dict as string]\n"
+            print "Example: rpc test_add {'x': 12, 'y': 17}\n"
+            return
+
+        response = self.trex.transmit(method_name, params)
+        if not self.virtual:
+            # expect response
+            rc, msg = response
+            if rc:
+                print "\nServer Response:\n\n" + json.dumps(msg) + "\n"
+            else:
+                print "\n*** " + msg + "\n"
+
+
+
+
+
     def do_push_files(self, filepaths):
         """Pushes a custom file to be stored locally on T-Rex server.\
         \nPush multiple files by specifying their path separated by ' ' (space)."""
@@ -52,21 +98,25 @@ if __name__ == "__main__":
 
     parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0 \t (C) Cisco Systems Inc.\n')
 
-    parser.add_argument("-t", "--trex-host", required = True, dest="trex_host",
-        action="store", help="Specify the hostname or ip to connect with T-Rex server.",
-        metavar="HOST" )
-    parser.add_argument("-p", "--trex-port", type=int, default = 8090, metavar="PORT", dest="trex_port",
-        help="Select port on which the T-Rex server listens. Default port is 8090.", action="store")
+    parser.add_argument("-t", "--trex-host", required = True, dest="trex_host",
+        action="store", help="Specify the hostname or ip to connect with T-Rex server.",
+        metavar="HOST" )
+    parser.add_argument("-p", "--trex-port", type=int, default = 8090, metavar="PORT", dest="trex_port",
+        help="Select port on which the T-Rex server listens. Default port is 8090.", action="store")
     # parser.add_argument("-m", "--maxhist", type=int, default = 100, metavar="SIZE", dest="hist_size",
     #     help="Specify maximum history size saved at client side. Default size is 100.", action="store")
+    parser.add_argument("--virtual", dest="virtual",
+                        action="store_true",
+                        help="Switch ON virtual option at TRex client. Default is: OFF.",
+                        default=False)
     parser.add_argument("--verbose", dest="verbose",
                         action="store_true",
-                        help="Switch ON verbose option at T-Rex client. Default is: OFF.",
+                        help="Switch ON verbose option at TRex client. Default is: OFF.",
                         default=False)
     args = parser.parse_args()
 
     try:
-        InteractiveStatelessTRex(args.verbose).cmdloop()
+        InteractiveStatelessTRex(**vars(args)).cmdloop()
 
     except KeyboardInterrupt:
         print termstyle.cyan('Bye Bye!')