def setup_int(self): self.send_request_add_entry_to_action( "int_egress.int_prep", None, "int_egress.int_transit", [("switch_id", stringify(1, 4))]) req = p4runtime_pb2.WriteRequest() for i in xrange(16): base = "int_set_header_0003_i" mf = self.Exact("hdr.int_header.instruction_mask_0003", stringify(i, 1)) action = "int_metadata_insert." + base + str(i) self.push_update_add_entry_to_action( req, "int_metadata_insert.int_inst_0003", [mf], action, []) self.write_request(req) req = p4runtime_pb2.WriteRequest() for i in xrange(16): base = "int_set_header_0407_i" mf = self.Exact("hdr.int_header.instruction_mask_0407", stringify(i, 1)) action = "int_metadata_insert." + base + str(i) self.push_update_add_entry_to_action( req, "int_metadata_insert.int_inst_0407", [mf], action, []) self.write_request(req)
def write_multicast_entry(self, hosts): mc_group_id = 1 mc_entries = self.sw_info.get('multicast_entries') if mc_entries: multicast_entry = self.p4info_helper.build_multicast_group_entry( mc_group_id, mc_entries) logger.info('Build Multicast Entry on device [%s]: [%s]', multicast_entry) request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = p4runtime_pb2.Update.INSERT update.entity.packet_replication_engine_entry.CopyFrom( multicast_entry) try: logger.debug( 'Request for writing a multicast entry to ' 'device [%s] - [%s]', self.device_id, request) self.client_stub.Write(request) except Exception as e: logging.error('Error requesting [%s] multicast - [%s]', request, e) raise e
def WriteTableEntry(self, update_type, table, match_key, action_data): global dev_id request = p4runtime_pb2.WriteRequest() request.device_id = dev_id request.election_id.low = 1 update = request.updates.add() update.type = update_type update.entity.table_entry.table_id = table update.entity.table_entry.is_default_action = 1 update.entity.table_entry.action.action.action_id = 1 matches = update.entity.table_entry.match.add() matches.field_id = 1 matches.exact.value = bytes(match_key) act = update.entity.table_entry.action.action.params.add() act.param_id = 2 act.value = bytes(action_data) ServerConfig.print_debug("Sending table write request to server:") ServerConfig.print_debug(request) try: self.stub.Write(request) except grpc.RpcError as error: ServerConfig.print_debug("An error ocurred during a 'write' execution!") ServerConfig.print_debug("{}: {}".format(error.code().name, error.details())) return
def setUp(self): super(SpgwSimpleTest, self).setUp() self.add_forwarding_unicast_v4_entry(self.S1U_ENB_IPV4, 32, 1) self.add_forwarding_unicast_v4_entry(self.END_POINT_IPV4, 32, 2) self.add_next_hop_L3(1, self.port2, self.SWITCH_MAC_2, self.DMAC_2) self.add_next_hop_L3(2, self.port1, self.SWITCH_MAC_1, self.DMAC_1) req = p4runtime_pb2.WriteRequest() req.device_id = self.device_id s1u_enb_ipv4_ = ipv4_to_binary(self.S1U_ENB_IPV4) s1u_sgw_ipv4_ = ipv4_to_binary(self.S1U_SGW_IPV4) end_point_ipv4_ = ipv4_to_binary(self.END_POINT_IPV4) self.push_update_add_entry_to_action( req, "spgw_ingress.ue_filter_table", [self.Lpm("ipv4.dst_addr", end_point_ipv4_, 32)], "NoAction", []) self.push_update_add_entry_to_action( req, "spgw_ingress.s1u_filter_table", [self.Exact("spgw_meta.s1u_sgw_addr", s1u_sgw_ipv4_)], "NoAction", []) self.push_update_add_entry_to_action( req, "spgw_ingress.dl_sess_lookup", [self.Exact("ipv4.dst_addr", end_point_ipv4_)], "spgw_ingress.set_dl_sess_info", [("teid", stringify(1, 4)), ("s1u_enb_addr", s1u_enb_ipv4_), ("s1u_sgw_addr", s1u_sgw_ipv4_)]) self.write_request(req)
def get_new_write_request(self): req = p4runtime_pb2.WriteRequest() req.device_id = self.device_id election_id = req.election_id election_id.high = 0 election_id.low = self.election_id return req
def write_digest_entry(self, digest_entry): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = p4runtime_pb2.Update.INSERT update.entity.digest_entry.CopyFrom(digest_entry) self.client_stub.Write(request)
def write_update(self, update): req = p4runtime_pb2.WriteRequest() req.device_id = self.device_id election_id = req.election_id election_id.high = self.election_id[0] election_id.low = self.election_id[1] req.updates.extend([update]) return self.stub.Write(req)
def SetMeters(self, meter_id=None, index=None, meter_entry=None): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = p4runtime_pb2.Update.INSERT # print(dir(update.entity)) update.entity.meter_entry.CopyFrom(meter_entry) self.client_stub.Write(request)
def make_write_request(self, update_type, entity_type, expected_txt): req = p4runtime_pb2.WriteRequest() req.device_id = self.device_id req.election_id.high = self.election_id[0] req.election_id.low = self.election_id[1] update = req.updates.add() update.type = update_type google.protobuf.text_format.Merge(expected_txt, getattr(update.entity, entity_type.name)) return req
def WriteTableEntry(self, table_entry, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id update = request.updates.add() update.type = p4runtime_pb2.Update.INSERT update.entity.table_entry.CopyFrom(table_entry) if dry_run: print "P4 Runtime Write:", request else: self.client_stub.Write(request)
def DeletePREEntry(self, pre_entry, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = p4runtime_pb2.Update.DELETE update.entity.packet_replication_engine_entry.CopyFrom(pre_entry) if dry_run: print "P4Runtime Write:", request else: self.client_stub.Write(request)
def send_request_add_entry_to_action(self, t_name, mk, a_name, params, priority=None): req = p4runtime_pb2.WriteRequest() req.device_id = self.device_id self.push_update_add_entry_to_action(req, t_name, mk, a_name, params, priority) return req, self.write_request(req, store=(mk is not None))
def WriteRegisterEntry(self, reg_entry, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = p4runtime_pb2.Update.MODIFY update.entity.register_entry.CopyFrom(reg_entry) print "P4Runtime Write:", request self.client_stub.Write(request)
def WriteDigestEntry(self, digest_entry, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = p4runtime_pb2.Update.INSERT update.entity.digest_entry.CopyFrom(digest_entry) if dry_run: print "P4Runtime Write:", request else: self.client_stub.Write(request)
def ModifyTableEntry(self, table_entry, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = p4runtime_pb2.Update.MODIFY update.entity.table_entry.CopyFrom(table_entry) if dry_run: print "P4Runtime Write:", request else: self.client_stub.Write(request)
def WriteMulticastGroupEntry(self, mc_entry, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = p4runtime_pb2.Update.INSERT update.entity.packet_replication_engine_entry.CopyFrom(mc_entry) if dry_run: print "P4Runtime Write:", request else: self.client_stub.Write(request)
def WriteGroup(self, group, update_type, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = update_type pre_entry = update.entity.packet_replication_engine_entry pre_entry.multicast_group_entry.CopyFrom(group) if dry_run: print "P4Runtime Write:", request else: self.client_stub.Write(request)
def DeleteTableEntry(self, table_entry, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() # Assign DELETE Type for it update.type = p4runtime_pb2.Update.DELETE update.entity.table_entry.CopyFrom(table_entry) if dry_run: print "P4Runtime Delete: ", request else: self.client_stub.Write(request)
def undo_write_requests(self, reqs): updates = [] for req in reversed(reqs): for update in reversed(req.updates): if update.type == p4runtime_pb2.Update.INSERT: updates.append(update) new_req = p4runtime_pb2.WriteRequest() new_req.device_id = self.device_id for update in updates: update.type = p4runtime_pb2.Update.DELETE new_req.updates.add().CopyFrom(update) rep = self._write(new_req)
def DeleteTableEntry(self, table_entry, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() # can't remove default entries: if not table_entry.is_default_action: update.type = p4runtime_pb2.Update.DELETE update.entity.table_entry.CopyFrom(table_entry) if dry_run: print "P4Runtime Write:", request else: self.client_stub.Write(request)
def add_mcast_group(self, group_id, ports): req = p4runtime_pb2.WriteRequest() req.device_id = self.device_id update = req.updates.add() update.type = p4runtime_pb2.Update.INSERT pre_entry = update.entity.packet_replication_engine_entry mg_entry = pre_entry.multicast_group_entry mg_entry.multicast_group_id = group_id for port in ports: replica = mg_entry.replicas.add() replica.egress_port = port replica.instance = 0 return req, self.write_request(req)
def WriteTableEntry(self, table_entry, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() if table_entry.is_default_action: update.type = p4runtime_pb2.Update.MODIFY else: update.type = p4runtime_pb2.Update.INSERT update.entity.table_entry.CopyFrom(table_entry) if dry_run: print("P4Runtime Write:", request) else: self.client_stub.Write(request)
def WriteTableEntry(self, table_entry, update_type=None, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() if update_type is None: update.type = p4runtime_pb2.Update.INSERT else: update.type = update_type update.entity.table_entry.CopyFrom(table_entry) if dry_run: print "P4Runtime Write:", request else: self.sw_conn.client_stub.Write(request)
def SendDigestEntry(self, digest_entry, dry_run=False): # send a digest entry INSERT message to init the streaming process request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = p4runtime_pb2.Update.INSERT update.entity.digest_entry.CopyFrom(digest_entry) if dry_run: print "P4Runtime Enable digest %s on switch %s" % ( digest_entry.digest_id, self.device_id) else: self.client_stub.Write(request)
def DeleteTableEntry(self, table_entry, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id #nur master duerfen writes vornehmen request.election_id.low = 1 request.election_id.high = 0 update = request.updates.add() update.type = p4runtime_pb2.Update.DELETE update.entity.table_entry.CopyFrom(table_entry) if dry_run: print "P4 Runtime Write:", request else: self.client_stub.Write(request)
def WriteTableEntry(self, table_entry, dry_run=False): if not self.active: return request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 request.election_id.high = 0 update = request.updates.add() update.type = p4runtime_pb2.Update.INSERT update.entity.table_entry.CopyFrom(table_entry) if dry_run: print("P4Runtime Write:", request) else: self.client_stub.Write(request)
def WriteMeter(self, meter_id, index, cir, pir, dry_run=False): request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = p4runtime_pb2.Update.MODIFY meter_entry = update.entity.meter_entry meter_entry.meter_id = meter_id meter_entry.index.index = index meter_entry.config.cir = cir * 10 meter_entry.config.pir = pir * 10 meter_entry.config.cburst = 1500 meter_entry.config.pburst = 1500 if dry_run: print "P4Runtime Write:", request else: self.client_stub.Write(request)
def __write_to_table(self, table_entry, update_type): logger.info('Writing table entry on device [%s] - [%s]', self.device_id, table_entry) request = p4runtime_pb2.WriteRequest() request.device_id = self.device_id request.election_id.low = 1 update = request.updates.add() update.type = update_type update.entity.table_entry.CopyFrom(table_entry) try: logger.debug( 'Request for writing table entry to device [%s] - [%s]', self.device_id, request) self.client_stub.Write(request) except Exception as e: logging.error('Error writing table entry to device [%s] - [%s]', self.device_id, e) raise e
def StreamDigestMessages(self, digest_id, dry_run=False): #send a digest entry INSERT message to init the streaming process activation_request = p4runtime_pb2.WriteRequest() activation_request.device_id = self.device_id activation_request.election_id.low = 1 activation_request.election_id.high = 0 update = activation_request.updates.add() update.type = p4runtime_pb2.Update.INSERT update.entity.digest_entry.digest_id = digest_id update.entity.digest_entry.config.max_timeout_ns = 1 update.entity.digest_entry.config.max_list_size = 1 update.entity.digest_entry.config.ack_timeout_ns = 10000 if dry_run: print "P4Runtime Enable digest %s on switch %s" % (digest_id, self.device_id) else: self.client_stub.Write(activation_request)
def deleteSLBRules(p4info_helper, slb_sw, table_entries): request = p4runtime_pb2.WriteRequest() request.device_id = slb_sw.device_id request.election_id.low = 1 for table_entry in table_entries: # do not delete default if "default_action" in table_entry: continue table_entry = p4info_helper.buildTableEntry( table_name=table_entry["table"], match_fields=table_entry["match"], action_name=table_entry["action_name"], action_params=table_entry["action_params"] ) update = request.updates.add() update.type = p4runtime_pb2.Update.DELETE update.entity.table_entry.CopyFrom(table_entry) slb_sw.client_stub.Write(request)