Commit 1f2f82b0 authored by garciay's avatar garciay
Browse files

Reorganise header files

parent 8be729c8
......@@ -135,7 +135,7 @@ namespace LibItsGeoNetworking__EncdecDeclarations {
if (p_geoNetworkingInd.get_at(i)->is_optional()) {
loggers::get_instance().log("fx__dec__GeoNetworkingInd: Bytes remaining: %d - field lenth: %d", decoding_buffer.get_len() - decoding_buffer.get_pos(), p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8);
if (std::string(p_geoNetworkingInd.fld_name(i)).compare("ssp") == 0) {
if ((decoding_buffer.get_len() - decoding_buffer.get_pos()) >= p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8) {
if ((decoding_buffer.get_len() - decoding_buffer.get_pos()) >= (int)p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8) {
loggers::get_instance().log("fx__dec__GeoNetworkingInd: decoding %s", p_geoNetworkingInd.fld_descr(i)->name);
BITSTRING ssp;
ssp.decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW);
......@@ -147,7 +147,7 @@ namespace LibItsGeoNetworking__EncdecDeclarations {
}
} else if (std::string(p_geoNetworkingInd.fld_name(i)).compare("its_aid") == 0) {
loggers::get_instance().log("fx__dec__GeoNetworkingInd: Bytes remaining: %d - its_aid lenth: %d", decoding_buffer.get_len() - decoding_buffer.get_pos(), p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8);
if ((decoding_buffer.get_len() - decoding_buffer.get_pos()) >= p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8) {
if ((decoding_buffer.get_len() - decoding_buffer.get_pos()) >= (int)p_geoNetworkingInd.fld_descr(i)->raw->fieldlength / 8) {
INTEGER its_aid;
its_aid.decode(*p_geoNetworkingInd.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW);
loggers::get_instance().log_msg("fx__dec__GeoNetworkingInd: its_aid=", its_aid);
......
#ifndef LAYER_HH
#define LAYER_HH
/*!
* \file Layer.hh
* \brief Header file for ITS abstract protocol layer definition.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
* \version 0.1
*/
#pragma once
#include <string>
#include <map>
......@@ -9,19 +18,40 @@
#include "Params.hh"
#include "loggers.hh"
class OCTETSTRING;
class BITSTRING;
class CHARSTRING;
class INTEGER;
class OCTETSTRING; //! Declare TITAN class
class BITSTRING; //! Declare TITAN class
class CHARSTRING; //! Declare TITAN class
class INTEGER; //! Declare TITAN class
/*!
* \class Layer
* \brief This class provides basic description of an ITS protocol layer
*/
class Layer {
std::vector<Layer*> upperLayers;
std::vector<Layer*> lowerLayers;
std::vector<Layer*> upperLayers; //! List of the upper protocol layers
std::vector<Layer*> lowerLayers; //! List of the lower protocol layers
protected:
std::string type;
std::string type; //! Type description, it indicates the protocol type (e.g. CAM, DENM, GN, ETH, PCAP...)
public:
/*!
* \brief Default constructor
* Create a new instance of the Layer class
*/
Layer() : upperLayers(), lowerLayers(), type(std::string("")) { loggers::get_instance().log("Layer::Layer (D)"); };
/*!
* \brief Specialized constructor
* Create a new instance of the Layer class with its type description
* \remark This constructor is called by the Layer factory
* \see LayerFactory
*/
Layer(const std::string& p_type) : upperLayers(), lowerLayers(), type(std::string(p_type.begin(), p_type.end())) { loggers::get_instance().log("Layer::Layer"); };
/*!
* \brief Default destructor
*/
virtual ~Layer() {
loggers::get_instance().log("Layer::~Layer");
// Double linked list, only remove layers in lowerLayers from the lowest one
......@@ -29,7 +59,13 @@ public:
lowerLayers.clear();
upperLayers.clear();
};
/*!
* \fn void deleteLayer();
* \brief Delete this layer
*/
void deleteLayer() { loggers::get_instance().log("Layer::deleteLayer"); };
public:
inline void addUpperLayer(Layer* p_layer) {
//loggers::get_instance().log(">>> Layer::addUpperLayer");
......@@ -40,12 +76,47 @@ public:
p_layer->lowerLayers.push_back(this);
};
};
void removeUpperLayer(Layer* p_layer) { };
virtual void sendData(OCTETSTRING& data, Params& params) { loggers::get_instance().log("Layer::sendData"); };
virtual void receiveData(OCTETSTRING& data, Params& params) { loggers::get_instance().log("Layer::receiveData"); }
virtual OCTETSTRING trigger_ac_event(OCTETSTRING& data, Params& params) { loggers::get_instance().log("Layer::trigger_ac_event"); return int2oct(0, 2); }
/*!
* \fn void removeUpperLayer(Layer* p_layer);
* \brief Remove the specified upper layer protocol from the list of the upper layer
* \param[in] p_layer The layer protocol to be removed
*/
void removeUpperLayer(Layer* p_layer) { };
/*!
* \virtual
* \fn void sendData(OCTETSTRING& data, Params& params);
* \brief Send bytes formated data to the lower layers
* \param[in] p_data The data to be sent
* \param[in] p_params Some parameters to overwrite default value of the lower layers parameters
*/
virtual void sendData(OCTETSTRING& p_data, Params& p_params) { loggers::get_instance().log("Layer::sendData"); };
/*!
* \virtual
* \fn void receiveData(OCTETSTRING& data, Params& params);
* \brief Receive bytes formated data from the lower layers
* \param[in] p_data The bytes formated data received
* \param[in] p_params Some lower layers parameters values when data was received
*/
virtual void receiveData(OCTETSTRING& p_data, Params& p_params) { loggers::get_instance().log("Layer::receiveData"); }
/*!
* \virtual
* \fn OCTETSTRING trigger_ac_event(OCTETSTRING& data, Params& params);
* \brief TODO
* \param[in] p_data
* \param[in] p_params
*/
virtual OCTETSTRING trigger_ac_event(OCTETSTRING& p_data, Params& p_params) { loggers::get_instance().log("Layer::trigger_ac_event"); return int2oct(0, 2); }
/*!
* \inline
* \fn const std::string& to_string();
* \brief Remove the specified upper layer protocol from the list of the upper layer
* \param[in] The layer protocol to be removed
*/
inline const std::string& to_string() const { return type; };
protected:
......@@ -56,6 +127,7 @@ protected:
p->receiveData(data, params); // FIXME BUG I
} // End of 'for' statement
};
inline void receiveToAllLayers(OCTETSTRING& data, Params& params) {
//loggers::get_instance().log(">>> Layer::receiveToAllLayers: %d", upperLayers.size());
for (std::vector<Layer*>::const_iterator it = upperLayers.cbegin(); it != upperLayers.cend(); ++it) {
......@@ -64,6 +136,7 @@ protected:
p->receiveData(data, params);
} // End of 'for' statement
};
inline void sendToAllLayers(OCTETSTRING& data, Params& params) {
//loggers::get_instance().log(">>> Layer::sendToAllLayers: %d", lowerLayers.size());
for (std::vector<Layer*>::const_iterator it = lowerLayers.cbegin(); it != lowerLayers.cend(); ++it) {
......@@ -74,50 +147,3 @@ protected:
};
}; // End of class Layer
template <typename TPort> class TLayer : public Layer {
typedef std::vector<TPort*> TPortList;
typedef typename std::vector<TPort*>::iterator TPortListIterator;
TPortList upperPorts;
public:
TLayer() : Layer(), upperPorts() { loggers::get_instance().log("TLayer::TLayer (D)"); };
TLayer(const std::string& p_type) : Layer(p_type), upperPorts() { loggers::get_instance().log("TLayer::TLayer"); };
void addUpperPort(TPort * p_port) { upperPorts.push_back(p_port); };
void removeUpperPort(TPort*);
protected:
template <typename TMessage>
inline void toAllUpperPorts(const TMessage& m, const Params& param) {
//loggers::get_instance().log(">>> TLayer::toAllUpperPorts: %d", upperPorts.size());
for(TPortListIterator it=upperPorts.begin(); it<upperPorts.end(); ++it){
(*it)->receiveMsg(m, param);
}
}
};
class LayerFactory {
public:
LayerFactory() {};
virtual Layer * createLayer(const std::string & type, const std::string & param) = 0;
};
class LayerStackBuilder {
typedef std::map<std::string, LayerFactory*> LayerFactoryMap;
static LayerStackBuilder * _instance;
std::map<std::string, LayerFactory*> _fs;
private:
LayerStackBuilder(); // can not be created manually
public:
static LayerStackBuilder * GetInstance();
static void RegisterLayerFactory(const std::string & type, LayerFactory * f);
public:
void registerLayerFactory(const std::string & type, LayerFactory * f);
Layer* createLayerStack(const char*);
};
#endif
/*!
* \file LayerFactory.hh
* \brief Header file for ITS abstract protocol layer definition.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
* \version 0.1
*/
#pragma once
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include "Layer.hh"
/*!
* \class Layerfactory
* \brief This class provides a factory class to create Layer class instances
* \abstract
*/
class LayerFactory {
public:
LayerFactory() {};
virtual Layer * createLayer(const std::string & type, const std::string & param) = 0;
}; // End of class LayerFactory
/*!
* \file LayerStackBuilder.hh
* \brief Header file for ITS protocol stack builder.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
* \version 0.1
*/
#pragma once
#include "LayerFactory.hh"
/*!
* \class LayerStackBuilder
* \brief This class provides a factory class to create Layer class instances
*/
class LayerStackBuilder {
typedef std::map<std::string, LayerFactory*> LayerFactoryMap;
static LayerStackBuilder * _instance;
std::map<std::string, LayerFactory*> _fs;
private:
LayerStackBuilder(); // can not be created manually
public:
static LayerStackBuilder * GetInstance();
static void RegisterLayerFactory(const std::string & type, LayerFactory * f);
public:
void registerLayerFactory(const std::string & type, LayerFactory * f);
Layer* createLayerStack(const char*);
}; // End of class LayerStackBuilder
/*!
* \file Params.hh
* \brief Header file for the parameter dictionary.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
* \version 0.1
*/
#pragma once
#include <vector>
#include <map>
/*!
* \class Params
* \brief This class provides basic functionalities for an ITS dictionary
* \implements std::map
*/
class Params : public std::map<std::string, std::string> {
public:
static const std::string& mac_src;
static const std::string& mac_dst;
static const std::string& mac_bc;
static const std::string& eth_type;
static const std::string& beaconing;
static const std::string& ssp;
static const std::string& its_aid;
static const std::string& gn_payload;
static const std::string& gn_next_header;
static const std::string& gn_header_type;
static const std::string& gn_header_sub_type;
static const std::string& gn_lifetime;
static const std::string& gn_traffic_class;
static const std::string& btp_type;
static const std::string& btp_payload;
static const std::string& btp_destination_port;
static const std::string& btp_info;
static const std::string& mac_src; //! Source MAC address parameter name
static const std::string& mac_dst; //! Destination MAC address parameter name
static const std::string& mac_bc; //! Broadcast MAC address parameter name
static const std::string& eth_type; //! Ethernet type parameter name
static const std::string& beaconing; //! Beaconing mode parameter name
static const std::string& ssp; //! SSP parameter name
static const std::string& its_aid; //! ITS-AID parameter name
static const std::string& gn_payload; //! GeoNetworking Payload parameter name
static const std::string& gn_next_header; //! GeoNetworking NextHeader parameter name
static const std::string& gn_header_type; //! GeoNetworking HeaderType parameter name
static const std::string& gn_header_sub_type; //! GeoNetworking HeaderSubType parameter name
static const std::string& gn_lifetime; //! GeoNetworking Lifetime parameter name
static const std::string& gn_traffic_class; //! GeoNetworking Traffic class parameter name
static const std::string& btp_type; //! BTP Type parameter name
static const std::string& btp_payload; //! BTP Payload parameter name
static const std::string& btp_destination_port; //! BTP DestinationPort parameter name
static const std::string& btp_info; //! BTP Info parameter name
static const std::string& nic;
static const std::string& ll_address;
static const std::string& latitude;
static const std::string& longitude;
static const std::string& expiry;
static const std::string& nic; //! Network Interface Card parameter name
static const std::string& ll_address; //! Test system GeoNetworking LL-Address parameter name
static const std::string& latitude; //! Test system Latitude parameter name
static const std::string& longitude; //! Test system Longitude parameter name
static const std::string& expiry; //! Test system GeoNetworking Lifetime parameter name (in ms)
static const std::string& packetize; /** Indicate to the lower layer to build packet */
static const std::string& distanceA;
static const std::string& distanceB;
static const std::string& angle;
static const std::string& packetize; //! Packetize mode, to indicate to the lower layer to build packet
static const std::string& distanceA; //! Test system GeoNetworking DistanceA parameter name
static const std::string& distanceB; //! Test system GeoNetworking DistanceB parameter name
static const std::string& angle; //! Test system GeoNetworking Angle parameter name
/*!
* \brief Default constructor
* Create a new instance of the Params class
*/
Params() : std::map<std::string, std::string>() {};
/*!
* \brief Copy constructor
* Clone an existing instance of a Params object
* \param[in] p_params An existing instance of a Params object
*/
Params(const Params& p_params) : std::map<std::string, std::string>(p_params.begin(), p_params.end()) {};
virtual ~Params() {};
/*!
* \brief Default destructor
*/
virtual ~Params() { };
/*!
* \fn void log();
* \brief Provides a dump of the content of this instance
*/
void log();
/*!
* \fn void reset();
* \brief Reset the content of this instance
*/
void reset();
/*!
* \static
* \fn void convert(Params& p_param, const std::string p_parameters);
* \brief Create a new instance of a Params object by converting a list of ITS parameters in string format (t1=v1,T2=(v0,v1v2)...)
* \return a new instance of a Params object
*/
static void convert(Params& p_param, const std::string p_parameters);
};
}; // End of class Params
/*!
* \file TLayer.hh
* \brief Header file for ITS abstract protocol layer definition.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
* \version 0.1
*/
#pragma once
#include "Layer.hh"
template <typename TPort> class TLayer : public Layer {
typedef std::vector<TPort*> TPortList;
typedef typename std::vector<TPort*>::iterator TPortListIterator;
TPortList upperPorts;
public:
TLayer() : Layer(), upperPorts() { loggers::get_instance().log("TLayer::TLayer (D)"); };
TLayer(const std::string& p_type) : Layer(p_type), upperPorts() { loggers::get_instance().log("TLayer::TLayer"); };
void addUpperPort(TPort * p_port) { upperPorts.push_back(p_port); };
void removeUpperPort(TPort*);
protected:
template <typename TMessage>
inline void toAllUpperPorts(const TMessage& m, const Params& param) {
//loggers::get_instance().log(">>> TLayer::toAllUpperPorts: %d", upperPorts.size());
for(TPortListIterator it=upperPorts.begin(); it<upperPorts.end(); ++it){
(*it)->receiveMsg(m, param);
}
}
}; // End of class TLayer
#ifndef REGISTRATION_HH
#define REGISTRATION_HH
/*!
* \file registration.hh
* \brief Header file for the control port registration functionality.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
* \version 0.1
*/
#pragma once
#include <string>
#include <map>
......@@ -55,5 +64,3 @@ TItem* registration<TItem>::get_item(const std::string & type)
return it->second;
}
#endif
#include "Layer.hh"
#include <stdexcept>
#include <regex>
#include "LayerStackBuilder.hh"
#include "loggers.hh"
LayerStackBuilder * LayerStackBuilder::_instance = NULL;
......@@ -41,8 +42,8 @@ Layer* LayerStackBuilder::createLayerStack(const char* s)
std::sregex_iterator end = std::sregex_iterator();
for (std::sregex_iterator it = begin; it != end; ++it) {
std::smatch m = *it;
//loggers::get_instance().log("LayerStackBuilder::createLayerStack: %d - %s - %s - %s - %s", m.size(), m[0].str().c_str(), m[1].str().c_str(), m[2].str().c_str(), m[3].str().c_str());
LayerFactoryMap::iterator i =_fs.find(m[1].str());
loggers::get_instance().log("LayerStackBuilder::createLayerStack: %d - %s - %s - %s - %s", m.size(), m[0].str().c_str(), m[1].str().c_str(), m[2].str().c_str(), m[3].str().c_str());
LayerFactoryMap::iterator i = _fs.find(m[1].str());
if (i == _fs.end()) {
loggers::get_instance().error("LayerStackBuilder::createLayerStack: %s: Unknown layer type", m[1].str().c_str());
}
......
/*!
* \file Params.cc
* \brief Source file for the parameter dictionary.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
* \version 0.1
*/
#include <stdexcept>
#include <regex>
......
......@@ -8,7 +8,7 @@
// add your member functions here.
#include "BtpPort.hh"
#include "BTPLayer.hh"
#include "BTPLayerFactory.hh"
#include "loggers.hh"
namespace LibItsBtp__TestSystem {
......
......@@ -8,7 +8,7 @@
// add your member functions here.
#include "CamPort.hh"
#include "CAMLayer.hh"
#include "CAMLayerFactory.hh"
#include "loggers.hh"
namespace LibItsCam__TestSystem {
......
......@@ -8,7 +8,7 @@
// add your member functions here.
#include "DenmPort.hh"
#include "DENMLayer.hh"
#include "DENMLayerFactory.hh"
#include "loggers.hh"
namespace LibItsDenm__TestSystem {
......
......@@ -8,7 +8,7 @@
// add your member functions here.
#include "GeoNetworkingPort.hh"
#include "GeoNetworkingLayer.hh"
#include "GeoNetworkingLayerFactory.hh"
#include "loggers.hh"
namespace LibItsGeoNetworking__TestSystem {
......
#include "BTPLayer.hh"
#include "BTPLayerFactory.hh"
#include "BTPTypes.hh"
#include "loggers.hh"
......@@ -85,26 +86,9 @@ void BTPLayer::receiveData(OCTETSTRING& data, Params& params)
} else {
loggers::get_instance().warning("BTPLayer::receiveData: No payload to pass to upper layers");
}
// Pass it to the ports if amy
// Pass it to the ports if any
//params.log();
toAllUpperPorts(p, params);
}
class BTPFactory : public LayerFactory {
static BTPFactory _f;
public:
BTPFactory();
virtual Layer * createLayer(const std::string & type, const std::string & param);
};
BTPFactory::BTPFactory(){
// Register factory
loggers::get_instance().log(">>> BTPFactory::BTPFactory");
LayerStackBuilder::RegisterLayerFactory("BTP", this);
}
Layer * BTPFactory::createLayer(const std::string & p_type, const std::string & param){
return new BTPLayer(p_type, param);
}
BTPFactory BTPFactory::_f;
BTPLayerFactory BTPLayerFactory::_f;
#ifndef BTP_LAYER_H
#define BTP_LAYER_H
/*!
* \file BTPLayer.hh
* \brief Header file for ITS BTP protocol layer.
* \author ETSI STF525
* \copyright ETSI Copyright Notification
* No part may be reproduced except as authorized by written permission.
* The copyright and the foregoing restriction extend to reproduction in all media.
* All rights reserved.
* \version 0.1
*/
#pragma once
#include "Layer.hh"
#include "TLayer.hh"
#include "BTPCodec.hh"
namespace LibItsBtp__TestSystem {
......@@ -15,13 +24,12 @@ class BTPLayer : public TLayer<LibItsBtp__TestSystem::BtpPort> {
BTPCodec _codec;
public:
BTPLayer() : TLayer<LibItsBtp__TestSystem::BtpPort>(), _params(), _codec() {};
BTPLayer(const std::string & p_type, const std::string & param);
BTPLayer(const std::string& p_type, const std::string& param);
virtual ~BTPLayer() {};
void sendMsg(const LibItsBtp__TestSystem::BtpReq&, Params& param);
virtual void sendData(OCTETSTRING& data, Params& params);
virtual void receiveData(OCTETSTRING& data, Params& info);
};