blob: bed13904795896014460093d2687df730a211013 [file] [log] [blame]
Thomas Vachuskac40d4632015-04-09 16:55:03 -07001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
16package org.onosproject.provider.nil;
17
18import static com.google.common.base.Preconditions.checkArgument;
19
20/**
21 * Tree topology with hosts at the leaf devices.
22 */
23public class TreeTopologySimulator extends TopologySimulator {
24
25 private int[] tierMultiplier;
26 private int[] tierDeviceCount;
27 private int[] tierOffset;
28
29 @Override
30 protected void processTopoShape(String shape) {
31 super.processTopoShape(shape);
32 tierOffset = new int[topoShape.length];
33 tierMultiplier = new int[topoShape.length];
34 tierDeviceCount = new int[topoShape.length];
35
36 deviceCount = 1;
37
38 tierOffset[0] = 0;
39 tierMultiplier[0] = 1;
40 tierDeviceCount[0] = deviceCount;
41
42 for (int i = 1; i < topoShape.length; i++) {
43 tierOffset[i] = deviceCount;
44 tierMultiplier[i] = Integer.parseInt(topoShape[i]);
45 tierDeviceCount[i] = tierDeviceCount[i - 1] * tierMultiplier[i];
46 deviceCount = deviceCount + tierDeviceCount[i];
47 }
48 }
49
50 @Override
51 public void setUpTopology() {
52 checkArgument(tierDeviceCount.length > 0, "There must be at least one tree tier");
53 super.setUpTopology();
54 }
55
56 @Override
57 protected void createLinks() {
58 for (int t = 1; t < tierOffset.length; t++) {
59 int child = tierOffset[t];
60 for (int parent = tierOffset[t - 1]; parent < tierOffset[t]; parent++) {
61 for (int i = 0; i < tierMultiplier[t]; i++) {
62 createLink(parent, child);
63 child++;
64 }
65 }
66 }
67 }
68
69 @Override
70 protected void createHosts() {
71 for (int i = tierOffset[tierOffset.length - 1]; i < deviceCount; i++) {
72 createHosts(deviceIds.get(i), hostCount);
73 }
74 }
75}