Deleting a key with Python

Hi

I have entires in my BMV as follows:

In [10]: bfrt.switch.pipe.ig_ctl.srv6.ipoe_transit.dump
-------> bfrt.switch.pipe.ig_ctl.srv6.ipoe_transit.dump()
----- ipoe_transit Dump Start -----
Default Entry:
Entry data (action : NoAction):

Entry 0:
Entry key:
hdr.ipv4.src_addr : (‘0x00000000’, ‘0x00000000’)
hdr.ipv4.dst_addr : (‘0xC0A80201’, ‘0xFFFFFFFF’)
$MATCH_PRIORITY : 0
Entry data (action : ig_ctl.srv6.fup_encap_dt2d_e):
src_addr : 0xFD010000000000000000000000000001
next_hop : 0xFC123456000000000000000000000000
src_mac : 0x00CAE1C90000
dst_mac : 0x00C86A020003
client_mac : 0x0C3311BF0000

Entry 1:
Entry key:
hdr.ipv4.src_addr : (‘0x00000000’, ‘0x00000000’)
hdr.ipv4.dst_addr : (‘0xC0A80266’, ‘0xFFFFFFFF’)
$MATCH_PRIORITY : 0
Entry data (action : ig_ctl.srv6.fup_encap_dt2d_e):
src_addr : 0xFD010000000000000000000000000001
next_hop : 0xFC123456000000000000000000000000
src_mac : 0x00CAE1C90000
dst_mac : 0x00C86A020003
client_mac : 0x0C3311BF0000

----- ipoe_transit Dump End -----

In [11]:

I want to delete the second one from my Python program so I have the following:

            srv6_end = bfrt_info.table_get('pipe.ig_ctl.srv6.ipoe_transit')


            keys_to_delete = []
            ip_in_int = int(ipaddress.ip_address(x[0]))
            print(hex(ip_in_int))
            search_key = srv6_end.make_key([
                gc.KeyTuple('$MATCH_PRIORITY', 0x00), gc.KeyTuple('hdr.ipv4.src_addr', 0x00000000, 0x00000000), gc.KeyTuple('hdr.ipv4.dst_addr', ip_in_int, 0xffffffff)])
            print(search_key)
srv6_end_entry_del(gc.Target(), search_key)

I’ve cheked the keys in the table against the ‘search_key’ that I generate and they appear to be identical:

search_key:

{‘$MATCH_PRIORITY’: {‘value’: 0}, ‘hdr.ipv4.dst_addr’: {‘value’: 3232236134, ‘mask’: 4294967295}, ‘hdr.ipv4.src_addr’: {‘value’: 0, ‘mask’: 0}}

displayed keys in Python from the BMV:

{‘$MATCH_PRIORITY’: {‘value’: 0}, ‘hdr.ipv4.dst_addr’: {‘value’: 3232236033, ‘mask’: 4294967295}, ‘hdr.ipv4.src_addr’: {‘value’: 0, ‘mask’: 0}}
{‘$MATCH_PRIORITY’: {‘value’: 0}, ‘hdr.ipv4.dst_addr’: {‘value’: 3232236134, ‘mask’: 4294967295}, ‘hdr.ipv4.src_addr’: {‘value’: 0, ‘mask’: 0}}

(the second one matches as is the one I wish to delete).

I can’t delete the key.

Where am I going wrong please?

Thanks

David

Hello David,

First of all, I’d highly recommend you provide accurate information about your environment. It looks like bfrt_python for Tofino, but that’s just my guess. Then you seem to proceed and use a different binding, that looks like bfrt_grpc.client module. The BMW you mentioned in the first sentence remains anyone’s guess.

In general, if you want to get help you should put some effort into your message. This includes providing the basic facts about your environment, providing your program, explaining your debugging steps and formatting the message nicely.

Looking at your current message, I am not sure what is that srv6_end_entry_del() function that you are using. If you are using bfrt_grpc.client module, the right way to do it would be to use the entry_del() method of the corresponding table object, i.e. srv6_end.entry_del(). However, you should’ve gotten a traceback immediately.

Or, are you trying to use that code (that starts with bfrt_info.table_get() inside bfrt_python, which would not make much sense.

So, what exactly are you trying to do?

Happy hacking,
Vladimir

Apologies for the inaccuracies in the email - small screen and fat fingers.

I had mixed-up the implementation and squaring that away has fixed the issue.

The table_get was not require and rebuilding the entry_del with the correct key/dictionary structure has resolved the issue.

Thank you again for the prompt to look more carefully at my work and fix it.

Kind regards

David

1 Like