A Discrete-Event Network Simulator
API
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 struct ipv4Addr tmp;
162 tmp.Address = srcAddress;
163 tmp.Mask = srcMask;
164 m_srcAddr.push_back(tmp);
165}
166
167void
169{
170 struct 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 struct 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 struct 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<struct ipv4Addr>::const_iterator iter = m_srcAddr.begin();
240 iter != m_srcAddr.end();
241 ++iter)
242 {
243 NS_LOG_INFO("src addr check match: pkt=" << srcAddress << " cls=" << (*iter).Address << "/"
244 << (*iter).Mask);
245 if (srcAddress.CombineMask((*iter).Mask) == (*iter).Address)
246 {
247 return true;
248 }
249 }
250 NS_LOG_INFO("NOT OK!");
251 return false;
252}
253
254bool
256{
257 for (std::vector<struct ipv4Addr>::const_iterator iter = m_dstAddr.begin();
258 iter != m_dstAddr.end();
259 ++iter)
260 {
261 NS_LOG_INFO("dst addr check match: pkt=" << dstAddress << " cls=" << (*iter).Address << "/"
262 << (*iter).Mask);
263 if (dstAddress.CombineMask((*iter).Mask) == (*iter).Address)
264 {
265 return true;
266 }
267 }
268 NS_LOG_INFO("NOT OK!");
269 return false;
270}
271
272bool
274{
275 for (std::vector<struct PortRange>::const_iterator iter = m_srcPortRange.begin();
276 iter != m_srcPortRange.end();
277 ++iter)
278 {
279 NS_LOG_INFO("src port check match: pkt=" << port << " cls= [" << (*iter).PortLow << " TO "
280 << (*iter).PortHigh << "]");
281 if (port >= (*iter).PortLow && port <= (*iter).PortHigh)
282 {
283 return true;
284 }
285 }
286 NS_LOG_INFO("NOT OK!");
287 return false;
288}
289
290bool
292{
293 for (std::vector<struct PortRange>::const_iterator iter = m_dstPortRange.begin();
294 iter != m_dstPortRange.end();
295 ++iter)
296 {
297 NS_LOG_INFO("dst port check match: pkt=" << port << " cls= [" << (*iter).PortLow << " TO "
298 << (*iter).PortHigh << "]");
299 if (port >= (*iter).PortLow && port <= (*iter).PortHigh)
300 {
301 return true;
302 }
303 }
304 NS_LOG_INFO("NOT OK!");
305 return false;
306}
307
308bool
310{
311 for (std::vector<uint8_t>::const_iterator iter = m_protocol.begin(); iter != m_protocol.end();
312 ++iter)
313 {
314 NS_LOG_INFO("proto check match: pkt=" << (uint16_t)proto << " cls=" << (uint16_t)proto);
315 if (proto == (*iter))
316 {
317 return true;
318 }
319 }
320 NS_LOG_INFO("NOT OK!");
321 return false;
322}
323
324bool
326 Ipv4Address dstAddress,
327 uint16_t srcPort,
328 uint16_t dstPort,
329 uint8_t proto) const
330{
331 return (CheckMatchProtocol(proto) && CheckMatchDstPort(dstPort) && CheckMatchSrcPort(srcPort) &&
332 CheckMatchDstAddr(dstAddress) && CheckMatchSrcAddr(srcAddress));
333}
334
335Tlv
337{
338 Ipv4AddressTlvValue ipv4AddrValSrc;
339 for (std::vector<struct ipv4Addr>::const_iterator iter = m_srcAddr.begin();
340 iter != m_srcAddr.end();
341 ++iter)
342 {
343 ipv4AddrValSrc.Add((*iter).Address, (*iter).Mask);
344 }
345
346 Ipv4AddressTlvValue ipv4AddrValDst;
347 for (std::vector<struct ipv4Addr>::const_iterator iter = m_dstAddr.begin();
348 iter != m_dstAddr.end();
349 ++iter)
350 {
351 ipv4AddrValDst.Add((*iter).Address, (*iter).Mask);
352 }
353
354 ProtocolTlvValue protoVal;
355 for (std::vector<uint8_t>::const_iterator iter = m_protocol.begin(); iter != m_protocol.end();
356 ++iter)
357 {
358 protoVal.Add((*iter));
359 }
360
361 PortRangeTlvValue portValueSrc;
362 for (std::vector<struct PortRange>::const_iterator iter = m_srcPortRange.begin();
363 iter != m_srcPortRange.end();
364 ++iter)
365 {
366 portValueSrc.Add((*iter).PortLow, (*iter).PortHigh);
367 }
368
369 PortRangeTlvValue portValueDst;
370 for (std::vector<struct PortRange>::const_iterator iter = m_dstPortRange.begin();
371 iter != m_dstPortRange.end();
372 ++iter)
373 {
374 portValueDst.Add((*iter).PortLow, (*iter).PortHigh);
375 }
376
379 ClassVectVal.Add(
382 ipv4AddrValSrc.GetSerializedSize(),
383 ipv4AddrValSrc));
385 ipv4AddrValDst.GetSerializedSize(),
386 ipv4AddrValDst));
388 portValueSrc.GetSerializedSize(),
389 portValueSrc));
391 portValueDst.GetSerializedSize(),
392 portValueDst));
394
396 ClassVectVal.GetSerializedSize(),
397 ClassVectVal);
398
399 return tmp_tlv;
400}
401
402} // 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.
bool CheckMatchSrcAddr(Ipv4Address srcAddress) const
Check match source address function.
bool CheckMatchProtocol(uint8_t proto) const
Check match protocol function.
std::vector< struct PortRange > m_dstPortRange
destination port range
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
std::vector< struct PortRange > m_srcPortRange
surce port range
bool CheckMatchSrcPort(uint16_t srcPort) const
Check match source port function.
std::vector< struct ipv4Addr > m_srcAddr
source address
void AddSrcPortRange(uint16_t srcPortLow, uint16_t srcPortHigh)
add a range of source port to the classifier
std::vector< struct 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
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:43
Ipv4Address CombineMask(const Ipv4Mask &mask) const
Combine this address with a network mask.
Ipv4AddressTlvValue class.
Definition: wimax-tlv.h:572
uint32_t GetSerializedSize() const override
Get serialized size in bytes.
Definition: wimax-tlv.cc:1041
void Add(Ipv4Address address, Ipv4Mask Mask)
Add IPv4 address and mask.
Definition: wimax-tlv.cc:1073
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
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:531
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:45
#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:160
#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