ITS
denKAFManagement.cpp
Go to the documentation of this file.
2 
4 {
5  m_paramGPS = gps;
6  m_paramAppli = appli;
7  m_geonet = gn;
8 
9  m_mutexForwarding = new QMutex;
10 }
11 
13 
14 //void denKAFManagement::execute(){while(true);}
15 
17 {
18  printf("UtInitialize KAF %d\n", m_forwardingDENM.size());
19  QMutexLocker locker(m_mutexForwarding);
21  m_forwardingDENM.clear();
22 }
23 
25 {
26  for(int i = 0 ; i < m_forwardingDENM.size() ; i++)
27  {
28  m_forwardingDENM[i]->m_validity->setTimer(-1);;
29  m_forwardingDENM[i]->m_forwarding->setTimer(-1);
30  }
31 }
32 
34 {
35  qDebug() << "KAF beginning";
36  /* 1) Check if the transmissionInterval exists in received DENM. */
37  /* a. If yes, continue the operation. */
39  /* b. Otherwise, omit execution of further steps. */
40  return;
41 
42  int found = haveDENM(denm->denm.management.actionID, m_forwardingDENM);
44  bool newEntry = false;
45 
46  if(found >= 0)
47  {
48  entry = m_forwardingDENM[found];
49 
50  /* 2) Check if the referenceTime of the received DENM is equal or greater than the referenceTime value of the
51  * DENM entry in the forwarding ITS-S message table of the same actionID. */
52  DENM_t tableDENM = entry->denm();;
53  quint64 tableReferenceTime, receivedReferenceTime;
54  asn_INTEGER2ulong((INTEGER_t*)&denm->denm.management.referenceTime, (long unsigned int*)&receivedReferenceTime);
55  asn_INTEGER2ulong((INTEGER_t*)&tableDENM.denm.management.referenceTime, (long unsigned int*)&tableReferenceTime);
56 
57  /* 2) a. if the received referenceTime is equal to the entry referenceTime, start/restart T_F_Forwarding and omit
58  * execution of furether steps. */
59  if(receivedReferenceTime == tableReferenceTime)
60  {
61  if(entry->m_forwarding)
62  {
63  qDebug() << "62 start";
64  entry->m_forwarding->m_T_Forwarding_timer.start();
65  return;
66  }
67  }
68  /* 2) b. if the received referenceTime is less than the entry referenceTime, discard the received DENM and omit
69  * execution of further steps. */
70  if(receivedReferenceTime < tableReferenceTime)
71  {
72  m_forwardingDENM.removeAt(found);
73  return;
74  }
75  }
76  else
77  {
78  newEntry = true;
80  entry->setActionID(denm->denm.management.actionID);
81  entry->moveToThread(entry->m_thread);
82  entry->setDENM(*denm);
83  m_forwardingDENM.append(entry);
85  QObject::connect(m_forwardingDENM[found], SIGNAL(T_F_ValiditySignal(ActionID_t)), this, SLOT(discardDENMFromForwardingTable(ActionID_t)));
86  QObject::connect(m_forwardingDENM[found], SIGNAL(T_ForwardingSignal(ActionID_t)), this, SLOT(repeatDENMFromForwardingTable(ActionID_t)));
87  }
88 
89  /* 2) c. Otherwise, continue the operation. */
90 
91  /* 3) Calculate expiration time of timer T_F_Validity. */
92  qint64 validity = -1;
93  quint64 detectionTime;
94  asn_INTEGER2ulong((INTEGER_t*)&denm->denm.management.detectionTime, (long unsigned int*)&detectionTime);
96  validity = m_paramGPS->timestamp() - detectionTime + ((*denm->denm.management.validityDuration) * 1000);
97  /* 3) a. if timer T_Forwarding is set to invalid value, omit execution of further steps. */
98  if(validity < 0)
99  return;
100  /* 3) b. Otherwise, continue the operation. */
101 
102  /* 4) Calculate timeout value for timer T_Forwarding. */
103  qint64 forwarding = -1;
105  {
106  forwarding = 2 * *denm->denm.management.transmissionInterval + (qrand() % 151);
107  if(forwarding > validity)
108  forwarding = validity;
109  }
110  /* 4) a. if timer T_Forwarding is set to invalid value, omit exection of further steps. */
111  if(forwarding < 0)
112  return;
113  /* 4) b. Otherwise, continue the operation. */
114 
115  /* 5) Start/restart timer T_F_Validity and T_Forwarding */
116  if(newEntry)
117  {
118  m_forwardingDENM[found]->setT_F_Validity(validity);
119  m_forwardingDENM[found]->setT_Forwarding(forwarding);
120  m_forwardingDENM[found]->moveToThread(m_forwardingDENM[found]->m_thread);
121  m_forwardingDENM[found]->m_thread->start();
122  }
123  else
124  {
125  m_forwardingDENM[found]->m_validity->setTimer(validity);
126  m_forwardingDENM[found]->m_validity->m_T_F_Validity_timer.start();
127  m_forwardingDENM[found]->m_forwarding->setTimer(forwarding);
128  m_forwardingDENM[found]->m_forwarding->m_T_Forwarding_timer.start();
129  }
130 
131 
132  /* 6) Reconstruct DENM by replacing the ITS PDU header. */
134  char encode[MSG_LENGTH] = {'\0'};
136  if(rval.encoded < 1)
137  {
138  qDebug() << "Unable to encode KAFed DENM";
139  return;
140  }
141 
142  /* 7) Update DENM entry in forwarding ITS-S message table. */
143  m_forwardingDENM[found]->setEncodedDENM(QByteArray(encode, (rval.encoded + 7) / 8));
144 
145  /* 8) End. */
146 // m_forwardingDENM[found]->m_thread->start();
147 }
148 
150 {
151  qDebug() << "Forward DENM" << actionID.originatingStationID << ":" << actionID.sequenceNumber;
152  QMutexLocker locker(m_mutexForwarding);
153  int found = haveDENM(actionID, m_forwardingDENM);
154 
155  if(found < 0)
156  {
157  qDebug() << "DENM" << actionID.originatingStationID << ":" << actionID.sequenceNumber <<
158  "not found in the received message table";
159  return;
160  }
161 
162  DENM_t denm = m_forwardingDENM[found]->denm();
164  if(!PassDenmToNetworkAndTransportLayerTrigger(data, m_forwardingDENM[found]->encodedDENM()))
165  {
166  qDebug() << "Unable to pass DENM to N&T";
167  return;
168  }
169 }
170 
172 {
173  QMutexLocker locker(m_mutexForwarding);
174  int found = haveDENM(actionID, m_forwardingDENM);
175 
176  if(found < 0)
177  {
178  qDebug() << "DENM" << actionID.originatingStationID << ":" << actionID.sequenceNumber <<
179  "not found in the received message table";
180  return;
181  }
182  if(m_forwardingDENM[found]->m_forwarding)
183  {
184  m_forwardingDENM[found]->m_forwarding->setTimer(-1);
185  }
186  if(m_forwardingDENM[found]->m_validity)
187  {
188  m_forwardingDENM[found]->m_validity->setTimer(-1);
189  }
190  m_forwardingDENM.removeAt(found);
191 }
192 
194 {
196 
197  dr.payload = payload;
198 
199  int foo;
200  if((foo = m_geonet->send(dr)) != GeoNet::geonetError_success)
201  {
202  qDebug() << "error " << foo;
203  return false;
204  }
205  return true;
206 }
void discardDENMFromForwardingTable(ActionID_t)
discardDENMFromForwardingTable Slot used to discard a DENM.
~denKAFManagement()
~denKAFManagement denKAFManagement destructor.
DEN KAF Management.
gnDataRequest_t structure is the GN data request definition.
Definition: GNDataRequest.h:46
DecentralizedEnvironmentalNotificationMessage_t denm
Definition: DENM.h:25
#define MSG_LENGTH
StationID_t originatingStationID
Definition: ActionID.h:24
StationID_t stationID
Definition: ItsPduHeader.h:40
ItsPduHeader_t header
Definition: DENM.h:24
void repeatDENMFromForwardingTable(ActionID_t)
repeatDENMFromForwardingTable Slot used to repeat a DENM.
FakeGPSProvider * m_paramGPS
gnDataRequest_t gnDataRequestFromAppDenmTriggerData(AppDenmTriggerData data, ParameterGPS gps)
gnDataRequestFromAppDenmTriggerData Generate a GN Data Request from an AppDenmTriggerData.
quint64 timestamp()
timestamp Timestamp getter.
SequenceNumber_t sequenceNumber
Definition: ActionID.h:25
ssize_t encoded
Definition: asn_codecs.h:48
void utInitialize()
utInitialize Initialize the DEN KAF Management.
void killForwardingThreads()
killForwardingThreads Kill living threads.
TimestampIts_t referenceTime
ValidityDuration_t * validityDuration
int asn_INTEGER2ulong(const INTEGER_t *i, unsigned long *l)
Definition: INTEGER.c:825
ParameterGPS & data()
data GPS data getter.
denKAFManagement(FakeGPSProvider *gps, FakeApplicationProvider *appli, GeoNet *gn)
denKAFManagement denKAFManagement constructor.
TimestampIts_t detectionTime
DENM_t denm() const
denm DENM getter.
TransmissionInterval_t * transmissionInterval
void setActionID(ActionID_t a)
setActionID Set the DENM&#39;s ActionID.
QVector< denMessageTableForwarding * > m_forwardingDENM
bool PassDenmToNetworkAndTransportLayerTrigger(AppDenmTriggerData data, QByteArray payload)
PassDenmToNetworkAndTransportLayerTrigger Pass DENM to the N&T layer.
asn_enc_rval_t uper_encode_to_buffer(struct asn_TYPE_descriptor_s *type_descriptor, void *struct_ptr, void *buffer, size_t buffer_size)
Definition: per_encoder.c:33
ReferencePosition_t eventPosition
StationID_t stationID() const
stationID Station ID getter.
Definition: DENM.h:23
QMutex * m_mutexForwarding
ParameterApplication & data()
data Returns the vehicle status.
int send(gnDataRequest_t gnDR)
send Creates the BTP and then select the correct packet send option.
Definition: Geonet.cpp:497
asn_TYPE_descriptor_t asn_DEF_DENM
Definition: DENM.c:45
FakeApplicationProvider * m_paramAppli
QByteArray payload
Definition: GNDataRequest.h:60
denMessageTableForwardingThread * m_forwarding
Definition: Geonet.h:42
void kaf(DENM_t *)
kaf Slot used to execute KAF.
int haveDENM(ActionID_t actionID, QVector< denMessageTableSource *> table)
haveDENM Check if the DENM exists in the denMessageTableSource
void setDENM(DENM_t d)
setDENM Set DENM.