Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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 | |
Hwanwook Lee | 9ac3125 | 2016-12-07 11:09:33 +0900 | [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 | * Full mesh topology with hosts at each device. |
| 22 | */ |
| 23 | public class MeshTopologySimulator extends TopologySimulator { |
| 24 | |
| 25 | @Override |
| 26 | protected void processTopoShape(String shape) { |
| 27 | super.processTopoShape(shape); |
Hwanwook Lee | 9ac3125 | 2016-12-07 11:09:33 +0900 | [diff] [blame] | 28 | deviceCount = (topoShape.length > 1) ? Integer.parseInt(topoShape[1]) : deviceCount; |
| 29 | hostCount = (topoShape.length > 2) ? Integer.parseInt(topoShape[2]) : hostCount; |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public void setUpTopology() { |
Hwanwook Lee | 9ac3125 | 2016-12-07 11:09:33 +0900 | [diff] [blame] | 34 | checkArgument(deviceCount > 1, "There must be at least 2 devices"); |
| 35 | checkArgument(hostCount > 0, "There must be at least 1 host"); |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 36 | super.setUpTopology(); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | protected void createLinks() { |
Hwanwook Lee | 9ac3125 | 2016-12-07 11:09:33 +0900 | [diff] [blame] | 41 | 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 Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | @Override |
| 49 | protected void createHosts() { |
Hwanwook Lee | 9ac3125 | 2016-12-07 11:09:33 +0900 | [diff] [blame] | 50 | for (int i = 0, n = deviceCount; i < n; i++) { |
| 51 | createHosts(deviceIds.get(i), deviceCount - 1); |
| 52 | } |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Hwanwook Lee | 9ac3125 | 2016-12-07 11:09:33 +0900 | [diff] [blame] | 55 | } |