From 8198e8794f6d2f56c4c72a5f73735b591b594732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hubert=20Mi=C5=9B?= Date: Tue, 10 Jan 2017 19:14:27 +0100 Subject: [PATCH] Add 'bufferinfo' commane to spinel-cli.py (#1125) --- tools/spinel-cli/spinel-cli.py | 38 +++++++++++++++++++++++++++ tools/spinel-cli/spinel/codec.py | 45 ++++++++++++++++++++++++++++++++ tools/spinel-cli/spinel/const.py | 22 ++++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/tools/spinel-cli/spinel-cli.py b/tools/spinel-cli/spinel-cli.py index d423df5bc..a9dd8e925 100755 --- a/tools/spinel-cli/spinel-cli.py +++ b/tools/spinel-cli/spinel-cli.py @@ -151,6 +151,7 @@ class SpinelCliCmd(Cmd, SpinelCodec): # OpenThread CLI commands 'help', + 'bufferinfo', 'channel', 'child', 'childmax', @@ -459,6 +460,43 @@ class SpinelCliCmd(Cmd, SpinelCodec): print() print(heap_stats.heap().byrcs) + def do_bufferinfo(self, line): + """ + \033[1mbufferinfo\033[0m + + Get the mesh forwarder buffer info. + \033[2m + > bufferinfo + total: 128 + free: 128 + 6lo send: 0 0 + 6lo reas: 0 0 + ip6: 0 0 + mpl: 0 0 + mle: 0 0 + arp: 0 0 + coap: 0 0 + Done + \033[0m + """ + + result = self.prop_get_value(SPINEL.PROP_MSG_BUFFER_COUNTERS) + if result != None: + result = result[0] + + print("total: %d" % result[0]) + print("free: %d" % result[1]) + print("6lo send: %d %d" % result[2:4]) + print("6lo reas: %d %d" % result[4:6]) + print("ip6: %d %d" % result[6:8]) + print("mpl: %d %d" % result[8:10]) + print("mle: %d %d" % result[10:12]) + print("arp: %d %d" % result[12:14]) + print("coap: %d %d" % result[14:16]) + print("Done") + else: + print("Error") + def do_channel(self, line): """ \033[1mchannel\033[0m diff --git a/tools/spinel-cli/spinel/codec.py b/tools/spinel-cli/spinel/codec.py index 0716bb126..a3993c10a 100644 --- a/tools/spinel-cli/spinel/codec.py +++ b/tools/spinel-cli/spinel/codec.py @@ -168,6 +168,47 @@ class SpinelCodec(object): print(traceback.format_exc()) return None + @classmethod + def parse_fields(cls, payload, spinel_format): + map_lengths = { + 'b': 1, + 'c': 1, + 'C': 1, + 's': 2, + 'S': 2, + 'l': 4, + 'L': 4, + '6': 16, + 'E': 8, + 'e': 6, + } + result = [] + + idx = 0 + while idx < len(spinel_format): + format = spinel_format[idx] + + if format == 'T': + if spinel_format[idx+1] != '(': + raise ValueError('Invalid structure format') + # TODO: count parentheses. There is a problem with nested structs. + struct_end = idx + spinel_format[idx:].index(')') + + struct_format = spinel_format[idx+2:struct_end] + struct_len = sum([map_lengths[c] for c in struct_format]) + + result.append(cls.parse_fields(payload, struct_format)) + payload = payload[struct_len:] + + idx = struct_end + 1 + else: + result.append(cls.parse_field(payload, spinel_format)) + payload = payload[map_lengths[spinel_format[idx]]:] + + idx += 1 + + return tuple(result) + @classmethod def encode_i(cls, data): """ Encode EXI integer format. """ @@ -553,6 +594,8 @@ class SpinelPropertyHandler(SpinelCodec): def PIB_MAC_SECURITY_ENABLED(self, _wpan_api, payload): pass + def MSG_BUFFER_COUNTERS(self, _wpan_api, payload): return self.parse_fields(payload, "T(SSSSSSSSSSSSSSSS)") + #========================================= @@ -717,6 +760,8 @@ SPINEL_PROP_DISPATCH = { SPINEL.PROP_PIB_15_4_PHY_CHANNELS_SUPPORTED: WPAN_PROP_HANDLER.PIB_PHY_CHANNELS_SUPPORTED, SPINEL.PROP_PIB_15_4_MAC_PROMISCUOUS_MODE: WPAN_PROP_HANDLER.PIB_MAC_PROMISCUOUS_MODE, SPINEL.PROP_PIB_15_4_MAC_SECURITY_ENABLED: WPAN_PROP_HANDLER.PIB_MAC_SECURITY_ENABLED, + + SPINEL.PROP_MSG_BUFFER_COUNTERS: WPAN_PROP_HANDLER.MSG_BUFFER_COUNTERS } diff --git a/tools/spinel-cli/spinel/const.py b/tools/spinel-cli/spinel/const.py index 00aea278d..4d5683574 100644 --- a/tools/spinel-cli/spinel/const.py +++ b/tools/spinel-cli/spinel/const.py @@ -314,6 +314,28 @@ class SPINEL(object): # Format: `L` (Read-only) */ PROP_CNTR_RX_ERR_OTHER = PROP_CNTR__BEGIN + 113 + # The message buffer counter info + # Format: `T(SSSSSSSSSSSSSSSS)` (Read-only) + # `T(` + # `S`, (TotalBuffers) The number of buffers in the pool. + # `S`, (FreeBuffers) The number of free message buffers. + # `S`, (6loSendMessages) The number of messages in the 6lo send queue. + # `S`, (6loSendBuffers) The number of buffers in the 6lo send queue. + # `S`, (6loReassemblyMessages) The number of messages in the 6LoWPAN reassembly queue. + # `S`, (6loReassemblyBuffers) The number of buffers in the 6LoWPAN reassembly queue. + # `S`, (Ip6Messages) The number of messages in the IPv6 send queue. + # `S`, (Ip6Buffers) The number of buffers in the IPv6 send queue. + # `S`, (MplMessages) The number of messages in the MPL send queue. + # `S`, (MplBuffers) The number of buffers in the MPL send queue. + # `S`, (MleMessages) The number of messages in the MLE send queue. + # `S`, (MleBuffers) The number of buffers in the MLE send queue. + # `S`, (ArpMessages) The number of messages in the ARP send queue. + # `S`, (ArpBuffers) The number of buffers in the ARP send queue. + # `S`, (CoapClientMessages) The number of messages in the CoAP client send queue. + # `S`, (CoapClientBuffers) The number of buffers in the CoAP client send queue. + # `)` + PROP_MSG_BUFFER_COUNTERS = PROP_CNTR__BEGIN + 400 + #========================================= MAC_FILTER_MDOE_NORMAL = 0