A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
epc-tft.cc
Go to the documentation of this file.
1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2011 CTTC
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Nicola Baldo <nbaldo@cttc.es>
19
*/
20
21
22
23
24
#include "
epc-tft.h
"
25
#include "ns3/abort.h"
26
#include "ns3/log.h"
27
28
29
namespace
ns3 {
30
31
NS_LOG_COMPONENT_DEFINE
(
"EpcTft"
);
32
33
std::ostream&
operator<<
(std::ostream& os,
EpcTft::Direction
& d)
34
{
35
switch
(d)
36
{
37
case
EpcTft::DOWNLINK
:
38
os <<
"DOWNLINK"
;
39
break
;
40
case
EpcTft::UPLINK
:
41
os <<
"UPLINK"
;
42
break
;
43
default
:
44
os <<
"BIDIRECTIONAL"
;
45
break
;
46
}
47
return
os;
48
}
49
50
51
std::ostream&
operator<<
(std::ostream& os,
EpcTft::PacketFilter
& f)
52
{
53
os <<
" direction: "
<< f.
direction
54
<<
" remoteAddress: "
<< f.
remoteAddress
55
<<
" remoteMask: "
<< f.
remoteMask
56
<<
" localAddress: "
<< f.
localAddress
57
<<
" localMask: "
<< f.
localMask
58
<<
" remotePortStart: "
<< f.
remotePortStart
59
<<
" remotePortEnd: "
<< f.
remotePortEnd
60
<<
" localPortStart: "
<< f.
localPortStart
61
<<
" localPortEnd: "
<< f.
localPortEnd
62
<<
" typeOfService: 0x"
<< std::hex << (uint16_t) f.
typeOfService
<< std::dec
63
<<
" typeOfServiceMask: 0x"
<< std::hex << (uint16_t) f.
typeOfServiceMask
<< std::dec;
64
return
os;
65
}
66
67
EpcTft::PacketFilter::PacketFilter
()
68
: precedence (255),
69
direction (BIDIRECTIONAL),
70
remoteMask (
"0.0.0.0"
),
71
localMask (
"0.0.0.0"
),
72
remotePortStart (0),
73
remotePortEnd (65535),
74
localPortStart (0),
75
localPortEnd (65535),
76
typeOfService (0),
77
typeOfServiceMask (0)
78
{
79
NS_LOG_FUNCTION
(
this
);
80
}
81
82
bool
83
EpcTft::PacketFilter::Matches
(
Direction
d,
84
Ipv4Address
ra,
85
Ipv4Address
la,
86
uint16_t rp,
87
uint16_t lp,
88
uint8_t tos)
89
{
90
NS_LOG_FUNCTION
(
this
<< d << ra << la << rp << lp << (uint16_t) tos);
91
if
(d & direction)
92
{
93
NS_LOG_LOGIC
(
"d matches"
);
94
if
(remoteMask.IsMatch (remoteAddress, ra))
95
{
96
NS_LOG_LOGIC
(
"ra matches"
);
97
if
(localMask.IsMatch (localAddress, la))
98
{
99
NS_LOG_LOGIC
(
"ls matches"
);
100
if
(rp >= remotePortStart)
101
{
102
NS_LOG_LOGIC
(
"rps matches"
);
103
if
(rp <= remotePortEnd)
104
{
105
NS_LOG_LOGIC
(
"rpe matches"
);
106
if
(lp >= localPortStart)
107
{
108
NS_LOG_LOGIC
(
"lps matches"
);
109
if
(lp <= localPortEnd)
110
{
111
NS_LOG_LOGIC
(
"lpe matches"
);
112
if
((tos & typeOfServiceMask) == (typeOfService & typeOfServiceMask))
113
{
114
NS_LOG_LOGIC
(
"tos matches --> have match!"
);
115
return
true
;
116
}
117
}
118
}
119
}
120
}
121
}
122
else
123
{
124
NS_LOG_LOGIC
(
"la doesn't match: la="
<< la <<
" f.la="
<< localAddress <<
" f.lmask="
<< localMask);
125
}
126
}
127
else
128
{
129
NS_LOG_LOGIC
(
"ra doesn't match: ra="
<< ra <<
" f.ra="
<< remoteAddress <<
" f.rmask="
<< remoteMask);
130
}
131
}
132
else
133
{
134
NS_LOG_LOGIC
(
"d doesn't match: d=0x"
<< std::hex << d <<
" f.d=0x"
<< std::hex << direction << std::dec);
135
}
136
return
false
;
137
}
138
139
140
Ptr<EpcTft>
141
EpcTft::Default
()
142
{
143
Ptr<EpcTft>
tft = Create<EpcTft> ();
144
EpcTft::PacketFilter
defaultPacketFilter;
145
tft->
Add
(defaultPacketFilter);
146
return
tft;
147
}
148
149
150
EpcTft::EpcTft
()
151
:
m_numFilters
(0)
152
{
153
NS_LOG_FUNCTION
(
this
);
154
}
155
156
uint8_t
157
EpcTft::Add
(
PacketFilter
f)
158
{
159
NS_LOG_FUNCTION
(
this
<< f);
160
NS_ABORT_IF
(
m_numFilters
>= 16);
161
162
std::list<PacketFilter>::iterator it;
163
for
(it =
m_filters
.begin ();
164
(it !=
m_filters
.end ()) && (it->precedence <= f.
precedence
);
165
++it)
166
{
167
}
168
m_filters
.insert (it, f);
169
++
m_numFilters
;
170
return
(
m_numFilters
- 1);
171
}
172
173
bool
174
EpcTft::Matches
(
Direction
direction,
175
Ipv4Address
remoteAddress,
176
Ipv4Address
localAddress,
177
uint16_t remotePort,
178
uint16_t localPort,
179
uint8_t typeOfService)
180
{
181
NS_LOG_FUNCTION
(
this
<< direction << remoteAddress << localAddress << std::dec << remotePort << localPort << (uint16_t) typeOfService);
182
for
(std::list<PacketFilter>::iterator it =
m_filters
.begin ();
183
it !=
m_filters
.end ();
184
++it)
185
{
186
if
(it->Matches (direction, remoteAddress, localAddress, remotePort, localPort, typeOfService))
187
{
188
return
true
;
189
}
190
}
191
return
false
;
192
}
193
194
195
}
// namespace ns3
src
lte
model
epc-tft.cc
Generated on Tue Oct 9 2012 16:45:40 for ns-3 by
1.8.1.2