@name, Thank you very much for your reply.
I’m so sorry I didn’t reply you in time for doing other things.
Ok, let me describe in detail what I am doing now and what I want to do with bmv2.
The function I am currently implementing in python code is a packet classification algorithm.
In theory, it can be applied to any scenario that requires packet classification, such as routing table query, firewall acl query, etc.
Packet classification is a process that classifies a packet to determine which rule in the rule set matches the packet by inspecting some packet header field.
A packet classifier contains a list of rules. Each rule specifies a pattern on multiple fields in the packet header. Typically, these fields include source and destination IP addresses, source and destination port numbers, and protocol type. The rule’s pattern specifies which packets match the rule. Matching conditions include prefix based matching (e.g., for IP addresses, similar to LPM supported by bmv2), range based matching (e.g., for port numbers, similar to RANGE supported by bmv2), and exact matching (e.g., for protocol type, similar to EXACT supported by bmv2).
A packet matches a rule if each field in the packet header satisfies the matching condition of the corresponding field in the rule, e.g., the packet’s source/destination IP address matches the
prefix of the source/destination address in the rule, the packet’s source/destination port number is contained in the source/destination range specified in the rule, and the packet’s protocol type matches
the rule’s protocol type.
In practice, the input to my algorithm looks like this:
205.169.228.10, 79.60.9.165, 2000, 1708, 0x06
consist of source and destination IP addresses, source and destination port numbers, and protocol type.
The set of rules to be queried looks like this:
205.169.228.10/32 79.60.9.165/32 0 : 65535 1708 : 1708 0x06/0xFF action1
205.171.136.164/32 79.60.10.66/32 0 : 65535 1526 : 1526 0x06/0xFF action2
205.191.6.238/32 79.60.2.20/32 0 : 65535 20 : 20 0x06/0xFF action3
205.176.132.226/32 79.60.19.50/32 0 : 65535 5632 : 5632 0x06/0xFF action4
Through my algorithm, the action1 corresponding to the first rule will eventually be output.
If implemented using p4, I think it might be something like this:
table ipv4_classification{
key = {
hdr.ipv4.srcAddr: lpm;
hdr.ipv4.dstAddr: lpm;
hdr.ipv4.srcPort: range;
hdr.ipv4.dstPort: range;
hdr.ipv4.protocol: exact;
}
actions = {
action1;
action2;
action3;
action4;
}
Now since my algorithm is just a simulation implementation, the rules are stored directly in a document and read directly with python. If I want to implement on bmv2, the rules should be stored in routing table entries in bmv2.
So I think I need to modify the underlying source code of bmv2 to implement a new match kind that can query the table that stores routing table rules in bmv2.
Thanks