A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipcs-classifier.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 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 *
19 */
20
21#include "ipcs-classifier.h"
22
23#include "service-flow.h"
24
25#include "ns3/ipv4-header.h"
26#include "ns3/llc-snap-header.h"
27#include "ns3/log.h"
28#include "ns3/packet.h"
29#include "ns3/tcp-header.h"
30#include "ns3/tcp-l4-protocol.h"
31#include "ns3/udp-header.h"
32#include "ns3/udp-l4-protocol.h"
33
34#include <stdint.h>
35
36namespace ns3
37{
38
39NS_LOG_COMPONENT_DEFINE("IpcsClassifier");
40
41NS_OBJECT_ENSURE_REGISTERED(IpcsClassifier);
42
43TypeId
45{
46 static TypeId tid = TypeId("ns3::IpcsClassifier").SetParent<Object>().SetGroupName("Wimax");
47 return tid;
48}
49
51{
52}
53
55{
56}
57
62{
63 Ptr<Packet> C_Packet = packet->Copy();
64
65 LlcSnapHeader llc;
66 C_Packet->RemoveHeader(llc);
67
68 Ipv4Header ipv4Header;
69 C_Packet->RemoveHeader(ipv4Header);
70 Ipv4Address source_address = ipv4Header.GetSource();
71 Ipv4Address dest_address = ipv4Header.GetDestination();
72 uint8_t protocol = ipv4Header.GetProtocol();
73
74 uint16_t sourcePort = 0;
75 uint16_t destPort = 0;
76 if (protocol == UdpL4Protocol::PROT_NUMBER)
77 {
78 UdpHeader udpHeader;
79 C_Packet->RemoveHeader(udpHeader);
80 sourcePort = udpHeader.GetSourcePort();
81 destPort = udpHeader.GetDestinationPort();
82 }
83 else if (protocol == TcpL4Protocol::PROT_NUMBER)
84 {
85 TcpHeader tcpHeader;
86 C_Packet->RemoveHeader(tcpHeader);
87 sourcePort = tcpHeader.GetSourcePort();
88 destPort = tcpHeader.GetDestinationPort();
89 }
90 else
91 {
92 NS_LOG_INFO("\t\t\tUnknown protocol: " << protocol);
93 return nullptr;
94 }
95
96 NS_LOG_INFO("Classifing packet: src_addr=" << source_address << " dst_addr=" << dest_address
97 << " src_port=" << sourcePort << " dst_port="
98 << destPort << " proto=" << (uint16_t)protocol);
99 return (sfm->DoClassify(source_address, dest_address, sourcePort, destPort, protocol, dir));
100}
101
102} // namespace ns3
ServiceFlow * Classify(Ptr< const Packet > packet, Ptr< ServiceFlowManager > sfm, ServiceFlow::Direction dir)
classify a packet in a service flow
static TypeId GetTypeId()
Get the type ID.
~IpcsClassifier() override
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Packet header for IPv4.
Definition: ipv4-header.h:34
Ipv4Address GetSource() const
Definition: ipv4-header.cc:302
uint8_t GetProtocol() const
Definition: ipv4-header.cc:281
Ipv4Address GetDestination() const
Definition: ipv4-header.cc:316
Header for the LLC/SNAP encapsulation.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:43
Direction
Direction enumeration.
Definition: service-flow.h:47
Header for the Transmission Control Protocol.
Definition: tcp-header.h:47
uint16_t GetDestinationPort() const
Get the destination port.
Definition: tcp-header.cc:112
uint16_t GetSourcePort() const
Get the source port.
Definition: tcp-header.cc:106
static const uint8_t PROT_NUMBER
protocol number (0x6)
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Packet header for UDP packets.
Definition: udp-header.h:41
uint16_t GetDestinationPort() const
Definition: udp-header.cc:54
uint16_t GetSourcePort() const
Definition: udp-header.cc:48
static const uint8_t PROT_NUMBER
protocol number (0x11)
#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
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string dir