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