[bbr/br] replace enum constants with constexpr (#6911)

This commit is contained in:
Abtin Keshavarzian
2021-08-10 18:48:55 -07:00
committed by GitHub
parent c3b4a35f42
commit c494b9f25d
7 changed files with 59 additions and 86 deletions
+1 -4
View File
@@ -43,10 +43,7 @@
namespace ot {
namespace BackboneRouter {
enum
{
kBackboneUdpPort = 61631, ///< Backbone TMF UDP Port
};
constexpr uint16_t kBackboneUdpPort = 61631; ///< Backbone TMF UDP Port
/**
* This class implements functionality of the Backbone TMF agent.
+2 -2
View File
@@ -61,7 +61,7 @@ class Leader : public InstanceLocator, private NonCopyable
{
public:
// Primary Backbone Router Service state or state change.
enum State
enum State : uint8_t
{
kStateNone = 0, ///< Not exist (trigger Backbone Router register its service).
kStateAdded, ///< Newly added.
@@ -73,7 +73,7 @@ public:
};
// Domain Prefix state or state change.
enum DomainPrefixState
enum DomainPrefixState : uint8_t
{
kDomainPrefixNone = 0, ///< Not available.
kDomainPrefixAdded, ///< Added.
+1 -4
View File
@@ -169,10 +169,7 @@ public:
uint32_t aTimeSinceLastTransaction);
private:
enum
{
kTimerInterval = 1000,
};
static constexpr uint32_t kTimerInterval = 1000;
#if OPENTHREAD_CONFIG_BACKBONE_ROUTER_MULTICAST_ROUTING_ENABLE
static void HandleMulticastListenerRegistration(void * aContext,
@@ -189,10 +189,7 @@ public:
otBackboneRouterMulticastListenerInfo & aListenerInfo);
private:
enum
{
kMulticastListenersTableSize = OPENTHREAD_CONFIG_MAX_MULTICAST_LISTENERS,
};
static constexpr uint16_t kMulticastListenersTableSize = OPENTHREAD_CONFIG_MAX_MULTICAST_LISTENERS;
static_assert(
kMulticastListenersTableSize >= 75,
+2 -5
View File
@@ -231,10 +231,7 @@ public:
Error GetInfo(const Ip6::Address &aDua, otBackboneRouterNdProxyInfo &aNdProxyInfo);
private:
enum
{
kMaxNdProxyNum = OPENTHREAD_CONFIG_NDPROXY_TABLE_ENTRY_NUM,
};
static constexpr uint16_t kMaxNdProxyNum = OPENTHREAD_CONFIG_NDPROXY_TABLE_ENTRY_NUM;
enum Filter : uint8_t
{
@@ -254,7 +251,7 @@ private:
friend class IteratorBuilder;
private:
enum IteratorType
enum IteratorType : uint8_t
{
kEndIterator,
};
+16 -26
View File
@@ -78,10 +78,7 @@ public:
kRouteInfo = 24, ///< Route Information Option.
};
enum : uint8_t
{
kLengthUnit = 8u, ///< The unit of length in octets.
};
static constexpr uint8_t kLengthUnit = 8; ///< The unit of length in octets.
/**
* This constructor initializes the option with given type and length.
@@ -268,11 +265,8 @@ public:
}
private:
enum : uint8_t
{
kAutoConfigFlagMask = 0x40u, // Bit mask of the Automatic Address Configure flag.
kOnLinkFlagMask = 0x80u, // Bit mask of the On-link flag.
};
static constexpr uint8_t kAutoConfigFlagMask = 0x40; // Bit mask of the Automatic Address Configure flag.
static constexpr uint8_t kOnLinkFlagMask = 0x80; // Bit mask of the On-link flag.
uint8_t mPrefixLength; // The prefix length in bits.
uint8_t mReserved1; // The reserved field.
@@ -358,18 +352,12 @@ public:
bool IsValid(void) const;
private:
enum : uint8_t
{
kPreferenceMask = 0x18u,
kPreferenceOffset = 3u,
};
static constexpr uint8_t kPreferenceMask = 0x18;
static constexpr uint8_t kPreferenceOffset = 3;
enum : uint8_t
{
kPreferenceLow = 0x03,
kPreferenceMed = 0x00,
kPreferenceHigh = 0x01,
};
static constexpr uint8_t kPreferenceLow = 0x03;
static constexpr uint8_t kPreferenceMed = 0x00;
static constexpr uint8_t kPreferenceHigh = 0x01;
uint8_t mPrefixLength; // The prefix length in bits.
uint8_t mReserved; // The reserved field.
@@ -461,12 +449,14 @@ public:
bool operator==(const RouterAdvMessage &aOther) const;
private:
enum : uint8_t
{
kRouteLifetimeIdx = 1u, // The index of Route Lifetime in ICMPv6 Header Data. In unit of 2 octets.
kReservedIdx = 1u, // The idex of Reserved byte in ICMPv6 Header Data. In unit of 1 octet.
kManagedAddressConfigMask = 0x80u, // The bitmask of the Managed Address Configuration ('m') flag.
};
// The index of Route Lifetime in ICMPv6 Header Data. In unit of 2 octets.
static constexpr uint8_t kRouteLifetimeIdx = 1;
// The index of Reserved byte in ICMPv6 Header Data. In unit of 1 octet.
static constexpr uint8_t kReservedIdx = 1;
// The bitmask of the Managed Address Configuration ('m') flag.
static constexpr uint8_t kManagedAddressConfigMask = 0x80;
Ip6::Icmp::Header mHeader; // The common ICMPv6 header.
uint32_t mReachableTime; // The reachable time. In milliseconds.
+36 -41
View File
@@ -141,52 +141,47 @@ public:
Error HandleInfraIfStateChanged(uint32_t aInfraIfIndex, bool aIsRunning);
private:
enum : uint16_t
{
kMaxRouterAdvMessageLength = 256u, // The maximum RA message length we can handle.
};
static constexpr uint16_t kMaxRouterAdvMessageLength = 256; // The maximum RA message length we can handle.
enum : uint8_t
{
kMaxOmrPrefixNum =
OPENTHREAD_CONFIG_IP6_SLAAC_NUM_ADDRESSES, // The maximum number of the OMR prefixes to advertise.
kMaxDiscoveredPrefixNum = 8u, // The maximum number of prefixes to discover on the infra link.
kOmrPrefixLength = OT_IP6_PREFIX_BITSIZE, // The length of an OMR prefix. In bits.
kOnLinkPrefixLength = OT_IP6_PREFIX_BITSIZE, // The length of an On-link prefix. In bits.
};
// The maximum number of the OMR prefixes to advertise.
static constexpr uint8_t kMaxOmrPrefixNum = OPENTHREAD_CONFIG_IP6_SLAAC_NUM_ADDRESSES;
enum : uint32_t
{
kMaxInitRtrAdvertisements = 3, // The maximum number of initial Router Advertisements.
kMaxRtrSolicitations = 3, // The Maximum number of Router Solicitations before sending Router Advertisements.
};
// The maximum number of prefixes to discover on the infra link.
static constexpr uint8_t kMaxDiscoveredPrefixNum = 8;
enum : uint32_t
{
kDefaultOmrPrefixLifetime = 1800, // The default OMR prefix valid lifetime. In seconds.
kDefaultOnLinkPrefixLifetime = 1800, // The default on-link prefix valid lifetime. In seconds.
kMaxRtrAdvInterval = 600, // Maximum Router Advertisement Interval. In seconds.
kMinRtrAdvInterval = kMaxRtrAdvInterval / 3, // Minimum Router Advertisement Interval. In seconds.
kMaxInitRtrAdvInterval = 16, // Maximum Initial Router Advertisement Interval. In seconds.
kMaxRaDelayTime = 500, // The maximum delay of sending RA after receiving RS. In milliseconds.
kRtrSolicitationInterval = 4, // The interval between Router Solicitations. In seconds.
kMaxRtrSolicitationDelay = 1, // The maximum delay for initial solicitation. In seconds.
kMaxRoutingPolicyDelay = 1, // The maximum delay for routing policy evaluation. In seconds.
static constexpr uint8_t kOmrPrefixLength = OT_IP6_PREFIX_BITSIZE; // The length of an OMR prefix. In bits.
static constexpr uint8_t kOnLinkPrefixLength = OT_IP6_PREFIX_BITSIZE; // The length of an On-link prefix. In bits.
// The STALE_RA_TIME in seconds. The Routing Manager will consider the prefixes
// and learned RA parameters STALE when they are not refreshed in STALE_RA_TIME
// seconds. The Routing Manager will then start Router Solicitation to verify
// that the STALE prefix is not being advertised anymore and remove the STALE
// prefix.
// The value is chosen in range of [`kMaxRtrAdvInterval` upper bound (1800s), `kDefaultOnLinkPrefixLifetime`].
kRtrAdvStaleTime = 1800,
// The maximum number of initial Router Advertisements.
static constexpr uint32_t kMaxInitRtrAdvertisements = 3;
// The VICARIOUS_SOLICIT_TIME in seconds. The Routing Manager will consider
// the discovered prefixes invalid if they are not refreshed after receiving
// a Router Solicitation message.
// The value is equal to Router Solicitation timeout.
kVicariousSolicitationTime = kRtrSolicitationInterval * (kMaxRtrSolicitations - 1) + kMaxRtrSolicitationDelay,
};
// The maximum number of Router Solicitations before sending Router Advertisements.
static constexpr uint32_t kMaxRtrSolicitations = 3;
static constexpr uint32_t kDefaultOmrPrefixLifetime = 1800; // The default OMR prefix valid lifetime. In sec.
static constexpr uint32_t kDefaultOnLinkPrefixLifetime = 1800; // The default on-link prefix valid lifetime. In sec.
static constexpr uint32_t kMaxRtrAdvInterval = 600; // Max Router Advertisement Interval. In sec.
static constexpr uint32_t kMinRtrAdvInterval = kMaxRtrAdvInterval / 3; // Min RA Interval. In sec.
static constexpr uint32_t kMaxInitRtrAdvInterval = 16; // Max Initial RA Interval. In sec.
static constexpr uint32_t kMaxRaDelayTime = 500; // Max delay of sending RA after rx RS. In msec.
static constexpr uint32_t kRtrSolicitationInterval = 4; // Interval between RSs. In sec.
static constexpr uint32_t kMaxRtrSolicitationDelay = 1; // Max delay for initial solicitation. In sec.
static constexpr uint32_t kMaxRoutingPolicyDelay = 1; // Max delay for routing policy evaluation. In sec.
// The STALE_RA_TIME in seconds. The Routing Manager will consider the prefixes
// and learned RA parameters STALE when they are not refreshed in STALE_RA_TIME
// seconds. The Routing Manager will then start Router Solicitation to verify
// that the STALE prefix is not being advertised anymore and remove the STALE
// prefix.
// The value is chosen in range of [`kMaxRtrAdvInterval` upper bound (1800s), `kDefaultOnLinkPrefixLifetime`].
static constexpr uint32_t kRtrAdvStaleTime = 1800;
// The VICARIOUS_SOLICIT_TIME in seconds. The Routing Manager will consider
// the discovered prefixes invalid if they are not refreshed after receiving
// a Router Solicitation message.
// The value is equal to Router Solicitation timeout.
static constexpr uint32_t kVicariousSolicitationTime =
kRtrSolicitationInterval * (kMaxRtrSolicitations - 1) + kMaxRtrSolicitationDelay;
static_assert(kMinRtrAdvInterval <= 3 * kMaxRtrAdvInterval / 4, "invalid RA intervals");
static_assert(kDefaultOmrPrefixLifetime >= kMaxRtrAdvInterval, "invalid default OMR prefix lifetime");