OpenFlow Change Path Tips


Dynamically change routing paths via switch VLAN tags

Initial the environment

cat start-lab-vlan-switch-path.sh
#! /bin/bash

echo "create namespaces..."
sudo ip netns add h1
sudo ip netns add h2
#sudo ip netns add s1
#sudo ip netns add s2
#sudo ip netns add s3
#sudo ip netns add s4

echo "generate virtual links..."
sudo ip link add h1_eth0 type veth peer name s1_eth0
sudo ip link add h2_eth0 type veth peer name s4_eth0
sudo ip link add s1_eth1 type veth peer name s2_eth0
sudo ip link add s1_eth2 type veth peer name s3_eth0
sudo ip link add s2_eth1 type veth peer name s4_eth1
sudo ip link add s3_eth1 type veth peer name s4_eth2

echo "init ovs bridges and add ports..."
sudo ovs-vsctl add-br s1
sudo ovs-vsctl add-br s2
sudo ovs-vsctl add-br s3
sudo ovs-vsctl add-br s4
sudo ovs-vsctl add-port s1 s1_eth0
sudo ovs-vsctl add-port s1 s1_eth1
sudo ovs-vsctl add-port s1 s1_eth2
sudo ovs-vsctl add-port s2 s2_eth0
sudo ovs-vsctl add-port s2 s2_eth1
sudo ovs-vsctl add-port s3 s3_eth0
sudo ovs-vsctl add-port s3 s3_eth1
sudo ovs-vsctl add-port s4 s4_eth0
sudo ovs-vsctl add-port s4 s4_eth1
sudo ovs-vsctl add-port s4 s4_eth2

echo "configure ovs..."
sudo ovs-vsctl set bridge s1 protocols=OpenFlow13
sudo ovs-vsctl set bridge s2 protocols=OpenFlow13
sudo ovs-vsctl set bridge s3 protocols=OpenFlow13
sudo ovs-vsctl set bridge s4 protocols=OpenFlow13
sudo ovs-vsctl set Interface s1_eth0 ofport_request=10
sudo ovs-vsctl set Interface s1_eth1 ofport_request=11
sudo ovs-vsctl set Interface s1_eth2 ofport_request=12
sudo ovs-vsctl set Interface s2_eth0 ofport_request=20
sudo ovs-vsctl set Interface s2_eth1 ofport_request=21
sudo ovs-vsctl set Interface s3_eth0 ofport_request=30
sudo ovs-vsctl set Interface s3_eth1 ofport_request=31
sudo ovs-vsctl set Interface s4_eth0 ofport_request=40
sudo ovs-vsctl set Interface s4_eth1 ofport_request=41
sudo ovs-vsctl set Interface s4_eth2 ofport_request=42

echo "assign virtual links..."
sudo ip link set h1_eth0 netns h1
sudo ip link set h2_eth0 netns h2
#sudo ip link set s1_eth0 netns s1
#sudo ip link set s1_eth1 netns s1
#sudo ip link set s1_eth2 netns s1
#sudo ip link set s2_eth0 netns s2
#sudo ip link set s2_eth1 netns s2
#sudo ip link set s3_eth0 netns s3
#sudo ip link set s3_eth1 netns s3
#sudo ip link set s4_eth0 netns s4
#sudo ip link set s4_eth1 netns s4
#sudo ip link set s4_eth2 netns s4

echo "launch loopback interfaces..."
sudo ip netns exec h1 ifconfig lo up
sudo ip netns exec h2 ifconfig lo up
#sudo ip netns exec s1 ifconfig lo up
#sudo ip netns exec s2 ifconfig lo up
#sudo ip netns exec s3 ifconfig lo up
#sudo ip netns exec s4 ifconfig lo up

