summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
author童宗振 <[email protected]>2023-12-29 04:09:08 +0000
committer陆秋文 <[email protected]>2023-12-29 04:09:08 +0000
commitbf85d39733c93f00c9c3540156ced32c34dbf837 (patch)
tree8dd72a7e87122a6d09b8284ec64ba5cf3b62322b /examples
parentdda2a20a5fc0187f304994fd116711e40fec8493 (diff)
fix compile warning
Diffstat (limited to 'examples')
-rw-r--r--examples/vxlan-virtual-link-id.cc109
1 files changed, 57 insertions, 52 deletions
diff --git a/examples/vxlan-virtual-link-id.cc b/examples/vxlan-virtual-link-id.cc
index c13a997..675da3f 100644
--- a/examples/vxlan-virtual-link-id.cc
+++ b/examples/vxlan-virtual-link-id.cc
@@ -1,15 +1,15 @@
extern "C"
{
+#include <assert.h>
#include <marsio.h>
#include <mrtunnat.h>
+#include <pcap/pcap.h>
+#include <pthread.h>
#include <stdio.h>
-#include <assert.h>
#include <stdlib.h>
-#include <pthread.h>
-#include <unistd.h>
#include <string.h>
-#include <pcap/pcap.h>
+#include <unistd.h>
}
#include <string>
@@ -26,18 +26,18 @@ struct mr_instance * mr_instance = NULL;
struct mr_vdev * dev_handler = NULL;
struct mr_sendpath * sendpath = NULL;
-#define BURST_MAX 64
+#define BURST_MAX 64
unsigned int nr_burst = 1;
unsigned int self_loop = 0;
class PacketLoader
{
-private:
- pcap_t*pcap_handle_{ nullptr };
+ private:
+ pcap_t * pcap_handle_{nullptr};
-public:
+ public:
static constexpr unsigned int PKTLEN_MAX = 4096;
- void LoadFromPcapFile(const std::string &path)
+ void LoadFromPcapFile(const std::string & path)
{
char error_buffer[PCAP_ERRBUF_SIZE];
pcap_handle_ = pcap_open_offline(path.c_str(), error_buffer);
@@ -46,13 +46,16 @@ public:
virtual ~PacketLoader()
{
- if (pcap_handle_) pcap_close(pcap_handle_);
+ if (pcap_handle_)
+ pcap_close(pcap_handle_);
}
const unsigned char * FetchPacket(unsigned & pkt_len)
{
- struct pcap_pkthdr header{};
- auto *pkt_content = pcap_next(pcap_handle_, &header);
+ struct pcap_pkthdr header
+ {
+ };
+ auto * pkt_content = pcap_next(pcap_handle_, &header);
pkt_len = header.caplen;
return pkt_content;
}
@@ -62,7 +65,7 @@ class PacketLoader * packet_loader = nullptr;
void * txonly_loop(void * arg)
{
- uintptr_t sid = (uintptr_t) arg;
+ uintptr_t sid = (uintptr_t)arg;
marsio_buff_t * tx_buff[BURST_MAX];
marsio_thread_init(mr_instance);
@@ -76,10 +79,15 @@ void * txonly_loop(void * arg)
{
unsigned pkt_len;
auto * pkt_ptr = packet_loader->FetchPacket(pkt_len);
- if(pkt_ptr == nullptr) break;
+ if (pkt_ptr == nullptr)
+ break;
int ret = marsio_buff_malloc_global(mr_instance, tx_buff, 1, MARSIO_SOCKET_ID_ANY, MARSIO_LCORE_ID_ANY);
- assert(ret >= 0);
+ if (ret < 0)
+ {
+ fprintf(stderr, "marsio_buff_malloc_global execution failed.");
+ exit(0);
+ }
marsio_buff_t * tx_buff_ptr = tx_buff[0];
char * tx_buff_begin = marsio_buff_append(tx_buff_ptr, pkt_len);
@@ -89,7 +97,7 @@ void * txonly_loop(void * arg)
marsio_send_burst_with_options(sendpath, sid, tx_buff, 1, MARSIO_SEND_OPT_FAST);
}
- return (void *) NULL;
+ return (void *)NULL;
}
int help()
@@ -105,42 +113,39 @@ int main(int argc, char * argv[])
char * endptr = NULL;
switch (opt)
{
- case '?':
- case 'h':
- {
+ 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 '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 'r':
- {
- snprintf(str_pcap_file, sizeof(str_pcap_file), "%s", optarg);
- break;
- }
- case 't':
- {
- link_id = strtoull(optarg, &endptr, 0);
- if (cpu_mask == 0 && endptr == optarg) help();
- break;
- }
-
- default:help();
- break;
+ break;
+ }
+ case 'r': {
+ snprintf(str_pcap_file, sizeof(str_pcap_file), "%s", optarg);
+ break;
+ }
+ case 't': {
+ link_id = strtoull(optarg, &endptr, 0);
+ if (cpu_mask == 0 && endptr == optarg)
+ help();
+ break;
+ }
+
+ default:
+ help();
+ break;
}
}
@@ -169,7 +174,7 @@ int main(int argc, char * argv[])
pthread_t __tmp_pid[nr_thread];
for (unsigned int i = 0; i < nr_thread; i++)
{
- pthread_create(&__tmp_pid[i], nullptr, txonly_loop, (void *) (uintptr_t) i);
+ pthread_create(&__tmp_pid[i], nullptr, txonly_loop, (void *)(uintptr_t)i);
}
for (unsigned int i = 0; i < nr_thread; i++)