Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.provider.nil; |
| 17 | |
Yi Tseng | fef5c66 | 2018-04-04 21:06:35 +0800 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkArgument; |
| 19 | |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 20 | /** |
| 21 | * Spine-leaf topology with hosts at the leaf devices. |
| 22 | */ |
| 23 | public class SpineLeafTopologySimulator extends TopologySimulator { |
Yi Tseng | fef5c66 | 2018-04-04 21:06:35 +0800 | [diff] [blame] | 24 | 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 Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 30 | |
| 31 | @Override |
| 32 | protected void processTopoShape(String shape) { |
| 33 | super.processTopoShape(shape); |
Yi Tseng | fef5c66 | 2018-04-04 21:06:35 +0800 | [diff] [blame] | 34 | // 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 Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public void setUpTopology() { |
Yi Tseng | fef5c66 | 2018-04-04 21:06:35 +0800 | [diff] [blame] | 51 | 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 Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 59 | super.setUpTopology(); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | protected void createLinks() { |
Yi Tseng | fef5c66 | 2018-04-04 21:06:35 +0800 | [diff] [blame] | 64 | 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 Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
| 73 | protected void createHosts() { |
Yi Tseng | fef5c66 | 2018-04-04 21:06:35 +0800 | [diff] [blame] | 74 | for (int i = spineCount; i < spineCount + leafCount; i++) { |
| 75 | createHosts(deviceIds.get(i), spineCount); |
| 76 | } |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | } |