Commit 693f91b4 authored by garciay's avatar garciay
Browse files

Validate GeNetworking, CAM,DENM & Security

Bug fixed in fx__getCurrentTime()
parent 2bfadde8
......@@ -48,7 +48,7 @@ namespace LibItsDenm__EncdecDeclarations {
INTEGER fx__dec__DenmInd(BITSTRING& b, LibItsDenm__TestSystem::DenmInd& p_denmInd)
{
loggers::get_instance().log_msg(">>> fx__enc__DenmInd: ", p_denmInd);
loggers::get_instance().log(">>> fx__dec__DenmInd");
DENMCodec codec;
DENM__PDU__Descriptions::DENM denm;
......
#include "LibItsCommon_Functions.hh"
//#include "ITS_Container.hh"
#include <time.h>
#include <chrono>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#define M_PI 3.14159265358979323846
#endif
namespace LibItsCommon__Functions
{
/**
* @desc This external function gets the current time
* @return Timestamp - current time since 01/01/2014 in milliseconds
* @see fx_getCurrentTime() return TimestampIts
*/
INTEGER fx__getCurrentTime(
/**
* @desc This external function gets the current time
* @return Timestamp - current time since 01/01/2014 in milliseconds
* @see fx_getCurrentTime() return TimestampIts
*/
INTEGER fx__getCurrentTime(
) {
unsigned long long timestamp2014 = 1356998400000;
struct timeval tv;
gettimeofday(&tv, NULL);
unsigned long long timestampNow = tv.tv_sec*1000 + tv.tv_usec/1000;
// i.set_long_long_val(timestampNow - timestamp2014);
// return i;
return INTEGER(timestampNow - timestamp2014);
}
/**
* @desc Gets the current time since 01/01/2004
* @return TimeMark - tenths of a second in the current or next hour in units of 1/10th second from UTC time
* @see function f_getCurrentTimeMark() return TimeMark
*/
INTEGER fx__getCurrentTimeMark(
unsigned long long ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - 1072911600000L; // TODO Add a global method such as its_tme() & its_time_mod() beacuse it is used also in GeoNetworkingLayer
/*unsigned long long its_ref_time = 1072911600000L;
struct timeval tv;
gettimeofday(&tv, NULL);
unsigned long long ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;*/
INTEGER i;
i.set_long_long_val(ms);
return i;
}
/**
* @desc Gets the current time since 01/01/2004
* @return TimeMark - tenths of a second in the current or next hour in units of 1/10th second from UTC time
* @see function f_getCurrentTimeMark() return TimeMark
*/
INTEGER fx__getCurrentTimeMark(
) {
// TODO: this is just a sceleton. fill in the function
return 0;
}
/**
* @desc Gets the Minute of current UTC year
* @return MinuteOfTheYear - tenths of a second in the current or next hour in units of 1/10th second from UTC time
* @see function f_getMinuteOfTheYear() return MinuteOfTheYear
*/
INTEGER fx__getMinuteOfTheYear(
// TODO: this is just a sceleton. fill in the function
return 0;
}
/**
* @desc Gets the Minute of current UTC year
* @return MinuteOfTheYear - tenths of a second in the current or next hour in units of 1/10th second from UTC time
* @see function f_getMinuteOfTheYear() return MinuteOfTheYear
*/
INTEGER fx__getMinuteOfTheYear(
) {
// TODO: this is just a sceleton. fill in the function
return 0;
}
// TODO: this is just a sceleton. fill in the function
return 0;
}
/**
/**
* @desc Gets the milliseconds point in the current UTC minute
* @return DSecond - The milliseconds point in the current UTC minute (0..60000)
* @see function f_getDSecond() return DSecond
*/
INTEGER fx__getDSecond(
) {
// TODO: this is just a sceleton. fill in the function
return 0;
}
/* * @desc External function to compute distance between two points
* @param p_latitudeA Latitude of first point
* @param p_longitudeA Longitude of first point
* @param p_latitudeB Latitude of second point
* @param p_longitudeB Longitude of second point
* @return Computed distance in meters
fx_computeDistance(in Int32 p_latitudeA, in Int32 p_longitudeA, in Int32 p_latitudeB, in Int32 p_longitudeB) return float;
*/
FLOAT fx__computeDistance(
const INTEGER& p__latitudeA,
const INTEGER& p__longitudeA,
const INTEGER& p__latitudeB,
const INTEGER& p__longitudeB
INTEGER fx__getDSecond(
) {
// TODO: this is just a sceleton. fill in the function
return 0;
}
/* * @desc External function to compute distance between two points
* @param p_latitudeA Latitude of first point
* @param p_longitudeA Longitude of first point
* @param p_latitudeB Latitude of second point
* @param p_longitudeB Longitude of second point
* @return Computed distance in meters
fx_computeDistance(in Int32 p_latitudeA, in Int32 p_longitudeA, in Int32 p_latitudeB, in Int32 p_longitudeB) return float;
*/
FLOAT fx__computeDistance(
const INTEGER& p__latitudeA,
const INTEGER& p__longitudeA,
const INTEGER& p__latitudeB,
const INTEGER& p__longitudeB
) {
double d_latA = ((double)p__latitudeA)/10000000.0;
double d_latB = ((double)p__latitudeB)/10000000.0;
......@@ -89,43 +88,43 @@ FLOAT fx__computeDistance(
double c = 2*atan2(sqrt(a), sqrt(1-a));
return FLOAT(earth_radius*c);
}
/* * @desc External function to compute a position using a reference position, a distance and an orientation
* @param p_iutLongPosVector Reference position
* @param p_distance Distance to the reference position (in meter)
* @param p_orientation Direction of the computed position (0 to 359; 0 means North)
* @param p_latitude Computed position's latitude
* @param p_longitude Computed position's longitude
fx_computePositionUsingDistance(in Int32 p_refLatitude,in Int32 p_refLongitude,in float p_distance,in integer p_orientation,out Int32 p_latitude,out Int32 p_longitude);
*/
void fx__computePositionUsingDistance(
const INTEGER& p__refLatitude,
const INTEGER& p__refLongitude,
const FLOAT& p__distance,
const INTEGER& p__orientation,
INTEGER& p__latitude,
INTEGER& p__longitude
) {
}
/* * @desc External function to compute a position using a reference position, a distance and an orientation
* @param p_iutLongPosVector Reference position
* @param p_distance Distance to the reference position (in meter)
* @param p_orientation Direction of the computed position (0 to 359; 0 means North)
* @param p_latitude Computed position's latitude
* @param p_longitude Computed position's longitude
fx_computePositionUsingDistance(in Int32 p_refLatitude,in Int32 p_refLongitude,in float p_distance,in integer p_orientation,out Int32 p_latitude,out Int32 p_longitude);
*/
void fx__computePositionUsingDistance(
const INTEGER& p__refLatitude,
const INTEGER& p__refLongitude,
const FLOAT& p__distance,
const INTEGER& p__orientation,
INTEGER& p__latitude,
INTEGER& p__longitude
) {
double distance = ((double)p__distance) / 6371000.0;
double angle = ((double)p__orientation) * (M_PI / 180.0);
double ref_lat = ((double)p__refLatitude) * (M_PI / 180.0);
// double ref_lon = ((double)p__refLongitude) * (M_PI / 180.0);
// double ref_lon = ((double)p__refLongitude) * (M_PI / 180.0);
p__latitude = asin(sin(ref_lat)*cos(distance) + cos(ref_lat)*sin(distance)*cos(angle)) * 180.0 / M_PI;
p__longitude = ((double)p__refLongitude) + atan2(sin(angle)*sin(distance)*cos(ref_lat), cos(distance) - sin(ref_lat)*sin((double)p__latitude))*(180.0/M_PI);
}
}
/* * @desc External function to compute radius of a given circular area
* @param p_squareMeters Square meters of an circular area
* @return Computed radius in meters
fx_computeRadiusFromCircularArea(in float p_squareMeters) return float;
*/
FLOAT fx__computeRadiusFromCircularArea(
const FLOAT& p__squareMeters
) {
/* * @desc External function to compute radius of a given circular area
* @param p_squareMeters Square meters of an circular area
* @return Computed radius in meters
fx_computeRadiusFromCircularArea(in float p_squareMeters) return float;
*/
FLOAT fx__computeRadiusFromCircularArea(
const FLOAT& p__squareMeters
) {
return FLOAT(sqrt(p__squareMeters/M_PI));
}
}
} // end of Namespace
......@@ -49,6 +49,10 @@ public:
static const std::string& distanceB; //! Test system GeoNetworking DistanceB parameter name
static const std::string& angle; //! Test system GeoNetworking Angle parameter name
static const std::string& next_header; //! Upper layer settings
static const std::string& header_type; //! Upper layer settings
static const std::string& header_sub_type; //! Upper layer settings
/*!
* \brief Default constructor
* Create a new instance of the Params class
......
......@@ -43,6 +43,10 @@ const std::string& Params::distanceA = std::string("distanceA");
const std::string& Params::distanceB = std::string("distanceB");
const std::string& Params::angle = std::string("angle");
const std::string& Params::next_header = std::string("next_header");
const std::string& Params::header_type = std::string("header_type");
const std::string& Params::header_sub_type = std::string("header_sub_type");
void Params::convert(Params& p_param, const std::string p_parameters) {
// Sanity checks
if (p_parameters.length() == 0) {
......
......@@ -52,9 +52,12 @@ namespace LibItsBtp__TestSystem {
Params::iterator it = _cfg_params.find(std::string("params"));
if (it != _cfg_params.end()) {
loggers::get_instance().log("BtpPort::user_map: %s", it->second.c_str());
// Setup parameters
Params::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless
// Create layer
_layer = LayerStackBuilder::GetInstance()->createLayerStack(it->second.c_str());
if (static_cast<BTPLayer *>(_layer) == NULL) {
loggers::get_instance().error("BtpPort::user_map: Invalid stack configuration: %s", it->second.c_str());
loggers::get_instance().error("BtpPort::user_map: Invalid stack configuration: %s", it->second.c_str());
}
static_cast<BTPLayer *>(_layer)->addUpperPort(this);
} else {
......
......@@ -57,6 +57,9 @@ namespace LibItsCam__TestSystem {
Params::iterator it = _cfg_params.find(std::string("params"));
if (it != _cfg_params.end()) {
loggers::get_instance().log("CamPort::user_map: %s", it->second.c_str());
// Setup parameters
Params::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless
// Create layer
_layer = LayerStackBuilder::GetInstance()->createLayerStack(it->second.c_str());
if (static_cast<CAMLayer *>(_layer) == NULL) {
loggers::get_instance().error("CamPort::user_map: Invalid stack configuration: %s", it->second.c_str());
......
......@@ -57,6 +57,9 @@ namespace LibItsDenm__TestSystem {
std::map<std::string, std::string>::iterator it = _cfg_params.find(std::string("params"));
if (it != _cfg_params.end()) {
loggers::get_instance().log("DenmPort::user_map: %s", it->second.c_str());
// Setup parameters
Params::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless
// Create layer
_layer = LayerStackBuilder::GetInstance()->createLayerStack(it->second.c_str());
if (static_cast<DENMLayer *>(_layer) == NULL) {
loggers::get_instance().error("DenmPort::user_map: Invalid stack configuration: %s", it->second.c_str());
......
......@@ -59,9 +59,9 @@ namespace LibItsGeoNetworking__TestSystem {
// Build layer stack
Params::iterator it = _cfg_params.find(std::string("params"));
if (it != _cfg_params.end()) {
//loggers::get_instance().log("GeoNetworkingPort::user_map: %s", it->second.c_str());
loggers::get_instance().log("GeoNetworkingPort::user_map: %s", it->second.c_str());
// Setup parameters
Params::convert(_layer_params, it->second);
Params::convert(_layer_params, it->second); // TODO This _layer_params seems to be useless
// Create layer
_layer = LayerStackBuilder::GetInstance()->createLayerStack(it->second.c_str());
if (static_cast<GeoNetworkingLayer *>(_layer) == NULL) {
......
......@@ -24,13 +24,13 @@ BTPLayer::BTPLayer(const std::string & p_type, const std::string & param) : TLay
}
it = _params.find(Params::device_mode);
if (it != _params.cend()) {
_device_mode = (0 == str2int(CHARSTRING(it->second.c_str())));
_device_mode = (1 == str2int(CHARSTRING(it->second.c_str())));
}
}
void BTPLayer::sendMsg(const LibItsBtp__TestSystem::BtpReq& p, Params& params){
loggers::get_instance().log(">>> BTPLayer::sendMsg");
//params.log();
params.log();
// Encode BTP PDU
OCTETSTRING data;
......@@ -44,7 +44,14 @@ void BTPLayer::sendData(OCTETSTRING& data, Params& params) {
if (_device_mode) {
LibItsBtp__TypesAndValues::BtpHeader header;
if (_params[Params::btp_type].compare("btpA") == 0) {
std::string btp_type;
Params::const_iterator it = params.find(Params::next_header);
if (it != params.cend()) {
btp_type = it->second;
} else {
btp_type = _params[Params::btp_type];
}
if (btp_type.compare("btpA") == 0) {
header.btpAHeader() = LibItsBtp__TypesAndValues::BtpAHeader(
std::stoi(_params[Params::btp_destination_port]),
std::stoi(_params[Params::btp_info])
......@@ -60,11 +67,13 @@ void BTPLayer::sendData(OCTETSTRING& data, Params& params) {
data
);
loggers::get_instance().log_msg("BTPLayer::sendData: ", p);
// Encode BTP PDU
OCTETSTRING os;
_codec.encode(p, os);
data = os;
}
sendToAllLayers(data, params);
}
......
......@@ -12,14 +12,16 @@ CAMLayer::CAMLayer(const std::string & p_type, const std::string & param) : TLay
void CAMLayer::sendMsg(const LibItsCam__TestSystem::CamReq& p, Params& params){
loggers::get_instance().log_msg(">>> CAMLayer::sendMsg: ", p);
params.log();
// Encode CAM PDU
OCTETSTRING data;
if (_codec.encode(p.msgOut(), data) == -1) {
loggers::get_instance().warning("CAMLayer::sendMsg: Encodeing failure");
return;
}
sendData(data, params);
sendData(data, _params);
}
void CAMLayer::sendData(OCTETSTRING& data, Params& params) {
......
......@@ -9,7 +9,7 @@ int DENMCodec::encode (const DENM__PDU__Descriptions::DENM& p_denm, OCTETSTRING&
BITSTRING b;
int rc = asnCodec.encode(p_denm, b);
if(rc > 0){
if(rc){
p_data = bit2oct(b);
}
loggers::get_instance().log("<<< DENMCodec::encode: %d", rc);
......@@ -18,11 +18,11 @@ int DENMCodec::encode (const DENM__PDU__Descriptions::DENM& p_denm, OCTETSTRING&
int DENMCodec::decode (const OCTETSTRING& p_data, DENM__PDU__Descriptions::DENM& p_denm, Params* params)
{
loggers::get_instance().log(">>> DENMCodec::decode");
loggers::get_instance().log_msg(">>> DENMCodec::decode:", p_data);
int rc = asnCodec.decode(oct2bit(p_data), p_denm);
loggers::get_instance().log("DENMCodec::decode: ASN.1 codec returned %d", rc);
if(rc > 0) {
if(rc) {
loggers::get_instance().log_msg("DENMCodec::decode: ", p_denm);
}
return rc;
......
......@@ -37,9 +37,10 @@ namespace LibItsGeoNetworking__TypesAndValues {
class GeoNetworkingLayer : public TLayer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort> {
Params _params;
GeoNetworkingCodec _codec;
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _beacon; /*!< Data structure used for beaconing */
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet */
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _ls_reply; /*!< Data structure used to reply to an incoming LS_REQUEST */
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _beacon; /*!< Data structure used for beaconing */
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _gbc_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a Geobroadcast*/
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _shb_packet; /*!< Data structure used to encapsulate upper layer PDU into a GeoNetworking packet as a SHB */
LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu* _ls_reply; /*!< Data structure used to reply to an incoming LS_REQUEST */
LocationTable _location_table;
LocationTable _pass_beacon_table;
bool _device_mode;
......@@ -50,6 +51,7 @@ class GeoNetworkingLayer : public TLayer<LibItsGeoNetworking__TestSystem::GeoNet
long long _freq_nanosecs;
sigset_t _mask;
struct sigaction _sa;
unsigned int _sequence_number;
/*!
* \brief Initialize a beacon object for a stand alone beaconing
......@@ -66,7 +68,15 @@ class GeoNetworkingLayer : public TLayer<LibItsGeoNetworking__TestSystem::GeoNet
* \param[in] p_longitude
* \param[in] p_address
*/
void fill_packet(const INTEGER& p_latitude, const INTEGER& p_longitude, const OCTETSTRING& p_ll_address, const INTEGER& p_geoAreaPosLatitude, const INTEGER& p_geoAreaPosLongitude, const INTEGER& p_distanceA, const INTEGER& p_distanceB, const INTEGER& p_angle = 0);
void fill_gbc_packet(const INTEGER& p_latitude, const INTEGER& p_longitude, const OCTETSTRING& p_ll_address, const INTEGER& p_geoAreaPosLatitude, const INTEGER& p_geoAreaPosLongitude, const INTEGER& p_distanceA, const INTEGER& p_distanceB, const INTEGER& p_angle = 0);
/*!
* \brief Initialize a GeoNetworking packet to send GeoNetworking Facility messages
* This object shall be updated before to be sent
* \param[in] p_latitude
* \param[in] p_longitude
* \param[in] p_address
*/
void fill_shb_packet(const INTEGER& p_latitude, const INTEGER& p_longitude, const OCTETSTRING& p_ll_address);
/*!
* \brief Initialize an LS_REPLY GeoNetworking packet to reply to an LS_REQUEST
* This object shall be updated before to be sent
......@@ -81,7 +91,7 @@ class GeoNetworkingLayer : public TLayer<LibItsGeoNetworking__TestSystem::GeoNet
const int _signal_id = SIGTERM;
public:
GeoNetworkingLayer() : TLayer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(), _params(), _codec(), _beacon(NULL), _packet(NULL), _location_table(), _pass_beacon_table(), _device_mode{false}, _sendData(), _timerid{0}, _sev{0}, _its{0}, _freq_nanosecs(0), _mask{0}, _sa{0} { };
GeoNetworkingLayer() : TLayer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(), _params(), _codec(), _beacon(NULL), _gbc_packet(NULL), _shb_packet(nullptr), _ls_reply(nullptr), _location_table(), _pass_beacon_table(), _device_mode{false}, _sendData(), _timerid{0}, _sev{0}, _its{0}, _freq_nanosecs(0), _mask{0}, _sa{0}, _sequence_number{0} { };
GeoNetworkingLayer(const std::string& p_type, const std::string& param);
virtual ~GeoNetworkingLayer();
......@@ -98,6 +108,8 @@ public:
void start_pass_beaconing(const LibItsGeoNetworking__TypesAndValues::BeaconHeader& p_beacon);
void stop_pass_beaconing();
const LibItsGeoNetworking__TypesAndValues::LongPosVector* get_lpv(const LibItsGeoNetworking__TypesAndValues::GN__Address& p_gn_address);
int build_geonetworking_pdu(OCTETSTRING& data, Params& params);
}; // End of class GeoNetworkingLayer
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