D2dAmc.h Source File

Simu5G: D2dAmc.h Source File
Simu5G
D2dAmc.h
1//
2// Simu5G
3//
4// Copyright (C) 2012-2021 Giovanni Nardini, Giovanni Stea, Antonio Virdis et al. (University of Pisa)
5// Copyright (C) 2022-2026 Giovanni Nardini, Giovanni Stea et al. (University of Pisa)
6//
7// This file is part of a software released under the license included in file
8// "license.pdf". Please read LICENSE and README files before using it.
9// The above files and the present reference are part of the software itself,
10// and cannot be removed from it.
11//
12
13#ifndef STACK_D2D_MAC_AMC_D2DAMC_H_
14#define STACK_D2D_MAC_AMC_D2DAMC_H_
15
16#include <cstring>
17
18#include <inet/common/ModuleRefByPar.h>
19
20#include "simu5g/stack/mac/amc/LteAmc.h"
21#include "simu5g/stack/d2d/binder/D2dBinder.h"
22#include "simu5g/stack/d2d/mac/ID2dAmc.h"
23#include "simu5g/stack/d2d/mac/amc/AmcPilotD2D.h"
24#include "simu5g/stack/d2d/mac/amc/D2dAmcHelper.h"
25#include "simu5g/common/InitStages.h"
26
27namespace simu5g {
28
43template<class Base>
44class D2dAmc : public Base, public ID2dAmc, public cListener
45{
46 protected:
47 // holds the D2D-specific AMC state and logic
48 D2dAmcHelper d2dHelper_;
49
50 // holder of the global D2D state
51 inet::ModuleRefByPar<D2dBinder> d2dBinder_;
52
53 void initialize(int stage) override
54 {
55 Base::initialize(stage);
56 if (stage == inet::INITSTAGE_LOCAL)
57 d2dBinder_.reference(this, "d2dBinderModule", true);
58 else if (stage == INITSTAGE_SIMU5G_BINDER_ACCESS) {
59 d2dHelper_.initD2D(d2dBinder_.get());
60 // A departing UE outlives itself in the AMCs of cells it never attached to, as a
61 // D2D feedback peer, which detachUser() at its own serving cell cannot reach. The
62 // Binder's notification reaches every D2D AMC in the network, so it does.
63 this->getBinder()->subscribe(Binder::nodeUnregisteredSignal_, this);
64 }
65 }
66
67 void receiveSignal(cComponent *source, simsignal_t signalID, long nodeId, cObject *details) override
68 {
69 ASSERT(signalID == Binder::nodeUnregisteredSignal_);
70 d2dHelper_.purgeDepartedNode(MacNodeId(nodeId));
71 }
72
73 // the "D2D" amcMode selects the D2D AMC pilot; other modes fall back to the base
74 AmcPilot *createAmcPilot(const char *amcMode) override
75 {
76 if (strcmp(amcMode, "D2D") == 0) {
77 EV << "Creating Amc pilot " << amcMode << endl;
78 return new AmcPilotD2D(this->binder_, this);
79 }
80 return Base::createAmcPilot(amcMode);
81 }
82
83 // D2D branch of the base routing seams
84 void printTxParamsForDirection(Direction dir, GHz carrierFrequency) override
85 {
86 if (dir == D2D)
87 d2dHelper_.printTxParamsD2D(carrierFrequency);
88 else
89 Base::printTxParamsForDirection(dir, carrierFrequency);
90 }
91
92 bool existTxParamsForDirection(MacNodeId id, Direction dir, GHz carrierFrequency) override
93 {
94 if (dir == D2D)
95 return d2dHelper_.existTxParamsD2D(id, carrierFrequency);
96 return Base::existTxParamsForDirection(id, dir, carrierFrequency);
97 }
98
99 const UserTxParams& setTxParamsForDirection(MacNodeId id, Direction dir, UserTxParams& info, GHz carrierFrequency) override
100 {
101 if (dir == D2D)
102 return d2dHelper_.setTxParamsD2D(id, info, carrierFrequency);
103 return Base::setTxParamsForDirection(id, dir, info, carrierFrequency);
104 }
105
106 const UserTxParams& getTxParamsForDirection(MacNodeId id, Direction dir, GHz carrierFrequency) override
107 {
108 if (dir == D2D)
109 return d2dHelper_.getTxParamsD2D(id, carrierFrequency);
110 return Base::getTxParamsForDirection(id, dir, carrierFrequency);
111 }
112
113 McsTable *getMcsTableForDirection(Direction dir) override
114 {
115 if (dir == D2D || dir == D2D_MULTI)
116 return &this->ulMcsTable_;
117 return Base::getMcsTableForDirection(dir);
118 }
119
120 void rescaleMcsForDirection(double rePerRb, Direction dir) override
121 {
122 if (dir == D2D)
123 d2dHelper_.rescaleD2D(rePerRb);
124 else
125 Base::rescaleMcsForDirection(rePerRb, dir);
126 }
127
128 void detachUserForDirection(MacNodeId nodeId, Direction dir) override
129 {
130 if (dir == D2D)
131 d2dHelper_.detachUserD2D(nodeId);
132 else
133 Base::detachUserForDirection(nodeId, dir);
134 }
135
136 void attachUserForDirection(MacNodeId nodeId, Direction dir) override
137 {
138 if (dir == D2D)
139 d2dHelper_.attachUserD2D(nodeId);
140 else
141 Base::attachUserForDirection(nodeId, dir);
142 }
143
144 void testUeForDirection(MacNodeId nodeId, Direction dir) override
145 {
146 if (dir == D2D)
147 d2dHelper_.testUeD2D(nodeId);
148 else
149 Base::testUeForDirection(nodeId, dir);
150 }
151
152 public:
153 D2dAmc() : d2dHelper_(this) {}
154
155 // ID2dAmc
156 void pushFeedbackD2D(MacNodeId id, LteFeedback fb, MacNodeId peerId, GHz carrierFrequency) override
157 {
158 d2dHelper_.pushFeedbackD2D(id, fb, peerId, carrierFrequency);
159 }
160
161 const LteSummaryFeedback& getFeedbackD2D(MacNodeId id, Remote antenna, TxMode txMode, MacNodeId peerId, GHz carrierFrequency) override
162 {
163 return d2dHelper_.getFeedbackD2D(id, antenna, txMode, peerId, carrierFrequency);
164 }
165};
166
167} //namespace
168
169#endif
AMC pilot for D2D communication.
Definition AmcPilotD2D.h:24
Abstract AMC Pilot class.
Definition AmcPilot.h:35
static simsignal_t nodeUnregisteredSignal_
Definition Binder.h:250
LTE feedback message exchanged between PHY and AMC.
Definition LteFeedback.h:31
Definition LteMcs.h:61
Definition AlertReceiver.h:24