Example #1
0
    def test_table_info(self):
        t = sh.P4Objects(P4Type.table)["ExactOne"]
        expected = """
preamble {
  id: 33582705
  name: "ExactOne"
  alias: "ExactOne"
}
match_fields {
  id: 1
  name: "header_test.field32"
  bitwidth: 32
  match_type: EXACT
}
action_refs {
  id: 16783703 ("actionA")
}
action_refs {
  id: 16809468 ("actionB")
}
action_refs {
  id: 16800567 ("NoAction")
  annotations: "@defaultonly"
  scope: DEFAULT_ONLY
}
direct_resource_ids: 318768298 ("ExactOne_counter")
direct_resource_ids: 352326600 ("ExactOne_meter")
size: 512
"""
        self.assertIn(str(t), expected)
                "args"  : {"port_num" : PORTS[idx]}
            }
            for idx in [UE, INTERNET]
        ]

entries =   filtering_entries + \
            spgw_entries + \
            forwarding_entries + \
            acl_entries + \
            next_entries + \
            []

print("deleting entries from any previous run")


tables = sh.P4Objects(context.P4Type.table)
count = 0
for table in tables:
    for te in sh.TableEntry(table.name).read():
        count += 1
        te.delete()
print("Deleted %d entries" % count)


print("installing entries")
for i, entry in enumerate(entries):
    print("installing %d" % i)
    try:
        te = sh.TableEntry(entry["table"])(action=entry["action"])
        for key, val in entry["keys"].items():  te.match[key] = val
        for arg,val in entry["args"].items():   te.action[arg] = val