def read_p4info_text_format_from_file(fname): p4info = p4info_pb2.P4Info() f = argparse.FileType('r')(fname) text = f.read() # TBD: Better to close file f here? text_format.Merge(text, p4info) return p4info
def setUp(self, grpc_addr, proto_txt_path): #BaseTest.setUp(self) self.device_id = 0 # Setting up PTF dataplane # self.dataplane = ptf.dataplane_instance # self.dataplane.flush() self._swports = [] # for device, port, ifname in config["interfaces"]: # self._swports.append(port) # grpc_addr = testutils.test_param_get("grpcaddr") if grpc_addr is None: grpc_addr = 'localhost:50051' self.channel = grpc.insecure_channel(grpc_addr) self.stub = p4runtime_pb2_grpc.P4RuntimeStub(self.channel) # proto_txt_path = testutils.test_param_get("p4info") print "Importing p4info proto from", proto_txt_path self.p4info = p4info_pb2.P4Info() with open(proto_txt_path, "rb") as fin: google.protobuf.text_format.Merge(fin.read(), self.p4info) self.import_p4info_names() self.import_p4info_ids() # used to store write requests sent to the P4Runtime server, useful for # autocleanup of tests (see definition of autocleanup decorator below) self._reqs = [] self.set_up_stream()
def tr_p4info(platform, p4info_path, p4info_out_path): """ Translate to NP4 compatible p4info """ p4info = p4info_pb2.P4Info() with open(p4info_path, 'r') as p4info_f: text_format.Merge(p4info_f.read(), p4info) # Spin through tables for table in p4info.tables: # Look for "standard_metadata" match fields for mf in table.match_fields: if platform == "np4": if mf.name.startswith("standard_metadata"): mf.name = mf.name.replace("standard", "intrinsic") mf.bitwidth = 8 elif mf.name == "vlan_tag.$valid$": mf.name = "vlan_tag" if platform == "np4": # Spin through actions for action in p4info.actions: # Look for "port_num" param for p in action.params: if p.name == "port_num": p.bitwidth = 8 # Add the packet in controller packet metadata cpm = p4info.controller_packet_metadata.add() cpm.preamble.id = 67146229 cpm.preamble.name = "packet_in" cpm.preamble.alias = "packet_in" metadata = cpm.metadata.add() metadata.id = 1 metadata.name = "ingress_port" metadata.bitwidth = 9 metadata = cpm.metadata.add() metadata.id = 2 metadata.name = "_pad" metadata.bitwidth = 7 # Add the packet out controller packet metadata cpm = p4info.controller_packet_metadata.add() cpm.preamble.id = 67121543 cpm.preamble.name = "packet_out" cpm.preamble.alias = "packet_out" metadata = cpm.metadata.add() metadata.id = 1 metadata.name = "egress_port" metadata.bitwidth = 9 metadata = cpm.metadata.add() metadata.id = 2 metadata.name = "_pad" metadata.bitwidth = 7 # Write out new p4info with open(p4info_out_path, 'w') as f: f.write(text_format.MessageToString(p4info)) print("P4Info successfully translated to {}".format(p4info_out_path))
def __init__(self, grpc_addr, device_id, device, election_id, role_id, config_path, p4info_path, ctx_json): self.grpc_addr = grpc_addr if self.grpc_addr is None: self.grpc_addr = 'localhost:50051' self.device_id = int(device_id) if self.device_id is None: print("Device ID is not set") self.device = device self.config_path = config_path self.p4info_path = p4info_path self.ctx_json_path = ctx_json self.channel = grpc.insecure_channel(self.grpc_addr) self.stub = p4runtime_pb2.P4RuntimeStub(self.channel) print "Importing p4info proto from", p4info_path self.p4info = p4info_pb2.P4Info() with open(p4info_path, "rb") as fin: google.protobuf.text_format.Merge(fin.read(), self.p4info) self.p4info_helper = helper.P4InfoHelper(p4info_path) self.import_p4info_names() # used to store write requests sent to the P4Runtime server, useful for # autocleanup of tests (see definition of autocleanup decorator below) self.reqs = [] self.election_id = election_id self.role_id = role_id self.set_up_stream()
def build_p4info(): """Builds P4 Info""" p4info = p4info_pb2.P4Info() with open(arg.p4info, "r") as f: text_format.Merge(f.read(), p4info) return p4info
def __init__(self, p4_info_filepath): p4info = p4info_pb2.P4Info() # Load the p4info file into a skeleton P4Info object with open(p4_info_filepath) as p4info_f: google.protobuf.text_format.Merge(p4info_f.read(), p4info) self.p4info = p4info self.next_mbr_id = 1 self.next_grp_id = 1
def setUp(self): BaseTest.setUp(self) self._swports = [] for device, port, ifname in config["interfaces"]: self._swports.append(port) grpc_addr = testutils.test_param_get("grpcaddr") if grpc_addr is None: grpc_addr = 'localhost:50051' self.device_id = int(testutils.test_param_get("device_id")) if self.device_id is None: self.fail("Device ID is not set") self.cpu_port = int(testutils.test_param_get("cpu_port")) if self.cpu_port is None: self.fail("CPU port is not set") self.device = testutils.test_param_get("device") if self.device is None: self.fail("Device is not set") pltfm = testutils.test_param_get("pltfm") if pltfm is not None and pltfm == 'hw' and getattr( self, "_skip_on_hw", False): raise SkipTest("Skipping test in HW") proto_txt_path = testutils.test_param_get("p4info") # print "Importing p4info proto from", proto_txt_path self.p4info = p4info_pb2.P4Info() with open(proto_txt_path, "rb") as fin: google.protobuf.text_format.Merge(fin.read(), self.p4info) self.import_p4info_names() # used to store write requests sent to the P4Runtime server, useful for # autocleanup of tests (see definition of autocleanup decorator below) self.reqs = [] self.election_id = 1 if testutils.test_param_get("generate_tv") == 'True': self.generate_tv = True else: self.generate_tv = False if self.generate_tv: self.tv_list = [] self.tv_name = self.__class__.__name__ else: # Setting up PTF dataplane self.dataplane = ptf.dataplane_instance self.dataplane.flush() self.channel = grpc.insecure_channel(grpc_addr) self.stub = p4runtime_pb2_grpc.P4RuntimeStub(self.channel) self.set_up_stream()
def __init__(self): self.p4info = p4info_pb2.P4Info() self.p4runtime_api_version = "1.3.0" self.stored_packet_out = queue.Queue()
def __init__(self): self.p4info = p4info_pb2.P4Info() self.p4runtime_api_version = "1.2.0-dev"
def __init__(self): self.p4info = p4info_pb2.P4Info()
def read_p4info_text_format_from_file(fname): p4info = p4info_pb2.P4Info() f = argparse.FileType('r')(fname) text = f.read() text_format.Merge(text, p4info) return p4info