21 #include "ns3/packet.h"
23 #include "ipv4-flow-classifier.h"
24 #include "ns3/udp-header.h"
25 #include "ns3/tcp-header.h"
30 const uint8_t TCP_PROT_NUMBER = 6;
31 const uint8_t UDP_PROT_NUMBER = 17;
35 bool operator < (
const Ipv4FlowClassifier::FiveTuple &t1,
36 const Ipv4FlowClassifier::FiveTuple &t2)
38 if (t1.sourceAddress < t2.sourceAddress)
42 if (t1.sourceAddress != t2.sourceAddress)
47 if (t1.destinationAddress < t2.destinationAddress)
51 if (t1.destinationAddress != t2.destinationAddress)
56 if (t1.protocol < t2.protocol)
60 if (t1.protocol != t2.protocol)
65 if (t1.sourcePort < t2.sourcePort)
69 if (t1.sourcePort != t2.sourcePort)
74 if (t1.destinationPort < t2.destinationPort)
78 if (t1.destinationPort != t2.destinationPort)
86 bool operator == (
const Ipv4FlowClassifier::FiveTuple &t1,
87 const Ipv4FlowClassifier::FiveTuple &t2)
89 return (t1.sourceAddress == t2.sourceAddress &&
90 t1.destinationAddress == t2.destinationAddress &&
91 t1.protocol == t2.protocol &&
92 t1.sourcePort == t2.sourcePort &&
93 t1.destinationPort == t2.destinationPort);
98 Ipv4FlowClassifier::Ipv4FlowClassifier ()
104 uint32_t *out_flowId, uint32_t *out_packetId)
113 tuple.sourceAddress = ipHeader.
GetSource ();
117 switch (tuple.protocol)
119 case UDP_PROT_NUMBER:
128 case TCP_PROT_NUMBER:
142 std::pair<std::map<FiveTuple, FlowId>::iterator,
bool> insert
143 = m_flowMap.insert (std::pair<FiveTuple, FlowId> (tuple, 0));
148 insert.first->second = GetNewFlowId ();
151 *out_flowId = insert.first->second;
161 for (std::map<FiveTuple, FlowId>::const_iterator
162 iter = m_flowMap.begin (); iter != m_flowMap.end (); iter++)
164 if (iter->second == flowId)
175 Ipv4FlowClassifier::SerializeToXmlStream (std::ostream &os,
int indent)
const
177 #define INDENT(level) for (int __xpto = 0; __xpto < level; __xpto++) os << ' ';
179 INDENT (indent); os <<
"<Ipv4FlowClassifier>\n";
182 for (std::map<FiveTuple, FlowId>::const_iterator
183 iter = m_flowMap.begin (); iter != m_flowMap.end (); iter++)
186 os <<
"<Flow flowId=\"" << iter->second <<
"\""
187 <<
" sourceAddress=\"" << iter->first.sourceAddress <<
"\""
188 <<
" destinationAddress=\"" << iter->first.destinationAddress <<
"\""
189 <<
" protocol=\"" << int(iter->first.protocol) <<
"\""
190 <<
" sourcePort=\"" << iter->first.sourcePort <<
"\""
191 <<
" destinationPort=\"" << iter->first.destinationPort <<
"\""
196 INDENT (indent); os <<
"</Ipv4FlowClassifier>\n";
#define NS_FATAL_ERROR(msg)
fatal error handling
FiveTuple FindFlow(FlowId flowId) const
Searches for the FiveTuple corresponding to the given flowId.
static Ipv4Address GetBroadcast(void)
uint32_t PeekHeader(Header &header) const
static Ipv4Address GetZero(void)
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