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// 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// Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt> <gjcarneiro@gmail.com>
18//
19
20#ifndef IPV4_FLOW_CLASSIFIER_H
21#define IPV4_FLOW_CLASSIFIER_H
22
23#include "flow-classifier.h"
24
25#include "ns3/ipv4-header.h"
26
27#include <map>
28#include <stdint.h>
29
30namespace ns3
31{
32
33class Packet;
34
35/// Classifies packets by looking at their IP and TCP/UDP headers.
36/// From these packet headers, a tuple (source-ip, destination-ip,
37/// protocol, source-port, destination-port) is created, and a unique
38/// flow identifier is assigned for each different tuple combination
40{
41 public:
42 /// Structure to classify a packet
43 struct FiveTuple
44 {
45 Ipv4Address sourceAddress; //!< Source address
46 Ipv4Address destinationAddress; //!< Destination address
47 uint8_t protocol; //!< Protocol
48 uint16_t sourcePort; //!< Source port
49 uint16_t destinationPort; //!< Destination port
50 };
51
53
54 /// \brief try to classify the packet into flow-id and packet-id
55 ///
56 /// \warning: it must be called only once per packet, from SendOutgoingLogger.
57 ///
58 /// \return true if the packet was classified, false if not (i.e. it
59 /// does not appear to be part of a flow).
60 /// \param ipHeader packet's IP header
61 /// \param ipPayload packet's IP payload
62 /// \param out_flowId packet's FlowId
63 /// \param out_packetId packet's identifier
64 bool Classify(const Ipv4Header& ipHeader,
65 Ptr<const Packet> ipPayload,
66 uint32_t* out_flowId,
67 uint32_t* out_packetId);
68
69 /// Searches for the FiveTuple corresponding to the given flowId
70 /// \param flowId the FlowId to search for
71 /// \returns the FiveTuple corresponding to flowId
72 FiveTuple FindFlow(FlowId flowId) const;
73
74 /// Comparator used to sort the vector of DSCP values
76 {
77 public:
78 /// Comparator function
79 /// \param left left operand
80 /// \param right right operand
81 /// \return true if left DSCP is greater than right DSCP
82 bool operator()(std::pair<Ipv4Header::DscpType, uint32_t> left,
83 std::pair<Ipv4Header::DscpType, uint32_t> right);
84 };
85
86 /// \brief get the DSCP values of the packets belonging to the flow with the
87 /// given FlowId, sorted in decreasing order of number of packets seen with
88 /// that DSCP value
89 /// \param flowId the identifier of the flow of interest
90 /// \returns the vector of DSCP values
91 std::vector<std::pair<Ipv4Header::DscpType, uint32_t>> GetDscpCounts(FlowId flowId) const;
92
93 void SerializeToXmlStream(std::ostream& os, uint16_t indent) const override;
94
95 private:
96 /// Map to Flows Identifiers to FlowIds
97 std::map<FiveTuple, FlowId> m_flowMap;
98 /// Map to FlowIds to FlowPacketId
99 std::map<FlowId, FlowPacketId> m_flowPktIdMap;
100 /// Map FlowIds to (DSCP value, packet count) pairs
101 std::map<FlowId, std::map<Ipv4Header::DscpType, uint32_t>> m_flowDscpMap;
102};
103
104/**
105 * \brief Less than operator.
106 *
107 * \param t1 the first operand
108 * \param t2 the first operand
109 * \returns true if the operands are equal
110 */
112
113/**
114 * \brief Equal to operator.
115 *
116 * \param t1 the first operand
117 * \param t2 the first operand
118 * \returns true if the operands are equal
119 */
121
122} // namespace ns3
123
124#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.
Definition: ipv4-address.h:42
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:34
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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:157
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
Structure to classify a packet.
uint16_t destinationPort
Destination port.
Ipv4Address sourceAddress
Source address.
Ipv4Address destinationAddress
Destination address.