Repository: mesos Updated Branches: refs/heads/master 4b1282c61 -> a4954e531
Added the missing handle.hpp. Review: https://reviews.apache.org/r/34740 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a4954e53 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a4954e53 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a4954e53 Branch: refs/heads/master Commit: a4954e531ce30635d4ade0ad3d579f708d7a7625 Parents: 4b1282c Author: Paul Brett <[email protected]> Authored: Wed May 27 17:02:12 2015 -0700 Committer: Jie Yu <[email protected]> Committed: Wed May 27 17:03:45 2015 -0700 ---------------------------------------------------------------------- src/linux/routing/handle.hpp | 93 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/a4954e53/src/linux/routing/handle.hpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/handle.hpp b/src/linux/routing/handle.hpp new file mode 100644 index 0000000..8f2da06 --- /dev/null +++ b/src/linux/routing/handle.hpp @@ -0,0 +1,93 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __LINUX_ROUTING_HANDLE_HPP__ +#define __LINUX_ROUTING_HANDLE_HPP__ + +#include <stdint.h> + +#include <netlink/route/tc.h> + +namespace routing { + +// The Linux kernel Traffic Control (TC) uses handles to uniqely +// identify the queueing disciplines (qdiscs), classes and filters +// attached to a network interface. The most common type of handle is +// identified by primary and secondary device numbers (sometimes +// called major and minor numbers) and written as primary:secondary. +// Handles provide the mechanism by which TC classes, qdiscs and +// filters can be connected together to create complex network traffic +// policing policies. +class Handle +{ +public: + explicit Handle(uint32_t _handle) : handle(_handle) {} + + Handle(uint16_t primary, uint16_t secondary) + { + handle = (((uint32_t)primary) << 16) + secondary; + } + + // NOTE: This is used to construct a classid. The higher 16 bits of + // the given 'parent' will be the primary and the lower 16 bits is + // specified by the given 'id'. + Handle(Handle parent, uint16_t id) + { + handle = (((uint32_t)parent.primary()) << 16) + id; + } + + bool operator==(const Handle& that) const + { + return handle == that.handle; + } + + bool operator!=(const Handle& that) const + { + return handle != that.handle; + } + + uint16_t primary() const { return handle >> 16; } + uint16_t secondary() const { return handle & 0x0000ffff; } + uint32_t get() const { return handle; } + +protected: + uint32_t handle; +}; + +// Packets flowing from the device driver to the network stack are +// called ingress traffic, and packets flowing from the network stack +// to the device driver are called egress traffic (shown below). +// +// +---------+ +// | Network | +// | Stack | +// |---------| +// | eth0 | +// +---------+ +// ^ | +// Ingress | | Egress +// | | +// -------+ +------> +// +// The parent of the root egress queueing discipline has an immutable +// handle. +const inline Handle EGRESS_ROOT() { return Handle(TC_H_ROOT); } + +} // namespace routing { + +#endif // __LINUX_ROUTING_HANDLE_HPP__
