GeoNetworkingLayer.cc 25.6 KB
Newer Older
1
#include <thread>
garciay's avatar
garciay committed
2
#include <chrono>
3
4
5
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
garciay's avatar
garciay committed
6

garciay's avatar
garciay committed
7
8
#include "GeoNetworkingLayerFactory.hh"

garciay's avatar
garciay committed
9
10
#include "GeoNetworkingTypes.hh"

garciay's avatar
garciay committed
11
#include "registration.hh"
garciay's avatar
garciay committed
12
13
#include "loggers.hh"

garciay's avatar
garciay committed
14
15
using namespace LibItsGeoNetworking__TypesAndValues;

garciay's avatar
garciay committed
16
GeoNetworkingLayer::GeoNetworkingLayer(const std::string & p_type, const std::string & param) : TLayer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(p_type), _params(), _codec(), _beacon(nullptr), _packet(nullptr), _location_table(), _pass_beacon_table(), _sendData(), _timerid{0}, _sev{0}, _its{0}, _freq_nanosecs(0), _mask{0}, _sa{0} {
garciay's avatar
garciay committed
17
  loggers::get_instance().log(">>> GeoNetworkingLayer::GeoNetworkingLayer: %s, %s", to_string().c_str(), param.c_str());
18
  
garciay's avatar
garciay committed
19
20
  // Setup parameters
  Params::convert(_params, param);
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  // Sanity checks
  INTEGER latitude;
  Params::const_iterator it = _params.find(Params::latitude);
  if (it != _params.cend()) {
    latitude = str2int(CHARSTRING(it->second.c_str()));
  }
  INTEGER longitude;
  it = _params.find(Params::longitude);
  if (it != _params.cend()) {
    longitude = str2int(CHARSTRING(it->second.c_str()));
  }
  OCTETSTRING ll_address;
  it = _params.find(Params::ll_address);
  if (it != _params.cend()) {
    ll_address = str2oct(CHARSTRING(it->second.c_str()));
  }
garciay's avatar
garciay committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  INTEGER distanceA = 1000; // 1km
  it = _params.find(Params::distanceA);
  if (it != _params.cend()) {
    distanceA = str2int(CHARSTRING(it->second.c_str()));
  }
  INTEGER distanceB = 1000; // 1Km
  it = _params.find(Params::distanceB);
  if (it != _params.cend()) {
    distanceB = str2int(CHARSTRING(it->second.c_str()));
  }
  INTEGER angle = 0;
  it = _params.find(Params::angle);
  if (it != _params.cend()) {
    angle = str2int(CHARSTRING(it->second.c_str()));
  }
52
53
  // Add broadcast address if needed
  it = _params.find("mac_bc");
garciay's avatar
garciay committed
54
55
56
  if (it == _params.cend()) {
    _params.insert(std::pair<std::string, std::string>(std::string("mac_bc"), "FFFFFFFFFFFF"));
  }
garciay's avatar
garciay committed
57
58
59
60
  // Register this object for AdapterControlPort
  loggers::get_instance().log("GeoNetworkingLayer::GeoNetworkingLayer: register %s/%p", p_type.c_str(), this);
  registration<GeoNetworkingLayer>::get_instance().add_item(p_type, this);
  
61
  Params::const_iterator i = _params.find(Params::beaconing);
garciay's avatar
garciay committed
62
  if ((i != _params.cend()) && (i->second.compare("1") == 0)) { // Immediate beaconing was requested
garciay's avatar
garciay committed
63
64
    // Prepare beaconing operation
    fill_beacon(latitude, longitude, ll_address);
65
66
    start_beaconing();
  }
garciay's avatar
garciay committed
67
68

  fill_packet(latitude, longitude, ll_address, latitude, longitude, distanceA, distanceB, angle);// TODO Check if GeoBroadcastArea lat/lon are identical to lat/lon of the Test System
69
 } // End of constructor
70

garciay's avatar
garciay committed
71
GeoNetworkingLayer::~GeoNetworkingLayer() {
garciay's avatar
garciay committed
72
73
  loggers::get_instance().log(">>> GeoNetworkingLayer::~GeoNetworkingLayer");

74
75
  if (_timerid != 0) {
    timer_delete(_timerid);
garciay's avatar
garciay committed
76
77
78
79
80
  }

  if (_beacon != nullptr) {
    delete _beacon;
  }
garciay's avatar
garciay committed
81
82
83
  if (_packet != nullptr) {
    delete _packet;
  }
84
85
} // End of destructor

