Compare Revisions

The credentials to download the source code are:
 Username: svnusers
 Password: svnusers

Ignore whitespace Rev 3324 → Rev 3325

/branches/STF525/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorLayer.cc
4,9 → 4,13
 
#include "ItsRSUsSimulator_TestSystem.hh"
 
#include "LibCommon_BasicTypesAndValues.hh"
 
#include "uppertester_cam_codec.hh"
#include "uppertester_geonetworking_codec.hh"
 
#include "LibItsCam_EncdecDeclarations.hh"
 
ConfigRsuSimulatorLayer::ConfigRsuSimulatorLayer(const std::string & p_type, const std::string & param) : t_layer<ItsRSUsSimulator__TestSystem::ConfigRsuSimulatorPort>(p_type), _params(), _codec(), _codec_cam() {
loggers::get_instance().log(">>> ConfigRsuSimulatorLayer::ConfigRsuSimulatorLayer: %s, %s", to_string().c_str(), param.c_str());
// Setup parameters
33,6 → 37,9
if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnResults::ALT_utGnInitializeResult)) {
encoding_buffer.put_c(0x01/*static_cast<const unsigned char>(uppertester_geonetworking_codec::c_utGnInitializeResult)*/);
encoding_buffer.put_c((unsigned char)static_cast<const boolean>(send_par.utGnInitializeResult()));
} else if (send_par.ischosen(LibItsGeoNetworking__TypesAndValues::UtGnResults::ALT_utGnTriggerResult)) {
encoding_buffer.put_c(0x41/*static_cast<const unsigned char>(uppertester_geonetworking_codec::c_utGnTriggerResult)*/);
encoding_buffer.put_c((unsigned char)static_cast<const boolean>(send_par.utGnTriggerResult()));
} else {
loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtGnResults variant");
return;
49,6 → 56,9
if (send_par.ischosen(LibItsCam__TypesAndValues::UtCamResults::ALT_utCamInitializeResult)) {
encoding_buffer.put_c(0x01/*static_cast<const unsigned char>(uppertester_cam_codec::c_utCamInitializeResult)*/);
encoding_buffer.put_c((unsigned char)static_cast<const boolean>(send_par.utCamInitializeResult()));
} else if (send_par.ischosen(LibItsCam__TypesAndValues::UtCamResults::ALT_utCamTriggerResult)) {
encoding_buffer.put_c(0x21/*static_cast<const unsigned char>(uppertester_cam_codec::c_utCamTriggerResult)*/);
encoding_buffer.put_c((unsigned char)static_cast<const boolean>(send_par.utCamTriggerResult()));
} else {
loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Unsupported UtCamResults variant");
return;
58,6 → 68,17
send_data(os, _params);
}
 
void ConfigRsuSimulatorLayer::sendMsg(const LibItsCam__TypesAndValues::UtCamEventInd& send_par, params& params) {
loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par);
 
TTCN_Buffer encoding_buffer;
encoding_buffer.put_c(0x23/*static_cast<const unsigned char>(uppertester_cam_codec::c_utCamEventInd)*/);
BITSTRING bs = LibItsCam__EncdecDeclarations::fx__enc__CAM(send_par.camMsg());
encoding_buffer.put_s(bs.lengthof(), static_cast<const unsigned char*>(bs));
OCTETSTRING os(encoding_buffer.get_len(), encoding_buffer.get_data());
send_data(os, _params);
}
 
void ConfigRsuSimulatorLayer::sendMsg(const LibItsDenm__TypesAndValues::UtDenmResults& send_par, params& params) {
loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par);
 
