Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [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 | |
| 17 | package org.onosproject.provider.nil.cli; |
| 18 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 19 | import org.apache.karaf.shell.api.action.Argument; |
| 20 | import org.apache.karaf.shell.api.action.Command; |
| 21 | import org.apache.karaf.shell.api.action.Option; |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 23 | import org.onosproject.net.ConnectPoint; |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 24 | import org.onosproject.net.Link; |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 25 | import org.onosproject.provider.nil.CustomTopologySimulator; |
| 26 | import org.onosproject.provider.nil.NullProviders; |
| 27 | import org.onosproject.provider.nil.TopologySimulator; |
| 28 | |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 29 | /** |
| 30 | * Adds a simulated link to the custom topology simulation. |
| 31 | */ |
Ray Milkey | 7a2dee5 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 32 | @Service |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 33 | @Command(scope = "onos", name = "null-create-link", |
| 34 | description = "Adds a simulated link to the custom topology simulation") |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 35 | public class CreateNullLink extends CreateNullEntity { |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 36 | |
| 37 | @Argument(index = 0, name = "type", description = "Link type, e.g. direct, indirect, optical", |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 38 | required = true) |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 39 | String type = null; |
| 40 | |
| 41 | @Argument(index = 1, name = "src", description = "Source device name", |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 42 | required = true) |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 43 | String src = null; |
| 44 | |
| 45 | @Argument(index = 2, name = "dst", description = "Destination device name", |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 46 | required = true) |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 47 | String dst = null; |
| 48 | |
Thomas Vachuska | b1906d2 | 2018-02-14 16:50:16 -0800 | [diff] [blame] | 49 | @Option(name = "-u", aliases = "--unidirectional", description = "Unidirectional link only") |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 50 | private boolean unidirectional = false; |
| 51 | |
| 52 | @Override |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 53 | protected void doExecute() { |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 54 | NullProviders service = get(NullProviders.class); |
| 55 | |
| 56 | TopologySimulator simulator = service.currentSimulator(); |
| 57 | if (!(simulator instanceof CustomTopologySimulator)) { |
| 58 | error("Custom topology simulator is not active."); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | CustomTopologySimulator sim = (CustomTopologySimulator) simulator; |
Thomas Vachuska | 4407a7e | 2016-07-02 12:38:01 +0200 | [diff] [blame] | 63 | ConnectPoint one = findAvailablePort(sim.deviceId(src), null); |
| 64 | ConnectPoint two = findAvailablePort(sim.deviceId(dst), one); |
Sean Condon | 8d338b5 | 2019-03-21 20:20:58 +0000 | [diff] [blame] | 65 | if (one == null) { |
| 66 | error("\u001B[1;31mLink not created - no location (free port) available on src %s\u001B[0m", src); |
| 67 | return; |
| 68 | } else if (two == null) { |
| 69 | error("\u001B[1;31mLink not created - no location (free port) available on dst %s\u001B[0m", dst); |
| 70 | return; |
| 71 | } |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 72 | sim.createLink(one, two, Link.Type.valueOf(type.toUpperCase()), !unidirectional); |
| 73 | } |
| 74 | |
Thomas Vachuska | 5c6ed22 | 2016-06-29 11:02:22 +0200 | [diff] [blame] | 75 | } |