def printRibEntries(encodedMessage): """ This is called when all the segments are received to decode the encodedMessage as repeated TLV RibEntry messages and display the values. :param Blob encodedMessage: The repeated TLV-encoded RibEntry. """ ribEntryMessage = rib_entry_pb2.RibEntryMessage() ProtobufTlv.decode(ribEntryMessage, encodedMessage) dump("RIB:"); for ribEntry in ribEntryMessage.rib_entry: line = "" line += ProtobufTlv.toName(ribEntry.name.component).toUri() # Show the routes. for route in ribEntry.routes: line += (" route={faceId=" + str(route.face_id) + " (origin=" + str(route.origin) + " cost=" + str(route.cost)) if (route.flags & 1) != 0: line += " ChildInherit" if (route.flags & 2) != 0: line += " Capture" if route.HasField("expiration_period"): line += " expirationPeriod=" + str(route.expiration_period) line += ")}" dump(line)
def processRegisterResponse(encodedControlResponse): """ This is called when the register route command responds to decode the encodedControlResponse as a TLV ControlParametersResponse message containing one ControlParameters. On success, print the ControlParameters values which should be the same as requested. :param Blob encodedControlResponse: The TLV-encoded ControlParametersResponse. """ decodedControlResponse = \ control_parameters_pb2.ControlParametersTypes.ControlParametersResponseMessage() ProtobufTlv.decode(decodedControlResponse, encodedControlResponse) controlResponse = decodedControlResponse.control_response lowestErrorCode = 400 if controlResponse.status_code >= lowestErrorCode: dump("Face create command got error, code " + str(controlResponse.status_code) + ": " + controlResponse.status_text) return if len(controlResponse.control_parameters) != 1: dump( "Face create command response does not have one ControlParameters") return # Success. Print the ControlParameters response. controlParameters = controlResponse.control_parameters[0] dump("Successful in name registration: ControlParameters(Name: " + ProtobufTlv.toName(controlParameters.name.component).toUri() + ", FaceId: " + str(controlParameters.face_id) + ", Origin: " + str(controlParameters.origin) + ", Cost: " + str(controlParameters.cost) + ", Flags: " + str(controlParameters.flags) + ")")
def main(): # Construct a sample FibEntry message using the structure in fib_entry_pb2 # which was produced by protoc. message = fib_entry_pb2.FibEntryMessage() message.fib_entry.name.component.append(b"ndn") message.fib_entry.name.component.append(b"ucla") nextHopRecord = message.fib_entry.next_hop_records.add() nextHopRecord.face_id = 16 nextHopRecord.cost = 1 # Encode the Protobuf message object as TLV. encoding = ProtobufTlv.encode(message) decodedMessage = fib_entry_pb2.FibEntryMessage() ProtobufTlv.decode(decodedMessage, encoding) dump("Re-decoded FibEntry:") # This should print the same values that we put in message above. value = "" value += ProtobufTlv.toName( decodedMessage.fib_entry.name.component).toUri() value += " nexthops = {" for next_hop_record in decodedMessage.fib_entry.next_hop_records: value += ("faceid=" + repr(next_hop_record.face_id) + " (cost=" + repr(next_hop_record.cost) + ")") value += " }" dump(value)
def processRegisterResponse(encodedControlResponse): """ This is called when the register route command responds to decode the encodedControlResponse as a TLV ControlParametersResponse message containing one ControlParameters. On success, print the ControlParameters values which should be the same as requested. :param Blob encodedControlResponse: The TLV-encoded ControlParametersResponse. """ decodedControlResponse = \ control_parameters_pb2.ControlParametersTypes.ControlParametersResponseMessage() ProtobufTlv.decode(decodedControlResponse, encodedControlResponse) controlResponse = decodedControlResponse.control_response lowestErrorCode = 400 if controlResponse.status_code >= lowestErrorCode: dump( "Face create command got error, code " + str(controlResponse.status_code) + ": " + controlResponse.status_text) return if len(controlResponse.control_parameters) != 1: dump( "Face create command response does not have one ControlParameters") return # Success. Print the ControlParameters response. controlParameters = controlResponse.control_parameters[0] dump( "Successful in name registration: ControlParameters(Name: " + ProtobufTlv.toName(controlParameters.name.component).toUri() + ", FaceId: " + str(controlParameters.face_id) + ", Origin: " + str(controlParameters.origin) + ", Cost: " + str(controlParameters.cost) + ", Flags: " + str(controlParameters.flags) + ")")
def main(): # Construct a sample FibEntry message using the structure in fib_entry_pb2 # which was produced by protoc. message = fib_entry_pb2.FibEntryMessage() message.fib_entry.name.component.append(b"ndn") message.fib_entry.name.component.append(b"ucla") nextHopRecord = message.fib_entry.next_hop_records.add() nextHopRecord.face_id = 16 nextHopRecord.cost = 1 # Encode the Protobuf message object as TLV. encoding = ProtobufTlv.encode(message) decodedMessage = fib_entry_pb2.FibEntryMessage() ProtobufTlv.decode(decodedMessage, encoding) dump("Re-decoded FibEntry:") # This should print the same values that we put in message above. value = "" value += ProtobufTlv.toName(decodedMessage.fib_entry.name.component).toUri() value += " nexthops = {" for next_hop_record in decodedMessage.fib_entry.next_hop_records: value += ("faceid=" + repr(next_hop_record.face_id) + " (cost=" + repr(next_hop_record.cost) + ")") value += " }" dump(value)
def printFibEntries(encodedMessage): """ This is called when all the segments are received to decode the encodedMessage as repeated TLV FibEntry messages and display the values. :param Blob encodedMessage: The repeated TLV-encoded FibEntry. """ fibEntryMessage = fib_entry_pb2.FibEntryMessage() ProtobufTlv.decode(fibEntryMessage, encodedMessage) dump("FIB:") for fibEntry in fibEntryMessage.fib_entry: line = "" line += ProtobufTlv.toName(fibEntry.name.component).toUri() # Show the routes. for nexthop in fibEntry.next_hop_records: line += (" NextHopRecord={faceId=" + str(nexthop.face_id) + " cost=" + str(nexthop.cost)) line += ")}" dump(line)