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-classifier.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
* Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Authors:
20
* Nicola Baldo <nbaldo@cttc.es> (the EpcTftClassifier class)
21
* Giuseppe Piro <g.piro@poliba.it> (part of the code in EpcTftClassifier::Classify ()
22
* which comes from RrcEntity::Classify of the GSoC 2010 LTE module)
23
*
24
*/
25
26
27
28
29
#include "
epc-tft-classifier.h
"
30
#include "
epc-tft.h
"
31
#include "ns3/log.h"
32
#include "ns3/packet.h"
33
#include "ns3/ipv4-header.h"
34
#include "ns3/udp-header.h"
35
#include "ns3/tcp-header.h"
36
#include "ns3/udp-l4-protocol.h"
37
#include "ns3/tcp-l4-protocol.h"
38
39
NS_LOG_COMPONENT_DEFINE
(
"EpcTftClassifier"
);
40
41
namespace
ns3 {
42
43
EpcTftClassifier::EpcTftClassifier
()
44
{
45
NS_LOG_FUNCTION
(
this
);
46
}
47
48
void
49
EpcTftClassifier::Add
(
Ptr<EpcTft>
tft, uint32_t
id
)
50
{
51
NS_LOG_FUNCTION
(
this
<< tft);
52
53
m_tftMap
[id] = tft;
54
55
// simple sanity check: there shouldn't be more than 16 bearers (hence TFTs) per UE
56
NS_ASSERT
(
m_tftMap
.size () <= 16);
57
}
58
59
void
60
EpcTftClassifier::Delete
(uint32_t
id
)
61
{
62
NS_LOG_FUNCTION
(
this
<<
id
);
63
m_tftMap
.erase (
id
);
64
}
65
66
67
uint32_t
68
EpcTftClassifier::Classify
(
Ptr<Packet>
p,
EpcTft::Direction
direction)
69
{
70
NS_LOG_FUNCTION
(
this
<< p << direction);
71
72
Ptr<Packet>
pCopy = p->
Copy
();
73
74
Ipv4Header
ipv4Header;
75
pCopy->
RemoveHeader
(ipv4Header);
76
77
Ipv4Address
localAddress;
78
Ipv4Address
remoteAddress;
79
80
81
if
(direction ==
EpcTft::UPLINK
)
82
{
83
localAddress = ipv4Header.
GetSource
();
84
remoteAddress = ipv4Header.
GetDestination
();
85
}
86
else
87
{
88
NS_ASSERT
(direction ==
EpcTft::DOWNLINK
);
89
remoteAddress = ipv4Header.
GetSource
();
90
localAddress = ipv4Header.
GetDestination
();
91
}
92
93
uint8_t protocol = ipv4Header.
GetProtocol
();
94
95
uint8_t tos = ipv4Header.
GetTos
();
96
97
uint16_t localPort = 0;
98
uint16_t remotePort = 0;
99
100
if
(protocol ==
UdpL4Protocol::PROT_NUMBER
)
101
{
102
UdpHeader
udpHeader;
103
pCopy->
RemoveHeader
(udpHeader);
104
105
if
(direction ==
EpcTft::UPLINK
)
106
{
107
localPort = udpHeader.
GetSourcePort
();
108
remotePort = udpHeader.
GetDestinationPort
();
109
}
110
else
111
{
112
remotePort = udpHeader.
GetSourcePort
();
113
localPort = udpHeader.
GetDestinationPort
();
114
}
115
}
116
else
if
(protocol ==
TcpL4Protocol::PROT_NUMBER
)
117
{
118
TcpHeader
tcpHeader;
119
pCopy->
RemoveHeader
(tcpHeader);
120
if
(direction ==
EpcTft::UPLINK
)
121
{
122
localPort = tcpHeader.
GetSourcePort
();
123
remotePort = tcpHeader.
GetDestinationPort
();
124
}
125
else
126
{
127
remotePort = tcpHeader.
GetSourcePort
();
128
localPort = tcpHeader.
GetDestinationPort
();
129
}
130
}
131
else
132
{
133
NS_LOG_INFO
(
"Unknown protocol: "
<< protocol);
134
return
0;
// no match
135
}
136
137
NS_LOG_INFO
(
"Classifing packet:"
138
<<
" localAddr="
<< localAddress
139
<<
" remoteAddr="
<< remoteAddress
140
<<
" localPort="
<< localPort
141
<<
" remotePort="
<< remotePort
142
<<
" tos=0x"
<< (uint16_t) tos );
143
144
// now it is possible to classify the packet!
145
// we use a reverse iterator since filter priority is not implemented properly.
146
// This way, since the default bearer is expected to be added first, it will be evaluated last.
147
std::map <uint32_t, Ptr<EpcTft> >::const_reverse_iterator it;
148
NS_LOG_LOGIC
(
"TFT MAP size: "
<<
m_tftMap
.size ());
149
150
for
(it =
m_tftMap
.rbegin (); it !=
m_tftMap
.rend (); ++it)
151
{
152
NS_LOG_LOGIC
(
"TFT id: "
<< it->first );
153
NS_LOG_LOGIC
(
" Ptr<EpcTft>: "
<< it->second);
154
Ptr<EpcTft>
tft = it->second;
155
if
(tft->Matches (direction, remoteAddress, localAddress, remotePort, localPort, tos))
156
{
157
NS_LOG_LOGIC
(
"matches with TFT ID = "
<< it->first);
158
return
it->first;
// the id of the matching TFT
159
}
160
}
161
NS_LOG_LOGIC
(
"no match"
);
162
return
0;
// no match
163
}
164
165
166
}
// namespace ns3
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition:
packet.cc:268
ns3::EpcTft::Direction
Direction
Indicates the direction of the traffic that is to be classified.
Definition:
epc-tft.h:56
ns3::Ptr
smart pointer class similar to boost::intrusive_ptr
Definition:
ptr.h:59
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
ns3::TcpHeader::GetDestinationPort
uint16_t GetDestinationPort() const
Definition:
tcp-header.cc:93
ns3::EpcTftClassifier::Add
void Add(Ptr< EpcTft > tft, uint32_t id)
add a TFT to the Classifier
Definition:
epc-tft-classifier.cc:49
ns3::Ipv4Header::GetDestination
Ipv4Address GetDestination(void) const
Definition:
ipv4-header.cc:304
ns3::EpcTft::UPLINK
Definition:
epc-tft.h:57
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::Ipv4Header::GetProtocol
uint8_t GetProtocol(void) const
Definition:
ipv4-header.cc:272
NS_LOG_INFO
#define NS_LOG_INFO(msg)
Definition:
log.h:298
ns3::Ipv4Header::GetSource
Ipv4Address GetSource(void) const
Definition:
ipv4-header.cc:291
ns3::EpcTftClassifier::Classify
uint32_t Classify(Ptr< Packet > p, EpcTft::Direction direction)
classify an IP packet
Definition:
epc-tft-classifier.cc:68
ns3::Ipv4Header
Packet header for IPv4.
Definition:
ipv4-header.h:31
epc-tft.h
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Definition:
log.h:368
ns3::EpcTftClassifier::EpcTftClassifier
EpcTftClassifier()
Definition:
epc-tft-classifier.cc:43
ns3::TcpL4Protocol::PROT_NUMBER
static const uint8_t PROT_NUMBER
protocol number (0x6)
Definition:
tcp-l4-protocol.h:63
ns3::Packet::Copy
Ptr< Packet > Copy(void) const
Definition:
packet.cc:122
ns3::TcpHeader
Header for the Transmission Control Protocol.
Definition:
tcp-header.h:43
ns3::UdpHeader::GetSourcePort
uint16_t GetSourcePort(void) const
Definition:
udp-header.cc:66
ns3::UdpHeader
Packet header for UDP packets.
Definition:
udp-header.h:39
ns3::EpcTftClassifier::m_tftMap
std::map< uint32_t, Ptr< EpcTft > > m_tftMap
Definition:
epc-tft-classifier.h:76
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition:
ipv4-address.h:38
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("EpcTftClassifier")
epc-tft-classifier.h
ns3::TcpHeader::GetSourcePort
uint16_t GetSourcePort() const
Definition:
tcp-header.cc:89
ns3::EpcTft::DOWNLINK
Definition:
epc-tft.h:56
ns3::Ipv4Header::GetTos
uint8_t GetTos(void) const
Definition:
ipv4-header.cc:195
ns3::EpcTftClassifier::Delete
void Delete(uint32_t id)
delete an existing TFT from the classifier
Definition:
epc-tft-classifier.cc:60
ns3::UdpHeader::GetDestinationPort
uint16_t GetDestinationPort(void) const
Definition:
udp-header.cc:71
ns3::UdpL4Protocol::PROT_NUMBER
static const uint8_t PROT_NUMBER
protocol number (0x11)
Definition:
udp-l4-protocol.h:55
src
lte
model
epc-tft-classifier.cc
Generated on Sat Apr 19 2014 14:06:59 for ns-3 by
1.8.6