blob: 97341d7616ec3e12ac3ecd0de7453ca7e48d0990 [file] [log] [blame]
Brian O'Connor5296b322014-10-23 14:59:05 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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'Connor5296b322014-10-23 14:59:05 -070018import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.ConnectPoint;
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070021import org.onosproject.net.OchPort;
22import org.onosproject.net.OduCltPort;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070023import org.onosproject.net.OduSignalType;
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070024import org.onosproject.net.Port;
25import org.onosproject.net.device.DeviceService;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import org.onosproject.net.intent.Intent;
27import org.onosproject.net.intent.IntentService;
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070028import org.onosproject.net.intent.OpticalCircuitIntent;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.intent.OpticalConnectivityIntent;
Brian O'Connor5296b322014-10-23 14:59:05 -070030
31/**
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070032 * Installs optical connectivity or circuit intents, depending on given port types.
Brian O'Connor5296b322014-10-23 14:59:05 -070033 */
34@Command(scope = "onos", name = "add-optical-intent",
35 description = "Installs optical connectivity intent")
36public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
37
38 @Argument(index = 0, name = "ingressDevice",
39 description = "Ingress Device/Port Description",
40 required = true, multiValued = false)
41 String ingressDeviceString = null;
42
43 @Argument(index = 1, name = "egressDevice",
44 description = "Egress Device/Port Description",
45 required = true, multiValued = false)
46 String egressDeviceString = null;
47
48 @Override
49 protected void execute() {
50 IntentService service = get(IntentService.class);
51
Jonathan Hartc3af35a2015-04-30 22:20:29 -070052 ConnectPoint ingress = ConnectPoint.deviceConnectPoint(ingressDeviceString);
Brian O'Connor5296b322014-10-23 14:59:05 -070053
Jonathan Hartc3af35a2015-04-30 22:20:29 -070054 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
Brian O'Connor5296b322014-10-23 14:59:05 -070055
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070056 DeviceService deviceService = get(DeviceService.class);
57 Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port());
58 Port dstPort = deviceService.getPort(egress.deviceId(), egress.port());
59
60 Intent intent;
61 // FIXME: Hardcoded signal types
62 if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
63 intent = OpticalCircuitIntent.builder()
64 .appId(appId())
65 .key(key())
66 .src(ingress)
67 .dst(egress)
68 .signalType(OduCltPort.SignalType.CLT_10GBE)
69 .build();
70 } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
71 intent = OpticalConnectivityIntent.builder()
72 .appId(appId())
73 .key(key())
74 .src(ingress)
75 .dst(egress)
76 .signalType(OduSignalType.ODU4)
77 .build();
78 } else {
79 print("Unable to create optical intent between connect points {} and {}", ingress, egress);
80 return;
81 }
82
Brian O'Connor5296b322014-10-23 14:59:05 -070083 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -080084 print("Optical intent submitted:\n%s", intent.toString());
Brian O'Connor5296b322014-10-23 14:59:05 -070085 }
Brian O'Connor5296b322014-10-23 14:59:05 -070086}