Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Foundation |
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 | |
| 18 | import static com.google.common.base.Preconditions.checkArgument; |
| 19 | |
| 20 | /** |
| 21 | * Re-routable linear topology simulator with an alternate path in the middle. |
| 22 | */ |
| 23 | public class RerouteTopologySimulator extends LinearTopologySimulator { |
| 24 | |
| 25 | @Override |
| 26 | protected void processTopoShape(String shape) { |
| 27 | super.processTopoShape(shape); |
Thomas Vachuska | f651cc9 | 2015-04-14 16:11:44 -0700 | [diff] [blame] | 28 | infrastructurePorts = 5; |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 29 | deviceCount = (topoShape.length == 1) ? deviceCount : Integer.parseInt(topoShape[1]); |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public void setUpTopology() { |
| 34 | checkArgument(deviceCount > 2, "There must be at least 3 devices"); |
| 35 | super.setUpTopology(); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | protected void createLinks() { |
Thomas Vachuska | f651cc9 | 2015-04-14 16:11:44 -0700 | [diff] [blame] | 40 | int portOffset = 1; |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 41 | for (int i = 0, n = deviceCount - 2; i < n; i++) { |
Thomas Vachuska | f651cc9 | 2015-04-14 16:11:44 -0700 | [diff] [blame] | 42 | createLink(i, i + 1, portOffset, 1); |
| 43 | portOffset = 2; |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 44 | } |
| 45 | int middle = (deviceCount - 1) / 2; |
| 46 | int alternate = deviceCount - 1; |
Thomas Vachuska | f651cc9 | 2015-04-14 16:11:44 -0700 | [diff] [blame] | 47 | createLink(middle - 1, alternate, 3, 1); |
| 48 | createLink(middle, alternate, 3, 2); |
Thomas Vachuska | c40d463 | 2015-04-09 16:55:03 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
| 52 | protected void createHosts() { |
| 53 | createHosts(deviceIds.get(0), infrastructurePorts); |
| 54 | createHosts(deviceIds.get(deviceCount - 2), infrastructurePorts); |
| 55 | } |
| 56 | |
| 57 | } |