Scott Baker | 5042166 | 2016-06-27 22:09:48 -0700 | [diff] [blame] | 1 | --- |
| 2 | - hosts: switch_vbng |
| 3 | sudo: yes |
| 4 | vars: |
| 5 | controller_ip: "{{ hostvars['onos_vbng']['ansible_ssh_host'] }}" |
| 6 | controller_port: 6653 |
| 7 | ovs_dpid: "0000000000000001" |
| 8 | tags: |
| 9 | - vbng |
| 10 | tasks: |
| 11 | - name: Fix /etc/hosts |
| 12 | lineinfile: |
| 13 | dest=/etc/hosts |
| 14 | regexp="127.0.0.1 localhost" |
| 15 | line="127.0.0.1 localhost {{ ansible_hostname }}" |
| 16 | |
| 17 | - name: Install packages |
| 18 | apt: name={{ item }} |
| 19 | state=latest |
| 20 | update_cache=yes |
| 21 | with_items: |
| 22 | - openvswitch-switch |
| 23 | - python-netifaces |
| 24 | |
| 25 | - name: Create br-vbng |
| 26 | openvswitch_bridge: |
| 27 | bridge=br-vbng |
| 28 | state=present |
| 29 | |
| 30 | - name: Find wan_network interface |
| 31 | script: scripts/if_from_ip.py {{ wan_ip }} |
| 32 | register: wan_net |
| 33 | |
| 34 | - name: Find public_network interface |
| 35 | script: scripts/if_from_ip.py {{ public_ip }} |
| 36 | register: public_net |
| 37 | |
| 38 | - name: Hook up wan-network to br-vbng |
| 39 | openvswitch_port: |
| 40 | bridge=br-vbng |
| 41 | port={{ wan_net.stdout }} |
| 42 | state=present |
| 43 | |
| 44 | - name: Hook up public-network to OvS |
| 45 | openvswitch_port: |
| 46 | bridge=br-vbng |
| 47 | port={{ public_net.stdout }} |
| 48 | state=present |
| 49 | |
| 50 | - name: Remove IP address on public_network |
| 51 | command: /sbin/ifconfig {{ public_net.stdout }} 0.0.0.0 |
| 52 | when: public_net.stdout |
| 53 | |
| 54 | - name: Change datapath ID of bridge to match config file |
| 55 | command: /usr/bin/ovs-vsctl set bridge br-vbng other-config:datapath-id={{ ovs_dpid }} |
| 56 | |
| 57 | - name: Add controller to switch |
| 58 | command: /usr/bin/ovs-vsctl set-controller br-vbng tcp:{{ controller_ip }}:{{ controller_port }} |
| 59 | |
| 60 | - hosts: switch_volt |
| 61 | sudo: yes |
| 62 | vars: |
| 63 | controller_ip: "{{ hostvars['onos_volt']['ansible_ssh_host'] }}" |
| 64 | controller_port: 6653 |
| 65 | vcpe_lan_ip: "{{ hostvars['vcpe']['lan_ip'] }}" |
| 66 | tags: |
| 67 | - volt |
| 68 | tasks: |
| 69 | |
| 70 | - name: Fix /etc/hosts |
| 71 | lineinfile: |
| 72 | dest=/etc/hosts |
| 73 | regexp="127.0.0.1 localhost" |
| 74 | line="127.0.0.1 localhost {{ ansible_hostname }}" |
| 75 | |
| 76 | - name: Install packages |
| 77 | apt: name={{ item }} state=present update_cache=yes |
| 78 | with_items: |
| 79 | - git |
| 80 | - python-netifaces |
| 81 | - openvswitch-switch |
| 82 | |
| 83 | - name: Checkout the Mininet repo |
| 84 | git: repo=https://github.com/mininet/mininet.git |
| 85 | dest=/tmp/mininet |
| 86 | |
| 87 | - name: Install the CPqD switch using Mininet install script |
| 88 | shell: /tmp/mininet/util/install.sh -3f |
| 89 | creates=/usr/local/bin/ofdatapath |
| 90 | ignore_errors: true |
| 91 | |
| 92 | - name: Find subscriber_network interface |
| 93 | script: scripts/if_from_ip.py {{ subscriber_ip }} |
| 94 | register: subscriber_net |
| 95 | |
| 96 | - name: Create bridge br-sub |
| 97 | openvswitch_bridge: |
| 98 | bridge=br-sub |
| 99 | state=present |
| 100 | |
| 101 | - name: Add subscriber_net to br-sub |
| 102 | openvswitch_port: |
| 103 | bridge=br-sub |
| 104 | port={{ subscriber_net.stdout }} |
| 105 | state=present |
| 106 | |
| 107 | # The CPqD switch is expecting that packets coming from the client have |
| 108 | # VLAN tag 1. However Neutron's OvS configuration eats VLAN-tagged packets. |
| 109 | # So tag them with VLAN 1 here before sending to CPqD. |
| 110 | # |
| 111 | # Note that the VLAN tag is 0 in the real-world setup, but the CPqD switch |
| 112 | # seems to have a problem with these packets. |
| 113 | |
| 114 | # Using OvS to tag packets with VLAN ID 1 is not quite working for some reason. |
| 115 | # The packets from the client get tagged OK, but only the first packet from the |
| 116 | # VCPE gets its tag stripped off. Very weird. That's why we are using veth |
| 117 | # devices instead. |
| 118 | #- name: Add tag 1 to br-sub port |
| 119 | # shell: ovs-vsctl set port {{ subscriber_net.stdout }} tag=1 |
| 120 | |
| 121 | - name: Create a pair of veth devices |
| 122 | shell: ifconfig veth0 >> /dev/null || ip link add veth0 type veth peer name veth1 |
| 123 | |
| 124 | - name: Create veth0.1 |
| 125 | shell: ifconfig veth0.1 >> /dev/null || ip link add link veth0 name veth0.1 type vlan id 1 |
| 126 | |
| 127 | - name: Bring the interfaces up |
| 128 | shell: ip link set {{ item }} up |
| 129 | with_items: |
| 130 | - veth0 |
| 131 | - veth1 |
| 132 | - veth0.1 |
| 133 | |
| 134 | - name: Add veth0.1 to br-sub |
| 135 | openvswitch_port: |
| 136 | bridge=br-sub |
| 137 | port=veth0.1 |
| 138 | state=present |
| 139 | |
| 140 | - name: Create bridge br-lan |
| 141 | openvswitch_bridge: |
| 142 | bridge=br-lan |
| 143 | state=present |
| 144 | |
| 145 | - name: Create tunnel port on br-lan |
| 146 | openvswitch_port: |
| 147 | bridge=br-lan |
| 148 | port=gre0 |
| 149 | state=present |
| 150 | |
| 151 | - name: Set up GRE tunnel to vCPE |
| 152 | shell: ovs-vsctl set Interface gre0 type=gre options:remote_ip={{ vcpe_lan_ip }} |
| 153 | |
| 154 | - name: Check if br-lan has an IPv6 address |
| 155 | shell: ip addr show br-lan|grep inet6|awk '{print $2}' |
| 156 | register: ipv6 |
| 157 | |
| 158 | - name: Remove br-lan IPv6 address if present |
| 159 | shell: ifconfig br-lan inet6 del {{ ipv6.stdout }} |
| 160 | when: ipv6.stdout != "" |
| 161 | |
| 162 | - name: Check if veth1 has an IPv6 address |
| 163 | shell: ip addr show veth1|grep inet6|awk '{print $2}' |
| 164 | register: ipv6 |
| 165 | |
| 166 | - name: Remove veth1 IPv6 address if present |
| 167 | shell: ifconfig veth1 inet6 del {{ ipv6.stdout }} |
| 168 | when: ipv6.stdout != "" |
| 169 | |
| 170 | - name: Run the datapath |
| 171 | command: /usr/local/bin/ofdatapath -i veth1,br-lan punix:/tmp/s1 -d 000000000001 --no-slicing -D -P |
| 172 | creates=/usr/local/var/run/ofdatapath.pid |
| 173 | |
| 174 | - name: Run the control program |
| 175 | command: /usr/local/bin/ofprotocol unix:/tmp/s1 tcp:{{ controller_ip }}:{{ controller_port }} --fail=closed --listen=punix:/tmp/s1.listen -D -P |
| 176 | creates=/usr/local/var/run/ofprotocol.pid |
| 177 | |
| 178 | - hosts: client |
| 179 | sudo: yes |
| 180 | tags: |
| 181 | - client |
| 182 | tasks: |
| 183 | |
| 184 | - name: Fix /etc/hosts |
| 185 | lineinfile: |
| 186 | dest=/etc/hosts |
| 187 | regexp="127.0.0.1 localhost" |
| 188 | line="127.0.0.1 localhost {{ ansible_hostname }}" |
| 189 | |
| 190 | - name: Install packages |
| 191 | apt: name={{ item }} |
| 192 | state=latest |
| 193 | update_cache=yes |
| 194 | with_items: |
| 195 | - openvswitch-switch |
| 196 | - python-netifaces |
| 197 | |
| 198 | - name: Create br-sub |
| 199 | openvswitch_bridge: |
| 200 | bridge=br-sub |
| 201 | state=present |
| 202 | |
| 203 | - name: Find subscriber_network interface |
| 204 | script: scripts/if_from_ip.py {{ subscriber_ip }} |
| 205 | register: client_net |
| 206 | |
| 207 | - name: Hook up subscriber-network to OvS |
| 208 | openvswitch_port: |
| 209 | bridge=br-sub |
| 210 | port={{ client_net.stdout }} |
| 211 | state=present |
| 212 | |
| 213 | - name: Run some commands on br-sub |
| 214 | shell: "{{ item }}" |
| 215 | with_items: |
| 216 | - ifconfig br-sub 0.0.0.0 mtu 1400 up |
| 217 | - ethtool -K br-sub tso off |
| 218 | - ethtool -K br-sub tx off |
| 219 | |
| 220 | # Run dhclient on br-sub internal interface to issue DHCP request to vCPE |
| 221 | |
| 222 | # |
| 223 | # Need to set up a tunnel between vCPE and vOLT to keep VLAN-tagged |
| 224 | # packets from being swallowed by the network. |
| 225 | # |
| 226 | - hosts: vcpe |
| 227 | sudo: yes |
| 228 | vars: |
| 229 | volt_lan_ip: "{{ hostvars['switch_volt']['lan_ip'] }}" |
| 230 | tags: |
| 231 | - vcpe |
| 232 | tasks: |
| 233 | |
| 234 | - name: Install packages |
| 235 | apt: name={{ item }} |
| 236 | state=latest |
| 237 | update_cache=yes |
| 238 | with_items: |
| 239 | - openvswitch-switch |
| 240 | |
| 241 | - name: Create br-lan |
| 242 | openvswitch_bridge: |
| 243 | bridge=br-lan |
| 244 | state=present |
| 245 | |
| 246 | - name: Create tunnel port |
| 247 | openvswitch_port: |
| 248 | bridge=br-lan |
| 249 | port=gre0 |
| 250 | state=present |
| 251 | |
| 252 | - name: Configure GRE tunnel to vOLT switch |
| 253 | shell: ovs-vsctl set Interface gre0 type=gre options:remote_ip={{ volt_lan_ip }} |
| 254 | |
| 255 | - name: Restart vCPEs |
| 256 | script: scripts/restart-vcpes.sh |