blob: 20f145284d8093080a7dd7c5b8cd8d68ed3d94df [file] [log] [blame]
Thomas Vachuskaa8e74772018-02-26 11:33:35 -08001#!/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"
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -070021 echo " -G gateways"
Thomas Vachuskaa8e74772018-02-26 11:33:35 -080022 echo " -a accessLeaves"
23 echo " -A accessHosts"
24 exit 1
25}
26
27spines=2
28spineLinks=2
29serviceLeafGroups="A B"
30serviceHosts=10
31accessLeaves=8
32accessHosts=100
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -070033gateways=2
Thomas Vachuskaa8e74772018-02-26 11:33:35 -080034
35# Scan arguments for user/password or other options...
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -070036while getopts s:l:a:A:S:G:?h o; do
Thomas Vachuskaa8e74772018-02-26 11:33:35 -080037 case "$o" in
38 s) spines=$OPTARG;;
39 l) spineLinks=$OPTARG;;
40 a) accessLeaves=$OPTARG;;
41 A) accessHosts=$OPTARG;;
42 S) serviceHosts=$OPTARG;;
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -070043 G) gateways=$OPTARG;;
Thomas Vachuskaa8e74772018-02-26 11:33:35 -080044 *) 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
51
52let OPC=$OPTIND-1
53shift $OPC
54
55# config
56node=${1:-$OCI}
57
58
59# Create the script of ONOS commands first and then execute it all at once.
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -070060export CMDS="/tmp/access-onos.cmds"
Thomas Vachuskaa8e74772018-02-26 11:33:35 -080061rm $CMDS
62
63function sim {
64 echo "$@" >> $CMDS
65}
66
67# Create spines
68for spine in $(seq 1 $spines); do
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -070069 sim "null-create-device switch Spine-${spine} ${spinePorts}"
Thomas Vachuskaa8e74772018-02-26 11:33:35 -080070done
71
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -070072gwIps=""
73
Thomas Vachuskaa8e74772018-02-26 11:33:35 -080074# Create 2 leaf pairs with dual links to the spines and a link between the pair
75for pair in $serviceLeafGroups; do
Thomas Vachuskac67a9912018-03-06 14:37:45 -080076 [ $pair = A ] && l1=1 || l1=3
77 [ $pair = A ] && l2=2 || l2=4
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -070078 sim "null-create-device switch Leaf-${pair}1 ${leafPorts}"
79 sim "null-create-device switch Leaf-${pair}2 ${leafPorts}"
Thomas Vachuskaa8e74772018-02-26 11:33:35 -080080 sim "null-create-link direct Leaf-${pair}1 Leaf-${pair}2"
81
82 for spine in $(seq 1 $spines); do
83 for link in $(seq 1 $spineLinks); do
84 sim "null-create-link direct Spine-${spine} Leaf-${pair}1"
85 sim "null-create-link direct Spine-${spine} Leaf-${pair}2"
86 done
87 done
88
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -070089 # Create gateways attached to each leaf group; multi-homed to each leaf in the pair
Thomas Vachuskaa8e74772018-02-26 11:33:35 -080090 [ $pair = A ] && pn=1 || pn=2
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -070091 for gw in $(seq 1 $gateways); do
92 sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.0.${gw}"
93 gwIps="${gwIps}|10.${pn}.0.${gw}"
94 done
95
96 # Create hosts for each leaf group; multi-homed to each leaf in the pair
Thomas Vachuskafa615492018-03-19 09:11:51 -070097 [ $pair = A ] && offset=-400 || offset=400
Thomas Vachuskaa8e74772018-02-26 11:33:35 -080098 for host in $(seq 1 $serviceHosts); do
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -070099 sim "null-create-host Leaf-${pair}1,Leaf-${pair}2 10.${pn}.1.${host}"
Thomas Vachuskaa8e74772018-02-26 11:33:35 -0800100 done
101done
102
103# Create single access leafs with dual links to the spines
104for access in $(seq $accessLeaves); do
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -0700105 sim "null-create-device switch Access-${access} ${accessPorts}"
Thomas Vachuskaa8e74772018-02-26 11:33:35 -0800106
107 for spine in $(seq 1 $spines); do
108 for link in $(seq 1 $spineLinks); do
109 sim "null-create-link direct Spine-${spine} Access-${access}"
110 done
111 done
112
113 # Create hosts for each access single leaf
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -0700114 sim "null-create-hosts Access-${access} 10.1${access}.1.*" $accessHosts
Thomas Vachuskaa8e74772018-02-26 11:33:35 -0800115 # sim "null-create-hosts Access-${access} 10.1${access}.2.*" $accessHosts
116done
117
118
119# make sure null providers are activated and any running simulation is stopped
120onos ${node} app activate org.onosproject.null
121sleep 2
122onos ${node} null-simulation stop
123
124# wait until the masterships clear-out across the cluster
125while onos ${node} masters | grep -qv " 0 devices"; do sleep 1; done
126
127# clean-up
128onos ${node} wipe-out please
129sleep 1
130
131# start custom simulation..
132onos ${node} null-simulation start custom
133sleep 2
134
135# Add devices, links, and hosts
136cat $CMDS | onos ${node}
137
Thomas Vachuska6f6b662f2018-05-07 15:01:06 -0700138# After the network is created, add network config to assign roles to gateway IPs.
139cfg=""
140for gw in $(onos ${node} hosts | egrep "${gwIps/|/}" | cut -d, -f1 | cut -d= -f2); do
141 cfg="${cfg}, \"$gw\": { \"basic\": { \"uiType\" : \"router\", \"roles\": [ \"gateway\" ]}}"
142done
143echo "{ \"hosts\": { ${cfg/,/} }}" > $CMDS
144
145onos-netcfg ${node} $CMDS