Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
IPAllocator.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2022 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19
20#ifndef IPALLOCATOR_H
21#define IPALLOCATOR_H
22
23#include <DobbyRdkPluginUtils.h>
24#include "NetworkingPluginCommon.h"
25
26#include <memory>
27#include <arpa/inet.h>
28#include <queue>
29
30#define TOTAL_ADDRESS_POOL_SIZE 250
31
33
35{
36public:
37 IPAllocator(const std::shared_ptr<DobbyRdkPluginUtils> &utils);
39
40public:
41 in_addr_t allocateIpAddress(const std::string &vethName);
42 in_addr_t allocateIpAddress(const std::string &containerId, const std::string &vethName);
43 bool deallocateIpAddress(const std::string &containerId);
44 bool getContainerNetworkInfo(const std::string &containerId, ContainerNetworkInfo &networkInfo) const;
45
46public:
47 static in_addr_t stringToIpAddress(const std::string &ipAddressStr);
48 static std::string ipAddressToString(const in_addr_t &ipAddress);
49
50private:
52 bool getNetworkInfo(const std::string &filePath, ContainerNetworkInfo &networkInfo) const;
53
54private:
55 const std::shared_ptr<DobbyRdkPluginUtils> mUtils;
56 const in_addr_t mBeginAddress;
57 const in_addr_t mEndAddress;
58
59 std::vector<ContainerNetworkInfo> mAllocatedIps;
60};
61
62#endif
Class for useful utility methods for plugins such as adding mounts and environment variables.
Definition DobbyRdkPluginUtils.h:79
Definition IPAllocator.h:35
bool getNetworkInfo(const std::string &filePath, ContainerNetworkInfo &networkInfo) const
Retrieves the networking information (veth, ip) from a file from the store.
Definition IPAllocator.cpp:179
static std::string ipAddressToString(const in_addr_t &ipAddress)
Convert an IP address to string. Note - doesn't do any byte-order modifications.
Definition IPAllocator.cpp:306
bool getContainerIpsFromDisk()
Synchronise the in-memory pool of allocated IPs with the disk store.
Definition IPAllocator.cpp:221
bool deallocateIpAddress(const std::string &containerId)
Releases a previously allocated IP address back to the pool so it can be re-used by other containers.
Definition IPAllocator.cpp:122
static in_addr_t stringToIpAddress(const std::string &ipAddressStr)
Convert an string to an IP address. Note - doesn't do any byte-order modifications.
Definition IPAllocator.cpp:288
bool getContainerNetworkInfo(const std::string &containerId, ContainerNetworkInfo &networkInfo) const
Retrieves the networking information (veth, ip) for a given container.
Definition IPAllocator.cpp:165
in_addr_t allocateIpAddress(const std::string &vethName)
Allocated an IP address for the currently running container with the specified veth.
Definition IPAllocator.cpp:62
Definition DobbyRdkPluginUtils.h:55