Modify scripts for creating and removing physical topology in openflow-renderer.
[nemo.git] / nemo-renderers / openflow-renderer / src / test / resources / network-up-servicechain.sh
1 #!/bin/bash
2
3 echo "Creating links......"
4
5 ########## sw1 ##########
6 ip link add name sw1-eth1 type veth peer name fw1-eth0
7 ip link add name sw1-eth2 type veth peer name fw2-eth0
8 ip link add name sw1-eth3 type veth peer name sw3-eth1
9
10 ########## sw2 ##########
11 ip link add name sw2-eth1 type veth peer name cache1-eth0
12 ip link add name sw2-eth2 type veth peer name cache2-eth0
13 ip link add name sw2-eth3 type veth peer name sw3-eth2
14
15 ########## sw3 ##########
16 #ip link add name sw3-eth1 type veth peer name sw1-eth3
17 #ip link add name sw3-eth2 type veth peer name sw2-eth3
18 ip link add name sw3-eth3 type veth peer name sw4-eth1
19 ip link add name sw3-eth4 type veth peer name branch-eth0
20
21 ########## sw4 ##########
22 #ip link add name sw4-eth1 type veth peer name sw3-eth3
23 ip link add name sw4-eth2 type veth peer name head-eth0
24
25 echo "Creating hosts......"
26
27 ########## fw1 ##########
28 ip netns add fw1
29 ip link set fw1-eth0 netns fw1
30
31 ########## fw2 ##########
32 ip netns add fw2
33 ip link set fw2-eth0 netns fw2
34
35 ########## cache1 ##########
36 ip netns add cache1
37 ip link set cache1-eth0 netns cache1
38
39 ########## cache2 ##########
40 ip netns add cache2
41 ip link set cache2-eth0 netns cache2
42
43 ########## headquarter ##########
44 ip netns add head
45 ip link set head-eth0 netns head
46
47 ########## branch ##########
48 ip netns add branch
49 ip link set branch-eth0 netns branch
50
51 echo "Starting OpenFlow soft switches......"
52
53 ########## sw1 ##########
54 ofdatapath -i sw1-eth1,sw1-eth2,sw1-eth3 punix:/tmp/sw1 -d 000000000001 1> /tmp/sw1-ofd.log 2> /tmp/sw1-ofd.log &
55 ofprotocol unix:/tmp/sw1 tcp:127.0.0.1:6633 --fail=closed --listen=ptcp:6661 1> /tmp/sw1-ofp.log 2> /tmp/sw1-ofp.log &
56
57 ########## sw2 ##########
58 ofdatapath -i sw2-eth1,sw2-eth2,sw2-eth3 punix:/tmp/sw2 -d 000000000002 1> /tmp/sw2-ofd.log 2> /tmp/sw2-ofd.log &
59 ofprotocol unix:/tmp/sw2 tcp:127.0.0.1:6633 --fail=closed --listen=ptcp:6662 1> /tmp/sw2-ofp.log 2> /tmp/sw2-ofp.log &
60
61 ########## sw3 ##########
62 ofdatapath -i sw3-eth1,sw3-eth2,sw3-eth3,sw3-eth4 punix:/tmp/sw3 -d 000000000003 1> /tmp/sw3-ofd.log 2> /tmp/sw3-ofd.log &
63 ofprotocol unix:/tmp/sw3 tcp:127.0.0.1:6633 --fail=closed --listen=ptcp:6663 1> /tmp/sw3-ofp.log 2> /tmp/sw3-ofp.log &
64
65 ########## sw4 ##########
66 ofdatapath -i sw4-eth1,sw4-eth2 punix:/tmp/sw4 -d 000000000004 1> /tmp/sw4-ofd.log 2> /tmp/sw4-ofd.log &
67 ofprotocol unix:/tmp/sw4 tcp:127.0.0.1:6633 --fail=closed --listen=ptcp:6664 1> /tmp/sw4-ofp.log 2> /tmp/sw4-ofp.log &
68
69 echo "Configuring OpenFlow soft switches......"
70
71 ifconfig sw1-eth1 down
72 ifconfig sw1-eth1 hw ether 00:00:00:00:01:01
73 ifconfig sw1-eth1 up
74
75 ifconfig sw2-eth2 down
76 ifconfig sw2-eth2 hw ether 00:00:00:00:02:02
77 ifconfig sw2-eth2 up
78
79 ifconfig sw3-eth4 down
80 ifconfig sw3-eth4 hw ether 00:00:00:00:03:04
81 ifconfig sw3-eth4 up
82
83 ifconfig sw4-eth2 down
84 ifconfig sw4-eth2 hw ether 00:00:00:00:04:02
85 ifconfig sw4-eth2 up
86
87 echo "Configuring hosts......"
88
89 ip netns exec fw1 ifconfig fw1-eth0 down
90 ip netns exec fw1 ifconfig fw1-eth0 hw ether 00:00:00:00:00:01
91 ip netns exec fw1 ifconfig fw1-eth0 192.168.13.2/24
92 ip netns exec fw1 ifconfig fw1-eth0 up
93 ip netns exec fw1 route add default gw 192.168.13.1
94 ip netns exec fw1 arp -s 192.168.13.1 00:00:00:00:01:01
95 ip netns exec fw1 echo 1 > /proc/sys/net/ipv4/ip_forward
96
97 ip netns exec cache2 ifconfig cache2-eth0 down
98 ip netns exec cache2 ifconfig cache2-eth0 hw ether 00:00:00:00:00:02
99 ip netns exec cache2 ifconfig cache2-eth0 192.168.14.2/24
100 ip netns exec cache2 ifconfig cache2-eth0 up
101 ip netns exec cache2 route add default gw 192.168.14.1
102 ip netns exec cache2 arp -s 192.168.14.1 00:00:00:00:02:02
103 ip netns exec cache2 echo 1 > /proc/sys/net/ipv4/ip_forward
104
105 ip netns exec head ifconfig head-eth0 down
106 ip netns exec head ifconfig head-eth0 hw ether 00:00:00:00:00:03
107 ip netns exec head ifconfig head-eth0 192.168.11.2/24
108 ip netns exec head ifconfig head-eth0 up
109 ip netns exec head route add default gw 192.168.11.1
110 ip netns exec head arp -s 192.168.11.1 00:00:00:00:04:02
111
112 ip netns exec branch ifconfig branch-eth0 down
113 ip netns exec branch ifconfig branch-eth0 hw ether 00:00:00:00:00:04
114 ip netns exec branch ifconfig branch-eth0 192.168.12.2/24
115 ip netns exec branch ifconfig branch-eth0 up
116 ip netns exec branch route add default gw 192.168.12.1
117 ip netns exec branch arp -s 192.168.12.1 00:00:00:00:03:04
118
119 echo "Configuring flow entries for topology discovery......"
120
121 sleep 5
122
123 ########## lldp ##########
124 dpctl unix:/tmp/sw1 flow-mod cmd=add,table=0,idle=0,hard=0,prio=65535 eth_type=0x88cc apply:output=ctrl:0xff
125 dpctl unix:/tmp/sw2 flow-mod cmd=add,table=0,idle=0,hard=0,prio=65535 eth_type=0x88cc apply:output=ctrl:0xff
126 dpctl unix:/tmp/sw3 flow-mod cmd=add,table=0,idle=0,hard=0,prio=65535 eth_type=0x88cc apply:output=ctrl:0xff
127 dpctl unix:/tmp/sw4 flow-mod cmd=add,table=0,idle=0,hard=0,prio=65535 eth_type=0x88cc apply:output=ctrl:0xff
128
129 echo "Creating network done."
130
131 exit 0
132
133
134
135 ip netns exec fw1 iptables -A FORWARD -i fw1-eth0 -j DROP
136 ip netns exec fw1 iptables -vxnL FORWARD
137
138 ip netns exec fw1 iptables -D FORWARD -i fw1-eth0 -j DROP
139 ip netns exec fw1 iptables -vxnL FORWARD