Commit 16e55358 authored by garciay's avatar garciay
Browse files

UpperTester changes

parent d8200ed1
#include "LibItsDenm_EncdecDeclarations.hh"
#include "DENMCodec.hh"
#include "UpperTesterCodec.hh"
#include "UpperTesterDenmCodec.hh"
#include "loggers.hh"
namespace LibItsDenm__EncdecDeclarations {
......@@ -97,11 +97,31 @@ namespace LibItsDenm__EncdecDeclarations {
{
loggers::get_instance().log_msg(">>> fx__enc__UtDenmInitialize: ", p_utDenmInitialize);
UpperTesterCodec codec;
UpperTesterDenmCodec codec;
OCTETSTRING os;
codec.encode(p_utDenmInitialize, os);
return oct2bit(os);
}
BITSTRING fx__enc__UtDenmChangePosition (const LibItsDenm__TypesAndValues::UtDenmChangePosition& p_utDenmChangePosition)
{
loggers::get_instance().log_msg(">>> fx__enc__UtDenmChangePosition: ", p_utDenmChangePosition);
UpperTesterDenmCodec codec;
OCTETSTRING os;
codec.encode(p_utDenmChangePosition, os);
return oct2bit(os);
}
BITSTRING fx__enc__UtDenmChangePseudonym (const LibItsDenm__TypesAndValues::UtDenmChangePseudonym& p_utDenmChangePseudonym)
{
loggers::get_instance().log_msg(">>> fx__enc__UtDenmChangePseudonym: ", p_utDenmChangePseudonym);
UpperTesterDenmCodec codec;
OCTETSTRING os;
codec.encode(p_utDenmChangePseudonym, os);
return oct2bit(os);
}
} //end namespace
#include "LibItsGeoNetworking_EncdecDeclarations.hh"
#include "GeoNetworkingCodec.hh"
#include "UpperTesterCodec.hh"
#include "UpperTesterGnCodec.hh"
#include "loggers.hh"
namespace LibItsGeoNetworking__EncdecDeclarations {
......@@ -231,7 +231,7 @@ namespace LibItsGeoNetworking__EncdecDeclarations {
{
loggers::get_instance().log_msg(">>> fx__enc__UtGnInitialize: ", p_utGnInitialize);
UpperTesterCodec codec;
UpperTesterGnCodec codec;
OCTETSTRING os;
codec.encode(p_utGnInitialize, os);
return oct2bit(os);
......@@ -241,7 +241,7 @@ namespace LibItsGeoNetworking__EncdecDeclarations {
{
loggers::get_instance().log_msg(">>> fx__enc__UtGnChangePosition: ", p_utGnChangePosition);
UpperTesterCodec codec;
UpperTesterGnCodec codec;
OCTETSTRING os;
codec.encode(p_utGnChangePosition, os);
return oct2bit(os);
......@@ -251,7 +251,7 @@ namespace LibItsGeoNetworking__EncdecDeclarations {
{
loggers::get_instance().log_msg(">>> fx__enc__UtGnTrigger: ", p_utGnTrigger);
UpperTesterCodec codec;
UpperTesterGnCodec codec;
OCTETSTRING os;
codec.encode(p_utGnTrigger, os);
return oct2bit(os);
......
......@@ -95,27 +95,34 @@ namespace LibItsDenm__TestSystem {
void UpperTesterPort::outgoing_send(const LibItsDenm__TypesAndValues::UtDenmTrigger& /*send_par*/)
{
}
void UpperTesterPort::outgoing_send(const LibItsDenm__TypesAndValues::UtDenmUpdate& /*send_par*/)
{
}
void UpperTesterPort::outgoing_send(const LibItsDenm__TypesAndValues::UtDenmTermination& /*send_par*/)
{
}
void UpperTesterPort::outgoing_send(const LibItsDenm__TypesAndValues::UtDenmChangePosition& /*send_par*/)
void UpperTesterPort::outgoing_send(const LibItsDenm__TypesAndValues::UtDenmChangePosition& send_par)
{
loggers::get_instance().log_msg(">>> UppertesterPort::outgoing_send: ", send_par);
float duration;
loggers::get_instance().set_start_time(_time_key);
static_cast<UpperTesterDenmLayer *>(_layer)->sendMsg(send_par, _layer_params);
loggers::get_instance().set_stop_time(_time_key, duration);
}
void UpperTesterPort::outgoing_send(const LibItsDenm__TypesAndValues::UtChangePseudonym& /*send_par*/)
void UpperTesterPort::outgoing_send(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym& send_par)
{
loggers::get_instance().log_msg(">>> UppertesterPort::outgoing_send: ", send_par);
float duration;
loggers::get_instance().set_start_time(_time_key);
static_cast<UpperTesterDenmLayer *>(_layer)->sendMsg(send_par, _layer_params);
loggers::get_instance().set_stop_time(_time_key, duration);
}
void UpperTesterPort::receiveMsg (const Base_Type& p_ind, const Params& p_params) {
......
......@@ -44,7 +44,7 @@ namespace LibItsDenm__TestSystem {
void outgoing_send(const LibItsDenm__TypesAndValues::UtDenmChangePosition& send_par);
void outgoing_send(const LibItsDenm__TypesAndValues::UtChangePseudonym& send_par);
void outgoing_send(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym& send_par);
};
......
#include <string>
//#include <typeinfo>
#include "UpperTesterCodec.hh"
#include "loggers.hh"
#include "UpperTesterTypes.hh"
/***
TODO Split UpperTester into UpperTester_GeoNetworking, UpperTester_Cam...
This one is the UpperTester_GeoNetworking
Not sure it's a good idea :-(
***/
template <typename T_type> class OPTIONAL;
class TTCN_EncDec;
int UpperTesterCodec::encode (const Record_Type& msg, OCTETSTRING& data)
{
loggers::get_instance().log_msg(">>> UpperTesterCodec::encode: ", (const Record_Type&)msg);
TTCN_EncDec::clear_error();
TTCN_Buffer encoding_buffer;
if (std::string(msg.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.UtGnInitialize") == 0) {
encoding_buffer.put_c(static_cast<unsigned char>(UpperTesterCodec::c_utInitialize));
} else if (std::string(msg.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.UtGnChangePosition") == 0) {
encoding_buffer.put_c(static_cast<unsigned char>(UpperTesterCodec::c_utChangePosition));
} else if (std::string(msg.get_descriptor()->name).compare("@LibItsDenm_TypesAndValues.UtDenmInitialize") == 0) {
encoding_buffer.put_c(static_cast<unsigned char>(UpperTesterCodec::c_utInitialize));
} else { // Error
data = OCTETSTRING();
return -1;
}
encode_(msg, *msg.get_descriptor(), encoding_buffer);
data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data());
loggers::get_instance().log_msg("<<< UpperTesterCodec::encode: data=", data);
return 0;
}
int UpperTesterCodec::encode (const Base_Type& msg, OCTETSTRING& data)
{
loggers::get_instance().log(">>> UpperTesterCodec::encode: %s", msg.get_descriptor()->name);
TTCN_EncDec::clear_error();
TTCN_Buffer encoding_buffer;
Base_Type* type = nullptr;
if (std::string(msg.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.UtGnTrigger") == 0) {
const LibItsGeoNetworking__TypesAndValues::UtGnTrigger& t = static_cast<const LibItsGeoNetworking__TypesAndValues::UtGnTrigger&>(msg);
loggers::get_instance().log("UpperTesterCodec::encode: After cast: %s", t.get_descriptor()->name);
if (t.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnTrigger::ALT_geoUnicast)) {
encoding_buffer.put_c(static_cast<unsigned char>(UpperTesterCodec::c_utGnTrigger_GeoUnicast));
type = (Base_Type*)&(t.geoUnicast());
} else if (t.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnTrigger::ALT_geoBroadcast)) {
encoding_buffer.put_c(static_cast<unsigned char>(UpperTesterCodec::c_utGnTrigger_GeoBroadcast));
type = (Base_Type*)&(t.geoBroadcast());
} else if (t.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnTrigger::ALT_geoAnycast)) {
encoding_buffer.put_c(static_cast<unsigned char>(UpperTesterCodec::c_utGnTrigger_GeoAnycast));
type = (Base_Type*)&(t.geoAnycast());
} else if (t.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnTrigger::ALT_shb)) {
encoding_buffer.put_c(static_cast<unsigned char>(UpperTesterCodec::c_utGnTrigger_Shb));
type = (Base_Type*)&(t.shb());
} else if (t.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnTrigger::ALT_tsb)) {
encoding_buffer.put_c(static_cast<unsigned char>(UpperTesterCodec::c_utGnTrigger_Tsb));
type = (Base_Type*)&(t.tsb());
} // else, nothing to do
} else {
data = OCTETSTRING();
return -1;
}
encode_(*type, *(type->get_descriptor()), encoding_buffer);
data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data());
loggers::get_instance().log_msg("<<< UpperTesterCodec::encode: data=", data);
return 0;
}
int UpperTesterCodec::encode_ (const Base_Type& type, const TTCN_Typedescriptor_t& field_descriptor, TTCN_Buffer& encoding_buffer)
{
loggers::get_instance().log(">>> UpperTesterCodec::encode_: processing %s/%s", type.get_descriptor()->name, field_descriptor.name);
loggers::get_instance().log_msg(">>> UpperTesterCodec::encode_: ", type);
if (dynamic_cast<const Record_Type*>(&type) != NULL) {
const Record_Type& r = (const Record_Type &)type;
loggers::get_instance().log("UpperTesterCodec::encode_: processing Record_Type %s", r.get_descriptor()->name);
for(int i = 0; i < r.get_count(); i++) {
loggers::get_instance().log("UpperTesterCodec::encode_: processing %s/%s/%s - %d (1 ==> use dynamic_cast<const OPTIONAL<...>) - %d", r.fld_name(i), r.fld_descr(i)->name, r.get_at(i)->get_descriptor()->name, r.get_at(i)->is_optional(), r.get_at(i)->is_present());
if (r.get_at(i)->is_present()) {
if (encode_(*r.get_at(i), *r.fld_descr(i), encoding_buffer) == -1) {
loggers::get_instance().warning("UpperTesterCodec::encode_: -1 result code returned");
return -1;
}
}
} // End of 'for' statement
} else {
std::string s(field_descriptor.name);
if (s.rfind(".shape") != string::npos) {
encoding_buffer.put_c((unsigned char)static_cast<const Enum_Type&>(type).as_int());
} else if (s.rfind(".payload") != string::npos) {
const OCTETSTRING& os = static_cast<const OCTETSTRING&>(type);
const unsigned char s[] = { (unsigned char)((os.lengthof() & 0x0000FF00) >> 8), (unsigned char)os.lengthof() };
encoding_buffer.put_s(2, s);
if (os.lengthof() != 0) {
encoding_buffer.put_string(os);
}
} else {
loggers::get_instance().log("UpperTesterCodec::encode_ (else): processing type %s/%s", type.get_descriptor()->name, field_descriptor.name);
type.encode(field_descriptor, encoding_buffer, TTCN_EncDec::CT_RAW);
}
}
loggers::get_instance().log_to_hexa("<<<UpperTesterCodec::encode_: encoding_buffer=", encoding_buffer);
return 0;
}
int UpperTesterCodec::decode (const OCTETSTRING& data, Record_Type& msg, Params* params)
{
TTCN_EncDec::clear_error();
TTCN_Buffer decoding_buffer(data);
_params = params;
loggers::get_instance().log_to_hexa(">>> UpperTesterCodec::decode: decoding_buffer=", decoding_buffer);
//decode_(msg, *msg.get_descriptor(), decoding_buffer);
loggers::get_instance().log_msg("<<< UpperTesterCodec::decode: ", (const Record_Type&)msg);
return 0;
}
int UpperTesterCodec::decode (const OCTETSTRING& data, LibItsGeoNetworking__TypesAndValues::UtGnResults& msg, Params* params)
{
loggers::get_instance().log_to_hexa(">>> UpperTesterCodec::decode: decoding_buffer=", data);
const unsigned char* ptr = static_cast<const unsigned char*>(data);
if (*ptr == UpperTesterCodec::c_utGnInitializeResult) {
msg.utGnInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01);
} else if (*ptr == UpperTesterCodec::c_utChangePositionResult) {
msg.utGnChangePositionResult() = BOOLEAN(*(ptr + 1) == 0x01);
} else if (*ptr == UpperTesterCodec::c_utGnTriggerResult) {
msg.utGnTriggerResult() = BOOLEAN(*(ptr + 1) == 0x01);
} else {
TTCN_warning("UpperTesterCodec::decode: Unsupported result");
}
loggers::get_instance().log_msg("<<< UpperTesterCodec::decode", msg);
return 0;
}
int UpperTesterCodec::decode (const OCTETSTRING& data, LibItsDenm__TypesAndValues::UtDenmResults& msg, Params* params)
{
loggers::get_instance().log_to_hexa(">>> UpperTesterCodec::decode: decoding_buffer=", data);
const unsigned char* ptr = static_cast<const unsigned char*>(data);
if (*ptr == UpperTesterCodec::c_utDenmInitializeResult) {
msg.utDenmInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01);
} else if (*ptr == UpperTesterCodec::c_utChangePositionResult) {
msg.utDenmChangePositionResult() = BOOLEAN(*(ptr + 1) == 0x01);
} else if (*ptr == UpperTesterCodec::c_utDenmTriggerResult) {
// TODO msg.utDenmTriggerResult() = BOOLEAN(*(ptr + 1) == 0x01);
} else {
TTCN_warning("UpperTesterCodec::decode: Unsupported result");
}
loggers::get_instance().log_msg("<<< UpperTesterCodec::decode", msg);
return 0;
}
#ifndef UpperTesterCODEC_H
#define UpperTesterCODEC_H
#include "Codec.hh"
#include "loggers.hh" // TODO To be removed
#include "Params.hh"
class Base_Type;
class Record_Type;
class TTCN_Typedescriptor_t;
class TTCN_Buffer;
namespace LibItsGeoNetworking__TypesAndValues {
class UtGnResults;
}
namespace LibItsDenm__TypesAndValues {
class UtDenmResults;
}
class UpperTesterCodec: public Codec <
Record_Type,
Record_Type>
{
const unsigned char c_utInitialize = 0x00;
const unsigned char c_utGnInitializeResult = 0x01;
const unsigned char c_utChangePosition = 0x02;
const unsigned char c_utChangePositionResult = 0x03;
const unsigned char c_utGnTriggerResult = 0x41;
const unsigned char c_utGnTrigger_GeoUnicast = 0x50;
const unsigned char c_utGnTrigger_GeoBroadcast = 0x51;
const unsigned char c_utGnTrigger_GeoAnycast = 0x52;
const unsigned char c_utGnTrigger_Shb = 0x53;
const unsigned char c_utGnTrigger_Tsb = 0x54;
const unsigned char c_utDenmInitializeResult = 0x01;
const unsigned char c_utDenmTriggerResult = 0x41;
int encode_ (const Base_Type& type, const TTCN_Typedescriptor_t& field_descriptor, TTCN_Buffer& encoding_buffer);
public:
UpperTesterCodec() : Codec<Record_Type, Record_Type>() { loggers::get_instance().log("UpperTesterCodec::UpperTesterCodec(D)"); };
virtual ~UpperTesterCodec() { loggers::get_instance().log("UpperTesterCodec::~UpperTesterCodec"); };
virtual int encode (const Record_Type&, OCTETSTRING& data);
virtual int encode (const Base_Type&, OCTETSTRING& data);
virtual int decode (const OCTETSTRING& data, Record_Type&, Params* params = NULL);
int decode (const OCTETSTRING& data, LibItsGeoNetworking__TypesAndValues::UtGnResults& msg, Params* params = NULL);
int decode (const OCTETSTRING& data, LibItsDenm__TypesAndValues::UtDenmResults& msg, Params* params = NULL);
};
#endif
......@@ -20,7 +20,7 @@ void UpperTesterDenmLayer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmIniti
sendData(data, params);
}
/*void UpperTesterDenmLayer::sendMsg(const LibItsDenm__TypesAndValues::UtGnChangePosition& send_par, Params& params)
void UpperTesterDenmLayer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePosition& send_par, Params& params)
{
loggers::get_instance().log_msg(">>> UpperTesterDenmLayer::sendMsg", send_par);
......@@ -30,9 +30,21 @@ void UpperTesterDenmLayer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmIniti
// Update parameters
Params par(params); // FIXME Review all const Param& in method declarations
sendData(data, params);
}
}
void UpperTesterDenmLayer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym& send_par, Params& params)
{
loggers::get_instance().log_msg(">>> UpperTesterDenmLayer::sendMsg", send_par);
// Encode UpperTester PDU
OCTETSTRING data;
_codec.encode((const Record_Type &)send_par, data);
// Update parameters
Params par(params); // FIXME Review all const Param& in method declarations
sendData(data, params);
}
void UpperTesterDenmLayer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmTrigger& send_par, Params& params)
/*void UpperTesterDenmLayer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmTrigger& send_par, Params& params)
{
loggers::get_instance().log_msg(">>> UpperTesterDenmLayer::sendMsg", send_par);
......@@ -66,16 +78,10 @@ void UpperTesterDenmLayer::receiveData(OCTETSTRING& data, Params& params)
{
loggers::get_instance().log_msg(">>> UpperTesterDenmLayer::receiveData: ", data);
if (data.lengthof() == 2) {
LibItsDenm__TypesAndValues::UtDenmResults p;
_codec.decode(data, p);
// Pass it to the ports if amy
toAllUpperPorts((Base_Type&)p, params);
} else {// Decode the payload
LibItsDenm__TypesAndValues::UtDenmEventInd p;
_codec.decode(data, p);
std::unique_ptr<Base_Type> r = _codec.decode(data);
if (r.get() != nullptr) {
// Pass it to the ports if amy
toAllUpperPorts(p, params);
toAllUpperPorts(*r, params);
}
}
......
......@@ -2,7 +2,7 @@
#define UpperTesterDenm_LAYER_H
#include "Layer.hh"
#include "UpperTesterCodec.hh"
#include "UpperTesterDenmCodec.hh"
namespace LibItsDenm__TestSystem {
class UpperTesterPort;
......@@ -10,14 +10,13 @@ namespace LibItsDenm__TestSystem {
namespace LibItsDenm__TypesAndValues {
class UtDenmInitialize;
/*class UtGnChangePosition;
class UtGnTrigger;
class UtAutoInteropTrigger;*/
class UtDenmChangePosition;
class UtDenmChangePseudonym;
}
class UpperTesterDenmLayer : public TLayer<LibItsDenm__TestSystem::UpperTesterPort> {
Params _params;
UpperTesterCodec _codec;
UpperTesterDenmCodec _codec;
public:
UpperTesterDenmLayer() : TLayer<LibItsDenm__TestSystem::UpperTesterPort>(), _params(), _codec() {};
......@@ -25,8 +24,9 @@ public:
virtual ~UpperTesterDenmLayer() {};
void sendMsg(const LibItsDenm__TypesAndValues::UtDenmInitialize& send_par, Params& params);
/* void sendMsg(const LibItsDenm__TypesAndValues::UtGnChangePosition& send_par, Params& params);
void sendMsg(const LibItsDenm__TypesAndValues::UtDenmTrigger& send_par, Params& params);
void sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePosition& send_par, Params& params);
void sendMsg(const LibItsDenm__TypesAndValues::UtDenmChangePseudonym& send_par, Params& params);
/*void sendMsg(const LibItsDenm__TypesAndValues::UtDenmTrigger& send_par, Params& params);
void sendMsg(const LibItsDenm__TypesAndValues::UtAutoInteropTrigger& send_par, Params& params);*/
virtual void sendData(OCTETSTRING& data, Params& params);
......
......@@ -65,17 +65,10 @@ void UpperTesterGnLayer::sendData(OCTETSTRING& data, Params& params) {
void UpperTesterGnLayer::receiveData(OCTETSTRING& data, Params& params)
{
loggers::get_instance().log_msg(">>> UpperTesterGnLayer::receiveData: ", data);
if (data.lengthof() == 2) {
LibItsGeoNetworking__TypesAndValues::UtGnResults p;
_codec.decode(data, p);
std::unique_ptr<Base_Type> r = _codec.decode(data);
if (r.get() != nullptr) {
// Pass it to the ports if amy
toAllUpperPorts((Base_Type&)p, params);
} else {// Decode the payload
LibItsGeoNetworking__TypesAndValues::UtGnEventInd p;
_codec.decode(data, p);
// Pass it to the ports if amy
toAllUpperPorts(p, params);
toAllUpperPorts(*r, params);
}
}
......
......@@ -2,7 +2,7 @@
#define UpperTesterGn_LAYER_H
#include "Layer.hh"
#include "UpperTesterCodec.hh"
#include "UpperTesterGnCodec.hh"
namespace LibItsGeoNetworking__TestSystem {
class UpperTesterPort;
......@@ -17,7 +17,7 @@ namespace LibItsGeoNetworking__TypesAndValues {
class UpperTesterGnLayer : public TLayer<LibItsGeoNetworking__TestSystem::UpperTesterPort> {
Params _params;
UpperTesterCodec _codec;
UpperTesterGnCodec _codec;
public:
UpperTesterGnLayer() : TLayer<LibItsGeoNetworking__TestSystem::UpperTesterPort>(), _params(), _codec() {};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment