blob: 80a3751e9f8015c1d7ff2ff62e187af13279ba24 [file] [log] [blame]
Thomas Vachuska722224e2018-03-26 10:56:18 -07001#!/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
14function 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
27spines=2
28spineLinks=2
29serviceLeafGroups="A B"
30serviceHosts=10
31fieldOffices=3
32accessLeaves=3
33accessHosts=60
34
35# Scan arguments for user/password or other options...
36while 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
46done
47
48spinePorts=48
49let leafPorts=serviceHosts+8 # derive service ports from service hosts
50let accessPorts=accessHosts+8 # derive access ports from access hosts
51let hagPorts=accessLeaves+8 # derive hag ports from access leaves
52
53let totalHags=fieldOffices*spines
54let totalAccess=fieldOffices*accessLeaves
55
56let OPC=$OPTIND-1
57shift $OPC
58
59# Optional ONOS node IP
60node=${1:-$OCI}
61
62# Create the script of ONOS commands first and then execute it all at once.
63export CMDS="/tmp/fab-onos.cmds"
64rm $CMDS
65
66function sim {
67 echo "$@" >> $CMDS
68}
69
70function 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
76for spine in $(seq 1 $spines); do
77 sim "null-create-device switch Spine-${spine} ${spinePorts} 0 $(y $spine $spines) grid"
78done
79
80# Create 2 leaf pairs with dual links to the spines and a link between the pair
81for 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
101done
102
103# Indexes for HAG and access leaves across all field offices
104let iagg=1
105let iacc=1
106
107# Create field offices
108for 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
128done
129
130# make sure null providers are activated and any running simulation is stopped
131onos ${node} app activate org.onosproject.null
132sleep 2
133onos ${node} null-simulation stop
134
135# wait until the masterships clear-out across the cluster
136while onos ${node} masters | grep -qv " 0 devices"; do sleep 1; done
137
138# clean-up
139onos ${node} wipe-out please
140sleep 1
141
142# start custom simulation..
143onos ${node} null-simulation start custom
144sleep 2
145
146# Add devices, links, and hosts
147cat $CMDS | onos ${node}
148