echo "setup hosts' interfaces..."
sudo ip netns exec h1 ifconfig h1_eth0 192.168.0.101/24 up
sudo ip netns exec h2 ifconfig h2_eth0 192.168.0.102/24 up
#sudo ip netns exec s1 ifconfig s1_eth0 up
#sudo ip netns exec s1 ifconfig s1_eth1 up
#sudo ip netns exec s1 ifconfig s1_eth2 up
#sudo ip netns exec s2 ifconfig s2_eth0 up
#sudo ip netns exec s2 ifconfig s2_eth1 up
#sudo ip netns exec s3 ifconfig s3_eth0 up
#sudo ip netns exec s3 ifconfig s3_eth1 up
#sudo ip netns exec s4 ifconfig s4_eth0 up
#sudo ip netns exec s4 ifconfig s4_eth1 up
#sudo ip netns exec s4 ifconfig s4_eth2 up
sudo ifconfig s1_eth0 up
sudo ifconfig s1_eth1 up
sudo ifconfig s1_eth2 up
sudo ifconfig s2_eth0 up
sudo ifconfig s2_eth1 up
sudo ifconfig s3_eth0 up
sudo ifconfig s3_eth1 up
sudo ifconfig s4_eth0 up
sudo ifconfig s4_eth1 up
sudo ifconfig s4_eth2 up

Setup the basic forwarding flows

cat s1-flows
in_port=11,dl_vlan=10,actions=pop_vlan,output:10
in_port=12,dl_vlan=20,actions=pop_vlan,output:10
table=1,in_port=10,dl_vlan=10,actions=output:11
table=1,in_port=10,dl_vlan=20,actions=output:12

cat s2-flows
in_port=20,actions=output:21
in_port=21,actions=output:20

cat s3-flows
in_port=30,actions=output:31
in_port=31,actions=output:30

cat s4-flows
in_port=41,dl_vlan=10,actions=pop_vlan,output:40
in_port=42,dl_vlan=20,actions=pop_vlan,output:40
table=1,in_port=40,dl_vlan=10,actions=output:41
table=1,in_port=40,dl_vlan=20,actions=output:42

Install flow commands

sudo ovs-ofctl -O OpenFlow13 del-flows s1
sudo ovs-ofctl -O OpenFlow13 del-flows s2
sudo ovs-ofctl -O OpenFlow13 del-flows s3
sudo ovs-ofctl -O OpenFlow13 del-flows s4
sudo ovs-ofctl -O OpenFlow13 add-flows s1 s1-flows
sudo ovs-ofctl -O OpenFlow13 add-flows s2 s2-flows
sudo ovs-ofctl -O OpenFlow13 add-flows s3 s3-flows
sudo ovs-ofctl -O OpenFlow13 add-flows s4 s4-flows

Push VLAN tag

sudo ovs-ofctl -O OpenFlow13 add-flow s1 in_port=10,action=mod_vlan_vid:10,goto_table:1
sudo ovs-ofctl -O OpenFlow13 add-flow s4 in_port=40,action=mod_vlan_vid:10,goto_table:1

Switch VLAN (delete previous mod_vlan_vid flow flows and then add a new one)

sudo ovs-ofctl -O OpenFlow13 del-flows s1 table=0,in_port=10
sudo ovs-ofctl -O OpenFlow13 del-flows s4 table=0,in_port=40
sudo ovs-ofctl -O OpenFlow13 add-flow s1 in_port=10,action=mod_vlan_vid:20,goto_table:1
sudo ovs-ofctl -O OpenFlow13 add-flow s4 in_port=40,action=mod_vlan_vid:20,goto_table:1

Ping test

sudo ip netns exec h1 ping 192.168.0.102

Restore lan

cat stop-lab-vlan-switch-path.sh
#! /bin/bash

