GeoNetworkingLayer.cc 2.7 KB
Newer Older
garciay's avatar
garciay committed
1
2
3
4
5
#include "GeoNetworkingLayer.hh"
#include "GeoNetworkingTypes.hh"

#include "loggers.hh"

garciay's avatar
garciay committed
6
GeoNetworkingLayer::GeoNetworkingLayer(const std::string & p_type, const std::string & param) : TLayer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(p_type), _params(), _codec() {
garciay's avatar
garciay committed
7
  loggers::loggers::log(">>> GeoNetworkingLayer::GeoNetworkingLayer: %s, %s", to_string().c_str(), param.c_str());
8
9
    // Setup parameters
    Params::convert(_params, param);
garciay's avatar
garciay committed
10
    //_params.log();
11
12
}

garciay's avatar
garciay committed
13
void GeoNetworkingLayer::sendMsg(const LibItsGeoNetworking__TestSystem::GeoNetworkingReq& p, const Params& params) {
garciay's avatar
garciay committed
14
15
16
  loggers::loggers::log(">>> GeoNetworkingLayer::sendMsg");
  OCTETSTRING data;
  _codec.encode(p.msgOut(), data);
garciay's avatar
garciay committed
17
  loggers::loggers::log_msg("GeoNetworkingLayer::sendMsg: After encoding: ", data);
garciay's avatar
garciay committed
18
  Params par(params);
garciay's avatar
garciay committed
19
20
  loggers::loggers::log("GeoNetworkingLayer::sendMsg: Before calling sendData");
  par.log();
garciay's avatar
garciay committed
21
  sendData(data, par);
garciay's avatar
garciay committed
22
23
}

garciay's avatar
garciay committed
24
25
void GeoNetworkingLayer::sendData(OCTETSTRING& data, Params& params) {
  loggers::loggers::log(">>> GeoNetworkingLayer::sendData");
garciay's avatar
garciay committed
26
  sendToAllLayers(data, params);
garciay's avatar
garciay committed
27
28
}

garciay's avatar
garciay committed
29
void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) { 
garciay's avatar
garciay committed
30
31
32
33
34
  loggers::loggers::log_msg(">>> GeoNetworkingLayer::receiveData: ", data);
  // Decode the payload
  LibItsGeoNetworking__TestSystem::GeoNetworkingInd p;
  _codec.decode(data, p.msgIn());
  // Add lower layers parameters
garciay's avatar
garciay committed
35
36
37
38
39
40
41
42
43
44
45
46
  // 1. Destination MAC address
  std::map<std::string, std::string>::const_iterator it = params.find("dst");
  if (it != params.cend()) {
    loggers::loggers::log("GeoNetworkingLayer::receiveData: dst=", it->second.c_str());
    p.macDestinationAddress() = str2oct(CHARSTRING(it->second.c_str()));
  } else {
    const unsigned char mac_address[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // TODO Declare it as a C++ constant
    p.macDestinationAddress() = OCTETSTRING(sizeof(mac_address), static_cast<const unsigned char *>(mac_address));
  }
  p.ssp().set_to_omit();
  // Its_Aid
  p.its__aid().set_to_omit();
garciay's avatar
garciay committed
47
  // Send it to the ports
garciay's avatar
garciay committed
48
  toAllUpperPorts(p, params);
garciay's avatar
garciay committed
49
50
51
52
53
54
55
56
57
58
59
60
}

class GeoNetworkingFactory: public LayerFactory {
    static GeoNetworkingFactory _f;
public:
    GeoNetworkingFactory();
    virtual Layer * createLayer(const std::string & type,
            const std::string & param);
};

GeoNetworkingFactory::GeoNetworkingFactory() {
    // register factory
61
62
    loggers::loggers::log(">>> GeoNetworkingFactory::GeoNetworkingFactory");
    LayerStackBuilder::RegisterLayerFactory("GN", this);
garciay's avatar
garciay committed
63
64
65
}

Layer * GeoNetworkingFactory::createLayer(const std::string & type, const std::string & param) {
garciay's avatar
garciay committed
66
  return new GeoNetworkingLayer(type, param);
garciay's avatar
garciay committed
67
68
69
}

GeoNetworkingFactory GeoNetworkingFactory::_f;