# Switch's IP and MAC address

**URL:** <https://forum.p4.org/t/switchs-ip-and-mac-address/1270>\
**Category:** P4 Dev\
**Created:** [March 9, 2025, 7:53pm UTC](https://forum.p4.org/t/switchs-ip-and-mac-address/1270 "2025-03-09T19:53:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![akshataavk](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@akshataavk](https://forum.p4.org/u/akshataavk)\
**Post date:** [March 9, 2025, 7:53pm UTC](https://forum.p4.org/t/switchs-ip-and-mac-address/1270/1 "2025-03-09T19:53:14Z")

</div>

Hello,  
As part of my project, I am working on a load balancer with 2 switches in the topology (JSON file). I followed the tutorials, and I found hosts broadcasting to send a packet from one host to another via the ports on the switch.  
I’m using bmv2 just like in the tutorials.  
In my implementation, however, I want to send the packets on switch 1 when I initiate a packet. Is it possible to have static IP and MAC addresses for the switches in the topology json the way hosts have them? I want to use the static MAC address of the switch when sending a packet.

I’m not sure if this will disrupt the setup in the tutorials exercise folder because in the run\_exercie.py , I see for link in host\_links:  
host\_name = link[‘node1’]  
sw\_name, sw\_port = self.parse\_switch\_node(link[‘node2’])  
host\_ip = hosts[host\_name][‘ip’]  
host\_mac = hosts[host\_name][‘mac’]  
self.addHost(host\_name, ip=host\_ip, mac=host\_mac)  
self.addLink(host\_name, sw\_name,  
delay=link[‘latency’], bw=link[‘bandwidth’],  
port2=sw\_port)

```
    for link in switch_links:
        sw1_name, sw1_port = self.parse_switch_node(link['node1'])
        sw2_name, sw2_port = self.parse_switch_node(link['node2'])
        self.addLink(sw1_name, sw2_name,
                    port1=sw1_port, port2=sw2_port,
                    delay=link['latency'], bw=link['bandwidth']).

```

Thanks a lot in advance!

---

<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:** [March 9, 2025, 8:25pm UTC](https://forum.p4.org/t/switchs-ip-and-mac-address/1270/2 "2025-03-09T20:25:35Z")

</div>

I only have a lead to a possible answer for you, not a detailed answer.

(a) It is possible to write P4 programs that run on a switch where the concept of the switch having a static IP address (or even more than one) or a static MAC address (or more than one) make sense.

(b) It is also possible to write P4 programs that run on a switch where it is not applicable to say that the switch has a static IP address, or a static MAC address, even though the switch is programmed with the concept of Ethernet and IPv4 headers.

(c) Finally, it is possible to write a P4 program that runs on a switch where the concept of Ethernet and IPv4 are not applicable.

Sorry, I do not know whether the P4 program you are thinking about fits into category (a) or (b). i am pretty sure it does not belong in category (c).
