A Discrete-Event Network Simulator
API
ipv4-packet-filter.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 Universita' degli Studi di Napoli Federico II
4  * 2016 University of Washington
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: Stefano Avallone <stavallo@unina.it>
20  * Tom Henderson <tomhend@u.washington.edu>
21  */
22 
23 #include "ns3/log.h"
24 #include "ns3/enum.h"
25 #include "ipv4-queue-disc-item.h"
26 #include "ipv4-packet-filter.h"
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("Ipv4PacketFilter");
31 
32 NS_OBJECT_ENSURE_REGISTERED (Ipv4PacketFilter);
33 
34 TypeId
36 {
37  static TypeId tid = TypeId ("ns3::Ipv4PacketFilter")
39  .SetGroupName ("Internet")
40  ;
41  return tid;
42 }
43 
45 {
46  NS_LOG_FUNCTION (this);
47 }
48 
50 {
51  NS_LOG_FUNCTION (this);
52 }
53 
54 bool
56 {
57  NS_LOG_FUNCTION (this << item);
58  return (DynamicCast<Ipv4QueueDiscItem> (item) != 0);
59 }
60 
61 // ------------------------------------------------------------------------- //
62 
64 
65 TypeId
67 {
68  static TypeId tid = TypeId ("ns3::PfifoFastIpv4PacketFilter")
70  .SetGroupName ("Internet")
71  .AddConstructor<PfifoFastIpv4PacketFilter> ()
72  .AddAttribute ("Mode",
73  "Whether to interpret the TOS byte as legacy TOS or DSCP",
76  MakeEnumChecker (PF_MODE_TOS, "TOS semantics",
77  PF_MODE_DSCP, "DSCP semantics"))
78  ;
79  return tid;
80 }
81 
83 {
84  NS_LOG_FUNCTION (this);
85 }
86 
88 {
89  NS_LOG_FUNCTION (this);
90 }
91 
92 int32_t
94 {
95  NS_LOG_FUNCTION (this << item);
96  uint32_t band;
97  Ptr<Ipv4QueueDiscItem> ipv4Item = DynamicCast<Ipv4QueueDiscItem> (item);
98 
99  NS_ASSERT (ipv4Item != 0);
100 
102  {
103  uint8_t tos = ipv4Item->GetHeader ().GetTos ();
104  band = TosToBand (tos);
105  NS_LOG_DEBUG ("Found Ipv4 packet; TOS " << (uint8_t) tos << " band " << band);
106  }
107  else
108  {
109  Ipv4Header::DscpType dscp = ipv4Item->GetHeader ().GetDscp ();
110  band = DscpToBand (dscp);
111  NS_LOG_DEBUG ("Found Ipv4 packet; DSCP " << ipv4Item->GetHeader ().DscpTypeToString (dscp) << " band " << band);
112  }
113 
114  return band;
115 }
116 
117 uint32_t
119 {
120  NS_LOG_FUNCTION (this << (uint16_t) tos);
121 
122  uint32_t band = 1;
123  switch (tos) {
124  case 0x10 :
125  case 0x12 :
126  case 0x14 :
127  case 0x16 :
128  band = 0;
129  break;
130  case 0x0 :
131  case 0x4 :
132  case 0x6 :
133  case 0x18 :
134  case 0x1a :
135  case 0x1c :
136  case 0x1e :
137  band = 1;
138  break;
139  case 0x2 :
140  case 0x8 :
141  case 0xa :
142  case 0xc :
143  case 0xe :
144  band = 2;
145  break;
146  default :
147  NS_LOG_ERROR ("Invalid TOS " << (uint16_t) tos);
148  }
149  return band;
150 }
151 
152 uint32_t
154 {
155  NS_LOG_FUNCTION (this);
156 
157  uint32_t band = 1;
158  switch (dscpType) {
159  case Ipv4Header::DSCP_EF :
160  case Ipv4Header::DSCP_AF13 :
161  case Ipv4Header::DSCP_AF23 :
162  case Ipv4Header::DSCP_AF33 :
163  case Ipv4Header::DSCP_AF43 :
165  case Ipv4Header::DSCP_CS2 :
166  case Ipv4Header::DSCP_CS3 :
167  band = 1;
168  break;
169  case Ipv4Header::DSCP_AF11 :
170  case Ipv4Header::DSCP_AF21 :
171  case Ipv4Header::DSCP_AF31 :
172  case Ipv4Header::DSCP_AF41 :
173  case Ipv4Header::DSCP_CS1 :
174  band = 2;
175  break;
176  case Ipv4Header::DSCP_AF12 :
177  case Ipv4Header::DSCP_AF22 :
178  case Ipv4Header::DSCP_AF32 :
179  case Ipv4Header::DSCP_AF42 :
180  case Ipv4Header::DSCP_CS4 :
181  case Ipv4Header::DSCP_CS5 :
182  case Ipv4Header::DSCP_CS6 :
183  case Ipv4Header::DSCP_CS7 :
184  band = 0;
185  break;
186  default :
187  band = 1;
188  }
189  NS_LOG_DEBUG ("Band returned: " << band);
190  return band;
191 }
192 
193 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
DscpType
DiffServ Code Points Code Points defined in Assured Forwarding (AF) RFC 2597 Expedited Forwarding (EF...
Definition: ipv4-header.h:65
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: enum.h:209
virtual int32_t DoClassify(Ptr< QueueDiscItem > item) const
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Hold variables of type enum.
Definition: enum.h:54
Ipv4TrafficClassMode m_trafficClassMode
traffic class mode
Every class exported by the ns3 library is enclosed in the ns3 namespace.
PfifoFastIpv4PacketFilter is the filter to be added to the PfifoFast queue disc to simulate the behav...
static TypeId GetTypeId(void)
Get the type ID.
uint32_t DscpToBand(Ipv4Header::DscpType dscpType) const
virtual bool CheckProtocol(Ptr< QueueDiscItem > item) const
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
use DSCP semantics to interpret TOS byte
use legacy TOS semantics to interpret TOS byte
static TypeId GetTypeId(void)
Get the type ID.
Ipv4PacketFilter is the abstract base class for filters defined for IPv4 packets. ...
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
PacketFilter is the abstract base class for filters used by queue discs to classify packets...
Definition: packet-filter.h:34
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:220
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826
uint32_t TosToBand(uint8_t tos) const