Marc De Leenheer
Committed by Gerrit Code Review

Driver and flow stats handling for Calient fiber switch S160.

Bump loxigen to 0.4.1.onos-SNAPSHOT.

Change-Id: Ieb8aa4fe716e12f89b83770eff617561f30cdd08
...@@ -26,7 +26,7 @@ public interface Device extends Element { ...@@ -26,7 +26,7 @@ public interface Device extends Element {
26 * Coarse classification of the type of the infrastructure device. 26 * Coarse classification of the type of the infrastructure device.
27 */ 27 */
28 public enum Type { 28 public enum Type {
29 - SWITCH, ROUTER, ROADM, OTN, ROADM_OTN, FIREWALL, BALANCER, IPS, IDS, CONTROLLER, VIRTUAL, OTHER 29 + SWITCH, ROUTER, ROADM, OTN, ROADM_OTN, FIREWALL, BALANCER, IPS, IDS, CONTROLLER, VIRTUAL, FIBER_SWITCH, OTHER
30 } 30 }
31 31
32 /** 32 /**
......
...@@ -194,8 +194,7 @@ public class PacketManager ...@@ -194,8 +194,7 @@ public class PacketManager
194 * @param request the packet request 194 * @param request the packet request
195 */ 195 */
196 private void pushRule(Device device, PacketRequest request) { 196 private void pushRule(Device device, PacketRequest request) {
197 - // Everything is pre-provisioned on ROADMs 197 + if (!device.type().equals(Device.Type.SWITCH)) {
198 - if (device.type().equals(Device.Type.ROADM)) {
199 return; 198 return;
200 } 199 }
201 200
...@@ -217,8 +216,7 @@ public class PacketManager ...@@ -217,8 +216,7 @@ public class PacketManager
217 * @param request the packet request 216 * @param request the packet request
218 */ 217 */
219 private void removeRule(Device device, PacketRequest request) { 218 private void removeRule(Device device, PacketRequest request) {
220 - // Everything is pre-provisioned on ROADMs 219 + if (!device.type().equals(Device.Type.SWITCH)) {
221 - if (device.type().equals(Device.Type.ROADM)) {
222 return; 220 return;
223 } 221 }
224 222
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * 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
7 + *
8 + * 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.
15 + */
16 +package org.onosproject.driver.handshaker;
17 +
18 +import com.google.common.collect.ImmutableList;
19 +import com.google.common.collect.ImmutableSet;
20 +import org.onosproject.net.Device;
21 +import org.onosproject.openflow.controller.OpenFlowOpticalSwitch;
22 +import org.onosproject.openflow.controller.PortDescPropertyType;
23 +import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
24 +import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted;
25 +import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted;
26 +import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted;
27 +import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsRequest;
28 +import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry;
29 +import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsReply;
30 +import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsRequest;
31 +import org.projectfloodlight.openflow.protocol.OFFlowStatsRequest;
32 +import org.projectfloodlight.openflow.protocol.OFMessage;
33 +import org.projectfloodlight.openflow.protocol.OFObject;
34 +import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
35 +import org.projectfloodlight.openflow.protocol.OFStatsRequest;
36 +import org.projectfloodlight.openflow.protocol.OFType;
37 +import org.projectfloodlight.openflow.types.OFPort;
38 +import org.projectfloodlight.openflow.types.TableId;
39 +
40 +import java.io.IOException;
41 +import java.util.ArrayList;
42 +import java.util.List;
43 +import java.util.Set;
44 +import java.util.concurrent.atomic.AtomicBoolean;
45 +
46 +public class CalientFiberSwitchHandshaker extends AbstractOpenFlowSwitch implements OpenFlowOpticalSwitch {
47 +
48 + private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false);
49 + private List<OFCalientPortDescStatsEntry> fiberPorts = new ArrayList<>();
50 +
51 +
52 + @Override
53 + public Boolean supportNxRole() {
54 + return false;
55 + }
56 +
57 + @Override
58 + public void startDriverHandshake() {
59 + log.warn("Starting driver handshake for sw {}", getStringId());
60 + if (startDriverHandshakeCalled) {
61 + throw new SwitchDriverSubHandshakeAlreadyStarted();
62 + }
63 + startDriverHandshakeCalled = true;
64 + try {
65 + sendHandshakeOFExperimenterPortDescRequest();
66 + } catch (IOException e) {
67 + log.error("Exception while sending experimenter port desc:", e.getMessage());
68 + e.printStackTrace();
69 + }
70 +
71 + }
72 +
73 + private void sendHandshakeOFExperimenterPortDescRequest() throws IOException {
74 + // send multi part message for port description for optical switches
75 + OFCalientPortDescStatsRequest portsRequest = factory()
76 + .buildCalientPortDescStatsRequest()
77 + .build();
78 + log.warn("Sending experimenter port description message {}",
79 + portsRequest.toString());
80 + this.sendHandshakeMessage(portsRequest);
81 + }
82 +
83 + @Override
84 + public boolean isDriverHandshakeComplete() {
85 + return driverHandshakeComplete.get();
86 + }
87 +
88 + @Override
89 + public void processDriverHandshakeMessage(OFMessage m) {
90 + if (!startDriverHandshakeCalled) {
91 + throw new SwitchDriverSubHandshakeNotStarted();
92 + }
93 + if (driverHandshakeComplete.get()) {
94 + throw new SwitchDriverSubHandshakeCompleted(m);
95 + }
96 +
97 + switch (m.getType()) {
98 + case BARRIER_REPLY:
99 + break;
100 + case ERROR:
101 + log.error("Switch Error {} {}", getStringId(), m);
102 + break;
103 + case FEATURES_REPLY:
104 + break;
105 + case FLOW_REMOVED:
106 + break;
107 + case GET_ASYNC_REPLY:
108 + break;
109 + case PACKET_IN:
110 + break;
111 + case PORT_STATUS:
112 + break;
113 + case QUEUE_GET_CONFIG_REPLY:
114 + break;
115 + case ROLE_REPLY:
116 + break;
117 + case STATS_REPLY:
118 + log.warn("Received port desc reply");
119 + OFCalientPortDescStatsReply descStatsReply = (OFCalientPortDescStatsReply) m;
120 + fiberPorts.addAll(descStatsReply.getPortDesc());
121 + // Multi-part message
122 + if (!descStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
123 + driverHandshakeComplete.set(true);
124 + }
125 + break;
126 + default:
127 + log.warn("Received message {} during switch-driver " +
128 + "subhandshake " + "from switch {} ... " +
129 + "Ignoring message", m,
130 + getStringId());
131 +
132 + }
133 + }
134 +
135 + @Override
136 + public Device.Type deviceType() {
137 + return Device.Type.FIBER_SWITCH;
138 + }
139 +
140 + @Override
141 + public List<? extends OFObject> getPortsOf(PortDescPropertyType type) {
142 + return ImmutableList.copyOf(fiberPorts);
143 + }
144 +
145 + @Override
146 + public Set<PortDescPropertyType> getPortTypes() {
147 + return ImmutableSet.of(PortDescPropertyType.OPTICAL_TRANSPORT);
148 + }
149 +
150 + @Override
151 + public final void sendMsg(OFMessage m) {
152 + OFMessage newMsg = m;
153 +
154 + if (m.getType() == OFType.STATS_REQUEST) {
155 + OFStatsRequest sr = (OFStatsRequest) m;
156 + log.debug("Rebuilding stats request type {}", sr.getStatsType());
157 + switch (sr.getStatsType()) {
158 + case FLOW:
159 + OFCalientFlowStatsRequest request = this.factory().buildCalientFlowStatsRequest()
160 + .setCookie(((OFFlowStatsRequest) sr).getCookie())
161 + .setCookieMask(((OFFlowStatsRequest) sr).getCookieMask())
162 + .setMatch(this.factory().matchWildcardAll())
163 + .setOutGroup(((OFFlowStatsRequest) sr).getOutGroup().getGroupNumber())
164 + .setOutPort(OFPort.ANY)
165 + .setTableId(TableId.ALL)
166 + .setXid(sr.getXid())
167 + .setFlags(sr.getFlags())
168 + .build();
169 + newMsg = request;
170 + break;
171 + case PORT:
172 + // TODO
173 + break;
174 + default:
175 + break;
176 + }
177 + }
178 +
179 + super.sendMsg(newMsg);
180 + }
181 +}
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.driver.handshaker; 16 package org.onosproject.driver.handshaker;
17 17
18 +import org.onosproject.net.Device;
18 import org.onosproject.openflow.controller.OpenFlowOpticalSwitch; 19 import org.onosproject.openflow.controller.OpenFlowOpticalSwitch;
19 import org.onosproject.openflow.controller.PortDescPropertyType; 20 import org.onosproject.openflow.controller.PortDescPropertyType;
20 import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; 21 import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch;
...@@ -156,8 +157,8 @@ public class OFOpticalSwitchImplLINC13 ...@@ -156,8 +157,8 @@ public class OFOpticalSwitchImplLINC13
156 } 157 }
157 158
158 @Override 159 @Override
159 - public boolean isOptical() { 160 + public Device.Type deviceType() {
160 - return true; 161 + return Device.Type.ROADM;
161 } 162 }
162 163
163 @Override 164 @Override
......
...@@ -105,5 +105,11 @@ ...@@ -105,5 +105,11 @@
105 <behaviour api="org.onosproject.net.behaviour.Pipeliner" 105 <behaviour api="org.onosproject.net.behaviour.Pipeliner"
106 impl="org.onosproject.driver.pipeline.CpqdOFDPA1Pipeline"/> 106 impl="org.onosproject.driver.pipeline.CpqdOFDPA1Pipeline"/>
107 </driver> 107 </driver>
108 + <driver name="calient" extends="default"
109 + manufacturer="calient inc" hwVersion="calient hardware"
110 + swVersion="ocs switch">
111 + <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver"
112 + impl="org.onosproject.driver.handshaker.CalientFiberSwitchHandshaker"/>
113 + </driver>
108 </drivers> 114 </drivers>
109 115
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.openflow.controller; 16 package org.onosproject.openflow.controller;
17 17
18 +import org.onosproject.net.Device;
18 import org.projectfloodlight.openflow.protocol.OFFactory; 19 import org.projectfloodlight.openflow.protocol.OFFactory;
19 import org.projectfloodlight.openflow.protocol.OFMessage; 20 import org.projectfloodlight.openflow.protocol.OFMessage;
20 import org.projectfloodlight.openflow.protocol.OFPortDesc; 21 import org.projectfloodlight.openflow.protocol.OFPortDesc;
...@@ -136,11 +137,11 @@ public interface OpenFlowSwitch { ...@@ -136,11 +137,11 @@ public interface OpenFlowSwitch {
136 void returnRoleReply(RoleState requested, RoleState response); 137 void returnRoleReply(RoleState requested, RoleState response);
137 138
138 /** 139 /**
139 - * Indicates if this switch is optical. 140 + * Returns the switch device type.
140 * 141 *
141 - * @return true if optical 142 + * @return device type
142 */ 143 */
143 - boolean isOptical(); 144 + Device.Type deviceType();
144 145
145 /** 146 /**
146 * Identifies the channel used to communicate with the switch. 147 * Identifies the channel used to communicate with the switch.
......
...@@ -18,6 +18,7 @@ package org.onosproject.openflow.controller.driver; ...@@ -18,6 +18,7 @@ package org.onosproject.openflow.controller.driver;
18 18
19 import org.jboss.netty.channel.Channel; 19 import org.jboss.netty.channel.Channel;
20 import org.onlab.packet.IpAddress; 20 import org.onlab.packet.IpAddress;
21 +import org.onosproject.net.Device;
21 import org.onosproject.net.driver.AbstractHandlerBehaviour; 22 import org.onosproject.net.driver.AbstractHandlerBehaviour;
22 import org.onosproject.openflow.controller.Dpid; 23 import org.onosproject.openflow.controller.Dpid;
23 import org.onosproject.openflow.controller.RoleState; 24 import org.onosproject.openflow.controller.RoleState;
...@@ -95,7 +96,7 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour ...@@ -95,7 +96,7 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour
95 } 96 }
96 97
97 @Override 98 @Override
98 - public final void sendMsg(OFMessage m) { 99 + public void sendMsg(OFMessage m) {
99 if (role == RoleState.MASTER && channel.isConnected()) { 100 if (role == RoleState.MASTER && channel.isConnected()) {
100 channel.write(Collections.singletonList(m)); 101 channel.write(Collections.singletonList(m));
101 } 102 }
...@@ -413,8 +414,8 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour ...@@ -413,8 +414,8 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour
413 414
414 415
415 @Override 416 @Override
416 - public boolean isOptical() { 417 + public Device.Type deviceType() {
417 - return false; 418 + return Device.Type.SWITCH;
418 } 419 }
419 420
420 421
......
...@@ -38,6 +38,8 @@ import org.onosproject.openflow.controller.PacketListener; ...@@ -38,6 +38,8 @@ import org.onosproject.openflow.controller.PacketListener;
38 import org.onosproject.openflow.controller.RoleState; 38 import org.onosproject.openflow.controller.RoleState;
39 import org.onosproject.openflow.controller.driver.OpenFlowAgent; 39 import org.onosproject.openflow.controller.driver.OpenFlowAgent;
40 import org.osgi.service.component.ComponentContext; 40 import org.osgi.service.component.ComponentContext;
41 +import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsEntry;
42 +import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsReply;
41 import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; 43 import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus;
42 import org.projectfloodlight.openflow.protocol.OFExperimenter; 44 import org.projectfloodlight.openflow.protocol.OFExperimenter;
43 import org.projectfloodlight.openflow.protocol.OFFactories; 45 import org.projectfloodlight.openflow.protocol.OFFactories;
...@@ -55,12 +57,17 @@ import org.projectfloodlight.openflow.protocol.OFPortStatsReply; ...@@ -55,12 +57,17 @@ import org.projectfloodlight.openflow.protocol.OFPortStatsReply;
55 import org.projectfloodlight.openflow.protocol.OFPortStatus; 57 import org.projectfloodlight.openflow.protocol.OFPortStatus;
56 import org.projectfloodlight.openflow.protocol.OFStatsReply; 58 import org.projectfloodlight.openflow.protocol.OFStatsReply;
57 import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; 59 import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
60 +import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
61 +import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
58 import org.slf4j.Logger; 62 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory; 63 import org.slf4j.LoggerFactory;
60 64
61 import java.util.Collection; 65 import java.util.Collection;
66 +import java.util.Collections;
62 import java.util.Dictionary; 67 import java.util.Dictionary;
63 import java.util.HashMap; 68 import java.util.HashMap;
69 +import java.util.LinkedList;
70 +import java.util.List;
64 import java.util.Map; 71 import java.util.Map;
65 import java.util.Set; 72 import java.util.Set;
66 import java.util.concurrent.ConcurrentHashMap; 73 import java.util.concurrent.ConcurrentHashMap;
...@@ -299,16 +306,63 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -299,16 +306,63 @@ public class OpenFlowControllerImpl implements OpenFlowController {
299 case PORT: 306 case PORT:
300 executorMsgs.submit(new OFMessageHandler(dpid, reply)); 307 executorMsgs.submit(new OFMessageHandler(dpid, reply));
301 break; 308 break;
302 - default: 309 + case EXPERIMENTER:
310 + if (reply instanceof OFCalientFlowStatsReply) {
311 + // Convert Calient flow statistics to regular flow stats
312 + // TODO: parse remaining fields such as power levels etc. when we have proper monitoring API
313 + OFFlowStatsReply.Builder fsr = getSwitch(dpid).factory().buildFlowStatsReply();
314 + List<OFFlowStatsEntry> entries = new LinkedList<>();
315 + for (OFCalientFlowStatsEntry entry : ((OFCalientFlowStatsReply) msg).getEntries()) {
316 +
317 + // Single instruction, i.e., output to port
318 + OFActionOutput action = OFFactories
319 + .getFactory(msg.getVersion())
320 + .actions()
321 + .buildOutput()
322 + .setPort(entry.getOutPort())
323 + .build();
324 + OFInstruction instruction = OFFactories
325 + .getFactory(msg.getVersion())
326 + .instructions()
327 + .applyActions(Collections.singletonList(action));
328 + OFFlowStatsEntry fs = getSwitch(dpid).factory().buildFlowStatsEntry()
329 + .setMatch(entry.getMatch())
330 + .setTableId(entry.getTableId())
331 + .setDurationSec(entry.getDurationSec())
332 + .setDurationNsec(entry.getDurationNsec())
333 + .setPriority(entry.getPriority())
334 + .setIdleTimeout(entry.getIdleTimeout())
335 + .setHardTimeout(entry.getHardTimeout())
336 + .setFlags(entry.getFlags())
337 + .setCookie(entry.getCookie())
338 + .setInstructions(Collections.singletonList(instruction))
339 + .build();
340 + entries.add(fs);
341 + }
342 + fsr.setEntries(entries);
343 +
344 + flowStats = publishFlowStats(dpid, fsr.build());
345 + if (flowStats != null) {
346 + OFFlowStatsReply.Builder rep =
347 + OFFactories.getFactory(msg.getVersion()).buildFlowStatsReply();
348 + rep.setEntries(Lists.newLinkedList(flowStats));
349 + executorMsgs.submit(new OFMessageHandler(dpid, rep.build()));
350 + }
351 + } else {
303 log.warn("Unsupported stats type : {}", reply.getStatsType()); 352 log.warn("Unsupported stats type : {}", reply.getStatsType());
304 } 353 }
305 break; 354 break;
355 + default:
356 + break;
357 + }
358 + break;
306 case BARRIER_REPLY: 359 case BARRIER_REPLY:
307 executorBarrier.submit(new OFMessageHandler(dpid, msg)); 360 executorBarrier.submit(new OFMessageHandler(dpid, msg));
308 break; 361 break;
309 case EXPERIMENTER: 362 case EXPERIMENTER:
310 - // Handle optical port stats 363 + long experimenter = ((OFExperimenter) msg).getExperimenter();
311 - if (((OFExperimenter) msg).getExperimenter() == 0x748771) { 364 + if (experimenter == 0x748771) {
365 + // LINC-OE port stats
312 OFCircuitPortStatus circuitPortStatus = (OFCircuitPortStatus) msg; 366 OFCircuitPortStatus circuitPortStatus = (OFCircuitPortStatus) msg;
313 OFPortStatus.Builder portStatus = this.getSwitch(dpid).factory().buildPortStatus(); 367 OFPortStatus.Builder portStatus = this.getSwitch(dpid).factory().buildPortStatus();
314 OFPortDesc.Builder portDesc = this.getSwitch(dpid).factory().buildPortDesc(); 368 OFPortDesc.Builder portDesc = this.getSwitch(dpid).factory().buildPortDesc();
......
...@@ -19,6 +19,7 @@ import org.jboss.netty.channel.Channel; ...@@ -19,6 +19,7 @@ import org.jboss.netty.channel.Channel;
19 import org.junit.After; 19 import org.junit.After;
20 import org.junit.Before; 20 import org.junit.Before;
21 import org.junit.Test; 21 import org.junit.Test;
22 +import org.onosproject.net.Device;
22 import org.onosproject.net.driver.DriverData; 23 import org.onosproject.net.driver.DriverData;
23 import org.onosproject.net.driver.DriverHandler; 24 import org.onosproject.net.driver.DriverHandler;
24 import org.onosproject.openflow.controller.Dpid; 25 import org.onosproject.openflow.controller.Dpid;
...@@ -181,8 +182,8 @@ public class RoleManagerTest { ...@@ -181,8 +182,8 @@ public class RoleManagerTest {
181 } 182 }
182 183
183 @Override 184 @Override
184 - public boolean isOptical() { 185 + public Device.Type deviceType() {
185 - return false; 186 + return Device.Type.SWITCH;
186 } 187 }
187 188
188 @Override 189 @Override
......
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
74 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 74 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
75 <netty4.version>4.0.23.Final</netty4.version> 75 <netty4.version>4.0.23.Final</netty4.version>
76 <copycat.version>0.5.0.onos12-SNAPSHOT</copycat.version> 76 <copycat.version>0.5.0.onos12-SNAPSHOT</copycat.version>
77 - <openflowj.version>0.4.0.onos</openflowj.version> 77 + <openflowj.version>0.4.1.onos-SNAPSHOT</openflowj.version>
78 <karaf.version>3.0.3</karaf.version> 78 <karaf.version>3.0.3</karaf.version>
79 <jersey.version>1.19</jersey.version> 79 <jersey.version>1.19</jersey.version>
80 </properties> 80 </properties>
......
...@@ -29,9 +29,10 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -29,9 +29,10 @@ import org.apache.felix.scr.annotations.Reference;
29 import org.apache.felix.scr.annotations.ReferenceCardinality; 29 import org.apache.felix.scr.annotations.ReferenceCardinality;
30 import org.onlab.packet.ChassisId; 30 import org.onlab.packet.ChassisId;
31 import org.onosproject.cfg.ComponentConfigService; 31 import org.onosproject.cfg.ComponentConfigService;
32 +import org.onlab.util.Frequency;
33 +import org.onlab.util.Spectrum;
32 import org.onosproject.net.AnnotationKeys; 34 import org.onosproject.net.AnnotationKeys;
33 import org.onosproject.net.DefaultAnnotations; 35 import org.onosproject.net.DefaultAnnotations;
34 -import org.onosproject.net.Device;
35 import org.onosproject.net.DeviceId; 36 import org.onosproject.net.DeviceId;
36 import org.onosproject.net.MastershipRole; 37 import org.onosproject.net.MastershipRole;
37 import org.onosproject.net.Port; 38 import org.onosproject.net.Port;
...@@ -44,6 +45,7 @@ import org.onosproject.net.device.DeviceDescription; ...@@ -44,6 +45,7 @@ import org.onosproject.net.device.DeviceDescription;
44 import org.onosproject.net.device.DeviceProvider; 45 import org.onosproject.net.device.DeviceProvider;
45 import org.onosproject.net.device.DeviceProviderRegistry; 46 import org.onosproject.net.device.DeviceProviderRegistry;
46 import org.onosproject.net.device.DeviceProviderService; 47 import org.onosproject.net.device.DeviceProviderService;
48 +import org.onosproject.net.device.OmsPortDescription;
47 import org.onosproject.net.device.PortDescription; 49 import org.onosproject.net.device.PortDescription;
48 import org.onosproject.net.device.PortStatistics; 50 import org.onosproject.net.device.PortStatistics;
49 import org.onosproject.net.provider.AbstractProvider; 51 import org.onosproject.net.provider.AbstractProvider;
...@@ -57,6 +59,7 @@ import org.onosproject.openflow.controller.OpenFlowSwitchListener; ...@@ -57,6 +59,7 @@ import org.onosproject.openflow.controller.OpenFlowSwitchListener;
57 import org.onosproject.openflow.controller.PortDescPropertyType; 59 import org.onosproject.openflow.controller.PortDescPropertyType;
58 import org.onosproject.openflow.controller.RoleState; 60 import org.onosproject.openflow.controller.RoleState;
59 import org.osgi.service.component.ComponentContext; 61 import org.osgi.service.component.ComponentContext;
62 +import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry;
60 import org.projectfloodlight.openflow.protocol.OFFactory; 63 import org.projectfloodlight.openflow.protocol.OFFactory;
61 import org.projectfloodlight.openflow.protocol.OFMessage; 64 import org.projectfloodlight.openflow.protocol.OFMessage;
62 import org.projectfloodlight.openflow.protocol.OFPortConfig; 65 import org.projectfloodlight.openflow.protocol.OFPortConfig;
...@@ -290,8 +293,6 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -290,8 +293,6 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
290 DeviceId did = deviceId(uri(dpid)); 293 DeviceId did = deviceId(uri(dpid));
291 OpenFlowSwitch sw = controller.getSwitch(dpid); 294 OpenFlowSwitch sw = controller.getSwitch(dpid);
292 295
293 - Device.Type deviceType = sw.isOptical() ? Device.Type.ROADM :
294 - Device.Type.SWITCH;
295 ChassisId cId = new ChassisId(dpid.value()); 296 ChassisId cId = new ChassisId(dpid.value());
296 297
297 SparseAnnotations annotations = DefaultAnnotations.builder() 298 SparseAnnotations annotations = DefaultAnnotations.builder()
...@@ -300,7 +301,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -300,7 +301,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
300 .build(); 301 .build();
301 302
302 DeviceDescription description = 303 DeviceDescription description =
303 - new DefaultDeviceDescription(did.uri(), deviceType, 304 + new DefaultDeviceDescription(did.uri(), sw.deviceType(),
304 sw.manufacturerDescription(), 305 sw.manufacturerDescription(),
305 sw.hardwareDescription(), 306 sw.hardwareDescription(),
306 sw.softwareDescription(), 307 sw.softwareDescription(),
...@@ -380,8 +381,11 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -380,8 +381,11 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
380 private List<PortDescription> buildPortDescriptions(OpenFlowSwitch sw) { 381 private List<PortDescription> buildPortDescriptions(OpenFlowSwitch sw) {
381 final List<PortDescription> portDescs = new ArrayList<>(sw.getPorts().size()); 382 final List<PortDescription> portDescs = new ArrayList<>(sw.getPorts().size());
382 sw.getPorts().forEach(port -> portDescs.add(buildPortDescription(port))); 383 sw.getPorts().forEach(port -> portDescs.add(buildPortDescription(port)));
383 - if (sw.isOptical()) { 384 +
384 - OpenFlowOpticalSwitch opsw = (OpenFlowOpticalSwitch) sw; 385 + OpenFlowOpticalSwitch opsw;
386 + switch (sw.deviceType()) {
387 + case ROADM:
388 + opsw = (OpenFlowOpticalSwitch) sw;
385 opsw.getPortTypes().forEach(type -> { 389 opsw.getPortTypes().forEach(type -> {
386 opsw.getPortsOf(type).forEach( 390 opsw.getPortsOf(type).forEach(
387 op -> { 391 op -> {
...@@ -389,7 +393,21 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -389,7 +393,21 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
389 } 393 }
390 ); 394 );
391 }); 395 });
396 + break;
397 + case FIBER_SWITCH:
398 + opsw = (OpenFlowOpticalSwitch) sw;
399 + opsw.getPortTypes().forEach(type -> {
400 + opsw.getPortsOf(type).forEach(
401 + op -> {
402 + portDescs.add(buildPortDescription((OFCalientPortDescStatsEntry) op));
403 + }
404 + );
405 + });
406 + break;
407 + default:
408 + break;
392 } 409 }
410 +
393 return portDescs; 411 return portDescs;
394 } 412 }
395 413
...@@ -454,6 +472,28 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -454,6 +472,28 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
454 return new DefaultPortDescription(portNo, enabled, FIBER, 0, annotations); 472 return new DefaultPortDescription(portNo, enabled, FIBER, 0, annotations);
455 } 473 }
456 474
475 + /**
476 + * Build a portDescription from a given port description describing a fiber switch optical port.
477 + *
478 + * @param port description property type.
479 + * @param port the port to build from.
480 + * @return portDescription for the port.
481 + */
482 + private PortDescription buildPortDescription(OFCalientPortDescStatsEntry port) {
483 + PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
484 +
485 + // FIXME when Calient OF agent reports port status
486 + boolean enabled = true;
487 + SparseAnnotations annotations = makePortNameAnnotation(port.getName());
488 +
489 + // Wavelength range: 1260 - 1630 nm (S160 data sheet)
490 + // Grid is irrelevant for this type of switch
491 + Frequency minFreq = Spectrum.O_BAND_MAX;
492 + Frequency maxFreq = Spectrum.U_BAND_MIN;
493 + Frequency grid = Frequency.ofGHz(100);
494 + return new OmsPortDescription(portNo, enabled, minFreq, maxFreq, grid, annotations);
495 + }
496 +
457 private PortDescription buildPortDescription(OFPortStatus status) { 497 private PortDescription buildPortDescription(OFPortStatus status) {
458 OFPortDesc port = status.getDesc(); 498 OFPortDesc port = status.getDesc();
459 if (status.getReason() != OFPortReason.DELETE) { 499 if (status.getReason() != OFPortReason.DELETE) {
......
...@@ -384,8 +384,8 @@ public class OpenFlowDeviceProviderTest { ...@@ -384,8 +384,8 @@ public class OpenFlowDeviceProviderTest {
384 } 384 }
385 385
386 @Override 386 @Override
387 - public boolean isOptical() { 387 + public Device.Type deviceType() {
388 - return false; 388 + return Device.Type.SWITCH;
389 } 389 }
390 390
391 @Override 391 @Override
......
...@@ -370,7 +370,7 @@ public class OpenFlowRuleProvider extends AbstractProvider ...@@ -370,7 +370,7 @@ public class OpenFlowRuleProvider extends AbstractProvider
370 + " tell us which one."); 370 + " tell us which one.");
371 } 371 }
372 } 372 }
373 - 373 + break;
374 default: 374 default:
375 log.debug("Unhandled message type: {}", msg.getType()); 375 log.debug("Unhandled message type: {}", msg.getType());
376 } 376 }
......
...@@ -6,6 +6,7 @@ import org.junit.Before; ...@@ -6,6 +6,7 @@ import org.junit.Before;
6 import org.junit.Test; 6 import org.junit.Test;
7 import org.onosproject.core.DefaultGroupId; 7 import org.onosproject.core.DefaultGroupId;
8 import org.onosproject.core.GroupId; 8 import org.onosproject.core.GroupId;
9 +import org.onosproject.net.Device;
9 import org.onosproject.net.DeviceId; 10 import org.onosproject.net.DeviceId;
10 import org.onosproject.net.PortNumber; 11 import org.onosproject.net.PortNumber;
11 import org.onosproject.net.flow.DefaultTrafficTreatment; 12 import org.onosproject.net.flow.DefaultTrafficTreatment;
...@@ -383,8 +384,8 @@ public class OpenFlowGroupProviderTest { ...@@ -383,8 +384,8 @@ public class OpenFlowGroupProviderTest {
383 } 384 }
384 385
385 @Override 386 @Override
386 - public boolean isOptical() { 387 + public Device.Type deviceType() {
387 - return false; 388 + return Device.Type.SWITCH;
388 } 389 }
389 390
390 @Override 391 @Override
......
...@@ -22,6 +22,7 @@ import org.junit.Before; ...@@ -22,6 +22,7 @@ import org.junit.Before;
22 import org.junit.Test; 22 import org.junit.Test;
23 import org.onlab.packet.ARP; 23 import org.onlab.packet.ARP;
24 import org.onlab.packet.Ethernet; 24 import org.onlab.packet.Ethernet;
25 +import org.onosproject.net.Device;
25 import org.onosproject.net.DeviceId; 26 import org.onosproject.net.DeviceId;
26 import org.onosproject.net.PortNumber; 27 import org.onosproject.net.PortNumber;
27 import org.onosproject.net.flow.DefaultTrafficTreatment; 28 import org.onosproject.net.flow.DefaultTrafficTreatment;
...@@ -412,12 +413,11 @@ public class OpenFlowPacketProviderTest { ...@@ -412,12 +413,11 @@ public class OpenFlowPacketProviderTest {
412 } 413 }
413 414
414 @Override 415 @Override
415 - public boolean isOptical() { 416 + public void returnRoleReply(RoleState requested, RoleState reponse) {
416 - return false;
417 } 417 }
418 -
419 @Override 418 @Override
420 - public void returnRoleReply(RoleState requested, RoleState reponse) { 419 + public Device.Type deviceType() {
420 + return Device.Type.SWITCH;
421 } 421 }
422 422
423 @Override 423 @Override
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * 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
7 + *
8 + * 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.
15 + */
16 +package org.onlab.util;
17 +
18 +/**
19 + * Telecom optical wavelength bands: O, E, S, C, L and U bands.
20 + *
21 + * See ITU-T G-Series Recommendations, Supplement 39
22 + */
23 +public final class Spectrum {
24 +
25 + private Spectrum() {
26 + }
27 +
28 + // O band (original): 1260 to 1360 nm
29 + public static final Frequency O_BAND_MIN = Frequency.ofTHz(220.436);
30 + public static final Frequency O_BAND_MAX = Frequency.ofTHz(237.931);
31 +
32 + // E band (extended): 1360 to 1460 nm
33 + public static final Frequency E_BAND_MIN = Frequency.ofTHz(205.337);
34 + public static final Frequency E_BAND_MAX = Frequency.ofTHz(220.436);
35 +
36 + // S band (short wavelength): 1460 to 1530 nm
37 + public static final Frequency S_BAND_MIN = Frequency.ofTHz(195.943);
38 + public static final Frequency S_BAND_MAX = Frequency.ofTHz(205.337);
39 +
40 + // C band (conventional): 1530 to 1565 nm
41 + public static final Frequency C_BAND_MIN = Frequency.ofTHz(191.561);
42 + public static final Frequency C_BAND_MAX = Frequency.ofTHz(195.943);
43 +
44 + // L band (long wavelength): 1565 to 1625 nm
45 + public static final Frequency L_BAND_MIN = Frequency.ofTHz(184.488);
46 + public static final Frequency L_BAND_MAX = Frequency.ofTHz(191.561);
47 +
48 + // U band (ultra-long wavelength): 1625 to 1675 nm
49 + public static final Frequency U_BAND_MIN = Frequency.ofTHz(178.981);
50 + public static final Frequency U_BAND_MAX = Frequency.ofTHz(184.488);
51 +}