Yuta HIGUCHI | a107172 | 2016-12-07 20:21:16 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Yuta HIGUCHI | a107172 | 2016-12-07 20:21:16 -0800 | [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.cli.net; |
| 17 | |
| 18 | import java.util.Optional; |
| 19 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Argument; |
| 21 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.Completion; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 23 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 24 | import org.apache.karaf.shell.api.action.Option; |
Yuta HIGUCHI | a107172 | 2016-12-07 20:21:16 -0800 | [diff] [blame] | 25 | import org.onosproject.cli.AbstractShellCommand; |
| 26 | import org.onosproject.net.DeviceId; |
| 27 | import org.onosproject.net.intent.Intent; |
| 28 | import org.onosproject.net.intent.IntentService; |
| 29 | import org.onosproject.net.intent.Key; |
| 30 | import org.onosproject.net.intent.ProtectedTransportIntent; |
| 31 | |
| 32 | /** |
| 33 | * Installs ProtectedTransportIntent. |
| 34 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 35 | @Service |
Yuta HIGUCHI | a107172 | 2016-12-07 20:21:16 -0800 | [diff] [blame] | 36 | @Command(scope = "onos", name = "add-protected-transport", |
| 37 | description = "Adds ProtectedTransportIntent") |
| 38 | public class AddProtectedTransportIntentCommand |
| 39 | extends AbstractShellCommand { |
| 40 | |
| 41 | @Option(name = "--key", aliases = "-k", |
| 42 | description = "Intent key", |
| 43 | required = false, multiValued = false) |
| 44 | private String keyStr = null; |
| 45 | |
| 46 | @Argument(index = 0, name = "deviceId1", |
| 47 | description = "First Device ID of protected path", |
| 48 | required = true, multiValued = false) |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 49 | @Completion(DeviceIdCompleter.class) |
Yuta HIGUCHI | a107172 | 2016-12-07 20:21:16 -0800 | [diff] [blame] | 50 | private String deviceId1Str = null; |
| 51 | |
| 52 | @Argument(index = 1, name = "deviceId2", |
| 53 | description = "Second Device ID of protected path", |
| 54 | required = true, multiValued = false) |
Ray Milkey | 0068fd0 | 2018-10-11 15:45:39 -0700 | [diff] [blame] | 55 | @Completion(DeviceIdCompleter.class) |
Yuta HIGUCHI | a107172 | 2016-12-07 20:21:16 -0800 | [diff] [blame] | 56 | private String deviceId2Str = null; |
| 57 | |
| 58 | private IntentService intentService; |
| 59 | |
| 60 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 61 | protected void doExecute() { |
Yuta HIGUCHI | a107172 | 2016-12-07 20:21:16 -0800 | [diff] [blame] | 62 | intentService = get(IntentService.class); |
| 63 | |
| 64 | DeviceId did1 = DeviceId.deviceId(deviceId1Str); |
| 65 | DeviceId did2 = DeviceId.deviceId(deviceId2Str); |
| 66 | |
| 67 | Intent intent; |
| 68 | intent = ProtectedTransportIntent.builder() |
| 69 | .key(key()) |
| 70 | .appId(appId()) |
| 71 | .one(did1) |
| 72 | .two(did2) |
| 73 | .build(); |
| 74 | |
| 75 | print("Submitting: %s", intent); |
| 76 | intentService.submit(intent); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns Key if specified in the option. |
| 81 | * |
| 82 | * @return Key instance or null |
| 83 | */ |
| 84 | protected Key key() { |
| 85 | return Optional.ofNullable(keyStr) |
| 86 | .map(s -> Key.of(s, appId())) |
| 87 | .orElse(null); |
| 88 | } |
| 89 | } |