Apache Mesos
filter.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __LINUX_ROUTING_FILTER_FILTER_HPP__
18 #define __LINUX_ROUTING_FILTER_FILTER_HPP__
19 
20 #include <vector>
21 
22 #include <process/shared.hpp>
23 
24 #include <stout/option.hpp>
25 
26 #include "linux/routing/handle.hpp"
27 
30 
31 namespace routing {
32 namespace filter {
33 
34 // Our representation of a filter. Each filter is attached to a
35 // 'parent' (either a queueing discipline or queueing class), and
36 // contains a 'classifier' which defines how packets will be matched,
37 // a 'priority' which defines the order in which filters will be
38 // applied, and a series of 'actions' that will be taken when a packet
39 // satisfies the conditions specified in the classifier. If the
40 // priority is not specified, the kernel will assign a priority to the
41 // filter.
42 // TODO(jieyu): Currently, libnl does not support getting all actions
43 // associated with a filter. In other words, the list of actions
44 // obtained from the filter might not be the complete list.
45 template <typename Classifier>
46 struct Filter
47 {
48 public:
49  // Creates a filter with no action.
50  Filter(const Handle& _parent,
51  const Classifier& _classifier,
52  const Option<Priority>& _priority,
53  const Option<Handle>& _handle,
54  const Option<Handle>& _classid)
55  : parent(_parent),
56  classifier(_classifier),
57  priority(_priority),
58  handle(_handle),
59  classid(_classid) {}
60 
61  // TODO(jieyu): Support arbitrary number of actions.
62  template <typename Action>
63  Filter(const Handle& _parent,
64  const Classifier& _classifier,
65  const Option<Priority>& _priority,
66  const Option<Handle>& _handle,
67  const Option<Handle>& _classid,
68  const Action& action)
69  : parent(_parent),
70  classifier(_classifier),
71  priority(_priority),
72  handle(_handle),
73  classid(_classid)
74  {
75  attach(action);
76  }
77 
78  // Attaches an action to this filter.
79  template <typename A>
80  void attach(const A& action)
81  {
82  actions.push_back(process::Shared<action::Action>(new A(action)));
83  }
84 
85  // Each filter is attached to a queueing object (either a queueing
86  // discipline or a queueing class).
88 
89  // The filter specific classifier.
90  Classifier classifier;
91 
92  // The priority of this filter.
94 
95  // The handle of this filter.
97 
98  // The classid of this filter.
99  //
100  // Note: the classid can be used for two purposes:
101  // 1) For a classful queueing discipline, set the class id which
102  // refers to a TC class;
103  // 2) For a classless queueing discipline, set the flow id which
104  // refers to a flow defined by its parent qdisc.
105  // In both cases, the primary portion of a classid refers to its
106  // parent queueing discipline, the secondary portion refers to
107  // either its child queueing discipline or a flow.
108  //
109  // Kernel uses classid and flowid interchangeably. However, in our
110  // code base, we use classid consistently.
112 
113  // The set of actions attached to this filer. Note that we use
114  // Shared here to make Filter copyable.
115  std::vector<process::Shared<action::Action>> actions;
116 };
117 
118 } // namespace filter {
119 } // namespace routing {
120 
121 #endif // __LINUX_ROUTING_FILTER_FILTER_HPP__
Definition: option.hpp:28
Classifier classifier
Definition: filter.hpp:90
Option< Handle > classid
Definition: filter.hpp:111
Definition: handle.hpp:38
Definition: filter.hpp:46
Option< Handle > handle
Definition: filter.hpp:96
Definition: owned.hpp:25
Filter(const Handle &_parent, const Classifier &_classifier, const Option< Priority > &_priority, const Option< Handle > &_handle, const Option< Handle > &_classid, const Action &action)
Definition: filter.hpp:63
Option< Priority > priority
Definition: filter.hpp:93
std::vector< process::Shared< action::Action > > actions
Definition: filter.hpp:115
void attach(const A &action)
Definition: filter.hpp:80
Handle parent
Definition: filter.hpp:87
Filter(const Handle &_parent, const Classifier &_classifier, const Option< Priority > &_priority, const Option< Handle > &_handle, const Option< Handle > &_classid)
Definition: filter.hpp:50
void filter(Filter *filter)