VLAN emulation using Virtualization
Go here for discussion - https://youtu.be/LuKP7SC055o
#!/bin/bash # Experiment: # To understand vlan as a logical broadcast domain created within a switch # where in the hosts within a same vlan will receive a broadcast packet # sent by one of the host of the same vlan. # This brings us the understanding that there can be more than 1 broadcast # domains within a switch. #Create 4 Network Namespaces N1, N2, N3 and N4 ip netns add C1 ip netns add C2 ip netns add C3 ip netns add C4 # Creation of OVS Bridge br0 BRIDGE0=br0 ovs-vsctl add-br $BRIDGE0 ip link set dev $BRIDGE0 up #Create a 4 veth pair (v1,v2), (v3,v4), (v5,v6), (v7, v8) ip link add v1 type veth peer name v2 ip link add v3 type veth peer name v4 ip link add v5 type veth peer name v6 ip link add v7 type veth peer name v8 # Interconnecting C1 and br0 ovs-vsctl add-port $BRIDGE0 v2 tag=10 # Connect v2 to bridge br0 ip link set v1 netns C1 # Connect v1 to C1 ip netns exec C1 ip addr add 10.10.10.2/24 dev v1 # Assign IP addr for v1 in C1 ip netns exec C1 ip link set dev v1 up # Bring up v1 in C1 ip link set dev v2 up # Bring up v2 in bridge br0 # Interconnecting C2 and br0 ovs-vsctl add-port $BRIDGE0 v4 tag=10 # Connect v4 to bridge br0 ip link set v3 netns C2 # Connect v3 to C2 ip netns exec C2 ip addr add 10.10.10.3/24 dev v3 # Assign IP addr for v3 in C2 ip netns exec C2 ip link set dev v3 up # Bring up v3 in C2 ip link set dev v4 up # Bring up v4 in bridge br0 # Interconnecting C3 and br0 ovs-vsctl add-port $BRIDGE0 v6 tag=20 # Connect v6 to bridge br0 ip link set v5 netns C3 # Connect v5 to C3 ip netns exec C3 ip addr add 10.10.20.2/24 dev v5 # Assign IP addr for v5 in C3 ip netns exec C3 ip link set dev v5 up # Bring up v5 in C3 ip link set dev v6 up # Bring up v6 in bridge br0 # Interconnecting C4 and br0 ovs-vsctl add-port $BRIDGE0 v8 tag=20 # Connect v8 to bridge br0 ip link set v7 netns C4 # Connect v7 to C4 ip netns exec C4 ip addr add 10.10.20.3/24 dev v7 # Assign IP addr for v7 in C4 ip netns exec C4 ip link set dev v7 up # Bring up v7 in C4 ip link set dev v8 up # Bring up v8 in bridge br0 ############################################################################## #!/bin/bash # exp 3 # To bring down the topology setup in exp 3 # To bring down the interfaces of containers ip netns exec C1 ip link set dev v1 down ip netns exec C2 ip link set dev v3 down ip netns exec C3 ip link set dev v5 down ip netns exec C4 ip link set dev v7 down # To bring down the interfaces of the bridge ip link set dev v2 down ip link set dev v4 down ip link set dev v6 down ip link set dev v8 down # Bring down the ovs bridge ip link set dev br0 down # Detach the Management ports from the OVS-Bridge ovs-vsctl del-port $BRIDGE0 v2 ovs-vsctl del-port $BRIDGE0 v4 ovs-vsctl del-port $BRIDGE0 v6 ovs-vsctl del-port $BRIDGE0 v8 # Delete the veth pairs ip link del dev v2 ip link del dev v4 ip link del dev v6 ip link del dev v8 # Delete ovs bridge from Host network namespace ovs-vsctl del-br br0 # Delete network namespaces or micro-containers ip netns del C1 ip netns del C2 ip netns del C3 ip netns del C4