A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-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// Modifications: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19//
20
21#ifndef IPV6_FLOW_CLASSIFIER_H
22#define IPV6_FLOW_CLASSIFIER_H
23
24#include "flow-classifier.h"
25
26#include "ns3/ipv6-header.h"
27
28#include <map>
29#include <stdint.h>
30
31namespace ns3
32{
33
34class Packet;
35
36/// Classifies packets by looking at their IP and TCP/UDP headers.
37/// From these packet headers, a tuple (source-ip, destination-ip,
38/// protocol, source-port, destination-port) is created, and a unique
39/// flow identifier is assigned for each different tuple combination
41{
42 public:
43 /// Structure to classify a packet
44 struct FiveTuple
45 {
46 Ipv6Address sourceAddress; //!< Source address
47 Ipv6Address destinationAddress; //!< Destination address
48 uint8_t protocol; //!< Protocol
49 uint16_t sourcePort; //!< Source port
50 uint16_t destinationPort; //!< Destination port
51 };
52
54
55 /// \brief try to classify the packet into flow-id and packet-id
56 ///
57 /// \warning: it must be called only once per packet, from SendOutgoingLogger.
58 ///
59 /// \return true if the packet was classified, false if not (i.e. it
60 /// does not appear to be part of a flow).
61 /// \param ipHeader packet's IP header
62 /// \param ipPayload packet's IP payload
63 /// \param out_flowId packet's FlowId
64 /// \param out_packetId packet's identifier
65 bool Classify(const Ipv6Header& ipHeader,
66 Ptr<const Packet> ipPayload,
67 uint32_t* out_flowId,
68 uint32_t* out_packetId);
69
70 /// Searches for the FiveTuple corresponding to the given flowId
71 /// \param flowId the FlowId to search for
72 /// \returns the FiveTuple corresponding to flowId
73 FiveTuple FindFlow(FlowId flowId) const;
74
75 /// Comparator used to sort the vector of DSCP values
77 {
78 public:
79 /// Comparator function
80 /// \param left left operand
81 /// \param right right operand
82 /// \return true if left DSCP is greater than right DSCP
83 bool operator()(std::pair<Ipv6Header::DscpType, uint32_t> left,
84 std::pair<Ipv6Header::DscpType, uint32_t> right);
85 };
86
87 /// \brief get the DSCP values of the packets belonging to the flow with the
88 /// given FlowId, sorted in decreasing order of number of packets seen with
89 /// that DSCP value
90 /// \param flowId the identifier of the flow of interest
91 /// \returns the vector of DSCP values
92 std::vector<std::pair<Ipv6Header::DscpType, uint32_t>> GetDscpCounts(FlowId flowId) const;
93
94 void SerializeToXmlStream(std::ostream& os, uint16_t indent) const override;
95
96 private:
97 /// Map to Flows Identifiers to FlowIds
98 std::map<FiveTuple, FlowId> m_flowMap;
99 /// Map to FlowIds to FlowPacketId
100 std::map<FlowId, FlowPacketId> m_flowPktIdMap;
101 /// Map FlowIds to (DSCP value, packet count) pairs
102 std::map<FlowId, std::map<Ipv6Header::DscpType, uint32_t>> m_flowDscpMap;
103};
104
105/**
106 * \brief Less than operator.
107 *
108 * \param t1 the first operand
109 * \param t2 the first operand
110 * \returns true if the operands are equal
111 */
113
114/**
115 * \brief Equal to operator.
116 *
117 * \param t1 the first operand
118 * \param t2 the first operand
119 * \returns true if the operands are equal
120 */
122
123} // namespace ns3
124
125#endif /* IPV6_FLOW_CLASSIFIER_H */
Provides a method to translate raw packet data into abstract flow identifier and packet identifier pa...
Describes an IPv6 address.
Definition: ipv6-address.h:49
Comparator used to sort the vector of DSCP values.
bool operator()(std::pair< Ipv6Header::DscpType, uint32_t > left, std::pair< Ipv6Header::DscpType, uint32_t > right)
Comparator function.
Classifies packets by looking at their IP and TCP/UDP headers.
std::map< FiveTuple, FlowId > m_flowMap
Map to Flows Identifiers to FlowIds.
void SerializeToXmlStream(std::ostream &os, uint16_t indent) const override
Serializes the results to an std::ostream in XML format.
std::vector< std::pair< Ipv6Header::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.
bool Classify(const Ipv6Header &ipHeader, Ptr< const Packet > ipPayload, uint32_t *out_flowId, uint32_t *out_packetId)
try to classify the packet into flow-id and packet-id
std::map< FlowId, FlowPacketId > m_flowPktIdMap
Map to FlowIds to FlowPacketId.
std::map< FlowId, std::map< Ipv6Header::DscpType, uint32_t > > m_flowDscpMap
Map FlowIds to (DSCP value, packet count) pairs.
Packet header for IPv6.
Definition: ipv6-header.h:35
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.
Ipv6Address destinationAddress
Destination address.
Ipv6Address sourceAddress
Source address.