Binder.h Source File

Simu5G: Binder.h Source File
Simu5G
Binder.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 _BINDER_H_
14#define _BINDER_H_
15
16#include <string>
17
18#include <inet/networklayer/contract/ipv4/Ipv4Address.h>
19#include <inet/networklayer/common/L3Address.h>
20
21#include "simu5g/common/LteCommon.h"
22#include "simu5g/common/blerCurves/PhyPisaData.h"
23#include "simu5g/nodes/ExtCell.h"
24#include "simu5g/stack/mac/LteMacBase.h"
25
26namespace simu5g {
27
28using namespace omnetpp;
29
32
33
34struct NodeInfo {
35 opp_component_ptr<cModule> moduleRef;
36 opp_component_ptr<LteMacBase> macModule;
37 bool isNr = false; // the node's radio technology, as stated at registration. For a UE
38 // the id says the same thing (isNrUe()); for a base station this
39 // is the only record of it, since eNBs and gNBs share one id range.
40};
41
47class Binder : public cSimpleModule
48{
49 private:
50
51 // name of the system (top-level) module
52 std::string networkName_;
53
54 // A node may be known under several addresses: a UE under those of its cellular
55 // interface (several with IPv6, of either family on a dual-stack UE), a base station
56 // under those of its X2 interfaces
57 std::map<inet::L3Address, MacNodeId> ipAddressToMacNodeId_;
58 std::map<inet::L3Address, MacNodeId> ipAddressToNrMacNodeId_;
59
60 // Consolidated node information - replaces nodeIds_, macNodeIdToModuleName_, macNodeIdToModuleRef_, macNodeIdToModule_
61 std::map<MacNodeId, NodeInfo> nodeInfoMap_;
62
63 std::vector<MacNodeId> servingNode_; // ueId -> servingEnbId
64 std::vector<MacNodeId> secondaryNodeToMasterNodeOrSelf_;
65
66 // stores the IP address of the MEC hosts in the simulation
67 std::set<inet::L3Address> mecHostAddress_;
68
69 // for GTP tunneling with MEC hosts involved
70 // this map associates the L3 address of the Virt. Infrastructure of a MEC host to
71 // the IP address of the corresponding UPF
72 std::map<inet::L3Address, inet::L3Address> mecHostToUpfAddress_;
73
74 // list of static external cells. Used for intercell interference evaluation
75 std::map<GHz, ExtCellList> extCellList_;
76
77 // list of static external cells. Used for intercell interference evaluation
78 std::map<GHz, BackgroundSchedulerList> bgSchedulerList_;
79
80 // list of all eNBs. Used for inter-cell interference evaluation
81 std::vector<EnbInfo *> enbList_;
82
83 // list of all UEs. Used for inter-cell interference evaluation
84 std::vector<UeInfo *> ueList_;
85
86 // list of all background traffic managers. Used for background UEs CQI computation
87 std::vector<BgTrafficManagerInfo *> bgTrafficManagerList_;
88
89 typedef std::map<unsigned int, std::map<unsigned int, double>> BgInterferenceMatrix;
90
91 /*
92 * Carrier Aggregation support
93 */
94 // total number of logical bands in the system. These bands
95 unsigned int totalBands_ = 0;
96 CarrierInfoMap componentCarriers_;
97
98 // for each carrier, store the UEs that are able to use it
99 typedef std::map<GHz, UeSet> CarrierUeMap;
100 CarrierUeMap carrierUeMap_;
101
102 // hack to link carrier freq to numerology index
103 std::map<GHz, NumerologyIndex> carrierFreqToNumerologyIndex_;
104 // max numerology index used by UEs
105 std::vector<NumerologyIndex> ueMaxNumerologyIndex_;
106 // set of numerologies used by each UE
107 std::map<MacNodeId, std::set<NumerologyIndex>> ueNumerologyIndex_;
108
109 /*
110 * Uplink interference support
111 */
112 typedef std::map<GHz, std::vector<std::vector<std::vector<UeAllocationInfo>>>> UplinkTransmissionMap;
113 // for each carrier frequency, for both previous and current TTIs, for each RB, stores the UE (nodeId and ref to the PHY module) that transmitted/are transmitting within that RB
114 UplinkTransmissionMap ulTransmissionMap_;
115 // TTI of the last update of the UL band status
116 simtime_t lastUpdateUplinkTransmissionInfo_;
117 // TTI of the last UL transmission (used for optimization purposes, see initAndResetUlTransmissionInfo() )
118 simtime_t lastUplinkTransmission_;
119
120 /*
121 * X2 Support
122 */
123 typedef std::map<X2NodeId, std::list<int>> X2ListeningPortMap;
124 X2ListeningPortMap x2ListeningPorts_;
125
126 std::map<MacNodeId, std::map<MacNodeId, inet::L3Address>> x2PeerAddress_;
127
128 /*
129 * Multicast support
130 */
131 // register here the IDs of the multicast group where UEs participate
132 typedef std::set<MacNodeId> MulticastGroupIdSet;
133 std::map<MacNodeId, MulticastGroupIdSet> nodeGroupMemberships_;
134
135 /*
136 * Multicast destination ID support
137 */
138 // Counter for allocating new multicast destination IDs
139 int16_t multicastDestIdCounter_ = MULTICAST_DEST_MIN_ID;
140 // Mapping from IPv4 multicast addresses to allocated multicast destination IDs
141 std::map<inet::Ipv4Address, MacNodeId> multicastAddrToDestId_;
142 // Reverse mapping from multicast destination IDs to IPv4 addresses (optional, for debugging)
143 std::map<MacNodeId, inet::Ipv4Address> multicastDestIdToAddr_;
144
145 public:
146 // The control-plane entry point of a user plane node (a UPF/PGW or a MEC host's UPF), as it
147 // registered (see registerUserPlaneNode())
148 struct UserPlaneNodeRegistration {
149 UserPlaneNodeControl *module = nullptr;
150 CoreNodeType type = UPF;
151 std::string gateway; // the core network gateway of a MEC host's UPF; empty otherwise
152 };
153
154 private:
155 std::vector<UserPlaneNodeRegistration> userPlaneNodes_; // in registration order
156
157 protected:
158 void initialize(int stages) override;
159 int numInitStages() const override { return inet::NUM_INIT_STAGES; }
160 void handleMessage(cMessage *msg) override {}
161
162 void finish() override;
163
164 // helpers
165 virtual bool isValidNodeId(MacNodeId nodeId) const;
166
167 public:
168 Binder() {}
169
170 virtual unsigned int getTotalBands()
171 {
172 return totalBands_;
173 }
174
175 ~Binder() override
176 {
177 for (auto enb : enbList_)
178 delete enb;
179
180 for (auto bg : bgTrafficManagerList_)
181 delete bg;
182
183 for (auto ue : ueList_)
184 delete ue;
185 }
186
187 virtual std::string& getNetworkName()
188 {
189 return networkName_;
190 }
191
195 virtual void registerCarrier(GHz carrierFrequency, unsigned int carrierNumBands, unsigned int numerologyIndex,
196 bool useTdd = false, unsigned int tddNumSymbolsDl = 0, unsigned int tddNumSymbolsUl = 0);
197
201 virtual void registerCarrierUe(GHz carrierFrequency, unsigned int numerologyIndex, MacNodeId ueId);
202
206 virtual const UeSet& getCarrierUeSet(GHz carrierFrequency);
207
212
216 virtual const std::set<NumerologyIndex> *getUeNumerologyIndex(MacNodeId ueId);
217
221 virtual NumerologyIndex getNumerologyIndexFromCarrierFreq(GHz carrierFreq) { return carrierFreqToNumerologyIndex_[carrierFreq]; }
222
226 virtual double getSlotDurationFromNumerologyIndex(NumerologyIndex numerologyIndex) { return pow(2.0, (-1) * (int)numerologyIndex) / 1000.0; }
227
231 virtual SlotFormat computeSlotFormat(bool useTdd, unsigned int tddNumSymbolsDl, unsigned int tddNumSymbolsUl);
232
236 virtual SlotFormat getSlotFormat(GHz carrierFrequency);
237
242 virtual void registerNode(MacNodeId nodeId, cModule *nodeModule, RanNodeType type, bool isNr = false);
243
250 static simsignal_t nodeUnregisteredSignal_;
251
255 virtual void unregisterNode(MacNodeId id);
256
264 virtual void registerUserPlaneNode(UserPlaneNodeControl *module, CoreNodeType type, const std::string& gateway);
265 const std::vector<UserPlaneNodeRegistration>& getUserPlaneNodes() const { return userPlaneNodes_; }
266
271 virtual void registerServingNode(MacNodeId enbId, MacNodeId ueId);
272
276 virtual void unregisterServingNode(MacNodeId enbId, MacNodeId ueId);
277
281 virtual MacNodeId getServingNode(MacNodeId ueId);
282
291 virtual void registerMasterNode(MacNodeId masterId, MacNodeId slaveId);
292
296 virtual bool nodeExists(MacNodeId nodeId) { return nodeInfoMap_.find(nodeId) != nodeInfoMap_.end(); }
297
301 virtual cModule *getNodeModule(MacNodeId nodeId);
302
303 /*
304 * getNodeInfoMap returns information on all nodes in a map
305 */
306 virtual const std::map<MacNodeId, NodeInfo>& getNodeInfoMap() const { return nodeInfoMap_; }
307
308 /*
309 * getMacFromMacNodeId() returns the reference to the LteMacBase module
310 * given the MacNodeId of a node
311 *
312 * @param id MacNodeId of the module
313 * @return LteMacBase* of the module
314 */
315 virtual LteMacBase *getMacFromMacNodeId(MacNodeId id);
316
320 virtual MacNodeId getServingNodeOrSelf(MacNodeId nodeId);
321
326 //TODO add MacNodeId ueId arg: In LTE DC, the roles (master/secondary) are per UE, not per bearer.
327 virtual MacNodeId getMasterNodeOrSelf(MacNodeId secondaryEnbId);
328
332 virtual MacNodeId getSecondaryNode(MacNodeId masterEnbId);
333
340 virtual MacNodeId getMacNodeId(const inet::L3Address& address)
341 {
342 if (ipAddressToMacNodeId_.find(address) == ipAddressToMacNodeId_.end())
343 return NODEID_NONE;
344 MacNodeId nodeId = ipAddressToMacNodeId_[address];
345
346 // if the UE is disconnected (its master node is 0), check the NR node Id
347 if (getServingNodeOrSelf(nodeId) == NODEID_NONE)
348 return getNrMacNodeId(address);
349 return nodeId;
350 }
351
358 virtual MacNodeId getNrMacNodeId(const inet::L3Address& address)
359 {
360 if (ipAddressToNrMacNodeId_.find(address) == ipAddressToNrMacNodeId_.end())
361 return NODEID_NONE;
362 return ipAddressToNrMacNodeId_[address];
363 }
364
372 virtual MacNodeId getUeNodeId(MacNodeId ue, bool isNr);
373
379 virtual bool isNrNodeB(MacNodeId nodeB);
380
392 virtual inet::Ipv4Address getIPv4Address(MacNodeId nodeId)
393 {
394 for (const auto& kv : ipAddressToMacNodeId_) {
395 if (kv.second == nodeId && kv.first.getType() == inet::L3Address::IPv4)
396 return kv.first.toIpv4();
397 }
398 for (const auto& kv : ipAddressToNrMacNodeId_) {
399 if (kv.second == nodeId && kv.first.getType() == inet::L3Address::IPv4)
400 return kv.first.toIpv4();
401 }
402 return inet::Ipv4Address::UNSPECIFIED_ADDRESS;
403 }
404
409 virtual std::vector<inet::L3Address> getAddresses(MacNodeId nodeId)
410 {
411 std::vector<inet::L3Address> addresses;
412 for (const auto& kv : isNrUe(nodeId) ? ipAddressToNrMacNodeId_ : ipAddressToMacNodeId_)
413 if (kv.second == nodeId)
414 addresses.push_back(kv.first);
415 return addresses;
416 }
417
424 virtual X2NodeId getX2NodeId(const inet::L3Address& address)
425 {
426 return getMacNodeId(address);
427 }
428
434 virtual void setMacNodeId(const inet::L3Address& address, MacNodeId nodeId)
435 {
436 if (isNrUe(nodeId))
437 ipAddressToNrMacNodeId_[address] = nodeId;
438 else
439 ipAddressToMacNodeId_[address] = nodeId;
440 }
441
447 virtual void unsetMacNodeId(const inet::L3Address& address, MacNodeId nodeId)
448 {
449 auto& addressToNodeId = isNrUe(nodeId) ? ipAddressToNrMacNodeId_ : ipAddressToMacNodeId_;
450 auto it = addressToNodeId.find(address);
451 if (it != addressToNodeId.end() && it->second == nodeId)
452 addressToNodeId.erase(it);
453 }
454
460 virtual void setX2NodeId(const inet::L3Address& address, X2NodeId nodeId)
461 {
462 setMacNodeId(address, nodeId);
463 }
464
465 virtual inet::L3Address getX2PeerAddress(X2NodeId srcId, X2NodeId destId)
466 {
467 return x2PeerAddress_[srcId][destId];
468 }
469
470 virtual void setX2PeerAddress(X2NodeId srcId, X2NodeId destId, inet::L3Address interfAddr)
471 {
472 x2PeerAddress_[srcId].insert({destId, interfAddr});
473 }
474
478 virtual void registerMecHost(const inet::L3Address& mecHostAddress);
482 virtual void registerMecHostUpfAddress(const inet::L3Address& mecHostAddress, const inet::L3Address& gtpAddress);
486 virtual bool isMecHost(const inet::L3Address& mecHostAddress);
490 virtual const inet::L3Address& getUpfFromMecHost(const inet::L3Address& mecHostAddress);
494 virtual cModule *getModuleByMacNodeId(MacNodeId nodeId);
495
496 /*
497 * getDeployedUes() returns the affiliates
498 * of a given eNodeB
499 */
500 virtual std::vector<MacNodeId> getDeployedUes(MacNodeId enbNodeId);
501
502 PhyPisaData phyPisaData;
503
504 virtual int getNodeCount() {
505 return nodeInfoMap_.size();
506 }
507
508 virtual int addExtCell(ExtCell *extCell, GHz carrierFrequency)
509 {
510 if (extCellList_.find(carrierFrequency) == extCellList_.end())
511 extCellList_[carrierFrequency] = ExtCellList();
512
513 extCellList_[carrierFrequency].push_back(extCell);
514 return extCellList_[carrierFrequency].size() - 1;
515 }
516
517 virtual ExtCellList getExtCellList(GHz carrierFrequency)
518 {
519 return extCellList_[carrierFrequency];
520 }
521
522 virtual int addBackgroundScheduler(BackgroundScheduler *bgScheduler, GHz carrierFrequency)
523 {
524 if (bgSchedulerList_.find(carrierFrequency) == bgSchedulerList_.end())
525 bgSchedulerList_[carrierFrequency] = BackgroundSchedulerList();
526
527 bgSchedulerList_[carrierFrequency].push_back(bgScheduler);
528 return bgSchedulerList_[carrierFrequency].size() - 1;
529 }
530
531 virtual const BackgroundSchedulerList& getBackgroundSchedulerList(GHz carrierFrequency)
532 {
533 return bgSchedulerList_[carrierFrequency];
534 }
535
536 virtual void addEnbInfo(EnbInfo *info)
537 {
538 enbList_.push_back(info);
539 }
540
541 virtual const std::vector<EnbInfo *>& getEnbList()
542 {
543 return enbList_;
544 }
545
546 virtual void addUeInfo(UeInfo *info)
547 {
548 ueList_.push_back(info);
549 }
550
551 virtual const std::vector<UeInfo *>& getUeList()
552 {
553 return ueList_;
554 }
555
556 virtual void addBgTrafficManagerInfo(BgTrafficManagerInfo *info)
557 {
558 bgTrafficManagerList_.push_back(info);
559 }
560
561 virtual const std::vector<BgTrafficManagerInfo *>& getBgTrafficManagerList()
562 {
563 return bgTrafficManagerList_;
564 }
565
566 virtual Cqi meanCqi(std::vector<Cqi> bandCqi, MacNodeId id, Direction dir);
567
568 virtual Cqi medianCqi(std::vector<Cqi> bandCqi, MacNodeId id, Direction dir);
569
570 /*
571 * Uplink interference support
572 */
573 virtual simtime_t getLastUpdateUlTransmissionInfo();
574 virtual void initAndResetUlTransmissionInfo();
575 virtual void storeUlTransmissionMap(GHz carrierFreq, Remote antenna, RbMap& rbMap, MacNodeId nodeId, MacCellId cellId, PhyBase *phy, Direction dir);
576 virtual void storeUlTransmissionMap(GHz carrierFreq, Remote antenna, RbMap& rbMap, MacNodeId nodeId, MacCellId cellId, TrafficGeneratorBase *trafficGen, Direction dir); // overloaded function for bgUes
577 virtual const std::vector<std::vector<UeAllocationInfo>> *getUlTransmissionMap(GHz carrierFreq, UlTransmissionMapTTI t);
578 /*
579 * X2 Support
580 */
581 virtual void registerX2Port(X2NodeId nodeId, int port);
582 virtual int getX2Port(X2NodeId nodeId);
583
584 /*
585 * Multicast Support
586 */
587 // add the group to the set of multicast group of nodeId
588 virtual void joinMulticastGroup(MacNodeId nodeId, MacNodeId multicastDestId);
589 // check if the node is enrolled in the group
590 virtual bool isInMulticastGroup(MacNodeId nodeId, MacNodeId multicastDestId);
591
592 /*
593 * Multicast Destination ID Support
594 */
595 // Allocate an (MBMS-RNTI-like) multicast destination ID for a multicast IPv4 address
596 virtual MacNodeId getOrAssignDestIdForMulticastAddress(inet::Ipv4Address multicastAddr);
597 // Checks if a multicast destination ID was already assigned for a multicast IPv4 address
598 virtual bool hasMulticastDestIdAssigned(inet::Ipv4Address multicastAddr) const {
599 return multicastAddrToDestId_.find(multicastAddr) != multicastAddrToDestId_.end();
600 }
601 // Get existing multicast destination ID for a multicast address (returns NODEID_NONE if not found)
602 virtual MacNodeId getDestIdForMulticastAddress(inet::Ipv4Address multicastAddr);
603 // Get multicast address from destination ID
604 virtual inet::Ipv4Address getAddressForMulticastDestId(MacNodeId multicastDestId);
605
606 virtual void updateUeInfoCellId(MacNodeId nodeId, MacCellId cellId);
607
608
609 /*
610 * author Alessandro Noferi.
611 *
612 * UeStatsCollector management
613 */
614
615 /* this method adds the UeStatsCollector reference to the baseStationStatsCollector
616 * structure.
617 * @params:
618 * ue: MacNodeId of the ue
619 * ueCollector: reference to the collector
620 * cell: MacCellId of the target eNB
621 */
622 virtual void addUeCollectorToEnodeB(MacNodeId ue, UeStatsCollector *ueCollector, MacCellId cell);
623
624 /* this method moves the UeStatsCollector reference between the eNB/gNB's baseStationStatsCollector
625 * structure.
626 * @params:
627 * ue: MacNodeId of the ue
628 * oldCell: MacCellId of the source eNB
629 * newCell: MacCellId of the target eNB
630 */
631 virtual void moveUeCollector(MacNodeId ue, MacCellId oldCell, MacCellId newCell);
632
633 virtual bool isGNodeB(MacNodeId enbId);
634
635 // Moved from LteCommon - getter functions that were taking Binder as first parameter
636 virtual CellInfo *getCellInfoByNodeId(MacNodeId nodeId);
637 virtual cModule *getPhyByNodeId(MacNodeId nodeId);
638 virtual cModule *getMacByNodeId(MacNodeId nodeId);
639 virtual cModule *getRrcByNodeId(MacNodeId nodeId);
640 virtual cModule *getIp2NicByNodeId(MacNodeId nodeId);
641};
642
643} //namespace
644
645#endif
virtual bool nodeExists(MacNodeId nodeId)
Definition Binder.h:296
virtual bool isNrNodeB(MacNodeId nodeB)
static simsignal_t nodeUnregisteredSignal_
Definition Binder.h:250
virtual void setMacNodeId(const inet::L3Address &address, MacNodeId nodeId)
Definition Binder.h:434
virtual void registerMecHostUpfAddress(const inet::L3Address &mecHostAddress, const inet::L3Address &gtpAddress)
virtual cModule * getModuleByMacNodeId(MacNodeId nodeId)
virtual std::vector< inet::L3Address > getAddresses(MacNodeId nodeId)
Definition Binder.h:409
virtual MacNodeId getSecondaryNode(MacNodeId masterEnbId)
virtual MacNodeId getUeNodeId(MacNodeId ue, bool isNr)
virtual void unsetMacNodeId(const inet::L3Address &address, MacNodeId nodeId)
Definition Binder.h:447
virtual SlotFormat computeSlotFormat(bool useTdd, unsigned int tddNumSymbolsDl, unsigned int tddNumSymbolsUl)
virtual MacNodeId getMacNodeId(const inet::L3Address &address)
Definition Binder.h:340
virtual void registerNode(MacNodeId nodeId, cModule *nodeModule, RanNodeType type, bool isNr=false)
virtual const UeSet & getCarrierUeSet(GHz carrierFrequency)
virtual void registerCarrierUe(GHz carrierFrequency, unsigned int numerologyIndex, MacNodeId ueId)
virtual void setX2NodeId(const inet::L3Address &address, X2NodeId nodeId)
Definition Binder.h:460
virtual void unregisterNode(MacNodeId id)
virtual void registerCarrier(GHz carrierFrequency, unsigned int carrierNumBands, unsigned int numerologyIndex, bool useTdd=false, unsigned int tddNumSymbolsDl=0, unsigned int tddNumSymbolsUl=0)
virtual MacNodeId getServingNodeOrSelf(MacNodeId nodeId)
virtual NumerologyIndex getNumerologyIndexFromCarrierFreq(GHz carrierFreq)
Definition Binder.h:221
virtual void registerServingNode(MacNodeId enbId, MacNodeId ueId)
virtual SlotFormat getSlotFormat(GHz carrierFrequency)
virtual NumerologyIndex getUeMaxNumerologyIndex(MacNodeId ueId)
virtual const std::set< NumerologyIndex > * getUeNumerologyIndex(MacNodeId ueId)
virtual const inet::L3Address & getUpfFromMecHost(const inet::L3Address &mecHostAddress)
virtual MacNodeId getNrMacNodeId(const inet::L3Address &address)
Definition Binder.h:358
virtual MacNodeId getMasterNodeOrSelf(MacNodeId secondaryEnbId)
virtual void unregisterServingNode(MacNodeId enbId, MacNodeId ueId)
virtual void registerMecHost(const inet::L3Address &mecHostAddress)
virtual void registerUserPlaneNode(UserPlaneNodeControl *module, CoreNodeType type, const std::string &gateway)
virtual bool isMecHost(const inet::L3Address &mecHostAddress)
virtual X2NodeId getX2NodeId(const inet::L3Address &address)
Definition Binder.h:424
virtual MacNodeId getServingNode(MacNodeId ueId)
virtual cModule * getNodeModule(MacNodeId nodeId)
virtual double getSlotDurationFromNumerologyIndex(NumerologyIndex numerologyIndex)
Definition Binder.h:226
virtual void registerMasterNode(MacNodeId masterId, MacNodeId slaveId)
virtual inet::Ipv4Address getIPv4Address(MacNodeId nodeId)
Definition Binder.h:392
MAC Layer.
Definition LteMacBase.h:80
Definition UeStatsCollector.h:40
Definition UserPlaneNodeControl.h:38
Definition AlertReceiver.h:24
MacNodeId X2NodeId
X2 node ID. It is equal to the eNodeB MAC Cell ID.
Definition LteTypes.h:69
MacNodeId MacCellId
Cell node ID. It is numerically equal to eNodeB MAC node ID.
Definition LteTypes.h:66
unsigned short Cqi
Channel Quality Indicator.
Definition LteTypes.h:133
std::set< MacNodeId > UeSet
Definition LteCommon.h:379
std::map< Remote, std::map< Band, unsigned int > > RbMap
Definition LteTypes.h:145
unsigned short NumerologyIndex
Numerology Index.
Definition LteCommon.h:205
constexpr MacNodeId NODEID_NONE
MAC node ID.
Definition LteTypes.h:54