garciay's avatar
garciay committed
86
void GeoNetworkingLayer::sendMsg(const LibItsGeoNetworking__TestSystem::GeoNetworkingReq& p, Params& params) {
garciay's avatar
garciay committed
87
  loggers::get_instance().log(">>> GeoNetworkingLayer::sendMsg");
garciay's avatar
garciay committed
88
89

  // Encode GeoNetworking PDU
garciay's avatar
garciay committed
90
91
  OCTETSTRING data;
  _codec.encode(p.msgOut(), data);
garciay's avatar
garciay committed
92
  sendData(data, params);
garciay's avatar
garciay committed
93
94
}

garciay's avatar
garciay committed
95
void GeoNetworkingLayer::sendData(OCTETSTRING& data, Params& params) {
garciay's avatar
garciay committed
96
  loggers::get_instance().log_msg(">>> GeoNetworkingLayer::sendData: ", data);
97
98
99
100
  //params.log();

  // TODO Take into account the Security
  Params::const_iterator it = params.find(Params::packetize);
garciay's avatar
garciay committed
101
102
103
104
105
106
107
108
109
110
111
112
113
  if (it != params.cend()) { // Need to build a GN packet
    params.log();
    ExtendedHeader* eh = static_cast<ExtendedHeader *>(_packet->gnPacket().packet().extendedHeader().get_opt_value());
    if (eh == NULL) {
      loggers::get_instance().error("GeoNetworkingLayer::sendData: Wrong cast");
      return;
    }
    // Update NextHeader
    it = params.find(Params::btp_type);
    if ((it != params.cend()) && (it->second.compare("btpB") == 0)) {
      _packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpB;
    } else { // Default btp is btpA
      _packet->gnPacket().packet().commonHeader().nextHeader() = NextHeader::e__btpA;
114
    }
garciay's avatar
garciay committed
115
116
117
118
119
120
121
122
123
124
    // Update sequence number
    eh->geoBroadcastHeader().seqNumber() = 1 + eh->geoBroadcastHeader().seqNumber();
    // Update payload
    _packet->gnPacket().packet().commonHeader().plLength() = data.lengthof();
    _packet->gnPacket().packet().payload() = OPTIONAL<OCTETSTRING>(data);
    // Update timestamp
    unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L;  // TODO Add method such as its_tme() & its_time_mod()
    eh->geoBroadcastHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(ms));

    loggers::get_instance().log_msg("GeoNetworkingLayer::sendData: ", *_packet);
125
126
127
    
    // Encode GeoNetworking PDU
    OCTETSTRING os;
garciay's avatar
garciay committed
128
    _codec.encode(*_packet, os);
129
    data = os;
garciay's avatar
garciay committed
130
  }
131
132
  
  // TODO To be removed
133
134
135
136
  while (_sendData.try_lock() == FALSE) {
    // not ready yet
    std::this_thread::sleep_for(std::chrono::milliseconds(1));
  } // End of 'while' statement
garciay's avatar
garciay committed
137
  sendToAllLayers(data, params);
138
139
  _sendData.unlock();
  loggers::get_instance().log("<<< GeoNetworkingLayer::sendData");
garciay's avatar
garciay committed
140
141
}

