Apache Mesos
handle.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_HANDLE_HPP__
18 #define __LINUX_ROUTING_FILTER_HANDLE_HPP__
19 
20 #include <stdint.h>
21 
22 #include "linux/routing/handle.hpp"
23 
24 namespace routing {
25 namespace filter {
26 
27 // When the number of Linux kernel Traffic Control (TC) objects
28 // attached to an interface is high, the kernel can spend a
29 // significant amount of time looking up TC filters (an operation that
30 // must be performed for every packet on the interface). To speed up
31 // these lookups, an alternative interpretation of the handle bits,
32 // the U32Handle, can be used breaking down the identifier into hash
33 // table id (htid), bucket (hash) and filter item (node) within the
34 // bucket. Careful selection of the handles by the administrator
35 // allows for the construction of hash tables that can significantly
36 // reduce lookup times.
37 // See http://ace-host.stuart.id.au/russell/files/tc/doc/cls_u32.txt
38 class U32Handle : public Handle
39 {
40 public:
41  explicit U32Handle(uint32_t _handle) : Handle(_handle) {}
42 
43  // The format of a u32 filter handle.
44  // +------------+--------+------------+
45  // | htid | hash | node |
46  // +------------+--------+------------+
47  // 12 bits 8 bits 12 bits
48  // NOLINT(readability/ending_punctuation)
49  U32Handle(uint32_t htid, uint32_t hash, uint32_t node)
50  : Handle(((htid & 0xfff) << 20) + ((hash & 0xff) << 12) + (node & 0xfff)) {}
51 
52  virtual ~U32Handle() {}
53 
54  uint32_t htid() const { return handle >> 20; }
55  uint32_t hash() const { return (handle & 0x000ff000) >> 12; }
56  uint32_t node() const { return handle & 0x00000fff; }
57 };
58 
59 } // namespace filter {
60 } // namespace routing {
61 
62 #endif // __LINUX_ROUTING_FILTER_HANDLE_HPP__
uint32_t handle
Definition: handle.hpp:69
U32Handle(uint32_t htid, uint32_t hash, uint32_t node)
Definition: handle.hpp:49
Definition: handle.hpp:38
virtual ~U32Handle()
Definition: handle.hpp:52
U32Handle(uint32_t _handle)
Definition: handle.hpp:41
uint32_t node() const
Definition: handle.hpp:56
Definition: handle.hpp:38
Definition: diagnosis.hpp:30
uint32_t htid() const
Definition: handle.hpp:54
uint32_t hash() const
Definition: handle.hpp:55
void filter(Filter *filter)