Skip to content

Commit

Permalink
Merge pull request #381 from ipdk-io/dal_meter_config_meter
Browse files Browse the repository at this point in the history
Added support for delete meter configuration
  • Loading branch information
bharticemk authored Dec 18, 2023
2 parents 7d5383b + b5b3875 commit 997dc0f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions clients/p4rt-ctl/p4rt-ctl.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ for P4Runtime switches:
add-meter-config SWITCH MTR_TBL MTR_FLOW add packet mod meter config table entry
get-packet-mod-meter SWITCH MTR_TBL MTR_FLOW gets packet mod meter table entry
get-direct-pkt-mod-meter SWITCH MTR_TBL MTR_FLOW gets direct packet mod meter table entry
del-meter-config SWITCH MTR_TBL MTR_FLOW delete packet mod meter config table entry
"""

def usage():
Expand Down Expand Up @@ -1909,6 +1910,34 @@ def p4ctl_get_direct_pkt_mod_meter_entry(client, bridge, tbl_name, flow):
if entity.direct_meter_entry.table_entry.table_id == ce.table_entry.table_id:
print(_format_dme(entry.direct_meter_entry))

@with_client
def p4ctl_del_meter_config(client, bridge, tbl_name, flow):
"""
del-meter-config SWITCH MTR_TBL MTR_FLOW
Example:
p4rt-ctl del-meter-config br0 my_control.meter1 "meter_id=2244878476,meter_index=10"
"""
p4info = client.get_p4info()
if not p4info:
raise Exception("cannot retrieve P4Info from device {}".format(bridge))

helper = P4InfoHelper(p4info)
entity = p4runtime_pb2.Entity()
ce = entity.meter_entry

if ce is None:
raise Exception("Cannot find meter_entry field in entity")

meter_id, index = parse_get_meter_flow(flow)
ce.index.index = int(index)
ce.meter_id = int(meter_id)

update = p4runtime_pb2.Update()
update.type = p4runtime_pb2.Update.DELETE
update.entity.meter_entry.CopyFrom(ce)

client.write_update(update)

all_commands = {
"show": (p4ctl_show, 1),
"set-pipe": (p4ctl_set_pipe, 3),
Expand All @@ -1933,6 +1962,7 @@ all_commands = {
"add-meter-config" : (p4ctl_add_meter_config, 3),
"get-packet-mod-meter" : (p4ctl_get_packet_mod_meter_entry, 2),
"get-direct-pkt-mod-meter" : (p4ctl_get_direct_pkt_mod_meter_entry, 2)
"del-meter-config" : (p4ctl_del_meter_config, 2)
}


Expand Down

0 comments on commit 997dc0f

Please sign in to comment.