blob: a70550eec6766c5f38e4304287040e5061c85202 [file] [log] [blame]
Brian O'Connor5296b322014-10-23 14:59:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Brian O'Connor5296b322014-10-23 14:59:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Brian O'Connor5296b322014-10-23 14:59:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Brian O'Connor5296b322014-10-23 14:59:05 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli.net;
Brian O'Connor5296b322014-10-23 14:59:05 -070017
Brian O'Connorabafb502014-12-02 22:26:20 -080018import static org.onosproject.net.DeviceId.deviceId;
19import static org.onosproject.net.PortNumber.portNumber;
Brian O'Connor5296b322014-10-23 14:59:05 -070020
21import org.apache.karaf.shell.commands.Argument;
22import org.apache.karaf.shell.commands.Command;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.PortNumber;
26import org.onosproject.net.intent.Intent;
27import org.onosproject.net.intent.IntentService;
28import org.onosproject.net.intent.OpticalConnectivityIntent;
Brian O'Connor5296b322014-10-23 14:59:05 -070029
30/**
31 * Installs optical connectivity intents.
32 */
33@Command(scope = "onos", name = "add-optical-intent",
34 description = "Installs optical connectivity intent")
35public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
36
37 @Argument(index = 0, name = "ingressDevice",
38 description = "Ingress Device/Port Description",
39 required = true, multiValued = false)
40 String ingressDeviceString = null;
41
42 @Argument(index = 1, name = "egressDevice",
43 description = "Egress Device/Port Description",
44 required = true, multiValued = false)
45 String egressDeviceString = null;
46
47 @Override
48 protected void execute() {
49 IntentService service = get(IntentService.class);
50
51 DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
52 PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
53 ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
54
55 DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
56 PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
57 ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
58
59 Intent intent = new OpticalConnectivityIntent(appId(), ingress, egress);
60 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080061 print("Optical intent submitted:\n%s", intent.toString());
Brian O'Connor5296b322014-10-23 14:59:05 -070062 }
63
64 /**
65 * Extracts the port number portion of the ConnectPoint.
66 *
67 * @param deviceString string representing the device/port
68 * @return port number as a string, empty string if the port is not found
69 */
70 private String getPortNumber(String deviceString) {
71 int slash = deviceString.indexOf('/');
72 if (slash <= 0) {
73 return "";
74 }
75 return deviceString.substring(slash + 1, deviceString.length());
76 }
77
78 /**
79 * Extracts the device ID portion of the ConnectPoint.
80 *
81 * @param deviceString string representing the device/port
82 * @return device ID string
83 */
84 private String getDeviceId(String deviceString) {
85 int slash = deviceString.indexOf('/');
86 if (slash <= 0) {
87 return "";
88 }
89 return deviceString.substring(0, slash);
90 }
91}