ITS
Geonet.h
Go to the documentation of this file.
1 
7 #ifndef _Geonet_H_
8 #define _Geonet_H_
9 
10 #include <iostream>
11 #include <QObject>
12 #include <QUdpSocket>
13 #include <stdlib.h>
14 #include <api.h>
15 #include <apiNetwork.h>
16 #include <DestinationArea.h>
17 #include <BeaconPacket.h>
18 #include <SHBPacket.h>
19 #include <GBCPacket.h>
20 #include <LSRequestPacket.h>
21 #include <LSReplyPacket.h>
22 #include <Manager.h>
23 #include <LocationTableEntry.h>
24 #include <GNDataRequest.h>
25 #include <BasicHeader.h>
26 #include <CommonHeader.h>
27 #include <ParameterNetwork.h>
28 #include <ParameterHybrid.h>
29 #include <caReceptionManagement.h>
30 #include <HistoryPacketBuffer.h>
33 #include <CBFPacketBuffer.h>
35 #include <RepetitionPacketBuffer.h>
36 #include <UpperTesterPrimitives.h>
37 #include <ReceivePackets.h>
39 #include <QSslSocket>
40 #include <SecurityManager.h>
41 
42 class GeoNet : public QObject
43 {
44  Q_OBJECT
45 public:
46 
51  {
52  uchar mid[6];
53  };
54 
59  {
64  };
65 
70  {
73  };
74 
79  {
82  // Send Errors
83  // Common Header Errors
85  // Anycast
87  // Broadcast
89  // Topological
92  // LSRequest Send Errors
98  // LSReply send Errors
104  // LSReply Forward Errors
109  // GAC Send Errors
120  // GAC Forward Errors
127  // GBC Send Errors
135  // GBC Forward Errors
141  // GUC Send Errors
149  // GUC Forward Errors
154  // SHB Send Errors
159  // TSB Send Errors
163  // TSB Forward Errors
167  // Receive Errors
168  // Basic Header Errors
173  // Common Header Errors
179  // Duplicate Packet Address Errors
189  // Duplicate Packet Timestamp &&/|| SN Errors
199  };
200 
204  GeoNet();
212  GeoNet(Manager* m, bool geonetFlag, bool hybridFlag, QMutex* mutex = nullptr);
216  ~GeoNet();
217 
223  int send(gnDataRequest_t gnDR);
224  //static int send(FakeApplicationProvider* paramAppli, FakeGPSProvider* paramGPS, ParameterConfiguration* paramConf, ParameterNetwork* paramNetwork, GnAddr* gnAddr, HistoryPacketBuffer* hpb);
226  //static int send(QByteArray payload, ParameterConfiguration* paramConf, ParameterNetwork* paramNetwork, bool containLPV);
234  int send(QByteArray payloadToSend, bool containLPV, BasicHeader bh);
235 
236  //static QElapsedTimer timeLastLPVSent;
237  static quint16 sequenceNumber;
250  ForwardingAlgorithmResponse greedy(BasicHeader bh, CommonHeader ch, GACPacket packet, QByteArray payload, QByteArray sender, uchar* destination, uchar* forwarder);
262  ForwardingAlgorithmResponse greedy(BasicHeader bh, CommonHeader ch, GBCPacket packet, QByteArray payload, QByteArray sender, uchar *destination, uchar *forwarder);
272  ForwardingAlgorithmResponse greedy(BasicHeader bh, CommonHeader ch, GUCPacket packet, QByteArray payload, QByteArray sender);
281  ForwardingAlgorithmResponse greedy(BasicHeader bh, CommonHeader ch, LSReplyPacket packet, QByteArray sender);
282 
294  ForwardingAlgorithmResponse simpleForwardingAlgorithm(BasicHeader bh, CommonHeader ch, GBCPacket packet, QByteArray packetPayload, e_shape shape, QByteArray sender, bool flagSrc);
295 
307  ForwardingAlgorithmResponse contentionBasedForwardingAlgorithm(BasicHeader bh, CommonHeader ch, GBCPacket packet, QByteArray packetPayload, e_shape shape, QByteArray sender, bool flagSrc);
308 
322  ForwardingAlgorithmResponse advancedForwarding(BasicHeader bh, CommonHeader ch, GBCPacket packet, QByteArray packetPayload, e_shape shape, QByteArray sender, uchar* destEth, uchar* forwarderEth, bool flagSrc);
323 
332  ForwardingAlgorithmResponse CBFUnicast(BasicHeader bh, CommonHeader ch, GACPacket packet, QByteArray packetPayload);
341  ForwardingAlgorithmResponse CBFUnicast(BasicHeader bh, CommonHeader ch, GUCPacket packet, QByteArray packetPayload);
342 
343 
344  QHash<int, QString> geonetErrors;
348 signals:
352  void lpvSent();
356  void packetReceived(QByteArray);
357 
358 public slots:
362  void execute();
367  void treatPackets(QByteArray);
372  void sendPacketFromRPB(gnDataRequest_t rawPacket);
376  void lpvUpdate();
381  void sendBeacon();
385  void utInitialize();
393  int lsRetransmit(GnAddr destination, QByteArray lsRequestData, BasicHeader bh);
394 
395 private slots:
402  int sendGUC(gnDataRequest_t gnDR);
406  void socketReadyRead();
407 
408 private:
412  void initGeoNetErrors();
413 
414 
422  int sendLsRequest(GnAddr dest, gnDataRequest_t gnDR);
429  int sendGAC(gnDataRequest_t gnDR);
436  int sendGBC(gnDataRequest_t gnDR);
438  //int sendGUC(gnDataRequest_t gnDR);
445  int sendSHB(gnDataRequest_t gnDR);
452  int sendTSB(gnDataRequest_t gnDR);
453 
462  int basicHeaderProcessing(uchar* packet, int len, sniff_ethernet_t* eth);
471  int commonHeaderProcessing(uchar* packet, sniff_ethernet_t* eth, BasicHeader bh);
481  int beaconPacketProcessing(uchar* packet, sniff_ethernet_t* eth, BasicHeader bh, CommonHeader ch);
491  int gacPacketProcessing(uchar* packet, sniff_ethernet_t* eth, BasicHeader bh, CommonHeader ch);
501  int gbcPacketProcessing(uchar* packet, sniff_ethernet_t* eth, BasicHeader bh, CommonHeader ch);
511  int gucPacketProcessing(uchar* packet, sniff_ethernet_t* eth, BasicHeader bh, CommonHeader ch);
521  int shbPacketProcessing(uchar* packet, sniff_ethernet_t* eth, BasicHeader bh, CommonHeader ch);
531  int tsbPacketProcessing(uchar* packet, sniff_ethernet_t* eth, BasicHeader bh, CommonHeader ch);
541  int LSRequestPacketProcessing(uchar* packet, sniff_ethernet_t* eth, BasicHeader bh, CommonHeader ch);
551  int LSReplyPacketProcessing(uchar* packet, sniff_ethernet_t* eth, BasicHeader bh, CommonHeader ch);
552 
558  void sendEventIndicationToUT(uchar* packetFull, int packetLen);
559 
560  //void handleBasicHeader(BasicHeader);
565  int InitRawSocket_send();
566 
570  void verifLocT();
571 
572  QTimer *m_beacon;
574  QUdpSocket* gen2fac;
575  QUdpSocket* gen2ut;
577  QSslSocket* m_sslSocket;
578  QTcpSocket* m_tcpSocket;
585  void initHybridSocket();
590  void sslErrors(const QList<QSslError> &errors);
594  void socketError(QAbstractSocket::SocketError);
598  void setupUnsecureSocket();
602  void setupSecureSocket();
608  int hybridSend(QByteArray payload);
609 
627  QHash<QByteArray, LocationTableEntry>* m_locationTable;
631  QHash<QByteArray, int> m_lsRetransmission;
633  QMutex* m_mutex;
634  QMutex* m_mutexLocT;
636  QHash<QByteArray, int> m_CBFPBCounter;
642  void flushPB(GnAddr destination);
643 
648  void flushLSPB(GnAddr destination);
652  void checkUCFPB();
657  void flushUCFPB(GnAddr destination);
661  void checkBCFPB();
662 
668  int TO_CBF_GBC(int distance);
674  int TO_CBF_GUC(int distance);
675 
679  void calculAngleThreshold();
680 
689  ForwardingAlgorithmResponse greedy(PacketBuffersEntry packet, QByteArray sender);
690 
691  /* Security layer */
698  QByteArray getSecuredPayload(QByteArray payload, BasicHeader bh);
705  QByteArray verifySecuredPayload(QByteArray payload, bool *success);
706  QUdpSocket *m_signatureSocket;
707  QUdpSocket *m_verifySocket;
709 };
710 
711 #endif // _Geonet_H_
Buffer used for CBF.
int sendGUC(gnDataRequest_t gnDR)
sendGUC Send a GUC.
Definition: Geonet.cpp:929
ForwardingAlgorithmResponse simpleForwardingAlgorithm(BasicHeader bh, CommonHeader ch, GBCPacket packet, QByteArray packetPayload, e_shape shape, QByteArray sender, bool flagSrc)
simpleForwardingAlgorithm Simple algorithm.
Definition: Geonet.cpp:2627
FakeGPSProvider * m_paramGPS
Definition: Geonet.h:610
Network configuration.
Location table entry definition.
void checkBCFPB()
checkBCFPB Check to flush the broadcast forawarding packet buffer.
Definition: Geonet.cpp:3267
gnDataRequest_t structure is the GN data request definition.
Definition: GNDataRequest.h:46
void flushLSPB(GnAddr destination)
flushLSPB Flush LS packet buffer.
Definition: Geonet.cpp:3078
int sendGBC(gnDataRequest_t gnDR)
sendGBC Send an LSRequest.
Definition: Geonet.cpp:815
CBFPacketBuffer * m_CBFPB
Definition: Geonet.h:623
GeoNet()
GeoNet GeoNet constructor.
Definition: Geonet.cpp:6
void sendPacketFromRPB(gnDataRequest_t rawPacket)
sendPacketFromRPB Slot used to send packet from repetition packet buffer.
Definition: Geonet.cpp:491
ForwardingAlgorithmResponse contentionBasedForwardingAlgorithm(BasicHeader bh, CommonHeader ch, GBCPacket packet, QByteArray packetPayload, e_shape shape, QByteArray sender, bool flagSrc)
contentionBasedForwardingAlgorithm CBF algorithm.
Definition: Geonet.cpp:2705
Usefull functions and declarations.
void verifLocT()
verifLocT Checks if the LocT has expired packet.
Definition: Geonet.cpp:212
ReceivePackets * m_RP
Definition: Geonet.h:629
int gbcPacketProcessing(uchar *packet, sniff_ethernet_t *eth, BasicHeader bh, CommonHeader ch)
gbcPacketProcessing GBC Header decoding.
Definition: Geonet.cpp:1934
GnAddr * m_gnAddr
Definition: Geonet.h:617
Buffer used to store sent and received packets.
int lsRetransmit(GnAddr destination, QByteArray lsRequestData, BasicHeader bh)
lsRetransmit Retransmission of an LSRequest.
Definition: Geonet.cpp:459
Common Header structure.
int TO_CBF_GUC(int distance)
TO_CBF_GUC TO_CBF_GUC computation.
Definition: Geonet.cpp:2504
~GeoNet()
~GeoNet GeoNet destructor.
Definition: Geonet.cpp:175
void treatPackets(QByteArray)
treatPackets Slot used to treat received packets.
Definition: Geonet.cpp:1248
QSslSocket * m_sslSocket
Definition: Geonet.h:577
int m_angleThreshold
Definition: Geonet.h:681
ParameterSecurity * m_paramSecu
Definition: Geonet.h:616
int commonHeaderProcessing(uchar *packet, sniff_ethernet_t *eth, BasicHeader bh)
commonHeaderProcessing Common Header decoding.
Definition: Geonet.cpp:1307
void sslErrors(const QList< QSslError > &errors)
sslErrors Print SSL errors.
Definition: Geonet.cpp:129
QMutex * m_mutexLocT
Definition: Geonet.h:634
SecurityManager definitions.
The destinationAddress_u union is used by the ForwardingalgorithmResponse, and so is an union...
Definition: Geonet.h:50
LSRequest Packet structure.
QByteArray getSecuredPayload(QByteArray payload, BasicHeader bh)
getSecuredPayload Send payload to secure to the HSM.jar.
Definition: Geonet.cpp:3461
void sendBeacon()
sendBeacon Slot used to send Beacon.
Definition: Geonet.cpp:569
Beacon packet structure.
QHash< QByteArray, LocationTableEntry > * m_locationTable
Definition: Geonet.h:627
Basic Header structure.
Manager class.
GN data request definition.
ParameterUpperTester * m_paramUpperTester
Definition: Geonet.h:614
QUdpSocket * m_signatureSocket
Definition: Geonet.h:706
SHB packet structure.
Buffer used for unicast forwarding.
bool m_hybridFlag
Definition: Geonet.h:580
Manager * m_manager
Definition: Geonet.h:618
QHash< int, QString > geonetErrors
Definition: Geonet.h:344
int sendLsRequest(GnAddr dest, gnDataRequest_t gnDR)
sendLsRequest Send an LSRequest.
Definition: Geonet.cpp:610
void flushPB(GnAddr destination)
flushPB Flush buffer.
Definition: Geonet.cpp:3071
ForwardingAlgorithmResponse advancedForwarding(BasicHeader bh, CommonHeader ch, GBCPacket packet, QByteArray packetPayload, e_shape shape, QByteArray sender, uchar *destEth, uchar *forwarderEth, bool flagSrc)
advancedForwarding Advanced algorithm.
Definition: Geonet.cpp:2805
The sniff_ethernet_t structure is a C style of the Ethernet header.
static quint16 sequenceNumber
Definition: Geonet.h:237
QUdpSocket * gen2ut
Definition: Geonet.h:575
void socketReadyRead()
socketReadyRead Slot used when socket is ready to read.
Definition: Geonet.cpp:147
Destination area structure.
Choice between a number or a MAC address.
QMutex * m_mutex
Definition: Geonet.h:633
Receiving packet class.
ParameterConfiguration * m_paramConf
Definition: Geonet.h:613
ParameterHybrid * m_paramHybrid
Definition: Geonet.h:579
FakeCANProvider * m_paramCAN
Definition: Geonet.h:611
QTimer * m_beacon
Definition: Geonet.h:572
bool m_geonetFlag
Definition: Geonet.h:581
e_geonetError
The e_geonetError enum is used for header encoding / decoding debug purpose.
Definition: Geonet.h:78
QHash< QByteArray, int > m_lsRetransmission
Definition: Geonet.h:631
int basicHeaderProcessing(uchar *packet, int len, sniff_ethernet_t *eth)
basicHeaderProcessing Basic Header decoding.
Definition: Geonet.cpp:1263
HistoryPacketBuffer * m_HPB
Definition: Geonet.h:620
Primitives message types definition.
void packetReceived(QByteArray)
packetReceived Signal used when a packet is received.
int shbPacketProcessing(uchar *packet, sniff_ethernet_t *eth, BasicHeader bh, CommonHeader ch)
shbPacketProcessing SHB Header decoding.
Definition: Geonet.cpp:2302
LSReply packet structure.
CAM reception management.
void initHybridSocket()
initHybridSocket Set the hybridization sockets.
Definition: Geonet.cpp:103
QHash< QByteArray, int > m_CBFPBCounter
Definition: Geonet.h:636
int tsbPacketProcessing(uchar *packet, sniff_ethernet_t *eth, BasicHeader bh, CommonHeader ch)
tsbPacketProcessing TSB Header decoding.
Definition: Geonet.cpp:2364
QUdpSocket * gen2fac
Definition: Geonet.h:574
QTcpSocket * m_tcpSocket
Definition: Geonet.h:578
int gucPacketProcessing(uchar *packet, sniff_ethernet_t *eth, BasicHeader bh, CommonHeader ch)
gucPacketProcessing GUC Header decoding.
Definition: Geonet.cpp:2128
LocationServicePacketBuffer * m_LSPB
Definition: Geonet.h:625
int beaconPacketProcessing(uchar *packet, sniff_ethernet_t *eth, BasicHeader bh, CommonHeader ch)
beaconPacketProcessing Beacon Header decoding.
Definition: Geonet.cpp:1369
e_shape
The e_shape enum defines the shapes type.
Definition: constantes.h:54
ForwardingAlgorithmResponse greedy(BasicHeader bh, CommonHeader ch, GACPacket packet, QByteArray payload, QByteArray sender, uchar *destination, uchar *forwarder)
greedy Greedy algorithm.
Definition: Geonet.cpp:2512
int sendTSB(gnDataRequest_t gnDR)
sendTSB Send an LSRequest.
Definition: Geonet.cpp:1090
void sendEventIndicationToUT(uchar *packetFull, int packetLen)
sendEventIndicationToUT Send decoding success notification to the UpperTester.
Definition: Geonet.cpp:442
GBC packet structure.
QUdpSocket * m_verifySocket
Definition: Geonet.h:707
void setupUnsecureSocket()
setupUnsecureSocket Set TCP socket for hybridization.
Definition: Geonet.cpp:159
int TO_CBF_GBC(int distance)
TO_CBF_GBC TO_CBF_GBC computation.
Definition: Geonet.cpp:2496
Buffer used for broadcast forwarding.
int sendSHB(gnDataRequest_t gnDR)
sendSHB Send an LSRequest.
Definition: Geonet.cpp:1026
int sendGAC(gnDataRequest_t gnDR)
sendGAC Send an LSRequest.
Definition: Geonet.cpp:665
BroadcastForwardingPacketBuffer * m_BCFPB
Definition: Geonet.h:621
Buffer used to repeat packet.
void initGeoNetErrors()
initGeoNetErrors Set the debugging print.
Definition: Geonet.cpp:265
void flushUCFPB(GnAddr destination)
flushUCFPB Flush unicast forawarding packet buffer.
Definition: Geonet.cpp:3192
UnicastForwardingPacketBuffer * m_UCFPB
Definition: Geonet.h:622
ParameterNetwork * m_paramNetwork
Definition: Geonet.h:615
int gacPacketProcessing(uchar *packet, sniff_ethernet_t *eth, BasicHeader bh, CommonHeader ch)
gacPacketProcessing GAC Header decoding.
Definition: Geonet.cpp:1755
void socketError(QAbstractSocket::SocketError)
socketError Print TCP socket error.
Definition: Geonet.cpp:142
Definition: GnAddr.h:28
e_hybridError
The e_hybridError enum is used for hybridization debug purpose.
Definition: Geonet.h:69
void execute()
execute Slot used to execute the Beacon creation and sending.
Definition: Geonet.cpp:180
FakeApplicationProvider * m_paramAppli
Definition: Geonet.h:612
void utInitialize()
utInitialize Slot used to initialize the N&T layer.
Definition: Geonet.cpp:241
int LSReplyPacketProcessing(uchar *packet, sniff_ethernet_t *eth, BasicHeader bh, CommonHeader ch)
LSReplyProcessing LSReply Header decoding.
Definition: Geonet.cpp:1607
int InitRawSocket_send()
InitRawSocket_send Set the ITS-G5 socket.
Definition: Geonet.cpp:387
int send(gnDataRequest_t gnDR)
send Creates the BTP and then select the correct packet send option.
Definition: Geonet.cpp:497
ForwardingAlgorithmResponse CBFUnicast(BasicHeader bh, CommonHeader ch, GACPacket packet, QByteArray packetPayload)
CBFUnicast Unicast CBF algoritm.
Definition: Geonet.cpp:3008
void setupSecureSocket()
setupSecureSocket Set SSL socket for hybridization.
Definition: Geonet.cpp:116
RepetitionPacketBuffer * m_RPB
Definition: Geonet.h:624
e_networkError
The e_networkError enum is used for networking debug purpose.
Definition: Geonet.h:58
Hybridization parameters.
void checkUCFPB()
checkUCFPB Check to flush the unicast forawarding packet buffer.
Definition: Geonet.cpp:3110
QByteArray verifySecuredPayload(QByteArray payload, bool *success)
verifySecuredPayload Send payload to verify to the HSM.jar.
Definition: Geonet.cpp:3488
int LSRequestPacketProcessing(uchar *packet, sniff_ethernet_t *eth, BasicHeader bh, CommonHeader ch)
LSRequestPacketProcessing LSRequest Header decoding.
Definition: Geonet.cpp:1426
Definition: Geonet.h:42
void lpvUpdate()
lpvUpdate Slot used when a packet containing an LPV is sent.
Definition: Geonet.cpp:260
int hybridSend(QByteArray payload)
hybridSend Send packet with the hybridization.
Definition: Geonet.cpp:1204
SecurityManager m_securityManager
Definition: Geonet.h:708
void calculAngleThreshold()
calculAngleThreshold Compute the ANGLE_TH for the advanced forwarding.
Definition: Geonet.cpp:191
void lpvSent()
lpvSent Signal used when a packet containing an LPV is sent.