Skip to content
GeoNetworkingLayer.cc 2.58 KiB
Newer Older
garciay's avatar
garciay committed
#include "GeoNetworkingLayer.hh"
#include "GeoNetworkingTypes.hh"

#include "loggers.hh"

garciay's avatar
garciay committed
GeoNetworkingLayer::GeoNetworkingLayer(const std::string & p_type, const std::string & param) : TLayer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(p_type), _params(), _codec() {
garciay's avatar
garciay committed
  loggers::get_instance().log(">>> GeoNetworkingLayer::GeoNetworkingLayer: %s, %s", to_string().c_str(), param.c_str());
    // Setup parameters
    Params::convert(_params, param);
garciay's avatar
garciay committed
    //_params.log();
garciay's avatar
garciay committed
void GeoNetworkingLayer::sendMsg(const LibItsGeoNetworking__TestSystem::GeoNetworkingReq& p, const Params& params) {
garciay's avatar
garciay committed
  loggers::get_instance().log(">>> GeoNetworkingLayer::sendMsg");
  
garciay's avatar
garciay committed
  OCTETSTRING data;
  _codec.encode(p.msgOut(), data);
  Params par(params);
  sendData(data, par);
garciay's avatar
garciay committed
void GeoNetworkingLayer::sendData(OCTETSTRING& data, Params& params) {
garciay's avatar
garciay committed
  loggers::get_instance().log_msg(">>> GeoNetworkingLayer::sendData: ", data);
  
garciay's avatar
garciay committed
  sendToAllLayers(data, params);
garciay's avatar
garciay committed
void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) { 
garciay's avatar
garciay committed
  loggers::get_instance().log_msg(">>> GeoNetworkingLayer::receiveData: ", data);
garciay's avatar
garciay committed
  // Decode the payload
  LibItsGeoNetworking__TestSystem::GeoNetworkingInd p;
  _codec.decode(data, p.msgIn());
  // Add lower layers parameters
garciay's avatar
garciay committed
  // 1. Destination MAC address
  std::map<std::string, std::string>::const_iterator it = params.find("dst");
  if (it != params.cend()) {
garciay's avatar
garciay committed
    loggers::get_instance().log("GeoNetworkingLayer::receiveData: dst=", it->second.c_str());
garciay's avatar
garciay committed
    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
  // Send it to the ports
garciay's avatar
garciay committed
  toAllUpperPorts(p, params);
garciay's avatar
garciay committed
}

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

GeoNetworkingFactory::GeoNetworkingFactory() {
    // register factory
garciay's avatar
garciay committed
    loggers::get_instance().log(">>> GeoNetworkingFactory::GeoNetworkingFactory");
    LayerStackBuilder::RegisterLayerFactory("GN", this);
garciay's avatar
garciay committed
}

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

GeoNetworkingFactory GeoNetworkingFactory::_f;