blob: d023624157f8a470a6207f86ec363c7227226776 [file] [log] [blame]
Thomas Vachuska722224e2018-03-26 10:56:18 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
Thomas Vachuska0d933862018-04-06 00:29:30 -07003# Creates a hierarchical access spine-leaf fabric with large number of hosts
4# using null providers.
Thomas Vachuska722224e2018-03-26 10:56:18 -07005#
6# Default setup as follows:
Thomas Vachuska0d933862018-04-06 00:29:30 -07007# 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.)
Thomas Vachuska722224e2018-03-26 10:56:18 -070011# -----------------------------------------------------------------------------
12
13function 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"
Thomas Vachuska0d933862018-04-06 00:29:30 -070020 echo " -G gateways"
Thomas Vachuska722224e2018-03-26 10:56:18 -070021 echo " -f fieldOffices"
22 echo " -a accessLeaves"
23 echo " -A accessHosts"
24 exit 1
25}
26
27spines=2
28spineLinks=2
29serviceLeafGroups="A B"
30serviceHosts=10
31fieldOffices=3
32accessLeaves=3
33accessHosts=60
Thomas Vachuska0d933862018-04-06 00:29:30 -070034gateways=2
Thomas Vachuska722224e2018-03-26 10:56:18 -070035
36# Scan arguments for user/password or other options...
Thomas Vachuska0d933862018-04-06 00:29:30 -070037while getopts s:l:a:f:A:S:G:?h o; do
Thomas Vachuska722224e2018-03-26 10:56:18 -070038 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;;
Thomas Vachuska0d933862018-04-06 00:29:30 -070045 G) gateways=$OPTARG;;
Thomas Vachuska722224e2018-03-26 10:56:18 -070046 *) usage $0;;
47 esac
48done
49
50spinePorts=48
51let leafPorts=serviceHosts+8 # derive service ports from service hosts
52let accessPorts=accessHosts+8 # derive access ports from access hosts
53let hagPorts=accessLeaves+8 # derive hag ports from access leaves
54
55let totalHags=fieldOffices*spines
56let totalAccess=fieldOffices*accessLeaves
57
58let OPC=$OPTIND-1
59shift $OPC
60
61# Optional ONOS node IP
62node=${1:-$OCI}
63
64# Create the script of ONOS commands first and then execute it all at once.
Thomas Vachuska0d933862018-04-06 00:29:30 -070065export CMDS="/tmp/access-onos.cmds"
66rm -f $CMDS 2>/dev/null
Thomas Vachuska722224e2018-03-26 10:56:18 -070067
68function sim {
69 echo "$@" >> $CMDS
70}
71
Thomas Vachuska722224e2018-03-26 10:56:18 -070072# Create central office spines
73for spine in $(seq 1 $spines); do
Thomas Vachuska17b6ac62018-05-07 15:01:06 -070074 sim "null-create-device switch Spine-${spine} ${spinePorts}"
Thomas Vachuska722224e2018-03-26 10:56:18 -070075done
76
Thomas Vachuska17b6ac62018-05-07 15:01:06 -070077gwIps=""
78
Thomas Vachuska722224e2018-03-26 10:56:18 -070079# Create 2 leaf pairs with dual links to the spines and a link between the pair
80for pair in $serviceLeafGroups; do
81 [ $pair = A ] && l1=1 || l1=3
82 [ $pair = A ] && l2=2 || l2=4
Thomas Vachuska17b6ac62018-05-07 15:01:06 -070083 sim "null-create-device switch Leaf-${pair}1 ${leafPorts}"
84 sim "null-create-device switch Leaf-${pair}2 ${leafPorts}"
Thomas Vachuska722224e2018-03-26 10:56:18 -070085 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
Thomas Vachuska0d933862018-04-06 00:29:30 -070094 # Create gateways attached to each leaf group; multi-homed to each leaf in the pair
Thomas Vachuska722224e2018-03-26 10:56:18 -070095 [ $pair = A ] && pn=1 || pn=2
Thomas Vachuska0d933862018-04-06 00:29:30 -070096 [ $pair = A ] && gwy=-800 || gwy=800
97 for gw in $(seq 1 $gateways); do
Thomas Vachuska17b6ac62018-05-07 15:01:06 -070098 sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.0.${gw}"
99 gwIps="${gwIps}|10.${pn}.0.${gw}"
Thomas Vachuska0d933862018-04-06 00:29:30 -0700100 done
101
102 # Create hosts for each leaf group; multi-homed to each leaf in the pair
Thomas Vachuska722224e2018-03-26 10:56:18 -0700103 [ $pair = A ] && offset=-400 || offset=400
104 for host in $(seq 1 $serviceHosts); do
Thomas Vachuska17b6ac62018-05-07 15:01:06 -0700105 sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.1.${host}"
Thomas Vachuska722224e2018-03-26 10:56:18 -0700106 done
107done
108
109# Indexes for HAG and access leaves across all field offices
110let iagg=1
111let iacc=1
112
113# Create field offices
114for field in $(seq $fieldOffices); do
115 # Create HAG spines for each office and connect it to central office spines
116 for spine in $(seq $spines); do
Thomas Vachuska17b6ac62018-05-07 15:01:06 -0700117 sim "null-create-device switch Spine-${field}-${spine} ${hagPorts}"
Thomas Vachuska722224e2018-03-26 10:56:18 -0700118 sim "null-create-link direct Spine-${spine} Spine-${field}-${spine}"
119 let iagg=iagg+1
120 done
121
122 # Create single access leafs with links to the spines
123 for access in $(seq $accessLeaves); do
Thomas Vachuska17b6ac62018-05-07 15:01:06 -0700124 sim "null-create-device switch Access-${field}-${access} ${accessPorts}"
Thomas Vachuska722224e2018-03-26 10:56:18 -0700125 for spine in $(seq 1 $spines); do
126 sim "null-create-link direct Spine-${field}-${spine} Access-${field}-${access}"
127 done
128
129 # Create hosts for each access single leaf
Thomas Vachuska17b6ac62018-05-07 15:01:06 -0700130 sim "null-create-hosts Access-${field}-${access} 10.${field}${access}.1.* $accessHosts"
Thomas Vachuska722224e2018-03-26 10:56:18 -0700131
132 let iacc=iacc+1
133 done
134done
135
136# make sure null providers are activated and any running simulation is stopped
137onos ${node} app activate org.onosproject.null
138sleep 2
139onos ${node} null-simulation stop
140
141# wait until the masterships clear-out across the cluster
142while onos ${node} masters | grep -qv " 0 devices"; do sleep 1; done
143
144# clean-up
145onos ${node} wipe-out please
146sleep 1
147
148# start custom simulation..
149onos ${node} null-simulation start custom
150sleep 2
151
152# Add devices, links, and hosts
153cat $CMDS | onos ${node}
154
Thomas Vachuska17b6ac62018-05-07 15:01:06 -0700155# After the network is created, add network config to assign roles to gateway IPs.
156cfg=""
157for gw in $(onos ${node} hosts | egrep "${gwIps/|/}" | cut -d, -f1 | cut -d= -f2); do
158 cfg="${cfg}, \"$gw\": { \"basic\": { \"uiType\" : \"router\", \"roles\": [ \"gateway\" ]}}"
159done
160echo "{ \"hosts\": { ${cfg/,/} }}" > $CMDS
161
162onos-netcfg ${node} $CMDS
163