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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
7 *
8 */
9
10#include "ipcs-classifier.h"
11
12#include "service-flow.h"
13
14#include "ns3/ipv4-header.h"
15#include "ns3/llc-snap-header.h"
16#include "ns3/log.h"
17#include "ns3/packet.h"
18#include "ns3/tcp-header.h"
19#include "ns3/tcp-l4-protocol.h"
20#include "ns3/udp-header.h"
21#include "ns3/udp-l4-protocol.h"
22
23#include <stdint.h>
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("IpcsClassifier");
29
30NS_OBJECT_ENSURE_REGISTERED(IpcsClassifier);
31
32TypeId
34{
35 static TypeId tid = TypeId("ns3::IpcsClassifier").SetParent<Object>().SetGroupName("Wimax");
36 return tid;
37}
38
42
46
51{
52 Ptr<Packet> C_Packet = packet->Copy();
53
54 LlcSnapHeader llc;
55 C_Packet->RemoveHeader(llc);
56
57 Ipv4Header ipv4Header;
58 C_Packet->RemoveHeader(ipv4Header);
59 Ipv4Address source_address = ipv4Header.GetSource();
60 Ipv4Address dest_address = ipv4Header.GetDestination();
61 uint8_t protocol = ipv4Header.GetProtocol();
62
63 uint16_t sourcePort = 0;
64 uint16_t destPort = 0;
65 if (protocol == UdpL4Protocol::PROT_NUMBER)
66 {
67 UdpHeader udpHeader;
68 C_Packet->RemoveHeader(udpHeader);
69 sourcePort = udpHeader.GetSourcePort();
70 destPort = udpHeader.GetDestinationPort();
71 }
72 else if (protocol == TcpL4Protocol::PROT_NUMBER)
73 {
74 TcpHeader tcpHeader;
75 C_Packet->RemoveHeader(tcpHeader);
76 sourcePort = tcpHeader.GetSourcePort();
77 destPort = tcpHeader.GetDestinationPort();
78 }
79 else
80 {
81 NS_LOG_INFO("\t\t\tUnknown protocol: " << protocol);
82 return nullptr;
83 }
84
85 NS_LOG_INFO("Classifing packet: src_addr=" << source_address << " dst_addr=" << dest_address
86 << " src_port=" << sourcePort << " dst_port="
87 << destPort << " proto=" << (uint16_t)protocol);
88 return (sfm->DoClassify(source_address, dest_address, sourcePort, destPort, protocol, dir));
89}
90
91} // 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.
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
Ipv4Address GetSource() const
uint8_t GetProtocol() const
Ipv4Address GetDestination() const
Header for the LLC/SNAP encapsulation.
A base class which provides memory management and object aggregation.
Definition object.h:78
Smart pointer class similar to boost::intrusive_ptr.
This class implements service flows as described by the IEEE-802.16 standard.
Direction
Direction enumeration.
Header for the Transmission Control Protocol.
Definition tcp-header.h:36
uint16_t GetDestinationPort() const
Get the destination port.
uint16_t GetSourcePort() const
Get the source port.
Definition tcp-header.cc:95
static const uint8_t PROT_NUMBER
protocol number (0x6)
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Packet header for UDP packets.
Definition udp-header.h:30
uint16_t GetDestinationPort() const
Definition udp-header.cc:43
uint16_t GetSourcePort() const
Definition udp-header.cc:37
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:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string dir