blob: c60ced35045f9b2acf342345e931137209e5a521 [file] [log] [blame]
Thomas Vachuskac40d4632015-04-09 16:55:03 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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
Hwanwook Lee9ac31252016-12-07 11:09:33 +090018import static com.google.common.base.Preconditions.checkArgument;
19
Thomas Vachuskac40d4632015-04-09 16:55:03 -070020/**
21 * Full mesh topology with hosts at each device.
22 */
23public class MeshTopologySimulator extends TopologySimulator {
24
25 @Override
26 protected void processTopoShape(String shape) {
27 super.processTopoShape(shape);
Hwanwook Lee9ac31252016-12-07 11:09:33 +090028 deviceCount = (topoShape.length > 1) ? Integer.parseInt(topoShape[1]) : deviceCount;
29 hostCount = (topoShape.length > 2) ? Integer.parseInt(topoShape[2]) : hostCount;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070030 }
31
32 @Override
33 public void setUpTopology() {
Hwanwook Lee9ac31252016-12-07 11:09:33 +090034 checkArgument(deviceCount > 1, "There must be at least 2 devices");
35 checkArgument(hostCount > 0, "There must be at least 1 host");
Thomas Vachuskac40d4632015-04-09 16:55:03 -070036 super.setUpTopology();
37 }
38
39 @Override
40 protected void createLinks() {
Hwanwook Lee9ac31252016-12-07 11:09:33 +090041 for (int i = 0, n = deviceCount - 1; i < n; i++) {
42 for (int j = 0; j < n - i; j++) {
43 createLink(i, i + j + 1, i + j + 1, i + 1);
44 }
45 }
Thomas Vachuskac40d4632015-04-09 16:55:03 -070046 }
47
48 @Override
49 protected void createHosts() {
Hwanwook Lee9ac31252016-12-07 11:09:33 +090050 for (int i = 0, n = deviceCount; i < n; i++) {
51 createHosts(deviceIds.get(i), deviceCount - 1);
52 }
Thomas Vachuskac40d4632015-04-09 16:55:03 -070053 }
54
Hwanwook Lee9ac31252016-12-07 11:09:33 +090055}