I plan to use P4runtime to assume forwarding rules for my switch, but I ran into the following problem。
and my code is following:
p4info_helper = p4runtime_lib.helper.P4InfoHelper(p4info_file_path)
try:
s1 = p4runtime_lib.bmv2.Bmv2SwitchConnection(
name='s1',
address='127.0.0.1:50051',
device_id=0,
proto_dump_file='logs/s1-p4runtime-request.txt'
)
s2 = p4runtime_lib.bmv2.Bmv2SwitchConnection(
name='s2',
address='127.0.0.1:50052',
device_id=1,
proto_dump_file='logs/s2-p4runtime-request.txt'
)
s3 = p4runtime_lib.bmv2.Bmv2SwitchConnection(
name='s3',
address='127.0.0.1:50053',
device_id=2,
proto_dump_file='logs/s3-p4runtime-request.txt'
)
s4 = p4runtime_lib.bmv2.Bmv2SwitchConnection(
name='s4',
address='127.0.0.1:50054',
device_id=3,
proto_dump_file='logs/s4-p4runtime-request.txt'
)
s5 = p4runtime_lib.bmv2.Bmv2SwitchConnection(
name='s5',
address='127.0.0.1:50055',
device_id=4,
proto_dump_file='logs/s5-p4runtime-request.txt'
)
s1.MasterArbitrationUpdate()
s2.MasterArbitrationUpdate()
s3.MasterArbitrationUpdate()
s4.MasterArbitrationUpdate()
s5.MasterArbitrationUpdate()
#在交换机上安装P4程序
s1.SetForwardingPipelineConfig(p4info=p4info_helper.p4info, bmv2_json_file_path=bmv2_file_path)
print("Installed P4 Program using SetForwardingPipelingeConfig on s1")
s2.SetForwardingPipelineConfig(p4info=p4info_helper.p4info, bmv2_json_file_path=bmv2_file_path)
print("Installed P4 Program using SetForwardingPipelingeConfig on s2")
s3.SetForwardingPipelineConfig(p4info=p4info_helper.p4info, bmv2_json_file_path=bmv2_file_path)
print("Installed P4 Program using SetForwardingPipelingeConfig on s3")
s4.SetForwardingPipelineConfig(p4info=p4info_helper.p4info, bmv2_json_file_path=bmv2_file_path)
print("Installed P4 Program using SetForwardingPipelingeConfig on s4")
s5.SetForwardingPipelineConfig(p4info=p4info_helper.p4info, bmv2_json_file_path=bmv2_file_path)
print("Installed P4 Program using SetForwardingPipelingeConfig on s5")
writeRules(p4info_helper, switch_name=s1, table_name="MyIngress.Is_local_ip", action="NoAction", match_fields="hdr.ipv4.dstAddr", match_value="192.168.7.128")
writeRules(p4info_helper, switch_name=s3, table_name="MyIngress.Is_local_ip", action="NoAction", match_fields="hdr.ipv4.dstAddr", match_value="192.168.10.128")
writeRules(p4info_helper, switch_name=s3, table_name="MyIngress.Is_local_ip", action="NoAction", match_fields="hdr.ipv4.dstAddr", match_value="192.168.11.128")
writeRules(p4info_helper, switch_name=s5, table_name="MyIngress.Is_local_ip", action="NoAction", match_fields="hdr.ipv4.dstAddr", match_value="192.168.8.128")
#ipv4_route
writeRouteRules(p4info_helper, switch_name=s1, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="10.0.1.2", value1="00:00:0a:00:01:02", value2=1)
writeRouteRules(p4info_helper, switch_name=s1, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.7.129", value1="b4:05:5d:9d:a9:20", value2=2)
writeRouteRules(p4info_helper, switch_name=s1, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.10.128", value1="b4:05:5d:9d:a9:20", value2=2)
writeRouteRules(p4info_helper, switch_name=s1, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.11.129", value1="b4:05:5d:9d:a9:20", value2=2)
writeRouteRules(p4info_helper, switch_name=s2, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.7.128", value1="b4:05:5d:9d:a8:20", value2=1)
writeRouteRules(p4info_helper, switch_name=s2, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.10.128", value1="b4:05:5d:9d:aa:50", value2=2)
writeRouteRules(p4info_helper, switch_name=s2, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.11.129", value1="b4:05:5d:9d:aa:50", value2=2)
writeRouteRules(p4info_helper, switch_name=s2, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.8.128", value1="b4:05:5d:9d:aa:50", value2=2)
writeRouteRules(p4info_helper, switch_name=s3, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.7.128", value1="b4:05:5d:9d:aa:21", value2=1)
writeRouteRules(p4info_helper, switch_name=s3, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.10.129", value1="b4:05:5d:9d:aa:21", value2=1)
writeRouteRules(p4info_helper, switch_name=s3, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.11.129", value1="b4:05:5d:78:72:ac", value2=2)
writeRouteRules(p4info_helper, switch_name=s3, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.8.128", value1="b4:05:5d:78:72:ac", value2=2)
writeRouteRules(p4info_helper, switch_name=s4, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.7.128", value1="b4:05:5d:9d:aa:f0", value2=1)
writeRouteRules(p4info_helper, switch_name=s4, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.10.129", value1="b4:05:5d:9d:aa:f0", value2=1)
writeRouteRules(p4info_helper, switch_name=s4, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.11.128", value1="b4:05:5d:9d:aa:f0", value2=1)
writeRouteRules(p4info_helper, switch_name=s4, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.8.128", value1="b4:05:5d:9d:23:21", value2=2)
writeRouteRules(p4info_helper, switch_name=s5, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="10.0.2.2", value1="00:00:0a:00:02:02", value2=2)
writeRouteRules(p4info_helper, switch_name=s5, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.10.129", value1="b4:05:5d:78:72:ab", value2=1)
writeRouteRules(p4info_helper, switch_name=s5, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.11.128", value1="b4:05:5d:78:72:ab", value2=1)
writeRouteRules(p4info_helper, switch_name=s5, table_name="MyIngress.ipv4_lpm", action="MyIngress.ipv4_forward", match_fields="hdr.ipv4.dstAddr", match_value="192.168.8.129", value1="b4:05:5d:78:72:ab", value2=1)
#read rules on switch
readTableRules(p4info_helper, s1)
readTableRules(p4info_helper, s2)
readTableRules(p4info_helper, s3)
readTableRules(p4info_helper, s4)
readTableRules(p4info_helper, s5)
I cannot see the error that appears with this issue,Is this because I added too many table entries at once?How can I solve this problem?