blob: 427b1fcef89b47c8f840e49575013d1d4964fda2 [file] [log] [blame]
Thomas Vachuska8e038eb2016-02-23 23:28:23 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuska8e038eb2016-02-23 23:28:23 -08003 *
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 * Rectangular grid topology with hosts at each device.
22 */
23public class GridTopologySimulator extends TopologySimulator {
24
25 private int cols;
26 private int rows;
27
28 @Override
29 protected void processTopoShape(String shape) {
30 super.processTopoShape(shape);
31 rows = topoShape.length > 1 ? Integer.parseInt(topoShape[1]) : 10;
32 cols = topoShape.length > 2 ? Integer.parseInt(topoShape[2]) : rows;
33 hostCount = topoShape.length > 3 ? Integer.parseInt(topoShape[3]) : 1;
34 infrastructurePorts = 4;
35 deviceCount = rows * cols;
36 }
37
38 @Override
39 public void setUpTopology() {
40 checkArgument(rows > 1, "There must be at least 2 rows");
41 checkArgument(cols > 1, "There must be at least 2 columns");
42 super.setUpTopology();
43 }
44
45 @Override
46 protected void createLinks() {
47 for (int r = 0; r < rows; r++) {
48 for (int c = 0; c < cols; c++) {
49 int i = r * cols + c;
50 if (c < cols - 1) {
51 createLink(i, i + 1, 3, 1);
52 }
53 if (r < rows - 1) {
54 createLink(i, (r + 1) * cols + c, 4, 2);
55 }
56 }
57 }
58 }
59
60 @Override
61 protected void createHosts() {
62 deviceIds.forEach(id -> createHosts(id, infrastructurePorts));
63 }
64
65}