Hello,
I am writing a P4 program in bmv2. I would like that P4 sends this information(including throughput and flow_id) by using digest + thrift to controller and set meter based on this digest.
I have already finish the function for get throughput and write digest in data plane, but when I try to write controller.py to receive the information, I always see the error: nnpy.errors.NNerror: Invalid argument.
I print the socket path and it shows ’ ', which means empty. What should I do to let the controller get correct socket path for specific P4 switch?
Here is my code part for get socket path in controller.py:
sock_path = sw.client.bm_mgmt_get_info().notifications_socket
sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
sub.connect(sock_path)
sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, b’')
print(“Connected to”, sock_path)
I suspect what you are asking can be made to work, but I have not done it before, and have no examples I can think of to point you at that does exactly that.
I do have an example I can point you at that:
sends a packet to the CPU port with a header containing P4-program-defined metadata fields at the beginning of the packet, which is similar to a digest, except that the packet is sent with it.
Uses a small controller program written in Python to receive the PacketIn messages from the switch that the switch creates and sends to the controller for such packets.
In fact, I can point you at two examples, which perhaps confusingly use two different Python libraries for interacting with the switch from the controller program.
Finally, I find that when use command “make run” in P4 toturial VM, system will use simple_switch_grpc to run Mininet. I change to use simple_switch and finally solve the empty socket path problem.
I discuss this problem with my classmate. Here is the discussion result about difference between simple_switch_grpc and simple_switch:
simple_switch : runs a thrift server on port 9090 and the controller can update
table via thrift APIs
simple_switch_grpc : runs a grpc server on port 50051 on the switch, and the
controller has to call grpc APIs to install table entries
Here are my solving steps:
I manually compiled the P4 code. Because my P4 code called “basic.p4”, I got “basic.json” file. The command:
I used mininetAPIs to write a python file to create a topo. Also, this topo.py will receive the parameter of the step3 command and run mininet using simple_switch
FYI, simple_switch_grpc can listen on two different TCP ports, one listening for Thrift-based control connection, and the other listening for P4Runtime API control connection, each with different TCP port numbers. Those TCP port numbers can be configured on the command line if you want non-default values, and I think the defaults might be the numbers you mentioned, but haven’t checked recently.