helloBye_C.cpp
Go to the documentation of this file.
1 #include "helloBye_C.hpp"
2 #include "IPv4_5TupleL2Ident.hpp"
3 #include "bufArray.hpp"
4 #include "headers.hpp"
5 #include "mbuf.hpp"
6 #include "stateMachine.hpp"
7 
8 #include <rte_mbuf.h>
9 
10 extern "C" {
11 
12 /*
13  * Server
14  */
15 
17 
18  auto *obj = new StateMachine<IPv4_5TupleL2Ident<mbuf>, mbuf>();
19 
20  obj->registerEndStateID(HelloBye::HelloByeServer::Terminate);
21  obj->registerStartStateID(HelloBye::HelloByeServer::Hello,
23 
24  obj->registerFunction(HelloBye::HelloByeServer::Hello,
26  obj->registerFunction(HelloBye::HelloByeServer::Bye,
28 
29  return obj;
30 };
31 
32 void *HelloByeServer_process(void *obj, struct rte_mbuf **inPkts, unsigned int inCount,
33  unsigned int *sendCount, unsigned int *freeCount) {
34 
35  BufArray<mbuf> *inPktsBA =
36  new BufArray<mbuf>(reinterpret_cast<mbuf **>(inPkts), inCount, true);
37 
38  auto *sm = reinterpret_cast<StateMachine<IPv4_5TupleL2Ident<mbuf>, mbuf> *>(obj);
39  sm->runPktBatch(*inPktsBA);
40  *sendCount = inPktsBA->getSendCount();
41  *freeCount = inPktsBA->getFreeCount();
42 
43  return inPktsBA;
44 };
45 
47  void *obj, struct rte_mbuf **sendPkts, struct rte_mbuf **freePkts) {
48  BufArray<mbuf> *inPktsBA = reinterpret_cast<BufArray<mbuf> *>(obj);
49 
50  inPktsBA->getSendBufs(reinterpret_cast<mbuf **>(sendPkts));
51  inPktsBA->getFreeBufs(reinterpret_cast<mbuf **>(freePkts));
52 
53  delete (inPktsBA);
54 };
55 
56 void HelloByeServer_free(void *obj) {
57  delete (reinterpret_cast<StateMachine<IPv4_5TupleL2Ident<mbuf>, mbuf> *>(obj));
58 };
59 
60 /*
61  * Client
62  */
63 
65  auto *obj = new StateMachine<IPv4_5TupleL2Ident<mbuf>, mbuf>();
66 
67  obj->registerEndStateID(HelloBye::HelloByeClient::Terminate);
68 
69  obj->registerFunction(HelloBye::HelloByeClient::Hello,
71  obj->registerFunction(HelloBye::HelloByeClient::Bye,
73  obj->registerFunction(HelloBye::HelloByeClient::RecvBye,
75 
76  return obj;
77 };
78 
79 void HelloByeClient_config(uint32_t srcIP, uint16_t dstPort) {
80 
83  config->setSrcIP(srcIP);
84  config->setDstPort(dstPort);
85 };
86 
87 void *HelloByeClient_connect(void *obj, struct rte_mbuf **inPkts, unsigned int inCount,
88  unsigned int *sendCount, unsigned int *freeCount, uint32_t dstIP, uint16_t srcPort) {
89 
90  auto *sm = reinterpret_cast<StateMachine<IPv4_5TupleL2Ident<mbuf>, mbuf> *>(obj);
91 
92  BufArray<mbuf> *inPktsBA =
93  new BufArray<mbuf>(reinterpret_cast<mbuf **>(inPkts), inCount, true);
94 
96 
98  cID.dstIP = htonl(config->getSrcIP());
99  cID.srcIP = htonl(dstIP);
100  cID.dstPort = htons(srcPort);
101  cID.srcPort = htons(config->getDstPort());
102  cID.proto = Headers::IPv4::PROTO_UDP;
103 
104  auto *hello =
106 
109 
110  sm->addState(cID, state, *inPktsBA);
111 
112  *sendCount = inPktsBA->getSendCount();
113  *freeCount = inPktsBA->getFreeCount();
114 
115  return inPktsBA;
116 };
117 
119  void *obj, struct rte_mbuf **sendPkts, struct rte_mbuf **freePkts) {
120  BufArray<mbuf> *inPktsBA = reinterpret_cast<BufArray<mbuf> *>(obj);
121 
122  inPktsBA->getSendBufs(reinterpret_cast<mbuf **>(sendPkts));
123  inPktsBA->getFreeBufs(reinterpret_cast<mbuf **>(freePkts));
124 
125  delete (inPktsBA);
126 };
127 
128 void *HelloByeClient_process(void *obj, struct rte_mbuf **inPkts, unsigned int inCount,
129  unsigned int *sendCount, unsigned int *freeCount) {
130  BufArray<mbuf> *inPktsBA =
131  new BufArray<mbuf>(reinterpret_cast<mbuf **>(inPkts), inCount, true);
132 
133  auto *sm = reinterpret_cast<StateMachine<IPv4_5TupleL2Ident<mbuf>, mbuf> *>(obj);
134  sm->runPktBatch(*inPktsBA);
135  *sendCount = inPktsBA->getSendCount();
136  *freeCount = inPktsBA->getFreeCount();
137 
138  return inPktsBA;
139 };
140 
145 void HelloByeClient_free(void *obj) {
146  delete (reinterpret_cast<StateMachine<IPv4_5TupleL2Ident<mbuf>, mbuf> *>(obj));
147 };
148 };
void HelloByeServer_getPkts(void *obj, struct rte_mbuf **sendPkts, struct rte_mbuf **freePkts)
Get the packets to send and free.
Definition: helloBye_C.cpp:46
static constexpr StateID Hello
void setDstPort(uint16_t newPort)
void * HelloByeServer_process(void *obj, struct rte_mbuf **inPkts, unsigned int inCount, unsigned int *sendCount, unsigned int *freeCount)
Process a batch of packets.
Definition: helloBye_C.cpp:32
State machine framework.
static constexpr StateID Terminate
void * HelloByeClient_init()
Init a HelloBye client.
Definition: helloBye_C.cpp:64
static constexpr StateID Bye
uint32_t getFreeCount() const
Get the number of packets currently marked as free.
Definition: bufArray.hpp:166
static HelloByeClientConfig * getInstance()
static constexpr StateID Hello
static constexpr StateID RecvBye
void HelloByeServer_free(void *obj)
Free recources used by the state machine.
Definition: helloBye_C.cpp:56
void * HelloByeClient_connect(void *obj, struct rte_mbuf **inPkts, unsigned int inCount, unsigned int *sendCount, unsigned int *freeCount, uint32_t dstIP, uint16_t srcPort)
Open a connection to a server.
Definition: helloBye_C.cpp:87
static constexpr uint8_t PROTO_UDP
Definition: headers.hpp:111
uint32_t getSendCount() const
Get the number of packets currently marked as send.
Definition: bufArray.hpp:151
Wrapper aroung DPDK rte_mbuf.
Definition: mbuf.hpp:9
void * HelloByeServer_init()
Init a HelloBye server.
Definition: helloBye_C.cpp:16
void HelloByeClient_free(void *obj)
Free recources used by the state machine.
Definition: helloBye_C.cpp:145
void getSendBufs(Packet **sendBufs) const
Get all the packets which are to be sent.
Definition: bufArray.hpp:175
void * HelloByeClient_process(void *obj, struct rte_mbuf **inPkts, unsigned int inCount, unsigned int *sendCount, unsigned int *freeCount)
Process a batch of packets.
Definition: helloBye_C.cpp:128
void getFreeBufs(Packet **freeBufs) const
Get all the packets which are to be freed.
Definition: bufArray.hpp:193
void HelloByeClient_config(uint32_t srcIP, uint16_t dstPort)
Configure the client.
Definition: helloBye_C.cpp:79
static constexpr StateID Terminate
void HelloByeClient_getPkts(void *obj, struct rte_mbuf **sendPkts, struct rte_mbuf **freePkts)
Get the packets to send and free.
Definition: helloBye_C.cpp:118
static constexpr StateID Bye
Wrapper around MoonGen bufarrays.
Definition: bufArray.hpp:42
void setSrcIP(uint32_t newIP)
void * factory(Identifier< mbuf >::ConnectionID id)
Definition: helloBye3.cpp:20