it2s-tender dbms logging update

This commit is contained in:
emanuel 2022-03-09 09:50:46 +00:00
parent 931cef50d0
commit 7ed58a1ac7
6 changed files with 69 additions and 36 deletions

View File

@ -754,10 +754,6 @@ void *ca_service(void *fc) {
memcpy(fmi->data.buf, bpr->data.buf, bpr->data.size); memcpy(fmi->data.buf, bpr->data.buf, bpr->data.size);
fmi->data.size = bpr->data.size; fmi->data.size = bpr->data.size;
if (facilities->logging.dbms) {
it2s_tender_db_add(facilities->logging.dbms, &facilities->epv, true, ItsPduHeader__messageID_cam, bpr->data.buf, bpr->data.size);
}
// Check if inside PZ // Check if inside PZ
bpr->gn.communicationProfile = 0; bpr->gn.communicationProfile = 0;
if (facilities->station_type != 15 && check_pz(facilities->lightship, &facilities->epv)) bpr->gn.communicationProfile = 1; if (facilities->station_type != 15 && check_pz(facilities->lightship, &facilities->epv)) bpr->gn.communicationProfile = 1;
@ -784,6 +780,14 @@ void *ca_service(void *fc) {
lightship_reset_timer(facilities->lightship, &facilities->epv); lightship_reset_timer(facilities->lightship, &facilities->epv);
// Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, ItsPduHeader__messageID_cam, NULL, bpr->data.buf, bpr->data.size);
}
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];

View File

@ -275,10 +275,6 @@ int facilities_config(void* facilities_s) {
memcpy(facilities->id.ipv6_addr+13, src_mac+3, 3); memcpy(facilities->id.ipv6_addr+13, src_mac+3, 3);
} }
facilities->logging.recorder = config->facilities.logging.management;
if (config->facilities.logging.dbms) {
facilities->logging.dbms = calloc(1, sizeof(it2s_tender_database_s));
}
// DENM // DENM
facilities->den->n_max_events = config->facilities.denm.nmax_active_events; facilities->den->n_max_events = config->facilities.denm.nmax_active_events;
@ -506,6 +502,25 @@ int facilities_config(void* facilities_s) {
facilities->vehicle.width = config->facilities.vehicle.width; facilities->vehicle.width = config->facilities.vehicle.width;
facilities->vehicle.role = config->facilities.vehicle.role; facilities->vehicle.role = config->facilities.vehicle.role;
// Logging
facilities->logging.recorder = config->facilities.logging.management;
if (config->general.logging.enabled && config->facilities.logging.dbms) {
facilities->logging.dbms = calloc(1, sizeof(it2s_tender_database_s));
if (it2s_tender_db_init(
facilities->logging.dbms,
config->general.logging.table_style,
ITSS_FACILITIES,
config->general.logging.host,
config->general.logging.port,
config->general.logging.username,
config->general.logging.password
)) {
syslog_err("[facilities] failed to initialize the database -> turning off logging");
free(facilities->logging.dbms);
facilities->logging.dbms = NULL;
}
}
cleanup: cleanup:
it2s_config_free(config); it2s_config_free(config);

View File

@ -714,10 +714,6 @@ void *cp_service(void *fc){
if(mk_cpm(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size, fmi->data.buf, (uint32_t *) &fmi->data.size, history_list, valid_array, history_timestamp) == 1) if(mk_cpm(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size, fmi->data.buf, (uint32_t *) &fmi->data.size, history_list, valid_array, history_timestamp) == 1)
continue; continue;
if (facilities->logging.dbms) {
it2s_tender_db_add(facilities->logging.dbms, &facilities->epv, true, 14, bpr->data.buf, bpr->data.size);
}
uint64_t id = rand() + 1; uint64_t id = rand() + 1;
bpr->id = id; bpr->id = id;
fmi->id = id; fmi->id = id;
@ -745,6 +741,13 @@ void *cp_service(void *fc){
/*Reset Timer for dissemination control */ /*Reset Timer for dissemination control */
dissemination_reset_timer(facilities->dissemination, &facilities->epv,1); dissemination_reset_timer(facilities->dissemination, &facilities->epv,1);
// Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, 14, NULL, bpr->data.buf, bpr->data.size);
}
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];

View File

@ -74,6 +74,8 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
asn_TYPE_descriptor_t *its_msg_descriptor = NULL; asn_TYPE_descriptor_t *its_msg_descriptor = NULL;
void *its_msg = NULL; void *its_msg = NULL;
int its_msg_type = 0; int its_msg_type = 0;
uint8_t* packet = NULL;
uint16_t packet_len = 0;
switch (tpi->present) { switch (tpi->present) {
case TransportPacketIndication_PR_btp: case TransportPacketIndication_PR_btp:
@ -135,6 +137,9 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
goto cleanup; goto cleanup;
} }
packet = tpi->choice.btp.data.buf;
packet_len = tpi->choice.btp.data.size;
dec = uper_decode_complete(NULL, its_msg_descriptor, (void**) &its_msg, tpi->choice.btp.data.buf, tpi->choice.btp.data.size); dec = uper_decode_complete(NULL, its_msg_descriptor, (void**) &its_msg, tpi->choice.btp.data.buf, tpi->choice.btp.data.size);
if (dec.code) { if (dec.code) {
syslog_debug("[facilities]<- invalid %s received", its_msg_descriptor->name); syslog_debug("[facilities]<- invalid %s received", its_msg_descriptor->name);
@ -142,10 +147,6 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
goto cleanup; goto cleanup;
} }
if (facilities->logging.dbms) {
it2s_tender_db_add(facilities->logging.dbms, &facilities->epv, false, its_msg_type, tpi->choice.btp.data.buf, tpi->choice.btp.data.size);
}
// Get permisisons // Get permisisons
uint8_t* ssp = NULL; uint8_t* ssp = NULL;
uint16_t ssp_len; uint16_t ssp_len;
@ -237,6 +238,8 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
break; break;
case TransportPacketIndication_PR_tcp: case TransportPacketIndication_PR_tcp:
id = tpi->choice.tcp.id; id = tpi->choice.tcp.id;
packet = tpi->choice.tcp.data.buf;
packet_len = tpi->choice.tcp.data.size;
syslog_debug("[facilities]<- TI.packet.tcp | id:%ld size:%dB", id, msg_len); syslog_debug("[facilities]<- TI.packet.tcp | id:%ld size:%dB", id, msg_len);
sreq = calloc(1, sizeof(SecurityRequest_t)); sreq = calloc(1, sizeof(SecurityRequest_t));
@ -339,6 +342,12 @@ static int transport_indication(facilities_t *facilities, void* responder, void*
} }
// Logging // Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, id, &facilities->epv, false, its_msg_type, NULL, packet, packet_len);
}
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
int e = it2s_tender_management_record_packet_sdu( int e = it2s_tender_management_record_packet_sdu(
buf, buf,
@ -759,13 +768,6 @@ int main() {
if (facilities.coordination.active) if (facilities.coordination.active)
pthread_create(&facilities.pc_service, NULL, pc_service, (void*) &facilities); pthread_create(&facilities.pc_service, NULL, pc_service, (void*) &facilities);
if (facilities.logging.dbms) {
if (it2s_tender_db_init(facilities.logging.dbms, "facilities", facilities.id.station_id)) {
syslog_err("[facilities] failed to initialize the database -> turning off logging");
free(facilities.logging.dbms);
facilities.logging.dbms = NULL;
}
}
void* security_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ); void* security_socket = zmq_socket(facilities.zmq.ctx, ZMQ_REQ);
int wait_ms = 1000; int wait_ms = 1000;

View File

@ -322,10 +322,6 @@ void *sa_service(void *fc) {
rv = mk_saem(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size); rv = mk_saem(facilities, bpr->data.buf, (uint32_t *) &bpr->data.size);
if (!rv) { if (!rv) {
if (facilities->logging.dbms) {
it2s_tender_db_add(facilities->logging.dbms, &facilities->epv, true, messageID_saem, bpr->data.buf, bpr->data.size);
}
bpr->id = rand() + 1; bpr->id = rand() + 1;
asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 1023); asn_enc_rval_t enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, tr_oer+1, 1023);
@ -334,6 +330,13 @@ void *sa_service(void *fc) {
continue; continue;
} else { } else {
it2s_tender_queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp"); it2s_tender_queue_send(facilities->tx_queue, tr_oer, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
// Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, messageID_saem, NULL, bpr->data.buf, bpr->data.size);
}
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];

View File

@ -158,10 +158,6 @@ int tpm_pay(void* fc, uint8_t* neighbour) {
bpr->gn.trafficClass = 2; bpr->gn.trafficClass = 2;
bpr->gn.packetTransportType = PacketTransportType_shb; bpr->gn.packetTransportType = PacketTransportType_shb;
if (facilities->logging.dbms) {
it2s_tender_db_add(facilities->logging.dbms, &facilities->epv, true, 117, bpr->data.buf, bpr->data.size);
}
// encode TR // encode TR
buf[0] = 4; buf[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1);
@ -173,6 +169,13 @@ int tpm_pay(void* fc, uint8_t* neighbour) {
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp"); it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
// Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, 117, NULL, bpr->data.buf, bpr->data.size);
}
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];
@ -376,10 +379,6 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, uint8_t* ne
memcpy(bpr->gn.securityNeighbour->buf, neighbour, 8); memcpy(bpr->gn.securityNeighbour->buf, neighbour, 8);
} }
if (facilities->logging.dbms) {
it2s_tender_db_add(facilities->logging.dbms, &facilities->epv, true, 117, bpr->data.buf, bpr->data.size);
}
// encode TR // encode TR
buf[0] = 4; buf[0] = 4;
enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1); enc = oer_encode_to_buffer(&asn_DEF_TransportRequest, NULL, tr, buf+1, buf_len-1);
@ -390,6 +389,13 @@ static void rsu_handle_recv(facilities_t* facilities, TPM_t* tpm_rx, uint8_t* ne
it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp"); it2s_tender_queue_send(facilities->tx_queue, buf, enc.encoded+1, ITSS_TRANSPORT, bpr->id, "TR.packet.btp");
// Logging
if (facilities->logging.dbms) {
pthread_mutex_lock(&facilities->id.lock);
uint64_t station_id = facilities->id.station_id;
pthread_mutex_unlock(&facilities->id.lock);
it2s_tender_db_add(facilities->logging.dbms, station_id, bpr->id, &facilities->epv, true, 117, NULL, bpr->data.buf, bpr->data.size);
}
if (facilities->logging.recorder) { if (facilities->logging.recorder) {
uint16_t buffer_len = 2048; uint16_t buffer_len = 2048;
uint8_t buffer[buffer_len]; uint8_t buffer[buffer_len];