A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipcs-classifier-record.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008, 2009 INRIA, UDcast
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
7 */
9
10#include "wimax-tlv.h"
11
12#include "ns3/ipv4-address.h"
13
14#include <stdint.h>
15
16namespace ns3
17{
18
19NS_LOG_COMPONENT_DEFINE("IpcsClassifierRecord");
20
22{
23 m_priority = 255;
24 m_priority = 0;
25 m_index = 0;
26 m_tosLow = 0;
27 m_tosHigh = 0;
28 m_tosMask = 0;
29 m_cid = 0;
30 m_protocol.push_back(6); // tcp
31 m_protocol.push_back(17); // udp
32 AddSrcAddr(Ipv4Address("0.0.0.0"), Ipv4Mask("0.0.0.0"));
33 AddDstAddr(Ipv4Address("0.0.0.0"), Ipv4Mask("0.0.0.0"));
34 AddSrcPortRange(0, 65535);
35 AddDstPortRange(0, 65535);
36}
37
41
43{
45 "Invalid TLV");
48 m_priority = 0;
49 m_index = 0;
50 m_tosLow = 0;
51 m_tosHigh = 0;
52 m_tosMask = 0;
53 m_cid = 0;
54 for (auto iter = rules->Begin(); iter != rules->End(); ++iter)
55 {
56 switch ((*iter)->GetType())
57 {
59 m_priority = ((U8TlvValue*)((*iter)->PeekValue()))->GetValue();
60 break;
61 }
63 NS_FATAL_ERROR("ToS Not implemented-- please implement and contribute a patch");
64 break;
65 }
67 auto list = (ProtocolTlvValue*)(*iter)->PeekValue();
68 for (auto iter2 = list->Begin(); iter2 != list->End(); ++iter2)
69 {
70 AddProtocol(*iter2);
71 }
72 break;
73 }
75 auto list = (Ipv4AddressTlvValue*)(*iter)->PeekValue();
76 for (auto iter2 = list->Begin(); iter2 != list->End(); ++iter2)
77 {
78 AddSrcAddr((*iter2).Address, (*iter2).Mask);
79 }
80 break;
81 }
83 auto list = (Ipv4AddressTlvValue*)(*iter)->PeekValue();
84 for (auto iter2 = list->Begin(); iter2 != list->End(); ++iter2)
85 {
86 AddDstAddr((*iter2).Address, (*iter2).Mask);
87 }
88 break;
89 }
91 auto list = (PortRangeTlvValue*)(*iter)->PeekValue();
92 for (auto iter2 = list->Begin(); iter2 != list->End(); ++iter2)
93 {
94 AddSrcPortRange((*iter2).PortLow, (*iter2).PortHigh);
95 }
96 break;
97 }
99 auto list = (PortRangeTlvValue*)(*iter)->PeekValue();
100 for (auto iter2 = list->Begin(); iter2 != list->End(); ++iter2)
101 {
102 AddDstPortRange((*iter2).PortLow, (*iter2).PortHigh);
103 }
104 break;
105 }
107 m_index = ((U16TlvValue*)((*iter)->PeekValue()))->GetValue();
108 break;
109 }
110 }
111 }
112}
113
115 Ipv4Mask SrcMask,
116 Ipv4Address DstAddress,
117 Ipv4Mask DstMask,
118 uint16_t SrcPortLow,
119 uint16_t SrcPortHigh,
120 uint16_t DstPortLow,
121 uint16_t DstPortHigh,
122 uint8_t protocol,
123 uint8_t priority)
124{
125 m_priority = priority;
126 m_protocol.push_back(protocol);
127 AddSrcAddr(SrcAddress, SrcMask);
128 AddDstAddr(DstAddress, DstMask);
129 AddSrcPortRange(SrcPortLow, SrcPortHigh);
130 AddDstPortRange(DstPortLow, DstPortHigh);
131 m_index = 0;
132 m_tosLow = 0;
133 m_tosHigh = 0;
134 m_tosMask = 0;
135 m_cid = 0;
136}
137
138void
140{
141 Ipv4Addr tmp;
142 tmp.Address = srcAddress;
143 tmp.Mask = srcMask;
144 m_srcAddr.push_back(tmp);
145}
146
147void
149{
150 Ipv4Addr tmp;
151 tmp.Address = dstAddress;
152 tmp.Mask = dstMask;
153 m_dstAddr.push_back(tmp);
154}
155
156void
157IpcsClassifierRecord::AddSrcPortRange(uint16_t srcPortLow, uint16_t srcPortHigh)
158{
159 PortRange tmp;
160 tmp.PortLow = srcPortLow;
161 tmp.PortHigh = srcPortHigh;
162 m_srcPortRange.push_back(tmp);
163}
164
165void
166IpcsClassifierRecord::AddDstPortRange(uint16_t dstPortLow, uint16_t dstPortHigh)
167{
168 PortRange tmp;
169 tmp.PortLow = dstPortLow;
170 tmp.PortHigh = dstPortHigh;
171 m_dstPortRange.push_back(tmp);
172}
173
174void
176{
177 m_protocol.push_back(proto);
178}
179
180void
182{
183 m_priority = prio;
184}
185
186void
188{
189 m_cid = cid;
190}
191
192void
194{
195 m_index = index;
196}
197
198uint16_t
200{
201 return m_index;
202}
203
204uint16_t
206{
207 return m_cid;
208}
209
210uint8_t
212{
213 return m_priority;
214}
215
216bool
218{
219 for (auto iter = m_srcAddr.begin(); iter != m_srcAddr.end(); ++iter)
220 {
221 NS_LOG_INFO("src addr check match: pkt=" << srcAddress << " cls=" << (*iter).Address << "/"
222 << (*iter).Mask);
223 if (srcAddress.CombineMask((*iter).Mask) == (*iter).Address)
224 {
225 return true;
226 }
227 }
228 NS_LOG_INFO("NOT OK!");
229 return false;
230}
231
232bool
234{
235 for (auto iter = m_dstAddr.begin(); iter != m_dstAddr.end(); ++iter)
236 {
237 NS_LOG_INFO("dst addr check match: pkt=" << dstAddress << " cls=" << (*iter).Address << "/"
238 << (*iter).Mask);
239 if (dstAddress.CombineMask((*iter).Mask) == (*iter).Address)
240 {
241 return true;
242 }
243 }
244 NS_LOG_INFO("NOT OK!");
245 return false;
246}
247
248bool
250{
251 for (auto iter = m_srcPortRange.begin(); iter != m_srcPortRange.end(); ++iter)
252 {
253 NS_LOG_INFO("src port check match: pkt=" << port << " cls= [" << (*iter).PortLow << " TO "
254 << (*iter).PortHigh << "]");
255 if (port >= (*iter).PortLow && port <= (*iter).PortHigh)
256 {
257 return true;
258 }
259 }
260 NS_LOG_INFO("NOT OK!");
261 return false;
262}
263
264bool
266{
267 for (auto iter = m_dstPortRange.begin(); iter != m_dstPortRange.end(); ++iter)
268 {
269 NS_LOG_INFO("dst port check match: pkt=" << port << " cls= [" << (*iter).PortLow << " TO "
270 << (*iter).PortHigh << "]");
271 if (port >= (*iter).PortLow && port <= (*iter).PortHigh)
272 {
273 return true;
274 }
275 }
276 NS_LOG_INFO("NOT OK!");
277 return false;
278}
279
280bool
282{
283 for (auto iter = m_protocol.begin(); iter != m_protocol.end(); ++iter)
284 {
285 NS_LOG_INFO("proto check match: pkt=" << (uint16_t)proto << " cls=" << (uint16_t)proto);
286 if (proto == (*iter))
287 {
288 return true;
289 }
290 }
291 NS_LOG_INFO("NOT OK!");
292 return false;
293}
294
295bool
297 Ipv4Address dstAddress,
298 uint16_t srcPort,
299 uint16_t dstPort,
300 uint8_t proto) const
301{
302 return (CheckMatchProtocol(proto) && CheckMatchDstPort(dstPort) && CheckMatchSrcPort(srcPort) &&
303 CheckMatchDstAddr(dstAddress) && CheckMatchSrcAddr(srcAddress));
304}
305
306Tlv
308{
309 Ipv4AddressTlvValue ipv4AddrValSrc;
310 for (auto iter = m_srcAddr.begin(); iter != m_srcAddr.end(); ++iter)
311 {
312 ipv4AddrValSrc.Add((*iter).Address, (*iter).Mask);
313 }
314
315 Ipv4AddressTlvValue ipv4AddrValDst;
316 for (auto iter = m_dstAddr.begin(); iter != m_dstAddr.end(); ++iter)
317 {
318 ipv4AddrValDst.Add((*iter).Address, (*iter).Mask);
319 }
320
321 ProtocolTlvValue protoVal;
322 for (auto iter = m_protocol.begin(); iter != m_protocol.end(); ++iter)
323 {
324 protoVal.Add(*iter);
325 }
326
327 PortRangeTlvValue portValueSrc;
328 for (auto iter = m_srcPortRange.begin(); iter != m_srcPortRange.end(); ++iter)
329 {
330 portValueSrc.Add((*iter).PortLow, (*iter).PortHigh);
331 }
332
333 PortRangeTlvValue portValueDst;
334 for (auto iter = m_dstPortRange.begin(); iter != m_dstPortRange.end(); ++iter)
335 {
336 portValueDst.Add((*iter).PortLow, (*iter).PortHigh);
337 }
338
341 ClassVectVal.Add(
344 ipv4AddrValSrc.GetSerializedSize(),
345 ipv4AddrValSrc));
347 ipv4AddrValDst.GetSerializedSize(),
348 ipv4AddrValDst));
350 portValueSrc.GetSerializedSize(),
351 portValueSrc));
353 portValueDst.GetSerializedSize(),
354 portValueDst));
356
358 ClassVectVal.GetSerializedSize(),
359 ClassVectVal);
360
361 return tmp_tlv;
362}
363
364} // namespace ns3
this class implements the classifier descriptor as a tlv vector
Definition wimax-tlv.h:397
void SetPriority(uint8_t prio)
Set the priority of this classifier.
std::vector< PortRange > m_dstPortRange
destination port range
bool CheckMatchSrcAddr(Ipv4Address srcAddress) const
Check match source address function.
bool CheckMatchProtocol(uint8_t proto) const
Check match protocol function.
void SetIndex(uint16_t index)
Set the index of the classifier.
void AddDstAddr(Ipv4Address dstAddress, Ipv4Mask dstMask)
add a new destination ip address to the classifier
bool CheckMatchSrcPort(uint16_t srcPort) const
Check match source port function.
std::vector< PortRange > m_srcPortRange
source port range
void AddSrcPortRange(uint16_t srcPortLow, uint16_t srcPortHigh)
add a range of source port to the classifier
std::vector< Ipv4Addr > m_dstAddr
destination address
bool CheckMatchDstAddr(Ipv4Address dstAddress) const
Check match destination address function.
Tlv ToTlv() const
Creates a TLV from this classifier.
bool CheckMatch(Ipv4Address srcAddress, Ipv4Address dstAddress, uint16_t srcPort, uint16_t dstPort, uint8_t proto) const
check if a packets can be used with this classifier
void SetCid(uint16_t cid)
Set the cid associated to this classifier.
void AddDstPortRange(uint16_t dstPortLow, uint16_t dstPortHigh)
add a range of destination port to the classifier
std::vector< uint8_t > m_protocol
protocol
void AddSrcAddr(Ipv4Address srcAddress, Ipv4Mask srcMask)
add a new source ip address to the classifier
std::vector< Ipv4Addr > m_srcAddr
source address
void AddProtocol(uint8_t proto)
add a protocol to the classifier
bool CheckMatchDstPort(uint16_t dstPort) const
Check match destination port function.
Ipv4 addresses are stored in host order in this class.
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
Ipv4AddressTlvValue class.
Definition wimax-tlv.h:562
void Add(Ipv4Address address, Ipv4Mask mask)
Add IPv4 address and mask.
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
a class to represent an Ipv4 address mask
PortRangeTlvValue class.
Definition wimax-tlv.h:473
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition wimax-tlv.cc:862
void Add(uint16_t portLow, uint16_t portHigh)
Add a range.
Definition wimax-tlv.cc:892
ProtocolTlvValue class.
Definition wimax-tlv.h:521
void Add(uint8_t protocol)
Add protocol number.
Definition wimax-tlv.cc:968
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition wimax-tlv.cc:941
This class implements the Type-Len-Value structure channel encodings as described by "IEEEStandard fo...
Definition wimax-tlv.h:76
uint8_t GetType() const
Get type value.
Definition wimax-tlv.cc:200
TlvValue * PeekValue()
Peek value.
Definition wimax-tlv.cc:212
U16TlvValue class.
Definition wimax-tlv.h:204
U8TlvValue class.
Definition wimax-tlv.h:164
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition wimax-tlv.cc:240
Iterator End() const
End iterator.
Definition wimax-tlv.cc:267
Iterator Begin() const
Begin iterator.
Definition wimax-tlv.cc:261
void Add(const Tlv &val)
Add a TLV.
Definition wimax-tlv.cc:273
uint16_t port
Definition dsdv-manet.cc:33
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Every class exported by the ns3 library is enclosed in the ns3 namespace.