blob: 3c07f5b58c53d4b930099c2d27fd6b1c46b86dd7 [file] [log] [blame]
Thomas Vachuska0d5106a2018-04-06 00:29:30 -07001#!/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
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"
20 echo " -G gateways"
21 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
34gateways=2
35
36# Scan arguments for user/password or other options...
37while 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
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.
65export CMDS="/tmp/access-onos.cmds"
66rm -f $CMDS 2>/dev/null
67
68function sim {
69 echo "$@" >> $CMDS
70}
71
72function y {
73 let p="${3:-400} * ($1 - 1) - (${3:-400} * ($2 - 1)) / 2 + ${4:-0}"
74 echo $p
75}
76
77# Create central office spines
78for spine in $(seq 1 $spines); do
79 sim "null-create-device switch Spine-${spine} ${spinePorts} 0 $(y $spine $spines) grid"
80done
81
82# Create 2 leaf pairs with dual links to the spines and a link between the pair
83for pair in $serviceLeafGroups; do
84 [ $pair = A ] && l1=1 || l1=3
85 [ $pair = A ] && l2=2 || l2=4
86 sim "null-create-device switch Leaf-${pair}1 ${leafPorts} -200 $(y $l1 4) grid"
87 sim "null-create-device switch Leaf-${pair}2 ${leafPorts} -200 $(y $l2 4) grid"
88 sim "null-create-link direct Leaf-${pair}1 Leaf-${pair}2"
89
90 for spine in $(seq 1 $spines); do
91 for link in $(seq 1 $spineLinks); do
92 sim "null-create-link direct Spine-${spine} Leaf-${pair}1"
93 sim "null-create-link direct Spine-${spine} Leaf-${pair}2"
94 done
95 done
96
97 # Create gateways attached to each leaf group; multi-homed to each leaf in the pair
98 [ $pair = A ] && pn=1 || pn=2
99 [ $pair = A ] && gwy=-800 || gwy=800
100 for gw in $(seq 1 $gateways); do
101 sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.0.${gw} $(y $gw $gateways 200 -200) ${gwy} grid"
102 done
103
104 # Create hosts for each leaf group; multi-homed to each leaf in the pair
105 [ $pair = A ] && offset=-400 || offset=400
106 for host in $(seq 1 $serviceHosts); do
107 sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.1.${host} -400 $(y $host $serviceHosts 60 $offset) grid"
108 done
109done
110
111# Indexes for HAG and access leaves across all field offices
112let iagg=1
113let iacc=1
114
115# Create field offices
116for field in $(seq $fieldOffices); do
117 # Create HAG spines for each office and connect it to central office spines
118 for spine in $(seq $spines); do
119 sim "null-create-device switch Spine-${field}-${spine} ${hagPorts} 200 $(y $iagg $totalHags) grid"
120 sim "null-create-link direct Spine-${spine} Spine-${field}-${spine}"
121 let iagg=iagg+1
122 done
123
124 # Create single access leafs with links to the spines
125 for access in $(seq $accessLeaves); do
126 sim "null-create-device switch Access-${field}-${access} ${accessPorts} 400 $(y $iacc $totalAccess) grid"
127 for spine in $(seq 1 $spines); do
128 sim "null-create-link direct Spine-${field}-${spine} Access-${field}-${access}"
129 done
130
131 # Create hosts for each access single leaf
132 sim "null-create-hosts Access-${field}-${access} 10.${field}${access}.1.*" $accessHosts 700 $(y $iacc $totalAccess) 6
133
134 let iacc=iacc+1
135 done
136done
137
138# make sure null providers are activated and any running simulation is stopped
139onos ${node} app activate org.onosproject.null
140sleep 2
141onos ${node} null-simulation stop
142
143# wait until the masterships clear-out across the cluster
144while onos ${node} masters | grep -qv " 0 devices"; do sleep 1; done
145
146# clean-up
147onos ${node} wipe-out please
148sleep 1
149
150# start custom simulation..
151onos ${node} null-simulation start custom
152sleep 2
153
154# Add devices, links, and hosts
155cat $CMDS | onos ${node}
156