Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Creates a spine-leaf fabric with large number of hosts using null providers |
| 4 | # |
| 5 | # Default setup as follows: |
| 6 | # 2 spines, can potentially be few more |
| 7 | # 12 leaves in total |
| 8 | # 2 leaf pair |
| 9 | # 8 non-paired |
| 10 | # Host per leaf up to 1K |
| 11 | # |
| 12 | # ----------------------------------------------------------------------------- |
| 13 | |
| 14 | function usage { |
| 15 | echo "usage: $(basename $0) [options] [onos-ip]" |
| 16 | echo "" |
| 17 | echo "Options:" |
| 18 | echo " -s spines" |
| 19 | echo " -l spineLinks" |
| 20 | echo " -S serviceHosts" |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 21 | echo " -G gateways" |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 22 | echo " -a accessLeaves" |
| 23 | echo " -A accessHosts" |
| 24 | exit 1 |
| 25 | } |
| 26 | |
| 27 | spines=2 |
| 28 | spineLinks=2 |
| 29 | serviceLeafGroups="A B" |
| 30 | serviceHosts=10 |
| 31 | accessLeaves=8 |
| 32 | accessHosts=100 |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 33 | gateways=2 |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 34 | |
| 35 | # Scan arguments for user/password or other options... |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 36 | while getopts s:l:a:A:S:G:?h o; do |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 37 | case "$o" in |
| 38 | s) spines=$OPTARG;; |
| 39 | l) spineLinks=$OPTARG;; |
| 40 | a) accessLeaves=$OPTARG;; |
| 41 | A) accessHosts=$OPTARG;; |
| 42 | S) serviceHosts=$OPTARG;; |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 43 | G) gateways=$OPTARG;; |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 44 | *) usage $0;; |
| 45 | esac |
| 46 | done |
| 47 | |
| 48 | spinePorts=48 |
| 49 | let leafPorts=serviceHosts+8 # derive service ports from service hosts |
| 50 | let accessPorts=accessHosts+8 # derive access ports from access hosts |
| 51 | |
| 52 | let OPC=$OPTIND-1 |
| 53 | shift $OPC |
| 54 | |
| 55 | # config |
| 56 | node=${1:-$OCI} |
| 57 | |
| 58 | |
| 59 | # Create the script of ONOS commands first and then execute it all at once. |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 60 | export CMDS="/tmp/access-onos.cmds" |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 61 | rm $CMDS |
| 62 | |
| 63 | function sim { |
| 64 | echo "$@" >> $CMDS |
| 65 | } |
| 66 | |
| 67 | # Create spines |
| 68 | for spine in $(seq 1 $spines); do |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 69 | sim "null-create-device switch Spine-${spine} ${spinePorts}" |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 70 | done |
| 71 | |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 72 | gwIps="" |
| 73 | |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 74 | # Create 2 leaf pairs with dual links to the spines and a link between the pair |
| 75 | for pair in $serviceLeafGroups; do |
Thomas Vachuska | c67a991 | 2018-03-06 14:37:45 -0800 | [diff] [blame] | 76 | [ $pair = A ] && l1=1 || l1=3 |
| 77 | [ $pair = A ] && l2=2 || l2=4 |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 78 | sim "null-create-device switch Leaf-${pair}1 ${leafPorts}" |
| 79 | sim "null-create-device switch Leaf-${pair}2 ${leafPorts}" |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 80 | sim "null-create-link direct Leaf-${pair}1 Leaf-${pair}2" |
| 81 | |
| 82 | for spine in $(seq 1 $spines); do |
| 83 | for link in $(seq 1 $spineLinks); do |
| 84 | sim "null-create-link direct Spine-${spine} Leaf-${pair}1" |
| 85 | sim "null-create-link direct Spine-${spine} Leaf-${pair}2" |
| 86 | done |
| 87 | done |
| 88 | |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 89 | # Create gateways attached to each leaf group; multi-homed to each leaf in the pair |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 90 | [ $pair = A ] && pn=1 || pn=2 |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 91 | for gw in $(seq 1 $gateways); do |
| 92 | sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.0.${gw}" |
| 93 | gwIps="${gwIps}|10.${pn}.0.${gw}" |
| 94 | done |
| 95 | |
| 96 | # Create hosts for each leaf group; multi-homed to each leaf in the pair |
Thomas Vachuska | fa61549 | 2018-03-19 09:11:51 -0700 | [diff] [blame] | 97 | [ $pair = A ] && offset=-400 || offset=400 |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 98 | for host in $(seq 1 $serviceHosts); do |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 99 | sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.1.${host}" |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 100 | done |
| 101 | done |
| 102 | |
| 103 | # Create single access leafs with dual links to the spines |
| 104 | for access in $(seq $accessLeaves); do |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 105 | sim "null-create-device switch Access-${access} ${accessPorts}" |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 106 | |
| 107 | for spine in $(seq 1 $spines); do |
| 108 | for link in $(seq 1 $spineLinks); do |
| 109 | sim "null-create-link direct Spine-${spine} Access-${access}" |
| 110 | done |
| 111 | done |
| 112 | |
| 113 | # Create hosts for each access single leaf |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 114 | sim "null-create-hosts Access-${access} 10.1${access}.1.*" $accessHosts |
Thomas Vachuska | a8e7477 | 2018-02-26 11:33:35 -0800 | [diff] [blame] | 115 | # sim "null-create-hosts Access-${access} 10.1${access}.2.*" $accessHosts |
| 116 | done |
| 117 | |
| 118 | |
| 119 | # make sure null providers are activated and any running simulation is stopped |
| 120 | onos ${node} app activate org.onosproject.null |
| 121 | sleep 2 |
| 122 | onos ${node} null-simulation stop |
| 123 | |
| 124 | # wait until the masterships clear-out across the cluster |
| 125 | while onos ${node} masters | grep -qv " 0 devices"; do sleep 1; done |
| 126 | |
| 127 | # clean-up |
| 128 | onos ${node} wipe-out please |
| 129 | sleep 1 |
| 130 | |
| 131 | # start custom simulation.. |
| 132 | onos ${node} null-simulation start custom |
| 133 | sleep 2 |
| 134 | |
| 135 | # Add devices, links, and hosts |
| 136 | cat $CMDS | onos ${node} |
| 137 | |
Thomas Vachuska | 6f6b662f | 2018-05-07 15:01:06 -0700 | [diff] [blame^] | 138 | # After the network is created, add network config to assign roles to gateway IPs. |
| 139 | cfg="" |
| 140 | for gw in $(onos ${node} hosts | egrep "${gwIps/|/}" | cut -d, -f1 | cut -d= -f2); do |
| 141 | cfg="${cfg}, \"$gw\": { \"basic\": { \"uiType\" : \"router\", \"roles\": [ \"gateway\" ]}}" |
| 142 | done |
| 143 | echo "{ \"hosts\": { ${cfg/,/} }}" > $CMDS |
| 144 | |
| 145 | onos-netcfg ${node} $CMDS |