Skip to content

Commit

Permalink
[routing-manager] support Advertising PIO (AP) flag in published route
Browse files Browse the repository at this point in the history
This commit adds support for the Advertising PIO (AP) flag in Network
Data `ExternalRoute` entries. It also updates the `RoutingManager`
class to set the AP flag on its published Network Data route when the
local on-link prefix is included as PIO in emitted RA messages, which
is equivalent to when the local on-link prefix is being published,
advertised, or deprecated.

This commit also updates the `test_routing_manager` unit test to
validate the AP flag in the published route under different
scenarios.
  • Loading branch information
abtink committed Jul 12, 2023
1 parent 34e9b92 commit c1fc685
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 64 deletions.
2 changes: 1 addition & 1 deletion include/openthread/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (344)
#define OPENTHREAD_API_VERSION (345)

/**
* @addtogroup api-instance
Expand Down
1 change: 1 addition & 0 deletions include/openthread/netdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ typedef struct otExternalRouteConfig
bool mNat64 : 1; ///< Whether this is a NAT64 prefix.
bool mStable : 1; ///< Whether this configuration is considered Stable Network Data.
bool mNextHopIsThisDevice : 1; ///< Whether the next hop is this device (value ignored on config add).
bool mAdvPio : 1; ///< Whether or not BR is advertising a ULA prefix in PIO (AP flag).
} otExternalRouteConfig;

/**
Expand Down
3 changes: 2 additions & 1 deletion src/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3020,12 +3020,13 @@ Get the external route list in the local Network Data.
Done
```
### route add \<prefix\> [sn][prf]
### route add \<prefix\> [sna][prf]
Add a valid external route to the Network Data.
- s: Stable flag
- n: NAT64 flag
- a: Advertising PIO (AP) flag
- prf: Default Router Preference, which may be: 'high', 'med', or 'low'.
```bash
Expand Down
3 changes: 3 additions & 0 deletions src/cli/README_NETDATA.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ Publish an external route entry.

- s: Stable flag
- n: NAT64 flag
- a: Advertising PIO (AP) flag
- prf: Preference, which may be: 'high', 'med', or 'low'.

```bash
Expand All @@ -312,6 +313,7 @@ If there is no previously published external route matching old prefix, this com

- s: Stable flag
- n: NAT64 flag
- a: Advertising PIO (AP) flag
- prf: Preference, which may be: 'high', 'med', or 'low'.

```bash
Expand Down Expand Up @@ -358,6 +360,7 @@ External Routes are listed under `Routes` header:
- Flags
- s: Stable flag
- n: NAT64 flag
- a: Advertising PIO (AP) flag
- Preference `high`, `med`, or `low`
- RLOC16 of device which added the route prefix

Expand Down
4 changes: 4 additions & 0 deletions src/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6321,6 +6321,10 @@ otError Interpreter::ParseRoute(Arg aArgs[], otExternalRouteConfig &aConfig)
aConfig.mNat64 = true;
break;

case 'a':
aConfig.mAdvPio = true;
break;

case '-':
break;

Expand Down
5 changes: 5 additions & 0 deletions src/cli/cli_network_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ void NetworkData::RouteFlagsToString(const otExternalRouteConfig &aConfig, Flags
*flagsPtr++ = 'n';
}

if (aConfig.mAdvPio)
{
*flagsPtr++ = 'a';
}

*flagsPtr = '\0';
}

Expand Down
21 changes: 20 additions & 1 deletion src/core/border_router/routing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,12 @@ void RoutingManager::OnLinkPrefixManager::SetState(State aState)
mLocalPrefix.ToString().AsCString());
mState = aState;

// Mark the Advertising PIO (AP) flag in the published route, when
// the local on-link prefix is being published, advertised, or
// deprecated.

Get<RoutingManager>().mRoutePublisher.UpdateAdvPioFlags(aState != kIdle);

exit:
return;
}
Expand Down Expand Up @@ -2745,6 +2751,7 @@ RoutingManager::RoutePublisher::RoutePublisher(Instance &aInstance)
, mState(kDoNotPublish)
, mPreference(NetworkData::kRoutePreferenceMedium)
, mUserSetPreference(false)
, mAdvPioFlag(false)
, mTimer(aInstance)
{
}
Expand Down Expand Up @@ -2799,7 +2806,8 @@ void RoutingManager::RoutePublisher::UpdatePublishedRoute(State aNewState)
{
// Updates the published route entry in Network Data, transitioning
// from current `mState` to new `aNewState`. This method can be used
// when there is no change to `mState` but a change to `mPreference`.
// when there is no change to `mState` but a change to `mPreference`
// or `mAdvPioFlag`.

Ip6::Prefix oldPrefix;
NetworkData::ExternalRouteConfig routeConfig;
Expand All @@ -2815,6 +2823,7 @@ void RoutingManager::RoutePublisher::UpdatePublishedRoute(State aNewState)

routeConfig.Clear();
routeConfig.mPreference = mPreference;
routeConfig.mAdvPio = mAdvPioFlag;
routeConfig.mStable = true;
DeterminePrefixFor(aNewState, routeConfig.GetPrefix());

Expand Down Expand Up @@ -2855,6 +2864,16 @@ void RoutingManager::RoutePublisher::Unpublish(void)
return;
}

void RoutingManager::RoutePublisher::UpdateAdvPioFlags(bool aAdvPioFlag)
{
VerifyOrExit(mAdvPioFlag != aAdvPioFlag);
mAdvPioFlag = aAdvPioFlag;
UpdatePublishedRoute(mState);

exit:
return;
}

void RoutingManager::RoutePublisher::SetPreference(RoutePreference aPreference)
{
LogInfo("User explicitly set published route preference to %s", RoutePreferenceToString(aPreference));
Expand Down
3 changes: 3 additions & 0 deletions src/core/border_router/routing_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ class RoutingManager : public InstanceLocator
void Stop(void) { Unpublish(); }
void Evaluate(void);

void UpdateAdvPioFlags(bool aAdvPioFlag);

RoutePreference GetPreference(void) const { return mPreference; }
void SetPreference(RoutePreference aPreference);
void ClearPreference(void);
Expand Down Expand Up @@ -1022,6 +1024,7 @@ class RoutingManager : public InstanceLocator
State mState;
RoutePreference mPreference;
bool mUserSetPreference;
bool mAdvPioFlag;
DelayTimer mTimer;
};

Expand Down
10 changes: 10 additions & 0 deletions src/core/thread/network_data_tlvs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,15 @@ class HasRouteEntry : public Equatable<HasRouteEntry>
*/
bool IsNat64(void) const { return (mFlags & kNat64Flag) != 0; }

/**
* Indicates whether or not the Advertising PIO (AP) flag is set.
*
* @retval TRUE If the AP flag is set.
* @retval FALSE If the AP flag is not set.
*
*/
bool IsAdvPio(void) const { return (mFlags & kAdvPioFlag) != 0; }

/**
* Returns a pointer to the next HasRouteEntry.
*
Expand Down Expand Up @@ -508,6 +517,7 @@ class HasRouteEntry : public Equatable<HasRouteEntry>
static constexpr uint8_t kPreferenceOffset = 6;
static constexpr uint8_t kPreferenceMask = 3 << kPreferenceOffset;
static constexpr uint8_t kNat64Flag = 1 << 5;
static constexpr uint8_t kAdvPioFlag = 1 << 4;

uint16_t mRloc;
uint8_t mFlags;
Expand Down
6 changes: 6 additions & 0 deletions src/core/thread/network_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ uint8_t ExternalRouteConfig::ConvertToTlvFlags(void) const
flags |= HasRouteEntry::kNat64Flag;
}

if (mAdvPio)
{
flags |= HasRouteEntry::kAdvPioFlag;
}

flags |= (RoutePreferenceToValue(mPreference) << HasRouteEntry::kPreferenceOffset);

return flags;
Expand All @@ -208,6 +213,7 @@ void ExternalRouteConfig::SetFrom(Instance &aInstance,
void ExternalRouteConfig::SetFromTlvFlags(uint8_t aFlags)
{
mNat64 = ((aFlags & HasRouteEntry::kNat64Flag) != 0);
mAdvPio = ((aFlags & HasRouteEntry::kAdvPioFlag) != 0);
mPreference = RoutePreferenceFromValue(aFlags >> HasRouteEntry::kPreferenceOffset);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_network_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void TestNetworkDataIterator(void)
false, // mNat64
false, // mStable
false, // mNextHopIsThisDevice
false, // mAdvPio
},
{
{
Expand All @@ -146,6 +147,7 @@ void TestNetworkDataIterator(void)
false, // mNat64
true, // mStable
false, // mNextHopIsThisDevice
false, // mAdvPio
},
};

Expand Down
Loading

0 comments on commit c1fc685

Please sign in to comment.