garciay's avatar
garciay committed
142
void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) { 
garciay's avatar
garciay committed
143
  loggers::get_instance().log_msg(">>> GeoNetworkingLayer::receiveData: ", data);
garciay's avatar
garciay committed
144
  // Decode the payload
garciay's avatar
garciay committed
145
146
147
148
149
150
151
152
153
154
155
  LibItsGeoNetworking__TestSystem::GeoNetworkingInd ind;
  _codec.decode(data, ind.msgIn(), &params);
  
  // Update GeoNetworking layer
  if (ind.msgIn().basicHeader().version() == 0) { // Non secured mode
    const LibItsGeoNetworking__TypesAndValues::LongPosVector* sopv = nullptr;
    const LibItsGeoNetworking__TypesAndValues::GnNonSecuredPacket& p = ind.msgIn().gnPacket().packet();
    const LibItsGeoNetworking__TypesAndValues::HeaderTST& htst = p.commonHeader().headerTST();
    if (p.extendedHeader().ispresent()) { // Update location table
      const LibItsGeoNetworking__TypesAndValues::ExtendedHeader& ex = p.extendedHeader();    
      if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_beaconHdr)) { // Receive a beacon
garciay's avatar
garciay committed
156
        sopv = &ex.beaconHeader().srcPosVector();
garciay's avatar
garciay committed
157
      } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_tsbHdr)) { // Receive a topologicallyScopeBroadcast
garciay's avatar
garciay committed
158
159
160
161
162
        if (ex.ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_tsbHeader)) {
          sopv = &ex.tsbHeader().srcPosVector();
        } else {
          sopv = &ex.shbHeader().srcPosVector();
        }
garciay's avatar
garciay committed
163
      } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_geoBroadcastHdr)) {
garciay's avatar
garciay committed
164
        sopv = &ex.geoBroadcastHeader().srcPosVector();
garciay's avatar
garciay committed
165
      } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_lsHdr)) { // Receive a location service
garciay's avatar
garciay committed
166
167
168
        if (ex.ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_lsRequestHeader)) { // Receive a LocationService/LsRequest
          sopv = &ex.lsRequestHeader().srcPosVector();
          // TODO Send LsReply if we are not in context of GN ATS
garciay's avatar
garciay committed
169
170

	    
garciay's avatar
garciay committed
171
172
173
174
175
        } else {
          sopv = &ex.lsReplyHeader().srcPosVector();
        }
      } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_geoAnycastHdr)) { // Receive a GeoAnycast
        sopv = &ex.geoAnycastHeader().srcPosVector();
garciay's avatar
garciay committed
176
      } else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_geoUnicastHdr)) {
garciay's avatar
garciay committed
177
178
179
180
181
182
183
184
185
        sopv = &ex.geoUnicastHeader().srcPosVector();
        /*} else if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_saHdr)) { // Receive Service Advertisement
          if (ex.ischosen(LibItsGeoNetworking__TypesAndValues::ExtendedHeader::ALT_xxx)) {
          sopv = &ex.xxxHeader().srcPosVector();
          } else {
          sopv = &ex.xxxHeader().srcPosVector();
          }*/
      } // else, nothing to do
      loggers::get_instance().log("GeoNetworkingLayer::receiveData: sopv is boud: %d", sopv->is_bound());
garciay's avatar
garciay committed
186
      if(sopv->is_bound()) {
garciay's avatar
garciay committed
187
188
        const LibItsGeoNetworking__TypesAndValues::LongPosVector& lpv = *sopv;
        _location_table.add_entry(lpv);
garciay's avatar
garciay committed
189
190
191
192
      }
    }
    
    // By default incoming beacons are filtered by the test adapter
garciay's avatar
garciay committed
193
194
195
196
197
198
199
200
201
202
203
204
205
    if (htst.ischosen(LibItsGeoNetworking__TypesAndValues::HeaderTST::ALT_beaconHdr)) {
      loggers::get_instance().log_msg("GeoNetworkingLayer::receiveData: Pass beaconing processing", htst);
      if (_pass_beacon_table.empty()) { // Discard beacon
        loggers::get_instance().log("GeoNetworkingLayer::receiveData: Pass beaconing table empty, skip it");
        return;
      } else { // TODO Add beacon filter for StartPassBeaconing/Stop
        if (!_pass_beacon_table.has_entry(sopv->gnAddr().mid())) { // Discard beacon
          loggers::get_instance().log_msg("GeoNetworkingLayer::receiveData: Not in pass beaconing table, skip it", *sopv);
          return;
        } // else, continue
      }
    } // else, continue
  } // TODO else security mode, becarefull to duplicate code
garciay's avatar
garciay committed
206

garciay's avatar
garciay committed
207
  // Add lower layers parameters
garciay's avatar
garciay committed
208
  // 1. Destination MAC address
garciay's avatar
garciay committed
209
  Params::const_iterator it = params.find(Params::mac_dst);
