summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLu Qiuwen <[email protected]>2018-11-29 19:18:57 +0800
committerLu Qiuwen <[email protected]>2018-11-29 19:18:57 +0800
commit0349b36e3d94804459ec2c6b32a5508a7e205712 (patch)
tree721927103c105d1a282546497fa88e5c834efdbf
parent7f1579e13b589b30719fc2b176d8f5b3a0443689 (diff)
增加vxlan网关有历史状态发包功能测试用例v4.2.44-20181129
-rw-r--r--examples/CMakeLists.txt5
-rw-r--r--examples/vxlan-encap.c156
2 files changed, 160 insertions, 1 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 6bebca2..5b73a59 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -13,4 +13,7 @@ add_executable(mrtest-rxonly rxonly.c)
target_link_libraries(mrtest-rxonly marsio pthread)
add_executable(mrtest-pag-rx pag/rx_sample.c)
-target_link_libraries(mrtest-pag-rx pag) \ No newline at end of file
+target_link_libraries(mrtest-pag-rx pag)
+
+add_executable(mrtest-vxlan-encap vxlan-encap.c)
+target_link_libraries(mrtest-vxlan-encap marsio pthread)
diff --git a/examples/vxlan-encap.c b/examples/vxlan-encap.c
new file mode 100644
index 0000000..68a3d3b
--- /dev/null
+++ b/examples/vxlan-encap.c
@@ -0,0 +1,156 @@
+
+#include <marsio.h>
+#include <mrtunnat.h>
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <string.h>
+
+static char appsym[64] = "vxlan_encap";
+static char dev_symbol[64] = "vxlan_user";
+
+uint64_t cpu_mask = 0x1;
+unsigned int nr_thread = 1;
+
+struct mr_instance * mr_instance = NULL;
+struct mr_vdev * dev_handler = NULL;
+struct mr_sendpath * sendpath = NULL;
+
+#define BURST_MAX 64
+unsigned int nr_burst = 1;
+unsigned int self_loop = 0;
+
+void * rxonly_loop(void * arg)
+{
+ uintptr_t sid = (uintptr_t)arg;
+ marsio_buff_t * rx_buff[BURST_MAX];
+ marsio_buff_t * tx_buff[BURST_MAX];
+ marsio_thread_init(mr_instance);
+
+ struct mr_tunnat_ctrlzone tx_ctrlzone;
+ memset(&tx_ctrlzone, 0, sizeof(struct mr_tunnat_ctrlzone));
+ tx_ctrlzone.action = TUNNAT_CZ_ACTION_ENCAP_INNER | TUNNAT_CZ_ACTION_ENCAP_OUTER;
+
+ for (;;)
+ {
+ int ret = marsio_recv_burst(dev_handler, sid, rx_buff, 1);
+ if (ret != 1) continue;
+
+ marsio_buff_t * rx_buff_ptr = rx_buff[0];
+ const char * pkt_ptr = marsio_buff_mtod(rx_buff_ptr);
+ unsigned int pkt_len = marsio_buff_datalen(rx_buff_ptr);
+ assert(pkt_ptr != NULL && pkt_len != 0);
+
+ /* Not encap packet, drop it */
+ struct mr_tunnat_ctrlzone * rx_ctrlzone = marsio_buff_ctrlzone(rx_buff_ptr, 0);
+ if (rx_ctrlzone->__encap_len == 0)
+ {
+ marsio_buff_free(mr_instance, rx_buff, 1, MARSIO_SOCKET_ID_ANY, MARSIO_LCORE_ID_ANY);
+ continue;
+ }
+
+ /* VXLAN packets, forward it */
+ ret = marsio_buff_malloc_global(mr_instance, tx_buff, 1, MARSIO_SOCKET_ID_ANY, MARSIO_LCORE_ID_ANY);
+ assert(ret >= 0);
+
+ marsio_buff_t * tx_buff_ptr = tx_buff[0];
+ char * tx_buff_begin = marsio_buff_append(tx_buff_ptr, pkt_len);
+ memcpy(tx_buff_begin, pkt_ptr, pkt_len);
+ marsio_buff_ctrlzone_set(tx_buff_ptr, 0, &tx_ctrlzone, sizeof(tx_ctrlzone));
+
+ marsio_send_burst_with_options(sendpath, sid, tx_buff, 1, MARSIO_SEND_OPT_FAST);
+ marsio_buff_free(mr_instance, rx_buff, 1, MARSIO_SOCKET_ID_ANY, MARSIO_LCORE_ID_ANY);
+ }
+
+ return (void *)NULL;
+}
+
+int help()
+{
+ return 0;
+}
+
+int main(int argc, char * argv[])
+{
+ int opt = 0;
+ while ((opt = getopt(argc, argv, "s:t:a:c:b:d:h?rl")) != -1)
+ {
+ char * endptr = NULL;
+ switch (opt)
+ {
+ case '?':
+ case 'h':
+ {
+ help();
+ break;
+ }
+ case 'd':
+ {
+ snprintf(dev_symbol, sizeof(dev_symbol), "%s", optarg);
+ break;
+ }
+ case 'a':
+ {
+ snprintf(appsym, sizeof(appsym), "%s", optarg);
+ break;
+ }
+ case 'c':
+ {
+ cpu_mask = strtoull(optarg, &endptr, 0);
+ if (cpu_mask == 0 && endptr == optarg) help();
+ break;
+ }
+ case 'b':
+ {
+ nr_burst = strtoull(optarg, &endptr, 0);
+ if (nr_burst == 0 && endptr == optarg) help();
+ break;
+ }
+ case 'l':
+ {
+ self_loop = 1;
+ break;
+ }
+
+ default:
+ help();
+ break;
+ }
+ }
+
+ mr_instance = marsio_create();
+ if (mr_instance == NULL)
+ {
+ fprintf(stderr, "Marsio instance create failed. ");
+ abort();
+ }
+
+ unsigned int opt_value = 1;
+ marsio_option_set(mr_instance, MARSIO_OPT_EXIT_WHEN_ERR, &opt_value, sizeof(opt_value));
+ marsio_option_set(mr_instance, MARSIO_OPT_THREAD_MASK, &cpu_mask, sizeof(cpu_mask));
+ marsio_init(mr_instance, appsym);
+
+ nr_thread = __builtin_popcountll(cpu_mask);
+ dev_handler = marsio_open_device(mr_instance, dev_symbol, nr_thread, nr_thread);
+ fprintf(stdout, "Thread Count = %d\n", nr_thread);
+
+ sendpath = marsio_sendpath_create_by_vdev(dev_handler);
+ assert(sendpath != NULL);
+
+ pthread_t __tmp_pid[nr_thread];
+ for (int i = 0; i < nr_thread; i++)
+ {
+ pthread_create(&__tmp_pid[i], NULL, rxonly_loop, (void *)(uintptr_t)i);
+ }
+
+ for (int i = 0; i < nr_thread; i++)
+ {
+ pthread_join(__tmp_pid[i], NULL);
+ }
+
+ marsio_destory(mr_instance);
+ fprintf(stdout, "RXONLY is terminated. ");
+ return 0;
+}