Commit 4bd2e095 authored by Boris Pilka's avatar Boris Pilka

Merge branch '39_pep8_compliance' into 'master'

#39 Make code base pep8 compliant

See merge request !12

Former-commit-id: c6065752
parents 0573fdeb 1f1373ea
......@@ -4,11 +4,14 @@ import threading
import time
from cbor2 import decoder
from ipnd.hexdump import hexdump
from ipnd import common
from ipnd.tcpcl import *
from ipnd.sdnv import sdnv_decode
from ipnd.tcpcl import ContactMessage, logging
logging.basicConfig(level=logging.DEBUG)
class Client(object):
"""Internal representation of a BP client as viewed by the server
......@@ -51,10 +54,12 @@ class Client(object):
self.buffer += msg
logging.debug("Received msg from {} of length {} (new buffer length: {} message:\n{}):"
.format(self.address, len(msg), len(self.buffer), hexdump(msg)))
.format(self.address, len(msg), len(self.buffer), hexdump(msg)))
try:
msg_stripped = self.decode_tcpcl_data_segment(msg)
# TODO: unused variable: msg_stripped
# msg_stripped = self.decode_tcpcl_data_segment(msg)
self.decode_tcpcl_data_segment(msg)
except Exception as e:
logging.debug("Not a bundle {}".format(e))
......@@ -105,7 +110,7 @@ class Client(object):
stripped_header = data[1:]
payload_length, bytes_decoded = sdnv_decode(buffer=stripped_header)
logging.debug("payload payload_length {} decoded bytes {} send for decoding \n{}"
.format(payload_length, bytes_decoded, hexdump(stripped_header[bytes_decoded:])))
.format(payload_length, bytes_decoded, hexdump(stripped_header[bytes_decoded:])))
return self.decode_bundle(stripped_header[bytes_decoded:])
......
......@@ -71,37 +71,37 @@ __all__ = [
class BundleProcFlag(IntFlag):
NONE = 0x0000
IS_FRAGMENT = 0x0001
ADMINISTRATIVE_RECORD = 0x0002
MUST_NOT_BE_FRAGMENTED = 0x0004
ACKNOWLEDGEMENT_REQUESTED = 0x0020
REPORT_STATUS_TIME = 0x0040
CONTAINS_MANIFEST = 0x0080
REPORT_RECEPTION = 0x0100
REPORT_FORWARDING = 0x0400
REPORT_DELIVERY = 0x0800
REPORT_DELETION = 0x1000
NONE = 0x0000
IS_FRAGMENT = 0x0001
ADMINISTRATIVE_RECORD = 0x0002
MUST_NOT_BE_FRAGMENTED = 0x0004
ACKNOWLEDGEMENT_REQUESTED = 0x0020
REPORT_STATUS_TIME = 0x0040
CONTAINS_MANIFEST = 0x0080
REPORT_RECEPTION = 0x0100
REPORT_FORWARDING = 0x0400
REPORT_DELIVERY = 0x0800
REPORT_DELETION = 0x1000
class CRCType(IntEnum):
NONE = 0 # indicates "no CRC is present."
NONE = 0 # indicates "no CRC is present."
CRC16 = 1 # indicates "a CRC-16 (a.k.a., CRC-16-ANSI) is present."
CRC32 = 2 # indicates "a standard IEEE 802.3 CRC-32 is present."
class BlockType(IntEnum):
PAYLOAD = 1
PREVIOUS_NODE = 7
BUNDLE_AGE = 8
HOP_COUNT = 9
PAYLOAD = 1
PREVIOUS_NODE = 7
BUNDLE_AGE = 8
HOP_COUNT = 9
class BlockProcFlag(IntFlag):
NONE = 0x00
MUST_BE_REPLICATED = 0x01
DISCARD_IF_UNPROC = 0x02
REPORT_IF_UNPROC = 0x04
NONE = 0x00
MUST_BE_REPLICATED = 0x01
DISCARD_IF_UNPROC = 0x02
REPORT_IF_UNPROC = 0x04
DELETE_BUNDLE_IF_UNPROC = 0x08
......@@ -111,22 +111,22 @@ class RecordType(IntEnum):
class ReasonCode(IntEnum):
"""Bundle status report reason codes"""
NO_INFO = 0
LIFETIME_EXPIRDE = 1
NO_INFO = 0
LIFETIME_EXPIRDE = 1
FORWARDED_UNIDIRECTIONAL = 2
TRANSMISSION_CANCELED = 3
DEPLETED_STORAGE = 4
DEST_EID_UNINTELLIGIBLE = 5
NO_KNOWN_ROUTE = 6
NO_TIMELY_CONTACT = 7
BLOCK_UNINTELLIGIBLE = 8
TRANSMISSION_CANCELED = 3
DEPLETED_STORAGE = 4
DEST_EID_UNINTELLIGIBLE = 5
NO_KNOWN_ROUTE = 6
NO_TIMELY_CONTACT = 7
BLOCK_UNINTELLIGIBLE = 8
class StatusCode(IntEnum):
RECEIVED_BUNDLE = 0x01
RECEIVED_BUNDLE = 0x01
FORWARDED_BUNDLE = 0x04
DELIVERED_BUNDLE = 0x08
DELETED_BUNDLE = 0x10
DELETED_BUNDLE = 0x10
class EID(tuple):
......@@ -186,6 +186,7 @@ class EID(tuple):
#
ZERO = timedelta(0)
class UTC(tzinfo):
"""UTC timezone info class that can be used by :class:`datetime.datetime`
objects."""
......@@ -199,6 +200,7 @@ class UTC(tzinfo):
def dst(self, dt):
return ZERO
utc = UTC()
dtn_start = datetime(2000, 1, 1, 0, 0, tzinfo=utc)
......@@ -214,7 +216,7 @@ class CreationTimestamp(tuple):
@property
def time(self):
return dtn_start + timedelta(seconds=self[0])
return dtn_start + timedelta(seconds=self[0])
@property
def sequence_number(self):
......@@ -231,19 +233,20 @@ def print_hex(binary):
in_hex.append("\n")
logging.debug("".join(in_hex))
class PrimaryBlock(object):
"""The primary bundle block contains the basic information needed to
forward bundles to their destinations.
"""
def __init__(self, bundle_proc_flags=BundleProcFlag.NONE,
crc_type=CRCType.CRC16,
destination=None,
source=None,
report_to=None,
creation_time=None,
fragment_offset=None,
lifetime=24 * 60 * 60):
crc_type=CRCType.CRC16,
destination=None,
source=None,
report_to=None,
creation_time=None,
fragment_offset=None,
lifetime=24 * 60 * 60):
self.version = 7
self.bundle_proc_flags = bundle_proc_flags
self.crc_type = crc_type
......@@ -263,7 +266,6 @@ class PrimaryBlock(object):
def has_flag(self, required):
return self.bundle_proc_flags & required == required
def serialize(self):
primary_block = [
self.version,
......@@ -309,7 +311,6 @@ class PrimaryBlock(object):
crc = crc16_x25(binary)
primary_block.append(struct.pack('!H', crc))
return cbor.dumps(primary_block)
......@@ -317,9 +318,9 @@ class CanonicalBlock(object):
"""Every block other than the primary block"""
def __init__(self, block_type, data,
block_number=None,
block_proc_flags=BlockProcFlag.NONE,
crc_type=CRCType.CRC32):
block_number=None,
block_proc_flags=BlockProcFlag.NONE,
crc_type=CRCType.CRC32):
self.block_type = block_type
self.block_proc_flags = block_proc_flags
self.block_number = block_number
......@@ -409,10 +410,10 @@ class BundleStatusReport(AdministrativeRecord):
def __init__(self, infos, reason, bundle, time=None):
status_info = [
[infos & StatusCode.RECEIVED_BUNDLE != 0],
[infos & StatusCode.RECEIVED_BUNDLE != 0],
[infos & StatusCode.FORWARDED_BUNDLE != 0],
[infos & StatusCode.DELIVERED_BUNDLE != 0],
[infos & StatusCode.DELETED_BUNDLE != 0],
[infos & StatusCode.DELETED_BUNDLE != 0],
]
if bundle.primary_block.has_flag(BundleProcFlag.REPORT_STATUS_TIME):
......@@ -467,7 +468,7 @@ class Bundle(object):
def __init__(self, primary_block, payload_block=None, blocks=None):
if payload_block is None:
payload_block = primary_block[-1]
blocks = primary_block[1:-1]
blocks = primary_block[1:-1]
primary_block = primary_block[0]
self.primary_block = primary_block
......@@ -518,7 +519,6 @@ class Bundle(object):
else:
self.blocks.append(new_block)
def serialize(self):
# Header for indefinite array
head = struct.pack('B', CBOR_ARRAY | 31)
......
from datetime import timedelta
from . import *
from . import Bundle, BundleAgeBlock, BundleProcFlag, BundleStatusReport, CreationTimestamp, HopCountBlock, PayloadBlock,\
PreviousNodeBlock, PrimaryBlock, ReasonCode, StatusCode, dtn_start, print_hex
primary_block = PrimaryBlock(
bundle_proc_flags=BundleProcFlag.MUST_NOT_BE_FRAGMENTED
| BundleProcFlag.CONTAINS_MANIFEST
| BundleProcFlag.REPORT_DELIVERY
| BundleProcFlag.REPORT_STATUS_TIME,
| BundleProcFlag.CONTAINS_MANIFEST
| BundleProcFlag.REPORT_DELIVERY
| BundleProcFlag.REPORT_STATUS_TIME,
destination="dtn:GS2",
source="dtn:none",
report_to="dtn:none",
......@@ -16,8 +17,8 @@ payload = PayloadBlock(b"Hello world!")
# Extension blocks
previous_node = PreviousNodeBlock("dtn:GS4")
hop_count = HopCountBlock(30, 0)
bundle_age = BundleAgeBlock(0)
hop_count = HopCountBlock(30, 0)
bundle_age = BundleAgeBlock(0)
bundle = Bundle([
primary_block,
......
......@@ -203,7 +203,6 @@ class CRC(object):
# Final XBOR
return crc ^ self.final_xor_value
def calculate_crc_table(self):
table = make_table(self.width)
......@@ -243,54 +242,54 @@ class CRC(object):
# Known CRC algorihtms
crc8 = CRC(8, 0x07, 0x00, 0x00, False, False)
crc8_sae_j1850 = CRC(8, 0x1d, 0xff, 0xff, False, False)
crc8 = CRC(8, 0x07, 0x00, 0x00, False, False)
crc8_sae_j1850 = CRC(8, 0x1d, 0xff, 0xff, False, False)
crc8_sae_j1850_zero = CRC(8, 0x1d, 0x00, 0x00, False, False)
crc8_8h2f = CRC(8, 0x2f, 0xff, 0xff, False, False)
crc8_cdma2000 = CRC(8, 0x9b, 0xff, 0x00, False, False)
crc8_darc = CRC(8, 0x39, 0x00, 0x00, True, True)
crc8_dvb_s2 = CRC(8, 0xd5, 0x00, 0x00, False, False)
crc8_ebu = CRC(8, 0x1d, 0xff, 0x00, True, True)
crc8_icode = CRC(8, 0x1d, 0xfd, 0x00, False, False)
crc8_itu = CRC(8, 0x07, 0x00, 0x55, False, False)
crc8_maxim = CRC(8, 0x31, 0x00, 0x00, True, True)
crc8_rohc = CRC(8, 0x07, 0xff, 0x00, True, True)
crc8_wcdma = CRC(8, 0x9b, 0x00, 0x00, True, True)
crc16_ccit_zero = CRC(16, 0x1021, 0x0000, 0x0000, False, False)
crc16_arc = CRC(16, 0x8005, 0x0000, 0x0000, True, True)
crc16_aug_ccitt = CRC(16, 0x1021, 0x1d0f, 0x0000, False, False)
crc16_buypass = CRC(16, 0x8005, 0x0000, 0x0000, False, False)
crc16_ccitt_false = CRC(16, 0x1021, 0xffff, 0x0000, False, False)
crc16_cdma2000 = CRC(16, 0xc867, 0xffff, 0x0000, False, False)
crc16_dds_110 = CRC(16, 0x8005, 0x800d, 0x0000, False, False)
crc16_dect_r = CRC(16, 0x0589, 0x0000, 0x0001, False, False)
crc16_dect_x = CRC(16, 0x0589, 0x0000, 0x0000, False, False)
crc16_dnp = CRC(16, 0x3d65, 0x0000, 0xffff, True, True)
crc16_en_13757 = CRC(16, 0x3d65, 0x0000, 0xffff, False, False)
crc16_genibus = CRC(16, 0x1021, 0xffff, 0xffff, False, False)
crc16_maxim = CRC(16, 0x8005, 0x0000, 0xffff, True, True)
crc16_mcrf4xx = CRC(16, 0x1021, 0xffff, 0x0000, True, True)
crc16_riello = CRC(16, 0x1021, 0xb2aa, 0x0000, True, True)
crc16_t10_dif = CRC(16, 0x8bb7, 0x0000, 0x0000, False, False)
crc16_teledisk = CRC(16, 0xa097, 0x0000, 0x0000, False, False)
crc16_tms37157 = CRC(16, 0x1021, 0x89ec, 0x0000, True, True)
crc16_usb = CRC(16, 0x8005, 0xffff, 0xffff, True, True)
crc16_a = CRC(16, 0x1021, 0xc6c6, 0x0000, True, True)
crc16_kermit = CRC(16, 0x1021, 0x0000, 0x0000, True, True)
crc16_modbus = CRC(16, 0x8005, 0xffff, 0x0000, True, True)
crc16_x25 = CRC(16, 0x1021, 0xffff, 0xffff, True, True)
crc16_xmodem = CRC(16, 0x1021, 0x0000, 0x0000, False, False)
crc32 = CRC(32, 0x04c11db7, 0xffffffff, 0xffffffff, True, True)
crc32_bzip2 = CRC(32, 0x04c11db7, 0xffffffff, 0xffffffff, False, False)
crc32_c = CRC(32, 0x1edc6f41, 0xffffffff, 0xffffffff, True, True)
crc32_d = CRC(32, 0xa833982b, 0xffffffff, 0xffffffff, True, True)
crc32_mpeg2 = CRC(32, 0x04c11db7, 0xffffffff, 0x00000000, False, False)
crc32_posix = CRC(32, 0x04c11db7, 0x00000000, 0xffffffff, False, False)
crc32_q = CRC(32, 0x814141ab, 0x00000000, 0x00000000, False, False)
crc32_jamcrc = CRC(32, 0x04c11db7, 0xffffffff, 0x00000000, True, True)
crc32_xfer = CRC(32, 0x000000af, 0x00000000, 0x00000000, False, False)
crc8_8h2f = CRC(8, 0x2f, 0xff, 0xff, False, False)
crc8_cdma2000 = CRC(8, 0x9b, 0xff, 0x00, False, False)
crc8_darc = CRC(8, 0x39, 0x00, 0x00, True, True)
crc8_dvb_s2 = CRC(8, 0xd5, 0x00, 0x00, False, False)
crc8_ebu = CRC(8, 0x1d, 0xff, 0x00, True, True)
crc8_icode = CRC(8, 0x1d, 0xfd, 0x00, False, False)
crc8_itu = CRC(8, 0x07, 0x00, 0x55, False, False)
crc8_maxim = CRC(8, 0x31, 0x00, 0x00, True, True)
crc8_rohc = CRC(8, 0x07, 0xff, 0x00, True, True)
crc8_wcdma = CRC(8, 0x9b, 0x00, 0x00, True, True)
crc16_ccit_zero = CRC(16, 0x1021, 0x0000, 0x0000, False, False)
crc16_arc = CRC(16, 0x8005, 0x0000, 0x0000, True, True)
crc16_aug_ccitt = CRC(16, 0x1021, 0x1d0f, 0x0000, False, False)
crc16_buypass = CRC(16, 0x8005, 0x0000, 0x0000, False, False)
crc16_ccitt_false = CRC(16, 0x1021, 0xffff, 0x0000, False, False)
crc16_cdma2000 = CRC(16, 0xc867, 0xffff, 0x0000, False, False)
crc16_dds_110 = CRC(16, 0x8005, 0x800d, 0x0000, False, False)
crc16_dect_r = CRC(16, 0x0589, 0x0000, 0x0001, False, False)
crc16_dect_x = CRC(16, 0x0589, 0x0000, 0x0000, False, False)
crc16_dnp = CRC(16, 0x3d65, 0x0000, 0xffff, True, True)
crc16_en_13757 = CRC(16, 0x3d65, 0x0000, 0xffff, False, False)
crc16_genibus = CRC(16, 0x1021, 0xffff, 0xffff, False, False)
crc16_maxim = CRC(16, 0x8005, 0x0000, 0xffff, True, True)
crc16_mcrf4xx = CRC(16, 0x1021, 0xffff, 0x0000, True, True)
crc16_riello = CRC(16, 0x1021, 0xb2aa, 0x0000, True, True)
crc16_t10_dif = CRC(16, 0x8bb7, 0x0000, 0x0000, False, False)
crc16_teledisk = CRC(16, 0xa097, 0x0000, 0x0000, False, False)
crc16_tms37157 = CRC(16, 0x1021, 0x89ec, 0x0000, True, True)
crc16_usb = CRC(16, 0x8005, 0xffff, 0xffff, True, True)
crc16_a = CRC(16, 0x1021, 0xc6c6, 0x0000, True, True)
crc16_kermit = CRC(16, 0x1021, 0x0000, 0x0000, True, True)
crc16_modbus = CRC(16, 0x8005, 0xffff, 0x0000, True, True)
crc16_x25 = CRC(16, 0x1021, 0xffff, 0xffff, True, True)
crc16_xmodem = CRC(16, 0x1021, 0x0000, 0x0000, False, False)
crc32 = CRC(32, 0x04c11db7, 0xffffffff, 0xffffffff, True, True)
crc32_bzip2 = CRC(32, 0x04c11db7, 0xffffffff, 0xffffffff, False, False)
crc32_c = CRC(32, 0x1edc6f41, 0xffffffff, 0xffffffff, True, True)
crc32_d = CRC(32, 0xa833982b, 0xffffffff, 0xffffffff, True, True)
crc32_mpeg2 = CRC(32, 0x04c11db7, 0xffffffff, 0x00000000, False, False)
crc32_posix = CRC(32, 0x04c11db7, 0x00000000, 0xffffffff, False, False)
crc32_q = CRC(32, 0x814141ab, 0x00000000, 0x00000000, False, False)
crc32_jamcrc = CRC(32, 0x04c11db7, 0xffffffff, 0x00000000, True, True)
crc32_xfer = CRC(32, 0x000000af, 0x00000000, 0x00000000, False, False)
# ----------
......@@ -298,10 +297,12 @@ crc32_xfer = CRC(32, 0x000000af, 0x00000000, 0x00000000, False, False)
# ----------
def test_crc16_cc():
assert crc16_ccit_zero(b'Hello world!') == 0x39db
assert crc16_ccit_zero(b'Hello world!') == 0x39db
def test_crc16_x25():
assert crc16_x25(b'Hello world!') == 0x8edb
assert crc16_x25(b'Hello world!') == 0x8edb
def test_crc32():
assert crc32(b'Hello world!') == 0x1b851995
......@@ -59,7 +59,7 @@ class BundlePrimaryBlock:
"""
Lifetime: The lifetime field is an unsigned integer that indicates the time
at which the bundle’s payload will no longer be useful, encoded as a number
of microseconds past the creation time.
of microseconds past the creation time.
"""
self.fragmentOffset = None
"""
......
......@@ -21,6 +21,7 @@ J2000_EPOCH = 946684800
NULL_EID = "dtn:none"
def sdnv_encode(value):
value = int(value)
if value == 0:
......@@ -43,6 +44,7 @@ def sdnv_read(buffer, offset=0):
result |= (cur & 0x7F)
return result, offset
def unix2dtn(unix_timestamp):
return unix_timestamp - J2000_EPOCH
......
......@@ -60,12 +60,12 @@ def hexdump(p):
0000 00 01 43 41 46 45 43 41 46 45 00 01 ..CAFECAFE..
"""
output = []
l = len(p)
length = len(p)
i = 0
while i < l:
while i < length:
output.append('{:04d} '.format(i))
for j in range(16):
if (i + j) < l:
if (i + j) < length:
if __python3__:
byte = p[i + j]
else:
......@@ -81,4 +81,5 @@ def hexdump(p):
i += 16
return ''.join(output)
__all__ = ['hexdump']
......@@ -2,10 +2,11 @@
# from src.ipnd.util import *
# from src.ipnd.sdnv import *
from ipnd.hexdump import hexdump
from ipnd.util import *
from ipnd.sdnv import *
from ipnd.util import IntField, ParsingError
from ipnd.sdnv import sdnv_decode, sdnv_encode
import struct
class ObjDef(object):
"""
Definitions for IPND bit fields.
......@@ -59,7 +60,7 @@ class ObjDef(object):
IPND_SD_TLV_DECODE_FORMAT = 1
IPND_SD_TLV_REPR_FORMAT = 2
ipnd_sd_tlv_primitives = { #length, decode hint, type
ipnd_sd_tlv_primitives = { # length, decode hint, type
IPND_SD_TLV_TAG_BASE_NAME + str(0): [1, '?', 'boolean'],
IPND_SD_TLV_TAG_BASE_NAME + str(1): [IPND_SD_TLV_SDNV_BYTES_MAX, 'sdnv', 'uint64'],
IPND_SD_TLV_TAG_BASE_NAME + str(2): [IPND_SD_TLV_SDNV_BYTES_MAX, 'sdnv', 'sint64'],
......@@ -72,10 +73,11 @@ class ObjDef(object):
IPND_SD_TLV_TAG_BASE_NAME + str(9): [0, 'bytes', 'bytes']
}
class beacon(object):
version = 4
def __init__(self, sequenceNo = 0, eid =""):
def __init__(self, sequenceNo=0, eid=""):
self.eidPresent = 0
self.serviceBlockPresent = 0
self.nbrghBlFilterPresent = 0
......@@ -83,7 +85,7 @@ class beacon(object):
self.sequenceNumber = sequenceNo
self.eidLen = len(eid)
self.eid = eid
self.serviceBlock = 0;
self.serviceBlock = 0
def serialize(self):
header = IntField()
......@@ -107,33 +109,31 @@ class beacon(object):
data = self.decodeHeader(data)
if self.serviceBlockPresent:
self.serviceBlock= serviceBlock()
self.serviceBlock = serviceBlock()
self.serviceBlock.decodeServiceBlock(data)
def decodeHeader(self, data):
headedAsInt, = struct.unpack('!L', data[0:ObjDef.HDR_SIZE])
headerAsIntField = IntField(headedAsInt)
self.version= headerAsIntField.get(ObjDef.HDR_VERSION)
self.version = headerAsIntField.get(ObjDef.HDR_VERSION)
self.eidPresent = headerAsIntField.get(ObjDef.FLAG_EID_PRESENT)
self.serviceBlockPresent = headerAsIntField.get(ObjDef.FLAG_SERVICE_BLOCK_PRESENT)
self.nbrghBlFilterPresent = headerAsIntField.get(ObjDef.FLAG_NBRGH_BL_FILTER_PRESENT)
self.beaconPeriodPresent = headerAsIntField.get(ObjDef.FLAG_BEACON_PERIOD_PRESENT)
self.sequenceNumber = headerAsIntField.get(ObjDef.BEACON_SEQUENCE_NUMBER)
offset = ObjDef.HDR_SIZE
offset = ObjDef.HDR_SIZE
self.eid_len, bytesDecoded = sdnv_decode(buffer=data, offset=offset)
offset +=bytesDecoded
offset += bytesDecoded
fmt = "!{}c".format(self.eid_len)
chars = struct.unpack(fmt, data[offset:(offset + self.eid_len)])
self.eid= (b"".join(chars)).decode("utf-8")
offset+= self.eid_len
self.eid = (b"".join(chars)).decode("utf-8")
offset += self.eid_len
return data[offset:]
def __str__(self):
representation = "Beacon"
representation += "\n\tIPND Version: {}".format(self.version)
......@@ -149,6 +149,7 @@ class beacon(object):
representation += "{}".format(self.serviceBlock)
return representation
class serviceBlock(object):
def __init__(self):
self.services = []
......@@ -163,7 +164,7 @@ class serviceBlock(object):
service = serviceBlockService()
data = service.decodeService(data)
self.services.append(service)
i+=1
i += 1
def __str__(self):
representation = "\n\tServices count: {}".format(self.noServices)
......@@ -177,7 +178,7 @@ class serviceBlock(object):
class serviceBlockService(object):
def __init__(self):
self.serviceTag = 0;
self.serviceTag = 0
self.serviceDecoded = []
pass
......@@ -190,7 +191,7 @@ class serviceBlockService(object):
length -= bytesDecoded
return data
def decodePrimitive (self, data, tag):
def decodePrimitive(self, data, tag):
if tag > len(ObjDef.ipnd_sd_tlv_primitives):
raise ParsingError("Attempt to decode unknown primitive tag '{}'".format(tag))
......@@ -202,7 +203,7 @@ class serviceBlockService(object):
if tagDef[ObjDef.IPND_SD_TLV_DECODE_FORMAT] == 'sdnv':
raise ParsingError("need to implement decode sdnv")
elif tagDef[ObjDef.IPND_SD_TLV_DECODE_FORMAT] == 'string':
raise ParsingError ("need to implement decode string")
raise ParsingError("need to implement decode string")
elif tagDef[ObjDef.IPND_SD_TLV_DECODE_FORMAT] == 'bytes':
length, bytesDecoded = sdnv_decode(buffer=data)
data = data[bytesDecoded:]
......@@ -235,5 +236,5 @@ class serviceBlockService(object):
def __repr__(self):
representation = "Tag {}".format(self.serviceTag)
for item in self.serviceDecoded:
representation+="\n\t\t\t{} \n\t\t\t{}".format(item[0], item[1])
representation += "\n\t\t\t{} \n\t\t\t{}".format(item[0], item[1])
return representation
......@@ -3,7 +3,7 @@
# License: Apache 2.0
def sdnv_decode(buffer: bytearray, offset: int=0, max_length: int=9) -> (int, int):
def sdnv_decode(buffer: bytearray, offset: int = 0, max_length: int = 9) -> (int, int):
"""Decode a SDNV from a buffer
:param buffer: The buffer which contains a SDNV
:param offset: The offset into the buffer, at which the SDNV can be found
......
import logging
from ipnd.hexdump import hexdump
from ipnd.util import *
from ipnd.sdnv import *
from ipnd.util import struct
from ipnd.sdnv import sdnv_encode
logging.basicConfig(level=logging.DEBUG)
class ObjDef(object):
"""
Definitions specific for TCPCL (https://tools.ietf.org/html/rfc7242)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment