|
| 1 | +Example 2 - VLAN |
| 2 | +========= |
| 3 | + |
| 4 | +In this example we will test the VLAN support. |
| 5 | +We will configure two bridges, and four network namespaces connected to them. |
| 6 | + |
| 7 | +:: |
| 8 | + |
| 9 | + veth1 veth3 |
| 10 | + 10.0.0.1/24 10.0.0.3/24 |
| 11 | + | | |
| 12 | + | | |
| 13 | + VLAN 1 --> | | <-- VLAN 1 |
| 14 | + +----------+ +----------+ |
| 15 | + | br1 |-------------------------------------| br2 | |
| 16 | + | (cube) | ^ ^ | (cube) | |
| 17 | + +---------.+ | | +----------+ |
| 18 | + VLAN 2 --> | TRUNK mode TRUNK mode | <-- VLAN 2 |
| 19 | + | allowed 1,2 allowed 1,2 | |
| 20 | + | | |
| 21 | + veth2 veth4 |
| 22 | + 10.0.0.2/24 10.0.0.4/24 |
| 23 | + |
| 24 | +The following code configures the network namespaces and virtual network interfaces to be used. |
| 25 | + |
| 26 | +:: |
| 27 | + |
| 28 | + # copy and paste in your terminal |
| 29 | + |
| 30 | + # namespace ns1 -> veth1 10.0.0.1/24 |
| 31 | + # namespace ns2 -> veth2 10.0.0.2/24 |
| 32 | + # namespace ns3 -> veth3 10.0.0.3/24 |
| 33 | + # namespace ns4 -> veth4 10.0.0.4/24 |
| 34 | + |
| 35 | + for i in `seq 1 4`; |
| 36 | + do |
| 37 | + sudo ip netns del ns${i} > /dev/null 2>&1 # remove ns if already existed |
| 38 | + sudo ip link del veth${i} > /dev/null 2>&1 |
| 39 | + |
| 40 | + sudo ip netns add ns${i} |
| 41 | + sudo ip link add veth${i}_ type veth peer name veth${i} |
| 42 | + sudo ip link set veth${i}_ netns ns${i} |
| 43 | + sudo ip netns exec ns${i} ip link set dev veth${i}_ up |
| 44 | + sudo ip link set dev veth${i} up |
| 45 | + sudo ip netns exec ns${i} ifconfig veth${i}_ 10.0.0.${i}/24 |
| 46 | + done |
| 47 | + |
| 48 | + |
| 49 | +Create bridge instances, and connect virtual interfaces to them |
| 50 | + |
| 51 | +:: |
| 52 | + |
| 53 | + # create instances |
| 54 | + polycubectl bridge add br1 |
| 55 | + polycubectl bridge add br2 |
| 56 | + |
| 57 | + # create ports on br1 |
| 58 | + polycubectl br1 ports add toveth1 peer=veth1 |
| 59 | + polycubectl br1 ports add toveth2 peer=veth2 |
| 60 | + polycubectl br1 ports add tobr2 mode=trunk |
| 61 | + |
| 62 | + # create ports on br2 |
| 63 | + polycubectl br2 ports add toveth3 peer=veth3 |
| 64 | + polycubectl br2 ports add toveth4 peer=veth4 |
| 65 | + polycubectl br2 ports add tobr1 mode=trunk |
| 66 | + |
| 67 | + # connect the two bridges |
| 68 | + polycubectl connect br1:tobr2 br2:tobr1 |
| 69 | + |
| 70 | +Configure VLANs |
| 71 | + |
| 72 | +:: |
| 73 | + |
| 74 | + # By default, ports are configured in access mode, with VLAN 1 |
| 75 | + # Instead, ports in trunk mode have VLAN 1 allowed by default |
| 76 | + # (and that is also the native vlan) |
| 77 | + |
| 78 | + # br1 |
| 79 | + polycubectl br1 ports toveth2 access set vlanid=2 |
| 80 | + polycubectl br1 ports tobr2 trunk allowed add 2 |
| 81 | + |
| 82 | + # br2 |
| 83 | + polycubectl br2 ports toveth4 access set vlanid=2 |
| 84 | + polycubectl br2 ports tobr1 trunk allowed add 2 |
| 85 | + |
| 86 | +Ping between namespaces |
| 87 | + |
| 88 | +:: |
| 89 | + |
| 90 | + # ping ns3 from ns1 |
| 91 | + sudo ip netns exec ns1 ping 10.0.0.3 # ok |
| 92 | + |
| 93 | + # ping ns4 from ns2 |
| 94 | + sudo ip netns exec ns2 ping 10.0.0.4 # ok |
| 95 | + |
| 96 | + # ping ns4 from ns1 |
| 97 | + sudo ip netns exec ns1 ping 10.0.0.4 # packet discarded by br2: not the same VLAN! |
| 98 | + |
| 99 | +Delete bridges |
| 100 | + |
| 101 | +:: |
| 102 | + |
| 103 | + polycubectl br1 del |
| 104 | + polycubectl br2 del |
| 105 | + |
0 commit comments