Skip to content

Commit bf8ddc1

Browse files
committed
ieee80211: drop StationLabelCache, resolve station labels on demand
The cache class wrapped a single call to L3AddressResolver::findHostWithMacAddress() in a per-receiver memoization map that every emitting component had to own and thread through as a parameter. The label derivation now lives in IRateSelection::getStationLabel() and runs on demand: Dcf, Hcf and RateControlBase lose their cache members, and emitDatarateSelected() loses its extra parameter. Uncached, the resolver sweeps the network's interface tables once per emitted label instead of at most once per receiver. datarateChanged only fires when a rate control module changes its decision, so it is unaffected in practice. datarateSelected fires for every transmitted frame, so the label is now only computed when the signal has listeners; with result recording off, transmitting costs nothing extra.
1 parent a91a713 commit bf8ddc1

10 files changed

Lines changed: 36 additions & 102 deletions

File tree

src/inet/linklayer/ieee80211/mac/common/StationLabelCache.cc

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/inet/linklayer/ieee80211/mac/common/StationLabelCache.h

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/inet/linklayer/ieee80211/mac/contract/IRateSelection.cc

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,44 @@
77

88
#include "inet/linklayer/ieee80211/mac/contract/IRateSelection.h"
99

10+
#include "inet/networklayer/common/L3AddressResolver.h"
11+
1012
namespace inet {
1113
namespace ieee80211 {
1214

1315
using namespace inet::physicallayer;
1416

1517
simsignal_t IRateSelection::datarateSelectedSignal = cComponent::registerSignal("datarateSelected");
1618

17-
void IRateSelection::emitDatarateSelected(cComponent *emitter, StationLabelCache& stationLabels, const Ptr<const Ieee80211MacHeader>& header, const IIeee80211Mode *mode)
19+
void IRateSelection::emitDatarateSelected(cComponent *emitter, const Ptr<const Ieee80211MacHeader>& header, const IIeee80211Mode *mode)
1820
{
1921
double rate = mode->getDataMode()->getNetBitrate().get<bps>();
2022
auto dataHeader = dynamicPtrCast<const Ieee80211DataHeader>(header);
21-
if (dataHeader != nullptr && !dataHeader->getReceiverAddress().isMulticast()) {
22-
cNamedObject details(stationLabels.getLabel(dataHeader->getReceiverAddress()).c_str());
23+
// resolving the station label sweeps the network, so skip it if nothing listens anyway
24+
if (dataHeader != nullptr && !dataHeader->getReceiverAddress().isMulticast() && emitter->mayHaveListeners(datarateSelectedSignal)) {
25+
cNamedObject details(getStationLabel(dataHeader->getReceiverAddress()).c_str());
2326
emitter->emit(datarateSelectedSignal, rate, &details);
2427
}
2528
else
2629
emitter->emit(datarateSelectedSignal, rate);
2730
}
2831

32+
std::string IRateSelection::getStationLabel(const MacAddress& receiver)
33+
{
34+
// resolve the receiver MAC to the network node that owns it; fall back to the MAC
35+
if (cModule *node = L3AddressResolver().findHostWithMacAddress(receiver)) {
36+
// the path relative to the network, so that nodes of the same name in different
37+
// subnetworks get different labels; for a node directly under the network this
38+
// is just its name
39+
std::string label = node->getFullPath();
40+
std::string networkPrefix = std::string(node->getSimulation()->getSystemModule()->getFullName()) + ".";
41+
if (label.compare(0, networkPrefix.length(), networkPrefix) == 0)
42+
label.erase(0, networkPrefix.length());
43+
return label;
44+
}
45+
return receiver.str();
46+
}
47+
2948
} // namespace ieee80211
3049
} // namespace inet
3150

src/inet/linklayer/ieee80211/mac/contract/IRateSelection.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include "inet/common/packet/Packet.h"
1212
#include "inet/linklayer/ieee80211/mac/Ieee80211Frame_m.h"
13-
#include "inet/linklayer/ieee80211/mac/common/StationLabelCache.h"
1413
#include "inet/physicallayer/wireless/ieee80211/mode/IIeee80211Mode.h"
1514
#include "inet/physicallayer/wireless/ieee80211/mode/Ieee80211ModeSet.h"
1615

@@ -34,7 +33,14 @@ class INET_API IRateSelection
3433
// rate, so the label always names the station whose rate is reported. Control, management and
3534
// group-addressed frames carry no per-station data rate and are emitted without details: the
3635
// aggregate datarateSelected statistic still records them, a bar chart ignores them.
37-
static void emitDatarateSelected(cComponent *emitter, StationLabelCache& stationLabels, const Ptr<const Ieee80211MacHeader>& header, const physicallayer::IIeee80211Mode *mode);
36+
static void emitDatarateSelected(cComponent *emitter, const Ptr<const Ieee80211MacHeader>& header, const physicallayer::IIeee80211Mode *mode);
37+
38+
// The label identifying a station in a per-station signal emission: it names the details
39+
// object emitted with the value, which a demux() result filter and the statistic bar chart
40+
// visualizer key their per-station series on. The receiver's network node path relative to
41+
// the network if the MAC address can be resolved (just the node name unless the node is
42+
// nested in a subnetwork), otherwise the MAC address string.
43+
static std::string getStationLabel(const MacAddress& receiver);
3844

3945
public:
4046
virtual ~IRateSelection() {}

src/inet/linklayer/ieee80211/mac/coordinationfunction/Dcf.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void Dcf::transmitControlResponseFrame(Packet *responsePacket, const Ptr<const I
102102
else
103103
throw cRuntimeError("Unknown received frame type");
104104
RateSelection::setFrameMode(responsePacket, responseHeader, responseMode);
105-
IRateSelection::emitDatarateSelected(this, stationLabels, responseHeader, responseMode);
105+
IRateSelection::emitDatarateSelected(this, responseHeader, responseMode);
106106
EV_DEBUG << "Datarate for " << responsePacket->getName() << " is set to " << responseMode->getDataMode()->getNetBitrate() << ".\n";
107107
tx->transmitFrame(responsePacket, responseHeader, modeSet->getSifsTime(), this);
108108
delete responsePacket;
@@ -166,7 +166,7 @@ void Dcf::transmitFrame(Packet *packet, simtime_t ifs)
166166
const auto& header = packet->peekAtFront<Ieee80211MacHeader>();
167167
auto mode = rateSelection->computeMode(packet, header);
168168
RateSelection::setFrameMode(packet, header, mode);
169-
IRateSelection::emitDatarateSelected(this, stationLabels, header, mode);
169+
IRateSelection::emitDatarateSelected(this, header, mode);
170170
EV_DEBUG << "Datarate for " << packet->getName() << " is set to " << mode->getDataMode()->getNetBitrate() << ".\n";
171171
auto pendingPacket = channelAccess->getInProgressFrames()->getPendingFrameFor(packet);
172172
auto duration = originatorProtectionMechanism->computeDurationField(packet, header, pendingPacket, pendingPacket == nullptr ? nullptr : pendingPacket->peekAtFront<Ieee80211DataOrMgmtHeader>());

src/inet/linklayer/ieee80211/mac/coordinationfunction/Dcf.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class INET_API Dcf : public ICoordinationFunction, public IFrameSequenceHandler:
5050
ITx *tx = nullptr;
5151

5252
IRateSelection *rateSelection = nullptr;
53-
// Names the station a datarateSelected value belongs to (see ~IRateSelection::emitDatarateSelected)
54-
StationLabelCache stationLabels;
5553

5654
// Channel access method
5755
Dcaf *channelAccess = nullptr;

src/inet/linklayer/ieee80211/mac/coordinationfunction/Hcf.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ void Hcf::transmitFrame(Packet *packet, simtime_t ifs)
668668
}
669669
auto mode = rateSelection->computeMode(packet, header, txop);
670670
setFrameMode(packet, header, mode);
671-
IRateSelection::emitDatarateSelected(this, stationLabels, header, mode);
671+
IRateSelection::emitDatarateSelected(this, header, mode);
672672
EV_DEBUG << "Datarate for " << packet->getName() << " is set to " << mode->getDataMode()->getNetBitrate() << ".\n";
673673
if (txop->getProtectionMechanism() == TxopProcedure::ProtectionMechanism::SINGLE_PROTECTION) {
674674
auto pendingPacket = channelOwner->getInProgressFrames()->getPendingFrameFor(packet);
@@ -703,7 +703,7 @@ void Hcf::transmitControlResponseFrame(Packet *responsePacket, const Ptr<const I
703703
else
704704
throw cRuntimeError("Unknown received frame type");
705705
setFrameMode(responsePacket, responseHeader, responseMode);
706-
IRateSelection::emitDatarateSelected(this, stationLabels, responseHeader, responseMode);
706+
IRateSelection::emitDatarateSelected(this, responseHeader, responseMode);
707707
EV_DEBUG << "Datarate for " << responsePacket->getName() << " is set to " << responseMode->getDataMode()->getNetBitrate() << ".\n";
708708
tx->transmitFrame(responsePacket, responseHeader, modeSet->getSifsTime(), this);
709709
delete responsePacket;

src/inet/linklayer/ieee80211/mac/coordinationfunction/Hcf.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ class INET_API Hcf : public ICoordinationFunction, public IFrameSequenceHandler:
6464
ITx *tx = nullptr;
6565

6666
IQosRateSelection *rateSelection = nullptr;
67-
// Names the station a datarateSelected value belongs to (see ~IRateSelection::emitDatarateSelected)
68-
StationLabelCache stationLabels;
6967

7068
// Channel Access Methods
7169
Edca *edca = nullptr;

src/inet/linklayer/ieee80211/mac/ratecontrol/RateControlBase.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "inet/common/ModuleAccess.h"
1111
#include "inet/common/Simsignals.h"
12+
#include "inet/linklayer/ieee80211/mac/contract/IRateSelection.h"
1213

1314
namespace inet {
1415
namespace ieee80211 {
@@ -55,7 +56,7 @@ void RateControlBase::emitDatarateChangedSignal(const MacAddress& receiver, cons
5556
if (receiver.isBroadcast() || receiver.isMulticast())
5657
emit(datarateChangedSignal, rate.get());
5758
else {
58-
cNamedObject details(stationLabel(receiver).c_str());
59+
cNamedObject details(IRateSelection::getStationLabel(receiver).c_str());
5960
emit(datarateChangedSignal, rate.get(), &details);
6061
}
6162
}

src/inet/linklayer/ieee80211/mac/ratecontrol/RateControlBase.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@
88
#ifndef __INET_RATECONTROLBASE_H
99
#define __INET_RATECONTROLBASE_H
1010

11-
#include <map>
12-
#include <string>
13-
1411
#include "inet/linklayer/common/MacAddress.h"
1512
#include "inet/linklayer/ieee80211/mac/common/ModeSetListener.h"
16-
#include "inet/linklayer/ieee80211/mac/common/StationLabelCache.h"
1713
#include "inet/linklayer/ieee80211/mac/contract/IRateControl.h"
1814

1915
namespace inet {
@@ -24,9 +20,6 @@ class INET_API RateControlBase : public ModeSetListener, public IRateControl
2420
public:
2521
static simsignal_t datarateChangedSignal;
2622

27-
protected:
28-
StationLabelCache stationLabels; // cache of receiver MAC -> demux label (peer node name)
29-
3023
protected:
3124
virtual int numInitStages() const override { return NUM_INIT_STAGES; }
3225
virtual void initialize(int stage) override;
@@ -36,9 +29,6 @@ class INET_API RateControlBase : public ModeSetListener, public IRateControl
3629
virtual MacAddress getReceiverAddress(Packet *frame) const;
3730
// The mode a newly seen station starts from: the initialRate parameter, or the fastest mandatory mode.
3831
virtual const physicallayer::IIeee80211Mode *getInitialMode();
39-
// The demux label identifying a receiver in the per-station datarate statistic: the receiver's
40-
// network node name if it can be resolved, otherwise the MAC address string. Cached per receiver.
41-
virtual const std::string& stationLabel(const MacAddress& receiver) { return stationLabels.getLabel(receiver); }
4232
// Emits datarateChanged with the receiver as a named details object, so a demux(datarateChanged)
4333
// result filter can record a separate data-rate vector per station. The aggregate datarateChanged
4434
// statistic ignores the details and is therefore unchanged. Group-addressed receivers are emitted

0 commit comments

Comments
 (0)