87,10 → 108,12
unsigned char id = *(static_cast<const unsigned char*>(data));
if (id == 0x00) { // Receive an UtxxInitialise
process_utinitialize_data(data, params);
} else if (id == 0x30/*uppertester_cam_codec::c_utCamChangeCurvature*/) {
process_ut_cam_changecurvature_data(data, params);
} else if (id == 0x31/*uppertester_cam_codec::c_utCamChangeSpeed*/) {
process_ut_cam_changespeed_data(data, params);
} else if (id == 0x30/*uppertester_cam_codec::c_utCamChangeCurvature*/) {
process_ut_cam_changecurvature_data(data, params);
} else if (id == 0x34/*uppertester_cam_codec::c_utCamChangeHeading*/) {
process_ut_cam_changeheading_data(data, params);
} else if ((id >= 0x50) && (id <= 0x54)) { // Receive an UtGnTrigger
process_ut_geonetworking_trigger(data, params);
} else {
164,9 → 187,9
}
 
if (_params[std::string("ut")].compare("cam") == 0) {
OCTETSTRING speed(data.lengthof() - 1, 1 + static_cast<const unsigned char*>(data));
OCTETSTRING curvature(data.lengthof() - 1, 1 + static_cast<const unsigned char*>(data));
LibItsCam__TypesAndValues::UtCamTrigger p;
p.changeCurvature() = oct2int(speed);
p.changeCurvature() = oct2int(curvature);
// Pass it to the ports if any
to_all_upper_ports(p, params);
} else {
177,6 → 200,29
return 0;
}
 
int ConfigRsuSimulatorLayer::process_ut_cam_changeheading_data(const OCTETSTRING& data, params& params) {
loggers::get_instance().log(">>> ConfigRsuSimulatorLayer::process_ut_cam_changeheading_data");
 
params::const_iterator it = _params.find("ut");
if (it == _params.cend()) {
loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_ut_cam_changeheading_data: CF layer's ut parameter is missing");
return -1;
}
 
if (_params[std::string("ut")].compare("cam") == 0) {
OCTETSTRING heading(data.lengthof() - 1, 1 + static_cast<const unsigned char*>(data));
LibItsCam__TypesAndValues::UtCamTrigger p;
p.changeHeading() = oct2int(heading);
// Pass it to the ports if any
to_all_upper_ports(p, params);
} else {
loggers::get_instance().warning("ConfigRsuSimulatorLayer::process_ut_cam_changeheading_data: Unsupported protocol");
return -1;
}
 
return 0;
}
 
int ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger(const OCTETSTRING& data, params& params) {
loggers::get_instance().log(">>> ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger");
 
187,17 → 233,25
}
 
if (_params[std::string("ut")].compare("gn") == 0) {
unsigned char msg_id = *static_cast<const unsigned char*>(data);
loggers::get_instance().log("ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger: msg_id=%02x", msg_id);
OCTETSTRING payload(data.lengthof() - 1, 1 + static_cast<const unsigned char*>(data));
loggers::get_instance().log_msg("ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger: payload:", payload);
TTCN_EncDec::clear_error();
TTCN_Buffer decoding_buffer(payload);
LibItsGeoNetworking__TypesAndValues::GenerateGeoUnicastMessage g;
for (int i = 0; i < g.get_count(); i++) {
loggers::get_instance().log_to_hexa("ConfigRsuSimulatorLayer::process_ut_geonetworking_trigger: decoding_buffer=", decoding_buffer);
g.decode(*g.fld_descr(i), decoding_buffer, TTCN_EncDec::CT_RAW);
 
LibItsGeoNetworking__TypesAndValues::UtGnTrigger p;
if (msg_id == 0x50/*uppertester_geonetworking_codec::c_utGnTrigger_GeoUnicast*/) {
LibItsGeoNetworking__TypesAndValues::GenerateGeoUnicastMessage g;
g.decode(*g.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW);
g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast<const unsigned char*>(g.payload()));
p.geoUnicast() = g;
} else if (msg_id == 0x51/*uppertester_geonetworking_codec::c_utGnTrigger_GeoBroadcast*/) {
LibItsGeoNetworking__TypesAndValues::GenerateGeoBroadcastMessage g;
g.decode(*g.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW);
g.payload() = OCTETSTRING(g.payload().lengthof() - 2, static_cast<const unsigned char*>(g.payload()));
p.geoBroadcast() = g;
}
LibItsGeoNetworking__TypesAndValues::UtGnTrigger p;
p.geoUnicast() = g;
// Pass it to the ports if any
to_all_upper_ports(p, params);
} else {
/branches/STF525/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorLayer.hh
34,6 → 34,7
void sendMsg(const ItsRSUsSimulator__TestSystem::CfInitialize&, params& params);
void sendMsg(const LibItsGeoNetworking__TypesAndValues::UtGnResults& send_par, params& params);
void sendMsg(const LibItsCam__TypesAndValues::UtCamResults& send_par, params& params);
void sendMsg(const LibItsCam__TypesAndValues::UtCamEventInd& send_par, params& params);
void sendMsg(const LibItsDenm__TypesAndValues::UtDenmResults& send_par, params& params);
virtual void send_data(OCTETSTRING& data, params& params);
43,6 → 44,7
int process_utinitialize_data(const OCTETSTRING& data, params& params);
int process_ut_cam_changespeed_data(const OCTETSTRING& data, params& params);
int process_ut_cam_changecurvature_data(const OCTETSTRING& data, params& params);
int process_ut_cam_changeheading_data(const OCTETSTRING& data, params& params);
int process_ut_geonetworking_trigger(const OCTETSTRING& data, params& params);
 
}; // End of class ConfigRsuSimulatorLayer
/branches/STF525/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorPort.cc
124,6 → 124,15
loggers::get_instance().set_stop_time(_time_key, duration);
}
 