garciay's avatar
garciay committed
210
  if (it != params.cend()) {
211
    loggers::get_instance().log("GeoNetworkingLayer::receiveData: dst=%s", it->second.c_str());
garciay's avatar
garciay committed
212
    ind.macDestinationAddress() = str2oct(CHARSTRING(it->second.c_str()));
garciay's avatar
garciay committed
213
  } else {
garciay's avatar
garciay committed
214
    ind.macDestinationAddress() = str2oct(CHARSTRING(_params["mac_bc"].c_str()));
garciay's avatar
garciay committed
215
216
217
218
  }
  // 2. ssp
  it = params.find(Params::ssp);
  if (it != params.cend()) {
219
    loggers::get_instance().log("GeoNetworkingLayer::receiveData: ssp=%s", it->second.c_str());
garciay's avatar
garciay committed
220
    ind.ssp() = str2bit(CHARSTRING(it->second.c_str()));
garciay's avatar
garciay committed
221
  } else {
garciay's avatar
garciay committed
222
    ind.ssp().set_to_omit();
garciay's avatar
garciay committed
223
  }
garciay's avatar
garciay committed
224
225
226
  // 3. its_aid
  it = params.find(Params::its_aid);
  if (it != params.cend()) {
227
    loggers::get_instance().log("GeoNetworkingLayer::receiveData: its_aid=%s", it->second.c_str());
garciay's avatar
garciay committed
228
    ind.its__aid() = std::stoi(it->second.c_str());
garciay's avatar
garciay committed
229
  } else {
garciay's avatar
garciay committed
230
    ind.its__aid().set_to_omit();
garciay's avatar
garciay committed
231
232
  }
  
233
234
235
236
237
238
239
240
241
242
  // Pass the GeoNetworking raw payload to the upper layers if any
  it = params.find(Params::gn_payload);
  if (it != params.cend()) {
    loggers::get_instance().log("GeoNetworkingLayer::receiveData: gn_payload=%s", it->second.c_str());
    OCTETSTRING os(str2oct(CHARSTRING(it->second.c_str())));
    receiveToAllLayers(os, params);
  } else {
    loggers::get_instance().warning("GeoNetworkingLayer::receiveData: No payload to pass to upper layers");
  }
  // Pass it to the ports
garciay's avatar
garciay committed
243
  toAllUpperPorts(ind, params);
garciay's avatar
garciay committed
244
245
}

garciay's avatar
garciay committed
246
247
248
249
250
251
252
253
OCTETSTRING GeoNetworkingLayer::trigger_ac_event(OCTETSTRING& data, Params& params)
{
  loggers::get_instance().log_to_hexa(">>> GeoNetworkingLayer::trigger_ac_event: ", data);


  return int2oct(0, 2);  
} // End of trigger_ac_event method

