├── LICENSE ├── README.md ├── case1.sh ├── case2.sh ├── case3.sh ├── case4.sh ├── case5.sh ├── lb.sh ├── ovn-port.sh └── ovn-router.sh /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Installing OVN from source 2 | ========================= 3 | 4 | * Clone the OVS repo. 5 | 6 | * Compile: 7 | 8 | ``` 9 | ./boot.sh 10 | ./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc --enable-ssl --with-linux=/lib/modules/`uname -r`/build 11 | make -j3 12 | make install 13 | ``` 14 | 15 | * Insert kernel modules 16 | 17 | ``` 18 | rmmod openvswitch 19 | modprobe libcrc32c 20 | modprobe nf_conntrack_ipv6 21 | modprobe nf_nat_ipv6 22 | modprobe gre 23 | insmod ./datapath/linux/openvswitch.ko 24 | insmod ./datapath/linux/vport-geneve.ko 25 | ``` 26 | 27 | * Copy a startup script 28 | 29 | ``` 30 | cp debian/openvswitch-switch.init /etc/init.d/openvswitch-switch 31 | ``` 32 | 33 | * Start Open vSwitch 34 | 35 | ``` 36 | /etc/init.d/openvswitch-switch start 37 | ``` 38 | 39 | * Start OVN central components 40 | 41 | ``` 42 | /usr/share/openvswitch/scripts/ovn-ctl restart_northd 43 | ``` 44 | 45 | Open up TCP ports. 46 | 47 | ``` 48 | ovn-nbctl set-connection ptcp:6641 49 | ovn-sbctl set-connection ptcp:6642 50 | ``` 51 | 52 | * One time setup on each host 53 | On each host, where you plan to spawn your containers, you will need to 54 | run the following command once. (You need to run it again if your OVS database 55 | gets cleared. It is harmless to run it again in any case.) 56 | 57 | $LOCAL_IP in the below command is the IP address via which other hosts 58 | can reach this host. This acts as your local tunnel endpoint. 59 | 60 | $ENCAP_TYPE is the type of tunnel that you would like to use for overlay 61 | networking. The options are "geneve" or "stt". (Please note that your 62 | kernel should have support for your chosen $ENCAP_TYPE. Both geneve 63 | and stt are part of the Open vSwitch kernel module that is compiled from this 64 | repo. If you use the Open vSwitch kernel module from upstream Linux, 65 | you will need a minumum kernel version of 3.18 for geneve. There is no stt 66 | support in upstream Linux. You can verify whether you have the support in your 67 | kernel by doing a "lsmod | grep $ENCAP_TYPE".) 68 | 69 | ``` 70 | ovs-vsctl set Open_vSwitch . external_ids:ovn-remote="tcp:$CENTRAL_IP:6642" \ 71 | external_ids:ovn-encap-ip=$LOCAL_IP external_ids:ovn-encap-type="$ENCAP_TYPE" 72 | ``` 73 | 74 | And finally, start the ovn-controller. (You need to run the below command 75 | on every boot) 76 | 77 | ``` 78 | /usr/share/openvswitch/scripts/ovn-ctl start_controller 79 | ``` 80 | 81 | Creating a simple topology with OVN using namespaces. 82 | ==================================================== 83 | 84 | * Create logical switches "foo" and "bar" 85 | 86 | ``` 87 | ovn-nbctl ls-add foo 88 | ovn-nbctl ls-add bar 89 | ``` 90 | 91 | * Create a router "router" 92 | 93 | ``` 94 | sh ovn-router.sh create-router router 95 | ``` 96 | 97 | * Connect switch "foo" to "router". The router port gets an ip address of 98 | 192.168.100.1/24 99 | 100 | ``` 101 | sh ovn-router.sh connect-switch router foo 192.168.100.1/24 102 | ``` 103 | 104 | * Connect switch "bar" to "router. The router port gets an ip address of 105 | 192.168.200.1/24 106 | 107 | ``` 108 | sh ovn-router.sh connect-switch router bar 192.168.200.1/24 109 | ``` 110 | 111 | * Create a namespace "foo1" and attach it as a logical port "foo1". 112 | You need to run this command on the machine you plan to spawn your namespace. 113 | If that machine is different than the machine where your northbound database 114 | runs, then you need to provide the --db option. e..g --db=tcp:10.33.75.67:6641 115 | 116 | ``` 117 | sh ovn-port.sh add-port foo foo1 192.168.100.2/24 192.168.100.1 118 | ``` 119 | 120 | * Create a namespace "bar1" and attach it as a logical port "bar1" 121 | 122 | ``` 123 | sh ovn-port.sh add-port --db=tcp:$IP:6641 bar bar1 192.168.200.2/24 192.168.200.1 124 | ``` 125 | 126 | * Test your pings 127 | 128 | ``` 129 | ip netns exec foo1 ping 192.168.200.2 130 | ``` 131 | -------------------------------------------------------------------------------- /case1.sh: -------------------------------------------------------------------------------- 1 | # 4 logical switches. 2 of them connected to one router. Another 2 to a 2 | # different one. The routers are connected via peer option. 3 | 4 | usage () { 5 | cat << EOF 6 | usage: case1.sh COMMAND 7 | 8 | Commands: 9 | host1 Run commands for host1. This host has northd running. 10 | host2 --db=tcp:IP:6641 Run commands for host2 11 | EOF 12 | } 13 | 14 | host1 () { 15 | sh ovn-router.sh create-router R1 16 | ovn-nbctl ls-add foo 17 | ovn-nbctl ls-add bar 18 | sh ovn-router.sh connect-switch R1 foo 192.168.1.1/24 19 | sh ovn-router.sh connect-switch R1 bar 192.168.2.1/24 20 | 21 | sh ovn-router.sh create-router R2 22 | ovn-nbctl ls-add alice 23 | ovn-nbctl ls-add bob 24 | sh ovn-router.sh connect-switch R2 alice 172.16.1.1/24 25 | sh ovn-router.sh connect-switch R2 bob 172.16.2.1/24 26 | 27 | sh ovn-router.sh connect-router R1 20.0.0.1/24 R2 20.0.0.2/24 28 | ovn-nbctl lr-route-add R1 0.0.0.0/0 20.0.0.2 29 | ovn-nbctl lr-route-add R2 0.0.0.0/0 20.0.0.1 30 | 31 | sh ovn-port.sh add-port foo foo1 192.168.1.2/24 192.168.1.1 32 | sh ovn-port.sh add-port alice alice1 172.16.1.2/24 172.16.1.1 33 | } 34 | 35 | host2 () { 36 | case $1 in 37 | --db=*) 38 | DB=`expr X"$1" : 'X[^=]*=\(.*\)'` 39 | shift 40 | ;; 41 | esac 42 | 43 | if [ -z "$DB" ]; then 44 | echo "DB not given" 45 | exit 1 46 | fi 47 | 48 | sh ovn-port.sh add-port --db=$DB bar bar1 192.168.2.2/24 192.168.2.1 49 | sh ovn-port.sh add-port --db=$DB bob bob1 172.16.2.2/24 172.16.2.1 50 | } 51 | 52 | 53 | case $1 in 54 | "host1") 55 | shift 56 | host1 57 | exit 0 58 | ;; 59 | "host2") 60 | shift 61 | host2 "$@" 62 | exit 0 63 | ;; 64 | -h | --help) 65 | usage 66 | exit 0 67 | ;; 68 | *) 69 | echo >&2 "$UTIL: unknown command \"$1\" (use --help for help)" 70 | exit 1 71 | ;; 72 | esac 73 | -------------------------------------------------------------------------------- /case2.sh: -------------------------------------------------------------------------------- 1 | # Logical network: 2 | # Three LRs - R1, R2 and R3 that are connected to each other via LS "join" 3 | # in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24) 4 | # connected to it. R2 has alice (172.16.1.0/24) and R3 has bob (10.32.1.0/24) 5 | # connected to it. 6 | 7 | usage () { 8 | cat << EOF 9 | usage: case1.sh COMMAND 10 | 11 | Commands: 12 | host1 Run commands for host1. This host has northd running. 13 | host2 --db=tcp:IP:6641 Run commands for host2 14 | EOF 15 | } 16 | 17 | host1 () { 18 | ovn-nbctl create Logical_Router name=R1 19 | ovn-nbctl create Logical_Router name=R2 20 | ovn-nbctl create Logical_Router name=R3 21 | 22 | ovn-nbctl ls-add foo 23 | ovn-nbctl ls-add alice 24 | ovn-nbctl ls-add bob 25 | ovn-nbctl ls-add join 26 | 27 | # Connect foo to R1 28 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=foo \ 29 | network=192.168.1.1/24 mac=\"00:00:01:01:02:03\" -- add Logical_Router R1 \ 30 | ports @lrp -- lsp-add foo rp-foo 31 | 32 | ovn-nbctl set Logical_switch_port rp-foo type=router options:router-port=foo \ 33 | addresses=\"00:00:01:01:02:03\" 34 | 35 | # Connect alice to R2 36 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=alice \ 37 | network=172.16.1.1/24 mac=\"00:00:02:01:02:03\" -- add Logical_Router R2 \ 38 | ports @lrp -- lsp-add alice rp-alice 39 | 40 | ovn-nbctl set Logical_switch_port rp-alice type=router options:router-port=alice \ 41 | addresses=\"00:00:02:01:02:03\" 42 | 43 | # Connect bob to R3 44 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=bob \ 45 | network=10.32.1.1/24 mac=\"00:00:03:01:02:03\" -- add Logical_Router R3 \ 46 | ports @lrp -- lsp-add bob rp-bob 47 | 48 | ovn-nbctl set Logical_switch_port rp-bob type=router options:router-port=bob \ 49 | addresses=\"00:00:03:01:02:03\" 50 | 51 | # Connect R1 to join 52 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=R1_join \ 53 | network=20.0.0.1/24 mac=\"00:00:04:01:02:03\" -- add Logical_Router R1 \ 54 | ports @lrp -- lsp-add join r1-join 55 | 56 | ovn-nbctl set Logical_switch_port r1-join type=router options:router-port=R1_join \ 57 | addresses='"00:00:04:01:02:03"' 58 | 59 | # Connect R2 to join 60 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=R2_join \ 61 | network=20.0.0.2/24 mac=\"00:00:04:01:02:04\" -- add Logical_Router R2 \ 62 | ports @lrp -- lsp-add join r2-join 63 | 64 | ovn-nbctl set Logical_switch_port r2-join type=router options:router-port=R2_join \ 65 | addresses='"00:00:04:01:02:04"' 66 | 67 | 68 | # Connect R3 to join 69 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=R3_join \ 70 | network=20.0.0.3/24 mac=\"00:00:04:01:02:05\" -- add Logical_Router R3 \ 71 | ports @lrp -- lsp-add join r3-join 72 | 73 | ovn-nbctl set Logical_switch_port r3-join type=router options:router-port=R3_join \ 74 | addresses='"00:00:04:01:02:05"' 75 | 76 | ovn-nbctl set Logical_Router R1 static_routes:172.16.1.0/24=20.0.0.2 77 | ovn-nbctl set logical_router R1 static_routes:10.32.1.0/24=20.0.0.3 78 | 79 | ovn-nbctl set logical_router R2 static_routes:192.168.1.0/24=20.0.0.1 80 | ovn-nbctl set logical_router R2 static_routes:10.32.1.0/24=20.0.0.3 81 | 82 | ovn-nbctl set logical_router R3 static_routes:192.168.1.0/24=20.0.0.1 83 | ovn-nbctl set logical_router R3 static_routes:172.16.1.0/24=20.0.0.2 84 | 85 | sh ovn-port.sh add-port foo foo1 192.168.1.2/24 192.168.1.1 86 | sh ovn-port.sh add-port alice alice1 172.16.1.2/24 172.16.1.1 87 | } 88 | 89 | host2 () { 90 | case $1 in 91 | --db=*) 92 | DB=`expr X"$1" : 'X[^=]*=\(.*\)'` 93 | shift 94 | ;; 95 | esac 96 | 97 | if [ -z "$DB" ]; then 98 | echo "DB not given" 99 | exit 1 100 | fi 101 | 102 | sh ovn-port.sh add-port --db=$DB bob bob1 10.32.1.2/24 10.32.1.1 103 | } 104 | 105 | 106 | case $1 in 107 | "host1") 108 | shift 109 | host1 110 | exit 0 111 | ;; 112 | "host2") 113 | shift 114 | host2 "$@" 115 | exit 0 116 | ;; 117 | -h | --help) 118 | usage 119 | exit 0 120 | ;; 121 | *) 122 | echo >&2 "$UTIL: unknown command \"$1\" (use --help for help)" 123 | exit 1 124 | ;; 125 | esac 126 | -------------------------------------------------------------------------------- /case3.sh: -------------------------------------------------------------------------------- 1 | # Logical network: 2 | # 2 LRs - R1, R2 that are connected to each other via LS "join" 3 | # in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24) 4 | # and bar (192.168.2.0/24) connected to it. R2 has alice (172.16.1.0/24) 5 | # R2 is a static (non-distributed) router. R1 and R2 are connected via switch "join" 6 | 7 | usage () { 8 | cat << EOF 9 | usage: case3.sh COMMAND 10 | 11 | Commands: 12 | host1 --chassis=$chassis Run commands for host1. This host has northd running. 13 | host2 --db=tcp:IP:6641 Run commands for host2 14 | EOF 15 | } 16 | 17 | host1 () { 18 | echo $1 19 | 20 | case $1 in 21 | --chassis=*) 22 | chassis=`expr X"$1" : 'X[^=]*=\(.*\)'` 23 | shift 24 | ;; 25 | esac 26 | 27 | if [ -z "$chassis" ]; then 28 | echo "chassis not given" 29 | exit 1 30 | fi 31 | 32 | ovn-nbctl create Logical_Router name=R1 33 | ovn-nbctl create Logical_Router name=R2 options:chassis=$chassis 34 | 35 | ovn-nbctl ls-add foo 36 | ovn-nbctl ls-add bar 37 | ovn-nbctl ls-add alice 38 | ovn-nbctl ls-add join 39 | 40 | # Connect foo to R1 41 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=foo \ 42 | network=192.168.1.1/24 mac=\"00:00:01:01:02:03\" -- add Logical_Router R1 \ 43 | ports @lrp -- lsp-add foo rp-foo 44 | 45 | ovn-nbctl set Logical_switch_port rp-foo type=router options:router-port=foo \ 46 | addresses=\"00:00:01:01:02:03\" 47 | 48 | # Connect bar to R1 49 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=bar \ 50 | network=192.168.2.1/24 mac=\"00:00:01:01:02:04\" -- add Logical_Router R1 \ 51 | ports @lrp -- lsp-add bar rp-bar 52 | 53 | ovn-nbctl set Logical_switch_port rp-bar type=router options:router-port=bar \ 54 | addresses=\"00:00:01:01:02:04\" 55 | 56 | # Connect alice to R2 57 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=alice \ 58 | network=172.16.1.1/24 mac=\"00:00:02:01:02:03\" -- add Logical_Router R2 \ 59 | ports @lrp -- lsp-add alice rp-alice 60 | 61 | ovn-nbctl set Logical_switch_port rp-alice type=router options:router-port=alice \ 62 | addresses=\"00:00:02:01:02:03\" 63 | 64 | # Connect R1 to join 65 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=R1_join \ 66 | network=20.0.0.1/24 mac=\"00:00:04:01:02:03\" -- add Logical_Router R1 \ 67 | ports @lrp -- lsp-add join r1-join 68 | 69 | ovn-nbctl set Logical_switch_port r1-join type=router options:router-port=R1_join \ 70 | addresses='"00:00:04:01:02:03"' 71 | 72 | # Connect R2 to join 73 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=R2_join \ 74 | network=20.0.0.2/24 mac=\"00:00:04:01:02:04\" -- add Logical_Router R2 \ 75 | ports @lrp -- lsp-add join r2-join 76 | 77 | ovn-nbctl set Logical_switch_port r2-join type=router options:router-port=R2_join \ 78 | addresses='"00:00:04:01:02:04"' 79 | 80 | 81 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ 82 | ip_prefix=172.16.1.0/24 nexthop=20.0.0.2 -- add Logical_Router \ 83 | R1 static_routes @lrt 84 | 85 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ 86 | ip_prefix=192.168.1.0/24 nexthop=20.0.0.1 -- add Logical_Router \ 87 | R2 static_routes @lrt 88 | 89 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ 90 | ip_prefix=192.168.2.0/24 nexthop=20.0.0.1 -- add Logical_Router \ 91 | R2 static_routes @lrt 92 | 93 | sh ovn-port.sh add-port foo foo1 192.168.1.2/24 192.168.1.1 94 | sh ovn-port.sh add-port bar bar1 192.168.2.2/24 192.168.2.1 95 | 96 | } 97 | 98 | host2 () { 99 | case $1 in 100 | --db=*) 101 | DB=`expr X"$1" : 'X[^=]*=\(.*\)'` 102 | shift 103 | ;; 104 | esac 105 | 106 | if [ -z "$DB" ]; then 107 | echo "DB not given" 108 | exit 1 109 | fi 110 | 111 | sh ovn-port.sh add-port --db=$DB alice alice1 172.16.1.2/24 172.16.1.1 112 | } 113 | 114 | 115 | case $1 in 116 | "host1") 117 | shift 118 | host1 "$*" 119 | exit 0 120 | ;; 121 | "host2") 122 | shift 123 | host2 "$@" 124 | exit 0 125 | ;; 126 | -h | --help) 127 | usage 128 | exit 0 129 | ;; 130 | *) 131 | echo >&2 "$UTIL: unknown command \"$1\" (use --help for help)" 132 | exit 1 133 | ;; 134 | esac 135 | -------------------------------------------------------------------------------- /case4.sh: -------------------------------------------------------------------------------- 1 | # Logical network: 2 | # 2 LRs - R1, R2 that are connected to each other via LS "join" 3 | # in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24) 4 | # and bar (192.168.2.0/24) connected to it. R2 has alice (172.16.1.0/24) 5 | # R2 is a static (non-distributed) router. R1 and R2 are connected via switch "join" 6 | 7 | # Do DNAT north-south 8 | 9 | usage () { 10 | cat << EOF 11 | usage: case3.sh COMMAND 12 | 13 | Commands: 14 | host1 --chassis=$chassis Run commands for host1. This host has northd running. 15 | host2 --db=tcp:IP:6641 Run commands for host2 16 | EOF 17 | } 18 | 19 | host1 () { 20 | echo $1 21 | 22 | case $1 in 23 | --chassis=*) 24 | chassis=`expr X"$1" : 'X[^=]*=\(.*\)'` 25 | shift 26 | ;; 27 | esac 28 | 29 | if [ -z "$chassis" ]; then 30 | echo "chassis not given" 31 | exit 1 32 | fi 33 | 34 | ovn-nbctl create Logical_Router name=R1 35 | ovn-nbctl create Logical_Router name=R2 options:chassis=$chassis 36 | 37 | ovn-nbctl ls-add foo 38 | ovn-nbctl ls-add bar 39 | ovn-nbctl ls-add alice 40 | ovn-nbctl ls-add join 41 | 42 | # Connect foo to R1 43 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=foo \ 44 | network=192.168.1.1/24 mac=\"00:00:01:01:02:03\" -- add Logical_Router R1 \ 45 | ports @lrp -- lsp-add foo rp-foo 46 | 47 | ovn-nbctl set Logical_switch_port rp-foo type=router options:router-port=foo \ 48 | addresses=\"00:00:01:01:02:03\" 49 | 50 | # Connect bar to R1 51 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=bar \ 52 | network=192.168.2.1/24 mac=\"00:00:01:01:02:04\" -- add Logical_Router R1 \ 53 | ports @lrp -- lsp-add bar rp-bar 54 | 55 | ovn-nbctl set Logical_switch_port rp-bar type=router options:router-port=bar \ 56 | addresses=\"00:00:01:01:02:04\" 57 | 58 | # Connect alice to R2 59 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=alice \ 60 | network=172.16.1.1/24 mac=\"00:00:02:01:02:03\" -- add Logical_Router R2 \ 61 | ports @lrp -- lsp-add alice rp-alice 62 | 63 | ovn-nbctl set Logical_switch_port rp-alice type=router options:router-port=alice \ 64 | addresses=\"00:00:02:01:02:03\" 65 | 66 | # Connect R1 to join 67 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=R1_join \ 68 | network=20.0.0.1/24 mac=\"00:00:04:01:02:03\" -- add Logical_Router R1 \ 69 | ports @lrp -- lsp-add join r1-join 70 | 71 | ovn-nbctl set Logical_switch_port r1-join type=router options:router-port=R1_join \ 72 | addresses='"00:00:04:01:02:03"' 73 | 74 | # Connect R2 to join 75 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=R2_join \ 76 | network=20.0.0.2/24 mac=\"00:00:04:01:02:04\" -- add Logical_Router R2 \ 77 | ports @lrp -- lsp-add join r2-join 78 | 79 | ovn-nbctl set Logical_switch_port r2-join type=router options:router-port=R2_join \ 80 | addresses='"00:00:04:01:02:04"' 81 | 82 | 83 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ 84 | ip_prefix=172.16.1.0/24 nexthop=20.0.0.2 -- add Logical_Router \ 85 | R1 static_routes @lrt 86 | 87 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ 88 | ip_prefix=192.168.1.0/24 nexthop=20.0.0.1 -- add Logical_Router \ 89 | R2 static_routes @lrt 90 | 91 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ 92 | ip_prefix=192.168.2.0/24 nexthop=20.0.0.1 -- add Logical_Router \ 93 | R2 static_routes @lrt 94 | 95 | sh ovn-port.sh add-port foo foo1 192.168.1.2/24 192.168.1.1 96 | sh ovn-port.sh add-port bar bar1 192.168.2.2/24 192.168.2.1 97 | 98 | ovn-nbctl -- --id=@nat create nat type="dnat" logical_ip=192.168.1.2 \ 99 | external_ip=30.0.0.2 -- add logical_router R2 nat @nat 100 | 101 | } 102 | 103 | host2 () { 104 | case $1 in 105 | --db=*) 106 | DB=`expr X"$1" : 'X[^=]*=\(.*\)'` 107 | shift 108 | ;; 109 | esac 110 | 111 | if [ -z "$DB" ]; then 112 | echo "DB not given" 113 | exit 1 114 | fi 115 | 116 | sh ovn-port.sh add-port --db=$DB alice alice1 172.16.1.2/24 172.16.1.1 117 | } 118 | 119 | 120 | case $1 in 121 | "host1") 122 | shift 123 | host1 "$*" 124 | exit 0 125 | ;; 126 | "host2") 127 | shift 128 | host2 "$@" 129 | exit 0 130 | ;; 131 | -h | --help) 132 | usage 133 | exit 0 134 | ;; 135 | *) 136 | echo >&2 "$UTIL: unknown command \"$1\" (use --help for help)" 137 | exit 1 138 | ;; 139 | esac 140 | -------------------------------------------------------------------------------- /case5.sh: -------------------------------------------------------------------------------- 1 | # Logical network: 2 | # 2 LRs - R1, R2 that are connected to each other via LS "join" 3 | # in 20.0.0.0/24 network. R1 has switchess foo (192.168.1.0/24) 4 | # and bar (192.168.2.0/24) connected to it. R2 has alice (172.16.1.0/24) 5 | # R2 is a static (non-distributed) router. R1 and R2 are connected via switch "join" 6 | 7 | # Do SNAT south-north 8 | 9 | usage () { 10 | cat << EOF 11 | usage: case3.sh COMMAND 12 | 13 | Commands: 14 | host1 --chassis=$chassis Run commands for host1. This host has northd running. 15 | host2 --db=tcp:IP:6640 Run commands for host2 16 | EOF 17 | } 18 | 19 | host1 () { 20 | echo $1 21 | 22 | case $1 in 23 | --chassis=*) 24 | chassis=`expr X"$1" : 'X[^=]*=\(.*\)'` 25 | shift 26 | ;; 27 | esac 28 | 29 | if [ -z "$chassis" ]; then 30 | echo "chassis not given" 31 | exit 1 32 | fi 33 | 34 | ovn-nbctl create Logical_Router name=R1 35 | ovn-nbctl create Logical_Router name=R2 options:chassis=$chassis 36 | 37 | ovn-nbctl ls-add foo 38 | ovn-nbctl ls-add bar 39 | ovn-nbctl ls-add alice 40 | ovn-nbctl ls-add join 41 | 42 | # Connect foo to R1 43 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=foo \ 44 | network=192.168.1.1/24 mac=\"00:00:01:01:02:03\" -- add Logical_Router R1 \ 45 | ports @lrp -- lsp-add foo rp-foo 46 | 47 | ovn-nbctl set Logical_switch_port rp-foo type=router options:router-port=foo \ 48 | addresses=\"00:00:01:01:02:03\" 49 | 50 | # Connect bar to R1 51 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=bar \ 52 | network=192.168.2.1/24 mac=\"00:00:01:01:02:04\" -- add Logical_Router R1 \ 53 | ports @lrp -- lsp-add bar rp-bar 54 | 55 | ovn-nbctl set Logical_switch_port rp-bar type=router options:router-port=bar \ 56 | addresses=\"00:00:01:01:02:04\" 57 | 58 | # Connect alice to R2 59 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=alice \ 60 | network=172.16.1.1/24 mac=\"00:00:02:01:02:03\" -- add Logical_Router R2 \ 61 | ports @lrp -- lsp-add alice rp-alice 62 | 63 | ovn-nbctl set Logical_switch_port rp-alice type=router options:router-port=alice \ 64 | addresses=\"00:00:02:01:02:03\" 65 | 66 | # Connect R1 to join 67 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=R1_join \ 68 | network=20.0.0.1/24 mac=\"00:00:04:01:02:03\" -- add Logical_Router R1 \ 69 | ports @lrp -- lsp-add join r1-join 70 | 71 | ovn-nbctl set Logical_switch_port r1-join type=router options:router-port=R1_join \ 72 | addresses='"00:00:04:01:02:03"' 73 | 74 | # Connect R2 to join 75 | ovn-nbctl -- --id=@lrp create Logical_Router_port name=R2_join \ 76 | network=20.0.0.2/24 mac=\"00:00:04:01:02:04\" -- add Logical_Router R2 \ 77 | ports @lrp -- lsp-add join r2-join 78 | 79 | ovn-nbctl set Logical_switch_port r2-join type=router options:router-port=R2_join \ 80 | addresses='"00:00:04:01:02:04"' 81 | 82 | 83 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ 84 | ip_prefix=172.16.1.0/24 nexthop=20.0.0.2 -- add Logical_Router \ 85 | R1 static_routes @lrt 86 | 87 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ 88 | ip_prefix=192.168.1.0/24 nexthop=20.0.0.1 -- add Logical_Router \ 89 | R2 static_routes @lrt 90 | 91 | ovn-nbctl -- --id=@lrt create Logical_Router_Static_Route \ 92 | ip_prefix=192.168.2.0/24 nexthop=20.0.0.1 -- add Logical_Router \ 93 | R2 static_routes @lrt 94 | 95 | sh ovn-port.sh add-port foo foo1 192.168.1.2/24 192.168.1.1 96 | sh ovn-port.sh add-port bar bar1 192.168.2.2/24 192.168.2.1 97 | 98 | # bar1 can ping alice1 and alice1 receives traffic from 30.0.0.1 99 | ovn-nbctl -- --id=@nat create nat type="snat" logical_ip=192.168.2.2 \ 100 | external_ip=30.0.0.1 -- add logical_router R2 nat @nat 101 | 102 | } 103 | 104 | host2 () { 105 | case $1 in 106 | --db=*) 107 | DB=`expr X"$1" : 'X[^=]*=\(.*\)'` 108 | shift 109 | ;; 110 | esac 111 | 112 | if [ -z "$DB" ]; then 113 | echo "DB not given" 114 | exit 1 115 | fi 116 | 117 | sh ovn-port.sh add-port --db=$DB alice alice1 172.16.1.2/24 172.16.1.1 118 | } 119 | 120 | 121 | case $1 in 122 | "host1") 123 | shift 124 | host1 "$*" 125 | exit 0 126 | ;; 127 | "host2") 128 | shift 129 | host2 "$@" 130 | exit 0 131 | ;; 132 | -h | --help) 133 | usage 134 | exit 0 135 | ;; 136 | *) 137 | echo >&2 "$UTIL: unknown command \"$1\" (use --help for help)" 138 | exit 1 139 | ;; 140 | esac 141 | -------------------------------------------------------------------------------- /lb.sh: -------------------------------------------------------------------------------- 1 | # 2 logical switches "foo" (192.168.1.0/24) and "bar" (172.16.1.0/24) 2 | # connected to a router R1. 3 | # foo has foo1, foo2, foo3 spread on 2 machines. 4 | # bar has bar1, bar2, bar3 spread on 2 machines. 5 | # 6 | # Loadbalancer rules in 30.0.0.0/24 network. 7 | 8 | usage () { 9 | cat << EOF 10 | usage: case1.sh COMMAND 11 | 12 | Commands: 13 | host1 Run commands for host1. This host has northd running. 14 | host2 --db=tcp:IP:6640 Run commands for host2 15 | EOF 16 | } 17 | 18 | host1 () { 19 | sh ovn-router.sh create-router R1 20 | ovn-nbctl ls-add foo 21 | ovn-nbctl ls-add bar 22 | sh ovn-router.sh connect-switch R1 foo 192.168.1.1/24 23 | sh ovn-router.sh connect-switch R1 bar 172.16.1.1/24 24 | 25 | sh ovn-port.sh add-port foo foo1 192.168.1.2/24 192.168.1.1 26 | sh ovn-port.sh add-port foo foo2 192.168.1.3/24 192.168.1.1 27 | 28 | sh ovn-port.sh add-port bar bar1 172.16.1.2/24 172.16.1.1 29 | } 30 | 31 | host2 () { 32 | case $1 in 33 | --db=*) 34 | DB=`expr X"$1" : 'X[^=]*=\(.*\)'` 35 | shift 36 | ;; 37 | esac 38 | 39 | if [ -z "$DB" ]; then 40 | echo "DB not given" 41 | exit 1 42 | fi 43 | 44 | sh ovn-port.sh add-port --db=$DB foo foo3 192.168.1.4/24 192.168.1.1 45 | sh ovn-port.sh add-port --db=$DB bar bar2 172.16.1.3/24 172.16.1.1 46 | sh ovn-port.sh add-port --db=$DB bar bar3 172.16.1.4/24 172.16.1.1 47 | } 48 | 49 | 50 | case $1 in 51 | "host1") 52 | shift 53 | host1 54 | exit 0 55 | ;; 56 | "host2") 57 | shift 58 | host2 "$@" 59 | exit 0 60 | ;; 61 | -h | --help) 62 | usage 63 | exit 0 64 | ;; 65 | *) 66 | echo >&2 "$UTIL: unknown command \"$1\" (use --help for help)" 67 | exit 1 68 | ;; 69 | esac 70 | -------------------------------------------------------------------------------- /ovn-port.sh: -------------------------------------------------------------------------------- 1 | usage () { 2 | cat << EOF 3 | usage: ovn-port COMMAND 4 | 5 | These commands need to be run on the host where you plan 6 | to spawn your namespaces. 7 | 8 | Commands: 9 | add-port [--db=tcp:IP:6640] LSWITCH LPORT_NAME IP/MASK GATEWAY 10 | del-port [--db=tcp:IP:6640] LPORT_NAME 11 | EOF 12 | } 13 | 14 | add_port () { 15 | 16 | case $1 in 17 | --db=*) 18 | DB=`expr X"$1" : 'X[^=]*=\(.*\)'` 19 | shift 20 | ;; 21 | esac 22 | 23 | LSWITCH=$1 24 | if [ -z "$LSWITCH" ]; then 25 | echo "No switch name given" >& 2 26 | exit 1 27 | fi 28 | 29 | if [ -n "$DB" ]; then 30 | exists=`ovn-nbctl --db=$DB get logical_switch $LSWITCH name` 31 | else 32 | exists=`ovn-nbctl get logical_switch $LSWITCH name` 33 | fi 34 | 35 | if [ -z "$exists" ]; then 36 | echo "$LSWITCH switch does not exist in NB" 37 | exit 1 38 | fi 39 | 40 | LPORT_NAME=$2 41 | if [ -z "$LPORT_NAME" ]; then 42 | echo "No lport name given" >& 2 43 | exit 1 44 | fi 45 | 46 | IP=$3 47 | if [ -z "$IP" ]; then 48 | echo "No IP given" >& 2 49 | exit 1 50 | fi 51 | 52 | GATEWAY=$4 53 | if [ -z "$GATEWAY" ]; then 54 | echo "No GATEWAY given" >& 2 55 | exit 1 56 | fi 57 | 58 | x=`shuf -i 1-99 -n 1` 59 | y=`shuf -i 1-99 -n 1` 60 | z=`shuf -i 1-99 -n 1` 61 | 62 | MAC="00:02:03:$x:$y:$z" 63 | 64 | if [ -n "$DB" ]; then 65 | ovn-nbctl --db=$DB lsp-add $LSWITCH $LPORT_NAME 66 | else 67 | ovn-nbctl lsp-add $LSWITCH $LPORT_NAME 68 | fi 69 | 70 | IP_ONLY=`echo $IP | awk -F \/ '{print $1}'` 71 | if [ -n "$DB" ]; then 72 | ovn-nbctl --db=$DB lsp-set-addresses $LPORT_NAME "$MAC $IP_ONLY" 73 | else 74 | ovn-nbctl lsp-set-addresses $LPORT_NAME "$MAC $IP_ONLY" 75 | fi 76 | 77 | ip netns add $LPORT_NAME 78 | ip link add "${LPORT_NAME}_l" type veth peer name "${LPORT_NAME}_c" 79 | 80 | BRIDGE="br-int" 81 | if ovs-vsctl --may-exist add-port "$BRIDGE" "${LPORT_NAME}_l" \ 82 | -- set interface "${LPORT_NAME}_l" \ 83 | external_ids:iface-id="$LPORT_NAME"; then : ; else 84 | echo >&2 "$UTIL: Failed to add "${LPORT_NAME}_l" port to bridge $BRIDGE" 85 | ip link delete "${LPORT_NAME}_l" 86 | exit 1 87 | fi 88 | 89 | ip link set "${LPORT_NAME}_l" up 90 | ip link set "${LPORT_NAME}_c" netns "${LPORT_NAME}" 91 | ip netns exec "${LPORT_NAME}" ip link set dev "${LPORT_NAME}_c" name eth0 92 | ip netns exec "${LPORT_NAME}" ip link set eth0 up 93 | ip netns exec "${LPORT_NAME}" ip link set dev eth0 mtu 1440 94 | 95 | ip netns exec "${LPORT_NAME}" ip addr add $IP dev eth0 96 | ip netns exec "${LPORT_NAME}" ip link set dev eth0 address "$MAC" 97 | ip netns exec "${LPORT_NAME}" ip route add default via "$GATEWAY" 98 | 99 | 100 | } 101 | 102 | del_port () { 103 | 104 | case $1 in 105 | --db=*) 106 | DB=`expr X"$1" : 'X[^=]*=\(.*\)'` 107 | shift 108 | ;; 109 | esac 110 | 111 | LPORT_NAME=$1 112 | if [ -z "$LPORT_NAME" ]; then 113 | echo "No lport name given" >& 2 114 | exit 1 115 | fi 116 | 117 | if [ -n "$DB" ]; then 118 | ovn-nbctl --db=$DB lport-del $LPORT_NAME 119 | else 120 | ovn-nbctl lport-del $LPORT_NAME 121 | fi 122 | 123 | ip netns delete $LPORT_NAME 124 | ovs-vsctl del-port ${LPORT_NAME}_l 125 | ip link delete ${LPORT_NAME}_l 126 | 127 | } 128 | 129 | case $1 in 130 | "add-port") 131 | shift 132 | add_port "$@" 133 | exit 0 134 | ;; 135 | "del-port") 136 | shift 137 | del_port "$@" 138 | exit 0 139 | ;; 140 | -h | --help) 141 | usage 142 | exit 0 143 | ;; 144 | *) 145 | echo >&2 "$UTIL: unknown command \"$1\" (use --help for help)" 146 | exit 1 147 | ;; 148 | esac 149 | -------------------------------------------------------------------------------- /ovn-router.sh: -------------------------------------------------------------------------------- 1 | usage () { 2 | cat << EOF 3 | usage: ovn-router COMMAND 4 | 5 | Commands: 6 | create-router NAME 7 | 8 | connect-switch ROUTER SWITCH SUBNET 9 | disconnect-switch ROUTER SWITCH 10 | 11 | connect-router ROUTER1 ROUTER1_SUBNET ROUTER2 ROUTER2_SUBNET 12 | disconnect-router ROUTER1 ROUTER2 13 | EOF 14 | } 15 | 16 | create_router () { 17 | NAME=$1 18 | if [ -z "$NAME" ]; then 19 | echo "No router name given" >& 2 20 | exit 1 21 | fi 22 | 23 | ovn-nbctl create Logical_Router name=$NAME 24 | } 25 | 26 | connect_switch () { 27 | ROUTER_NAME="$1" 28 | SWITCH_NAME="$2" 29 | SUBNET="$3" 30 | 31 | if [ -z "$ROUTER_NAME" ] || [ -z "$SWITCH_NAME" ]; then 32 | echo >&2 "router name or switch name not given" 33 | exit 1 34 | fi 35 | 36 | if [ -z "$SUBNET" ]; then 37 | echo >&2 "subnet not given" 38 | exit 1 39 | fi 40 | 41 | x=`shuf -i 1-99 -n 1` 42 | y=`shuf -i 1-99 -n 1` 43 | z=`shuf -i 1-99 -n 1` 44 | 45 | LRP_MAC="00:00:00:$x:$y:$z" 46 | 47 | lrp_uuid=`ovn-nbctl -- --id=@lrp create Logical_Router_port name=$SWITCH_NAME \ 48 | network=$SUBNET mac=\"$LRP_MAC\" -- add Logical_Router $ROUTER_NAME ports @lrp \ 49 | -- lsp-add $SWITCH_NAME rp-"$SWITCH_NAME"` 50 | 51 | ovn-nbctl set Logical_switch_port rp-"$SWITCH_NAME" \ 52 | type=router options:router-port=$SWITCH_NAME addresses=\"$LRP_MAC\" 53 | 54 | } 55 | 56 | disconnect_switch () { 57 | 58 | ROUTER_NAME="$1" 59 | SWITCH_NAME="$2" 60 | 61 | if [ -z "$ROUTER_NAME" ] || [ -z "$SWITCH_NAME" ]; then 62 | echo >&2 "router name or switch name not given" 63 | exit 1 64 | fi 65 | 66 | lrp1_uuid=`ovn-nbctl --data=bare --no-heading --columns=_uuid find logical_router_port name=$SWITCH_NAME` 67 | 68 | if [ -z "$lrp1_uuid" ]; then 69 | echo "no switch with name $SWITCH_NAME connected to $ROUTER_NAME" 70 | exit 1 71 | fi 72 | 73 | ovn-nbctl remove Logical_Router $ROUTER_NAME ports $lrp1_uuid -- destroy logical_router_port $lrp1_uuid 74 | ovn-nbctl lport-del "rp-$SWITCH_NAME" 75 | } 76 | 77 | connect_router () { 78 | ROUTER1="$1" 79 | ROUTER1_SUBNET="$2" 80 | ROUTER2="$3" 81 | ROUTER2_SUBNET="$4" 82 | 83 | if [ -z "$ROUTER1" ] || [ -z "$ROUTER1_SUBNET" ]; then 84 | echo >&2 "router1 name or subnet not given" 85 | exit 1 86 | fi 87 | 88 | if [ -z "$ROUTER2" ] || [ -z "$ROUTER2_SUBNET" ]; then 89 | echo >&2 "router2 name or subnet not given" 90 | exit 1 91 | fi 92 | 93 | x=`shuf -i 1-99 -n 1` 94 | y=`shuf -i 1-99 -n 1` 95 | z=`shuf -i 1-99 -n 1` 96 | 97 | ROUTER1_MAC="00:00:00:$x:$y:$z" 98 | 99 | lrp1_uuid=`ovn-nbctl -- --id=@lrp create Logical_Router_port \ 100 | name=${ROUTER1}_$ROUTER2 \ 101 | network=$ROUTER1_SUBNET mac=\"$ROUTER1_MAC\" -- \ 102 | add Logical_Router $ROUTER1 ports @lrp` 103 | 104 | x=`shuf -i 1-99 -n 1` 105 | y=`shuf -i 1-99 -n 1` 106 | z=`shuf -i 1-99 -n 1` 107 | 108 | ROUTER2_MAC="00:00:00:$x:$y:$z" 109 | 110 | lrp2_uuid=`ovn-nbctl -- --id=@lrp create Logical_Router_port \ 111 | name=${ROUTER2}_$ROUTER1 \ 112 | network=$ROUTER2_SUBNET mac=\"$ROUTER2_MAC\" -- \ 113 | add Logical_Router $ROUTER2 ports @lrp` 114 | 115 | ovn-nbctl set logical_router_port $lrp1_uuid peer=${ROUTER2}_$ROUTER1 116 | ovn-nbctl set logical_router_port $lrp2_uuid peer=${ROUTER1}_$ROUTER2 117 | } 118 | 119 | disconnect_router () { 120 | ROUTER1="$1" 121 | ROUTER2="$2" 122 | 123 | if [ -z "$ROUTER1" ] || [ -z "$ROUTER2" ]; then 124 | echo >&2 "router1 and router2 name not given" 125 | exit 1 126 | fi 127 | 128 | lrp1_uuid=`ovn-nbctl --data=bare --no-heading --columns=_uuid find logical_router_port name=${ROUTER1}_$ROUTER2` 129 | lrp2_uuid=`ovn-nbctl --data=bare --no-heading --columns=_uuid find logical_router_port name=${ROUTER2}_$ROUTER1` 130 | 131 | if [ -z "$lrp1_uuid" ] || [ -z $lrp2_uuid ]; then 132 | echo >&2 "failed to fetch uuids of router ports from names" 133 | exit 1 134 | fi 135 | 136 | ovn-nbctl remove logical_router "$ROUTER1" ports $lrp1_uuid -- destroy logical_router_port $lrp1_uuid 137 | ovn-nbctl remove logical_router "$ROUTER2" ports $lrp2_uuid -- destroy logical_router_port $lrp2_uuid 138 | 139 | } 140 | 141 | 142 | case $1 in 143 | "create-router") 144 | shift 145 | create_router "$@" 146 | exit 0 147 | ;; 148 | "connect-switch") 149 | shift 150 | connect_switch "$@" 151 | exit 0 152 | ;; 153 | "disconnect-switch") 154 | shift 155 | disconnect_switch "$@" 156 | exit 0 157 | ;; 158 | "connect-router") 159 | shift 160 | connect_router "$@" 161 | exit 0 162 | ;; 163 | "disconnect-router") 164 | shift 165 | disconnect_router "$@" 166 | exit 0 167 | ;; 168 | -h | --help) 169 | usage 170 | exit 0 171 | ;; 172 | *) 173 | echo >&2 "$UTIL: unknown command \"$1\" (use --help for help)" 174 | exit 1 175 | ;; 176 | esac 177 | --------------------------------------------------------------------------------