19#ifndef _LTE_LTECOMMON_H_
20#define _LTE_LTECOMMON_H_
35#include <inet/common/packet/Packet.h>
36#include <inet/common/Protocol.h>
37#include <inet/common/Units.h>
38#include <inet/common/geometry/Geometry_m.h>
39#include <inet/networklayer/common/L3Address.h>
40#include <inet/networklayer/contract/ipv4/Ipv4Address.h>
42#include "simu5g/common/LteDefs.h"
43#include "simu5g/common/LteTypes.h"
44#include "simu5g/common/LteCommonEnum_m.h"
50using namespace omnetpp;
66class IBackgroundTrafficManager;
67class BackgroundScheduler;
68class TrafficGeneratorBase;
76 static const inet::Protocol pdcp;
77 static const inet::Protocol rlc;
78 static const inet::Protocol ltemac;
79 static const inet::Protocol gtp;
80 static const inet::Protocol x2ap;
81 static const inet::Protocol sdap;
82 static const inet::Protocol unstructured;
91 Direction direction = DL;
92 DrbId drbId = DRBID_NONE;
99 FlowId reversed()
const;
102inline std::ostream& operator<<(std::ostream& os,
const FlowId& e)
104 os <<
"src=" << e.sourceId <<
" dst=" << e.destId <<
" dir=" << e.direction <<
" drb=" << e.drbId
105 <<
" d2dGroup=" << e.d2dGroupId <<
" d2dTx=" << e.d2dTxPeerId <<
" d2dRx=" << e.d2dRxPeerId;
113struct FlowBindingKey {
114 inet::L3Address srcAddr;
115 inet::L3Address dstAddr;
116 uint16_t typeOfService = 0;
117 Direction direction = DL;
119 bool operator==(
const FlowBindingKey& other)
const {
120 return srcAddr == other.srcAddr && dstAddr == other.dstAddr &&
121 typeOfService == other.typeOfService && direction == other.direction;
126 FlowBindingKey reversed()
const {
127 Direction revDir = (direction == UL) ? DL : (direction == DL) ? UL : direction;
128 return FlowBindingKey{dstAddr, srcAddr, typeOfService, revDir};
132inline std::ostream& operator<<(std::ostream& os,
const FlowBindingKey& k)
134 os << k.srcAddr <<
"->" << k.dstAddr <<
" tos=" << k.typeOfService <<
" dir=" << k.direction;
138struct FlowBindingKeyHash {
139 static std::size_t hashAddress(
const inet::L3Address& addr) {
140 if (addr.getType() == inet::L3Address::IPv4)
141 return std::hash<uint32_t>{}(addr.toIpv4().getInt());
142 const uint32_t *w = addr.toIpv6().words();
143 return std::hash<uint32_t>{}(w[0] ^ w[1] ^ w[2] ^ w[3]);
145 std::size_t operator()(
const FlowBindingKey& key)
const {
146 std::size_t h1 = hashAddress(key.srcAddr);
147 std::size_t h2 = hashAddress(key.dstAddr);
148 std::size_t h3 = std::hash<uint16_t>{}(key.typeOfService);
149 std::size_t h4 = std::hash<uint16_t>{}(uint16_t(key.direction));
150 return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3);
159struct BearerRequest {
160 RlcMode rlcMode = UM;
168 std::optional<FlowBindingKey> flowBindingKey;
171inline std::ostream& operator<<(std::ostream& os,
const BearerRequest& e)
173 os <<
"rlcMode=" << e.rlcMode <<
" lcg=" << e.lcg <<
" hasFlowBindingKey=" << e.flowBindingKey.has_value();
180#define ELEM(x) { x, #x }
189#define MAX_CODEWORDS 2
192#define LTE_QCI_CLASSES 9
196typedef std::vector<Band> UsableBands;
199typedef std::map<MacNodeId, UsableBands> UsableBandsList;
208typedef std::vector<double> AttenuationVector;
222const unsigned int txModeToIndex[2] = { 0, 1 };
224const TxMode indexToTxMode[2] = {
225 SINGLE_ANTENNA_PORT0,
229typedef std::map<MacNodeId, TxMode> TxModeMap;
231const double cqiToByteTms[16] = { 0, 2, 3, 5, 11, 15, 20, 25, 36, 38, 49, 63, 72, 79, 89, 92 };
233double dBmToLinear(
double dbm);
234double dBToLinear(
double db);
235double linearToDBm(
double lin);
236double linearToDb(
double lin);
243class X2InformationElement;
265 BandLimit() :
band_(0)
267 limit_.resize(MAX_CODEWORDS, -1);
273 limit_.resize(MAX_CODEWORDS, -1);
276 bool operator<(
const BandLimit rhs)
const
278 return limit_[0] > rhs.limit_[0];
283typedef std::vector<BandLimit> BandLimitVector;
289const unsigned char MAXCW = 2;
290const Cqi MAXCQI = 15;
291const Cqi NOSIGNALCQI = 0;
292const Rank NORANK = 1;
293const Tbs CQI2ITBSSIZE = 29;
294const unsigned int PDCP_HEADER_UM = 1;
295const unsigned int PDCP_HEADER_AM = 2;
301const unsigned int RLC_HEADER_UM = 2;
302const unsigned int RLC_HEADER_AM = 2;
308enum NrUmSegState { NRUM_COMPLETE = 0, NRUM_FIRST = 1, NRUM_CONTINUATION = 2 };
312inline unsigned int nrUmHeaderBytes(NrUmSegState s,
unsigned int snBits)
314 if (s == NRUM_COMPLETE)
316 unsigned int base = (2u + snBits + 7u) / 8u;
317 return (s == NRUM_CONTINUATION) ? base + 2u : base;
323inline unsigned int nrAmHeaderBytes(NrUmSegState s,
unsigned int snBits)
325 unsigned int base = (4u + snBits + 7u) / 8u;
326 return (s == NRUM_CONTINUATION) ? base + 2u : base;
328const unsigned int MAC_HEADER = 2;
329const unsigned int MAXGRANT = 4294967295U;
337class MacControlElement;
350typedef std::map<std::pair<MacNodeId, Codeword>, inet::Packet *>
MacPduList;
355typedef std::map<MacNodeId, unsigned int> LteMacAllocatedCws;
362typedef std::list<size_t> RlcSduListSizes;
389#define HARQ_TX_INTERVAL 7 * TTI
392typedef std::list<Codeword> CwList;
406 TxDirectionType txDirection;
409 PhyBase *phy =
nullptr;
410 LteMacEnb *mac =
nullptr;
412 opp_component_ptr<cModule> eNodeB;
414 std::string str()
const;
423 StochasticChannelModel *realChan =
nullptr;
424 opp_component_ptr<cModule> ue;
425 PhyBase *phy =
nullptr;
426 std::string str()
const;
432struct BgTrafficManagerInfo
435 IBackgroundTrafficManager *bgTrafficManager =
nullptr;
436 GHz carrierFrequency;
437 double allocatedRbsDl;
438 double allocatedRbsUl;
439 std::vector<double> allocatedRbsUeUl;
440 std::string str()
const;
444struct UeAllocationInfo {
447 PhyBase *phy =
nullptr;
448 TrafficGeneratorBase *trafficGen =
nullptr;
452inline std::ostream& operator<<(std::ostream& os,
const UeAllocationInfo& e)
454 os <<
"node=" << e.nodeId <<
" cell=" << e.cellId <<
" dir=" << e.dir;
458typedef std::vector<ExtCell *> ExtCellList;
459typedef std::vector<BackgroundScheduler *> BackgroundSchedulerList;
465typedef std::vector<std::vector<std::vector<double>>> BlerCurves;
469 unsigned int numDlSymbols;
470 unsigned int numUlSymbols;
471 unsigned int numFlexSymbols;
474inline std::ostream& operator<<(std::ostream& os,
const SlotFormat& e)
476 os <<
"tdd=" << e.tdd <<
" dl=" << e.numDlSymbols <<
" ul=" << e.numUlSymbols <<
" flex=" << e.numFlexSymbols;
481 GHz carrierFrequency;
482 unsigned int numBands;
483 unsigned int firstBand;
484 unsigned int lastBand;
485 BandLimitVector bandLimit;
487 SlotFormat slotFormat;
490inline std::ostream& operator<<(std::ostream& os,
const CarrierInfo& e)
492 os <<
"freq=" << e.carrierFrequency <<
" numBands=" << e.numBands
493 <<
" bands=[" << e.firstBand <<
"," << e.lastBand <<
"] numerology=" << e.numerologyIndex
494 <<
" slot={" << e.slotFormat <<
"} bandLimitEntries=" << e.bandLimit.size();
498typedef std::map<GHz, CarrierInfo> CarrierInfoMap;
504typedef std::vector<Cqi> CqiVector;
505typedef std::set<Band> BandSet;
506typedef std::set<Remote> RemoteSet;
507typedef std::map<MacNodeId, bool> ConnectedUesMap;
508typedef std::pair<int, simtime_t> PacketInfo;
509typedef std::set<MacNodeId> ActiveUser;
510typedef std::set<MacCid> ActiveSet;
524const std::string dirToA(Direction dir);
528const std::string d2dModeToA(LteD2DMode mode);
529const std::string allocationTypeToA(RbAllocationType type);
530const std::string modToA(LteMod mod);
531const std::string periodicityToA(FbPeriodicity per);
532const std::string txModeToA(TxMode tx);
533TxMode aToTxMode(std::string s);
534const std::string schedDisciplineToA(SchedDiscipline discipline);
535SchedDiscipline aToSchedDiscipline(std::string s);
536Remote aToDas(std::string s);
537const std::string dasToA(
const Remote r);
538const char *nodeTypeToA(RanNodeType t);
539RanNodeType aToNodeType(std::string name);
540RanNodeType getNodeTypeById(MacNodeId
id);
541bool isBaseStation(CoreNodeType nodeType);
542void verifyControlInfo(
const FlowControlInfo *info);
543bool isNrUe(MacNodeId
id);
544FeedbackType getFeedbackType(std::string s);
545RbAllocationType getRbAllocationType(std::string s);
546const std::string phyFrameTypeToA(
const LtePhyFrameType r);
547LtePhyFrameType aToPhyFrameType(std::string s);
548const std::string rlcModeToA(RlcMode type);
549char *cStringToLower(
char *str);
550RlcMode aToRlcMode(std::string s);
551const std::string sessionTypeToA(SessionType type);
552SessionType aToSessionType(std::string s);
553bool isIpSessionType(SessionType type);
554const std::string coreNetworkToA(CoreNetwork type);
555CoreNetwork aToCoreNetwork(std::string s);
556const std::string cellGroupToA(CellGroup group);
557CellGroup aToCellGroup(std::string s);
561void configurePacketFilter(inet::PacketFilter& filter,
const char *spec);
567omnetpp::cDynamicExpression *getExpressionFromPar(omnetpp::cPar& par, omnetpp::cDynamicExpression::IResolver *resolver);
568const std::string planeToA(Plane p);
569MacNodeId ctrlInfoToUeId(
const FlowControlInfo *info);
570DrbKey ctrlInfoToTxDrbKey(
const FlowControlInfo *info);
571DrbKey ctrlInfoToRxDrbKey(
const FlowControlInfo *info);
572const std::string DeploymentScenarioToA(DeploymentScenario type);
573DeploymentScenario aToDeploymentScenario(std::string s);
582 return num(nodeId) >= MULTICAST_DEST_MIN_ID;
619void removeAllSimu5GTags(inet::Packet *pkt);
622bool checkIfHeaderType(
const inet::Packet *pkt,
bool checkFirst =
false) {
624 auto pktAux = pkt->dup();
627 while (pktAux->getBitLength() > 0 && pktAux->peekAtFront<inet::Chunk>()) {
628 auto chunk = pktAux->popAtFront<inet::Chunk>();
629 if (inet::dynamicPtrCast<const T>(chunk)) {
631 if (index != 0 && checkFirst)
632 throw cRuntimeError(
"The header is not the top");
There is one CellInfo module for each eNB (thus one for each cell). Keeps cross-layer information abo...
Definition CellInfo.h:30
Definition LteTypes.h:191
MAC Layer.
Definition LteMacBase.h:80
Buffers for MAC packets.
Definition LteMacBuffer.h:28
Queue for MAC SDU packets.
Definition LteMacQueue.h:41
Definition LteCommon.h:74
Definition StochasticChannelModel.h:74
Definition AlertReceiver.h:24
unsigned short Tbs
Transport Block Size.
Definition LteTypes.h:137
std::list< MacControlElement * > MacControlElementsList
Definition LteCommon.h:374
std::map< std::string, cMsgPar > ParameterMap
Definition LteCommon.h:518
unsigned short Band
Logical band.
Definition LteTypes.h:140
void getParametersFromXML(cXMLElement *xmlData, ParameterMap &outputMap)
unsigned short Codeword
Codeword.
Definition LteCommon.h:202
std::list< inet::Packet * > RlcSduList
Definition LteCommon.h:361
std::list< X2InformationElement * > X2InformationElementsList
Definition LteCommon.h:249
Direction directionFromBsrLcid(LogicalCid lcid, Direction fallback)
const unsigned char DL_NUM_TXMODE
Number of transmission modes in DL direction.
Definition LteCommon.h:216
void parseStringToIntArray(std::string str, int *values, int dim, int pad)
MacNodeId MacCellId
Cell node ID. It is numerically equal to eNodeB MAC node ID.
Definition LteTypes.h:66
std::map< std::pair< MacCid, Codeword >, unsigned int > LteMacScheduleList
Definition LteCommon.h:344
const unsigned char UL_NUM_TXMODE
Number of transmission modes in UL direction.
Definition LteCommon.h:219
void initializeAllChannels(cModule *mod)
unsigned short Cqi
Channel Quality Indicator.
Definition LteTypes.h:133
std::set< MacNodeId > UeSet
Definition LteCommon.h:379
unsigned short Rank
Connection Identifier: <MacNodeId,LogicalCid>
Definition LteTypes.h:130
std::pair< unsigned char, CwList > UnitList
Pair of acid, list of unit ids.
Definition LteCommon.h:395
unsigned short NumerologyIndex
Numerology Index.
Definition LteCommon.h:205
bool isMulticastDestId(MacNodeId nodeId)
Definition LteCommon.h:581
std::map< std::pair< MacNodeId, Codeword >, inet::Packet * > MacPduList
Definition LteCommon.h:350
constexpr MacNodeId NODEID_NONE
MAC node ID.
Definition LteTypes.h:54
cPacketQueue MacSduList
Definition LteCommon.h:368
Definition LteCommon.h:259
Band band_
Band which the element refers to.
Definition LteCommon.h:261
std::vector< int > limit_
Limit of bytes (per codeword) which can be requested for the current band.
Definition LteCommon.h:263