Commit e4494579 authored by garciay's avatar garciay
Browse files

Start UpperTester changes

parent 0ac6133d
#include "LibItsGeoNetworking_EncdecDeclarations.hh"
#include "GeoNetworkingCodec.hh"
#include "UpperTesterCodec.hh"
#include "loggers.hh"
namespace LibItsGeoNetworking__EncdecDeclarations {
......@@ -226,4 +227,14 @@ namespace LibItsGeoNetworking__EncdecDeclarations {
return -1;
}
BITSTRING fx__enc__UtGnInitialize (const LibItsGeoNetworking__TypesAndValues::UtGnInitialize& p_utGnInitialize)
{
loggers::get_instance().log_msg(">>> fx__enc__UtGnInitialize: ", p_utGnInitialize);
UpperTesterCodec codec;
OCTETSTRING os;
codec.encode(p_utGnInitialize, os);
return oct2bit(os);
}
} //end namespace
......@@ -82,7 +82,7 @@ void UpperTesterPort::user_stop()
}
void UpperTesterPort::outgoing_send(const LibItsCommon__TypesAndValues::UtInitialize& send_par)
void UpperTesterPort::outgoing_send(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize& send_par)
{
loggers::get_instance().log_msg(">>> UppertesterPort::outgoing_send: payload=", send_par);
......@@ -115,6 +115,10 @@ void UpperTesterPort::receiveMsg (const Base_Type& p_ind, const Params& p_params
return;
}
//loggers::get_instance().log("UpperTesterPort::receive_msg: %s", p_ind.get_descriptor()->name);
if (std::string(p_ind.get_descriptor()->name).compare("@LibItsGeoNetworking_TypesAndValues.UtGnResults") == 0) { // TODO To be refined
incoming_message((LibItsGeoNetworking__TypesAndValues::UtGnResults&)p_ind);
}
}
} /* end of namespace */
......@@ -3,6 +3,8 @@
//=============================================================================
#include "LibItsGeoNetworking_TestSystem.hh"
#include "LibItsGeoNetworking_TypesAndValues.hh"
namespace LibItsGeoNetworking__TestSystem {
class UpperTesterPort : public UpperTesterPort_BASE {
......@@ -34,7 +36,7 @@ protected:
void user_start();
void user_stop();
void outgoing_send(const LibItsCommon__TypesAndValues::UtInitialize& send_par);
void outgoing_send(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize& send_par);
void outgoing_send(const LibItsCommon__TypesAndValues::UtChangePosition& send_par);
......
......@@ -171,23 +171,23 @@ void GeoNetworkingLayer::start_beaconing() {
loggers::get_instance().log(">>> GeoNetworkingLayer::start_beaconing");
// Establish handler for timer signal
loggers::get_instance().log("GeoNetworkingLayer::start_beaconing: Establishing handler for signal %d\n", SIGALRM);
loggers::get_instance().log("GeoNetworkingLayer::start_beaconing: Establishing handler for signal %d\n", _signal_id);
_sa.sa_flags = SA_SIGINFO;
_sa.sa_sigaction = timer_irq_sigalrm_handler;
sigemptyset(&_sa.sa_mask);
if (sigaction(SIGALRM, &_sa, NULL) == -1) {
if (sigaction(_signal_id, &_sa, NULL) == -1) {
loggers::get_instance().error("GeoNetworkingLayer::start_beaconing: Sigaction failure: %d", errno);
}
// Block timer signal temporarily
loggers::get_instance().log("GeoNetworkingLayer::start_beaconing: Blocking signal %d\n", SIGALRM);
loggers::get_instance().log("GeoNetworkingLayer::start_beaconing: Blocking signal %d\n", _signal_id);
sigemptyset(&_mask);
sigaddset(&_mask, SIGALRM);
sigaddset(&_mask, _signal_id);
if (sigprocmask(SIG_SETMASK, &_mask, NULL) == -1) {
loggers::get_instance().error("GeoNetworkingLayer::start_beaconing: Sigprocmask failure: %d", errno);
}
// Create the timer
_sev.sigev_notify = SIGEV_SIGNAL;
_sev.sigev_signo = SIGALRM; // Use signal alarm
_sev.sigev_signo = _signal_id; // Use signal alarm
_sev.sigev_value.sival_ptr = this; // The GeoNetworkingLayer object address
if (timer_create(CLOCK_REALTIME, &_sev, &_timerid) == -1) {
loggers::get_instance().error("GeoNetworkingLayer::start_beaconing: Timer failure: %d", errno);
......@@ -208,7 +208,7 @@ void GeoNetworkingLayer::start_beaconing() {
loggers::get_instance().error("GeoNetworkingLayer::start_beaconing: Sigprocmask failure: %d", errno);
}
// Unlock the timer signal, so that timer notification can be delivered
loggers::get_instance().log("GeoNetworkingLayer::start_beaconing: Unblocking signal %d\n", SIGALRM);
loggers::get_instance().log("GeoNetworkingLayer::start_beaconing: Unblocking signal %d\n", _signal_id);
if (sigprocmask(SIG_UNBLOCK, &_mask, NULL) == -1) {
loggers::get_instance().error("GeoNetworkingLayer::start_beaconing: Sigprocmask failure: %d", errno);
}
......@@ -218,9 +218,9 @@ void GeoNetworkingLayer::stop_beaconing() {
loggers::get_instance().log(">>> GeoNetworkingLayer::stop_beaconing");
// Block timer signal temporarily
loggers::get_instance().log("GeoNetworkingLayer::stop_beaconing: Blocking signal %d\n", SIGALRM);
loggers::get_instance().log("GeoNetworkingLayer::stop_beaconing: Blocking signal %d\n", _signal_id);
sigemptyset(&_mask);
sigaddset(&_mask, SIGALRM);
sigaddset(&_mask, _signal_id);
if (sigprocmask(SIG_SETMASK, &_mask, NULL) == -1) {
loggers::get_instance().error("GeoNetworkingLayer::stop_beaconing: Sigprocmask failure: %d", errno);
}
......@@ -236,8 +236,9 @@ void GeoNetworkingLayer::send_beacon() {
loggers::get_instance().error("GeoNetworkingLayer::send_beacon: Wrong cast");
}
// Update timestamp
unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L; // TODO Add method such as its_tme() & its_time_mod()
eh->beaconHeader().srcPosVector().timestamp__() = ms;
unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L; // TODO Add method such as its_tme() & its_time_mod()
eh->beaconHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(ms));
//loggers::get_instance().log_msg("GeoNetworkingLayer::send_beacon: ", *_beacon);
// Encode message using TITAN because of payload in omited
TTCN_Buffer encoding_buffer;
_beacon->encode(*(_beacon->get_descriptor()), encoding_buffer, TTCN_EncDec::CT_RAW);
......@@ -246,7 +247,7 @@ void GeoNetworkingLayer::send_beacon() {
Params params(_params);
sendData(data, params);
loggers::get_instance().log("<<< GeoNetworkingLayer::send_beacon");
//loggers::get_instance().log("<<< GeoNetworkingLayer::send_beacon");
} // End of send_beacon method
void GeoNetworkingLayer::fill_beacon(INTEGER& p_latitude, INTEGER& p_longitude, OCTETSTRING& p_ll_address)
......@@ -313,7 +314,7 @@ void GeoNetworkingLayer::fill_beacon(INTEGER& p_latitude, INTEGER& p_longitude,
void GeoNetworkingLayer::timer_irq_sigalrm_handler(int p_signal, siginfo_t *p_signal_info, void *p_uc) {
loggers::get_instance().log("GeoNetworkingLayer::timer_irq_sigalrm_handler: Caught signal %d\n", p_signal);
//loggers::get_instance().log(">>> GeoNetworkingLayer::timer_irq_sigalrm_handler: Caught signal %d", p_signal);
static_cast<GeoNetworkingLayer *>(p_signal_info->si_value.sival_ptr)->send_beacon();
} // End of method timer_irq_sigalrm_handler
......
......@@ -50,6 +50,7 @@ public:
void start_beaconing();
void stop_beaconing();
void send_beacon();
const int _signal_id = SIGTERM;
};
#endif
......@@ -15,13 +15,43 @@ int UpperTesterCodec::encode (const Record_Type& msg, OCTETSTRING& data)
TTCN_EncDec::clear_error();
TTCN_Buffer encoding_buffer;
//encode_(msg, *msg.get_descriptor(), encoding_buffer);
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& 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 (std::string(field_descriptor.name).compare("@LibItsGeoNetworking_TypesAndValues.UtGnInitialize") == 0) {
encoding_buffer.put_c(static_cast<unsigned char>(0x00));
}
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 {
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();
......@@ -35,4 +65,17 @@ int UpperTesterCodec::decode (const OCTETSTRING& data, Record_Type& msg, Params*
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 == 0x01) {
msg.utGnInitializeResult() = BOOLEAN(*(ptr + 1) == 0x01);
} else {
TTCN_warning("UpperTesterCodec::decode: Unsupported result");
}
loggers::get_instance().log_msg("<<< UpperTesterCodec::decode", msg);
return 0;
}
......@@ -10,20 +10,22 @@ class Record_Type;
class TTCN_Typedescriptor_t;
class TTCN_Buffer;
namespace LibItsGeoNetworking__TestSystem {
class UtInitialize;
namespace LibItsGeoNetworking__TypesAndValues {
class UtGnResults;
}
class UpperTesterCodec: public Codec <
Record_Type,
Record_Type>
{
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 decode (const OCTETSTRING& data, Record_Type&, Params* params = NULL);
int decode (const OCTETSTRING& data, LibItsGeoNetworking__TypesAndValues::UtGnResults& msg, Params* params = NULL);
};
#endif
......@@ -9,15 +9,15 @@ UpperTesterLayer::UpperTesterLayer(const std::string & p_type, const std::string
Params::convert(_params, param);
}
void UpperTesterLayer::sendMsg(const LibItsCommon__TypesAndValues::UtInitialize& p, Params& params){
void UpperTesterLayer::sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize& p, Params& params){
loggers::get_instance().log_msg(">>> UpperTesterLayer::sendMsg", p);
// Encode UpperTester PDU
OCTETSTRING data;
data = int2oct(0, 9);
// TODO _codec.encode((const Record_Type &)p, data);
_codec.encode((const Record_Type &)p, data);
// Update parameters
// Params par(params); // FIXME Review all const Param& in method declarations
Params par(params); // FIXME Review all const Param& in method declarations
sendData(data, params);
}
......@@ -30,12 +30,18 @@ void UpperTesterLayer::sendData(OCTETSTRING& data, Params& params) {
void UpperTesterLayer::receiveData(OCTETSTRING& data, Params& params)
{
loggers::get_instance().log_msg(">>> UpperTesterLayer::receiveData: ", data);
// Decode the payload
//Record_Type *p = new Record_Type();
//_codec.decode(data, *p);
// Pass it to the ports if amy
//toAllUpperPorts(p, params);
if (data.lengthof() == 2) {
LibItsGeoNetworking__TypesAndValues::UtGnResults p;
_codec.decode(data, p);
// 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);
}
}
class UpperTesterFactory : public LayerFactory {
......
......@@ -8,19 +8,20 @@ namespace LibItsGeoNetworking__TestSystem {
class UpperTesterPort;
}
namespace LibItsCommon__TypesAndValues {
class UtInitialize;
namespace LibItsGeoNetworking__TypesAndValues {
class UtGnInitialize;
}
class UpperTesterLayer : public TLayer<LibItsGeoNetworking__TestSystem::UpperTesterPort> {
Params _params;
UpperTesterCodec _codec;
public:
UpperTesterLayer() : TLayer<LibItsGeoNetworking__TestSystem::UpperTesterPort>(), _params(), _codec() {};
UpperTesterLayer(const std::string & p_type, const std::string & param);
virtual ~UpperTesterLayer() {};
void sendMsg(const LibItsCommon__TypesAndValues::UtInitialize&, Params& params);
void sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnInitialize&, Params& params);
virtual void sendData(OCTETSTRING& data, Params& params);
virtual void receiveData(OCTETSTRING& data, Params& info);
......
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