blob: 7360cecabcd6171d4713be0c4f273ce2591e5d25 [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;
22import org.apache.karaf.shell.api.action.lifecycle.Service;
23import org.apache.karaf.shell.api.action.Option;
Yuta HIGUCHIa1071722016-12-07 20:21:16 -080024import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.intent.Intent;
27import org.onosproject.net.intent.IntentService;
28import org.onosproject.net.intent.Key;
29import org.onosproject.net.intent.ProtectedTransportIntent;
30
31/**
32 * Installs ProtectedTransportIntent.
33 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070034@Service
Yuta HIGUCHIa1071722016-12-07 20:21:16 -080035@Command(scope = "onos", name = "add-protected-transport",
36 description = "Adds ProtectedTransportIntent")
37public class AddProtectedTransportIntentCommand
38 extends AbstractShellCommand {
39
40 @Option(name = "--key", aliases = "-k",
41 description = "Intent key",
42 required = false, multiValued = false)
43 private String keyStr = null;
44
45 @Argument(index = 0, name = "deviceId1",
46 description = "First Device ID of protected path",
47 required = true, multiValued = false)
48 private String deviceId1Str = null;
49
50 @Argument(index = 1, name = "deviceId2",
51 description = "Second Device ID of protected path",
52 required = true, multiValued = false)
53 private String deviceId2Str = null;
54
55 private IntentService intentService;
56
57 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070058 protected void doExecute() {
Yuta HIGUCHIa1071722016-12-07 20:21:16 -080059 intentService = get(IntentService.class);
60
61 DeviceId did1 = DeviceId.deviceId(deviceId1Str);
62 DeviceId did2 = DeviceId.deviceId(deviceId2Str);
63
64 Intent intent;
65 intent = ProtectedTransportIntent.builder()
66 .key(key())
67 .appId(appId())
68 .one(did1)
69 .two(did2)
70 .build();
71
72 print("Submitting: %s", intent);
73 intentService.submit(intent);
74 }
75
76 /**
77 * Returns Key if specified in the option.
78 *
79 * @return Key instance or null
80 */
81 protected Key key() {
82 return Optional.ofNullable(keyStr)
83 .map(s -> Key.of(s, appId()))
84 .orElse(null);
85 }
86}