Commit e27923da authored by garciay's avatar garciay
Browse files

Validate AtsRSUSimulator for CAM & DENM

parent 9b1b6235
#include "LibItsSecurity_EncdecDeclarations.hh"
#include "EtsiTs103097Codec_Certificate.hh"
#include "EtsiTs103097Codec_ToBeSignedCertificate.hh"
#include "EtsiTs103097Codec_Data.hh"
#include "loggers.hh"
......@@ -34,14 +35,30 @@ namespace LibItsSecurity__EncdecDeclarations {
return 0;
}
BITSTRING fx__enc__ToBeSignedCertificate(const IEEE1609dot2::ToBeSignedCertificate& p) {
return int2bit(0, 1);
BITSTRING fx__enc__ToBeSignedCertificate(const IEEE1609dot2::ToBeSignedCertificate& p_toBeSignedCertificate) {
loggers::get_instance().log_msg(">>> fx__enc__ToBeSignedCertificate: ", p_toBeSignedCertificate);
EtsiTs103097Codec_ToBeSignedCertificate codec;
OCTETSTRING os;
if (codec.encode(p_toBeSignedCertificate, os) == -1) {
loggers::get_instance().warning("fx__enc__ToBeSignedCertificate: -1 result code was returned");
return int2bit(0, 1);
}
return oct2bit(os);
}
BITSTRING fx__enc__Ieee1609Dot2Data(const IEEE1609dot2::Ieee1609Dot2Data& p) {
loggers::get_instance().log_msg(">>> fx__enc__CertificateBase: ", p);
BITSTRING fx__enc__Ieee1609Dot2Data(const IEEE1609dot2::Ieee1609Dot2Data& p__ieee1609Dot2Data) {
loggers::get_instance().log_msg(">>> fx__enc__Ieee1609Dot2Data: ", p__ieee1609Dot2Data);
return int2bit(0, 1);
EtsiTs103097Codec_Data codec;
OCTETSTRING os;
if (codec.encode(p__ieee1609Dot2Data, os) == -1) {
loggers::get_instance().warning("fx__enc__Ieee1609Dot2Data: -1 result code was returned");
return int2bit(0, 1);
}
return oct2bit(os);
}
INTEGER fx__dec__Ieee1609Dot2Data(BITSTRING& p__data, IEEE1609dot2::Ieee1609Dot2Data& p__ieee1609Dot2Data) {
......@@ -61,24 +78,33 @@ namespace LibItsSecurity__EncdecDeclarations {
BITSTRING fx__enc__SspCAM(const LibItsSecurity__TypesAndValues::SspCAM& p__ssp) {
loggers::get_instance().log_msg(">>> fx__enc__SspCAM: ", p__ssp);
return int2bit(0, 1);
TTCN_Buffer encoding_buffer;
p__ssp.encode(*p__ssp.get_descriptor(), encoding_buffer, TTCN_EncDec::CT_RAW);
return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()));
}
INTEGER fx__dec__SspCAM(BITSTRING& p__data, LibItsSecurity__TypesAndValues::SspCAM& p__ssp) {
loggers::get_instance().log_msg(">>> fx__dec__SspCAM: ", p__data);
return -1;
TTCN_Buffer decoding_buffer(bit2oct(p__data));
p__ssp.decode(*p__ssp.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW);
return 0;
}
BITSTRING fx__enc__SspDENM(const LibItsSecurity__TypesAndValues::SspDENM& p__ssp) {
loggers::get_instance().log_msg(">>> fx__enc__SspDENM: ", p__ssp);
return int2bit(0, 1);
TTCN_Buffer encoding_buffer;
p__ssp.encode(*p__ssp.get_descriptor(), encoding_buffer, TTCN_EncDec::CT_RAW);
return oct2bit(OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()));
}
INTEGER fx__dec__SspDENM(BITSTRING& p__data, LibItsSecurity__TypesAndValues::SspDENM& p__ssp) {
loggers::get_instance().log_msg(">>> fx__dec__SspDENM: ", p__data);
return -1;
TTCN_Buffer decoding_buffer(bit2oct(p__data));
p__ssp.decode(*p__ssp.get_descriptor(), decoding_buffer, TTCN_EncDec::CT_RAW);
return 0;
}
} //end namespace
#include "ItsRSUsSimulator_Functions.hh"
namespace ItsRSUsSimulator__Functions
{
void fx__computePositionFromRotation(const INTEGER& p__refLatitude, const INTEGER& p__refLongitude, const INTEGER& p__cenLatitude, const INTEGER& p__cenLongitude, const INTEGER& p__rotation, INTEGER& p__latitude, INTEGER& p__longitude) {
// TODO
p__latitude = p__cenLatitude;
p__longitude = p__cenLongitude;
}
} // end of namespace
/*!
* \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; //! 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; //! 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; //! 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()) {};
/*!
* \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 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; //! 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; //! 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& device_mode; //! To indicate to the lower layer to act as a standalone device
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()) {};
/*!
* \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
......@@ -38,7 +38,7 @@ const std::string& Params::longitude = std::string("longitude");
const std::string& Params::ll_address = std::string("ll_address");
const std::string& Params::expiry = std::string("expiry");
const std::string& Params::packetize = std::string("packetize");
const std::string& Params::device_mode = std::string("device_mode");
const std::string& Params::distanceA = std::string("distanceA");
const std::string& Params::distanceB = std::string("distanceB");
const std::string& Params::angle = std::string("angle");
......
#include "BTPLayerFactory.hh"
#include "BTPTypes.hh"
#include "loggers.hh"
BTPLayer::BTPLayer(const std::string & p_type, const std::string & param) : TLayer<LibItsBtp__TestSystem::BtpPort>(p_type), _params(), _codec() {
loggers::get_instance().log(">>> BTPLayer::BTPLayer: %s, %s", to_string().c_str(), param.c_str());
// Setup parameters
Params::convert(_params, param);
// Sanity check
Params::const_iterator it = _params.find(Params::btp_type);
if (it == _params.cend()) {
_params[Params::btp_type] = std::string("btpA");
}
it = _params.find(Params::btp_destination_port);
if (it == _params.cend()) {
_params[Params::btp_destination_port] = std::to_string(2001);
}
it = _params.find(Params::btp_info);
if (it == _params.cend()) {
_params[Params::btp_info] = std::to_string(0);
}
}
void BTPLayer::sendMsg(const LibItsBtp__TestSystem::BtpReq& p, Params& params){
loggers::get_instance().log(">>> BTPLayer::sendMsg");
//params.log();
// Encode BTP PDU
OCTETSTRING data;
_codec.encode(p.msgOut(), data);
sendData(data, params);
}
void BTPLayer::sendData(OCTETSTRING& data, Params& params) {
loggers::get_instance().log_msg(">>> BTPLayer::sendData: ", data);
params.log();
Params::const_iterator it = params.find(Params::packetize);
if (it != params.cend()) {
LibItsBtp__TypesAndValues::BtpHeader header;
if (_params[Params::btp_type].compare("btpA") == 0) {
header.btpAHeader() = LibItsBtp__TypesAndValues::BtpAHeader(
std::stoi(_params[Params::btp_destination_port]),
std::stoi(_params[Params::btp_info])
);
} else {
header.btpBHeader() = LibItsBtp__TypesAndValues::BtpBHeader(
std::stoi(_params[Params::btp_destination_port]),
std::stoi(_params[Params::btp_info])
);
}
LibItsBtp__TypesAndValues::BtpPacket p(
header,
data
);
loggers::get_instance().log_msg("BTPLayer::sendData: ", p);
// Encode BTP PDU
OCTETSTRING os;
_codec.encode(p, os);
data = os;
}
sendToAllLayers(data, params);
}
void BTPLayer::receiveData(OCTETSTRING& data, Params& params)
{
loggers::get_instance().log_msg(">>> BTPLayer::receiveData: ", data);
params.log();
// Decode the payload
LibItsBtp__TestSystem::BtpInd p;
Params::const_iterator it = params.find(Params::gn_next_header);
if (it != params.cend()) {
_codec.set_btp_type((it->second.compare("02") == 0) ? BTPCodec::btpB : BTPCodec::btpA);
}
_codec.decode(data, p.msgIn(), &params);
// Pass the BTP raw payload to the upper layers if any
it = params.find(Params::btp_payload);
if (it != params.cend()) {
loggers::get_instance().log("BTPLayer::receiveData: btp_payload=%s", it->second.c_str());
OCTETSTRING os(str2oct(CHARSTRING(it->second.c_str())));
receiveToAllLayers(os, params);
} else {
loggers::get_instance().warning("BTPLayer::receiveData: No payload to pass to upper layers");
}
// Pass it to the ports if any
//params.log();
toAllUpperPorts(p, params);
}
BTPLayerFactory BTPLayerFactory::_f;
#include "BTPLayerFactory.hh"
#include "BTPTypes.hh"
#include "loggers.hh"
BTPLayer::BTPLayer(const std::string & p_type, const std::string & param) : TLayer<LibItsBtp__TestSystem::BtpPort>(p_type), _params(), _codec(), _device_mode{false} {
loggers::get_instance().log(">>> BTPLayer::BTPLayer: %s, %s", to_string().c_str(), param.c_str());
// Setup parameters
Params::convert(_params, param);
// Sanity check
Params::const_iterator it = _params.find(Params::btp_type);
if (it == _params.cend()) {
_params[Params::btp_type] = std::string("btpA");
}
it = _params.find(Params::btp_destination_port);
if (it == _params.cend()) {
_params[Params::btp_destination_port] = std::to_string(2001);
}
it = _params.find(Params::btp_info);
if (it == _params.cend()) {
_params[Params::btp_info] = std::to_string(0);
}
it = _params.find(Params::device_mode);
if (it != _params.cend()) {
_device_mode = (0 == str2int(CHARSTRING(it->second.c_str())));
}
}
void BTPLayer::sendMsg(const LibItsBtp__TestSystem::BtpReq& p, Params& params){
loggers::get_instance().log(">>> BTPLayer::sendMsg");
//params.log();
// Encode BTP PDU
OCTETSTRING data;
_codec.encode(p.msgOut(), data);
sendData(data, params);
}
void BTPLayer::sendData(OCTETSTRING& data, Params& params) {
loggers::get_instance().log_msg(">>> BTPLayer::sendData: ", data);
params.log(); // TODO To be removed
if (_device_mode) {
LibItsBtp__TypesAndValues::BtpHeader header;
if (_params[Params::btp_type].compare("btpA") == 0) {
header.btpAHeader() = LibItsBtp__TypesAndValues::BtpAHeader(
std::stoi(_params[Params::btp_destination_port]),
std::stoi(_params[Params::btp_info])
);
} else {
header.btpBHeader() = LibItsBtp__TypesAndValues::BtpBHeader(
std::stoi(_params[Params::btp_destination_port]),
std::stoi(_params[Params::btp_info])
);
}
LibItsBtp__TypesAndValues::BtpPacket p(
header,
data
);
loggers::get_instance().log_msg("BTPLayer::sendData: ", p);
// Encode BTP PDU
OCTETSTRING os;
_codec.encode(p, os);
data = os;
}
sendToAllLayers(data, params);
}
void BTPLayer::receiveData(OCTETSTRING& data, Params& params)
{
loggers::get_instance().log_msg(">>> BTPLayer::receiveData: ", data);
params.log();
// Decode the payload
LibItsBtp__TestSystem::BtpInd p;
Params::const_iterator it = params.find(Params::gn_next_header);
if (it != params.cend()) {
_codec.set_btp_type((it->second.compare("02") == 0) ? BTPCodec::btpB : BTPCodec::btpA);
}
_codec.decode(data, p.msgIn(), &params);
// Pass the BTP raw payload to the upper layers if any
it = params.find(Params::btp_payload);
if (it != params.cend()) {
loggers::get_instance().log("BTPLayer::receiveData: btp_payload=%s", it->second.c_str());
OCTETSTRING os(str2oct(CHARSTRING(it->second.c_str())));
receiveToAllLayers(os, params);
} else {
loggers::get_instance().warning("BTPLayer::receiveData: No payload to pass to upper layers");
}
// Pass it to the ports if any
//params.log();
toAllUpperPorts(p, params);
}
BTPLayerFactory BTPLayerFactory::_f;
......@@ -22,8 +22,9 @@ namespace LibItsBtp__TestSystem {
class BTPLayer : public TLayer<LibItsBtp__TestSystem::BtpPort> {
Params _params;
BTPCodec _codec;
bool _device_mode;
public:
BTPLayer() : TLayer<LibItsBtp__TestSystem::BtpPort>(), _params(), _codec() {};
BTPLayer() : TLayer<LibItsBtp__TestSystem::BtpPort>(), _params(), _codec(), _device_mode{false} {};
BTPLayer(const std::string& p_type, const std::string& param);
virtual ~BTPLayer() {};
......
#include "CAMLayerFactory.hh"
#include "CAMTypes.hh"
#include "loggers.hh"
CAMLayer::CAMLayer(const std::string & p_type, const std::string & param) : TLayer<LibItsCam__TestSystem::CamPort>(p_type), _params(), _codec() {
loggers::get_instance().log(">>> CAMLayer::CAMLayer: %s, %s", to_string().c_str(), param.c_str());
// Setup parameters
Params::convert(_params, param);
}
void CAMLayer::sendMsg(const LibItsCam__TestSystem::CamReq& p, Params& params){
loggers::get_instance().log_msg(">>> CAMLayer::sendMsg: ", p);
// Encode CAM PDU
OCTETSTRING data;
if (_codec.encode(p.msgOut(), data) == -1) {
loggers::get_instance().warning("CAMLayer::sendMsg: Encodeing failure");
return;
}
// Update parameters
params.insert(std::pair<std::string, std::string>(
Params::packetize,
std::string("")
));
sendData(data, params);
}
void CAMLayer::sendData(OCTETSTRING& data, Params& params) {
loggers::get_instance().log_msg(">>> CAMLayer::sendData: ", data);
//params.log();
sendToAllLayers(data, params);
}
void CAMLayer::receiveData(OCTETSTRING& data, Params& params)
{
loggers::get_instance().log_msg(">>> CAMLayer::receiveData: ", data);
// Sanity check
if (*(static_cast<const unsigned char*>(data)+ 1) != 0x02) { // Check that received packet has CA message id - See ETSI TS 102 894
// Not a CAM message, discard it
loggers::get_instance().warning("CAMLayer::receiveData: Wrong message id: 0x%02x", *(static_cast<const unsigned char*>(data)+ 1));
return;
}
// Decode the payload
LibItsCam__TestSystem::CamInd p;
_codec.decode(data, p.msgIn());
if (!p.msgIn().is_bound()) {
// Discard it
return;
} // else, continue
// Process lower layer data
// gnNextHeader
Params::const_iterator it = params.find(Params::gn_next_header);
if (it != params.cend()) {
p.gnNextHeader() = std::stoi(it->second);
} else {
p.gnNextHeader().set_to_omit();
}
// gnHeaderType
it = params.find(Params::gn_header_type);
if (it != params.cend()) {
p.gnHeaderType() = std::stoi(it->second);
} else {
p.gnHeaderType().set_to_omit();
}
// gnHeaderSubtype
it = params.find(Params::gn_header_sub_type);
if (it != params.cend()) {
p.gnHeaderSubtype() = std::stoi(it->second);
} else {
p.gnHeaderSubtype().set_to_omit();
}
// gnLifetime
it = params.find(Params::gn_lifetime);
if (it != params.cend()) {
p.gnLifetime() = std::stoi(it->second);
} else {
p.gnLifetime().set_to_omit();
}
// gnTrafficClass
it = params.find(Params::gn_traffic_class);
if (it != params.cend()) {
p.gnTrafficClass() = std::stoi(it->second);
} else {
p.gnTrafficClass().set_to_omit();
}
// btpDestinationPort
it = params.find(Params::btp_destination_port);
if (it != params.cend()) {
p.btpDestinationPort() = std::stoi(it->second);
} else {
p.btpDestinationPort().set_to_omit();
}
// btpInfo
it = params.find(Params::btp_info);
if (it != params.cend()) {
p.btpInfo() = std::stoi(it->second);
} else {
p.btpInfo().set_to_omit();
}
// ssp
it = params.find(Params::ssp);