Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Creates a hierarchical access spine-leaf fabric with large number of hosts |
| 4 | # using null providers. |
| 5 | # |
| 6 | # Default setup as follows: |
| 7 | # 2 primary spines (or more if needed, but this is typically not the case) |
| 8 | # 2 aggregating spines per access headend |
| 9 | # ~3 access leaves per headend |
| 10 | # 2 leaf pairs for connecting gateways and compute (services/caching/etc.) |
| 11 | # ----------------------------------------------------------------------------- |
| 12 | |
| 13 | function usage { |
| 14 | echo "usage: $(basename $0) [options] [onos-ip]" |
| 15 | echo "" |
| 16 | echo "Options:" |
| 17 | echo " -s spines" |
| 18 | echo " -l spineLinks" |
| 19 | echo " -S serviceHosts" |
| 20 | echo " -G gateways" |
| 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 | gateways=2 |
| 35 | |
| 36 | # Scan arguments for user/password or other options... |
| 37 | while getopts s:l:a:f:A:S:G:?h o; do |
| 38 | case "$o" in |
| 39 | s) spines=$OPTARG;; |
| 40 | l) spineLinks=$OPTARG;; |
| 41 | a) accessLeaves=$OPTARG;; |
| 42 | f) fieldOffices=$OPTARG;; |
| 43 | A) accessHosts=$OPTARG;; |
| 44 | S) serviceHosts=$OPTARG;; |
| 45 | G) gateways=$OPTARG;; |
| 46 | *) usage $0;; |
| 47 | esac |
| 48 | done |
| 49 | |
| 50 | spinePorts=48 |
| 51 | let leafPorts=serviceHosts+8 # derive service ports from service hosts |
| 52 | let accessPorts=accessHosts+8 # derive access ports from access hosts |
| 53 | let hagPorts=accessLeaves+8 # derive hag ports from access leaves |
| 54 | |
| 55 | let totalHags=fieldOffices*spines |
| 56 | let totalAccess=fieldOffices*accessLeaves |
| 57 | |
| 58 | let OPC=$OPTIND-1 |
| 59 | shift $OPC |
| 60 | |
| 61 | # Optional ONOS node IP |
| 62 | node=${1:-$OCI} |
| 63 | |
| 64 | # Create the script of ONOS commands first and then execute it all at once. |
| 65 | export CMDS="/tmp/access-onos.cmds" |
| 66 | rm -f $CMDS 2>/dev/null |
| 67 | |
| 68 | function sim { |
| 69 | echo "$@" >> $CMDS |
| 70 | } |
| 71 | |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 72 | # Create central office spines |
| 73 | for spine in $(seq 1 $spines); do |
Thomas Vachuska | 5064e20 | 2018-04-24 10:12:41 -0400 | [diff] [blame] | 74 | sim "null-create-device switch Spine-${spine} ${spinePorts}" |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 75 | done |
| 76 | |
Thomas Vachuska | 37e32b8 | 2018-05-07 15:01:06 -0700 | [diff] [blame] | 77 | gwIps="" |
| 78 | |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 79 | # Create 2 leaf pairs with dual links to the spines and a link between the pair |
| 80 | for pair in $serviceLeafGroups; do |
| 81 | [ $pair = A ] && l1=1 || l1=3 |
| 82 | [ $pair = A ] && l2=2 || l2=4 |
Thomas Vachuska | 5064e20 | 2018-04-24 10:12:41 -0400 | [diff] [blame] | 83 | sim "null-create-device switch Leaf-${pair}1 ${leafPorts}" |
| 84 | sim "null-create-device switch Leaf-${pair}2 ${leafPorts}" |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 85 | sim "null-create-link direct Leaf-${pair}1 Leaf-${pair}2" |
| 86 | |
| 87 | for spine in $(seq 1 $spines); do |
| 88 | for link in $(seq 1 $spineLinks); do |
| 89 | sim "null-create-link direct Spine-${spine} Leaf-${pair}1" |
| 90 | sim "null-create-link direct Spine-${spine} Leaf-${pair}2" |
| 91 | done |
| 92 | done |
| 93 | |
| 94 | # Create gateways attached to each leaf group; multi-homed to each leaf in the pair |
| 95 | [ $pair = A ] && pn=1 || pn=2 |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 96 | for gw in $(seq 1 $gateways); do |
Thomas Vachuska | 5064e20 | 2018-04-24 10:12:41 -0400 | [diff] [blame] | 97 | sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.0.${gw}" |
Thomas Vachuska | 37e32b8 | 2018-05-07 15:01:06 -0700 | [diff] [blame] | 98 | gwIps="${gwIps}|10.${pn}.0.${gw}" |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 99 | done |
| 100 | |
| 101 | # Create hosts for each leaf group; multi-homed to each leaf in the pair |
| 102 | [ $pair = A ] && offset=-400 || offset=400 |
| 103 | for host in $(seq 1 $serviceHosts); do |
Thomas Vachuska | 5064e20 | 2018-04-24 10:12:41 -0400 | [diff] [blame] | 104 | sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.1.${host}" |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 105 | done |
| 106 | done |
| 107 | |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 108 | # Create field offices |
| 109 | for field in $(seq $fieldOffices); do |
| 110 | # Create HAG spines for each office and connect it to central office spines |
| 111 | for spine in $(seq $spines); do |
Thomas Vachuska | 5064e20 | 2018-04-24 10:12:41 -0400 | [diff] [blame] | 112 | sim "null-create-device switch Spine-${field}-${spine} ${hagPorts}" |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 113 | sim "null-create-link direct Spine-${spine} Spine-${field}-${spine}" |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 114 | done |
| 115 | |
| 116 | # Create single access leafs with links to the spines |
| 117 | for access in $(seq $accessLeaves); do |
Thomas Vachuska | 5064e20 | 2018-04-24 10:12:41 -0400 | [diff] [blame] | 118 | sim "null-create-device switch Access-${field}-${access} ${accessPorts}" |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 5064e20 | 2018-04-24 10:12:41 -0400 | [diff] [blame] | 124 | sim "null-create-hosts Access-${field}-${access} 10.${field}${access}.1.* $accessHosts" |
Thomas Vachuska | 0d5106a | 2018-04-06 00:29:30 -0700 | [diff] [blame] | 125 | done |
| 126 | done |
| 127 | |
| 128 | # make sure null providers are activated and any running simulation is stopped |
| 129 | onos ${node} app activate org.onosproject.null |
| 130 | sleep 2 |
| 131 | onos ${node} null-simulation stop |
| 132 | |
| 133 | # wait until the masterships clear-out across the cluster |
| 134 | while onos ${node} masters | grep -qv " 0 devices"; do sleep 1; done |
| 135 | |
| 136 | # clean-up |
| 137 | onos ${node} wipe-out please |
| 138 | sleep 1 |
| 139 | |
| 140 | # start custom simulation.. |
| 141 | onos ${node} null-simulation start custom |
| 142 | sleep 2 |
| 143 | |
| 144 | # Add devices, links, and hosts |
| 145 | cat $CMDS | onos ${node} |
| 146 | |
Thomas Vachuska | 37e32b8 | 2018-05-07 15:01:06 -0700 | [diff] [blame] | 147 | # After the network is created, add network config to assign roles to gateway IPs. |
| 148 | cfg="" |
| 149 | for gw in $(onos ${node} hosts | egrep "${gwIps/|/}" | cut -d, -f1 | cut -d= -f2); do |
| 150 | cfg="${cfg}, \"$gw\": { \"basic\": { \"uiType\" : \"router\", \"roles\": [ \"gateway\" ]}}" |
| 151 | done |
| 152 | echo "{ \"hosts\": { ${cfg/,/} }}" > $CMDS |
| 153 | |
| 154 | onos-netcfg ${node} $CMDS |
| 155 | |