A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
ipv4-flow-classifier.h
Go to the documentation of this file.
1
//
2
// Copyright (c) 2009 INESC Porto
3
//
4
// SPDX-License-Identifier: GPL-2.0-only
5
//
6
// Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt> <gjcarneiro@gmail.com>
7
//
8
9
#ifndef IPV4_FLOW_CLASSIFIER_H
10
#define IPV4_FLOW_CLASSIFIER_H
11
12
#include "
flow-classifier.h
"
13
14
#include "ns3/ipv4-header.h"
15
16
#include <map>
17
#include <stdint.h>
18
19
namespace
ns3
20
{
21
22
class
Packet;
23
24
/// Classifies packets by looking at their IP and TCP/UDP headers.
25
/// From these packet headers, a tuple (source-ip, destination-ip,
26
/// protocol, source-port, destination-port) is created, and a unique
27
/// flow identifier is assigned for each different tuple combination
28
class
Ipv4FlowClassifier
:
public
FlowClassifier
29
{
30
public
:
31
/// Structure to classify a packet
32
struct
FiveTuple
33
{
34
Ipv4Address
sourceAddress
;
//!< Source address
35
Ipv4Address
destinationAddress
;
//!< Destination address
36
uint8_t
protocol
;
//!< Protocol
37
uint16_t
sourcePort
;
//!< Source port
38
uint16_t
destinationPort
;
//!< Destination port
39
};
40
41
Ipv4FlowClassifier
();
42
43
/// \brief try to classify the packet into flow-id and packet-id
44
///
45
/// \warning: it must be called only once per packet, from SendOutgoingLogger.
46
///
47
/// \return true if the packet was classified, false if not (i.e. it
48
/// does not appear to be part of a flow).
49
/// \param ipHeader packet's IP header
50
/// \param ipPayload packet's IP payload
51
/// \param out_flowId packet's FlowId
52
/// \param out_packetId packet's identifier
53
bool
Classify
(
const
Ipv4Header
& ipHeader,
54
Ptr<const Packet>
ipPayload,
55
uint32_t
* out_flowId,
56
uint32_t
* out_packetId);
57
58
/// Searches for the FiveTuple corresponding to the given flowId
59
/// \param flowId the FlowId to search for
60
/// \returns the FiveTuple corresponding to flowId
61
FiveTuple
FindFlow
(
FlowId
flowId)
const
;
62
63
/// Comparator used to sort the vector of DSCP values
64
class
SortByCount
65
{
66
public
:
67
/// Comparator function
68
/// \param left left operand
69
/// \param right right operand
70
/// \return true if left DSCP is greater than right DSCP
71
bool
operator()
(std::pair<Ipv4Header::DscpType, uint32_t> left,
72
std::pair<Ipv4Header::DscpType, uint32_t> right);
73
};
74
75
/// \brief get the DSCP values of the packets belonging to the flow with the
76
/// given FlowId, sorted in decreasing order of number of packets seen with
77
/// that DSCP value
78
/// \param flowId the identifier of the flow of interest
79
/// \returns the vector of DSCP values
80
std::vector<std::pair<Ipv4Header::DscpType, uint32_t>>
GetDscpCounts
(
FlowId
flowId)
const
;
81
82
void
SerializeToXmlStream
(std::ostream& os, uint16_t indent)
const override
;
83
84
private
:
85
/// Map to Flows Identifiers to FlowIds
86
std::map<FiveTuple, FlowId>
m_flowMap
;
87
/// Map to FlowIds to FlowPacketId
88
std::map<FlowId, FlowPacketId>
m_flowPktIdMap
;
89
/// Map FlowIds to (DSCP value, packet count) pairs
90
std::map<FlowId, std::map<Ipv4Header::DscpType, uint32_t>>
m_flowDscpMap
;
91
};
92
93
/**
94
* \brief Less than operator.
95
*
96
* \param t1 the first operand
97
* \param t2 the first operand
98
* \returns true if the operands are equal
99
*/
100
bool
operator<
(
const
Ipv4FlowClassifier::FiveTuple
& t1,
const
Ipv4FlowClassifier::FiveTuple
& t2);
101
102
/**
103
* \brief Equal to operator.
104
*
105
* \param t1 the first operand
106
* \param t2 the first operand
107
* \returns true if the operands are equal
108
*/
109
bool
operator==
(
const
Ipv4FlowClassifier::FiveTuple
& t1,
const
Ipv4FlowClassifier::FiveTuple
& t2);
110
111
}
// namespace ns3
112
113
#endif
/* IPV4_FLOW_CLASSIFIER_H */
ns3::FlowClassifier
Provides a method to translate raw packet data into abstract flow identifier and packet identifier pa...
Definition
flow-classifier.h:43
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Ipv4FlowClassifier::SortByCount
Comparator used to sort the vector of DSCP values.
Definition
ipv4-flow-classifier.h:65
ns3::Ipv4FlowClassifier::SortByCount::operator()
bool operator()(std::pair< Ipv4Header::DscpType, uint32_t > left, std::pair< Ipv4Header::DscpType, uint32_t > right)
Comparator function.
Definition
ipv4-flow-classifier.cc:185
ns3::Ipv4FlowClassifier
Classifies packets by looking at their IP and TCP/UDP headers.
Definition
ipv4-flow-classifier.h:29
ns3::Ipv4FlowClassifier::m_flowPktIdMap
std::map< FlowId, FlowPacketId > m_flowPktIdMap
Map to FlowIds to FlowPacketId.
Definition
ipv4-flow-classifier.h:88
ns3::Ipv4FlowClassifier::SerializeToXmlStream
void SerializeToXmlStream(std::ostream &os, uint16_t indent) const override
Serializes the results to an std::ostream in XML format.
Definition
ipv4-flow-classifier.cc:208
ns3::Ipv4FlowClassifier::GetDscpCounts
std::vector< std::pair< Ipv4Header::DscpType, uint32_t > > GetDscpCounts(FlowId flowId) const
get the DSCP values of the packets belonging to the flow with the given FlowId, sorted in decreasing ...
Definition
ipv4-flow-classifier.cc:192
ns3::Ipv4FlowClassifier::FindFlow
FiveTuple FindFlow(FlowId flowId) const
Searches for the FiveTuple corresponding to the given flowId.
Definition
ipv4-flow-classifier.cc:170
ns3::Ipv4FlowClassifier::Ipv4FlowClassifier
Ipv4FlowClassifier()
Definition
ipv4-flow-classifier.cc:83
ns3::Ipv4FlowClassifier::m_flowDscpMap
std::map< FlowId, std::map< Ipv4Header::DscpType, uint32_t > > m_flowDscpMap
Map FlowIds to (DSCP value, packet count) pairs.
Definition
ipv4-flow-classifier.h:90
ns3::Ipv4FlowClassifier::m_flowMap
std::map< FiveTuple, FlowId > m_flowMap
Map to Flows Identifiers to FlowIds.
Definition
ipv4-flow-classifier.h:86
ns3::Ipv4FlowClassifier::Classify
bool Classify(const Ipv4Header &ipHeader, Ptr< const Packet > ipPayload, uint32_t *out_flowId, uint32_t *out_packetId)
try to classify the packet into flow-id and packet-id
Definition
ipv4-flow-classifier.cc:88
ns3::Ipv4Header
Packet header for IPv4.
Definition
ipv4-header.h:23
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
uint32_t
flow-classifier.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::operator==
bool operator==(const EventId &a, const EventId &b)
Definition
event-id.h:155
ns3::operator<
bool operator<(const EventId &a, const EventId &b)
Definition
event-id.h:168
ns3::Ipv4FlowClassifier::FiveTuple
Structure to classify a packet.
Definition
ipv4-flow-classifier.h:33
ns3::Ipv4FlowClassifier::FiveTuple::destinationPort
uint16_t destinationPort
Destination port.
Definition
ipv4-flow-classifier.h:38
ns3::Ipv4FlowClassifier::FiveTuple::sourceAddress
Ipv4Address sourceAddress
Source address.
Definition
ipv4-flow-classifier.h:34
ns3::Ipv4FlowClassifier::FiveTuple::destinationAddress
Ipv4Address destinationAddress
Destination address.
Definition
ipv4-flow-classifier.h:35
ns3::Ipv4FlowClassifier::FiveTuple::protocol
uint8_t protocol
Protocol.
Definition
ipv4-flow-classifier.h:36
ns3::Ipv4FlowClassifier::FiveTuple::sourcePort
uint16_t sourcePort
Source port.
Definition
ipv4-flow-classifier.h:37
src
flow-monitor
model
ipv4-flow-classifier.h
Generated on Fri Nov 8 2024 13:59:00 for ns-3 by
1.11.0