blob: 57c410098c50844cb5e6ddce649e2cb8c70bf2df [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;
Aaron Kruglikov0a4da0d2015-06-10 14:40:48 -070020import org.apache.karaf.shell.commands.Option;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.ConnectPoint;
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070022import org.onosproject.net.OchPort;
23import org.onosproject.net.OduCltPort;
Marc De Leenheer88194c32015-05-29 22:10:59 -070024import org.onosproject.net.DeviceId;
Marc De Leenheer8c2caac2015-05-28 16:37:33 -070025import org.onosproject.net.OduSignalType;
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070026import org.onosproject.net.Port;
27import org.onosproject.net.device.DeviceService;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.intent.Intent;
29import org.onosproject.net.intent.IntentService;
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070030import org.onosproject.net.intent.OpticalCircuitIntent;
Brian O'Connorabafb502014-12-02 22:26:20 -080031import org.onosproject.net.intent.OpticalConnectivityIntent;
Brian O'Connor5296b322014-10-23 14:59:05 -070032
Marc De Leenheer88194c32015-05-29 22:10:59 -070033import java.util.List;
34
35import static com.google.common.base.Preconditions.checkArgument;
36
Brian O'Connor5296b322014-10-23 14:59:05 -070037/**
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070038 * Installs optical connectivity or circuit intents, depending on given port types.
Brian O'Connor5296b322014-10-23 14:59:05 -070039 */
40@Command(scope = "onos", name = "add-optical-intent",
41 description = "Installs optical connectivity intent")
42public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
43
44 @Argument(index = 0, name = "ingressDevice",
45 description = "Ingress Device/Port Description",
46 required = true, multiValued = false)
47 String ingressDeviceString = null;
48
49 @Argument(index = 1, name = "egressDevice",
50 description = "Egress Device/Port Description",
51 required = true, multiValued = false)
52 String egressDeviceString = null;
Aaron Kruglikov0a4da0d2015-06-10 14:40:48 -070053
54 @Option(name = "-b", aliases = "--bidirectional",
55 description = "If this argument is passed the optical link created will be bidirectional, " +
56 "else the link will be unidirectional.",
57 required = false, multiValued = false)
58 private boolean bidirectional = false;
59
Brian O'Connor5296b322014-10-23 14:59:05 -070060
Marc De Leenheer88194c32015-05-29 22:10:59 -070061 private ConnectPoint createConnectPoint(String devicePortString) {
62 String[] splitted = devicePortString.split("/");
63
64 checkArgument(splitted.length == 2,
65 "Connect point must be in \"deviceUri/portNumber\" format");
66
67 DeviceId deviceId = DeviceId.deviceId(splitted[0]);
68
69 DeviceService deviceService = get(DeviceService.class);
70
71 List<Port> ports = deviceService.getPorts(deviceId);
72
73 for (Port port : ports) {
74 if (splitted[1].equals(port.number().name())) {
75 return new ConnectPoint(deviceId, port.number());
76 }
77 }
78
79 return null;
80 }
81
Brian O'Connor5296b322014-10-23 14:59:05 -070082 @Override
83 protected void execute() {
84 IntentService service = get(IntentService.class);
85
Marc De Leenheer88194c32015-05-29 22:10:59 -070086 ConnectPoint ingress = createConnectPoint(ingressDeviceString);
87 ConnectPoint egress = createConnectPoint(egressDeviceString);
Brian O'Connor5296b322014-10-23 14:59:05 -070088
Marc De Leenheer88194c32015-05-29 22:10:59 -070089 if (ingress == null || egress == null) {
90 print("Could not create optical intent");
91 }
Brian O'Connor5296b322014-10-23 14:59:05 -070092
Marc De Leenheer9f7d1892015-05-30 13:22:24 -070093 DeviceService deviceService = get(DeviceService.class);
94 Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port());
95 Port dstPort = deviceService.getPort(egress.deviceId(), egress.port());
96
97 Intent intent;
98 // FIXME: Hardcoded signal types
99 if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
100 intent = OpticalCircuitIntent.builder()
101 .appId(appId())
102 .key(key())
103 .src(ingress)
104 .dst(egress)
105 .signalType(OduCltPort.SignalType.CLT_10GBE)
Aaron Kruglikov0a4da0d2015-06-10 14:40:48 -0700106 .bidirectional(bidirectional)
Marc De Leenheer9f7d1892015-05-30 13:22:24 -0700107 .build();
108 } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
109 intent = OpticalConnectivityIntent.builder()
110 .appId(appId())
111 .key(key())
112 .src(ingress)
113 .dst(egress)
114 .signalType(OduSignalType.ODU4)
Aaron Kruglikov0a4da0d2015-06-10 14:40:48 -0700115 .bidirectional(bidirectional)
Marc De Leenheer9f7d1892015-05-30 13:22:24 -0700116 .build();
117 } else {
118 print("Unable to create optical intent between connect points {} and {}", ingress, egress);
119 return;
120 }
121
Brian O'Connor5296b322014-10-23 14:59:05 -0700122 service.submit(intent);
Ray Milkeycb33a132015-02-02 10:05:12 -0800123 print("Optical intent submitted:\n%s", intent.toString());
Brian O'Connor5296b322014-10-23 14:59:05 -0700124 }
Brian O'Connor5296b322014-10-23 14:59:05 -0700125}