mirror of
https://github.com/espressif/openthread.git
synced 2026-08-19 17:09:51 +00:00
[low-power] implement forward tracking series (#5608)
This commit implements the Forward Tracking Series feature in Link Metrics.
- Two new apis are added:
- otLinkMetricsSendMgmtRequestForwardTrackingSeries, which is used
to send an MLE Link Metrics Management Request
- otLinkMetricsSendLinkProbe, which is used to send an MLE Link Probe
- A new class LinkMetricsSeriesInfo is used to maintain the data of
one Series configured by a neighbor. This class inherits
LinkedListEntry and each Neighbor has a list of
LinkMetricsSeriesInfo. All LinkedListEntrys are allocated and freed
by a Pool in LinkMetrics.
- To specify SeriesFlags in cli command for Forward Tracking Series, a
similar approach with LinkMetricsFlags is used. Another character
flags is used to represent SeriesFlags.
- Whenever the node receives a frame (including ACK) from a neighbor,
it would call Neighbor::AggregateLinkMetrics which goes through each
LinkMetricsSeriesInfo entry in the neighbor's list and aggregate the
data if the frame type matches the entry.
- Two test scripts are added to test this function:
- v1_2_LowPower_7_2_01_ForwardTrackingSeries.py
- v1_2_LowPower_test_forward_tracking_series.py
This commit is contained in:
@@ -259,7 +259,9 @@ def create_default_mle_tlvs_factories():
|
||||
mle.TlvType.TIME_PARAMETER: mle.TimeParameterFactory(),
|
||||
mle.TlvType.THREAD_DISCOVERY: create_default_mle_tlv_thread_discovery_factory(),
|
||||
mle.TlvType.LINK_METRICS_QUERY: mle.LinkMetricsQueryFactory(),
|
||||
mle.TlvType.LINK_METRICS_MANAGEMENT: mle.LinkMetricsManagementFactory(),
|
||||
mle.TlvType.LINK_METRICS_REPORT: mle.LinkMetricsReportFactory(),
|
||||
mle.TlvType.LINK_PROBE: mle.LinkProbeFactory(),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -58,6 +58,9 @@ class CommandType(IntEnum):
|
||||
ANNOUNCE = 15
|
||||
DISCOVERY_REQUEST = 16
|
||||
DISCOVERY_RESPONSE = 17
|
||||
LINK_METRICS_MANAGEMENT_REQUEST = 18
|
||||
LINK_METRICS_MANAGEMENT_RESPONSE = 19
|
||||
LINK_PROBE = 20
|
||||
TIME_SYNC = 99
|
||||
|
||||
|
||||
@@ -90,11 +93,22 @@ class TlvType(IntEnum):
|
||||
CSL_CHANNEL = 80
|
||||
CSL_SYNCHRONIZED_TIMEOUT = 85
|
||||
LINK_METRICS_QUERY = 87
|
||||
LINK_METRICS_MANAGEMENT = 88
|
||||
LINK_METRICS_REPORT = 89
|
||||
LINK_PROBE = 90
|
||||
TIME_REQUEST = 252
|
||||
TIME_PARAMETER = 253
|
||||
|
||||
|
||||
class LinkMetricsSubTlvType(IntEnum):
|
||||
LINK_METRICS_REPORT = 0
|
||||
LINK_METRICS_QUERY_ID = 1
|
||||
LINK_METRICS_QUERY_OPTIONS = 2
|
||||
FORWARD_PROBING_REGISTRATION = 3
|
||||
LINK_METRICS_STATUS = 5
|
||||
ENHANCED_ACK_LINK_METRICS_CONFIGURATION = 7
|
||||
|
||||
|
||||
class SourceAddress(object):
|
||||
|
||||
def __init__(self, address):
|
||||
@@ -1117,6 +1131,19 @@ class LinkMetricsQueryFactory:
|
||||
return LinkMetricsQuery()
|
||||
|
||||
|
||||
class LinkMetricsManagement:
|
||||
# TODO: Not implemented yet
|
||||
|
||||
def __init__(self):
|
||||
print("LinkMetricsManagement is not implemented yet.")
|
||||
|
||||
|
||||
class LinkMetricsManagementFactory:
|
||||
|
||||
def parse(self, data, message_info):
|
||||
return LinkMetricsManagement()
|
||||
|
||||
|
||||
class LinkMetricsReport:
|
||||
# TODO: Not implemented yet
|
||||
|
||||
@@ -1130,6 +1157,19 @@ class LinkMetricsReportFactory:
|
||||
return LinkMetricsReport()
|
||||
|
||||
|
||||
class LinkProbe:
|
||||
# TODO: Not implemented yet
|
||||
|
||||
def __init__(self):
|
||||
print("LinkProbe is not implemented yet.")
|
||||
|
||||
|
||||
class LinkProbeFactory:
|
||||
|
||||
def parse(self, data, message_info):
|
||||
return LinkProbe()
|
||||
|
||||
|
||||
class MleCommand(object):
|
||||
|
||||
def __init__(self, _type, tlvs):
|
||||
|
||||
@@ -1920,6 +1920,22 @@ class NodeImpl:
|
||||
self.send_command(cmd)
|
||||
self._expect('Done')
|
||||
|
||||
def link_metrics_query_forward_tracking_series(self, dst_addr: str, series_id: int):
|
||||
cmd = 'linkmetrics query %s forward %d' % (dst_addr, series_id)
|
||||
self.send_command(cmd)
|
||||
self._expect('Done')
|
||||
|
||||
def link_metrics_mgmt_req_forward_tracking_series(self, dst_addr: str, series_id: int, series_flags: str,
|
||||
metrics_flags: str):
|
||||
cmd = "linkmetrics mgmt %s forward %d %s %s" % (dst_addr, series_id, series_flags, metrics_flags)
|
||||
self.send_command(cmd)
|
||||
self._expect('Done')
|
||||
|
||||
def link_metrics_send_link_probe(self, dst_addr: str, series_id: int, length: int):
|
||||
cmd = "linkmetrics probe %s %d %d" % (dst_addr, series_id, length)
|
||||
self.send_command(cmd)
|
||||
self._expect('Done')
|
||||
|
||||
def send_address_notification(self, dst: str, target: str, mliid: str):
|
||||
cmd = f'fake /a/an {dst} {target} {mliid}'
|
||||
self.send_command(cmd)
|
||||
|
||||
@@ -75,6 +75,9 @@ MLE_CHILD_UPDATE_RESPONSE = 14
|
||||
MLE_ANNOUNCE = 15
|
||||
MLE_DISCOVERY_REQUEST = 16
|
||||
MLE_DISCOVERY_RESPONSE = 17
|
||||
MLE_LINK_METRICS_MANAGEMENT_REQUEST = 18
|
||||
MLE_LINK_METRICS_MANAGEMENT_RESPONSE = 19
|
||||
MLE_LINK_PROBE = 20
|
||||
|
||||
# COAP URIs
|
||||
ADDR_QRY_URI = '/a/aq'
|
||||
@@ -285,6 +288,22 @@ THREAD_VERSION_1_2 = 3
|
||||
# ICMPv6 Types
|
||||
ICMPV6_TYPE_DESTINATION_UNREACHABLE = 1
|
||||
|
||||
# Link Metrics
|
||||
LINK_METRICS_STATUS_SUCCESS = 0
|
||||
LINK_METRICS_STATUS_CANNOT_SUPPORT_NEW_SERIES = 1
|
||||
LINK_METRICS_STATUS_SERIES_ID_ALREADY_REGISTERED = 2
|
||||
LINK_METRICS_STATUS_SERIES_ID_NOT_RECOGNIZED = 3
|
||||
LINK_METRICS_STATUS_NO_MATCHING_FRAMES_RECEIVED = 4
|
||||
LINK_METRICS_STATUS_OTHER_ERROR = 254
|
||||
|
||||
LINK_METRICS_TYPE_AVERAGE_ENUM_COUNT = 0
|
||||
LINK_METRICS_TYPE_AVERAGE_ENUM_EXPONENTIAL = 1
|
||||
|
||||
LINK_METRICS_METRIC_TYPE_ENUM_PDU_COUNT = 0
|
||||
LINK_METRICS_METRIC_TYPE_ENUM_LQI = 1
|
||||
LINK_METRICS_METRIC_TYPE_ENUM_LINK_MARGIN = 2
|
||||
LINK_METRICS_METRIC_TYPE_ENUM_RSSI = 3
|
||||
|
||||
if __name__ == '__main__':
|
||||
from pktverify.addrs import Ipv6Addr
|
||||
|
||||
|
||||
@@ -293,6 +293,13 @@ _LAYER_FIELDS = {
|
||||
'mle.tlv.addr16': _auto,
|
||||
'mle.tlv.channel': _auto,
|
||||
'mle.tlv.addr_reg_iid': _list(_auto),
|
||||
'mle.tlv.link_forward_series': _list(_auto),
|
||||
'mle.tlv.link_sub_tlv': _auto,
|
||||
'mle.tlv.link_status_sub_tlv': _auto,
|
||||
'mle.tlv.query_id': _auto,
|
||||
'mle.tlv.metric_type_id_flags.type': _list(_hex),
|
||||
'mle.tlv.metric_type_id_flags.metric': _list(_hex),
|
||||
'mle.tlv.metric_type_id_flags.l': _list(_hex),
|
||||
|
||||
# IP
|
||||
'ip.version': _auto,
|
||||
|
||||
@@ -0,0 +1,340 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
import unittest
|
||||
|
||||
from config import ADDRESS_TYPE
|
||||
from mle import LinkMetricsSubTlvType, TlvType
|
||||
from pktverify import consts
|
||||
from pktverify.null_field import nullField
|
||||
from pktverify.packet_verifier import PacketVerifier
|
||||
|
||||
import thread_cert
|
||||
|
||||
LEADER = 1
|
||||
SED_1 = 2
|
||||
SSED_1 = 3
|
||||
|
||||
SERIES_ID = 1
|
||||
SERIES_ID_2 = 2
|
||||
POLL_PERIOD = 2000 # 2s
|
||||
|
||||
|
||||
class LowPower_7_2_01_ForwardTrackingSeries(thread_cert.TestCase):
|
||||
TOPOLOGY = {
|
||||
LEADER: {
|
||||
'version': '1.2',
|
||||
'name': 'LEADER',
|
||||
'mode': 'rdn',
|
||||
'panid': 0xface,
|
||||
'allowlist': [SED_1, SSED_1],
|
||||
},
|
||||
SED_1: {
|
||||
'version': '1.2',
|
||||
'name': 'SED_1',
|
||||
'mode': '-',
|
||||
'panid': 0xface,
|
||||
'allowlist': [LEADER],
|
||||
},
|
||||
SSED_1: {
|
||||
'version': '1.2',
|
||||
'name': 'SSED_1',
|
||||
'mode': '-',
|
||||
'panid': 0xface,
|
||||
'allowlist': [LEADER],
|
||||
}
|
||||
}
|
||||
"""All nodes are created with default configurations"""
|
||||
|
||||
def test(self):
|
||||
self.nodes[LEADER].start()
|
||||
self.simulator.go(5)
|
||||
self.assertEqual(self.nodes[LEADER].get_state(), 'leader')
|
||||
|
||||
self.nodes[SED_1].set_pollperiod(POLL_PERIOD)
|
||||
self.nodes[SED_1].start()
|
||||
self.simulator.go(5)
|
||||
self.assertEqual(self.nodes[SED_1].get_state(), 'child')
|
||||
|
||||
self.nodes[SSED_1].set_csl_period(consts.CSL_DEFAULT_PERIOD)
|
||||
self.nodes[SSED_1].start()
|
||||
self.simulator.go(5)
|
||||
self.assertEqual(self.nodes[SSED_1].get_state(), 'child')
|
||||
|
||||
leader_addr = self.nodes[LEADER].get_ip6_address(ADDRESS_TYPE.LINK_LOCAL)
|
||||
|
||||
# Step 3 - Verify connectivity by instructing each device to send an ICMPv6 Echo Request to the DUT
|
||||
self.assertTrue(self.nodes[SED_1].ping(leader_addr, timeout=POLL_PERIOD))
|
||||
self.assertTrue(self.nodes[SSED_1].ping(leader_addr, timeout=2 * consts.CSL_DEFAULT_PERIOD))
|
||||
self.simulator.go(5)
|
||||
|
||||
# Step 4 - SED_1 requests a Forward Tracking Series by sending a Link Metrics Management Request
|
||||
# Forward Series Flags = 0x04:
|
||||
# - Bit 2 = 1, MAC Data Request
|
||||
# - Bits 0,1 & 3-7 = 0
|
||||
# Concatenation of Link Metric Type ID Flags = 0x00:
|
||||
# - Item1: (0)(1)(000)(000) = 0x40
|
||||
# -- E = 0
|
||||
# -- L = 1
|
||||
# -- Type/Average Enum = 0 (count)
|
||||
# -- Metrics Enum = 0 (count)
|
||||
self.nodes[SED_1].link_metrics_mgmt_req_forward_tracking_series(leader_addr, SERIES_ID, 'r', 'p')
|
||||
|
||||
self.simulator.go(5)
|
||||
|
||||
# Step 6 - Configures SED_1 to send MAC Data Request every 2 seconds and wait for 30 seconds
|
||||
self.simulator.go(30)
|
||||
|
||||
# Step 7 - SED_1 sends an MLE Data Request to retrieve aggregated Forward Series Results
|
||||
self.nodes[SED_1].link_metrics_query_forward_tracking_series(leader_addr, SERIES_ID)
|
||||
|
||||
self.simulator.go(5)
|
||||
|
||||
# Step 9 - SED_1 clears the Forward Tracking Series
|
||||
# Forward Series Flags = 0x00:
|
||||
# - Bits 0-7 = 0
|
||||
# Concatenation of Link Metric Type ID Flags = NULL:
|
||||
self.nodes[SED_1].link_metrics_mgmt_req_forward_tracking_series(leader_addr, SERIES_ID, 'X', '')
|
||||
|
||||
self.simulator.go(5)
|
||||
|
||||
# Step 16 - SSED_1 requests a Forward Tracking Series by sending a Link Metrics Management Request
|
||||
# Forward Series Flags = 0x02:
|
||||
# - Bit 1 = 1, (all Link Layer Data Frames)
|
||||
# - Bits 0, 2-7 = 0
|
||||
# Concatenation of Link Metric Type ID Flags = 0x0a:
|
||||
# - Item1: (0)(0)(001)(010) = 0x0a
|
||||
# -- E = 0
|
||||
# -- L = 0
|
||||
# -- Type/Average Enum = 1 (Exponential Moving Average)
|
||||
# -- Metrics Enum = 2 (Link Margin)
|
||||
self.nodes[SSED_1].link_metrics_mgmt_req_forward_tracking_series(leader_addr, SERIES_ID_2, 'd', 'm')
|
||||
|
||||
self.simulator.go(5)
|
||||
|
||||
# Step 18 - SSED_1 sends MAC Data packet every 1 second for 30 seconds
|
||||
# Note: As the api to send MAC Data frame hasn't been implemented, we send MLE Link Probe message here
|
||||
for i in range(30):
|
||||
self.nodes[SSED_1].link_metrics_send_link_probe(leader_addr, SERIES_ID_2, 1)
|
||||
self.simulator.go(1)
|
||||
|
||||
# Step 19 - SSED_1 sends an MLE Data Request to retrieve aggregated Forward Series Results
|
||||
self.nodes[SSED_1].link_metrics_query_forward_tracking_series(leader_addr, SERIES_ID_2)
|
||||
|
||||
self.simulator.go(5)
|
||||
|
||||
# Step 21 - SSED_1 clears the Forward Series Link Metrics
|
||||
# Forward Series Flags = 0x00:
|
||||
# - Bits 0-7 = 0
|
||||
# Concatenation of Link Metric Type ID Flags = NULL
|
||||
self.nodes[SSED_1].link_metrics_mgmt_req_forward_tracking_series(leader_addr, SERIES_ID_2, 'X', '')
|
||||
|
||||
self.simulator.go(5)
|
||||
|
||||
# Step 23 - SSED_1 sends an MLE Data Request to retrieve aggregated Forward Series Results
|
||||
self.nodes[SSED_1].link_metrics_query_forward_tracking_series(leader_addr, SERIES_ID_2)
|
||||
|
||||
self.simulator.go(5)
|
||||
|
||||
def verify(self, pv):
|
||||
pkts = pv.pkts
|
||||
pv.summary.show()
|
||||
LEADER = pv.vars['LEADER']
|
||||
SED_1 = pv.vars['SED_1']
|
||||
SSED_1 = pv.vars['SSED_1']
|
||||
|
||||
# Step 3 - The DUT MUST send ICMPv6 Echo Responses to both SED1 & SSED1
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(SED_1) \
|
||||
.filter_ping_reply() \
|
||||
.must_next()
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(SSED_1) \
|
||||
.filter_ping_reply() \
|
||||
.must_next()
|
||||
|
||||
# Step 4 - SED_1 requests a Forward Series Link Metrics by sending a Link Metrics Management Request
|
||||
# Forward Series Flags = 0x04:
|
||||
# - Bit 2 = 1, MAC Data Request
|
||||
# - Bits 0,1 & 3-7 = 0
|
||||
# Concatenation of Link Metric Type ID Flags = 0x40:
|
||||
# - Item1: (0)(1)(000)(000) = 0x40
|
||||
# -- E = 0
|
||||
# -- L = 1
|
||||
# -- Type/Average Enum = 0 (count)
|
||||
# -- Metrics Enum = 0 (count)
|
||||
pkts.filter_wpan_src64(SED_1) \
|
||||
.filter_wpan_dst64(LEADER) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_REQUEST) \
|
||||
.filter(lambda p: p.mle.tlv.link_sub_tlv == LinkMetricsSubTlvType.FORWARD_PROBING_REGISTRATION) \
|
||||
.filter(lambda p: 4 in p.mle.tlv.link_forward_series) \
|
||||
.filter(lambda p: consts.LINK_METRICS_TYPE_AVERAGE_ENUM_COUNT in p.mle.tlv.metric_type_id_flags.type) \
|
||||
.filter(lambda p: consts.LINK_METRICS_METRIC_TYPE_ENUM_PDU_COUNT in p.mle.tlv.metric_type_id_flags.metric) \
|
||||
.filter(lambda p: 1 in p.mle.tlv.metric_type_id_flags.l) \
|
||||
.must_next()
|
||||
|
||||
# Step 5 - Leader responds with a Link Metrics Management Response
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(SED_1) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_RESPONSE) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_SUCCESS) \
|
||||
.must_next()
|
||||
|
||||
# Step 8 - Leader responds with an MLE Data Response
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(SED_1) \
|
||||
.filter_mle_cmd(consts.MLE_DATA_RESPONSE) \
|
||||
.filter(lambda p: TlvType.LINK_METRICS_REPORT in p.mle.tlv.type) \
|
||||
.filter(lambda p: consts.LINK_METRICS_TYPE_AVERAGE_ENUM_COUNT in p.mle.tlv.metric_type_id_flags.type) \
|
||||
.filter(lambda p: consts.LINK_METRICS_METRIC_TYPE_ENUM_PDU_COUNT in p.mle.tlv.metric_type_id_flags.metric) \
|
||||
.must_next()
|
||||
|
||||
# Step 9 - SED_1 clears the Forward Series Link Metrics
|
||||
# Forward Series Flags = 0x00:
|
||||
# - Bits 0-7 = 0
|
||||
# Concatenation of Link Metric Type ID Flags = NULL:
|
||||
pkts.filter_wpan_src64(SED_1) \
|
||||
.filter_wpan_dst64(LEADER) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_REQUEST) \
|
||||
.filter(lambda p: p.mle.tlv.link_sub_tlv == LinkMetricsSubTlvType.FORWARD_PROBING_REGISTRATION) \
|
||||
.filter(lambda p: 0 in p.mle.tlv.link_forward_series) \
|
||||
.filter(lambda p: p.mle.tlv.metric_type_id_flags.type is nullField) \
|
||||
.filter(lambda p: p.mle.tlv.metric_type_id_flags.metric is nullField) \
|
||||
.must_next()
|
||||
|
||||
# Step 10 - Leader responds with a Link Metrics Management Response
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(SED_1) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_RESPONSE) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_SUCCESS) \
|
||||
.must_next()
|
||||
|
||||
# Step 16 - SSED_1 requests a Forward Series Link Metrics by sending a Link Metrics Management Request
|
||||
# Forward Series Flags = 0x02:
|
||||
# - Bit 1 = 1, (all Link Layer Data Frames)
|
||||
# - Bits 0, 2-7 = 0
|
||||
# Concatenation of Link Metric Type ID Flags = 0x0a:
|
||||
# - Item1: (0)(0)(001)(010) = 0x0a
|
||||
# -- E = 0
|
||||
# -- L = 0
|
||||
# -- Type/Average Enum = 1 (Exponential Moving Average)
|
||||
# -- Metrics Enum = 2 (Link Margin)
|
||||
pkts.filter_wpan_src64(SSED_1) \
|
||||
.filter_wpan_dst64(LEADER) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_REQUEST) \
|
||||
.filter(lambda p: p.mle.tlv.link_sub_tlv == LinkMetricsSubTlvType.FORWARD_PROBING_REGISTRATION) \
|
||||
.filter(lambda p: 2 in p.mle.tlv.link_forward_series) \
|
||||
.filter(lambda p: consts.LINK_METRICS_TYPE_AVERAGE_ENUM_EXPONENTIAL in p.mle.tlv.metric_type_id_flags.type) \
|
||||
.filter(lambda p: consts.LINK_METRICS_METRIC_TYPE_ENUM_LINK_MARGIN in p.mle.tlv.metric_type_id_flags.metric) \
|
||||
.must_next()
|
||||
|
||||
# Step 17 - Leader responds with a Link Metrics Management Response
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(SSED_1) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_RESPONSE) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_SUCCESS) \
|
||||
.must_next()
|
||||
|
||||
# Step 19 - SSED_1 sends an MLE Data Request to retrieve aggregated Forward Series results
|
||||
# - TLV Request TLV(Link Metrics Report TLV specified
|
||||
# - Link Metrics Query TLV
|
||||
# -- Link Metrics Query ID Sub-TLV
|
||||
# --- Query ID: (ID set in step 16)
|
||||
# - Verify that the Link Metrics Query Options Sub-TLV is NOT present
|
||||
pkts.filter_wpan_src64(SSED_1) \
|
||||
.filter_wpan_dst64(LEADER) \
|
||||
.filter_mle_cmd(consts.MLE_DATA_REQUEST) \
|
||||
.filter(lambda p: TlvType.LINK_METRICS_QUERY in p.mle.tlv.type) \
|
||||
.filter(lambda p: p.mle.tlv.query_id == SERIES_ID_2) \
|
||||
.must_next()
|
||||
|
||||
# Step 20 - Leader MUST reply to SSED_1 with an MLE Data Response with the following:
|
||||
# - Link Metrics Report TLV
|
||||
# -- Link Metrics Report Sub-TLV
|
||||
# --- Metric Type ID Flags
|
||||
# ---- Type / Average Enum = 1 (Exponential Moving Average)
|
||||
# ---- Metric Enum = 2 (Link Margin)
|
||||
# --- Value (1 bytes)
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(SSED_1) \
|
||||
.filter_mle_cmd(consts.MLE_DATA_RESPONSE) \
|
||||
.filter_mle_has_tlv(TlvType.LINK_METRICS_REPORT) \
|
||||
.filter(lambda p: p.mle.tlv.link_sub_tlv == LinkMetricsSubTlvType.LINK_METRICS_REPORT) \
|
||||
.filter(lambda p: consts.LINK_METRICS_TYPE_AVERAGE_ENUM_EXPONENTIAL in p.mle.tlv.metric_type_id_flags.type) \
|
||||
.filter(lambda p: consts.LINK_METRICS_METRIC_TYPE_ENUM_LINK_MARGIN in p.mle.tlv.metric_type_id_flags.metric) \
|
||||
.must_next()
|
||||
|
||||
# Step 21 - SSED_1 clears the Forward Series Link Metrics
|
||||
# Forward Series Flags = 0x00:
|
||||
# - Bits 0-7 = 0
|
||||
# Concatenation of Link Metric Type ID Flags = NULL
|
||||
pkts.filter_wpan_src64(SSED_1) \
|
||||
.filter_wpan_dst64(LEADER) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_REQUEST) \
|
||||
.filter(lambda p: p.mle.tlv.link_sub_tlv == LinkMetricsSubTlvType.FORWARD_PROBING_REGISTRATION) \
|
||||
.filter(lambda p: 0 in p.mle.tlv.link_forward_series) \
|
||||
.filter(lambda p: p.mle.tlv.metric_type_id_flags.type is nullField) \
|
||||
.filter(lambda p: p.mle.tlv.metric_type_id_flags.metric is nullField) \
|
||||
.must_next()
|
||||
|
||||
# Step 22 - Leader responds with a Link Metrics Management Response
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(SSED_1) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_RESPONSE) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_SUCCESS) \
|
||||
.must_next()
|
||||
|
||||
# Step 23 - SSED_1 sends an MLE Data Request to retrieve aggregated Forward Series results
|
||||
# - TLV Request TLV(Link Metrics Report TLV specified
|
||||
# - Link Metrics Query TLV
|
||||
# -- Link Metrics Query ID Sub-TLV
|
||||
# --- Query ID: (ID set in step 16)
|
||||
# This is a negative step
|
||||
pkts.filter_wpan_src64(SSED_1) \
|
||||
.filter_wpan_dst64(LEADER) \
|
||||
.filter_mle_cmd(consts.MLE_DATA_REQUEST) \
|
||||
.filter(lambda p: TlvType.LINK_METRICS_QUERY in p.mle.tlv.type) \
|
||||
.filter(lambda p: p.mle.tlv.query_id == SERIES_ID_2) \
|
||||
.must_next()
|
||||
|
||||
# Step 24 - Leader MUST reply to SSED_1 with an MLE Data Response with the following:
|
||||
# - Link Metrics Report TLV
|
||||
# -- Link Metrics Status Sub-TLV
|
||||
# --- Status = 3 (Series ID not recognized)
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(SSED_1) \
|
||||
.filter_mle_cmd(consts.MLE_DATA_RESPONSE) \
|
||||
.filter_mle_has_tlv(TlvType.LINK_METRICS_REPORT) \
|
||||
.filter(lambda p: p.mle.tlv.link_sub_tlv == LinkMetricsSubTlvType.LINK_METRICS_STATUS) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_SERIES_ID_NOT_RECOGNIZED) \
|
||||
.must_next()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,194 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
import unittest
|
||||
|
||||
from config import ADDRESS_TYPE
|
||||
from mle import LinkMetricsSubTlvType, TlvType
|
||||
from pktverify import consts
|
||||
from pktverify.null_field import nullField
|
||||
from pktverify.packet_verifier import PacketVerifier
|
||||
|
||||
import thread_cert
|
||||
|
||||
LEADER = 1
|
||||
CHILD = 2
|
||||
|
||||
SERIES_ID_1 = 1
|
||||
SERIES_ID_2 = 2
|
||||
|
||||
|
||||
class LowPower_test_ForwardTrackingSeries(thread_cert.TestCase):
|
||||
TOPOLOGY = {
|
||||
LEADER: {
|
||||
'version': '1.2',
|
||||
'name': 'LEADER',
|
||||
'mode': 'rdn',
|
||||
'panid': 0xface,
|
||||
'allowlist': [CHILD],
|
||||
},
|
||||
CHILD: {
|
||||
'version': '1.2',
|
||||
'name': 'CHILD',
|
||||
'mode': 'rn',
|
||||
'panid': 0xface,
|
||||
'allowlist': [LEADER],
|
||||
}
|
||||
}
|
||||
"""All nodes are created with default configurations"""
|
||||
|
||||
def test(self):
|
||||
self.nodes[LEADER].start()
|
||||
self.simulator.go(5)
|
||||
self.assertEqual(self.nodes[LEADER].get_state(), 'leader')
|
||||
|
||||
self.nodes[CHILD].start()
|
||||
self.simulator.go(5)
|
||||
self.assertEqual(self.nodes[CHILD].get_state(), 'child')
|
||||
|
||||
leader_addr = self.nodes[LEADER].get_ip6_address(ADDRESS_TYPE.LINK_LOCAL)
|
||||
|
||||
# 1. Child configures a Forward Tracking Series successfully.
|
||||
# The Series tracks the count of MAC Data Request.
|
||||
# Child should get a response with status 0 (SUCCESS).
|
||||
self.nodes[CHILD].link_metrics_mgmt_req_forward_tracking_series(leader_addr, SERIES_ID_1, 'r', 'p')
|
||||
self.simulator.go(1)
|
||||
|
||||
# 2. Child configures the same Forward Tracking Series again.
|
||||
# Child should get a response with status 2 (SERIES_ID_ALREADY_REGISTERED).
|
||||
self.nodes[CHILD].link_metrics_mgmt_req_forward_tracking_series(leader_addr, SERIES_ID_1, 'r', 'p')
|
||||
self.simulator.go(1)
|
||||
|
||||
# 3. Child queries a Series that doesn't exist (using a wrong Series ID).
|
||||
# Child should get a report with status 3 (SERIES_ID_NOT_RECOGNIZED).
|
||||
self.nodes[CHILD].link_metrics_query_forward_tracking_series(leader_addr, SERIES_ID_2)
|
||||
self.simulator.go(1)
|
||||
|
||||
# 4. Child queries a Series that don't have matched frames yet.
|
||||
# Child should get a report with status 4 (NO_MATCHING_FRAMES_RECEIVED).
|
||||
self.nodes[CHILD].link_metrics_query_forward_tracking_series(leader_addr, SERIES_ID_1)
|
||||
self.simulator.go(1)
|
||||
|
||||
# 5. Child clears a Forward Tracking Series that doesn't exist.
|
||||
# Child should get a response with status 3 (SERIES_ID_NOT_RECOGNIZED).
|
||||
self.nodes[CHILD].link_metrics_mgmt_req_forward_tracking_series(leader_addr, SERIES_ID_2, 'X', '')
|
||||
self.simulator.go(1)
|
||||
|
||||
# 6. Child clears a Forward Tracking Series successfully.
|
||||
# Child should get a response with status 0 (SUCCESS).
|
||||
self.nodes[CHILD].link_metrics_mgmt_req_forward_tracking_series(leader_addr, SERIES_ID_1, 'X', '')
|
||||
self.simulator.go(1)
|
||||
|
||||
# 7. Child configures a new Forward Tracking Series successfully.
|
||||
# The Series tracks the count of all MAC Data frames.
|
||||
# Child should get a response with status 0 (SUCCESS).
|
||||
self.nodes[CHILD].link_metrics_mgmt_req_forward_tracking_series(leader_addr, SERIES_ID_2, 'd', 'pqmr')
|
||||
self.simulator.go(1)
|
||||
|
||||
# 8. Child sends an MLE Link Probe message to the Subject for the newly configured Series.
|
||||
self.nodes[CHILD].link_metrics_send_link_probe(leader_addr, SERIES_ID_2, 1)
|
||||
|
||||
# 9. Child queries the newly configured Series successfully.
|
||||
# Child should get a report with valid values.
|
||||
self.nodes[CHILD].link_metrics_query_forward_tracking_series(leader_addr, SERIES_ID_2)
|
||||
self.simulator.go(1)
|
||||
|
||||
def verify(self, pv):
|
||||
pkts = pv.pkts
|
||||
pv.summary.show()
|
||||
LEADER = pv.vars['LEADER']
|
||||
CHILD = pv.vars['CHILD']
|
||||
|
||||
# 1. Child should get a response with status 0 (SUCCESS).
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(CHILD) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_RESPONSE) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_SUCCESS) \
|
||||
.must_next()
|
||||
|
||||
# 2. Child should get a response with status 2 (SERIES_ID_ALREADY_REGISTERED).
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(CHILD) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_RESPONSE) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_SERIES_ID_ALREADY_REGISTERED) \
|
||||
.must_next()
|
||||
|
||||
# 3. Child should get a report with status 3 (SERIES_ID_NOT_RECOGNIZED).
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(CHILD) \
|
||||
.filter_mle_cmd(consts.MLE_DATA_RESPONSE) \
|
||||
.filter_mle_has_tlv(TlvType.LINK_METRICS_REPORT) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_SERIES_ID_NOT_RECOGNIZED) \
|
||||
.must_next()
|
||||
|
||||
# 4. Child should get a report with status 4 (NO_MATCHING_FRAMES_RECEIVED).
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(CHILD) \
|
||||
.filter_mle_cmd(consts.MLE_DATA_RESPONSE) \
|
||||
.filter_mle_has_tlv(TlvType.LINK_METRICS_REPORT) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_NO_MATCHING_FRAMES_RECEIVED) \
|
||||
.must_next()
|
||||
|
||||
# 5. Child should get a response with status 3 (SERIES_ID_NOT_RECOGNIZED).
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(CHILD) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_RESPONSE) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_SERIES_ID_NOT_RECOGNIZED) \
|
||||
.must_next()
|
||||
|
||||
# 6. Child should get a response with status 0 (SUCCESS).
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(CHILD) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_RESPONSE) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_SUCCESS) \
|
||||
.must_next()
|
||||
|
||||
# 7. Child should get a response with status 0 (SUCCESS).
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(CHILD) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_METRICS_MANAGEMENT_RESPONSE) \
|
||||
.filter(lambda p: p.mle.tlv.link_status_sub_tlv == consts.LINK_METRICS_STATUS_SUCCESS) \
|
||||
.must_next()
|
||||
|
||||
# 8. Child sends an MLE Link Probe message to the Subject for the newly configured Series.
|
||||
pkts.filter_wpan_src64(CHILD) \
|
||||
.filter_wpan_dst64(LEADER) \
|
||||
.filter_mle_cmd(consts.MLE_LINK_PROBE) \
|
||||
.must_next()
|
||||
|
||||
# 9. Child should get a report with valid values.
|
||||
pkts.filter_wpan_src64(LEADER) \
|
||||
.filter_wpan_dst64(CHILD) \
|
||||
.filter_mle_cmd(consts.MLE_DATA_RESPONSE) \
|
||||
.filter(lambda p: TlvType.LINK_METRICS_REPORT in p.mle.tlv.type) \
|
||||
.must_next()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user