void ConfigRsuSimulatorPort::outgoing_send(const LibItsCam__TypesAndValues::UtCamEventInd& send_par) {
loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::outgoing_send: payload=", send_par);
float duration;
loggers::get_instance().set_start_time(_time_key);
static_cast<ConfigRsuSimulatorLayer *>(_layer)->sendMsg(send_par, _layer_params);
loggers::get_instance().set_stop_time(_time_key, duration);
}
 
void ConfigRsuSimulatorPort::outgoing_send(const LibItsDenm__TypesAndValues::UtDenmResults& send_par) {
loggers::get_instance().log_msg(">>> ConfigRsuSimulatorPort::outgoing_send: payload=", send_par);
/branches/STF525/ccsrc/Ports/LibIts_ports/RSUsSimulator_ports/ConfigRsuSimulatorPort.hh
57,6 → 57,7
void outgoing_send(const BOOLEAN& send_par);
void outgoing_send(const LibItsGeoNetworking__TypesAndValues::UtGnResults& send_par);
void outgoing_send(const LibItsCam__TypesAndValues::UtCamResults& send_par);
void outgoing_send(const LibItsCam__TypesAndValues::UtCamEventInd& send_par);
void outgoing_send(const LibItsDenm__TypesAndValues::UtDenmResults& send_par);
}; // End of class ConfigRsuSimulatorPort
 
