From f7b8c48882575befa62839b5b3188aee7917e68d Mon Sep 17 00:00:00 2001 From: emanuel Date: Thu, 10 Nov 2022 18:39:17 +0000 Subject: [PATCH] StationID 32 bits, multiple targetted VCM --- src/cam.c | 6 ++--- src/cam.h | 2 +- src/cpm.c | 2 +- src/facilities.c | 4 ++-- src/facilities.h | 2 +- src/infrastructure.h | 2 +- src/saem.c | 2 +- src/saem.h | 2 +- src/tpm.c | 4 ++-- src/tpm.h | 2 +- src/vcm.c | 55 +++++++++++++++++++++++++++++++++++++------- src/vcm.h | 9 +++++++- 12 files changed, 69 insertions(+), 23 deletions(-) diff --git a/src/cam.c b/src/cam.c index ea946d2..ce582bb 100644 --- a/src/cam.c +++ b/src/cam.c @@ -552,7 +552,7 @@ void lightship_reset_timer() { lightship->next_cam_max = now + lightship->vehicle_gen_max; lightship->next_cam_min = now + lightship->vehicle_gen_min; } else { // RSU - if (now > lightship->last_vehicle + lightship->rsu_vehicle_permanence) { + if (now > lightship->t_last_vehicle + lightship->rsu_vehicle_permanence) { lightship->is_vehicle_near = false; } lightship->next_cam_min = now + lightship->rsu_gen_min; @@ -692,7 +692,7 @@ enum CAM_CHECK_R check_cam(BTPPacketIndication_t *bpi, CAM_t* cam, uint8_t* ssp, if (lightship->type == StationType_roadSideUnit) { // Send CAMs if vehicles nearby if (bpi->stationType != StationType_roadSideUnit && bpi->isNeighbour) { - lightship->last_vehicle = now; + lightship->t_last_vehicle = now; lightship->is_vehicle_near = true; } } else { @@ -879,7 +879,7 @@ void* ca_service() { // Logging if (facilities.logging.dbms) { pthread_mutex_lock(&facilities.id.lock); - uint64_t station_id = facilities.id.station_id; + uint32_t station_id = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); itss_db_add(facilities.logging.dbms, station_id, bpr->id, true, messageID_cam, NULL, bpr->data.buf, bpr->data.size); } diff --git a/src/cam.h b/src/cam.h index a55d875..da46fd8 100644 --- a/src/cam.h +++ b/src/cam.h @@ -76,7 +76,7 @@ typedef struct lightship { bool is_vehicle_near; - uint64_t last_vehicle; + uint64_t t_last_vehicle; uint32_t vehicle_gen_min; uint32_t vehicle_gen_max; diff --git a/src/cpm.c b/src/cpm.c index f2a2dd8..c30cbba 100644 --- a/src/cpm.c +++ b/src/cpm.c @@ -747,7 +747,7 @@ void *cp_service(){ // Logging if (facilities.logging.dbms) { pthread_mutex_lock(&facilities.id.lock); - uint64_t station_id = facilities.id.station_id; + uint32_t station_id = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); itss_db_add(facilities.logging.dbms, station_id, bpr->id, true, 14, NULL, bpr->data.buf, bpr->data.size); } diff --git a/src/facilities.c b/src/facilities.c index 88bc39c..de260b7 100644 --- a/src/facilities.c +++ b/src/facilities.c @@ -424,7 +424,7 @@ static int transport_indication(void* responder, void** security_socket, uint8_t // Logging if (facilities.logging.dbms) { pthread_mutex_lock(&facilities.id.lock); - uint64_t station_id = facilities.id.station_id; + uint32_t station_id = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); itss_db_add(facilities.logging.dbms, station_id, id, false, its_msg_type, NULL, packet, packet_len); } @@ -659,7 +659,7 @@ static int networking_indication(void* responder, uint8_t* msg, uint32_t msg_len *ni->choice.data.mobileNeighbour) { pthread_mutex_lock(&facilities.lightship.lock); - facilities.lightship.last_vehicle = itss_time_get(); + facilities.lightship.t_last_vehicle = itss_time_get(); facilities.lightship.is_vehicle_near = true; pthread_mutex_unlock(&facilities.lightship.lock); } diff --git a/src/facilities.h b/src/facilities.h index 786e8b1..a1efd02 100644 --- a/src/facilities.h +++ b/src/facilities.h @@ -88,7 +88,7 @@ typedef struct facilities { struct { pthread_mutex_t lock; - uint64_t station_id; + uint32_t station_id; uint8_t ipv6_addr[16]; struct { pthread_mutex_t lock; diff --git a/src/infrastructure.h b/src/infrastructure.h index 25a5caa..b3f7e24 100644 --- a/src/infrastructure.h +++ b/src/infrastructure.h @@ -46,7 +46,7 @@ typedef struct service { uint64_t id; bool enabled; enum SERVICE_TYPE type; - uint64_t station_id; + uint32_t station_id; enum SERVICE_STATE state; IVIM_t *ivim; diff --git a/src/saem.c b/src/saem.c index 98e09c4..8d2e204 100644 --- a/src/saem.c +++ b/src/saem.c @@ -338,7 +338,7 @@ void *sa_service() { // Logging if (facilities.logging.dbms) { pthread_mutex_lock(&facilities.id.lock); - uint64_t station_id = facilities.id.station_id; + uint32_t station_id = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); itss_db_add(facilities.logging.dbms, station_id, bpr->id, true, messageID_saem, NULL, bpr->data.buf, bpr->data.size); } diff --git a/src/saem.h b/src/saem.h index d85a520..8f3fe8e 100644 --- a/src/saem.h +++ b/src/saem.h @@ -25,7 +25,7 @@ typedef struct announcement { void* internal_p; } info; - uint64_t station_id; + uint32_t station_id; uint64_t timestamp; uint32_t n_trigger; /* number of times service was triggered */ diff --git a/src/tpm.c b/src/tpm.c index 8238d2e..0e0280a 100644 --- a/src/tpm.c +++ b/src/tpm.c @@ -383,7 +383,7 @@ int tpm_pay(tolling_info_t* info, void** security_socket, uint8_t* neighbour, ui // Logging if (facilities.logging.dbms) { pthread_mutex_lock(&facilities.id.lock); - uint64_t station_id = facilities.id.station_id; + uint32_t station_id = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); itss_db_add(facilities.logging.dbms, station_id, id, true, 117, NULL, tpm_uper, tpm_uper_len); } @@ -950,7 +950,7 @@ static void rsu_handle_recv(TPM_t* tpm_rx, void** security_socket, uint8_t* neig // Logging if (facilities.logging.dbms) { pthread_mutex_lock(&facilities.id.lock); - uint64_t station_id = facilities.id.station_id; + uint32_t station_id = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); itss_db_add(facilities.logging.dbms, station_id, id, true, 117, NULL, tpm_uper, tpm_uper_len); } diff --git a/src/tpm.h b/src/tpm.h index dea7f4b..37ad9f1 100644 --- a/src/tpm.h +++ b/src/tpm.h @@ -44,7 +44,7 @@ typedef struct tlsc { } tlsc_t; typedef struct toll_client { - uint64_t station_id; + uint32_t station_id; uint64_t id; uint64_t ts; int8_t accepted; diff --git a/src/vcm.c b/src/vcm.c index 7dbd88d..ab68e17 100644 --- a/src/vcm.c +++ b/src/vcm.c @@ -53,7 +53,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { coordination_t* coordination = &facilities.coordination; pthread_mutex_lock(&facilities.id.lock); - uint64_t my_station_id = facilities.id.station_id; + uint32_t my_station_id = facilities.id.station_id; pthread_mutex_unlock(&facilities.id.lock); // Is request for me? @@ -61,7 +61,7 @@ static int vcm_check_handle_request(VCM_t* vcm, mc_neighbour_s* neighbour) { bool is_req4me = false; for (int i = 0; i < request->desiredTrajectories.list.count && !is_req4me; ++i) { for (int j = 0; j < request->desiredTrajectories.list.array[i]->affectingStations.list.count; ++j) { - log_debug("[vc] VCM.request meant for %lld", *request->desiredTrajectories.list.array[i]->affectingStations.list.array[j]); + log_debug("[vc] VCM.request meant for %d", *request->desiredTrajectories.list.array[i]->affectingStations.list.array[j]); if (my_station_id == *request->desiredTrajectories.list.array[i]->affectingStations.list.array[j]) { is_req4me = true; break; @@ -397,6 +397,7 @@ static int intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour) { ProposedTrajectory_t* pt = mvc->negotiation->choice.request.desiredTrajectories.list.array[0]; mvc->negotiation->choice.request.requesterId = vcm->header.stationID; mvc->negotiation->choice.request.nonce = rand() + 1; + neighbour->nonce = mvc->negotiation->choice.request.nonce; pt->trajectory.list.count = trajectoryA_len - 1; pt->trajectory.list.size = sizeof(void*) * (trajectoryA_len - 1); @@ -411,12 +412,43 @@ static int intersection_detected(VCM_t* vcm, mc_neighbour_s* neighbour) { pt->offer = 5; pt->priority = 1; pt->id = 0; - pt->affectingStations.list.count = 1; - pt->affectingStations.list.size = 1*sizeof(void*); - pt->affectingStations.list.array = malloc(sizeof(void*)); - pt->affectingStations.list.array[0] = malloc(sizeof(long long)); - *pt->affectingStations.list.array[0] = neighbour->station_id; - log_debug("[vc] this VCM.request affects %ld", neighbour->station_id); + + uint32_t intneigh[MC_MAX_NEIGHBOURS]; + intneigh[0] = neighbour->station_id; + int n_intneigh = 1; + for (int n = 0; n < coordination->neighbours_len; ++n) { + if (coordination->neighbours[n].station_id == neighbour->station_id) { + continue; + } + + int index; + if (are_vehicles_intersecting( + trajectoryA, trajectoryA_len, + facilities.vehicle.length, facilities.vehicle.length, + coordination->neighbours[n].trajectory, coordination->neighbours[n].trajectory_len, + coordination->neighbours[n].length, coordination->neighbours[n].width, + &index + )) { + intneigh[n_intneigh] = coordination->neighbours[n].station_id; + ++n_intneigh; + } + } + +#ifndef NDEBUG + char buffer[512]; + int wr = 0; +#endif + pt->affectingStations.list.count = n_intneigh; + pt->affectingStations.list.size = n_intneigh*sizeof(void*); + pt->affectingStations.list.array = malloc(n_intneigh * sizeof(void*)); + for (int i = 0; i < n_intneigh; ++i) { + pt->affectingStations.list.array[i] = malloc(sizeof(long long)); + *pt->affectingStations.list.array[i] = intneigh[i]; +#ifndef NDEBUG + wr += sprintf(buffer + wr, " %d", intneigh[i]); +#endif + } + log_debug("[vc] this VCM.request affects %d station(s):%s", n_intneigh, buffer); asn_enc_rval_t enc = uper_encode_to_buffer(&asn_DEF_VCM, NULL, vcm_req, buf, buf_len); if (enc.encoded == -1) { @@ -530,6 +562,7 @@ int vcm_check(VCM_t* vcm) { ni = coordination->neighbours_len; ++coordination->neighbours_len; } + switch (vcm->vcm.maneuverContainer.present) { case ManeuverContainer_PR_vehicle: ; @@ -568,6 +601,12 @@ int vcm_check(VCM_t* vcm) { ++trajectoryB_len; } + // Save neighbour trajectory + memcpy(coordination->neighbours[ni].trajectory, trajectoryB, trajectoryB_len * sizeof(itss_st_t)); + coordination->neighbours[ni].trajectory_len = trajectoryB_len; + coordination->neighbours[ni].length = mvc->vehicleLength.vehicleLengthValue; + coordination->neighbours[ni].width = mvc->vehicleWidth; + bool intersecting = false; int index = -1; diff --git a/src/vcm.h b/src/vcm.h index 0b4884b..aaf4a62 100644 --- a/src/vcm.h +++ b/src/vcm.h @@ -4,17 +4,24 @@ #include #include +#include #define MC_MAX_NEIGHBOURS 32 #define MC_RESOLUTION_TIMEOUT 1000 typedef struct { - uint64_t station_id; + uint32_t station_id; + uint16_t length; + uint16_t width; + + itss_st_t trajectory[TRAJECTORY_MAX_LEN + 1]; + uint8_t trajectory_len; bool intersecting; uint64_t t_iid; /* initial intersection detection */ bool proposed; + uint64_t nonce; uint64_t t_proposal; } mc_neighbour_s;