diff options
| author | guopeixu <[email protected]> | 2022-11-30 14:07:19 +0800 |
|---|---|---|
| committer | guopeixu <[email protected]> | 2022-11-30 14:07:57 +0800 |
| commit | 882763498372a8118d43f4aed0bf36d3f1eee16b (patch) | |
| tree | 6740d94e181cf6fb79348c9c1fe6282dd72d691d | |
| parent | 3e900681fcb332380aea44b7c5989455f7172a33 (diff) | |
python调用marsio的C接口
| -rw-r--r-- | .gitlab-ci.yml | 2 | ||||
| -rwxr-xr-x | tools/ptf_mrzcpd/marsio.py | 68 | ||||
| -rwxr-xr-x | tools/ptf_mrzcpd/test.py | 32 |
3 files changed, 99 insertions, 3 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d800f22..c4ec900 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -258,7 +258,7 @@ ptf_test_mrzcpd_for_centos8: - pip3 install scapy==2.4.5 - pip3 install -r requirements-dev.txt - cp /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_PATH/tools/ptf_mrzcpd ./ -rf - - python3 ./ptf --test-dir ./ptf_mrzcpd --interface 0-1@lo --test-params="mrzcpd='/tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_PATH/build/service/mrzcpd';conf='./ptf_mrzcpd/mrglobal.conf'" + - python3 ./ptf --test-dir ./ptf_mrzcpd --interface 0-1@lo --test-params="project='/tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX/$CI_PROJECT_PATH'" tags: - share diff --git a/tools/ptf_mrzcpd/marsio.py b/tools/ptf_mrzcpd/marsio.py new file mode 100755 index 0000000..fa5227a --- /dev/null +++ b/tools/ptf_mrzcpd/marsio.py @@ -0,0 +1,68 @@ +import ctypes
+from ctypes import *
+import ptf.testutils as testutils
+from enum import Enum
+
+MARSIO_OPT_THREAD_NUM = 0
+MARSIO_OPT_THREAD_AFFINITY_MODE = 1
+MARSIO_OPT_EXIT_WHEN_ERR = 2
+MARSIO_OPT_THREAD_MASK_IN_CPUSET = 3
+
+
+MR_SENDPATH_VDEV = 0
+MR_SENDPATH_ROUTE_NORMAL = 1
+MR_SENDPATH_ROUTE_SPEC_DEV = 2
+MR_SENDPATH_MAX = 3
+
+class marsio():
+ marsio_so = 0
+ def __init__(self):
+ print("im in marsio init")
+ project_path = testutils.test_param_get("project")
+ print("project_path = %s" % project_path)
+ marsio_so_path = project_path + "/build/app/libmarsio.so"
+ print("marsio_so_path = %s" % marsio_so_path)
+ self.marsio_so = ctypes.CDLL(marsio_so_path)
+ def marsio_create(self)->c_void_p:
+ self.marsio_so.marsio_create.restype= c_void_p
+ instance = self.marsio_so.marsio_create()
+ print(instance)
+ return instance
+ def marsio_init(self, instance, appsym):
+ print(instance)
+ self.marsio_so.marsio_init.restype = c_int
+ ret = self.marsio_so.marsio_init(c_void_p(instance), bytes(appsym,encoding="utf-8"))
+ print(ret)
+ return ret
+ def marsio_option_set(self, instance, opt_type, opt, sz_opt)->c_int:
+ self.marsio_so.marsio_option_set.restype = c_int
+ ret = self.marsio_so.marsio_option_set(c_void_p(instance), opt_type, c_void_p(opt), c_size_t(sz_opt))
+ return ret
+ def marsio_open_device(self, instance, devsym, nr_rxstream,nr_txstream)->c_void_p:
+ self.marsio_so.marsio_open_device.restype = c_void_p
+ ret = self.marsio_so.marsio_open_device(c_void_p(instance), bytes(devsym,encoding="utf-8"), c_uint(nr_rxstream),c_uint(nr_txstream))
+ return ret
+ def marsio_sendpath_create_by_droute(self, dest_device, addr_str)->c_void_p:
+ self.marsio_so.marsio_sendpath_create_by_droute_for_py.restype = c_void_p
+ ret = self.marsio_so.marsio_sendpath_create_by_droute_for_py(c_void_p(dest_device), bytes(addr_str,encoding="utf-8"))
+ return ret
+ def marsio_sendpath_create_by_route(self, instance, addr_str)->c_void_p:
+ self.marsio_so.marsio_sendpath_create_by_route_for_py.restype = c_void_p
+ ret = self.marsio_so.marsio_sendpath_create_by_route_for_py(c_void_p(instance), bytes(addr_str,encoding="utf-8"))
+ return ret
+ def marsio_sendpath_create_by_vdev(self, dest_device)->c_void_p:
+ self.marsio_so.marsio_sendpath_create_by_vdev.restype = c_void_p
+ ret = self.marsio_so.marsio_sendpath_create_by_vdev(c_void_p(dest_device))
+ return ret
+ def marsio_send_burst(self, sendpath, sid, mbufs, nr_mbufs)->c_int:
+ self.marsio_so.marsio_send_burst.restype = c_int
+ ret = self.marsio_so.marsio_send_burst(c_void_p(sendpath), c_uint(sid), mbufs, c_int(nr_mbufs))
+ return ret
+ def marsio_recv_burst(self, vdev, qid, mbufs, nr_mbufs)->c_int:
+ self.marsio_so.marsio_recv_burst.restype = c_int
+ ret = self.marsio_so.marsio_recv_burst(c_void_p(vdev), c_uint(qid), mbufs, c_int(nr_mbufs))
+ return ret
+ def __del__(self):
+ print("im in marsio del")
+
+
diff --git a/tools/ptf_mrzcpd/test.py b/tools/ptf_mrzcpd/test.py index dd118d0..936f095 100755 --- a/tools/ptf_mrzcpd/test.py +++ b/tools/ptf_mrzcpd/test.py @@ -6,6 +6,10 @@ import ptf.testutils as testutils import time import os import subprocess +import ctypes +from ctypes import * +import marsio +from marsio import * mrzcpd_pid=-1 @@ -28,8 +32,10 @@ class GlobalSetup(DataplaneBaseTest): def runTest(self): print() global mrzcpd_pid - mrzcpd_path = testutils.test_param_get("mrzcpd") - conf_path = testutils.test_param_get("conf") + project_path = testutils.test_param_get("project") + print("project_path = %s" % project_path) + mrzcpd_path = project_path + "/build/service/mrzcpd" + conf_path = project_path + "/tools/ptf_mrzcpd/mrglobal.conf" print("mrzcpd_path = %s" % mrzcpd_path) print("conf_path = %s" % conf_path) mrzcpd_process = subprocess.Popen([mrzcpd_path, "-c", conf_path]) @@ -49,6 +55,28 @@ class SimpleTcpPacketTest(DataplaneBaseTest): print("im in teardown") def runTest(self): print("im in runtest") + + mr_instance=marsio() + instance = mr_instance.marsio_create() + print(instance) + """ + mr_instance.marsio_option_set(instance, MARSIO_OPT_THREAD_MASK_IN_CPUSET, 0, 4) + mr_instance.marsio_init(instance, "app") + device = mr_instance.marsio_open_device(instance, "meth0", 10086, 95535) + print(device) + sendpath_droute = mr_instance.marsio_sendpath_create_by_droute(device,"192.168.1.1") + print(sendpath_droute) + sendpath_route = mr_instance.marsio_sendpath_create_by_route(instance, "192.168.2.2") + print(sendpath_route) + sendpath_vdev = mr_instance.marsio_sendpath_create_by_vdev(device) + print(sendpath_vdev) + + mbufs = ((c_char_p * 1024) *2)() + mbufs[0].value = "hello" + mbufs[1].value = " word" + #mr_instance.marsio_send_burst(sendpath_vdev, 1, mbufs, 2) + """ + pktlen = 400 pkt = testutils.simple_tcp_packet(pktlen=pktlen) self.assertEqual(len(pkt), pktlen) |
