helloBye2_C.cpp
Go to the documentation of this file.
1 #include "helloBye2_C.hpp"
2 #include "bufArray.hpp"
3 #include "headers.hpp"
4 #include "mbuf.hpp"
5 #include "stateMachine.hpp"
6 
7 #include <rte_mbuf.h>
8 
9 extern "C" {
10 
11 /*
12  * Server
13  */
14 
16 
17  srand(time(NULL));
18 
20 
21  obj->registerEndStateID(HelloBye2::Server::States::Terminate);
22  obj->registerStartStateID(HelloBye2::Server::States::Hello,
24 
25  obj->registerFunction(HelloBye2::Server::States::Hello,
27  obj->registerFunction(HelloBye2::Server::States::Bye,
29 
30  return obj;
31 };
32 
33 void *HelloBye2_Server_process(void *obj, struct rte_mbuf **inPkts, unsigned int inCount,
34  unsigned int *sendCount, unsigned int *freeCount) {
35 
36  BufArray<mbuf> *inPktsBA =
37  new BufArray<mbuf>(reinterpret_cast<mbuf **>(inPkts), inCount, true);
38 
39  auto *sm = reinterpret_cast<StateMachine<HelloBye2::Identifier<mbuf>, mbuf> *>(obj);
40  sm->runPktBatch(*inPktsBA);
41  *sendCount = inPktsBA->getSendCount();
42  *freeCount = inPktsBA->getFreeCount();
43 
44  return inPktsBA;
45 };
46 
48  void *obj, struct rte_mbuf **sendPkts, struct rte_mbuf **freePkts) {
49  BufArray<mbuf> *inPktsBA = reinterpret_cast<BufArray<mbuf> *>(obj);
50 
51  inPktsBA->getSendBufs(reinterpret_cast<mbuf **>(sendPkts));
52  inPktsBA->getFreeBufs(reinterpret_cast<mbuf **>(freePkts));
53 
54  delete (inPktsBA);
55 };
56 
57 void HelloBye2_Server_free(void *obj) {
58  delete (reinterpret_cast<StateMachine<HelloBye2::Identifier<mbuf>, mbuf> *>(obj));
59 };
60 
61 /*
62  * Client
63  */
64 
66 
67  srand(time(NULL));
68 
70 
71  obj->registerEndStateID(HelloBye2::Client::States::Terminate);
72 
73  obj->registerFunction(HelloBye2::Client::States::Hello,
75  obj->registerFunction(HelloBye2::Client::States::Bye,
77  obj->registerFunction(HelloBye2::Client::States::RecvBye,
79 
80  return obj;
81 };
82 
83 void HelloBye2_Client_config(uint32_t srcIP, uint16_t dstPort) {
84 
87  config.setSrcIP(srcIP);
88  config.setDstPort(dstPort);
89 };
90 
91 void *HelloBye2_Client_connect(void *obj, struct rte_mbuf **inPkts, unsigned int inCount,
92  unsigned int *sendCount, unsigned int *freeCount, uint32_t dstIP, uint16_t srcPort,
93  uint64_t ident) {
94 
95  auto *sm = reinterpret_cast<StateMachine<HelloBye2::Identifier<mbuf>, mbuf> *>(obj);
96 
97  BufArray<mbuf> *inPktsBA =
98  new BufArray<mbuf>(reinterpret_cast<mbuf **>(inPkts), inCount, true);
99 
101  cID.ident = ident;
102 
104  dstIP, srcPort, ident);
105 
108 
109  sm->addState(cID, state, *inPktsBA);
110 
111  *sendCount = inPktsBA->getSendCount();
112  *freeCount = inPktsBA->getFreeCount();
113 
114  return inPktsBA;
115 };
116 
118  void *obj, struct rte_mbuf **sendPkts, struct rte_mbuf **freePkts) {
119  BufArray<mbuf> *inPktsBA = reinterpret_cast<BufArray<mbuf> *>(obj);
120 
121  inPktsBA->getSendBufs(reinterpret_cast<mbuf **>(sendPkts));
122  inPktsBA->getFreeBufs(reinterpret_cast<mbuf **>(freePkts));
123 
124  delete (inPktsBA);
125 };
126 
127 void *HelloBye2_Client_process(void *obj, struct rte_mbuf **inPkts, unsigned int inCount,
128  unsigned int *sendCount, unsigned int *freeCount) {
129  BufArray<mbuf> *inPktsBA =
130  new BufArray<mbuf>(reinterpret_cast<mbuf **>(inPkts), inCount, true);
131 
132  auto *sm = reinterpret_cast<StateMachine<HelloBye2::Identifier<mbuf>, mbuf> *>(obj);
133  sm->runPktBatch(*inPktsBA);
134  *sendCount = inPktsBA->getSendCount();
135  *freeCount = inPktsBA->getFreeCount();
136 
137  return inPktsBA;
138 };
139 
144 void HelloBye2_Client_free(void *obj) {
145  delete (reinterpret_cast<StateMachine<HelloBye2::Identifier<mbuf>, mbuf> *>(obj));
146 };
147 };
StateMachine< IPv4_5TupleL2Ident< mbuf >, mbuf > * sm
Definition: dtlsClient.cpp:300
static HelloBye2ClientConfig & getInstance()
static constexpr StateID Terminate
void runPktBatch(BufArray< Packet > &pktsIn)
Run a batch of packets.
State machine framework.
static constexpr StateID Hello
static constexpr StateID Bye
static constexpr StateID RecvBye
static constexpr StateID Terminate
uint32_t getFreeCount() const
Get the number of packets currently marked as free.
Definition: bufArray.hpp:166
static constexpr StateID Bye
void HelloBye2_Client_getPkts(void *obj, struct rte_mbuf **sendPkts, struct rte_mbuf **freePkts)
Get the packets to send and free.
void HelloBye2_Client_config(uint32_t srcIP, uint16_t dstPort)
Configure the client.
Definition: helloBye2_C.cpp:83
void setDstPort(uint16_t newPort)
void HelloBye2_Server_getPkts(void *obj, struct rte_mbuf **sendPkts, struct rte_mbuf **freePkts)
Get the packets to send and free.
Definition: helloBye2_C.cpp:47
void * HelloBye2_Server_process(void *obj, struct rte_mbuf **inPkts, unsigned int inCount, unsigned int *sendCount, unsigned int *freeCount)
Process a batch of packets.
Definition: helloBye2_C.cpp:33
void * HelloBye2_Client_init()
Init a HelloBye client.
Definition: helloBye2_C.cpp:65
void * HelloBye2_Client_process(void *obj, struct rte_mbuf **inPkts, unsigned int inCount, unsigned int *sendCount, unsigned int *freeCount)
Process a batch of packets.
static constexpr StateID Hello
uint32_t getSendCount() const
Get the number of packets currently marked as send.
Definition: bufArray.hpp:151
void addState(ConnectionID id, State st, BufArray< Packet > &pktsIn)
Open an outgoing connection.
Wrapper aroung DPDK rte_mbuf.
Definition: mbuf.hpp:9
uint16_t dstPort
Definition: dtlsClient.cpp:296
void getSendBufs(Packet **sendBufs) const
Get all the packets which are to be sent.
Definition: bufArray.hpp:175
void * HelloBye2_Server_init()
Init a HelloBye server.
Definition: helloBye2_C.cpp:15
void getFreeBufs(Packet **freeBufs) const
Get all the packets which are to be freed.
Definition: bufArray.hpp:193
void HelloBye2_Server_free(void *obj)
Free recources used by the state machine.
Definition: helloBye2_C.cpp:57
uint32_t dstIP
Definition: dtlsClient.cpp:295
Wrapper around MoonGen bufarrays.
Definition: bufArray.hpp:42
void * factory(Identifier< mbuf >::ConnectionID id)
Definition: helloBye3.cpp:20
void HelloBye2_Client_free(void *obj)
Free recources used by the state machine.
void * HelloBye2_Client_connect(void *obj, struct rte_mbuf **inPkts, unsigned int inCount, unsigned int *sendCount, unsigned int *freeCount, uint32_t dstIP, uint16_t srcPort, uint64_t ident)
Open a connection to a server.
Definition: helloBye2_C.cpp:91