Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set custom IP and MAC address for host and switch #11

Closed
HUSTer2013 opened this issue Sep 9, 2019 · 2 comments
Closed

Set custom IP and MAC address for host and switch #11

HUSTer2013 opened this issue Sep 9, 2019 · 2 comments

Comments

@HUSTer2013
Copy link

Hi!
Can I set custom IP and MAC addresses for both hosts and switches by writing code in the p4app.json file? Or I can achieve this in another alternative way?
Thanks!

@edgar-costa
Copy link
Collaborator

edgar-costa commented Sep 11, 2019

Yes you can do it, however you have to use the manual IP assignment strategy:

https://github.com/nsg-ethz/p4-utils#assignment_strategy

Then for each host you can set an IP and Gateway IP. You can also assign IPs to switches however they will not be directly assigned to the interfaces but they will be stored in the Topology object in case you need to know them. To assign switches IPs you need to do the following:

"switches": {
      "s1": {
	"cpu_port" : true,
         "h1" : "10.0.1.1/24",
         "s2" : "10.0.2.1/24"
          }

So for example for the interface facing h1 you want 10.0.1.1/24.

The reason why switches can not get IPs assigned is the following: when a packet is sent between the virtual ethernet interfaces the linux network stack will check if it can forward that packet directly using its own routing table making the packet jump from one interface to the other without even crossing switches. For example:

h1------(10.0.1.1/24)sw1-------sw2-----sw3(10.0.3.1/24)------(10.0.3.2)h2.

Imagine that h1 is sending a packet to h2. This type of switches are configured in the main namespace of the linux network container, meaning that all the interfaces that you configure there share the same network stack. When you set the ip of sw1 and sw3 the linux routing table will have some entries that say that packets forwarded to 10.0.1.0/24 and 10.0.3.0/24 have to be sent to some known interface so when the packet with destination h2 arrives at sw1 even before it enters the switch, the linux kernel will send the packet directly to the sw3 interface, thus jumping sw2. However as i noted before, it is not necessary to set the IPs directly to the interface, you can still emulate it pretty well if you use the right controller/P4 code.

@HUSTer2013
Copy link
Author

Got it. Many thanks for your detailed reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants