Thomas Vachuska | 722224e | 2018-03-26 10:56:18 -0700 | [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" |
| 21 | echo " -f fieldOffices" |
| 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 | fieldOffices=3 |
| 32 | accessLeaves=3 |
| 33 | accessHosts=60 |
| 34 | |
| 35 | # Scan arguments for user/password or other options... |
| 36 | while getopts s:l:a:f:A:S:?h o; do |
| 37 | case "$o" in |
| 38 | s) spines=$OPTARG;; |
| 39 | l) spineLinks=$OPTARG;; |
| 40 | a) accessLeaves=$OPTARG;; |
| 41 | f) fieldOffices=$OPTARG;; |
| 42 | A) accessHosts=$OPTARG;; |
| 43 | S) serviceHosts=$OPTARG;; |
| 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 | let hagPorts=accessLeaves+8 # derive hag ports from access leaves |
| 52 | |
| 53 | let totalHags=fieldOffices*spines |
| 54 | let totalAccess=fieldOffices*accessLeaves |
| 55 | |
| 56 | let OPC=$OPTIND-1 |
| 57 | shift $OPC |
| 58 | |
| 59 | # Optional ONOS node IP |
| 60 | node=${1:-$OCI} |
| 61 | |
| 62 | # Create the script of ONOS commands first and then execute it all at once. |
| 63 | export CMDS="/tmp/fab-onos.cmds" |
| 64 | rm $CMDS |
| 65 | |
| 66 | function sim { |
| 67 | echo "$@" >> $CMDS |
| 68 | } |
| 69 | |
| 70 | function y { |
| 71 | let p="${3:-400} * ($1 - 1) - (${3:-400} * ($2 - 1)) / 2 + ${4:-0}" |
| 72 | echo $p |
| 73 | } |
| 74 | |
| 75 | # Create central office spines |
| 76 | for spine in $(seq 1 $spines); do |
| 77 | sim "null-create-device switch Spine-${spine} ${spinePorts} 0 $(y $spine $spines) grid" |
| 78 | done |
| 79 | |
| 80 | # Create 2 leaf pairs with dual links to the spines and a link between the pair |
| 81 | for pair in $serviceLeafGroups; do |
| 82 | [ $pair = A ] && l1=1 || l1=3 |
| 83 | [ $pair = A ] && l2=2 || l2=4 |
| 84 | sim "null-create-device switch Leaf-${pair}1 ${leafPorts} -200 $(y $l1 4) grid" |
| 85 | sim "null-create-device switch Leaf-${pair}2 ${leafPorts} -200 $(y $l2 4) grid" |
| 86 | sim "null-create-link direct Leaf-${pair}1 Leaf-${pair}2" |
| 87 | |
| 88 | for spine in $(seq 1 $spines); do |
| 89 | for link in $(seq 1 $spineLinks); do |
| 90 | sim "null-create-link direct Spine-${spine} Leaf-${pair}1" |
| 91 | sim "null-create-link direct Spine-${spine} Leaf-${pair}2" |
| 92 | done |
| 93 | done |
| 94 | |
| 95 | # Create hosts for each leaf group; multi-homed to each leaf in the pair |
| 96 | [ $pair = A ] && pn=1 || pn=2 |
| 97 | [ $pair = A ] && offset=-400 || offset=400 |
| 98 | for host in $(seq 1 $serviceHosts); do |
| 99 | sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.1.${host} -400 $(y $host $serviceHosts 60 $offset) grid" |
| 100 | done |
| 101 | done |
| 102 | |
| 103 | # Indexes for HAG and access leaves across all field offices |
| 104 | let iagg=1 |
| 105 | let iacc=1 |
| 106 | |
| 107 | # Create field offices |
| 108 | for field in $(seq $fieldOffices); do |
| 109 | # Create HAG spines for each office and connect it to central office spines |
| 110 | for spine in $(seq $spines); do |
| 111 | sim "null-create-device switch Spine-${field}-${spine} ${hagPorts} 200 $(y $iagg $totalHags) grid" |
| 112 | sim "null-create-link direct Spine-${spine} Spine-${field}-${spine}" |
| 113 | let iagg=iagg+1 |
| 114 | done |
| 115 | |
| 116 | # Create single access leafs with links to the spines |
| 117 | for access in $(seq $accessLeaves); do |
| 118 | sim "null-create-device switch Access-${field}-${access} ${accessPorts} 400 $(y $iacc $totalAccess) grid" |
| 119 | for spine in $(seq 1 $spines); do |
| 120 | sim "null-create-link direct Spine-${field}-${spine} Access-${field}-${access}" |
| 121 | done |
| 122 | |
| 123 | # Create hosts for each access single leaf |
| 124 | sim "null-create-hosts Access-${field}-${access} 10.${field}${access}.1.*" $accessHosts 700 $(y $iacc $totalAccess) 6 |
| 125 | |
| 126 | let iacc=iacc+1 |
| 127 | done |
| 128 | done |
| 129 | |
| 130 | # make sure null providers are activated and any running simulation is stopped |
| 131 | onos ${node} app activate org.onosproject.null |
| 132 | sleep 2 |
| 133 | onos ${node} null-simulation stop |
| 134 | |
| 135 | # wait until the masterships clear-out across the cluster |
| 136 | while onos ${node} masters | grep -qv " 0 devices"; do sleep 1; done |
| 137 | |
| 138 | # clean-up |
| 139 | onos ${node} wipe-out please |
| 140 | sleep 1 |
| 141 | |
| 142 | # start custom simulation.. |
| 143 | onos ${node} null-simulation start custom |
| 144 | sleep 2 |
| 145 | |
| 146 | # Add devices, links, and hosts |
| 147 | cat $CMDS | onos ${node} |
| 148 | |