Brian O'Connor

adding add-optical-intent command

Change-Id: I4f2dacb52739dbbbdbcbc59916998bd161fe3fe8
1 +/*
2 + * Licensed to the Apache Software Foundation (ASF) under one
3 + * or more contributor license agreements. See the NOTICE file
4 + * distributed with this work for additional information
5 + * regarding copyright ownership. The ASF licenses this file
6 + * to you under the Apache License, Version 2.0 (the
7 + * "License"); you may not use this file except in compliance
8 + * with the License. You may obtain a copy of the License at
9 + *
10 + * http://www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing,
13 + * software distributed under the License is distributed on an
14 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 + * KIND, either express or implied. See the License for the
16 + * specific language governing permissions and limitations
17 + * under the License.
18 + */
19 +package org.onlab.onos.cli.net;
20 +
21 +import static org.onlab.onos.net.DeviceId.deviceId;
22 +import static org.onlab.onos.net.PortNumber.portNumber;
23 +
24 +import org.apache.karaf.shell.commands.Argument;
25 +import org.apache.karaf.shell.commands.Command;
26 +import org.onlab.onos.net.ConnectPoint;
27 +import org.onlab.onos.net.DeviceId;
28 +import org.onlab.onos.net.PortNumber;
29 +import org.onlab.onos.net.intent.Intent;
30 +import org.onlab.onos.net.intent.IntentService;
31 +import org.onlab.onos.net.intent.OpticalConnectivityIntent;
32 +
33 +/**
34 + * Installs optical connectivity intents.
35 + */
36 +@Command(scope = "onos", name = "add-optical-intent",
37 + description = "Installs optical connectivity intent")
38 +public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
39 +
40 + @Argument(index = 0, name = "ingressDevice",
41 + description = "Ingress Device/Port Description",
42 + required = true, multiValued = false)
43 + String ingressDeviceString = null;
44 +
45 + @Argument(index = 1, name = "egressDevice",
46 + description = "Egress Device/Port Description",
47 + required = true, multiValued = false)
48 + String egressDeviceString = null;
49 +
50 + @Override
51 + protected void execute() {
52 + IntentService service = get(IntentService.class);
53 +
54 + DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
55 + PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
56 + ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
57 +
58 + DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
59 + PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
60 + ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
61 +
62 + Intent intent = new OpticalConnectivityIntent(appId(), ingress, egress);
63 + service.submit(intent);
64 + }
65 +
66 + /**
67 + * Extracts the port number portion of the ConnectPoint.
68 + *
69 + * @param deviceString string representing the device/port
70 + * @return port number as a string, empty string if the port is not found
71 + */
72 + private String getPortNumber(String deviceString) {
73 + int slash = deviceString.indexOf('/');
74 + if (slash <= 0) {
75 + return "";
76 + }
77 + return deviceString.substring(slash + 1, deviceString.length());
78 + }
79 +
80 + /**
81 + * Extracts the device ID portion of the ConnectPoint.
82 + *
83 + * @param deviceString string representing the device/port
84 + * @return device ID string
85 + */
86 + private String getDeviceId(String deviceString) {
87 + int slash = deviceString.indexOf('/');
88 + if (slash <= 0) {
89 + return "";
90 + }
91 + return deviceString.substring(0, slash);
92 + }
93 +}
...@@ -119,6 +119,14 @@ ...@@ -119,6 +119,14 @@
119 </optional-completers> 119 </optional-completers>
120 </command> 120 </command>
121 <command> 121 <command>
122 + <action class="org.onlab.onos.cli.net.AddOpticalIntentCommand"/>
123 + <completers>
124 + <ref component-id="connectPointCompleter"/>
125 + <ref component-id="connectPointCompleter"/>
126 + <null/>
127 + </completers>
128 + </command>
129 + <command>
122 <action class="org.onlab.onos.cli.net.GetStatistics"/> 130 <action class="org.onlab.onos.cli.net.GetStatistics"/>
123 <completers> 131 <completers>
124 <ref component-id="connectPointCompleter"/> 132 <ref component-id="connectPointCompleter"/>
......