254
255
void GeoNetworkingLayer::start_beaconing() {
  loggers::get_instance().log(">>> GeoNetworkingLayer::start_beaconing");
garciay's avatar
garciay committed
256
  //loggers::get_instance().log_msg("GeoNetworkingLayer::start_beaconing: _beacon=", *_beacon);
garciay's avatar
garciay committed
257

258
  // Establish handler for timer signal
garciay's avatar
garciay committed
259
  loggers::get_instance().log("GeoNetworkingLayer::start_beaconing: Establishing handler for signal %d\n", _signal_id);
260
261
262
  _sa.sa_flags = SA_SIGINFO;
  _sa.sa_sigaction = timer_irq_sigalrm_handler;
  sigemptyset(&_sa.sa_mask);
garciay's avatar
garciay committed
263
  if (sigaction(_signal_id, &_sa, NULL) == -1) {
264
265
266
    loggers::get_instance().error("GeoNetworkingLayer::start_beaconing: Sigaction failure: %d", errno);
  }
  // Block timer signal temporarily
garciay's avatar
garciay committed
267
  loggers::get_instance().log("GeoNetworkingLayer::start_beaconing: Blocking signal %d\n", _signal_id);
268
  sigemptyset(&_mask);
garciay's avatar
garciay committed
269
  sigaddset(&_mask, _signal_id);
270
271
272
273
274
  if (sigprocmask(SIG_SETMASK, &_mask, NULL) == -1) {
    loggers::get_instance().error("GeoNetworkingLayer::start_beaconing: Sigprocmask failure: %d", errno);
  }	
  // Create the timer 
  _sev.sigev_notify = SIGEV_SIGNAL;
garciay's avatar
garciay committed
275
  _sev.sigev_signo = _signal_id; // Use signal alarm
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
  _sev.sigev_value.sival_ptr = this; // The GeoNetworkingLayer object address
  if (timer_create(CLOCK_REALTIME, &_sev, &_timerid) == -1) {
    loggers::get_instance().error("GeoNetworkingLayer::start_beaconing: Timer failure: %d", errno);
  }
  loggers::get_instance().log("GeoNetworkingLayer::start_beaconing: timer ID is 0x%lx\n", (long)_timerid);
  // Start the timer
  unsigned int expiry = 1000; // Default expiry time 1000ms
  Params::const_iterator i = _params.find("expiry");
  if (i != _params.cend()) {
    expiry = static_cast<unsigned int>(std::strtoul(i->second.c_str(), NULL, 10));
  }
  _freq_nanosecs = expiry * 1000000;
  _its.it_value.tv_sec = _freq_nanosecs / 1000000000;
  _its.it_value.tv_nsec = _freq_nanosecs % 1000000000;
  _its.it_interval.tv_sec = _its.it_value.tv_sec;
  _its.it_interval.tv_nsec = _its.it_value.tv_nsec;
  if (timer_settime(_timerid, 0, &_its, NULL) == -1) {
    loggers::get_instance().error("GeoNetworkingLayer::start_beaconing: Sigprocmask failure: %d", errno);
  }
  // Unlock the timer signal, so that timer notification can be delivered
garciay's avatar
garciay committed
296
  loggers::get_instance().log("GeoNetworkingLayer::start_beaconing: Unblocking signal %d\n", _signal_id);
297
298
299
  if (sigprocmask(SIG_UNBLOCK, &_mask, NULL) == -1) {
    loggers::get_instance().error("GeoNetworkingLayer::start_beaconing: Sigprocmask failure: %d", errno);
  }
garciay's avatar
garciay committed
300
301
302
303
304
305
306
307
308
309
310
311
312
} // End of start_beaconing method

void GeoNetworkingLayer::start_beaconing(const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& p_beacon) {
  loggers::get_instance().log_msg(">>> GeoNetworkingLayer::start_beaconing", p_beacon);

  // Initialize the beacon
  if (_beacon != nullptr) {
    delete _beacon;
  }
  _beacon = new LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu(p_beacon);

  start_beaconing(); // TODO Refined adding a boolean return code
} // End of start_beaconing method
313
314
315
316
317

void GeoNetworkingLayer::stop_beaconing() {
  loggers::get_instance().log(">>> GeoNetworkingLayer::stop_beaconing");
  
  // Block timer signal temporarily
garciay's avatar
garciay committed
318
  loggers::get_instance().log("GeoNetworkingLayer::stop_beaconing: Blocking signal %d\n", _signal_id);
319
  sigemptyset(&_mask);
garciay's avatar
garciay committed
320
  sigaddset(&_mask, _signal_id);
321
322
323
324
325
  if (sigprocmask(SIG_SETMASK, &_mask, NULL) == -1) {
    loggers::get_instance().error("GeoNetworkingLayer::stop_beaconing: Sigprocmask failure: %d", errno);
  }	
  timer_delete(_timerid);
  _timerid = 0;
garciay's avatar
garciay committed
326
} // End of stop_beaconing method
327

328
329
void GeoNetworkingLayer::send_beacon() {
  loggers::get_instance().log(">>> GeoNetworkingLayer::send_beacon");
330
  
331
  ExtendedHeader* eh = static_cast<ExtendedHeader *>(_beacon->gnPacket().packet().extendedHeader().get_opt_value());
garciay's avatar
garciay committed
332
  if (eh == NULL) {
333
    loggers::get_instance().error("GeoNetworkingLayer::send_beacon: Wrong cast");
garciay's avatar
garciay committed
334
  }
335
  // Update timestamp
garciay's avatar
garciay committed
336
  unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L;  // TODO Add method such as its_time() & its_time_mod()
garciay's avatar
garciay committed
337
338
  eh->beaconHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(ms));
  //loggers::get_instance().log_msg("GeoNetworkingLayer::send_beacon: ", *_beacon);
