A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ipv6-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 "ipv6-queue-disc-item.h"
26 #include "ipv6-packet-filter.h"
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("Ipv6PacketFilter");
31 
32 NS_OBJECT_ENSURE_REGISTERED (Ipv6PacketFilter);
33 
34 TypeId
36 {
37  static TypeId tid = TypeId ("ns3::Ipv6PacketFilter")
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<Ipv6QueueDiscItem> (item) != 0);
59 }
60 
61 // ------------------------------------------------------------------------- //
62 
64 
65 TypeId
67 {
68  static TypeId tid = TypeId ("ns3::PfifoFastIpv6PacketFilter")
70  .SetGroupName ("Internet")
71  .AddConstructor<PfifoFastIpv6PacketFilter> ()
72  ;
73  return tid;
74 }
75 
77 {
78  NS_LOG_FUNCTION (this);
79 }
80 
82 {
83  NS_LOG_FUNCTION (this);
84 }
85 
86 int32_t
88 {
89  NS_LOG_FUNCTION (this << item);
90  uint32_t band;
91  Ptr<Ipv6QueueDiscItem> ipv6Item = DynamicCast<Ipv6QueueDiscItem> (item);
92 
93  NS_ASSERT (ipv6Item != 0);
94 
95  Ipv6Header::DscpType dscp = ipv6Item->GetHeader ().GetDscp ();
96  band = DscpToBand (dscp);
97  NS_LOG_DEBUG ("Found Ipv6 packet; DSCP " << ipv6Item->GetHeader ().DscpTypeToString (dscp) << " band " << band);
98 
99  return band;
100 }
101 
102 uint32_t
104 {
105  NS_LOG_FUNCTION (this);
106 
107  uint32_t band = 1;
108  switch (dscpType) {
109  case Ipv6Header::DSCP_EF :
110  case Ipv6Header::DSCP_AF13 :
111  case Ipv6Header::DSCP_AF23 :
112  case Ipv6Header::DSCP_AF33 :
113  case Ipv6Header::DSCP_AF43 :
115  case Ipv6Header::DSCP_CS2 :
116  case Ipv6Header::DSCP_CS3 :
117  band = 1;
118  break;
119  case Ipv6Header::DSCP_AF11 :
120  case Ipv6Header::DSCP_AF21 :
121  case Ipv6Header::DSCP_AF31 :
122  case Ipv6Header::DSCP_AF41 :
123  case Ipv6Header::DSCP_CS1 :
124  band = 2;
125  break;
126  case Ipv6Header::DSCP_AF12 :
127  case Ipv6Header::DSCP_AF22 :
128  case Ipv6Header::DSCP_AF32 :
129  case Ipv6Header::DSCP_AF42 :
130  case Ipv6Header::DSCP_CS4 :
131  case Ipv6Header::DSCP_CS5 :
132  case Ipv6Header::DSCP_CS6 :
133  case Ipv6Header::DSCP_CS7 :
134  band = 0;
135  break;
136  default :
137  band = 1;
138  }
139  NS_LOG_DEBUG ("Band returned: " << band);
140  return band;
141 }
142 
143 } // 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
#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
DscpType
DiffServ Code Points Code Points defined in Assured Forwarding (AF) RFC 2597 Expedited Forwarding (EF...
Definition: ipv6-header.h:44
static TypeId GetTypeId(void)
Get the type ID.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t DscpToBand(Ipv6Header::DscpType dscpType) const
Converts a DSCP field value into a priority band.
virtual int32_t DoClassify(Ptr< QueueDiscItem > item) const
Classify a packet.
PfifoFastIpv6PacketFilter is the filter to be added to the PfifoFast queue disc to simulate the behav...
Ipv6PacketFilter is the abstract base class for filters defined for IPv6 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
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:827
virtual bool CheckProtocol(Ptr< QueueDiscItem > item) const
Checks if the filter is able to classify a kind of items.