p4lang / tdi

Table-Driven Interface (TDI) for a P4-programmable backend device.
Apache License 2.0
40 stars 23 forks source link

fix for add_from_json with register data fields #66

Closed satish153 closed 2 years ago

satish153 commented 2 years ago

Root cause: dump command outputs the register data fields as a list. So dump to json files has register datafield as list. But register data field is BYTE_STREAM and expects the input as BYTE_STREAM while adding entries.

Resolution: Picking the first element of the list as input for Register datafield.

Testing: tdi.tna_ternary_match.pipe.SwitchIngress.tcam_table> add_with_change_dmac(dst_addr="1.1.1.1", dst_addr_mask="255.255.255.255", src_addr="2.2.2.2",src_addr_mask="255.255.255.255", MATCH_PRIORITY=1, dstMac=0x0a0b0c0d0e0f, dst_port=5, fir ...: st="1", second="2")

tdi.tna_ternary_match.pipe.SwitchIngress.tcam_table> a=dump(json=True) table_type=0x800 ----- tcam_table Dump Start -----

tdi.tna_ternary_match.pipe.SwitchIngress.tcam_table> a Out[7]: '[{"table_name": "pipe.SwitchIngress.tcam_table", "action": "SwitchIngress.change_dmac", "key": {"hdr.ipv4.dst_addr": [16843009, 4294967295], "hdr.ipv4.src_addr": [33686018, 4294967295], "$MATCH_PRIORITY": 1}, "data": {"dstMac" : 11042563100175, "dst_port": 5, "SwitchIngress.direct_reg.first": [1, 1, 1, 1], "SwitchIngress.direct_reg.second": [2, 2, 2, 2]}}]'

tdi.tna_ternary_match.pipe.SwitchIngress.tcam_table> clear ---------------------------------------------------> clear()

tdi.tna_ternary_match.pipe.SwitchIngress.tcam_table> dump ---------------------------------------------------> dump() table_type=0x800 ----- tcam_table Dump Start ----- Default Entry: table_type=0x800 Entry data (action : NoAction): SwitchIngress.direct_reg.first : [] SwitchIngress.direct_reg.second : []

Table pipe.SwitchIngress.tcam_table has no entries. ----- tcam_table Dump End -----

tdi.tna_ternary_match.pipe.SwitchIngress.tcam_table> add_from_json(a) data_type=BYTE_STREAM data_type=BYTE_STREAM data_type=BYTE_STREAM data_type=BYTE_STREAM

tdi.tna_ternary_match.pipe.SwitchIngress.tcam_table> dump() table_type=0x800 ----- tcam_table Dump Start ----- Default Entry: table_type=0x800 Entry data (action : NoAction): SwitchIngress.direct_reg.first : [] SwitchIngress.direct_reg.second : []

Entry 0: Entry key: hdr.ipv4.dst_addr : ('0x01010101', '0xFFFFFFFF') hdr.ipv4.src_addr : ('0x02020202', '0xFFFFFFFF') $MATCH_PRIORITY : 1 Entry data (action : SwitchIngress.change_dmac): dstMac : 0x0A0B0C0D0E0F dst_port : 0x05 SwitchIngress.direct_reg.first : [1, 1, 1, 1] SwitchIngress.direct_reg.second : [2, 2, 2, 2]

----- tcam_table Dump End -----