Commit 46286882 authored by YannGarcia's avatar YannGarcia
Browse files

Merge MEC developments with ITS/NG112 developments

parent 4688594a
-include config.mk
ifeq (,$(ATS))
$(error ATS shall be defined)
endif
ifeq (,$(TOPDIR))
TOPDIR := .
endif
ifeq (,$(TTCN3_DIR))
$(error TTCN3_DIR shall be defined in config.mk)
endif
first: all
define IncludeModule
undefine sources
undefine modules
undefine includes
include $(1)/module.mk
$$(foreach S, $$(sources), $$(eval all_sources += $(1)/$$(S)))
$$(foreach I, $$(includes), $$(eval all_includes += $(1)/$$(I)))
$$(foreach M, $$(modules), $$(eval $$(call IncludeModule, $$(if $$(filter /%, $$(M)), $$(M), $(1)/$$(M)))))
endef
all_includes := $(TTCN3_DIR)/include $(TTCN3_DIR)/src $(TOPDIR)/ccsrc/Framework
defines += TITAN_RUNTIME_2 _NO_SOFTLINKS_ $(ATS) AS_USE_SSL
libs += $(TTCN3_DIR)/lib/libttcn3-rt2-parallel.a -lstdc++fs
ifeq (Windows_NT,$(OS))
# Silence linker warnings.
LDFLAGS += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc
defines += WIN32
libs += $(patsubst %, -L%/lib, $(OPENSSL_DIR))
all_includes += $(addsuffix /include, $(OPENSSL_DIR))
libs += $(WPCAP_DLL_PATH)
else
defines += LINUX
libs += -lpcap -lrt -lpthread
endif
libs += -lssl -lcrypto -lxml2
$(eval $(call IncludeModule, $(TOPDIR)/ttcn/$(ATS)))
outdir := $(TOPDIR)/build/$(ATS)
bindir := $(TOPDIR)/bin
sources := $(sort $(all_sources))
includes := $(outdir) $(outdir)/.. $(all_includes) $(NPCAP_INCLUDE)
ifeq (Windows_NT,$(OS))
EXE=.exe
endif
ttcn_sources := $(filter %.ttcn , $(sources))
ttcn3_sources := $(filter %.ttcn3, $(sources))
tt_sources := $(ttcn_sources) $(ttcn3_sources)
cc_sources := $(filter %.cc, $(sources))
gen_ttcn_sources := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn, %.cc, $(ttcn_sources))))
gen_ttcn_headers := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn, %.hh, $(ttcn_sources))))
gen_ttcn3_sources := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn3, %.cc, $(ttcn3_sources))))
gen_ttcn3_headers := $(addprefix $(outdir)/, $(notdir $(patsubst %.ttcn3, %.hh, $(ttcn3_sources))))
gen_sources := $(gen_ttcn_sources) $(gen_ttcn3_sources)
gen_headers := $(gen_ttcn_headers) $(gen_ttcn3_headers)
gen_objects := $(patsubst %.cc, %.o, $(gen_sources))
cc_objects := $(patsubst %.cc, $(outdir)/%.o, $(cc_sources))
.PHONY: all FORCE echo
all: $(bindir) $(outdir) $(bindir)/$(ATS)$(EXE)
echo_sources:
@echo -e "$(addsuffix \n,$(all_sources))"
echo: echo_sources
@echo -e "sources:\n $(addsuffix \n, $(sources))"
@echo -e "gen_sources:\n $(addsuffix \n, $(gen_sources))"
@echo -e "gen_objects:\n $(addsuffix \n, $(gen_objects))"
@echo -e "cc_objects:\n $(addsuffix \n, $(cc_objects))"
@echo -e "includes:\n $(addsuffix \n, $(includes))"
@echo -e "defines: $(addsuffix \n, $(defines))"
clean:
rm -f $(outdir)/$(ATS)$(EXE) $(gen_objects) $(gen_sources) $(gen_headers) $(cc_objects) $(outdir)/.generate
regen: force_regen $(outdir)/.generate
force_regen:
rm -f $(outdir)/.generate
$(outdir) $(bindir):
mkdir -p $@
$(bindir)/$(ATS)$(EXE): $(gen_objects) $(cc_objects)
g++ -g -O0 -o $@ $(LDFLAGS) $(gen_objects) $(cc_objects) $(libs)
$(gen_objects) :%.o :%.cc
g++ -g -O0 -c $(addprefix -D, $(defines)) $(addprefix -I, $(includes)) -o $@ $<
$(cc_objects) : $(outdir)/%.o : %.cc
mkdir -p $(dir $@)
g++ -g -O0 -c $(addprefix -D, $(defines)) $(addprefix -I, $(includes)) -o $@ $<
#$(gen_sources):
# $(TTCN3_DIR)/bin/compiler -n -e -L -R -U none -o $(outdir) $(tt_sources)
$(gen_sources): $(outdir)/.generate
$(outdir)/.generate: Makefile $(tt_sources)
$(TTCN3_DIR)/bin/compiler -b -d -e -f -g -l -L -M -n -O -r -R -U none -x -X -o $(outdir) $(tt_sources)
touch $@
$(foreach S, $(ttcn_sources), $(eval $(outdir)/$(notdir $(patsubst %.ttcn, %.cc, $(S))): $(S)))
$(foreach S, $(ttcn3_sources), $(eval $(outdir)/$(notdir $(patsubst %.ttcn3, %.cc, $(S))): $(S)))
sources := LibItsHttp_Encdec.cc
sources := LocationAPI
......@@ -11,6 +11,7 @@
#pragma once
#include <vector>
#include <string>
#include <map>
/*!
......@@ -29,11 +30,54 @@ public: //! \publicsection
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& timestamp; //! Packet reception timestamp
static const std::string& station_type;
static const std::string& country;
static const std::string& type_of_address;
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& station_id; //! To indicate to the peer ITS_Container::stationID
static const std::string& device_mode; //! To indicate to the lower layer to act as a standalone device
static const std::string& secured_mode; //! To indicate to the lower layer to apply signature on message exchanges as defined in IEEE 1609.2 & ETSI TS 102 965
static const std::string& encrypted_mode; //! To indicate to the lower layer to apply encryption on message exchanges as defined in IEEE 1609.2 & ETSI TS 102 965
static const std::string& enable_security_checks;//! To indicates if security check failures shall be treated as error or warning
static const std::string& sec_db_path; //! Path to the folder containing certificates
static const std::string& certificate; //! The certificate identifier the Test System shall use. E.g. CERT_TS_A
static const std::string& peer_certificate; //! The peer certificate identifier the Test System shall use for encryption. E.g. CERT_TS_A
static const std::string& hash; //! The digest algorithm the Test System shall use, authorised values are SHA-256 or SHA-384. Default: SHA-256
static const std::string& signature; //! The signature algorithm the Test System shall use, authorised values are NISTP-256, BP-256 and BP-384. Default: NISTP-256
static const std::string& cypher; //! The encryption algorithm the Test System shall use, authorised values are NISTP-256 and BP-256. Default: NISTP-256
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
static const std::string& payload_type; //! Tyoe of payload, value is the ITS Conatainer message identifier or omitted in case of unknown payload
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
static const std::string& interface_id; //! Commsignia antenna selector
static const std::string& server; //! HTTP server address (e.g. www.etsi.org)
static const std::string& port; //! HTTP server port. Default: 80
static const std::string& use_ssl; //! Set to 1 to use SSL to communicate with the HTTP server. Default: false
......@@ -45,10 +89,6 @@ public: //! \publicsection
static const std::string& host; //! HTTP Host value. Default: 127.0.0.1
static const std::string& content_type; //! HTTP Content-type value. Default: application/text
static const std::string& sip_url;
static const std::string& sip_version;
static const std::string& payload; //! UpperLayer Payload parameter name
static const std::string& codecs; //! List of codecs to use for HTTP application layers
/*!
......
sources := src/base_time.cc \
src/codec_stack_builder.cc \
src/converter.cc \
src/layer_factory.cc \
src/params.cc
includes += ./include
......@@ -22,12 +22,53 @@ const std::string& params::mac_src = std::string("mac_src");
const std::string& params::mac_dst = std::string("mac_dst");
const std::string& params::mac_bc = std::string("mac_bc");
const std::string& params::eth_type = std::string("eth_type");
const std::string& params::beaconing = std::string("beaconing");
const std::string& params::timestamp = std::string("timestamp");
const std::string& params::station_type = std::string("station_type");
const std::string& params::country = std::string("country");
const std::string& params::type_of_address = std::string("type_of_address");
const std::string& params::its_aid = std::string("its_aid");
const std::string& params::ssp = std::string("ssp");
const std::string& params::gn_payload = std::string("gn_payload");
const std::string& params::gn_next_header = std::string("gnNextHeader");
const std::string& params::gn_header_type = std::string("gnHeaderType");
const std::string& params::gn_header_sub_type = std::string("gnHeaderSubtype");
const std::string& params::gn_lifetime = std::string("gnLifetime");
const std::string& params::gn_traffic_class = std::string("gnTrafficClass");
const std::string& params::btp_type = std::string("btp_type");
const std::string& params::btp_payload = std::string("btp_payload");
const std::string& params::btp_destination_port = std::string("dst_port");
const std::string& params::btp_info = std::string("btp_info");
const std::string& params::nic = std::string("nic");
const std::string& params::latitude = std::string("latitude");
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::station_id = std::string("station_id");
const std::string& params::device_mode = std::string("device_mode");
const std::string& params::secured_mode = std::string("secured_mode");
const std::string& params::encrypted_mode = std::string("encrypted_mode");
const std::string& params::enable_security_checks = std::string("enable_security_checks");
const std::string& params::certificate = std::string("certificate");
const std::string& params::peer_certificate = std::string("peer_certificate");
const std::string& params::sec_db_path = std::string("sec_db_path");
const std::string& params::hash = std::string("hash");
const std::string& params::signature = std::string("signature");
const std::string& params::cypher = std::string("cypher");
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::payload_type = std::string("payload_type");
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");
const std::string& params::interface_id = std::string("interface_id");
const std::string& params::server = std::string("server");
const std::string& params::port = std::string("port");
......@@ -40,9 +81,9 @@ const std::string& params::uri = std::string("uri");
const std::string& params::host = std::string("host");
const std::string& params::content_type = std::string("content_type");
const std::string& params::sip_url = std::string("sip_url");
const std::string& params::sip_version = std::string("sip_version");
const std::string& params::payload = std::string("payload");
//const std::string& params::sip_url = std::string("sip_url");
//const std::string& params::sip_version = std::string("sip_version");
//const std::string& params::payload = std::string("payload");
const std::string& params::codecs = std::string("codecs");
......
sources := HttpPort.cc
includes := .
sources := ethernet_layer.cc
includes := .
sources := http_codec.cc http_layer.cc
includes := .
sources := json_codec.cc
includes := .
sources := pcap_cygwin_layer.cc pcap_layer.cc pcap_linux_layer.cc pcap_offline_layer.cc
includes := .
......@@ -76,7 +76,7 @@ pcap_layer::pcap_layer(const std::string& p_type, const std::string& param) :
loggers::get_instance().log("pcap_layer::pcap_layer: Device %s Network address: %d", nic.c_str(), net);
// Open the device
_device = pcap_open_live(nic.c_str(), 65536, 1, 200, error_buffer);
_device = pcap_open_live(nic.c_str(), 65536/*64*1024*/, 1, 100, error_buffer);
if (_device == NULL) {
loggers::get_instance().error("pcap_layer::pcap_layer: Failed to open device %s", nic.c_str());
return;
......@@ -192,7 +192,7 @@ void* pcap_layer::thread() {
const u_char *pkt_data;
unsigned char pkt_count = 0;
loggers::get_instance().log(">>> pcap_layer::run");
// loggers::get_instance().log(">>> pcap_layer::run");
_running = TRUE;
......@@ -206,7 +206,7 @@ void* pcap_layer::thread() {
continue;
}
if(result < 0){
loggers::get_instance().log("<<< pcap_layer::run: error %s", pcap_geterr(_device));
// loggers::get_instance().log("<<< pcap_layer::run: error %s", pcap_geterr(_device));
break;
}
......@@ -219,17 +219,17 @@ void* pcap_layer::thread() {
std::time_t t = pkt_header->ts.tv_sec;
std::tm * pt = std::localtime( &t );
t = std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", pt);
std::sprintf(buf+t, ".%06ld", pkt_header->ts.tv_usec);
_o_params["timestamp"] = std::string(buf);
std::sprintf(buf+t, "%ld", pkt_header->ts.tv_sec * 1000 + static_cast<int>(pkt_header->ts.tv_usec / 1000)); // Use milliseconds
_o_params[params::timestamp] = std::string(buf);
}
#else
_o_params["timestamp"] = std::to_string(pkt_header->ts.tv_usec);
_o_params[params::timestamp] = std::to_string(pkt_header->ts.tv_sec * 1000 + static_cast<int>(pkt_header->ts.tv_usec / 1000)); // Use milliseconds
#endif
_o_data = OCTETSTRING(pkt_header->len, pkt_data);
write(_fd[1], &pkt_count, 1);pkt_count++;
}
_running = FALSE;
loggers::get_instance().log("<<< pcap_layer::run");
// loggers::get_instance().log("<<< pcap_layer::run");
return NULL;
}
......
......@@ -244,10 +244,10 @@ void pcap_layer::Handle_Fd_Event_Readable(int fd) {
int result = pcap_next_ex(_device, (struct pcap_pkthdr**)&pkt_header, &pkt_data);
if (result == 1) { // Succeed
if (pkt_header->caplen > 14) { // Reject too small packet
//loggers::get_instance().log("pcap_layer::Handle_Fd_Event_Readable: %.6d - %d", pkt_header->ts.tv_usec, pkt_header->len);
//loggers::get_instance().log("pcap_layer::Handle_Fd_Event_Readable: %ld - % ld - %d", pkt_header->ts.tv_sec, pkt_header->ts.tv_usec, pkt_header->len);
// Fill parameters from PCAP layer
params params;
params.insert(std::pair<std::string, std::string>(std::string("timestamp"), std::to_string(pkt_header->ts.tv_usec)));
params.insert(std::pair<std::string, std::string>(params::timestamp, std::to_string(pkt_header->ts.tv_sec * 1000 + static_cast<int>(pkt_header->ts.tv_usec / 1000)))); // Use milliseconds
// Process the packet at this layer
OCTETSTRING os(pkt_header->caplen, pkt_data);
//loggers::get_instance().log_to_hexa("pcap_layer::Handle_Fd_Event_Readable: ", os);
......
......@@ -59,12 +59,12 @@ pcap_layer::pcap_layer(const std::string& p_type, const std::string& param)
bpf_u_int32 net, mask; // ip address and subnet mask
if (pcap_lookupnet(nic.c_str(), &net, &mask, error_buffer) != 0) {
loggers::get_instance().error("pcap_layer::pcap_layer: Failed to fetch newtork address for device %s", nic.c_str());
}else{
} else {
loggers::get_instance().log("pcap_layer::pcap_layer: Device %s Network address: %d", nic.c_str(), net);
}
}
// Open the device
_device = pcap_open_live(nic.c_str(), 65536, 1, 100, error_buffer); // TODO Replace hard coded values by pcap_layer::<constants>
// Open the device in promiscuous mode
_device = pcap_open_live(nic.c_str(), 65536/*64*1024*/, 1, 100, error_buffer); // TODO Replace hard coded values by pcap_layer::<constants>
if (_device == NULL) {
loggers::get_instance().error("pcap_layer::pcap_layer: Failed to open device %s", nic.c_str());
return;
......@@ -73,7 +73,7 @@ pcap_layer::pcap_layer(const std::string& p_type, const std::string& param)
if (pcap_setnonblock(_device, 1, error_buffer) != 0) {
loggers::get_instance().error("pcap_layer::pcap_layer: Failed to set blocking mode: %s", error_buffer);
}
// Retrieve the device file handler
// Retrieve the device file handler
_pcap_h = pcap_get_selectable_fd(_device);
if (_pcap_h == -1) {
loggers::get_instance().error("pcap_layer::pcap_layer: Failed to get device handler");
......@@ -85,14 +85,14 @@ pcap_layer::pcap_layer(const std::string& p_type, const std::string& param)
it = _params.find(params::mac_src);
if (it != _params.end()) { // Use online capture
mac_src = it->second;
} else{
// detect MAC address of NIC
} else {
// Detect MAC address of NIC
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
nic.copy(ifr.ifr_name, sizeof(ifr.ifr_name));
if (ioctl(_pcap_h, SIOCGIFHWADDR, &ifr) == -1) {
loggers::get_instance().error("pcap_layer::pcap_layer: Failed to get device MAC address");
}else{
} else {
char buf[13];
*_bin2hex(buf, sizeof(buf), ifr.ifr_hwaddr.sa_data, 6) = 0;
mac_src = buf;
......@@ -178,10 +178,10 @@ void pcap_layer::Handle_Fd_Event_Readable(int fd) {
int result = pcap_next_ex(_device, &pkt_header, &pkt_data);
if (result == 1) { // Succeed
if (pkt_header->caplen > 14) { // Reject too small packet
//loggers::get_instance().log("pcap_layer::Handle_Fd_Event_Readable: %.6d - %d", pkt_header->ts.tv_usec, pkt_header->len);
loggers::get_instance().log("pcap_layer::Handle_Fd_Event_Readable: %ld - %ld - %ld - %d", pkt_header->ts.tv_sec, pkt_header->ts.tv_usec, pkt_header->ts.tv_sec * 1000 + static_cast<unsigned int>(pkt_header->ts.tv_usec / 1000), pkt_header->len);
// Fill parameters from PCAP layer
params params;
params.insert(std::pair<std::string, std::string>(std::string("timestamp"), std::to_string(pkt_header->ts.tv_usec)));
params.insert(std::pair<std::string, std::string>(params::timestamp, std::to_string(pkt_header->ts.tv_sec * 1000 + static_cast<unsigned int>(pkt_header->ts.tv_usec / 1000)))); // Use milliseconds
// Process the packet at this layer
OCTETSTRING os(pkt_header->caplen, pkt_data);
//loggers::get_instance().log_to_hexa("pcap_layer::Handle_Fd_Event_Readable: ", os);
......
......@@ -139,7 +139,7 @@ void* pcap_offline_layer::thread() {
const u_char *pkt_data;
unsigned char pkt_count = 0;
loggers::get_instance().log(">>> pcap_offline_layer::run");
// loggers::get_instance().log(">>> pcap_offline_layer::run");
memset(&lh, 0, sizeof(lh));
......@@ -197,7 +197,7 @@ void* pcap_offline_layer::thread() {
write(_fd[1], &pkt_count, 1);pkt_count++;
}
loggers::get_instance().log("<<< pcap_offline_layer::run");
// loggers::get_instance().log("<<< pcap_offline_layer::run");
return NULL;
}
......
sources := tcp_layer.cc
includes := .
......@@ -6,8 +6,6 @@
#include "tcp_layer_factory.hh"
#include "converter.hh"
#include "loggers.hh"
tcp_layer::tcp_layer(const std::string & p_type, const std::string & param) : layer(p_type), SSL_Socket(), PORT(p_type.c_str()), _params(), _client_id{-1}, _time_key("tcp_layer::Handle_Fd_Event_Readable"), _reconnect_on_send{false} {
......@@ -26,7 +24,7 @@ tcp_layer::tcp_layer(const std::string & p_type, const std::string & param) : la
bool server_mode = false;
it = _params.find(params::server_mode);
if (it != _params.cend()) {
server_mode = (1 == converter::get_instance().string_to_int(it->second));
server_mode = (1 == std::stoi(it->second));
}
it = _params.find(params::server);
if (it == _params.cend()) {
......@@ -77,10 +75,10 @@ tcp_layer::tcp_layer(const std::string & p_type, const std::string & param) : la
map_user();
if (!_reconnect_on_send && !server_mode) {
open_client_connection(_params[params::server].c_str(), _params[params::port].c_str(), NULL, NULL);
if (!_reconnect_on_send) {
open_client_connection(_params[params::server].c_str(), _params[params::port].c_str(), NULL, NULL);
}
}
}
tcp_layer::~tcp_layer() {
loggers::get_instance().log(">>> tcp_layer::~tcp_layer: %d", _client_id);
......
sources := LibMec_ExternalFunctions.cc
Supports Markdown
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