From 9934c50671550188b04bb379825a5c4f2e4181c2 Mon Sep 17 00:00:00 2001 From: Xinyu Ma Date: Mon, 16 Nov 2020 02:04:15 -0800 Subject: [PATCH] encoding: fix typo and bugs in NDNLPv2 Ref: #20 --- src/ndn/encoding/ndnlp_v2.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ndn/encoding/ndnlp_v2.py b/src/ndn/encoding/ndnlp_v2.py index fc7cb49..83f75d3 100644 --- a/src/ndn/encoding/ndnlp_v2.py +++ b/src/ndn/encoding/ndnlp_v2.py @@ -18,8 +18,7 @@ from typing import Optional from .tlv_type import BinaryStr, VarBinaryStr from .tlv_var import parse_and_check_tl -from .tlv_model import TlvModel, UintField, BytesField, ModelField, BoolField - +from .tlv_model import TlvModel, UintField, BytesField, ModelField, BoolField, DecodeError __all__ = ['LpTypeNumber', 'NackReason', 'parse_network_nack', 'make_network_nack', 'parse_lp_packet'] @@ -36,8 +35,8 @@ class LpTypeNumber: NACK_REASON = 0x0321 NEXT_HOP_FACE_ID = 0x0330 INCOMING_FACE_ID = 0x0331 - CACHE_POLITY = 0x0334 - CACHE_POLITY_TYPE = 0x0335 + CACHE_POLICY = 0x0334 + CACHE_POLICY_TYPE = 0x0335 CONGESTION_MARK = 0x0340 ACK = 0x0344 TX_SEQUENCE = 0x0348 @@ -57,7 +56,7 @@ class NetworkNack(TlvModel): class CachePolicy(TlvModel): - cache_policy_type = UintField(LpTypeNumber.CACHE_POLITY_TYPE) + cache_policy_type = UintField(LpTypeNumber.CACHE_POLICY_TYPE) class LpPacketValue(TlvModel): @@ -67,7 +66,7 @@ class LpPacketValue(TlvModel): nack = ModelField(LpTypeNumber.NACK, NetworkNack) next_hop_face_id = UintField(LpTypeNumber.NEXT_HOP_FACE_ID) incoming_face_id = UintField(LpTypeNumber.INCOMING_FACE_ID) - cache_policy = ModelField(LpTypeNumber.NACK, NetworkNack) + cache_policy = ModelField(LpTypeNumber.CACHE_POLICY, CachePolicy) congestion_mark = UintField(LpTypeNumber.CONGESTION_MARK) tx_sequence = BytesField(LpTypeNumber.TX_SEQUENCE) ack = BytesField(LpTypeNumber.ACK) @@ -94,6 +93,9 @@ def parse_lp_packet(wire: BinaryStr, with_tl: bool = True) -> (Optional[int], Op markers = {} ret = LpPacketValue.parse(wire, markers, ignore_critical=True) + if ret.frag_index is not None or ret.frag_count is not None: + raise DecodeError('NDNLP fragmentation is not implemented yet.') + if ret.nack is not None: return ret.nack.nack_reason, ret.fragment else: