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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
18 */
20
21#include "wimax-tlv.h"
22
23#include "ns3/ipv4-address.h"
24
25#include <stdint.h>
26
27namespace ns3
28{
29
30NS_LOG_COMPONENT_DEFINE("IpcsClassifierRecord");
31
33{
34 m_priority = 255;
35 m_priority = 0;
36 m_index = 0;
37 m_tosLow = 0;
38 m_tosHigh = 0;
39 m_tosMask = 0;
40 m_cid = 0;
41 m_protocol.push_back(6); // tcp
42 m_protocol.push_back(17); // udp
43 AddSrcAddr(Ipv4Address("0.0.0.0"), Ipv4Mask("0.0.0.0"));
44 AddDstAddr(Ipv4Address("0.0.0.0"), Ipv4Mask("0.0.0.0"));
45 AddSrcPortRange(0, 65535);
46 AddDstPortRange(0, 65535);
47}
48
50{
51}
52
54{
56 "Invalid TLV");
59 m_priority = 0;
60 m_index = 0;
61 m_tosLow = 0;
62 m_tosHigh = 0;
63 m_tosMask = 0;
64 m_cid = 0;
65 for (std::vector<Tlv*>::const_iterator iter = rules->Begin(); iter != rules->End(); ++iter)
66 {
67 switch ((*iter)->GetType())
68 {
70 m_priority = ((U8TlvValue*)((*iter)->PeekValue()))->GetValue();
71 break;
72 }
74 NS_FATAL_ERROR("ToS Not implemented-- please implement and contribute a patch");
75 break;
76 }
78 ProtocolTlvValue* list = (ProtocolTlvValue*)(*iter)->PeekValue();
79 for (std::vector<uint8_t>::const_iterator iter2 = list->Begin(); iter2 != list->End();
80 ++iter2)
81 {
82 AddProtocol(*iter2);
83 }
84 break;
85 }
87 Ipv4AddressTlvValue* list = (Ipv4AddressTlvValue*)(*iter)->PeekValue();
88 for (std::vector<Ipv4AddressTlvValue::Ipv4Addr>::const_iterator iter2 = list->Begin();
89 iter2 != list->End();
90 ++iter2)
91 {
92 AddSrcAddr((*iter2).Address, (*iter2).Mask);
93 }
94 break;
95 }
97 Ipv4AddressTlvValue* list = (Ipv4AddressTlvValue*)(*iter)->PeekValue();
98 for (std::vector<Ipv4AddressTlvValue::Ipv4Addr>::const_iterator iter2 = list->Begin();
99 iter2 != list->End();
100 ++iter2)
101 {
102 AddDstAddr((*iter2).Address, (*iter2).Mask);
103 }
104 break;
105 }
107 PortRangeTlvValue* list = (PortRangeTlvValue*)(*iter)->PeekValue();
108 for (std::vector<PortRangeTlvValue::PortRange>::const_iterator iter2 = list->Begin();
109 iter2 != list->End();
110 ++iter2)
111 {
112 AddSrcPortRange((*iter2).PortLow, (*iter2).PortHigh);
113 }
114 break;
115 }
117 PortRangeTlvValue* list = (PortRangeTlvValue*)(*iter)->PeekValue();
118 for (std::vector<PortRangeTlvValue::PortRange>::const_iterator iter2 = list->Begin();
119 iter2 != list->End();
120 ++iter2)
121 {
122 AddDstPortRange((*iter2).PortLow, (*iter2).PortHigh);
123 }
124 break;
125 }
127 m_index = ((U16TlvValue*)((*iter)->PeekValue()))->GetValue();
128 break;
129 }
130 }
131 }
132}
133
135 Ipv4Mask SrcMask,
136 Ipv4Address DstAddress,
137 Ipv4Mask DstMask,
138 uint16_t SrcPortLow,
139 uint16_t SrcPortHigh,
140 uint16_t DstPortLow,
141 uint16_t DstPortHigh,
142 uint8_t protocol,
143 uint8_t priority)
144{
145 m_priority = priority;
146 m_protocol.push_back(protocol);
147 AddSrcAddr(SrcAddress, SrcMask);
148 AddDstAddr(DstAddress, DstMask);
149 AddSrcPortRange(SrcPortLow, SrcPortHigh);
150 AddDstPortRange(DstPortLow, DstPortHigh);
151 m_index = 0;
152 m_tosLow = 0;
153 m_tosHigh = 0;
154 m_tosMask = 0;
155 m_cid = 0;
156}
157
158void
160{
161 Ipv4Addr tmp;
162 tmp.Address = srcAddress;
163 tmp.Mask = srcMask;
164 m_srcAddr.push_back(tmp);
165}
166
167void
169{
170 Ipv4Addr tmp;
171 tmp.Address = dstAddress;
172 tmp.Mask = dstMask;
173 m_dstAddr.push_back(tmp);
174}
175
176void
177IpcsClassifierRecord::AddSrcPortRange(uint16_t srcPortLow, uint16_t srcPortHigh)
178{
179 PortRange tmp;
180 tmp.PortLow = srcPortLow;
181 tmp.PortHigh = srcPortHigh;
182 m_srcPortRange.push_back(tmp);
183}
184
185void
186IpcsClassifierRecord::AddDstPortRange(uint16_t dstPortLow, uint16_t dstPortHigh)
187{
188 PortRange tmp;
189 tmp.PortLow = dstPortLow;
190 tmp.PortHigh = dstPortHigh;
191 m_dstPortRange.push_back(tmp);
192}
193
194void
196{
197 m_protocol.push_back(proto);
198}
199
200void
202{
203 m_priority = prio;
204}
205
206void
208{
209 m_cid = cid;
210}
211
212void
214{
215 m_index = index;
216}
217
218uint16_t
220{
221 return m_index;
222}
223
224uint16_t
226{
227 return m_cid;
228}
229
230uint8_t
232{
233 return m_priority;
234}
235
236bool
238{
239 for (std::vector<Ipv4Addr>::const_iterator iter = m_srcAddr.begin(); iter != m_srcAddr.end();
240 ++iter)
241 {
242 NS_LOG_INFO("src addr check match: pkt=" << srcAddress << " cls=" << (*iter).Address << "/"
243 << (*iter).Mask);
244 if (srcAddress.CombineMask((*iter).Mask) == (*iter).Address)
245 {
246 return true;
247 }
248 }
249 NS_LOG_INFO("NOT OK!");
250 return false;
251}
252
253bool
255{
256 for (std::vector<Ipv4Addr>::const_iterator iter = m_dstAddr.begin(); iter != m_dstAddr.end();
257 ++iter)
258 {
259 NS_LOG_INFO("dst addr check match: pkt=" << dstAddress << " cls=" << (*iter).Address << "/"
260 << (*iter).Mask);
261 if (dstAddress.CombineMask((*iter).Mask) == (*iter).Address)
262 {
263 return true;
264 }
265 }
266 NS_LOG_INFO("NOT OK!");
267 return false;
268}
269
270bool
272{
273 for (std::vector<PortRange>::const_iterator iter = m_srcPortRange.begin();
274 iter != m_srcPortRange.end();
275 ++iter)
276 {
277 NS_LOG_INFO("src port check match: pkt=" << port << " cls= [" << (*iter).PortLow << " TO "
278 << (*iter).PortHigh << "]");
279 if (port >= (*iter).PortLow && port <= (*iter).PortHigh)
280 {
281 return true;
282 }
283 }
284 NS_LOG_INFO("NOT OK!");
285 return false;
286}
287
288bool
290{
291 for (std::vector<PortRange>::const_iterator iter = m_dstPortRange.begin();
292 iter != m_dstPortRange.end();
293 ++iter)
294 {
295 NS_LOG_INFO("dst port check match: pkt=" << port << " cls= [" << (*iter).PortLow << " TO "
296 << (*iter).PortHigh << "]");
297 if (port >= (*iter).PortLow && port <= (*iter).PortHigh)
298 {
299 return true;
300 }
301 }
302 NS_LOG_INFO("NOT OK!");
303 return false;
304}
305
306bool
308{
309 for (std::vector<uint8_t>::const_iterator iter = m_protocol.begin(); iter != m_protocol.end();
310 ++iter)
311 {
312 NS_LOG_INFO("proto check match: pkt=" << (uint16_t)proto << " cls=" << (uint16_t)proto);
313 if (proto == (*iter))
314 {
315 return true;
316 }
317 }
318 NS_LOG_INFO("NOT OK!");
319 return false;
320}
321
322bool
324 Ipv4Address dstAddress,
325 uint16_t srcPort,
326 uint16_t dstPort,
327 uint8_t proto) const
328{
329 return (CheckMatchProtocol(proto) && CheckMatchDstPort(dstPort) && CheckMatchSrcPort(srcPort) &&
330 CheckMatchDstAddr(dstAddress) && CheckMatchSrcAddr(srcAddress));
331}
332
333Tlv
335{
336 Ipv4AddressTlvValue ipv4AddrValSrc;
337 for (std::vector<Ipv4Addr>::const_iterator iter = m_srcAddr.begin(); iter != m_srcAddr.end();
338 ++iter)
339 {
340 ipv4AddrValSrc.Add((*iter).Address, (*iter).Mask);
341 }
342
343 Ipv4AddressTlvValue ipv4AddrValDst;
344 for (std::vector<Ipv4Addr>::const_iterator iter = m_dstAddr.begin(); iter != m_dstAddr.end();
345 ++iter)
346 {
347 ipv4AddrValDst.Add((*iter).Address, (*iter).Mask);
348 }
349
350 ProtocolTlvValue protoVal;
351 for (std::vector<uint8_t>::const_iterator iter = m_protocol.begin(); iter != m_protocol.end();
352 ++iter)
353 {
354 protoVal.Add((*iter));
355 }
356
357 PortRangeTlvValue portValueSrc;
358 for (std::vector<PortRange>::const_iterator iter = m_srcPortRange.begin();
359 iter != m_srcPortRange.end();
360 ++iter)
361 {
362 portValueSrc.Add((*iter).PortLow, (*iter).PortHigh);
363 }
364
365 PortRangeTlvValue portValueDst;
366 for (std::vector<PortRange>::const_iterator iter = m_dstPortRange.begin();
367 iter != m_dstPortRange.end();
368 ++iter)
369 {
370 portValueDst.Add((*iter).PortLow, (*iter).PortHigh);
371 }
372
375 ClassVectVal.Add(
378 ipv4AddrValSrc.GetSerializedSize(),
379 ipv4AddrValSrc));
381 ipv4AddrValDst.GetSerializedSize(),
382 ipv4AddrValDst));
384 portValueSrc.GetSerializedSize(),
385 portValueSrc));
387 portValueDst.GetSerializedSize(),
388 portValueDst));
390
392 ClassVectVal.GetSerializedSize(),
393 ClassVectVal);
394
395 return tmp_tlv;
396}
397
398} // namespace ns3
this class implements the classifier descriptor as a tlv vector
Definition: wimax-tlv.h:408
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.
Definition: ipv4-address.h:42
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
Ipv4AddressTlvValue class.
Definition: wimax-tlv.h:573
void Add(Ipv4Address address, Ipv4Mask mask)
Add IPv4 address and mask.
Definition: wimax-tlv.cc:1073
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:1041
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:257
PortRangeTlvValue class.
Definition: wimax-tlv.h:484
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:883
void Add(uint16_t portLow, uint16_t portHigh)
Add a range.
Definition: wimax-tlv.cc:915
ProtocolTlvValue class.
Definition: wimax-tlv.h:532
void Add(uint8_t protocol)
Add protocol number.
Definition: wimax-tlv.cc:994
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:966
This class implements the Type-Len-Value structure channel encodings as described by "IEEE Standard f...
Definition: wimax-tlv.h:87
uint8_t GetType() const
Get type value.
Definition: wimax-tlv.cc:211
TlvValue * PeekValue()
Peek value.
Definition: wimax-tlv.cc:223
U16TlvValue class.
Definition: wimax-tlv.h:215
U8TlvValue class.
Definition: wimax-tlv.h:175
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:252
Iterator End() const
End iterator.
Definition: wimax-tlv.cc:281
Iterator Begin() const
Begin iterator.
Definition: wimax-tlv.cc:275
void Add(const Tlv &val)
Add a TLV.
Definition: wimax-tlv.cc:287
uint16_t port
Definition: dsdv-manet.cc:44
#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:86
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define list