339
340
341
342
343
344
345
  // Encode message using TITAN because of payload in omited
  TTCN_Buffer encoding_buffer;
  _beacon->encode(*(_beacon->get_descriptor()), encoding_buffer, TTCN_EncDec::CT_RAW);
  OCTETSTRING data(encoding_buffer.get_len(), encoding_buffer.get_data());
  // Send it
  Params params(_params);
  sendData(data, params);
garciay's avatar
garciay committed
346
  
garciay's avatar
garciay committed
347
  //loggers::get_instance().log("<<< GeoNetworkingLayer::send_beacon");
348
} // End of send_beacon method
garciay's avatar
garciay committed
349

garciay's avatar
garciay committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
void GeoNetworkingLayer::start_pass_beaconing(const LibItsGeoNetworking__TypesAndValues::BeaconHeader& p_beacon) {
  loggers::get_instance().log_msg(">>> GeoNetworkingLayer::start_pass_beaconing", p_beacon);

  const LibItsGeoNetworking__TypesAndValues::LongPosVector& lpv = p_beacon.srcPosVector();
  if (!_pass_beacon_table.has_entry(lpv.gnAddr().mid())) {
    _pass_beacon_table.add_entry(lpv);
  } // TODO Refined adding a boolean return code
} // End of start_pass_beaconing method

void GeoNetworkingLayer::stop_pass_beaconing() {
  loggers::get_instance().log(">>> GeoNetworkingLayer::stop_pass_beaconing");

  _pass_beacon_table.reset();
} // End of stop_pass_beaconing method

garciay's avatar
garciay committed
365
366
367
368
369
370
371
372
373
374
375
const LongPosVector* GeoNetworkingLayer::get_lpv(const GN__Address& p_gn_address)
{
  loggers::get_instance().log_msg(">>> GeoNetworkingLayer::get_lpv", p_gn_address);
  
  const LongPosVector* lpv = nullptr;
  if (_location_table.has_entry(p_gn_address.mid())) {
    lpv = _location_table.get_entry(p_gn_address.mid());
  }
  return lpv;
} // End of get_lpv

376
377
378
379
380
void GeoNetworkingLayer::fill_beacon(INTEGER& p_latitude, INTEGER& p_longitude, OCTETSTRING& p_ll_address)
{
  _beacon = new GeoNetworkingPdu();
  HeaderTST h;
  h.beaconHdr() = BeaconHeaderType(
garciay's avatar
garciay committed
381
382
383
                                   HeaderType(HeaderType::e__beacon),
                                   0
                                   );
384
385
  ExtendedHeader eh;
  eh.beaconHeader() = BeaconHeader(
garciay's avatar
garciay committed
386
387
                                   LongPosVector(
                                                 GN__Address(
garciay's avatar
garciay committed
388
389
                                                             TypeOfAddress(TypeOfAddress::e__manual), // TODO Use Params
                                                             StationType(StationType::e__roadSideUnit), // TODO Use Params
garciay's avatar
garciay committed
390
391
392
393
394
395
396
397
398
399
400
                                                             33,
                                                             p_ll_address
                                                             ),
                                                 0,
                                                 p_latitude,
                                                 p_longitude,
                                                 int2bit(0, 1),
                                                 0,
                                                 0
                                                 )
                                   );
401
  _beacon->basicHeader() = BasicHeader(
garciay's avatar
garciay committed
402
403
404
405
406
407
408
409
410
411
412
                                       0,
                                       BasicNextHeader(
                                                       BasicNextHeader::e__commonHeader
                                                       ),
                                       0,
                                       Lifetime(
                                                4,
                                                LtBase(LtBase::e__50ms)
                                                ),
                                       5
                                       );
413
  _beacon->gnPacket().packet() = GnNonSecuredPacket(
garciay's avatar
garciay committed
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
                                                    CommonHeader(
                                                                 NextHeader(
                                                                            NextHeader::e__any
                                                                            ),
                                                                 0,
                                                                 h,
                                                                 TrafficClass(
                                                                              SCF(SCF::e__scfDisabled),
                                                                              ChannelOffload(ChannelOffload::e__choffDisabled),
                                                                              0
                                                                              ),
                                                                 int2bit(0, 8),
                                                                 0,
                                                                 1,
                                                                 0
                                                                 ),
                                                    OPTIONAL<ExtendedHeader>(eh),
                                                    OPTIONAL<GnRawPayload>()
                                                    );
433
434
  _beacon->gnPacket().packet().payload().set_to_omit();
  _beacon->gnPacket().securedMsg().set_to_omit();
garciay's avatar
garciay committed
435
  //loggers::get_instance().log_msg("GeoNetworkingLayer::fill_beacon: beacon value: ", *_beacon);
garciay's avatar
garciay committed
436
} // End of fill_beacon method
garciay's avatar
garciay committed
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
  
