# Run multiple p4 programs on different P4 switches using bmv2

**URL:** <https://forum.p4.org/t/run-multiple-p4-programs-on-different-p4-switches-using-bmv2/936>\
**Category:** P4 Dev\
**Created:** [September 3, 2023, 2:54am UTC](https://forum.p4.org/t/run-multiple-p4-programs-on-different-p4-switches-using-bmv2/936 "2023-09-03T02:54:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gxpy](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@gxpy](https://forum.p4.org/u/gxpy)\
**Post date:** [September 3, 2023, 2:54am UTC](https://forum.p4.org/t/run-multiple-p4-programs-on-different-p4-switches-using-bmv2/936/1 "2023-09-03T02:54:54Z")

</div>

Hi, I was told to run multiple p4 programs using bmv2, say we define switch A and switch B, and want to execute A.p4 on switch A and B.p4 on switch B. But I’m not quite sure if this can be done using bmv2. If this is possible, how can I do it?  
Thanks a lot for any reply 😄

---

<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:** [September 3, 2023, 3:32am UTC](https://forum.p4.org/t/run-multiple-p4-programs-on-different-p4-switches-using-bmv2/936/2 "2023-09-03T03:32:39Z")

</div>

Each bmv2 switch is a separate user space process, started via executing the command `simple_switch_grpc` with the desired command line options.

If you use the P4Runtime API, you can write one or more separate programs that act as P4Runtime API clients, connect using a TCP connection to a TCP port on which the `simple_switch_grpc` processes are listening for incoming connections (by default, TCP port 9559, unless you give a command line option that changes this default), and then send P4Runtime API messages over that socket to request that the switch perform various operations.

One of those operations, typically one of the first you do after making such a connection, is called `SetForwardingPipelineConfig`, which takes several parameters, one of which is the output of compiling a P4 program to be loaded into the switch. Your control program(s) could choose to give a different compiled P4 program to each of the `simple_switch_grpc` processes, or the same one – it is up to you to decide.

---

<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:** [September 3, 2023, 3:34am UTC](https://forum.p4.org/t/run-multiple-p4-programs-on-different-p4-switches-using-bmv2/936/3 "2023-09-03T03:34:14Z")

</div>

If you want an example of doing these steps using a single `simple_switch_grpc` process, and a single client program written in Python, before you later advance to doing so with multiple `simple_switch_grpc` processes, one place you can start is here:

- [https://github.com/jafingerhut/p4-guide/blob/master/demo1/README-p4runtime.md](https://github.com/jafingerhut/p4-guide/blob/master/demo1/README-p4runtime.md)

---

<div class="post-metadata">

**Author:** ![gxpy](https://avatars.discourse-cdn.com/v4/letter/g/54ee81/32.png) [@gxpy](https://forum.p4.org/u/gxpy)\
**Post date:** [September 3, 2023, 10:34am UTC](https://forum.p4.org/t/run-multiple-p4-programs-on-different-p4-switches-using-bmv2/936/4 "2023-09-03T10:34:42Z")

</div>

Thank you for your detailed explanation! This helped me a lot:)
