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