void GeoNetworkingLayer::fill_packet(const INTEGER& p_latitude, const INTEGER& p_longitude, const OCTETSTRING& p_ll_address, const INTEGER& p_geoAreaPosLatitude, const INTEGER& p_geoAreaPosLongitude, const INTEGER& p_distanceA, const INTEGER& p_distanceB, const INTEGER& p_angle)
{
  _packet = new GeoNetworkingPdu();
  HeaderTST h;
  h.geoBroadcastHdr() = GeoBroadcastHeaderType(
                                               HeaderType(HeaderType::e__geoBroadcast),
                                               HeaderSubTypeGeoBroadcast(HeaderSubTypeGeoBroadcast::e__geoBroadcastElip)
                                               );
  ExtendedHeader eh;
  eh.geoBroadcastHeader() = GeoAnycastHeader( // GeoBradcastHeader is identical as GeoAnycastHeader
                                             0,
                                             0,
                                             LongPosVector(
                                                           GN__Address(
                                                                       TypeOfAddress(TypeOfAddress::e__manual), // TODO Use Params
                                                                       StationType(StationType::e__passengerCar), // TODO Use Params
                                                                       33,
                                                                       p_ll_address
                                                                       ),
                                                           0,
                                                           p_latitude,
                                                           p_longitude,
                                                           int2bit(1, 1), // PAI
                                                           0,
                                                           0
                                                           ),
                                             p_geoAreaPosLatitude,
                                             p_geoAreaPosLongitude,
                                             p_distanceA,
                                             p_distanceB,
                                             p_angle,
                                             0
                                              );
  _packet->basicHeader() = BasicHeader(
                                       0,
                                       BasicNextHeader(
                                                       BasicNextHeader::e__commonHeader
                                                       ),
                                       0,
                                       Lifetime(
                                                4,
                                                LtBase(LtBase::e__50ms)
                                                ),
                                       5
                                       );
  _packet->gnPacket().packet() = GnNonSecuredPacket(
                                                    CommonHeader(
                                                                 NextHeader(
                                                                            NextHeader::e__btpA
                                                                            ),
                                                                 0,
                                                                 h,
                                                                 TrafficClass(
                                                                              SCF(SCF::e__scfDisabled),
                                                                              ChannelOffload(ChannelOffload::e__choffDisabled),
                                                                              0
                                                                              ),
                                                                 int2bit(128, 8), // Mobile stationnary flag set
                                                                 0,
                                                                 5,
                                                                 0
                                                                 ),
                                                    OPTIONAL<ExtendedHeader>(eh),
                                                    OPTIONAL<GnRawPayload>()
                                                    );
  _packet->gnPacket().packet().payload().set_to_omit();
  _packet->gnPacket().securedMsg().set_to_omit();
  //loggers::get_instance().log_msg("GeoNetworkingLayer::fill_packet: packet value: ", *_packet);
} // End of fill_packet method
507
508
  
void GeoNetworkingLayer::timer_irq_sigalrm_handler(int p_signal, siginfo_t *p_signal_info, void *p_uc) {
garciay's avatar
garciay committed
509
  //loggers::get_instance().log(">>> GeoNetworkingLayer::timer_irq_sigalrm_handler: Caught signal %d", p_signal);
510
511
512
513

  static_cast<GeoNetworkingLayer *>(p_signal_info->si_value.sival_ptr)->send_beacon();
} // End of method timer_irq_sigalrm_handler

garciay's avatar
garciay committed
514
GeoNetworkingLayerFactory GeoNetworkingLayerFactory::_f;
garciay's avatar
garciay committed
515