ReflectiveQosTable.h Source File

Simu5G: ReflectiveQosTable.h Source File
Simu5G
ReflectiveQosTable.h
1//
2// Simu5G
3//
4// Authors: Andras Varga (OpenSim Ltd)
5//
6// This file is part of a software released under the license included in file
7// "license.pdf". Please read LICENSE and README files before using it.
8// The above files and the present reference are part of the software itself,
9// and cannot be removed from it.
10//
11
12#ifndef STACK_SDAP_COMMON_REFLECTIVEQOSTABLE_H_
13#define STACK_SDAP_COMMON_REFLECTIVEQOSTABLE_H_
14
15#include <omnetpp.h>
16#include <map>
17#include <set>
18#include <string>
19#include <inet/common/packet/Packet.h>
20#include "simu5g/common/LteTypes.h"
21
22using namespace omnetpp;
23
24namespace simu5g {
25
26// Structure to represent a flow key (5-tuple)
27struct FlowKey {
28 std::string srcAddr;
29 std::string dstAddr;
30 uint16_t srcPort = 0;
31 uint16_t dstPort = 0;
32 uint8_t protocol = 0;
33
34 // Constructor
35 FlowKey() = default;
36 FlowKey(const std::string& src, const std::string& dst, uint16_t sp, uint16_t dp, uint8_t prot)
37 : srcAddr(src), dstAddr(dst), srcPort(sp), dstPort(dp), protocol(prot) {}
38
39 // Generate string representation for map keys
40 std::string toString() const {
41 return srcAddr + ":" + std::to_string(srcPort) + "->" +
42 dstAddr + ":" + std::to_string(dstPort) + "/" + std::to_string(protocol);
43 }
44
45 // Generate reverse flow key (swap src/dst)
46 FlowKey reverse() const {
47 return FlowKey(dstAddr, srcAddr, dstPort, srcPort, protocol);
48 }
49
50 // Comparison operators for use in maps
51 bool operator<(const FlowKey& other) const {
52 if (srcAddr != other.srcAddr) return srcAddr < other.srcAddr;
53 if (dstAddr != other.dstAddr) return dstAddr < other.dstAddr;
54 if (srcPort != other.srcPort) return srcPort < other.srcPort;
55 if (dstPort != other.dstPort) return dstPort < other.dstPort;
56 return protocol < other.protocol;
57 }
58
59 bool operator==(const FlowKey& other) const {
60 return srcAddr == other.srcAddr && dstAddr == other.dstAddr &&
61 srcPort == other.srcPort && dstPort == other.dstPort &&
62 protocol == other.protocol;
63 }
64};
65
66inline std::ostream& operator<<(std::ostream& os, const FlowKey& k)
67{
68 os << k.srcAddr << ":" << k.srcPort << "->" << k.dstAddr << ":" << k.dstPort
69 << "/" << (unsigned int)k.protocol;
70 return os;
71}
72
73// Structure to store reflective QoS flow information
74struct ReflectiveQosFlow {
75 Qfi qfi = QFI_NONE;
76 FlowKey flowKey;
77 simtime_t lastSeen;
78 bool isActive = true;
79
80 // Constructor
81 ReflectiveQosFlow() = default;
82 ReflectiveQosFlow(Qfi q, const FlowKey& key)
83 : qfi(q), flowKey(key), lastSeen(simTime()), isActive(true) {}
84};
85
86inline std::ostream& operator<<(std::ostream& os, const ReflectiveQosFlow& f)
87{
88 os << "qfi=" << f.qfi << " flow=" << f.flowKey << " lastSeen=" << f.lastSeen
89 << (f.isActive ? " active" : " inactive");
90 return os;
91}
92
106class ReflectiveQosTable : public cSimpleModule
107{
108 private:
109 // Configuration (from module parameters)
110 simtime_t timeout_ = 30;
111
112 std::map<FlowKey, ReflectiveQosFlow> reflectiveFlows_;
113 cMessage *cleanupTimer_ = nullptr;
114
115 protected:
116 virtual void initialize() override;
117 virtual void handleMessage(cMessage *msg) override;
118 virtual void finish() override;
119
120 public:
121 // Constructor and destructor
122 ReflectiveQosTable();
123 virtual ~ReflectiveQosTable();
124
125 // Core reflective QoS functionality
126 virtual void handleDownlinkFlow(inet::Packet *pkt, Qfi qfi);
127 virtual Qfi lookupUplinkQfi(inet::Packet *pkt);
128
129 // Flow management
130 virtual void cleanupExpiredFlows();
131 size_t getActiveFlowCount() const { return reflectiveFlows_.size(); }
132 virtual void clearAllFlows();
133
134 // Debug and monitoring
135 virtual void printFlows() const;
136
137 private:
138 // Helper methods
139 virtual FlowKey extractFlowKey(inet::Packet *pkt) const;
140
141 // Timer management
142 virtual void scheduleCleanupTimer();
143 virtual void cancelCleanupTimer();
144};
145
146} // namespace simu5g
147
148#endif /* STACK_SDAP_COMMON_REFLECTIVEQOSTABLE_H_ */
Definition AlertReceiver.h:24
constexpr Qfi QFI_NONE
Logical Connection Identifier (used in MAC layer)
Definition LteTypes.h:82