blob: fc20f3e2d2383550c7a5a0b6327641fa1c9e840f [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 Leenheer88194c32015-05-29 22:10:59 -070023import org.onosproject.net.DeviceId;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070024import org.onosproject.net.OduSignalType;
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070025import org.onosproject.net.Port;
26import org.onosproject.net.device.DeviceService;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.net.intent.Intent;
28import org.onosproject.net.intent.IntentService;
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070029import org.onosproject.net.intent.OpticalCircuitIntent;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.net.intent.OpticalConnectivityIntent;
Brian O'Connor5296b322014-10-23 14:59:05 -070031
Marc De Leenheer88194c32015-05-29 22:10:59 -070032import java.util.List;
33
34import static com.google.common.base.Preconditions.checkArgument;
35
Brian O'Connor5296b322014-10-23 14:59:05 -070036/**
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070037 * Installs optical connectivity or circuit intents, depending on given port types.
Brian O'Connor5296b322014-10-23 14:59:05 -070038 */
39@Command(scope = "onos", name = "add-optical-intent",
40 description = "Installs optical connectivity intent")
41public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
42
43 @Argument(index = 0, name = "ingressDevice",
44 description = "Ingress Device/Port Description",
45 required = true, multiValued = false)
46 String ingressDeviceString = null;
47
48 @Argument(index = 1, name = "egressDevice",
49 description = "Egress Device/Port Description",
50 required = true, multiValued = false)
51 String egressDeviceString = null;
Marc De Leenheer4a1c1fa2015-06-01 18:08:56 -070052 // TODO: add parameter for uni/bidirectional intents
Brian O'Connor5296b322014-10-23 14:59:05 -070053
Marc De Leenheer88194c32015-05-29 22:10:59 -070054 private ConnectPoint createConnectPoint(String devicePortString) {
55 String[] splitted = devicePortString.split("/");
56
57 checkArgument(splitted.length == 2,
58 "Connect point must be in \"deviceUri/portNumber\" format");
59
60 DeviceId deviceId = DeviceId.deviceId(splitted[0]);
61
62 DeviceService deviceService = get(DeviceService.class);
63
64 List<Port> ports = deviceService.getPorts(deviceId);
65
66 for (Port port : ports) {
67 if (splitted[1].equals(port.number().name())) {
68 return new ConnectPoint(deviceId, port.number());
69 }
70 }
71
72 return null;
73 }
74
Brian O'Connor5296b322014-10-23 14:59:05 -070075 @Override
76 protected void execute() {
77 IntentService service = get(IntentService.class);
78
Marc De Leenheer88194c32015-05-29 22:10:59 -070079 ConnectPoint ingress = createConnectPoint(ingressDeviceString);
80 ConnectPoint egress = createConnectPoint(egressDeviceString);
Brian O'Connor5296b322014-10-23 14:59:05 -070081
Marc De Leenheer88194c32015-05-29 22:10:59 -070082 if (ingress == null || egress == null) {
83 print("Could not create optical intent");
84 }
Brian O'Connor5296b322014-10-23 14:59:05 -070085
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070086 DeviceService deviceService = get(DeviceService.class);
87 Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port());
88 Port dstPort = deviceService.getPort(egress.deviceId(), egress.port());
89
90 Intent intent;
91 // FIXME: Hardcoded signal types
92 if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
93 intent = OpticalCircuitIntent.builder()
94 .appId(appId())
95 .key(key())
96 .src(ingress)
97 .dst(egress)
98 .signalType(OduCltPort.SignalType.CLT_10GBE)
99 .build();
100 } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
101 intent = OpticalConnectivityIntent.builder()
102 .appId(appId())
103 .key(key())
104 .src(ingress)
105 .dst(egress)
106 .signalType(OduSignalType.ODU4)
107 .build();
108 } else {
109 print("Unable to create optical intent between connect points {} and {}", ingress, egress);
110 return;
111 }
112
Brian O'Connor5296b322014-10-23 14:59:05 -0700113 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -0800114 print("Optical intent submitted:\n%s", intent.toString());
Brian O'Connor5296b322014-10-23 14:59:05 -0700115 }
Brian O'Connor5296b322014-10-23 14:59:05 -0700116}