blob: ad8954eee035d64d530a6df40819a326e8fd08a8 [file] [log] [blame]
Yuta HIGUCHIa1071722016-12-07 20:21:16 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yuta HIGUCHIa1071722016-12-07 20:21:16 -08003 *
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.cli.net;
17
18import java.util.Optional;
19
Ray Milkeyd84f89b2018-08-17 14:54:17 -070020import org.apache.karaf.shell.api.action.Argument;
21import org.apache.karaf.shell.api.action.Command;
Ray Milkey0068fd02018-10-11 15:45:39 -070022import org.apache.karaf.shell.api.action.Completion;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070023import org.apache.karaf.shell.api.action.lifecycle.Service;
24import org.apache.karaf.shell.api.action.Option;
Yuta HIGUCHIa1071722016-12-07 20:21:16 -080025import org.onosproject.cli.AbstractShellCommand;
26import org.onosproject.net.DeviceId;
27import org.onosproject.net.intent.Intent;
28import org.onosproject.net.intent.IntentService;
29import org.onosproject.net.intent.Key;
30import org.onosproject.net.intent.ProtectedTransportIntent;
31
32/**
33 * Installs ProtectedTransportIntent.
34 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070035@Service
Yuta HIGUCHIa1071722016-12-07 20:21:16 -080036@Command(scope = "onos", name = "add-protected-transport",
37 description = "Adds ProtectedTransportIntent")
38public 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 Milkey0068fd02018-10-11 15:45:39 -070049 @Completion(DeviceIdCompleter.class)
Yuta HIGUCHIa1071722016-12-07 20:21:16 -080050 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 Milkey0068fd02018-10-11 15:45:39 -070055 @Completion(DeviceIdCompleter.class)
Yuta HIGUCHIa1071722016-12-07 20:21:16 -080056 private String deviceId2Str = null;
57
58 private IntentService intentService;
59
60 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070061 protected void doExecute() {
Yuta HIGUCHIa1071722016-12-07 20:21:16 -080062 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}