echo "del ovs ports and bridges"
sudo ovs-vsctl del-port s1 s1_eth0
sudo ovs-vsctl del-port s1 s1_eth1
sudo ovs-vsctl del-port s1 s1_eth2
sudo ovs-vsctl del-port s4 s4_eth0
sudo ovs-vsctl del-port s4 s4_eth1
sudo ovs-vsctl del-port s4 s4_eth2
sudo ovs-vsctl del-port s2 s2_eth0
sudo ovs-vsctl del-port s2 s2_eth1
sudo ovs-vsctl del-port s3 s3_eth0
sudo ovs-vsctl del-port s3 s3_eth1
sudo ovs-vsctl del-br s1
sudo ovs-vsctl del-br s2
sudo ovs-vsctl del-br s3
sudo ovs-vsctl del-br s4

echo "delete namespaces..."
sudo ip netns del h1
sudo ip netns del h2
#sudo ip netns del s1
#sudo ip netns del s2
#sudo ip netns del s3
#sudo ip netns del s4

echo "delete virtual links..."
sudo ip link del h1_eth0
sudo ip link del h2_eth0
sudo ip link del s1_eth1
sudo ip link del s1_eth2
sudo ip link del s2_eth1
sudo ip link del s3_eth1

Dynamically change routing paths via switch MPLS tags

cat s1-flows
in_port=11,dl_vlan=10,actions=pop_vlan,output:10
in_port=12,dl_vlan=20,actions=pop_vlan,output:10
table=1,in_port=10,dl_vlan=10,actions=output:11
table=1,in_port=10,dl_vlan=20,actions=output:12
dl_type=0x8847,mpls_label=110,actions=pop_mpls:0x0800,output:10
dl_type=0x8847,mpls_label=111,actions=pop_mpls:0x0806,output:10
dl_type=0x8847,mpls_label=120,actions=pop_mpls:0x0800,output:10
dl_type=0x8847,mpls_label=121,actions=pop_mpls:0x0806,output:10
table=2,in_port=10,dl_type=0x8847,mpls_label=110,actions=output:11
table=2,in_port=10,dl_type=0x8847,mpls_label=111,actions=output:11
table=2,in_port=10,dl_type=0x8847,mpls_label=120,actions=output:12
table=2,in_port=10,dl_type=0x8847,mpls_label=121,actions=output:12

cat s4-flows
in_port=41,dl_vlan=10,actions=pop_vlan,output:40
in_port=42,dl_vlan=20,actions=pop_vlan,output:40
table=1,in_port=40,dl_vlan=10,actions=output:41
table=1,in_port=40,dl_vlan=20,actions=output:42
dl_type=0x8847,mpls_label=110,actions=pop_mpls:0x0800,output:40
dl_type=0x8847,mpls_label=111,actions=pop_mpls:0x0806,output:40
dl_type=0x8847,mpls_label=120,actions=pop_mpls:0x0800,output:40
dl_type=0x8847,mpls_label=121,actions=pop_mpls:0x0806,output:40
table=2,in_port=40,dl_type=0x8847,mpls_label=110,actions=output:41
table=2,in_port=40,dl_type=0x8847,mpls_label=111,actions=output:41
table=2,in_port=40,dl_type=0x8847,mpls_label=120,actions=output:42
table=2,in_port=40,dl_type=0x8847,mpls_label=121,actions=output:42

IP flow rules

sudo ovs-ofctl -O OpenFlow13 add-flow s1 in_port=10,ip,action=push_mpls:0x8847,set_mpls_label:110,goto_table:2
sudo ovs-ofctl -O OpenFlow13 add-flow s1 dl_type=0x8847,mpls_label=110,actions=pop_mpls:0x0800,output:10

ARP flow rules

sudo ovs-ofctl -O OpenFlow13 add-flow s1 in_port=10,arp,action=push_mpls:0x8847,set_mpls_label:111,goto_table:2
sudo ovs-ofctl -O OpenFlow13 add-flow s1 dl_type=0x8847,mpls_label=111,actions=pop_mpls:0x0806,output:10

Delete flows in table 0 which in_port is 10 or 40.

sudo ovs-ofctl -O OpenFlow13 del-flows s1 table=0,in_port=10
sudo ovs-ofctl -O OpenFlow13 del-flows s4 table=0,in_port=40









References


Chi-Sheng Su