20 #include "ipcs-classifier-record.h"
22 #include "ns3/ipv4-address.h"
23 #include "wimax-tlv.h"
28 IpcsClassifierRecord::IpcsClassifierRecord (
void)
37 m_protocol.push_back (6);
38 m_protocol.push_back (17);
39 AddSrcAddr (Ipv4Address (
"0.0.0.0"), Ipv4Mask (
"0.0.0.0"));
40 AddDstAddr (Ipv4Address (
"0.0.0.0"), Ipv4Mask (
"0.0.0.0"));
45 IpcsClassifierRecord::~IpcsClassifierRecord (
void)
49 IpcsClassifierRecord::IpcsClassifierRecord (
Tlv tlv)
51 NS_ASSERT_MSG (tlv.GetType () == CsParamVectorTlvValue::Packet_Classification_Rule,
"Invalid TLV");
59 for (std::vector<Tlv*>::const_iterator iter = rules->Begin (); iter != rules->End (); ++iter)
61 switch ((*iter)->GetType ())
63 case ClassificationRuleVectorTlvValue::Priority:
65 m_priority = ((
U8TlvValue*)((*iter)->PeekValue ()))->GetValue ();
68 case ClassificationRuleVectorTlvValue::ToS:
70 NS_FATAL_ERROR (
"ToS Not implemented-- please implement and contribute a patch");
73 case ClassificationRuleVectorTlvValue::Protocol:
76 for (std::vector<uint8_t>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
82 case ClassificationRuleVectorTlvValue::IP_src:
85 for (std::vector<Ipv4AddressTlvValue::ipv4Addr>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
91 case ClassificationRuleVectorTlvValue::IP_dst:
94 for (std::vector<Ipv4AddressTlvValue::ipv4Addr>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
100 case ClassificationRuleVectorTlvValue::Port_src:
103 for (std::vector<PortRangeTlvValue::PortRange>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
109 case ClassificationRuleVectorTlvValue::Port_dst:
112 for (std::vector<PortRangeTlvValue::PortRange>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
118 case ClassificationRuleVectorTlvValue::Index:
120 m_index = ((
U16TlvValue*)((*iter)->PeekValue ()))->GetValue ();
127 IpcsClassifierRecord::IpcsClassifierRecord (
Ipv4Address SrcAddress,
132 uint16_t SrcPortHigh,
134 uint16_t DstPortHigh,
138 m_priority = priority;
139 m_protocol.push_back (protocol);
155 tmp.Address = srcAddress;
157 m_srcAddr.push_back (tmp);
163 tmp.Address = dstAddress;
165 m_dstAddr.push_back (tmp);
171 tmp.PortLow = srcPortLow;
172 tmp.PortHigh = srcPortHigh;
173 m_srcPortRange.push_back (tmp);
180 tmp.PortLow = dstPortLow;
181 tmp.PortHigh = dstPortHigh;
182 m_dstPortRange.push_back (tmp);
187 m_protocol.push_back (proto);
222 IpcsClassifierRecord::CheckMatchSrcAddr (
Ipv4Address srcAddress)
const
224 for (std::vector<struct ipv4Addr>::const_iterator iter = m_srcAddr.begin (); iter != m_srcAddr.end (); ++iter)
226 NS_LOG_INFO (
"src addr check match: pkt=" << srcAddress <<
" cls=" << (*iter).Address <<
"/" << (*iter).Mask);
227 if (srcAddress.
CombineMask ((*iter).Mask) == (*iter).Address)
236 IpcsClassifierRecord::CheckMatchDstAddr (Ipv4Address dstAddress)
const
239 for (std::vector<struct ipv4Addr>::const_iterator iter = m_dstAddr.begin (); iter != m_dstAddr.end (); ++iter)
241 NS_LOG_INFO (
"dst addr check match: pkt=" << dstAddress <<
" cls=" << (*iter).Address <<
"/" << (*iter).Mask);
242 if (dstAddress.CombineMask ((*iter).Mask) == (*iter).Address)
251 IpcsClassifierRecord::CheckMatchSrcPort (uint16_t port)
const
253 for (std::vector<struct PortRange>::const_iterator iter = m_srcPortRange.begin (); iter != m_srcPortRange.end (); ++iter)
255 NS_LOG_INFO (
"src port check match: pkt=" << port <<
" cls= [" << (*iter).PortLow <<
" TO " << (*iter).PortHigh
257 if (port >= (*iter).PortLow && port <= (*iter).PortHigh)
266 IpcsClassifierRecord::CheckMatchDstPort (uint16_t port)
const
268 for (std::vector<struct PortRange>::const_iterator iter = m_dstPortRange.begin (); iter != m_dstPortRange.end (); ++iter)
270 NS_LOG_INFO (
"dst port check match: pkt=" << port <<
" cls= [" << (*iter).PortLow <<
" TO " << (*iter).PortHigh
272 if (port >= (*iter).PortLow && port <= (*iter).PortHigh)
281 IpcsClassifierRecord::CheckMatchProtocol (uint8_t proto)
const
283 for (std::vector<uint8_t>::const_iterator iter = m_protocol.begin (); iter != m_protocol.end (); ++iter)
285 NS_LOG_INFO (
"proto check match: pkt=" << (uint16_t) proto <<
" cls=" << (uint16_t) proto);
286 if (proto == (*iter))
301 return (CheckMatchProtocol (proto) && CheckMatchDstPort (dstPort) && CheckMatchSrcPort (srcPort)
302 && CheckMatchDstAddr (dstAddress) && CheckMatchSrcAddr (srcAddress));
309 for (std::vector<struct ipv4Addr>::const_iterator iter = m_srcAddr.begin (); iter != m_srcAddr.end (); ++iter)
311 ipv4AddrValSrc.Add ((*iter).Address, (*iter).Mask);
315 for (std::vector<struct ipv4Addr>::const_iterator iter = m_dstAddr.begin (); iter != m_dstAddr.end (); ++iter)
317 ipv4AddrValDst.Add ((*iter).Address, (*iter).Mask);
321 for (std::vector<uint8_t>::const_iterator iter = m_protocol.begin (); iter != m_protocol.end (); ++iter)
323 protoVal.Add ((*iter));
327 for (std::vector<struct PortRange>::const_iterator iter = m_srcPortRange.begin (); iter != m_srcPortRange.end (); ++iter)
329 portValueSrc.Add ((*iter).PortLow, (*iter).PortHigh);
333 for (std::vector<struct PortRange>::const_iterator iter = m_dstPortRange.begin (); iter != m_dstPortRange.end (); ++iter)
335 portValueDst.Add ((*iter).PortLow, (*iter).PortHigh);
339 ClassVectVal.Add (
Tlv (ClassificationRuleVectorTlvValue::Priority, 1,
U8TlvValue (m_priority)));
340 ClassVectVal.Add (
Tlv (ClassificationRuleVectorTlvValue::Protocol, protoVal.GetSerializedSize (), protoVal));
341 ClassVectVal.Add (
Tlv (ClassificationRuleVectorTlvValue::IP_src, ipv4AddrValSrc.GetSerializedSize (), ipv4AddrValSrc));
342 ClassVectVal.Add (
Tlv (ClassificationRuleVectorTlvValue::IP_dst, ipv4AddrValDst.GetSerializedSize (), ipv4AddrValDst));
343 ClassVectVal.Add (
Tlv (ClassificationRuleVectorTlvValue::Port_src, portValueSrc.GetSerializedSize (), portValueSrc));
344 ClassVectVal.Add (
Tlv (ClassificationRuleVectorTlvValue::Port_dst, portValueDst.GetSerializedSize (), portValueDst));
345 ClassVectVal.Add (
Tlv (ClassificationRuleVectorTlvValue::Index, 2,
U16TlvValue (1)));
347 Tlv tmp_tlv (CsParamVectorTlvValue::Packet_Classification_Rule, ClassVectVal.GetSerializedSize (), ClassVectVal);
a class to represent an Ipv4 address mask
bool CheckMatch(Ipv4Address srcAddress, Ipv4Address dstAddress, uint16_t srcPort, uint16_t dstPort, uint8_t proto) const
check if a packets can be used with this classifier
#define NS_LOG_COMPONENT_DEFINE(name)
Ipv4Address CombineMask(Ipv4Mask const &mask) const
Combine this address with a network mask.
This class implements the Type-Len-Value structure channel encodings as described by "IEEE Standard f...
#define NS_FATAL_ERROR(msg)
fatal error handling
uint16_t GetCid(void) const
void AddSrcAddr(Ipv4Address srcAddress, Ipv4Mask srcMask)
add a new source ip address to the classifier
void AddSrcPortRange(uint16_t srcPortLow, uint16_t srcPortHigh)
add a range of source port to the classifier
void AddDstAddr(Ipv4Address dstAddress, Ipv4Mask dstMask)
add a new destination ip address to the classifier
void SetCid(uint16_t cid)
Set the cid associated to this classifier.
void SetPriority(uint8_t prio)
Set the priority of this classifier.
this class implements the classifier descriptor as a tlv vector
void AddDstPortRange(uint16_t dstPortLow, uint16_t dstPortHigh)
add a range of destination port to the classifier
#define NS_ASSERT_MSG(condition, message)
Ipv4 addresses are stored in host order in this class.
uint16_t GetIndex(void) const
void AddProtocol(uint8_t proto)
add a protocol to the classifier
void SetIndex(uint16_t index)
Set the index of the classifier.
uint8_t GetPriority(void) const
Tlv ToTlv(void) const
Creates a TLV from this classifier.