def testEncodePayload(self): pyld_data = cbor2.dumps(['some', 'data']) bdl = Bundle(primary=PrimaryBlock(), blocks=[ CanonicalBlock( block_num=1, btsd=pyld_data, ), ]) self.assertEqual(self._encode(bdl), [ [ 7, 0, 0, DTN_NONE, DTN_NONE, DTN_NONE, [0, 0], 0, ], [ None, 1, 0, 0, pyld_data, ], ])
def testEncodeDefault(self): blk = CanonicalBlock() self.assertEqual(self._encode(blk), [ None, None, 0, 0, None, ])
def testEncode(self): blk = CanonicalBlock() / BundleAgeBlock(age=10) self.assertEqual(self._encode(blk), [ 7, None, 0, 0, cbor2.dumps(10), ])
def _dummy_ctr(self): ''' Generate a dummy bundle container. ''' ctr = BundleContainer() ctr.bundle.primary = PrimaryBlock(destination="dtn://other/svc", ) ctr.add_block(CanonicalBlock( type_code=1, btsd=b'hi', )) self._bp._apply_primary(ctr) return ctr
def testEncodeNoData(self): blk = CanonicalBlock( type_code=3, block_num=8, ) self.assertEqual(self._encode(blk), [ 3, 8, 0, 0, None, ])
def testEncode(self): blk = CanonicalBlock() / HopCountBlock( limit=10, count=5, ) item = [ 10, None, 0, 0, cbor2.dumps([10, 5]), ] self.assertEqual(self._encode(blk), item)
def testEncode(self): blk = CanonicalBlock() / PreviousNodeBlock(node='dtn://node/serv') item = [ 6, None, 0, 0, cbor2.dumps([ EidField.TypeCode.dtn, '//node/serv', ]), ] self.assertEqual(self._encode(blk), item)
def testEncodeBlock(self): pkt = CanonicalBlock(block_num=3, ) / BlockIntegrityBlock( targets=[1, 2], context_id=3, context_flags=0, source='dtn://nodeA/', results=[ TargetResultList(results=[ TypeValuePair(type_code=1, value='hi'), ]), TargetResultList(results=[ TypeValuePair(type_code=2, value=False), ]), ]) data = b'850b030000581b' + b'82010203008201682f2f6e6f6465412f82818201626869818202f4' self.assertEqual(hexlify(bytes(pkt)), data)
def testEncodeRawData(self): blk = CanonicalBlock(type_code=1, block_num=8, btsd=b'hi') self.assertEqual(self._encode(blk), [1, 8, 0, 0, b'hi'])