diff --git a/src/saem.c b/src/saem.c index 9dcbcd9..a7e9a6a 100644 --- a/src/saem.c +++ b/src/saem.c @@ -377,7 +377,10 @@ void *sa_service(void *fc) { // Tolling if (facilities->tolling.enabled && bulletin->to_consume[a]->its_aid == 1 && - now > bulletin->to_consume[a]->t_trigger + TOLLING_PAYMENT_MIN_PERIOD_MS && + ( + now > bulletin->to_consume[a]->t_trigger + TOLLING_PAYMENT_MIN_PERIOD_MS || + (facilities->tolling.protocol.p == TOLLING_PROTOCOL_SIMPLE && tpm_should_retransmit(facilities)) + ) && facilities->station_type != 15) { tolling_info_t* info = (tolling_info_t*) bulletin->to_consume[a]->info.internal_p; diff --git a/src/tpm.c b/src/tpm.c index a860e7f..2664c01 100644 --- a/src/tpm.c +++ b/src/tpm.c @@ -38,6 +38,26 @@ int tpm_is_inside_zone(void* fc, tolling_info_t* ti) { return 0; } +int tpm_should_retransmit(void* fc) { + + facilities_t* facilities = (facilities_t*) fc; + tolling_t* tolling = &facilities->tolling; + + uint64_t now = itss_time_get(&facilities->epv); + + if (tolling->station.obu.rt_on) { + if (now > tolling->station.obu.rt_init + TOLLING_RT_TIMEOUT_MS) { + tolling->station.obu.rt_on = false; + return 0; + } + if (now > tolling->station.obu.rt_t_trigger + TOLLING_RT_PERIOD_MS) { + return 1; + } + } + + return 0; +} + int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neighbour, uint8_t* dst_addr) { int rv = 0; @@ -54,9 +74,16 @@ int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neig } pthread_mutex_lock(&facilities->epv.time.lock); - tolling->tz = itss_ts_get(TIME_MICROSECONDS) ; + tolling->tz = itss_ts_get(TIME_MICROSECONDS); pthread_mutex_unlock(&facilities->epv.time.lock); + // Retransmission + if (!tolling->station.obu.rt_on) { + tolling->station.obu.rt_init = itss_time_get(&facilities->epv); + tolling->station.obu.rt_on = true; + } + tolling->station.obu.rt_t_trigger = itss_time_get(&facilities->epv); + TPM_t* tpm = NULL; TransportRequest_t* tr = NULL; SecurityRequest_t* sreq = NULL; @@ -1187,6 +1214,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, pthread_mutex_lock(&facilities->epv.time.lock); syslog_info("[facilities] [tolling] entry.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz); pthread_mutex_unlock(&facilities->epv.time.lock); + tolling->station.obu.rt_on = false; veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr); break; default: @@ -1214,6 +1242,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, pthread_mutex_lock(&facilities->epv.time.lock); syslog_info("[facilities] [tolling] exit.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz); pthread_mutex_unlock(&facilities->epv.time.lock); + tolling->station.obu.rt_on = false; veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr); break; default: @@ -1238,6 +1267,7 @@ int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, pthread_mutex_lock(&facilities->epv.time.lock); syslog_info("[facilities] [tolling] single.reply took %ld us", itss_ts_get(TIME_MICROSECONDS) - tolling->tz); pthread_mutex_unlock(&facilities->epv.time.lock); + tolling->station.obu.rt_on = false; veh_handle_recv(tolling, tpm_rx, security_socket, facilities->tx_queue, &facilities->epv, neighbour, src_addr); break; default: diff --git a/src/tpm.h b/src/tpm.h index 6ff4bab..4554335 100644 --- a/src/tpm.h +++ b/src/tpm.h @@ -10,6 +10,8 @@ #define TOLLING_PAYMENT_MIN_PERIOD_MS 40000 #define TOLLING_MAX_CONNS 64 #define TOLLING_CONN_TIMEOUT_MS 10000 +#define TOLLING_RT_PERIOD_MS 400 +#define TOLLING_RT_TIMEOUT_MS 5000 typedef enum TOLLING_PROTOCOL { TOLLING_PROTOCOL_SIMPLE, @@ -71,6 +73,11 @@ typedef struct tolling { uint64_t client_id; uint64_t tls_conn_id; TPM_t* entry_proof; + + // Retransmission + uint64_t rt_init; + uint64_t rt_t_trigger; + bool rt_on; } obu; } station; @@ -95,6 +102,7 @@ int tolling_init(tolling_t* tolling, void* zmq_ctx, char* security_address, uint int tpm_pay(void* fc, tolling_info_t* info, void* security_socket, uint8_t* neighbour, uint8_t* dst_addr); int tpm_recv(void* fc, TPM_t* tpm_rx, void* security_socket, uint8_t* neighbour, uint8_t* src_addr); +int tpm_should_retransmit(void* fc); int tpm_is_inside_zone(void* fc, tolling_info_t* ti); tolling_info_t* tolling_info_new(itss_epv_t* epv, TollingPaymentInfo_t* tpi);