Add Bonds, Slaves, and Flows
This commit is contained in:
parent
de9cfbe9b0
commit
a50e8e9878
31 changed files with 4898 additions and 1966 deletions
231
node/BondController.hpp
Normal file
231
node/BondController.hpp
Normal file
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* Copyright (c)2013-2020 ZeroTier, Inc.
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file in the project's root directory.
|
||||
*
|
||||
* Change Date: 2024-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2.0 of the Apache License.
|
||||
*/
|
||||
/****/
|
||||
|
||||
#ifndef ZT_BONDCONTROLLER_HPP
|
||||
#define ZT_BONDCONTROLLER_HPP
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "SharedPtr.hpp"
|
||||
#include "../osdep/Phy.hpp"
|
||||
#include "../osdep/Slave.hpp"
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
class RuntimeEnvironment;
|
||||
class Bond;
|
||||
class Peer;
|
||||
|
||||
class BondController
|
||||
{
|
||||
friend class Bond;
|
||||
|
||||
public:
|
||||
|
||||
BondController(const RuntimeEnvironment *renv);
|
||||
|
||||
/**
|
||||
* @return The minimum interval required to poll the active bonds to fulfill all active monitoring timing requirements.
|
||||
*/
|
||||
bool slaveAllowed(std::string &policyAlias, SharedPtr<Slave> slave);
|
||||
|
||||
/**
|
||||
* @return The minimum interval required to poll the active bonds to fulfill all active monitoring timing requirements.
|
||||
*/
|
||||
int minReqPathMonitorInterval() { return _minReqPathMonitorInterval; }
|
||||
|
||||
/**
|
||||
* @return The minimum interval required to poll the active bonds to fulfill all active monitoring timing requirements.
|
||||
*/
|
||||
static void setMinReqPathMonitorInterval(int minReqPathMonitorInterval) { _minReqPathMonitorInterval = minReqPathMonitorInterval; }
|
||||
|
||||
/**
|
||||
* @return Whether the bonding layer is currently set up to be used.
|
||||
*/
|
||||
bool inUse() { return !_bondPolicyTemplates.empty() || _defaultBondingPolicy; }
|
||||
|
||||
/**
|
||||
* @param basePolicyName Bonding policy name (See ZeroTierOne.h)
|
||||
* @return The bonding policy code for a given human-readable bonding policy name
|
||||
*/
|
||||
static int getPolicyCodeByStr(const std::string& basePolicyName)
|
||||
{
|
||||
if (basePolicyName == "active-backup") { return 1; }
|
||||
if (basePolicyName == "broadcast") { return 2; }
|
||||
if (basePolicyName == "balance-rr") { return 3; }
|
||||
if (basePolicyName == "balance-xor") { return 4; }
|
||||
if (basePolicyName == "balance-aware") { return 5; }
|
||||
return 0; // "none"
|
||||
}
|
||||
|
||||
/**
|
||||
* @param policy Bonding policy code (See ZeroTierOne.h)
|
||||
* @return The human-readable name for the given bonding policy code
|
||||
*/
|
||||
static std::string getPolicyStrByCode(int policy)
|
||||
{
|
||||
if (policy == 1) { return "active-backup"; }
|
||||
if (policy == 2) { return "broadcast"; }
|
||||
if (policy == 3) { return "balance-rr"; }
|
||||
if (policy == 4) { return "balance-xor"; }
|
||||
if (policy == 5) { return "balance-aware"; }
|
||||
return "none";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default bonding policy for new or undefined bonds.
|
||||
*
|
||||
* @param bp Bonding policy
|
||||
*/
|
||||
void setBondingLayerDefaultPolicy(uint8_t bp) { _defaultBondingPolicy = bp; }
|
||||
|
||||
/**
|
||||
* Sets the default (custom) bonding policy for new or undefined bonds.
|
||||
*
|
||||
* @param alias Human-readable string alias for bonding policy
|
||||
*/
|
||||
void setBondingLayerDefaultPolicyStr(std::string alias) { _defaultBondingPolicyStr = alias; }
|
||||
|
||||
/**
|
||||
* @return The default bonding policy
|
||||
*/
|
||||
static int defaultBondingPolicy() { return _defaultBondingPolicy; }
|
||||
|
||||
/**
|
||||
* Add a user-defined slave to a given bonding policy.
|
||||
*
|
||||
* @param policyAlias User-defined custom name for variant of bonding policy
|
||||
* @param slave Pointer to new slave definition
|
||||
*/
|
||||
void addCustomSlave(std::string& policyAlias, SharedPtr<Slave> slave);
|
||||
|
||||
/**
|
||||
* Add a user-defined bonding policy that is based on one of the standard types.
|
||||
*
|
||||
* @param newBond Pointer to custom Bond object
|
||||
* @return Whether a uniquely-named custom policy was successfully added
|
||||
*/
|
||||
bool addCustomPolicy(const SharedPtr<Bond>& newBond);
|
||||
|
||||
/**
|
||||
* Assigns a specific bonding policy
|
||||
*
|
||||
* @param identity
|
||||
* @param policyAlias
|
||||
* @return
|
||||
*/
|
||||
bool assignBondingPolicyToPeer(int64_t identity, const std::string& policyAlias);
|
||||
|
||||
/**
|
||||
* Add a new bond to the bond controller.
|
||||
*
|
||||
* @param renv Runtime environment
|
||||
* @param peer Remote peer that this bond services
|
||||
* @return A pointer to the newly created Bond
|
||||
*/
|
||||
SharedPtr<Bond> createTransportTriggeredBond(const RuntimeEnvironment *renv, const SharedPtr<Peer>& peer);
|
||||
|
||||
/**
|
||||
* Periodically perform maintenance tasks for the bonding layer.
|
||||
*
|
||||
* @param tPtr Thread pointer to be handed through to any callbacks called as a result of this call
|
||||
* @param now Current time
|
||||
*/
|
||||
void processBackgroundTasks(void *tPtr, int64_t now);
|
||||
|
||||
/**
|
||||
* Gets a reference to a physical slave definition given a policy alias and a local socket.
|
||||
*
|
||||
* @param policyAlias Policy in use
|
||||
* @param localSocket Local source socket
|
||||
* @return Physical slave definition
|
||||
*/
|
||||
SharedPtr<Slave> getSlaveBySocket(const std::string& policyAlias, uint64_t localSocket);
|
||||
|
||||
/**
|
||||
* Gets a reference to a physical slave definition given its human-readable system name.
|
||||
*
|
||||
* @param policyAlias Policy in use
|
||||
* @param ifname Alphanumeric human-readable name
|
||||
* @return Physical slave definition
|
||||
*/
|
||||
SharedPtr<Slave> getSlaveByName(const std::string& policyAlias, const std::string& ifname);
|
||||
|
||||
/**
|
||||
* @param ifname Name of interface that we want to know if we can bind to
|
||||
*/
|
||||
bool allowedToBind(const std::string& ifname);
|
||||
|
||||
uint64_t getBondStartTime() { return bondStartTime; }
|
||||
|
||||
private:
|
||||
|
||||
Phy<BondController *> *_phy;
|
||||
const RuntimeEnvironment *RR;
|
||||
|
||||
Mutex _bonds_m;
|
||||
Mutex _slaves_m;
|
||||
|
||||
/**
|
||||
* The last time that the bond controller updated the set of bonds.
|
||||
*/
|
||||
uint64_t _lastBackgroundBondControlTaskCheck;
|
||||
|
||||
/**
|
||||
* The minimum monitoring interval among all paths in this bond.
|
||||
*/
|
||||
static int _minReqPathMonitorInterval;
|
||||
|
||||
/**
|
||||
* The default bonding policy used for new bonds unless otherwise specified.
|
||||
*/
|
||||
static uint8_t _defaultBondingPolicy;
|
||||
|
||||
/**
|
||||
* The default bonding policy used for new bonds unless otherwise specified.
|
||||
*/
|
||||
std::string _defaultBondingPolicyStr;
|
||||
|
||||
/**
|
||||
* All currently active bonds.
|
||||
*/
|
||||
std::map<int64_t,SharedPtr<Bond> > _bonds;
|
||||
|
||||
/**
|
||||
* Map of peers to custom bonding policies
|
||||
*/
|
||||
std::map<int64_t,std::string> _policyTemplateAssignments;
|
||||
|
||||
/**
|
||||
* User-defined bonding policies (can be assigned to a peer)
|
||||
*/
|
||||
std::map<std::string,SharedPtr<Bond> > _bondPolicyTemplates;
|
||||
|
||||
/**
|
||||
* Set of slaves defined for a given bonding policy
|
||||
*/
|
||||
std::map<std::string,std::vector<SharedPtr<Slave> > > _slaveDefinitions;
|
||||
|
||||
/**
|
||||
* Set of slave objects mapped to their physical interfaces
|
||||
*/
|
||||
std::map<std::string, std::map<std::string, SharedPtr<Slave> > > _interfaceToSlaveMap;
|
||||
|
||||
// TODO: Remove
|
||||
uint64_t bondStartTime;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue