blob: e42ae7074a2e8796df2dccf47ecccb033499cbd1 [file] [log] [blame]
Thomas Vachuskac40d4632015-04-09 16:55:03 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuskac40d4632015-04-09 16:55:03 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.provider.nil;
17
Yi Tsengfef5c662018-04-04 21:06:35 +080018import static com.google.common.base.Preconditions.checkArgument;
19
Thomas Vachuskac40d4632015-04-09 16:55:03 -070020/**
21 * Spine-leaf topology with hosts at the leaf devices.
22 */
23public class SpineLeafTopologySimulator extends TopologySimulator {
Yi Tsengfef5c662018-04-04 21:06:35 +080024 private static final int DEFAULT_SPINE_COUNT = 2;
25 private static final int DEFAULT_LEAF_COUNT = 2;
26 private static final int DEFAULT_HOST_PER_LEAF = 2;
27 private int spineCount = DEFAULT_SPINE_COUNT;
28 private int leafCount = DEFAULT_LEAF_COUNT;
29 private int hostPerLeaf = DEFAULT_HOST_PER_LEAF;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070030
31 @Override
32 protected void processTopoShape(String shape) {
33 super.processTopoShape(shape);
Yi Tsengfef5c662018-04-04 21:06:35 +080034 // topology shape: spineleaf,[spine count],[leaf count],[host per leaf]
35
36 if (topoShape.length > 1) {
37 spineCount = Integer.parseInt(topoShape[1]);
38 }
39
40 if (topoShape.length > 2) {
41 leafCount = Integer.parseInt(topoShape[2]);
42 }
43
44 if (topoShape.length > 3) {
45 hostPerLeaf = Integer.parseInt(topoShape[3]);
46 }
Thomas Vachuskac40d4632015-04-09 16:55:03 -070047 }
48
49 @Override
50 public void setUpTopology() {
Yi Tsengfef5c662018-04-04 21:06:35 +080051 checkArgument(spineCount > 0, "There must be at least one spine");
52 checkArgument(leafCount > 0, "There must be at least one leaf");
53
54 deviceCount = spineCount + leafCount;
55 hostCount = hostPerLeaf;
56 log.info("Setup Spine-Leaf topology with {} spine(s), {} leaf(s), and {} host per leaf",
57 spineCount, leafCount, hostPerLeaf);
58
Thomas Vachuskac40d4632015-04-09 16:55:03 -070059 super.setUpTopology();
60 }
61
62 @Override
63 protected void createLinks() {
Yi Tsengfef5c662018-04-04 21:06:35 +080064 for (int spineIndex = 0; spineIndex < spineCount; spineIndex++) {
65 for (int leafIndex = spineCount; leafIndex < spineCount + leafCount; leafIndex++) {
66 // Nth port of spine connect to Nth leaf, vice versa
67 createLink(spineIndex, leafIndex, leafIndex - spineCount + 1, spineIndex + 1);
68 }
69 }
Thomas Vachuskac40d4632015-04-09 16:55:03 -070070 }
71
72 @Override
73 protected void createHosts() {
Yi Tsengfef5c662018-04-04 21:06:35 +080074 for (int i = spineCount; i < spineCount + leafCount; i++) {
75 createHosts(deviceIds.get(i), spineCount);
76 }
Thomas Vachuskac40d4632015-04-09 16:55:03 -070077 }
78
79}