# How to get Socket path when using controller to get information from data plane

**URL:** <https://forum.p4.org/t/how-to-get-socket-path-when-using-controller-to-get-information-from-data-plane/1358>\
**Category:** Getting Started with P4\
**Created:** [July 29, 2025, 1:11am UTC](https://forum.p4.org/t/how-to-get-socket-path-when-using-controller-to-get-information-from-data-plane/1358 "2025-07-29T01:11:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuexin12138](https://avatars.discourse-cdn.com/v4/letter/y/edb3f5/32.png) [@yuexin12138](https://forum.p4.org/u/yuexin12138)\
**Post date:** [July 29, 2025, 1:11am UTC](https://forum.p4.org/t/how-to-get-socket-path-when-using-controller-to-get-information-from-data-plane/1358/1 "2025-07-29T01:11:24Z")

</div>

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)

Thanks,  
Yuexin.

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [July 29, 2025, 11:16pm UTC](https://forum.p4.org/t/how-to-get-socket-path-when-using-controller-to-get-information-from-data-plane/1358/2 "2025-07-29T23:16:41Z")

</div>

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.

- [p4-guide/ptf-tests/packetinout at master · jafingerhut/p4-guide · GitHub](https://github.com/jafingerhut/p4-guide/tree/master/ptf-tests/packetinout)
- [tutorials/exercises/flowcache at master · p4lang/tutorials · GitHub](https://github.com/p4lang/tutorials/tree/master/exercises/flowcache)

---

<div class="post-metadata">

**Author:** ![yuexin12138](https://avatars.discourse-cdn.com/v4/letter/y/edb3f5/32.png) [@yuexin12138](https://forum.p4.org/u/yuexin12138)\
**Post date:** [July 30, 2025, 5:13pm UTC](https://forum.p4.org/t/how-to-get-socket-path-when-using-controller-to-get-information-from-data-plane/1358/4 "2025-07-30T17:13:51Z")

</div>

> [@yuexin12138](#):
>

Thank you for your help! I will try that examples.

---

<div class="post-metadata">

**Author:** ![yuexin12138](https://avatars.discourse-cdn.com/v4/letter/y/edb3f5/32.png) [@yuexin12138](https://forum.p4.org/u/yuexin12138)\
**Post date:** [August 13, 2025, 5:37pm UTC](https://forum.p4.org/t/how-to-get-socket-path-when-using-controller-to-get-information-from-data-plane/1358/5 "2025-08-13T17:37:42Z")

</div>

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_:

1. simple\_switch : runs a thrift server on port 9090 and the controller can update  
table via thrift APIs
2. 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:

1. I manually compiled the P4 code. Because my P4 code called “basic.p4”, I got “basic.json” file. The command:

> p4c --target bmv2 --arch v1model --std p4-16 basic.p4

1. 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

2. I use following command to run Mininet:

> sudo python3 topo.py --behavioral-exe simple\_switch --json basic.json

1. Set up the forwarding table and static ARP binding
2. In P4 switch terminal, run controller code “controller.py”:

> Python3 controller.py

---

<div class="post-metadata">

**Author:** ![andyfingerhut](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.p4.org/andyfingerhut/32/17_2.png) [@andyfingerhut](https://forum.p4.org/u/andyfingerhut)\
**Post date:** [August 13, 2025, 9:53pm UTC](https://forum.p4.org/t/how-to-get-socket-path-when-using-controller-to-get-information-from-data-plane/1358/6 "2025-08-13T21:53:27Z")

</div>

Glad you got things working.

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.

---

<div class="post-metadata">

**Author:** ![yuexin12138](https://avatars.discourse-cdn.com/v4/letter/y/edb3f5/32.png) [@yuexin12138](https://forum.p4.org/u/yuexin12138)\
**Post date:** [August 13, 2025, 9:56pm UTC](https://forum.p4.org/t/how-to-get-socket-path-when-using-controller-to-get-information-from-data-plane/1358/7 "2025-08-13T21:56:02Z")

</div>

> [@andyfingerhut](#):
>
> 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.

Thank you for your help!
