Apache Mesos
priority.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_PRIORITY_HPP__
18 #define __LINUX_ROUTING_FILTER_PRIORITY_HPP__
19 
20 #include <stdint.h>
21 
22 namespace routing {
23 namespace filter {
24 
25 // Each filter on a link has a priority (a 16-bit integer). The
26 // priority defines the order in which filters will be applied to each
27 // packet. The lower the number, the higher the priority. In order to
28 // deal with filters of different types, we split the priority into
29 // two 8-bit parts: a primary part and a secondary part. When
30 // comparing two priorities, their primary parts will be compared
31 // first. If they have the same primary part, their secondary parts
32 // will then be compared. Typically, the primary part is used to
33 // define the preference order between different types of filters. For
34 // example, a user may want ICMP packet filters to be always applied
35 // first than IP packet filters. In that case, the user can assign
36 // ICMP packet filters a higher priority in the primary part. If the
37 // user wants to further define orders between filters of the same
38 // type, they can use the secondary part.
39 class Priority
40 {
41 public:
42  explicit Priority(uint16_t priority)
43  {
44  primary = (uint8_t) (priority >> 8);
45  secondary = (uint8_t) priority;
46  }
47 
48  Priority(uint8_t _primary, uint8_t _secondary)
49  : primary(_primary), secondary(_secondary) {}
50 
51  uint16_t get() const
52  {
53  return (((uint16_t) primary) << 8) + secondary;
54  }
55 
56 private:
57  uint8_t primary;
58  uint8_t secondary;
59 };
60 
61 } // namespace filter {
62 } // namespace routing {
63 
64 #endif // __LINUX_ROUTING_FILTER_PRIORITY_HPP__
Definition: priority.hpp:39
Priority(uint16_t priority)
Definition: priority.hpp:42
void filter(Filter *filter)
Priority(uint8_t _primary, uint8_t _secondary)
Definition: priority.hpp:48