def _makeInterestPacket(): subpackages = [] npackage = _makeNamePacket() subpackages.append(npackage) cbppackage = _getOptional(_makeCanBePrefix) if cbppackage is not None: subpackages.append(cbppackage) fhpackage = _getOptional(_makeForwardingHint) if fhpackage is not None: subpackages.append(fhpackage) mbfpackage = _getOptional(_makeMustBeFresh) if mbfpackage is not None: subpackages.append(mbfpackage) nopackage = _getOptional(_makeNonce) if nopackage is not None: subpackages.append(nopackage) ilpackage = _getOptional(_makeInterestLifetime) if ilpackage is not None: subpackages.append(ilpackage) hplpackage = _getOptional(_makeHopLimit) if hplpackage is not None: subpackages.append(hplpackage) ppackage = _getOptional(_makeParameters) if ppackage is not None: subpackages.append(ppackage) length = _randomLength(len(subpackages)) ipackage = TLVPackage("Interest", enc.Tlv.Interest, length, subpackages) return ipackage
def _makeCCNxName(): subpackages = [] for x in range(random.randint(0, 8)): p = _makeBasicTLVPackage("Name Segment", 0x0001) subpackages.append(p) length = _randomLength(len(subpackages)) return TLVPackage("Name", 0x0000, length, subpackages)
def _makeLinkContent(): subpackages = [] for x in range(1, 6): cpackage = _makeDelegation() subpackages.append(cpackage) length = _randomLength(len(subpackages)) return TLVPackage("LinkContent", enc.Tlv.ContentType, length, subpackages)
def _makeKeyLocator(): subpackages = [] r = random.randint(0, 1) if r == 0: subpackages.append(_makeNamePacket()) else: subpackages.append(_makeKeyDigest()) return TLVPackage("KeyLocator", enc.Tlv.KeyLocator, _randomLength(1), subpackages)
def _makeDelegation(): subpackages = [] ppackage = _makePreference() subpackages.append(ppackage) npackage = _makeNamePacket() subpackages.append(npackage) length = _randomLength(len(subpackages)) return TLVPackage("Delegation", enc.Tlv.Link_Delegation, length, subpackages)
def _makeSignatureInfo(): subpackages = [] stpackage = _makeSignatureType() subpackages.append(stpackage) klPackage = _getOptional(_makeKeyLocator) if klPackage is not None: subpackages.append(klPackage) length = _randomLength(len(subpackages)) return TLVPackage("SignatureInfo", enc.Tlv.SignatureInfo, length, subpackages)
def _makeCCNxContentObject(): subpackages = [] namep = _makeCCNxName() subpackages.append(namep) x = random.randint(0, 3) if x % 2 is 1: ptp = _makePayloadType() subpackages.append(ptp) if x > 1: extp = _makeExpiriyTime() subpackages.append(extp) length = _randomLength(len(subpackages)) return TLVPackage("ContentOject", 0x0002, length, subpackages)
def _makeCCNxInterest(): subpackages = [] namep = _makeCCNxName() subpackages.append(namep) x = random.randint(0, 3) if x % 2 is 1: kidp = _makeKeyIdRestriciton() subpackages.append(kidp) if x > 1: cohrp = _makeContentObjectHashRestriciton() subpackages.append(cohrp) length = _randomLength(len(subpackages)) return TLVPackage("Interest", 0x0001, length, subpackages)
def _makeMetaInfo(): subpackages = [] ctpackage = _getOptional(_makeContentType) if ctpackage is not None: subpackages.append(ctpackage) fppackage = _getOptional(_makeFreshnessPeriod) if (fppackage is not None): subpackages.append(fppackage) fbidpackage = _getOptional(_makeFinalBlockId) if (fbidpackage is not None): subpackages.append(fbidpackage) length = _randomLength(len(subpackages)) return TLVPackage("MetaInfo", enc.Tlv.MetaInfo, length, subpackages)
def _makeLinkObject(): subpackages = [] npackage = _makeNamePacket() subpackages.append(npackage) mipackage = _makeMetaInfo() subpackages.append(mipackage) lcpackage = _makeLinkContent() subpackages.append(lcpackage) sipackage = _makeSignatureInfo() subpackages.append(sipackage) svpackage = _makeSignatureValue() subpackages.append(svpackage) length = _randomLength(len(subpackages)) linkObject = TLVPackage("LinkObject", enc.Tlv.Data, length, subpackages) return linkObject
def _makeDataPacket(): subpackages = [] npackage = _makeNamePacket() subpackages.append(npackage) mipackage = _getOptional(_makeMetaInfo) if mipackage is not None: subpackages.append(mipackage) cpackage = _getOptional(_makeContent) if cpackage is not None: subpackages.append(cpackage) sipackage = _makeSignatureInfo() subpackages.append(sipackage) svpackage = _makeSignatureValue() subpackages.append(svpackage) length = _randomLength(len(subpackages)) datpackage = TLVPackage("Data", enc.Tlv.Data, length, subpackages) return datpackage
def _makeExpiriyTime(): return TLVPackage("ExpiryTime", 0x0006, 8)
def _makeBasicTLVPackage(name, type, len=-1): if len == -1: len = _randomLength() return TLVPackage(name, type, len)
def _makeForwardingHint(): subpackages = [] for x in range(1, 6): subpackages.append(_makeDelegation()) length = _randomLength(len(subpackages)) return TLVPackage("ForwardingHint", enc.Tlv.ForwardingHint, length, subpackages)
def _makeNamePacket(): subpackages = [] for x in range(random.randint(0, 8)): subpackages.append(_makeNameComponentPacket()) length = _randomLength(len(subpackages)) return TLVPackage("Name", enc.Tlv.Name, length, subpackages)
def _makeFinalBlockId(): ncpackage = _makeNameComponentPacket() return TLVPackage("FinalBlockId", enc.Tlv.FinalBlockId, _randomLength(1), [ncpackage])