blob: 1a9eaccb1641aa98d14cd6b68001895268ede80d [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
18import static com.google.common.base.Preconditions.checkArgument;
19
20/**
21 * Linear topology simulator.
22 */
23public class LinearTopologySimulator extends TopologySimulator {
24
25 @Override
26 protected void processTopoShape(String shape) {
27 super.processTopoShape(shape);
28 deviceCount = (topoShape.length == 1) ? deviceCount : Integer.parseInt(topoShape[1]);
29 }
30
31 @Override
32 public void setUpTopology() {
33 checkArgument(deviceCount > 1, "There must be at least 2 devices");
34
35 prepareForDeviceEvents(deviceCount);
36 createDevices();
37 waitForDeviceEvents();
38
39 createLinks();
40 createHosts();
41 }
42
43 @Override
44 protected void createLinks() {
Thomas Vachuskaf651cc92015-04-14 16:11:44 -070045 int portOffset = 1;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070046 for (int i = 0, n = deviceCount - 1; i < n; i++) {
Thomas Vachuskaf651cc92015-04-14 16:11:44 -070047 createLink(i, i + 1, portOffset, 1);
48 portOffset = 2;
Thomas Vachuskac40d4632015-04-09 16:55:03 -070049 }
50 }
51
52 @Override
53 protected void createHosts() {
54 createHosts(deviceIds.get(0), infrastructurePorts);
55 createHosts(deviceIds.get(deviceCount - 1), infrastructurePorts);
56 }
57
58}