@@ -154,20 +154,20 @@ MetricSupervisor::signalSentPacket(std::string buf, double lat, double lon, uint
154
154
}
155
155
156
156
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 )
159
159
{
160
- int stationID = ids[i] ;
160
+ std::string stationID = it-> first ;
161
161
162
- carla::Vehicle vehicle = m_carla_ptr->GetManagedActorById (stationID);
162
+ carla::Vehicle vehicle = m_carla_ptr->GetManagedActorById (std::stoi ( stationID) );
163
163
164
- if (stationID == nodeID)
164
+ if (std::stoi ( stationID) == nodeID)
165
165
m_stationtype_map[buf] = StationType_passengerCar;
166
166
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 ())) {
168
168
if (MetricSupervisor_haversineDist (lat,lon,vehicle.latitude (),vehicle.longitude ())<=m_baseline_m)
169
169
{
170
- m_packetbuff_map[buf].nodeList .push_back (stationID);
170
+ m_packetbuff_map[buf].nodeList .push_back (std::stoi ( stationID) );
171
171
}
172
172
}
173
173
}
@@ -445,7 +445,7 @@ storeCBR80211p (std::string context, Time start, Time duration, WifiPhyState sta
445
445
std::size_t last = context.find (" /" , first);
446
446
std::string node = context.substr (first, last - first);
447
447
448
- if (state != WifiPhyState::IDLE && state != WifiPhyState::SLEEP)
448
+ if (state != WifiPhyState::IDLE && state != WifiPhyState::SLEEP && state != WifiPhyState::TX )
449
449
{
450
450
// Check if the last measurement for busy state started before the last CBR check
451
451
// 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
473
473
}
474
474
else
475
475
{
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
476
481
nodeLastState80211p[node].first = Simulator::Now ();
477
482
nodeLastState80211p[node].second = WifiPhyState::IDLE;
478
483
}
@@ -486,17 +491,18 @@ storeCBRNr(std::string context, Time duration)
486
491
std::size_t last = context.find (" /" , first);
487
492
std::string node = context.substr (first, last - first);
488
493
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)
493
497
{
494
- currentBusyCBR[ node] = duration;
498
+ if (it-> first != node) nodeDurationStateNr[it-> first ] = Simulator::Now () + duration;
495
499
}
496
- else
500
+
501
+ for (auto it = currentBusyCBR.begin (); it != currentBusyCBR.end (); ++it)
497
502
{
498
- currentBusyCBR[ node] += duration;
503
+ if (it-> first != node) it-> second += duration;
499
504
}
505
+
500
506
}
501
507
502
508
void
@@ -522,19 +528,21 @@ MetricSupervisor::checkCBR ()
522
528
Time busyCbr = currentBusyCBR[node_id];
523
529
524
530
// We are in the middle of a busy state
531
+ /*
525
532
if (m_channel_technology == "80211p" &&
526
533
nodeLastState80211p[node_id].second == WifiPhyState::CCA_BUSY)
527
534
{
528
535
// 80211p duration refers to the past time the channel was busy
529
536
// We need to add the time from the last check if the state is still busy
530
537
busyCbr += Simulator::Now () - nodeLastState80211p[node_id].first;
531
538
}
539
+ */
532
540
533
541
if (m_channel_technology == " Nr" )
534
542
{
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)
538
546
if (nodeDurationStateNr[node_id] > Simulator::Now ())
539
547
{
540
548
Time nextToAdd = nodeDurationStateNr[node_id] - Simulator::Now ();
@@ -576,19 +584,21 @@ MetricSupervisor::checkCBR ()
576
584
Time busyCbr = currentBusyCBR[node_id];
577
585
578
586
// We are in the middle of a busy state
587
+ /*
579
588
if (m_channel_technology == "80211p" &&
580
589
nodeLastState80211p[node_id].second == WifiPhyState::CCA_BUSY)
581
590
{
582
591
// 80211p duration refers to the past time the channel was busy
583
592
// We need to add the time from the last check if the state is still busy
584
593
busyCbr += Simulator::Now () - nodeLastState80211p[node_id].first;
585
594
}
595
+ */
586
596
587
597
if (m_channel_technology == " Nr" )
588
598
{
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)
592
602
if (nodeDurationStateNr[node_id] > Simulator::Now ())
593
603
{
594
604
Time nextToAdd = nodeDurationStateNr[node_id] - Simulator::Now ();
@@ -688,6 +698,8 @@ MetricSupervisor::startCheckCBR ()
688
698
oss << " /NodeList/" << node->GetId () << " /DeviceList/*/$ns3::NrUeNetDevice/ComponentCarrierMapUe/*/NrUePhy/NrSpectrumPhyList/*/ChannelOccupied" ;
689
699
std::string var = oss.str ();
690
700
Config::Connect (var, MakeCallback (&storeCBRNr));
701
+ currentBusyCBR[std::to_string (node->GetId ())] = Time (0 );
702
+ nodeDurationStateNr[std::to_string (node->GetId ())] = Time (0 );
691
703
}
692
704
}
693
705
@@ -754,12 +766,12 @@ MetricSupervisor::channelOccupationBytesPerSecondsPerSquareMeter ()
754
766
{
755
767
if (m_total_area == 0 )
756
768
{
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 ();
758
770
double totalArea = 0 ;
759
- for (size_t i = 0 ; i < ids.size (); ++i )
771
+ for (auto it = ids. begin (); it != ids.end (); ++it )
760
772
{
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) );
763
775
totalArea += vehicle.length () * vehicle.width ();
764
776
}
765
777
0 commit comments