[P4-discuss] P4 Tutorials - P4D2_2017_Fall/utils/mininet

Antonin Bas antonin at barefootnetworks.com
Mon Oct 23 14:44:34 EDT 2017


This was copied from this file (
https://github.com/p4lang/behavioral-model/blob/master/mininet/1sw_demo.py#L78),
which I wrote a while ago.
The idea was to have 2 modes: "l3" to test L3 forwarding and "l2" to test
L2 forwarding.

In "l3" mode, we assumed the P4 switch didn't implement ARP, which is why
the ARP cache is populated manually for each switch with setARP. The "l3"
mode was originally meant to be used to test / demo this P4 program (
https://github.com/p4lang/behavioral-model/blob/master/targets/simple_router/simple_router.p4),
whose ipv4_lpm table would be populated with static L3 entries (
https://github.com/p4lang/behavioral-model/blob/master/targets/simple_router/commands.txt
).

The "l2" mode was meant to be used with this P4 program (
https://github.com/p4lang/behavioral-model/blob/master/targets/l2_switch/l2_switch.p4).
A simple control plane program was provided to learn mac addresses and
populate the smac / dmac tables.

In both cases, we had to set the default route in order to get it to work
and use the correct interface for all outgoing traffic. In "l3" mode we
need to provide a L3 gateway, but not in "l2" mode obviously, which is why
the 2 calls to setDefaultRoute are different.

On Mon, Oct 23, 2017 at 8:02 AM, Phanindra Palagummi <
phanindra.palagummi at gmail.com> wrote:

> Hello,
>
> Please consider below single_switch_mininet.py python file.
> https://github.com/p4lang/tutorials/blob/master/P4D2_
> 2017_Fall/utils/mininet/single_switch_mininet.py
>
> I put my own custom topology in the file single_switch_mininet.py, which
> is working properly, but I'm wondering why this below code is put, I see no
> link of this for any examples in tutorials, can any one please let me know
> if I'm missing anything.
>
>     """
>     sw_mac = ["00:aa:bb:00:00:%02x" % n for n in xrange(num_hosts)]
>
>     sw_addr = ["10.0.%d.1" % n for n in xrange(num_hosts)]
>
>     for n in xrange(num_hosts):
>         h = net.get('h%d' % (n + 1))
>         if mode == "l2":
>             h.setDefaultRoute("dev %s" % h.defaultIntf().name)
>         else:
>             h.setARP(sw_addr[n], sw_mac[n])
>             h.setDefaultRoute("dev %s via %s" % (h.defaultIntf().name,
> sw_addr[n]))
>
>     for n in xrange(num_hosts):
>         h = net.get('h%d' % (n + 1))
>         h.describe(sw_addr[n], sw_mac[n])
>
>     sleep(1)
>     """
>
> Thank you,
> Phani
>
> _______________________________________________
> P4-discuss mailing list
> P4-discuss at lists.p4.org
> http://lists.p4.org/mailman/listinfo/p4-discuss_lists.p4.org
>



-- 
Antonin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-discuss_lists.p4.org/attachments/20171023/cb6b3764/attachment-0002.html>


More information about the P4-discuss mailing list