mirror of
https://github.com/espressif/openthread.git
synced 2026-08-03 01:17:46 +00:00
[mle] let the command partitionid return the current partition id (#5872)
If user doesn't set the Partition Id using the command 'leaderpartitionid xxx', the current cli command 'leaderpartitionid' always return 0. This commit renames the command 'leaderpartitionid' to partitionid and let the command partitionid returns the current leader Partition Id and add command partitionid preferred to set or get preferred Partition Id.
This commit is contained in:
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (50)
|
||||
#define OPENTHREAD_API_VERSION (51)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -219,23 +219,23 @@ uint8_t otThreadGetLocalLeaderWeight(otInstance *aInstance);
|
||||
void otThreadSetLocalLeaderWeight(otInstance *aInstance, uint8_t aWeight);
|
||||
|
||||
/**
|
||||
* Get the Thread Leader Partition Id used when operating in the Leader role.
|
||||
* Get the preferred Thread Leader Partition Id used when operating in the Leader role.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
*
|
||||
* @returns The Thread Leader Partition Id value.
|
||||
*
|
||||
*/
|
||||
uint32_t otThreadGetLocalLeaderPartitionId(otInstance *aInstance);
|
||||
uint32_t otThreadGetPreferredLeaderPartitionId(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* Set the Thread Leader Partition Id used when operating in the Leader role.
|
||||
* Set the preferred Thread Leader Partition Id used when operating in the Leader role.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aPartitionId The Thread Leader Partition Id value.
|
||||
*
|
||||
*/
|
||||
void otThreadSetLocalLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId);
|
||||
void otThreadSetPreferredLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId);
|
||||
|
||||
/**
|
||||
* Get the Joiner UDP Port.
|
||||
|
||||
+34
-20
@@ -57,7 +57,6 @@ Done
|
||||
- [joinerport](#joinerport-port)
|
||||
- [keysequence](#keysequence-counter)
|
||||
- [leaderdata](#leaderdata)
|
||||
- [leaderpartitionid](#leaderpartitionid)
|
||||
- [leaderweight](#leaderweight)
|
||||
- [linkmetrics](#linkmetrics-mgmt-ipaddr-forward-seriesid-ldraxpqmr)
|
||||
- [linkquality](#linkquality-extaddr)
|
||||
@@ -77,6 +76,7 @@ Done
|
||||
- [panid](#panid)
|
||||
- [parent](#parent)
|
||||
- [parentpriority](#parentpriority)
|
||||
- [partitionid](#partitionid)
|
||||
- [ping](#ping-ipaddr-sizecount-intervalhoplimit)
|
||||
- [pollperiod](#pollperiod-pollperiod)
|
||||
- [preferrouterid](#preferrouterid-routerid)
|
||||
@@ -1093,25 +1093,6 @@ Set Thread Key Switch Guard Time (in hours) 0 means Thread Key Switch imediately
|
||||
Done
|
||||
```
|
||||
|
||||
### leaderpartitionid
|
||||
|
||||
Get the Thread Leader Partition ID.
|
||||
|
||||
```bash
|
||||
> leaderpartitionid
|
||||
4294967295
|
||||
Done
|
||||
```
|
||||
|
||||
### leaderpartitionid \<partitionid\>
|
||||
|
||||
Set the Thread Leader Partition ID.
|
||||
|
||||
```bash
|
||||
> leaderpartitionid 0xffffffff
|
||||
Done
|
||||
```
|
||||
|
||||
### leaderdata
|
||||
|
||||
Show the Thread Leader Data.
|
||||
@@ -1518,6 +1499,39 @@ Set the assigned parent priority value: 1, 0, -1 or -2.
|
||||
Done
|
||||
```
|
||||
|
||||
### partitionid
|
||||
|
||||
Get the Thread Network Partition ID.
|
||||
|
||||
```bash
|
||||
> partitionid
|
||||
4294967295
|
||||
Done
|
||||
```
|
||||
|
||||
### partitionid preferred
|
||||
|
||||
Get the preferred Thread Leader Partition ID.
|
||||
|
||||
`OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE` is required.
|
||||
|
||||
```bash
|
||||
> partitionid preferred
|
||||
4294967295
|
||||
Done
|
||||
```
|
||||
|
||||
### partitionid preferred \<partitionid\>
|
||||
|
||||
Set the preferred Thread Leader Partition ID.
|
||||
|
||||
`OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE` is required.
|
||||
|
||||
```bash
|
||||
> partitionid preferred 0xffffffff
|
||||
Done
|
||||
```
|
||||
|
||||
### ping \<ipaddr\> [size][count] [interval][hoplimit]
|
||||
|
||||
Send an ICMPv6 Echo Request.
|
||||
|
||||
+21
-7
@@ -1881,23 +1881,37 @@ exit:
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
otError Interpreter::ProcessLeaderPartitionId(uint8_t aArgsLength, char *aArgs[])
|
||||
otError Interpreter::ProcessPartitionId(uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
OT_UNUSED_VARIABLE(aArgs);
|
||||
|
||||
otError error = OT_ERROR_INVALID_COMMAND;
|
||||
|
||||
if (aArgsLength == 0)
|
||||
{
|
||||
OutputLine("%u", otThreadGetLocalLeaderPartitionId(mInstance));
|
||||
OutputLine("%u", otThreadGetPartitionId(mInstance));
|
||||
error = OT_ERROR_NONE;
|
||||
}
|
||||
else
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
else if (strcmp(aArgs[0], "preferred") == 0)
|
||||
{
|
||||
uint32_t partitionId;
|
||||
if (aArgsLength == 1)
|
||||
{
|
||||
OutputLine("%u", otThreadGetPreferredLeaderPartitionId(mInstance));
|
||||
error = OT_ERROR_NONE;
|
||||
}
|
||||
else if (aArgsLength == 2)
|
||||
{
|
||||
uint32_t partitionId;
|
||||
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[0], partitionId));
|
||||
otThreadSetLocalLeaderPartitionId(mInstance, partitionId);
|
||||
SuccessOrExit(error = ParseAsUint32(aArgs[1], partitionId));
|
||||
otThreadSetPreferredLeaderPartitionId(mInstance, partitionId);
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
#endif
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -381,7 +381,7 @@ private:
|
||||
otError ProcessKeySequence(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessLeaderData(uint8_t aArgsLength, char *aArgs[]);
|
||||
#if OPENTHREAD_FTD
|
||||
otError ProcessLeaderPartitionId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessPartitionId(uint8_t aArgsLength, char *aArgs[]);
|
||||
otError ProcessLeaderWeight(uint8_t aArgsLength, char *aArgs[]);
|
||||
#endif
|
||||
otError ProcessMasterKey(uint8_t aArgsLength, char *aArgs[]);
|
||||
@@ -661,7 +661,6 @@ private:
|
||||
{"keysequence", &Interpreter::ProcessKeySequence},
|
||||
{"leaderdata", &Interpreter::ProcessLeaderData},
|
||||
#if OPENTHREAD_FTD
|
||||
{"leaderpartitionid", &Interpreter::ProcessLeaderPartitionId},
|
||||
{"leaderweight", &Interpreter::ProcessLeaderWeight},
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_ENABLE
|
||||
@@ -699,6 +698,7 @@ private:
|
||||
{"parent", &Interpreter::ProcessParent},
|
||||
#if OPENTHREAD_FTD
|
||||
{"parentpriority", &Interpreter::ProcessParentPriority},
|
||||
{"partitionid", &Interpreter::ProcessPartitionId},
|
||||
#endif
|
||||
{"ping", &Interpreter::ProcessPing},
|
||||
{"pollperiod", &Interpreter::ProcessPollPeriod},
|
||||
|
||||
@@ -110,19 +110,21 @@ void otThreadSetLocalLeaderWeight(otInstance *aInstance, uint8_t aWeight)
|
||||
instance.Get<Mle::MleRouter>().SetLeaderWeight(aWeight);
|
||||
}
|
||||
|
||||
uint32_t otThreadGetLocalLeaderPartitionId(otInstance *aInstance)
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
uint32_t otThreadGetPreferredLeaderPartitionId(otInstance *aInstance)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
return instance.Get<Mle::MleRouter>().GetLeaderPartitionId();
|
||||
return instance.Get<Mle::MleRouter>().GetPreferredLeaderPartitionId();
|
||||
}
|
||||
|
||||
void otThreadSetLocalLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId)
|
||||
void otThreadSetPreferredLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
return instance.Get<Mle::MleRouter>().SetLeaderPartitionId(aPartitionId);
|
||||
instance.Get<Mle::MleRouter>().SetPreferredLeaderPartitionId(aPartitionId);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint16_t otThreadGetJoinerUdpPort(otInstance *aInstance)
|
||||
{
|
||||
|
||||
@@ -67,7 +67,9 @@ MleRouter::MleRouter(Instance &aInstance)
|
||||
, mRouterUpgradeThreshold(kRouterUpgradeThreshold)
|
||||
, mRouterDowngradeThreshold(kRouterDowngradeThreshold)
|
||||
, mLeaderWeight(kLeaderWeight)
|
||||
, mFixedLeaderPartitionId(0)
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
, mPreferredLeaderPartitionId(0)
|
||||
#endif
|
||||
, mRouterEligible(true)
|
||||
, mAddressSolicitPending(false)
|
||||
, mAddressSolicitRejected(false)
|
||||
@@ -191,7 +193,11 @@ otError MleRouter::BecomeLeader(void)
|
||||
|
||||
mRouterTable.Clear();
|
||||
|
||||
partitionId = mFixedLeaderPartitionId ? mFixedLeaderPartitionId : Random::NonCrypto::GetUint32();
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
partitionId = mPreferredLeaderPartitionId ? mPreferredLeaderPartitionId : Random::NonCrypto::GetUint32();
|
||||
#else
|
||||
partitionId = Random::NonCrypto::GetUint32();
|
||||
#endif
|
||||
|
||||
leaderId = IsRouterIdValid(mPreviousRouterId) ? mPreviousRouterId
|
||||
: Random::NonCrypto::GetUint8InRange(0, kMaxRouterId + 1);
|
||||
|
||||
@@ -157,21 +157,24 @@ public:
|
||||
*/
|
||||
void SetLeaderWeight(uint8_t aWeight) { mLeaderWeight = aWeight; }
|
||||
|
||||
/**
|
||||
* This method returns the fixed Partition Id of Thread network partition for certification testing.
|
||||
*
|
||||
* @returns The Partition Id for this Thread network partition.
|
||||
*
|
||||
*/
|
||||
uint32_t GetLeaderPartitionId(void) const { return mFixedLeaderPartitionId; }
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
|
||||
/**
|
||||
* This method sets the fixed Partition Id for Thread network partition for certification testing.
|
||||
* This method returns the preferred Partition Id when operating in the Leader role for certification testing.
|
||||
*
|
||||
* @param[in] aPartitionId The Leader Partition Id.
|
||||
* @returns The preferred Partition Id value.
|
||||
*
|
||||
*/
|
||||
void SetLeaderPartitionId(uint32_t aPartitionId) { mFixedLeaderPartitionId = aPartitionId; }
|
||||
uint32_t GetPreferredLeaderPartitionId(void) const { return mPreferredLeaderPartitionId; }
|
||||
|
||||
/**
|
||||
* This method sets the preferred Partition Id when operating in the Leader role for certification testing.
|
||||
*
|
||||
* @param[in] aPartitionId The preferred Leader Partition Id.
|
||||
*
|
||||
*/
|
||||
void SetPreferredLeaderPartitionId(uint32_t aPartitionId) { mPreferredLeaderPartitionId = aPartitionId; }
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This method sets the preferred Router Id. Upon becoming a router/leader the node
|
||||
@@ -671,10 +674,12 @@ private:
|
||||
uint8_t mRouterUpgradeThreshold;
|
||||
uint8_t mRouterDowngradeThreshold;
|
||||
uint8_t mLeaderWeight;
|
||||
uint32_t mFixedLeaderPartitionId; ///< only for certification testing
|
||||
bool mRouterEligible : 1;
|
||||
bool mAddressSolicitPending : 1;
|
||||
bool mAddressSolicitRejected : 1;
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
uint32_t mPreferredLeaderPartitionId; ///< only for certification testing
|
||||
#endif
|
||||
bool mRouterEligible : 1;
|
||||
bool mAddressSolicitPending : 1;
|
||||
bool mAddressSolicitRejected : 1;
|
||||
|
||||
uint8_t mRouterId;
|
||||
uint8_t mPreviousRouterId;
|
||||
|
||||
@@ -388,7 +388,9 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey)
|
||||
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_NET_MASTER_KEY),
|
||||
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_NET_KEY_SEQUENCE_COUNTER),
|
||||
#if OPENTHREAD_FTD
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_NET_PARTITION_ID),
|
||||
#endif
|
||||
#endif
|
||||
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING),
|
||||
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_NET_KEY_SWITCH_GUARDTIME),
|
||||
|
||||
@@ -348,6 +348,7 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_PARTITION_ID>(void)
|
||||
{
|
||||
uint32_t partitionId = 0;
|
||||
@@ -355,11 +356,12 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_NET_PARTITION_ID>(voi
|
||||
|
||||
SuccessOrExit(error = mDecoder.ReadUint32(partitionId));
|
||||
|
||||
otThreadSetLocalLeaderPartitionId(mInstance, partitionId);
|
||||
otThreadSetPreferredLeaderPartitionId(mInstance, partitionId);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_CHILD_COUNT_MAX>(void)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/expect -f
|
||||
#
|
||||
# Copyright (c) 2020, The OpenThread Authors.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. Neither the name of the copyright holder nor the
|
||||
# names of its contributors may be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
source "tests/scripts/expect/_common.exp"
|
||||
|
||||
spawn_node 1
|
||||
|
||||
send "partitionid preferred 12345678\n"
|
||||
expect "Done"
|
||||
send "partitionid preferred\n"
|
||||
expect "12345678"
|
||||
expect "Done"
|
||||
send "partitionid invalid\n"
|
||||
expect "Error 35: InvalidCommand"
|
||||
send "partitionid\n"
|
||||
expect "0"
|
||||
expect "Done"
|
||||
|
||||
dispose_all
|
||||
@@ -114,7 +114,7 @@ class Cert_5_5_3_SplitMergeChildren(thread_cert.TestCase):
|
||||
|
||||
self.nodes[LEADER].reset()
|
||||
self._setUpLeader()
|
||||
self.nodes[ROUTER2].set_partition_id(0xffffffff)
|
||||
self.nodes[ROUTER2].set_preferred_partition_id(0xffffffff)
|
||||
|
||||
self.simulator.go(140)
|
||||
|
||||
|
||||
@@ -939,12 +939,12 @@ class NodeImpl:
|
||||
self.send_command(cmd)
|
||||
self._expect('Done')
|
||||
|
||||
def get_partition_id(self):
|
||||
self.send_command('leaderpartitionid')
|
||||
def get_preferred_partition_id(self):
|
||||
self.send_command('partitionid preferred')
|
||||
return self._expect_result(r'\d+')
|
||||
|
||||
def set_partition_id(self, partition_id):
|
||||
cmd = 'leaderpartitionid %d' % partition_id
|
||||
def set_preferred_partition_id(self, partition_id):
|
||||
cmd = 'partitionid preferred %d' % partition_id
|
||||
self.send_command(cmd)
|
||||
self._expect('Done')
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ class TestCase(NcpSupportMixin, unittest.TestCase):
|
||||
self.nodes[i].set_mode(params['mode'])
|
||||
|
||||
if 'partition_id' in params:
|
||||
self.nodes[i].set_partition_id(params['partition_id'])
|
||||
self.nodes[i].set_preferred_partition_id(params['partition_id'])
|
||||
if 'channel' in params:
|
||||
self.nodes[i].set_channel(params['channel'])
|
||||
if 'masterkey' in params:
|
||||
|
||||
@@ -39,6 +39,14 @@
|
||||
#define OPENTHREAD_RADIO 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
*
|
||||
* Define to 1 to enable Thread Test Harness reference device support.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE 1
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
|
||||
*
|
||||
|
||||
@@ -1930,7 +1930,7 @@ class OpenThreadTHCI(object):
|
||||
print('%s call setPartationId' % self)
|
||||
print(partationId)
|
||||
|
||||
cmd = 'leaderpartitionid %s' % (str(hex(partationId)).rstrip('L'))
|
||||
cmd = 'partitionid preferred %s' % (str(hex(partationId)).rstrip('L'))
|
||||
print(cmd)
|
||||
return self.__executeCommand(cmd)[-1] == 'Done'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user