dtlsClient.hpp
Go to the documentation of this file.
1 #include <array>
2 #include <cstdint>
3 #include <iostream>
4 
5 #include <openssl/bio.h>
6 #include <openssl/conf.h>
7 #include <openssl/dh.h>
8 #include <openssl/engine.h>
9 #include <openssl/err.h>
10 #include <openssl/ssl.h>
11 
12 #include "IPv4_5TupleL2Ident.hpp"
13 #include "mbuf.hpp"
14 #include "stateMachine.hpp"
15 
16 namespace DTLS_Client {
17 
18 struct dtlsClient {
19  SSL *ssl;
20  BIO *wbio;
21  BIO *rbio;
22  uint32_t localIP;
23  uint32_t remoteIP;
24  uint16_t localPort;
25  uint16_t remotePort;
26  uint16_t counter;
27  std::array<uint8_t, 6> localMac;
28  std::array<uint8_t, 6> remoteMac;
29 };
30 
35 struct States {
36  static constexpr StateID DOWN = 0;
37  static constexpr StateID HANDSHAKE = 1;
38  static constexpr StateID ESTABLISHED = 2;
39  static constexpr StateID RUN_TEARDOWN = 3;
40  static constexpr StateID DELETED = 4;
41 };
42 
47 SSL_CTX *createCTX();
48 
59 
73  uint32_t localIP, uint32_t remoteIP, uint16_t localPort, uint16_t remotePort,
74  std::array<uint8_t, 6> localMac, std::array<uint8_t, 6> remoteMac);
75 
76 /*
77  * The following functions are the state functions, as they should be registered
78  * in the StateMachine<>
79  */
80 
82  StateMachine<IPv4_5TupleL2Ident<mbuf>, mbuf>::FunIface &funIface);
83 
85  StateMachine<IPv4_5TupleL2Ident<mbuf>, mbuf>::FunIface &funIface);
86 
88  StateMachine<IPv4_5TupleL2Ident<mbuf>, mbuf>::FunIface &funIface);
89 
91  StateMachine<IPv4_5TupleL2Ident<mbuf>, mbuf>::FunIface &funIface);
92 
93 }; // namespace DTLS_Client
94 
95 extern "C" {
105 void *DtlsClient_init(uint32_t dstIP, uint16_t dstPort, uint8_t srcMac[6], uint8_t dstMac[6]);
106 
119 void *DtlsClient_connect(void *obj, struct rte_mbuf **inPkts, unsigned int inCount,
120  unsigned int *sendCount, unsigned int *freeCount, uint32_t srcIP, uint16_t srcPort);
121 
128 void DtlsClient_getPkts(void *obj, struct rte_mbuf **sendPkts, struct rte_mbuf **freePkts);
129 
138 void *DtlsClient_process(void *obj, struct rte_mbuf **inPkts, unsigned int inCount,
139  unsigned int *sendCount, unsigned int *freeCount);
140 
145 void DtlsClient_free(void *obj);
146 }
static constexpr StateID DOWN
Definition: dtlsClient.hpp:36
void * DtlsClient_init(uint32_t dstIP, uint16_t dstPort, uint8_t srcMac[6], uint8_t dstMac[6])
Initialize a DTLS client.
Definition: dtlsClient.cpp:303
State machine framework.
void configStateMachine(StateMachine< IPv4_5TupleL2Ident< mbuf >, mbuf > &sm)
Configure the state machine.
void DtlsClient_free(void *obj)
Free recources used by the state machine.
Definition: dtlsClient.cpp:369
SSL_CTX * createCTX()
Use this to create the SSL context for creaeteStateData()
Definition: dtlsClient.cpp:11
The state of the DTLS client.
Definition: dtlsClient.hpp:35
StateMachine< IPv4_5TupleL2Ident< mbuf >, mbuf >::State createStateData(SSL_CTX *ctx, uint32_t localIP, uint32_t remoteIP, uint16_t localPort, uint16_t remotePort, std::array< uint8_t, 6 > localMac, std::array< uint8_t, 6 > remoteMac)
Create the state of the client.
Definition: dtlsClient.cpp:55
void * DtlsClient_connect(void *obj, struct rte_mbuf **inPkts, unsigned int inCount, unsigned int *sendCount, unsigned int *freeCount, uint32_t srcIP, uint16_t srcPort)
Add one connection to the State Machine.
Definition: dtlsClient.cpp:320
void runHandshake(StateMachine< IPv4_5TupleL2Ident< mbuf >, mbuf >::State &state, mbuf *, StateMachine< IPv4_5TupleL2Ident< mbuf >, mbuf >::FunIface &funIface)
void sendData(StateMachine< IPv4_5TupleL2Ident< mbuf >, mbuf >::State &state, mbuf *, StateMachine< IPv4_5TupleL2Ident< mbuf >, mbuf >::FunIface &funIface)
static constexpr StateID DELETED
Definition: dtlsClient.hpp:40
std::array< uint8_t, 6 > localMac
Definition: dtlsClient.hpp:27
static constexpr StateID ESTABLISHED
Definition: dtlsClient.hpp:38
void DtlsClient_getPkts(void *obj, struct rte_mbuf **sendPkts, struct rte_mbuf **freePkts)
Get the packets from an opaque structure.
Definition: dtlsClient.cpp:346
void * DtlsClient_process(void *obj, struct rte_mbuf **inPkts, unsigned int inCount, unsigned int *sendCount, unsigned int *freeCount)
Process incoming packets.
Definition: dtlsClient.cpp:355
Wrapper aroung DPDK rte_mbuf.
Definition: mbuf.hpp:9
static constexpr StateID HANDSHAKE
Definition: dtlsClient.hpp:37
std::array< uint8_t, 6 > remoteMac
Definition: dtlsClient.hpp:28
uint16_t StateID
Definition: common.hpp:19
void runTeardown(StateMachine< IPv4_5TupleL2Ident< mbuf >, mbuf >::State &state, mbuf *, StateMachine< IPv4_5TupleL2Ident< mbuf >, mbuf >::FunIface &funIface)
static constexpr StateID RUN_TEARDOWN
Definition: dtlsClient.hpp:39
void initHandshake(StateMachine< IPv4_5TupleL2Ident< mbuf >, mbuf >::State &state, mbuf *, StateMachine< IPv4_5TupleL2Ident< mbuf >, mbuf >::FunIface &funIface)