/branches/STF525/ccsrc/Protocols/Http/http_codec.cc
332,6 → 332,16
const LibItsHttp__XmlMessageBodyTypes::XmlBody& xml_body = p_message_body.xml__body();
if (xml_body.ischosen(LibItsHttp__XmlMessageBodyTypes::XmlBody::ALT_raw)) {
p_encoding_buffer = OCTETSTRING(xml_body.raw().lengthof(), (unsigned char*)static_cast<const char*>(xml_body.raw()));
} else if (xml_body.ischosen(LibItsHttp__XmlMessageBodyTypes::XmlBody::ALT_findServiceRequest)) {
std::map<std::string, std::unique_ptr<codec<Record_Type, Record_Type> > >::const_iterator it = _codecs.find("lost");
if (it != _codecs.cend()) {
loggers::get_instance().log("http_codec::encode_body: Call 'lost_codec'");
_codecs["lost"]->encode((Record_Type&)xml_body, p_encoding_buffer);
} else {
loggers::get_instance().warning("http_codec::encode_body: Unsupported HTTP codec, use raw field as default");
p_encoding_buffer = OCTETSTRING(xml_body.raw().lengthof(), (unsigned char*)static_cast<const char*>(xml_body.raw()));
// TODO Add new HTTP message codec here
}
} else {
std::map<std::string, std::unique_ptr<codec<Record_Type, Record_Type> > >::const_iterator it = _codecs.find("held");
if (it != _codecs.cend()) {
431,7 → 441,23
loggers::get_instance().warning("http_codec::decode_body: No codec for HELD");
xml_body.raw() = CHARSTRING(body.lengthof(), (char*)static_cast<const unsigned char*>(body));
}
message_body.xml__body() = xml_body;
message_body.xml__body() = xml_body;
} else if (p["decode_str"].find("xmlns=\"urn:ietf:params:xml:ns:lost1\">") != std::string::npos) {
loggers::get_instance().log("http_codec::decode_body: Find 'urn:ietf:params:xml:ns:loat1'");
if (_codecs["lost"].get() != nullptr) {
loggers::get_instance().log("http_codec::decode_body: Call 'lost_codec'");
if (_codecs["lost"]->decode(body, (Record_Type&)xml_body, &p) == -1) {
loggers::get_instance().warning("http_codec::decode_body: Failed to decode LOST message");
xml_body.raw() = CHARSTRING(body.lengthof(), (char*)static_cast<const unsigned char*>(body));
} else {
loggers::get_instance().log_msg("http_codec::decode_body: Decoded message:", xml_body);
message_body.xml__body() = xml_body;
}
} else {
loggers::get_instance().warning("http_codec::decode_body: No codec for LOST");
xml_body.raw() = CHARSTRING(body.lengthof(), (char*)static_cast<const unsigned char*>(body));
}
message_body.xml__body() = xml_body;
}
} else if (p["decode_str"].find("<html>") != std::string::npos) { // Try to identify HTML
loggers::get_instance().log("http_codec::decode_body: Find html message");
494,7 → 520,7
// Extract codecs
try {
std::regex rgx("(\\w+)(:(\\w+))*(;((\\w+)(:(\\w+))*))*");
std::regex rgx("(\\w+):(\\w+)(;(\\w+):(\\w+))*");
std::sregex_iterator begin(p_codecs.cbegin(), p_codecs.cend(), rgx);
std::sregex_iterator end = std::sregex_iterator();
// E.g. 9 - xml - :held_codec - held_codec - ;html:html_codec - html:html_codec - html - :html_codec - html_codec
501,10 → 527,10
for (std::sregex_iterator it = begin; it != end; ++it) {
std::smatch m = *it;
loggers::get_instance().log("http_codec::set_payload_codecs: %d - %s - %s - %s - %s - %s - %s - %s - %s", m.size(), m[1].str().c_str(), m[2].str().c_str(), m[3].str().c_str(), m[4].str().c_str(), m[5].str().c_str(), m[6].str().c_str(), m[7].str().c_str(), m[8].str().c_str());
for (unsigned int j = 1; j < m.size() - 1; j += 5) { // Exclude m[0]
loggers::get_instance().log("http_codec::set_payload_codecs: insert (%s, %s), j = %d", m[j].str().c_str(), m[j + 2].str().c_str(), j);
for (unsigned int j = 1; j < m.size() - 1; j += 3) { // Exclude m[0]
loggers::get_instance().log("http_codec::set_payload_codecs: insert (%s, %s), j = %d", m[j].str().c_str(), m[j + 1].str().c_str(), j);
std::string key(m[j].str());
_codecs.insert(std::make_pair(key, std::unique_ptr<codec<Record_Type, Record_Type> >(codec_stack_builder::get_instance()->get_codec(m[j + 2].str().c_str()))));
_codecs.insert(std::make_pair(key, std::unique_ptr<codec<Record_Type, Record_Type> >(codec_stack_builder::get_instance()->get_codec(m[j + 1].str().c_str()))));
} // End of 'for' statement
} // End of 'for' statement
//loggers::get_instance().log("http_codec::set_payload_codecs: _codecs length=%d", _codecs.size());