You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2016/02/04 20:21:55 UTC

[3/3] mesos git commit: Defined the NetClsHandleManager class.

Defined the NetClsHandleManager class.

This class will be responsible for keeping track of the free and
allocated net_cls handles.

Review: https://reviews.apache.org/r/42586/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5ff85e1d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5ff85e1d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5ff85e1d

Branch: refs/heads/master
Commit: 5ff85e1d1be69fb261ab373bc9ea2fa9e4902f82
Parents: cc877e5
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Thu Feb 4 10:46:09 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Feb 4 11:21:48 2016 -0800

----------------------------------------------------------------------
 .../mesos/isolators/cgroups/net_cls.cpp         | 18 ++++++
 .../mesos/isolators/cgroups/net_cls.hpp         | 63 ++++++++++++++++++++
 2 files changed, 81 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/5ff85e1d/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
index 8821ccd..52a1109 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.cpp
@@ -51,6 +51,24 @@ namespace mesos {
 namespace internal {
 namespace slave {
 
+Try<NetClsHandle> NetClsHandleManager::alloc(uint16_t primary)
+{
+  return Error("Not Implemented");
+}
+
+
+Try<Nothing> NetClsHandleManager::reserve(const NetClsHandle& handle)
+{
+  return Error("Not Implemented");
+}
+
+
+Try<Nothing> NetClsHandleManager::free(const NetClsHandle& handle)
+{
+  return Error("Not Implemented");
+}
+
+
 CgroupsNetClsIsolatorProcess::CgroupsNetClsIsolatorProcess(
     const Flags& _flags,
     const string& _hierarchy)

http://git-wip-us.apache.org/repos/asf/mesos/blob/5ff85e1d/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
index b4bc521..6de2056 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/net_cls.hpp
@@ -17,9 +17,18 @@
 #ifndef __CGROUPS_NET_CLS_ISOLATOR_HPP__
 #define __CGROUPS_NET_CLS_ISOLATOR_HPP__
 
+#include <stdint.h>
+
+#include <bitset>
+#include <iostream>
+#include <sstream>
 #include <string>
 
 #include <stout/hashmap.hpp>
+#include <stout/interval.hpp>
+#include <stout/nothing.hpp>
+#include <stout/result.hpp>
+#include <stout/try.hpp>
 
 #include "slave/containerizer/mesos/isolator.hpp"
 
@@ -27,6 +36,60 @@ namespace mesos {
 namespace internal {
 namespace slave {
 
+// This defines the net_cls handle. The handle is composed of two parts, a
+// 16-bit primary handle and a 16-bit secondary handle.
+//
+// TODO(asridharan): Currently we need to define the net_cls handle here, since
+// we cannot use the definitions in `src/linux/routing/handle.hpp` due to its
+// dependency on `libnl`, which is under GPL. Once we have been able to resolve
+// these issues we should remove this definition and use the definition
+// presented in `src/linux/routing/handle.hpp`.
+struct NetClsHandle
+{
+  NetClsHandle(uint16_t _primary, uint16_t _secondary)
+    : primary(_primary), secondary(_secondary) {};
+
+  explicit NetClsHandle(uint32_t handle)
+  {
+    primary = handle >> 16;
+    secondary = handle & 0xFFFF;
+  };
+
+  uint16_t primary;
+  uint16_t secondary;
+};
+
+
+// This manages the net_cls handles for the `cgroup/net_cls` isolator.  The
+// isolator can use this with a range of primary handles, which will be managed
+// by this class.  For each primary handle there are 64K possible secondary
+// handles.  For a given primary handle the isolator can get a secondary handle
+// by calling `alloc` and release an allocated handle by calling `free` on the
+// secondary handle. For a given primary handle, the isolator can also
+// explicitly reserve a secondary handle by calling `reserve`.
+class NetClsHandleManager
+{
+public:
+  NetClsHandleManager(const IntervalSet<uint16_t>& _primaries)
+    : primaries(_primaries) {};
+
+  ~NetClsHandleManager() {};
+
+  // Allocates a primary handle from the given interval set.
+  Try<uint16_t> allocPrimary() { return Error("Not Implemented");};
+  Try<NetClsHandle> alloc(uint16_t primary);
+
+  Try<Nothing> reserve(const NetClsHandle& handle);
+  Try<Nothing> free(const NetClsHandle& handle);
+
+private:
+  // The key to this hashmap is the 16-bit primary handle.
+  hashmap<uint16_t, std::bitset<0x10000>> used;
+
+  IntervalSet<uint16_t> primaries;
+};
+
+
 // Uses the Linux net_cls subsystem for allocating network handles to
 // containers. The network handles of a net_cls cgroup will be used for tagging
 // packets originating from containers belonging to that cgroup. The tags on the