A Discrete-Event Network Simulator
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
19namespace ns3
20{
21
22class 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
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
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
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 */
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 */
110
111} // namespace ns3
112
113#endif /* IPV4_FLOW_CLASSIFIER_H */
Provides a method to translate raw packet data into abstract flow identifier and packet identifier pa...
Ipv4 addresses are stored in host order in this class.
Comparator used to sort the vector of DSCP values.
bool operator()(std::pair< Ipv4Header::DscpType, uint32_t > left, std::pair< Ipv4Header::DscpType, uint32_t > right)
Comparator function.
Classifies packets by looking at their IP and TCP/UDP headers.
std::map< FlowId, FlowPacketId > m_flowPktIdMap
Map to FlowIds to FlowPacketId.
void SerializeToXmlStream(std::ostream &os, uint16_t indent) const override
Serializes the results to an std::ostream in XML format.
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 ...
FiveTuple FindFlow(FlowId flowId) const
Searches for the FiveTuple corresponding to the given flowId.
std::map< FlowId, std::map< Ipv4Header::DscpType, uint32_t > > m_flowDscpMap
Map FlowIds to (DSCP value, packet count) pairs.
std::map< FiveTuple, FlowId > m_flowMap
Map to Flows Identifiers to FlowIds.
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
Packet header for IPv4.
Definition ipv4-header.h:23
Smart pointer class similar to boost::intrusive_ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:155
bool operator<(const EventId &a, const EventId &b)
Definition event-id.h:168
Structure to classify a packet.
uint16_t destinationPort
Destination port.
Ipv4Address sourceAddress
Source address.
Ipv4Address destinationAddress
Destination address.