mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 14:17:47 +00:00
[tests] add test case Cert_9_2_02 (#3589)
1. Add new test case **Cert_9_2_02**. Since the test case contains 2 topologies, added 2 new files: - `Cert_9_2_02A_MGMTCommissionerSet.py`, - `Cert_9_2_02B_MGMTCommissionerSet.py`. 2. Add mesh_cop tlvs parsing. The corresponding file is `mesh_cop.py`. The mesh_cop tlvs are used in many cases. For example, `CommissionerSessionId` is used in both the parsing of **Commissioning Data**(in mle) and the parsing of **CoAP**. Collected all mesh_cop tlvs refered in Thread into this file with some unused tlvs unimplemented. 3. Reuse `SubTlvsFactory` in `network_data.py`. `SubTlvsFactory` are used to choose the corresponding factory of specific tlv and do the parsing of it. The `NetworkLayerTlvsFactory` in `network_layer.py` had exactly the same function with it (almost the same code). Moved the `SubTlvsFactory` into a new file `tlvs_parsing.py` and change the usage in `network_data.py` and `network_layer.py`. This helps us remove some redundant code. 4. Some format issues. Remove some trailing spaces.
This commit is contained in:
@@ -33,6 +33,7 @@ import struct
|
||||
|
||||
from binascii import hexlify
|
||||
from enum import IntEnum
|
||||
from tlvs_parsing import SubTlvsFactory
|
||||
|
||||
import common
|
||||
|
||||
@@ -47,13 +48,6 @@ class TlvType(IntEnum):
|
||||
SERVER = 6
|
||||
|
||||
|
||||
class MeshcopTlvType(IntEnum):
|
||||
STEERING_DATA = 8
|
||||
BORDER_AGENT_LOCATOR = 9
|
||||
COMMISSIONER_SESSION_ID = 11
|
||||
COMMISSIONER_UDP_PORT = 15
|
||||
|
||||
|
||||
class NetworkData(object):
|
||||
|
||||
def __init__(self, stable):
|
||||
@@ -64,36 +58,6 @@ class NetworkData(object):
|
||||
return self._stable
|
||||
|
||||
|
||||
class SubTlvsFactory(object):
|
||||
|
||||
def __init__(self, sub_tlvs_factories):
|
||||
self._sub_tlvs_factories = sub_tlvs_factories
|
||||
|
||||
def _get_factory(self, _type):
|
||||
try:
|
||||
return self._sub_tlvs_factories[_type]
|
||||
except KeyError:
|
||||
raise RuntimeError("Could not find factory. Factory type = {}.".format(_type))
|
||||
|
||||
def parse(self, data, message_info):
|
||||
sub_tlvs = []
|
||||
|
||||
while data.tell() < len(data.getvalue()):
|
||||
_type = ord(data.read(1))
|
||||
|
||||
length = ord(data.read(1))
|
||||
value = data.read(length)
|
||||
|
||||
factory = self._get_factory(_type)
|
||||
|
||||
message_info.length = length
|
||||
tlv = factory.parse(io.BytesIO(value), message_info)
|
||||
|
||||
sub_tlvs.append(tlv)
|
||||
|
||||
return sub_tlvs
|
||||
|
||||
|
||||
class NetworkDataSubTlvsFactory(SubTlvsFactory):
|
||||
|
||||
def parse(self, data, message_info):
|
||||
@@ -434,107 +398,6 @@ class CommissioningDataFactory(object):
|
||||
|
||||
return CommissioningData(sub_tlvs, message_info.stable)
|
||||
|
||||
|
||||
class SteeringData(object):
|
||||
|
||||
def __init__(self, bloom_filter):
|
||||
self._bloom_filter = bloom_filter
|
||||
|
||||
@property
|
||||
def bloom_filter(self):
|
||||
return self._bloom_filter
|
||||
|
||||
def __eq__(self, other):
|
||||
common.expect_the_same_class(self, other)
|
||||
|
||||
return self._bloom_filter == other._bloom_filter
|
||||
|
||||
def __repr__(self):
|
||||
return "SteeringData(bloom_filter={})".format(hexlify(self._bloom_filter))
|
||||
|
||||
|
||||
class SteeringDataFactory:
|
||||
|
||||
def parse(self, data, message_info):
|
||||
bloom_filter = data.read(message_info.length)
|
||||
return SteeringData(bloom_filter)
|
||||
|
||||
|
||||
class BorderAgentLocator(object):
|
||||
|
||||
def __init__(self, address):
|
||||
self._udp_port = address
|
||||
|
||||
@property
|
||||
def udp_port(self):
|
||||
return self._udp_port
|
||||
|
||||
def __eq__(self, other):
|
||||
common.expect_the_same_class(self, other)
|
||||
|
||||
return self._udp_port == other._udp_port
|
||||
|
||||
def __repr__(self):
|
||||
return "BorderAgentLocator(rloc16={})".format(hex(self._udp_port))
|
||||
|
||||
|
||||
class BorderAgentLocatorFactory:
|
||||
|
||||
def parse(self, data, message_info):
|
||||
border_agent_locator = struct.unpack(">H", data.read(2))[0]
|
||||
return BorderAgentLocator(border_agent_locator)
|
||||
|
||||
|
||||
class CommissionerSessionId(object):
|
||||
|
||||
def __init__(self, commissioner_session_id):
|
||||
self._udp_port = commissioner_session_id
|
||||
|
||||
@property
|
||||
def udp_port(self):
|
||||
return self._udp_port
|
||||
|
||||
def __eq__(self, other):
|
||||
common.expect_the_same_class(self, other)
|
||||
|
||||
return self._udp_port == other._udp_port
|
||||
|
||||
def __repr__(self):
|
||||
return "CommissionerSessionId(id={})".format(hex(self._udp_port))
|
||||
|
||||
|
||||
class CommissionerSessionIdFactory:
|
||||
|
||||
def parse(self, data, message_info):
|
||||
session_id = struct.unpack(">H", data.read(2))[0]
|
||||
return CommissionerSessionId(session_id)
|
||||
|
||||
|
||||
class CommissionerUdpPort(object):
|
||||
|
||||
def __init__(self, udp_port):
|
||||
self._udp_port = udp_port
|
||||
|
||||
@property
|
||||
def udp_port(self):
|
||||
return self._udp_port
|
||||
|
||||
def __eq__(self, other):
|
||||
common.expect_the_same_class(self, other)
|
||||
|
||||
return self._udp_port == other._udp_port
|
||||
|
||||
def __repr__(self):
|
||||
return "CommissionerUdpPort(udp_port={})".format(self._udp_port)
|
||||
|
||||
|
||||
class CommissionerUdpPortFactory:
|
||||
|
||||
def parse(self, data, message_info):
|
||||
udp_port = struct.unpack(">H", data.read(2))[0]
|
||||
return CommissionerUdpPort(udp_port)
|
||||
|
||||
|
||||
class Service(NetworkData):
|
||||
|
||||
def __init__(self, t, _id, enterprise_number, service_data_length, service_data, sub_tlvs, stable):
|
||||
|
||||
Reference in New Issue
Block a user