Commit 94e1ccc3 authored by Yann Garcia's avatar Yann Garcia
Browse files

Review date/time

parent d51a1e64
......@@ -2,6 +2,7 @@
#include <math.h>
#include "base_time.hh"
#include "loggers.hh"
#ifndef M_PI
#define M_PI 3.14159265358979323846
......@@ -14,13 +15,14 @@ namespace LibItsCommon__Functions
/**
* @desc This external function gets the current time
* @return Timestamp - current time since 01/01/2014 in milliseconds
* @return Timestamp - current time since 01/01/2004 in milliseconds
* @see fx_getCurrentTime() return TimestampIts
*/
INTEGER fx__getCurrentTime(
) {
INTEGER i;
i.set_long_long_val(base_time::get_instance().get_its_current_time());
i.set_long_long_val(base_time::get_instance().get_its_current_time_ms());
loggers::get_instance().log_msg("<<< fx__getCurrentTime: ", i);
return i;
}
/**
......@@ -31,7 +33,8 @@ namespace LibItsCommon__Functions
INTEGER fx__getCurrentTimeUtc(
) {
INTEGER i;
i.set_long_long_val(base_time::get_instance().get_current_time());
i.set_long_long_val(base_time::get_instance().get_current_time_ms());
loggers::get_instance().log_msg("<<< fx__getCurrentTimeUtc: ", i);
return i;
}
/**
......
......@@ -17,7 +17,7 @@
* \brief This class provides time tools such as getting current time
*/
class base_time {
const unsigned long long its_base_time = 1072915200000L; //! Base time 01/01/2004 12:00am in millseconds
const unsigned long long its_base_time_ms = 1072915200000L; //! Base time 01/01/2004 12:00am in millseconds
static base_time* _instance;
private:
......@@ -28,9 +28,11 @@ public:
virtual ~base_time() { if (_instance != nullptr) delete _instance; };
public:
inline const unsigned long long get_current_time() const;
inline const unsigned long long get_its_base_time() const;
inline const unsigned long long get_its_current_time() const;
inline const unsigned long long get_current_time_ms() const;
inline const unsigned long long get_its_base_time_ms() const;
inline const unsigned long long get_its_current_time_ms() const;
inline const unsigned long long get_its_current_time_us() const;
inline const unsigned long long get_its_current_time_mod_ms() const;
}; // End of class base_time
// static functions
......@@ -38,14 +40,23 @@ base_time& base_time::get_instance() {
return (_instance != nullptr) ? *_instance : *(_instance = new base_time());
}
const unsigned long long base_time::get_current_time() const {
const unsigned long long base_time::get_current_time_ms() const {
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
const unsigned long long base_time::get_its_base_time() const {
return base_time::its_base_time;
const unsigned long long base_time::get_its_base_time_ms() const {
return base_time::its_base_time_ms;
}
const unsigned long long base_time::get_its_current_time() const {
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time;
const unsigned long long base_time::get_its_current_time_ms() const {
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms;
}
const unsigned long long base_time::get_its_current_time_us() const {
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms * 1000;
}
const unsigned long long base_time::get_its_current_time_mod_ms() const {
return (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - base_time::its_base_time_ms) % 65536;
}
......@@ -114,13 +114,13 @@ public:
* \param[in] p_value The string value
* \return The hexadecimal value
*/
std::string string_to_hexa(const std::string & p_value);
std::string string_to_hexa(const std::string & p_value, const bool p_uppercase = false);
/*!
* \brief Convert a bytes array int32_t an hexadecimal string
* \param[in] p_value The bytes array value
* \return The hexadecimal value
*/
std::string bytes_to_hexa(const std::vector<uint8_t> & p_value);
std::string bytes_to_hexa(const std::vector<uint8_t> & p_value, const bool p_uppercase = false);
/*!
* \brief Convert an hexadecimal string into a bytes array
* \param[in] p_value The hexadecimal value
......@@ -328,8 +328,24 @@ public:
return ss.str();
}; // End of string_to_bytes
/*!
* \brief Convert a string in to lower case
* \param[in/out] p_value The string value to convert
*/
inline void to_lower(std::string& p_value) {
std::transform(p_value.begin(), p_value.end(), p_value.begin(), ::tolower);
}
/*!
* \brief Convert a string in to upper case
* \param[in/out] p_value The string value to convert
*/
inline void to_upper(std::string& p_value) {
std::transform(p_value.begin(), p_value.end(), p_value.begin(), ::toupper);
}
public:
/*!
* \brief Returns a copy of the string, with leading and trailing special characters omitted
* \param[in] p_value The string value
......@@ -369,5 +385,22 @@ public:
*/
std::vector<std::string> split_arguments_line(const std::string & p_value);
static const std::string lut;
/*!
* \brief Convert the provided buffer into a Base64
* \param[in] p_value The buffer value
* \return The Base64 encoded buffert
*/
std::vector<unsigned char> buffer_to_base64(const std::vector<unsigned char> & p_value);
/*!
* \brief Convert the provided Base64 buffer
* \param[in] p_value The buffer value
* \return The Base64 encoded buffert
*/
std::vector<unsigned char> base64_to_buffer(const std::vector<unsigned char> & p_value);
static const std::string lut_u;
static const std::string lut_l;
static const std::string base64_enc_map;
}; // End of class converter
......@@ -12,8 +12,9 @@ uint32_t converter::swap(const uint32_t p_value) {
return (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
}
const std::string converter::lut = "0123456789ABCDEF";
std::string converter::string_to_hexa(const std::string & p_value) {
const std::string converter::lut_u = "0123456789ABCDEF";
const std::string converter::lut_l = "0123456789abcdef";
std::string converter::string_to_hexa(const std::string & p_value, const bool p_uppercase) {
std::string input(p_value);
std::for_each(
......@@ -27,30 +28,49 @@ std::string converter::string_to_hexa(const std::string & p_value) {
std::string output;
uint32_t length = p_value.length();
output.reserve(2 * length);
for (uint32_t i = 0; i < length; ++i) {
const uint8_t c = input[i];
output.push_back(lut[c >> 4]);
output.push_back(lut[c & 15]);
} // End of 'for' statement
if (p_uppercase) { // TODO Use pointer to reduce code size
for (uint32_t i = 0; i < length; ++i) {
const uint8_t c = input[i];
output.push_back(lut_u[c >> 4]);
output.push_back(lut_u[c & 15]);
} // End of 'for' statement
} else {
for (uint32_t i = 0; i < length; ++i) {
const uint8_t c = input[i];
output.push_back(lut_l[c >> 4]);
output.push_back(lut_l[c & 15]);
} // End of 'for' statement
}
return output;
}
std::string converter::bytes_to_hexa(const std::vector<uint8_t> & p_value) {
std::string converter::bytes_to_hexa(const std::vector<uint8_t> & p_value, const bool p_uppercase) {
std::string ret;
ret.assign(p_value.size()*2, ' ');
for(size_t i=0; i<p_value.size(); i++){
uint8_t c = p_value[i];
ret[i*2] = lut[c>>4];
ret[i*2+1] = lut[c&0xF];
if (p_uppercase) { // TODO Use pointer to reduce code size
for(size_t i=0; i<p_value.size(); i++){
uint8_t c = p_value[i];
ret[i*2] = lut_u[c>>4];
ret[i*2+1] = lut_u[c&0xF];
}
} else {
for(size_t i=0; i<p_value.size(); i++){
uint8_t c = p_value[i];
ret[i*2] = lut_l[c>>4];
ret[i*2+1] = lut_l[c&0xF];
}
}
return ret;
}
inline uint8_t char2byte(const char ch) {
size_t s = converter::lut.find(ch);
if(s == std::string::npos)
throw (std::length_error(""));
inline uint8_t char2byte(const char p_ch) {
size_t s = converter::lut_l.find(p_ch);
if(s == std::string::npos) {
if ((s = converter::lut_u.find(p_ch)) == std::string::npos) {
throw (std::length_error(""));
}
}
return s;
}
......@@ -133,3 +153,50 @@ std::vector<std::string> converter::split_arguments_line(const std::string & p_v
} // else, invalid command line
return output;
}
const std::string converter::base64_enc_map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
std::vector<unsigned char> converter::buffer_to_base64(const std::vector<unsigned char> & p_value) {
std::vector<unsigned char> out;
int val = 0, valb = -6;
for (unsigned char c : p_value) {
val = (val << 8) + c;
valb += 8;
while (valb >= 0) {
out.push_back(converter::base64_enc_map[(val >> valb) & 0x3F]);
valb -= 6;
} // End of 'while' statement
} // End of 'for' statement
if (valb > -6) {
out.push_back(converter::base64_enc_map[((val << 8) >> (valb + 8)) & 0x3F]);
}
while (out.size() % 4) {
out.push_back('=');
} // End of 'while' statement
return out;
}
std::vector<unsigned char> converter::base64_to_buffer(const std::vector<unsigned char> &p_value) {
std::vector<unsigned char> out;
std::vector<int> T(256, -1);
for (int i = 0; i < 64; i++) {
T[converter::base64_enc_map[i]] = i;
}
int val = 0, valb = -8;
for (unsigned char c : p_value) {
if (T[c] == -1) {
break;
}
val = (val << 6) + T[c];
valb += 6;
if (valb >= 0) {
out.push_back((unsigned char)char((val >> valb) & 0xFF));
valb -= 8;
}
} // End of 'for' statement
return out;
}
......@@ -288,7 +288,7 @@ void geonetworking_layer::receive_data(OCTETSTRING& data, params& params) {
eh->lsReplyHeader().dstPosVector().latitude() = sopv->latitude();
eh->lsReplyHeader().dstPosVector().longitude() = sopv->longitude();
// Update timestamp
eh->lsReplyHeader().srcPosVector().timestamp__().set_long_long_val(base_time::get_instance().get_its_current_time());
eh->lsReplyHeader().srcPosVector().timestamp__().set_long_long_val(base_time::get_instance().get_its_current_time_mod_ms());
eh->lsReplyHeader().dstPosVector().timestamp__() = eh->lsReplyHeader().srcPosVector().timestamp__();
loggers::get_instance().log_msg("geonetworking_layer::receive_data: ", *_ls_reply);
......@@ -486,7 +486,7 @@ void geonetworking_layer::send_beacon() {
loggers::get_instance().error("geonetworking_layer::send_beacon: Wrong cast");
}
// Update timestamp
eh->beaconHeader().srcPosVector().timestamp__().set_long_long_val((unsigned int)base_time::get_instance().get_its_current_time());
eh->beaconHeader().srcPosVector().timestamp__().set_long_long_val((unsigned int)base_time::get_instance().get_its_current_time_mod_ms());
//loggers::get_instance().log_msg("geonetworking_layer::send_beacon: ", *_beacon);
// Encode message using TITAN because of payload in omited
TTCN_Buffer encoding_buffer;
......@@ -943,7 +943,7 @@ int geonetworking_layer::build_geonetworking_pdu(OCTETSTRING& data, params& para
_shb_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof();
_shb_packet->gnPacket().packet().payload() = OPTIONAL<OCTETSTRING>(data);
// Update timestamp
eh->shbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(base_time::get_instance().get_its_current_time()));
eh->shbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(base_time::get_instance().get_its_current_time_mod_ms()));
loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: shb: ", *_shb_packet);
// Encode GeoNetworking PDU
......@@ -969,7 +969,7 @@ int geonetworking_layer::build_geonetworking_pdu(OCTETSTRING& data, params& para
_tsb_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof();
_tsb_packet->gnPacket().packet().payload() = OPTIONAL<OCTETSTRING>(data);
// Update timestamp
eh->tsbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(base_time::get_instance().get_its_current_time()));
eh->tsbHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(base_time::get_instance().get_its_current_time_mod_ms()));
loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: tsb: ", *_tsb_packet);
// Encode GeoNetworking PDU
......@@ -997,7 +997,7 @@ int geonetworking_layer::build_geonetworking_pdu(OCTETSTRING& data, params& para
_gbc_packet->gnPacket().packet().commonHeader().plLength() = data.lengthof();
_gbc_packet->gnPacket().packet().payload() = OPTIONAL<OCTETSTRING>(data);
// Update timestamp
eh->geoBroadcastHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(base_time::get_instance().get_its_current_time()));
eh->geoBroadcastHeader().srcPosVector().timestamp__().set_long_long_val(static_cast<unsigned int>(base_time::get_instance().get_its_current_time_mod_ms()));
loggers::get_instance().log_msg("geonetworking_layer::build_geonetworking_pdu: gbc: ", *_gbc_packet);
......
......@@ -159,7 +159,7 @@ int security_services::process_ieee_1609_dot2_signed_data(const IEEE1609dot2::Si
const OPTIONAL<INTEGER>& v = dynamic_cast<const OPTIONAL<INTEGER>& >(header_info.generationTime()); // in millisecond
unsigned long long gt = ((INTEGER&)(*v.get_opt_value())).get_long_long_val();
// Get current time timestamp
unsigned long long ms = base_time::get_instance().get_current_time(); // in millisecond
unsigned long long ms = base_time::get_instance().get_its_current_time_us(); // in millisecond
loggers::get_instance().log("security_services::process_ieee_1609_dot2_signed_data: generation time check %ld / %ld", header_info.generationTime(), ms);
if (abs((double)gt - (double)ms) >= 5.0) { // TODO Use a params for generation_time_epsilon
loggers::get_instance().warning("security_services::process_ieee_1609_dot2_signed_data: Invalid generation time, discard it");
......@@ -486,7 +486,7 @@ int security_services::sign_payload(const OCTETSTRING& p_unsecured_gn_payload, O
loggers::get_instance().log("security_services::sign_payload: Payload type not set");
// Noting to do
}
unsigned long long ms = base_time::get_instance().get_its_current_time();
unsigned long long ms = base_time::get_instance().get_its_current_time_us();
INTEGER i;
i.set_long_long_val((unsigned int)ms);
header_info.generationTime() = OPTIONAL<INTEGER>(i);
......
......@@ -23,20 +23,20 @@ ItsRSUsSimulator_Pixits.PX_RSU_ID := 8;
# UC7 (CAM only): PX_ETSI_USE_CASE_ID := 7
# UC8 (EVCSN only): PX_ETSI_USE_CASE_ID := 8
# UC9 (CAM only): PX_ETSI_USE_CASE_ID := 9
ItsRSUsSimulator_Pixits.PX_ETSI_USE_CASE_ID := 1
ItsRSUsSimulator_Pixits.PX_ETSI_USE_CASE_ID := 6
# Indicate which zone to simulate
ItsRSUsSimulator_Pixits.PX_ETSI_ZONE_ID := 1
ItsRSUsSimulator_Pics.PICS_GENERATE_BEACON := false
ItsRSUsSimulator_Pics.PICS_GENERATE_CAM := false
ItsRSUsSimulator_Pics.PICS_GENERATE_DENM := true
ItsRSUsSimulator_Pics.PICS_GENERATE_CAM := true
ItsRSUsSimulator_Pics.PICS_GENERATE_DENM := false
ItsRSUsSimulator_Pics.PICS_GENERATE_IVIM := false
ItsRSUsSimulator_Pics.PICS_GENERATE_MAPEM := false
ItsRSUsSimulator_Pics.PICS_GENERATE_SPATEM := false
ItsRSUsSimulator_Pics.PICS_GENERATE_SSEM := false
ItsRSUsSimulator_Pics.PICS_BEACON_FREQUENCY := 1.0
ItsRSUsSimulator_Pics.PICS_CAM_FREQUENCY := 0.25
ItsRSUsSimulator_Pics.PICS_CAM_FREQUENCY := 0.75
ItsRSUsSimulator_Pics.PICS_DENM_FREQUENCY := 0.25
ItsRSUsSimulator_Pics.PICS_SEND_CAM_INDICATION := false
......@@ -125,7 +125,7 @@ LogEventTypes:= Yes
# Single GeoNetworking component port
# its_aid=36: CAM
# its_aid=37: DENM
system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=43551050,longitude=10298730,its_aid=37,secured_mode=1,encrypted_mode=0,certificate=CERT_IUT_A_AT,peer_certificate=CERT_TS_A_AT,sec_db_path=/home/vagrant/tmp/asn1c_cert)/ETH(mac_src=080027500f9b)/PCAP(mac_src=080027500f9b,nic=eth1,filter=and ether proto 0x8947)"
system.geoNetworkingPort.params := "GN(ll_address=4C5E0C14D2EB,latitude=43551050,longitude=10298730,its_aid=36,secured_mode=1,encrypted_mode=0,certificate=CERT_IUT_A_AT,peer_certificate=CERT_TS_A_AT,sec_db_path=/home/vagrant/tmp/asn1c_cert)/ETH(mac_src=080027500f9b)/PCAP(mac_src=080027500f9b,nic=eth1,filter=and ether proto 0x8947)"
# Config port based on UDP
system.cfPort.params := "CF(ut=cam)/UDP(dst_ip=192.168.0.4)"
......
Subproject commit c7d7b24f14bed9f6088cc9df85d9f45327f4db96
Subproject commit 1451dd87f9c492f4afcb9def9ec05a000e7b3f5a
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