Loading ccsrc/EncDec/LibItsCam_Encdec.cc +21 −14 Original line number Original line Diff line number Diff line #include "LibItsCam_EncdecDeclarations.hh" #include "LibItsCam_EncdecDeclarations.hh" #include "CAMCodec.hh" namespace LibItsCam__EncdecDeclarations { namespace LibItsCam__EncdecDeclarations { /**************************************************** /**************************************************** Loading @@ -8,20 +9,7 @@ namespace LibItsCam__EncdecDeclarations { ****************************************************/ ****************************************************/ BITSTRING fx__enc__CamReq(const LibItsCam__TestSystem::CamReq& p) BITSTRING fx__enc__CamReq(const LibItsCam__TestSystem::CamReq& p) { { //set error behavior return fx__enc__CAM(p.msgOut()); TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL,TTCN_EncDec::EB_WARNING); TTCN_Buffer TTCN_buf; TTCN_buf.clear(); //encode message in BER (CER variant, but can be any) p.msgOut().encode(CAM__PDU__Descriptions::CAM_descr_,TTCN_buf,TTCN_EncDec::CT_BER,BER_ENCODE_CER); OCTETSTRING encodedData(TTCN_buf.get_len(), TTCN_buf.get_data()); //insert BER2PER recoding here! return oct2bit(encodedData); } } Loading @@ -36,4 +24,23 @@ INTEGER fx__dec__CamReq(BITSTRING& b, LibItsCam__TestSystem::CamReq& p) return -1; return -1; } } */ */ BITSTRING fx__enc__CAM(const CAM__PDU__Descriptions::CAM& p) { CAMPDUCodec codec; BITSTRING b; codec.encode(p, b); return b; } INTEGER fx__dec__CAM(BITSTRING& b, CAM__PDU__Descriptions::CAM& p) { CAMPDUCodec codec; INTEGER rc = codec.decode(b, p); if(rc > 0){ b = (b >> rc); } } } //end namespace } //end namespace ccsrc/Framework/Codec.hh +14 −6 Original line number Original line Diff line number Diff line #ifndef CODEC_H #ifndef CODEC_H #define CODEC_H #define CODEC_H class OCTETSTRING; class OCTETSTRING; template<typename TPDU> class Codec { class BITSTRING; template<typename TPDUEnc, typename TPDUDec> class Codec { public: public: Codec(){} virtual int encode(const TPDUEnc& msg, OCTETSTRING& data) = 0; virtual int encode (const TPDU& msg, OCTETSTRING& data) = 0; virtual int decode(const OCTETSTRING& data, TPDUDec& msg) = 0; virtual int decode (const OCTETSTRING& data, TPDU& msg) = 0; }; template<typename TPDU> class PERCodec { public: virtual int encode(const TPDU& msg, BITSTRING& bits); virtual int decode(const BITSTRING& bits, TPDU& msg); }; }; #endif #endif ccsrc/Framework/Layer.hh +22 −8 Original line number Original line Diff line number Diff line #ifndef LAYER_H #ifndef LAYER_HH #define LAYER_H #define LAYER_HH #include <string> #include <string> #include <map> #include <map> #include <vector> #include <vector> Loading @@ -12,6 +12,8 @@ class Layer { std::vector<Layer*> lowerLayers; std::vector<Layer*> lowerLayers; public: public: Layer(){} Layer(){} virtual ~Layer(); void deleteLayer(); public: public: void addUpperLayer(Layer*); void addUpperLayer(Layer*); void removeUpperLayer(Layer*); void removeUpperLayer(Layer*); Loading @@ -21,13 +23,17 @@ class Layer { protected: protected: void toAllLayers(std::vector<Layer*>&layers, const OCTETSTRING& data, const Params& info); void toAllLayers(std::vector<Layer*>&layers, const OCTETSTRING& data, const Params& info); inline void toAllUpperLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(upperLayers, data, info); } inline void toAllLowerLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(upperLayers, data, info); } inline void receiveToAllLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(upperLayers, data, info); } inline void receiveToAllLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(upperLayers, data, info); } inline void sendToAllLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(lowerLayers, data, info); } inline void sendToAllLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(lowerLayers, data, info); } }; }; template <typename TPort> class TLayer : public Layer { template <typename TPort> class TLayer : public Layer { typedef std::vector<TPort*> TPortList; typedef std::vector<TPort*> TPortList; typedef typename std::vector<TPort*>::iterator TPortListIterator; typedef typename std::vector<TPort*>::iterator TPortListIterator; TPortList upperPorts; TPortList upperPorts; public: public: Loading @@ -35,25 +41,33 @@ template <typename TPort> class TLayer : public Layer { void addUpperPort(TPort*); void addUpperPort(TPort*); void removeUpperPort(TPort*); void removeUpperPort(TPort*); template <typename T> void receiveToAllPorts(const T& m, const Params& param) { protected: template <typename TMessage> void toAllUpperPorts(const TMessage& m, const Params& param) { for(TPortListIterator it=upperPorts.begin(); it<upperPorts.end(); ++it){ for(TPortListIterator it=upperPorts.begin(); it<upperPorts.end(); ++it){ (*it)->receiveMsg(m, param); (*it)->receiveMsg(m, param); } } } } }; }; class LayerFactory { class LayerFactory { public: public: LayerFactory(){} LayerFactory(){} virtual Layer * createLayer(const std::string & type, const std::string & param) = 0; virtual Layer * createLayer(const std::string & type, const std::string & param) = 0; }; }; class StackFactory { class LayerStackBuilder { static StackFactory * _instance; typedef std::map<std::string, LayerFactory*> LayerFactoryMap; static LayerStackBuilder * _instance; std::map<std::string, LayerFactory*> _fs; std::map<std::string, LayerFactory*> _fs; private: LayerStackBuilder(); // can not be created manually public: public: static StackFactory * getInstance(); static LayerStackBuilder * GetInstance(); static void RegisterLayerFactory(const std::string & type, LayerFactory * f); public: void registerLayerFactory(const std::string & type, LayerFactory * f); void registerLayerFactory(const std::string & type, LayerFactory * f); Layer* createLayerStack(const char*); Layer* createLayerStack(const char*); }; }; Loading ccsrc/Framework/Makefile +3 −2 Original line number Original line Diff line number Diff line Loading @@ -4,11 +4,12 @@ PROJECT = its-framework DEBUG = yes DEBUG = yes testdir = tests testdir = tests srcdir = src srcdir = src ccflags += -std=c++11 alibs = $(PROJECT) alibs = $(PROJECT) sources := LayerFactory.cpp sources := LayerFactory.cc headers := Codec.h Layer.h headers := Codec.hh Layer.hh includes := . .. includes := . .. include ../common.mk include ../common.mk ccsrc/Framework/src/LayerFactory.cc +53 −13 Original line number Original line Diff line number Diff line #include "Layer.hh" #include "Layer.hh" #include <stdexcept> #include <regex> StackFactory * StackFactory::_instance = NULL; LayerStackBuilder * LayerStackBuilder::_instance = NULL; StackFactory * StackFactory::getInstance(){ return _instance ? _instance : _instance=new StackFactory(); // static functions LayerStackBuilder * LayerStackBuilder::GetInstance() { return _instance ? _instance : _instance=new LayerStackBuilder(); } void LayerStackBuilder::RegisterLayerFactory(const std::string & type, LayerFactory * f) { LayerStackBuilder::GetInstance()->registerLayerFactory(type, f); } } void StackFactory::registerLayerFactory(const std::string & type, LayerFactory * f) // member functions LayerStackBuilder::LayerStackBuilder() { } void LayerStackBuilder::registerLayerFactory(const std::string & type, LayerFactory * f) { { _fs[type] = f; _fs[type] = f; } } Layer* StackFactory::createLayerStack(const char* str) Layer* LayerStackBuilder::createLayerStack(const char* s) { { std::string type; Layer * up = NULL; std::string param; //parse str //parse str LayerFactory * f = _fs[type]; std::regex rgx ("(\\w+)(\\((.*?)\\))?(\\/|$)"); if(f){ std::smatch m; return f->createLayer(type, param); std::string str = s; try { while(std::regex_search(str, m, rgx)) { std::string mname = m[1]; LayerFactoryMap::iterator it =_fs.find(mname); if(it == _fs.end()){ throw (std::logic_error(mname + ": Unknown layer type")); } } return NULL; // TODO: parse parameters Layer * l = it->second->createLayer(mname, m[3]); if(NULL == l){ throw (std::logic_error(mname + ": Layer creation error")); } } l->addUpperLayer(up); up = l; } } catch(const std::logic_error& e){ if(up){ up->deleteLayer(); up = NULL; } } return up; } void Layer::deleteLayer() { } Loading
ccsrc/EncDec/LibItsCam_Encdec.cc +21 −14 Original line number Original line Diff line number Diff line #include "LibItsCam_EncdecDeclarations.hh" #include "LibItsCam_EncdecDeclarations.hh" #include "CAMCodec.hh" namespace LibItsCam__EncdecDeclarations { namespace LibItsCam__EncdecDeclarations { /**************************************************** /**************************************************** Loading @@ -8,20 +9,7 @@ namespace LibItsCam__EncdecDeclarations { ****************************************************/ ****************************************************/ BITSTRING fx__enc__CamReq(const LibItsCam__TestSystem::CamReq& p) BITSTRING fx__enc__CamReq(const LibItsCam__TestSystem::CamReq& p) { { //set error behavior return fx__enc__CAM(p.msgOut()); TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL,TTCN_EncDec::EB_WARNING); TTCN_Buffer TTCN_buf; TTCN_buf.clear(); //encode message in BER (CER variant, but can be any) p.msgOut().encode(CAM__PDU__Descriptions::CAM_descr_,TTCN_buf,TTCN_EncDec::CT_BER,BER_ENCODE_CER); OCTETSTRING encodedData(TTCN_buf.get_len(), TTCN_buf.get_data()); //insert BER2PER recoding here! return oct2bit(encodedData); } } Loading @@ -36,4 +24,23 @@ INTEGER fx__dec__CamReq(BITSTRING& b, LibItsCam__TestSystem::CamReq& p) return -1; return -1; } } */ */ BITSTRING fx__enc__CAM(const CAM__PDU__Descriptions::CAM& p) { CAMPDUCodec codec; BITSTRING b; codec.encode(p, b); return b; } INTEGER fx__dec__CAM(BITSTRING& b, CAM__PDU__Descriptions::CAM& p) { CAMPDUCodec codec; INTEGER rc = codec.decode(b, p); if(rc > 0){ b = (b >> rc); } } } //end namespace } //end namespace
ccsrc/Framework/Codec.hh +14 −6 Original line number Original line Diff line number Diff line #ifndef CODEC_H #ifndef CODEC_H #define CODEC_H #define CODEC_H class OCTETSTRING; class OCTETSTRING; template<typename TPDU> class Codec { class BITSTRING; template<typename TPDUEnc, typename TPDUDec> class Codec { public: public: Codec(){} virtual int encode(const TPDUEnc& msg, OCTETSTRING& data) = 0; virtual int encode (const TPDU& msg, OCTETSTRING& data) = 0; virtual int decode(const OCTETSTRING& data, TPDUDec& msg) = 0; virtual int decode (const OCTETSTRING& data, TPDU& msg) = 0; }; template<typename TPDU> class PERCodec { public: virtual int encode(const TPDU& msg, BITSTRING& bits); virtual int decode(const BITSTRING& bits, TPDU& msg); }; }; #endif #endif
ccsrc/Framework/Layer.hh +22 −8 Original line number Original line Diff line number Diff line #ifndef LAYER_H #ifndef LAYER_HH #define LAYER_H #define LAYER_HH #include <string> #include <string> #include <map> #include <map> #include <vector> #include <vector> Loading @@ -12,6 +12,8 @@ class Layer { std::vector<Layer*> lowerLayers; std::vector<Layer*> lowerLayers; public: public: Layer(){} Layer(){} virtual ~Layer(); void deleteLayer(); public: public: void addUpperLayer(Layer*); void addUpperLayer(Layer*); void removeUpperLayer(Layer*); void removeUpperLayer(Layer*); Loading @@ -21,13 +23,17 @@ class Layer { protected: protected: void toAllLayers(std::vector<Layer*>&layers, const OCTETSTRING& data, const Params& info); void toAllLayers(std::vector<Layer*>&layers, const OCTETSTRING& data, const Params& info); inline void toAllUpperLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(upperLayers, data, info); } inline void toAllLowerLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(upperLayers, data, info); } inline void receiveToAllLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(upperLayers, data, info); } inline void receiveToAllLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(upperLayers, data, info); } inline void sendToAllLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(lowerLayers, data, info); } inline void sendToAllLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(lowerLayers, data, info); } }; }; template <typename TPort> class TLayer : public Layer { template <typename TPort> class TLayer : public Layer { typedef std::vector<TPort*> TPortList; typedef std::vector<TPort*> TPortList; typedef typename std::vector<TPort*>::iterator TPortListIterator; typedef typename std::vector<TPort*>::iterator TPortListIterator; TPortList upperPorts; TPortList upperPorts; public: public: Loading @@ -35,25 +41,33 @@ template <typename TPort> class TLayer : public Layer { void addUpperPort(TPort*); void addUpperPort(TPort*); void removeUpperPort(TPort*); void removeUpperPort(TPort*); template <typename T> void receiveToAllPorts(const T& m, const Params& param) { protected: template <typename TMessage> void toAllUpperPorts(const TMessage& m, const Params& param) { for(TPortListIterator it=upperPorts.begin(); it<upperPorts.end(); ++it){ for(TPortListIterator it=upperPorts.begin(); it<upperPorts.end(); ++it){ (*it)->receiveMsg(m, param); (*it)->receiveMsg(m, param); } } } } }; }; class LayerFactory { class LayerFactory { public: public: LayerFactory(){} LayerFactory(){} virtual Layer * createLayer(const std::string & type, const std::string & param) = 0; virtual Layer * createLayer(const std::string & type, const std::string & param) = 0; }; }; class StackFactory { class LayerStackBuilder { static StackFactory * _instance; typedef std::map<std::string, LayerFactory*> LayerFactoryMap; static LayerStackBuilder * _instance; std::map<std::string, LayerFactory*> _fs; std::map<std::string, LayerFactory*> _fs; private: LayerStackBuilder(); // can not be created manually public: public: static StackFactory * getInstance(); static LayerStackBuilder * GetInstance(); static void RegisterLayerFactory(const std::string & type, LayerFactory * f); public: void registerLayerFactory(const std::string & type, LayerFactory * f); void registerLayerFactory(const std::string & type, LayerFactory * f); Layer* createLayerStack(const char*); Layer* createLayerStack(const char*); }; }; Loading
ccsrc/Framework/Makefile +3 −2 Original line number Original line Diff line number Diff line Loading @@ -4,11 +4,12 @@ PROJECT = its-framework DEBUG = yes DEBUG = yes testdir = tests testdir = tests srcdir = src srcdir = src ccflags += -std=c++11 alibs = $(PROJECT) alibs = $(PROJECT) sources := LayerFactory.cpp sources := LayerFactory.cc headers := Codec.h Layer.h headers := Codec.hh Layer.hh includes := . .. includes := . .. include ../common.mk include ../common.mk
ccsrc/Framework/src/LayerFactory.cc +53 −13 Original line number Original line Diff line number Diff line #include "Layer.hh" #include "Layer.hh" #include <stdexcept> #include <regex> StackFactory * StackFactory::_instance = NULL; LayerStackBuilder * LayerStackBuilder::_instance = NULL; StackFactory * StackFactory::getInstance(){ return _instance ? _instance : _instance=new StackFactory(); // static functions LayerStackBuilder * LayerStackBuilder::GetInstance() { return _instance ? _instance : _instance=new LayerStackBuilder(); } void LayerStackBuilder::RegisterLayerFactory(const std::string & type, LayerFactory * f) { LayerStackBuilder::GetInstance()->registerLayerFactory(type, f); } } void StackFactory::registerLayerFactory(const std::string & type, LayerFactory * f) // member functions LayerStackBuilder::LayerStackBuilder() { } void LayerStackBuilder::registerLayerFactory(const std::string & type, LayerFactory * f) { { _fs[type] = f; _fs[type] = f; } } Layer* StackFactory::createLayerStack(const char* str) Layer* LayerStackBuilder::createLayerStack(const char* s) { { std::string type; Layer * up = NULL; std::string param; //parse str //parse str LayerFactory * f = _fs[type]; std::regex rgx ("(\\w+)(\\((.*?)\\))?(\\/|$)"); if(f){ std::smatch m; return f->createLayer(type, param); std::string str = s; try { while(std::regex_search(str, m, rgx)) { std::string mname = m[1]; LayerFactoryMap::iterator it =_fs.find(mname); if(it == _fs.end()){ throw (std::logic_error(mname + ": Unknown layer type")); } } return NULL; // TODO: parse parameters Layer * l = it->second->createLayer(mname, m[3]); if(NULL == l){ throw (std::logic_error(mname + ": Layer creation error")); } } l->addUpperLayer(up); up = l; } } catch(const std::logic_error& e){ if(up){ up->deleteLayer(); up = NULL; } } return up; } void Layer::deleteLayer() { }