Skip to content

Commit 3331ef6

Browse files
committed
Bug fixed in MetricSupervisor for the calculation of CBR
1 parent e2c6222 commit 3331ef6

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

src/automotive/model/Measurements/MetricSupervisor.cc

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,20 @@ MetricSupervisor::signalSentPacket(std::string buf, double lat, double lon, uint
154154
}
155155

156156

157-
std::vector<int> ids = m_carla_ptr->getManagedConnectedIds ();
158-
for (size_t i = 0; i < ids.size(); ++i)
157+
std::map<std::basic_string<char>, std::basic_string<char>> ids = m_carla_ptr->getManagedConnectedNodes();
158+
for (auto it = ids.begin(); it != ids.end(); ++it)
159159
{
160-
int stationID = ids[i];
160+
std::string stationID = it->first;
161161

162-
carla::Vehicle vehicle = m_carla_ptr->GetManagedActorById(stationID);
162+
carla::Vehicle vehicle = m_carla_ptr->GetManagedActorById(std::stoi(stationID));
163163

164-
if (stationID == nodeID)
164+
if (std::stoi(stationID) == nodeID)
165165
m_stationtype_map[buf] = StationType_passengerCar;
166166

167-
if(m_excluded_vehID_enabled==false || (m_excluded_vehID_list.find(stationID)==m_excluded_vehID_list.end())) {
167+
if(m_excluded_vehID_enabled==false || (m_excluded_vehID_list.find(std::stoi(stationID))==m_excluded_vehID_list.end())) {
168168
if(MetricSupervisor_haversineDist(lat,lon,vehicle.latitude (),vehicle.longitude ())<=m_baseline_m)
169169
{
170-
m_packetbuff_map[buf].nodeList.push_back(stationID);
170+
m_packetbuff_map[buf].nodeList.push_back(std::stoi(stationID));
171171
}
172172
}
173173
}
@@ -445,7 +445,7 @@ storeCBR80211p (std::string context, Time start, Time duration, WifiPhyState sta
445445
std::size_t last = context.find ("/", first);
446446
std::string node = context.substr (first, last - first);
447447

448-
if (state != WifiPhyState::IDLE && state != WifiPhyState::SLEEP)
448+
if (state != WifiPhyState::IDLE && state != WifiPhyState::SLEEP && state != WifiPhyState::TX)
449449
{
450450
// Check if the last measurement for busy state started before the last CBR check
451451
// In this case we need to consider only the time from the last CBR check
@@ -473,6 +473,11 @@ storeCBR80211p (std::string context, Time start, Time duration, WifiPhyState sta
473473
}
474474
else
475475
{
476+
if (currentBusyCBR.find(node) == currentBusyCBR.end())
477+
{
478+
currentBusyCBR[node] = Time(0);
479+
}
480+
// Skip the part for the updating of CBR, because doing += Time(0) would be useless
476481
nodeLastState80211p[node].first = Simulator::Now();
477482
nodeLastState80211p[node].second = WifiPhyState::IDLE;
478483
}
@@ -486,17 +491,18 @@ storeCBRNr(std::string context, Time duration)
486491
std::size_t last = context.find ("/", first);
487492
std::string node = context.substr (first, last - first);
488493

489-
// How long the state will last?
490-
nodeDurationStateNr[node] = Simulator::Now() + duration;
491-
492-
if (currentBusyCBR.find(node) == currentBusyCBR.end())
494+
// How long the state will last for the other nodes?
495+
// This management will be useful when the CheckCBR function will start (see below)
496+
for (auto it = nodeDurationStateNr.begin(); it != nodeDurationStateNr.end(); ++it)
493497
{
494-
currentBusyCBR[node] = duration;
498+
if (it->first != node) nodeDurationStateNr[it->first] = Simulator::Now() + duration;
495499
}
496-
else
500+
501+
for (auto it = currentBusyCBR.begin(); it != currentBusyCBR.end(); ++it)
497502
{
498-
currentBusyCBR[node] += duration;
503+
if (it->first != node) it->second += duration;
499504
}
505+
500506
}
501507

502508
void
@@ -522,19 +528,21 @@ MetricSupervisor::checkCBR ()
522528
Time busyCbr = currentBusyCBR[node_id];
523529

524530
// We are in the middle of a busy state
531+
/*
525532
if (m_channel_technology == "80211p" &&
526533
nodeLastState80211p[node_id].second == WifiPhyState::CCA_BUSY)
527534
{
528535
// 80211p duration refers to the past time the channel was busy
529536
// We need to add the time from the last check if the state is still busy
530537
busyCbr += Simulator::Now () - nodeLastState80211p[node_id].first;
531538
}
539+
*/
532540

533541
if (m_channel_technology == "Nr")
534542
{
535-
// NR duration refers to the future time the channel will be busy
536-
// We need to subtract the time that will be busy after this check
537-
// This time will be added in the next check (see below)
543+
// NR duration refers to the future time the channel will be busy due to resource allocation for a certain node
544+
// We need to subtract the time that the channel will be busy for this node after this current check
545+
// This time will be added for the next check (see below)
538546
if (nodeDurationStateNr[node_id] > Simulator::Now ())
539547
{
540548
Time nextToAdd = nodeDurationStateNr[node_id] - Simulator::Now ();
@@ -576,19 +584,21 @@ MetricSupervisor::checkCBR ()
576584
Time busyCbr = currentBusyCBR[node_id];
577585

578586
// We are in the middle of a busy state
587+
/*
579588
if (m_channel_technology == "80211p" &&
580589
nodeLastState80211p[node_id].second == WifiPhyState::CCA_BUSY)
581590
{
582591
// 80211p duration refers to the past time the channel was busy
583592
// We need to add the time from the last check if the state is still busy
584593
busyCbr += Simulator::Now () - nodeLastState80211p[node_id].first;
585594
}
595+
*/
586596

587597
if (m_channel_technology == "Nr")
588598
{
589-
// NR duration refers to the future time the channel will be busy
590-
// We need to subtract the time that will be busy after this check
591-
// This time will be added in the next check (see below)
599+
// NR duration refers to the future time the channel will be busy due to resource allocation for a certain node
600+
// We need to subtract the time that the channel will be busy for this node after this current check
601+
// This time will be added for the next check (see below)
592602
if (nodeDurationStateNr[node_id] > Simulator::Now ())
593603
{
594604
Time nextToAdd = nodeDurationStateNr[node_id] - Simulator::Now ();
@@ -688,6 +698,8 @@ MetricSupervisor::startCheckCBR ()
688698
oss << "/NodeList/" << node->GetId() << "/DeviceList/*/$ns3::NrUeNetDevice/ComponentCarrierMapUe/*/NrUePhy/NrSpectrumPhyList/*/ChannelOccupied";
689699
std::string var = oss.str();
690700
Config::Connect(var, MakeCallback(&storeCBRNr));
701+
currentBusyCBR[std::to_string (node->GetId())] = Time(0);
702+
nodeDurationStateNr[std::to_string (node->GetId())] = Time(0);
691703
}
692704
}
693705

@@ -754,12 +766,12 @@ MetricSupervisor::channelOccupationBytesPerSecondsPerSquareMeter ()
754766
{
755767
if (m_total_area == 0)
756768
{
757-
std::vector<int> ids = m_carla_ptr->getManagedConnectedIds ();
769+
std::map<std::basic_string<char>, std::basic_string<char>> ids = m_carla_ptr->getManagedConnectedNodes ();
758770
double totalArea = 0;
759-
for (size_t i = 0; i < ids.size(); ++i)
771+
for (auto it = ids.begin(); it != ids.end(); ++it)
760772
{
761-
int stationID = ids[i];
762-
carla::Vehicle vehicle = m_carla_ptr->GetManagedActorById(stationID);
773+
std::string stationID = it->first;
774+
carla::Vehicle vehicle = m_carla_ptr->GetManagedActorById(std::stoi (stationID));
763775
totalArea += vehicle.length () * vehicle.width ();
764776
}
765777

0 commit comments

Comments
 (0)