p4lang / tutorials

P4 language tutorials
Apache License 2.0
1.33k stars 878 forks source link

When p4runtime writes a new rule, do we insert the new rule or overwrite all existing rules? #546

Closed sunruifeng0602 closed 6 months ago

sunruifeng0602 commented 6 months ago

The JSON code snippet for topology is as follows:

table_entries": [
    {
      "table": "ingress.ipv4_lpm",
      "default_action": true,
      "action_name": "ingress._drop",
      "action_params": { }
    },
    {
      "table": "ingress.ipv4_lpm",
      "match": {
        "ipv4.dstAddr": ["10.0.1.1", 32]
      },
      "action_name": "ingress.ipv4_forward",
      "action_params": {
        "dstAddr": "08:00:00:00:01:11",
        "port": 1
      }
    },
    {
      "table": "ingress.ipv4_lpm",
      "match": {
        "ipv4.dstAddr": ["10.0.2.2", 32]
      },
      "action_name": "ingress.ipv4_forward",
      "action_params": {
        "dstAddr": "08:00:00:00:02:00",
        "port": 2
      }
    },
    {
      "table": "ingress.ipv4_lpm",
      "match": {
        "ipv4.dstAddr": ["10.0.3.3", 32]
      },
      "action_name": "ingress.ipv4_forward",
      "action_params": {
        "dstAddr": "08:00:00:00:03:00",
        "port": 3
      }
    }
  ]

When I write new rules(with completely different effects), it's like this:

table_entry = p4info_helper.buildTableEntry(
        table_name="MyIngress.newRule",
        match_fields={
        },
        action_name="MyIngress.newRule_ingress",
        action_params={
        })
    ingress_sw.WriteTableEntry(table_entry)

Insert new rules or overwrite all existing rules

jafingerhut commented 6 months ago

I would recommend asking such questions at https://forum.p4.org where there are more people reading questions (and potentially answering them) than this Github repository.

I would also recommend for your particular question that you find out the answer by experimentation -- write some Python code that reads out the entries of the tables and prints them to the terminal, and try running that before you insert a new rule, and after. If you see any results that confuse you, ask about it (with details of what you tried, and what you expected to be different) at https://forum.p4.org

sunruifeng0602 commented 6 months ago

Thank you for your help