1. 主要逻辑

该部分代码的主要实现逻辑如下所示,函数位置在 BasePhyLayer 模块 initializeAnalogueModels 中:

1
2
3
4
5
6
7
8
9
BasePhyLayer -> void initializeAnalogueModels(cXMLElement* xmlConfig);

BasePhyLayer -> std::unique_ptr<AnalogueModel> getAnalogueModelFromName(std::string name, ParameterMap& params)

PhyLayer80211p -> unique_ptr<AnalogueModel> PhyLayer80211p::getAnalogueModelFromName(std::string name, ParameterMap& params)

PhyLayer80211p -> unique_ptr<AnalogueModel> PhyLayer80211p::initializeSimpleObstacleShadowing(ParameterMap& params)

···

通过这几步后将所有 Analogue Model 汇总到 BasePhyLayer 中 analogueModels 成员变量里,供后续 Signal 来处理仿真真实环境。

不同种类的衰落模型都派生自 AnalogueModel 类,其包括一个重要的纯虚函数 virtual void filterSignal(Signal* signal) ,由其他不同类型的模型来 override 实现不同程度的衰落。

2. 调用关系

前面说完了 Analogue Model 内部生成的逻辑,下面记录下项目中实际调用的逻辑。其主要在 BaseDecider 模块中用来处理不同的 Signal,函数调用如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
simtime_t BaseDecider::processSignal(AirFrame* frame)
{
ASSERT(frame);
EV_INFO << "Processing AirFrame..." << endl;

switch (getSignalState(frame)) {
case NEW:
EV_INFO << "process new signal" << endl;
return processNewSignal(frame);
case EXPECT_HEADER:
EV_INFO << "process signal header" << endl;
return processSignalHeader(frame);
case EXPECT_END:
EV_INFO << "process signal end" << endl;
return processSignalEnd(frame);
default:
EV_INFO << "process unknown signal" << endl;
return processUnknownSignal(frame);
}
}

其中 processNewSignal(frame) 函数承担主要功能,在 BaseDecider 中作为虚函数有一个基本实现,后其在 Decider80211p 中重新 override 该函数。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
simtime_t Decider80211p::processNewSignal(AirFrame* msg)
{
EV_INFO << "Decider80211p::processNewSignal" << endl;
AirFrame11p* frame = check_and_cast<AirFrame11p*>(msg);

// get the receiving power of the Signal at start-time and center frequency
Signal& signal = frame->getSignal();

signalStates[frame] = EXPECT_END;

if (signal.smallerAtCenterFrequency(minPowerLevel)) {
EV_INFO << "current signal smaller at center frequency" << endl;
// annotate the frame, so that we won't try decoding it at its end
frame->setUnderMinPowerLevel(true);
// check channel busy status. a superposition of low power frames might turn channel status to busy
if (cca(simTime(), nullptr) == false) {
setChannelIdleStatus(false);
}
return signal.getReceptionEnd();
}
else {
EV_INFO << "current signal bigger at center frequency" << endl;
// This value might be just an intermediate result (due to short circuiting)
double recvPower = signal.getAtCenterFrequency();
setChannelIdleStatus(false);

if (phy11p->getRadioState() == Radio::TX) {
frame->setBitError(true);
frame->setWasTransmitting(true);
EV_INFO << "AirFrame: " << frame->getId() << " (" << recvPower << ") received, while already sending. Setting BitErrors to true" << std::endl;
}
else {
EV_INFO << "phy11p->getRadioState() != Radio::TX" << endl;
if (!currentSignal.first) {
// NIC is not yet synced to any frame, so lock and try to decode this frame
currentSignal.first = frame;
EV_INFO << "AirFrame: " << frame->getId() << " with (" << recvPower << " > " << minPowerLevel << ") -> Trying to receive AirFrame." << std::endl;
if (notifyRxStart) {
phy->sendControlMsgToMac(new cMessage("RxStartStatus", MacToPhyInterface::PHY_RX_START));
}
}
else {
// NIC is currently trying to decode another frame. this frame will be simply treated as interference
EV_INFO << "AirFrame: " << frame->getId() << " with (" << recvPower << " > " << minPowerLevel << ") -> Already synced to another AirFrame. Treating AirFrame as interference." << std::endl;
}

// channel turned busy
// measure communication density
myBusyTime += signal.getDuration().dbl();
}
return signal.getReceptionEnd();
}
}

在其中有一个很重要的判断 signal.smallerAtCenterFrequency(minPowerLevel) 调用了 Analogue Model 来模拟实际环境。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool Signal::smallerAtCenterFrequency(double threshold)
{
EV_INFO << "signal power is " << values[centerFrequencyIndex] << " threshold is " << threshold << endl;
if (values[centerFrequencyIndex] < threshold) return true;

uint16_t maxAnalogueModels = analogueModelList->size();

while (numAnalogueModelsApplied < maxAnalogueModels) {
// Apply filter here
(*analogueModelList)[numAnalogueModelsApplied]->filterSignal(this);
numAnalogueModelsApplied++;
if (values[centerFrequencyIndex] < threshold) return true;
}
return false;
}

可以看到在其中分别调用不同的衰落模型来 filter signal,当所有模型调用结束后如果得到的功率大小满足要求,则后面便可以把 frame 进一步发送到更上一层来进行处理。