RohcCompressor.h Source File

Simu5G: RohcCompressor.h Source File
Simu5G
RohcCompressor.h
1//
2// Simu5G
3//
4// Copyright (C) 2026 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 _ROHC_COMPRESSOR_H_
13#define _ROHC_COMPRESSOR_H_
14
15#include <map>
16#include <set>
17#include <string>
18#include <vector>
19
20#include <inet/common/packet/Packet.h>
21
22namespace simu5g {
23
24// The ROHC profiles the model implements (RFC 3095, RFC 3843, RFC 6846)
25enum RohcProfile {
26 ROHC_UNCOMPRESSED, // 0x0000: none of the bearer's profiles fits the packet
27 ROHC_RTP, // 0x0001: IP + UDP + RTP headers
28 ROHC_UDP, // 0x0002: IP + UDP headers
29 ROHC_TCP, // 0x0006: IP + TCP headers
30 ROHC_IP // 0x0004: the IP header only
31};
32
33// The name of a profile in the bearer configuration ("rtp", "udp", "tcp", "ip")
34const char *rohcProfileName(RohcProfile profile);
35
36// The profile with the given configuration name; throws for an unknown or unmodeled one
37RohcProfile parseRohcProfile(const std::string& name);
38
39// The configuration names of the profiles a bearer can be configured with, most specific first
40const std::vector<std::string>& rohcProfileNames();
41
67class RohcCompressor
68{
69 public:
70 enum State { IR, FO, SO };
71
72 struct Parameters {
73 std::set<RohcProfile> profiles; // the bearer's configured profiles
74 std::map<RohcProfile, inet::B> foHeaderSize; // compressed header size per profile, FO state
75 std::map<RohcProfile, inet::B> soHeaderSize; // compressed header size per profile, SO state
76 inet::B irOverhead = inet::B(3); // IR packet: packet type, profile, CRC
77 int irPackets = 3; // IR packets before moving to FO
78 int foPackets = 3; // FO packets before moving to SO
79 int irRefresh = 1700; // packets of a context between IR refreshes
80 int foRefresh = 700; // packets of a context between FO refreshes
81 };
82
83 static const int MAX_CONTEXTS = 16;
84
85 struct Result {
86 RohcProfile profile;
87 int cid;
88 State state;
89 inet::b compressedSize;
90 };
91
92 protected:
93 struct Context {
94 std::string flow; // the profile and the static header fields
95 State state = IR;
96 int packetsInState = 0; // since the context entered its state
97 int packetsSinceIr = 0;
98 int packetsSinceFo = 0;
99 uint64_t lastUsed = 0;
100 };
101
102 Parameters params_;
103 std::vector<Context> contexts_; // indexed by CID
104 uint64_t packetCount_ = 0;
105
106 virtual bool isAllowed(RohcProfile profile) const { return params_.profiles.count(profile) != 0; }
107
108 // The CID of the flow's context, creating it (in IR) if there is none
109 virtual int findOrCreateContext(const std::string& flow);
110
111 // The state the context's next packet is sent in; advances the context
112 virtual State nextState(Context& context);
113
114 public:
115 explicit RohcCompressor(const Parameters& params);
116 virtual ~RohcCompressor() {}
117
118 // Replaces the headers of the IP datagram at the front of the packet that its profile
119 // covers with a RohcHeader of the compressed size, which carries them
120 virtual Result compress(inet::Packet *pkt);
121
122 int getNumContexts() const { return contexts_.size(); }
123};
124
125const char *rohcStateName(RohcCompressor::State state);
126
127} // namespace simu5g
128
129#endif
Definition AlertReceiver.h:24