blob: 130ad53d9405c371c72ba229a9018212bbf7ffeb [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska781d18b2014-10-27 10:31:25 -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
Thomas Vachuska781d18b2014-10-27 10:31:25 -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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.provider.of.device.impl;
tomb5a46e62014-08-26 14:20:00 -070017
Marc De Leenheer8aba62f2017-04-25 14:33:37 -070018import com.google.common.base.Strings;
19import com.google.common.collect.ImmutableList;
20import com.google.common.collect.Lists;
21import com.google.common.collect.Maps;
22import com.google.common.collect.Sets;
Thomas Vachuskaf0397b52015-05-29 13:50:17 -070023import org.onlab.packet.ChassisId;
Marc De Leenheerb9311372015-07-09 11:36:49 -070024import org.onlab.util.Frequency;
25import org.onlab.util.Spectrum;
Yafit Hadara9a73de2015-09-06 13:52:52 +030026import org.onosproject.cfg.ComponentConfigService;
Thomas Vachuskab52a0142015-04-21 17:48:15 -070027import org.onosproject.net.AnnotationKeys;
Marc De Leenheerfc913dd2015-07-30 16:04:55 -070028import org.onosproject.net.ChannelSpacing;
Toru Furusawa72ee30c2016-01-08 13:29:04 -080029import org.onosproject.net.CltSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.net.DefaultAnnotations;
Yuta HIGUCHI2341e602017-03-08 20:10:08 -080031import org.onosproject.net.DefaultAnnotations.Builder;
Yafit Hadara9a73de2015-09-06 13:52:52 +030032import org.onosproject.net.Device;
Brian O'Connorabafb502014-12-02 22:26:20 -080033import org.onosproject.net.DeviceId;
Marc De Leenheerfc913dd2015-07-30 16:04:55 -070034import org.onosproject.net.GridType;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.MastershipRole;
Marc De Leenheerfc913dd2015-07-30 16:04:55 -070036import org.onosproject.net.OchSignal;
37import org.onosproject.net.OduSignalType;
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +020038import org.onosproject.net.OtuSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080039import org.onosproject.net.Port;
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -070040import org.onosproject.net.Port.Type;
Brian O'Connorabafb502014-12-02 22:26:20 -080041import org.onosproject.net.PortNumber;
42import org.onosproject.net.SparseAnnotations;
Jimmy Yan4deb03b2016-06-24 10:53:54 -070043import org.onosproject.net.behaviour.LambdaQuery;
Brian O'Connorabafb502014-12-02 22:26:20 -080044import org.onosproject.net.device.DefaultDeviceDescription;
45import org.onosproject.net.device.DefaultPortDescription;
sangho538108b2015-04-08 14:29:20 -070046import org.onosproject.net.device.DefaultPortStatistics;
Brian O'Connorabafb502014-12-02 22:26:20 -080047import org.onosproject.net.device.DeviceDescription;
48import org.onosproject.net.device.DeviceProvider;
49import org.onosproject.net.device.DeviceProviderRegistry;
50import org.onosproject.net.device.DeviceProviderService;
Thomas Vachuska164ecf62018-05-08 17:29:55 -070051import org.onosproject.net.device.DeviceService;
Brian O'Connorabafb502014-12-02 22:26:20 -080052import org.onosproject.net.device.PortDescription;
sangho538108b2015-04-08 14:29:20 -070053import org.onosproject.net.device.PortStatistics;
Victor Silvaac8dab02016-11-28 16:33:08 -030054import org.onosproject.net.driver.Driver;
Jimmy Yan4deb03b2016-06-24 10:53:54 -070055import org.onosproject.net.driver.DriverHandler;
Victor Silvaac8dab02016-11-28 16:33:08 -030056import org.onosproject.net.driver.DriverService;
Jimmy Yan4deb03b2016-06-24 10:53:54 -070057import org.onosproject.net.driver.HandlerBehaviour;
Brian O'Connorabafb502014-12-02 22:26:20 -080058import org.onosproject.net.provider.AbstractProvider;
59import org.onosproject.net.provider.ProviderId;
60import org.onosproject.openflow.controller.Dpid;
61import org.onosproject.openflow.controller.OpenFlowController;
sangho538108b2015-04-08 14:29:20 -070062import org.onosproject.openflow.controller.OpenFlowEventListener;
Ayaka Koshibe5460d622015-05-14 12:19:19 -070063import org.onosproject.openflow.controller.OpenFlowOpticalSwitch;
Brian O'Connorabafb502014-12-02 22:26:20 -080064import org.onosproject.openflow.controller.OpenFlowSwitch;
65import org.onosproject.openflow.controller.OpenFlowSwitchListener;
Ayaka Koshibe5460d622015-05-14 12:19:19 -070066import org.onosproject.openflow.controller.PortDescPropertyType;
Brian O'Connorabafb502014-12-02 22:26:20 -080067import org.onosproject.openflow.controller.RoleState;
Dusan Pajinbab8a5e2015-07-24 17:37:19 +020068import org.osgi.service.component.ComponentContext;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070069import org.osgi.service.component.annotations.Activate;
70import org.osgi.service.component.annotations.Component;
71import org.osgi.service.component.annotations.Deactivate;
72import org.osgi.service.component.annotations.Modified;
73import org.osgi.service.component.annotations.Reference;
74import org.osgi.service.component.annotations.ReferenceCardinality;
Marc De Leenheerc662d322016-02-18 16:05:10 -080075import org.projectfloodlight.openflow.protocol.OFCalientPortDescProp;
76import org.projectfloodlight.openflow.protocol.OFCalientPortDescPropOptical;
Marc De Leenheerb9311372015-07-09 11:36:49 -070077import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry;
Laszlo Papp58174812018-01-16 13:29:47 +000078import org.projectfloodlight.openflow.protocol.OFCapabilities;
Saurav Dasa2d37502016-03-25 17:50:40 -070079import org.projectfloodlight.openflow.protocol.OFErrorMsg;
80import org.projectfloodlight.openflow.protocol.OFErrorType;
Yafit Hadara9a73de2015-09-06 13:52:52 +030081import org.projectfloodlight.openflow.protocol.OFExpPort;
82import org.projectfloodlight.openflow.protocol.OFExpPortDescPropOpticalTransport;
83import org.projectfloodlight.openflow.protocol.OFExpPortOpticalTransportLayerEntry;
Ayaka Koshibee8708e32014-10-22 13:40:18 -070084import org.projectfloodlight.openflow.protocol.OFFactory;
sangho538108b2015-04-08 14:29:20 -070085import org.projectfloodlight.openflow.protocol.OFMessage;
Yafit Hadara9a73de2015-09-06 13:52:52 +030086import org.projectfloodlight.openflow.protocol.OFObject;
alshabib4680bb62014-09-04 17:15:08 -070087import org.projectfloodlight.openflow.protocol.OFPortConfig;
alshabib25c8eec2014-09-04 16:41:31 -070088import org.projectfloodlight.openflow.protocol.OFPortDesc;
Laszlo Papp8e8ff052018-01-16 09:55:45 +000089import org.projectfloodlight.openflow.protocol.OFPortDescProp;
Yuta HIGUCHI2341e602017-03-08 20:10:08 -080090import org.projectfloodlight.openflow.protocol.OFPortDescPropEthernet;
91import org.projectfloodlight.openflow.protocol.OFPortDescPropOptical;
Marc De Leenheerfc913dd2015-07-30 16:04:55 -070092import org.projectfloodlight.openflow.protocol.OFPortDescPropOpticalTransport;
Palash Kala496ef1a22018-03-21 14:57:50 +090093import org.projectfloodlight.openflow.protocol.OFPortDescStatsRequest;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070094import org.projectfloodlight.openflow.protocol.OFPortFeatures;
Saurav Dasa2d37502016-03-25 17:50:40 -070095import org.projectfloodlight.openflow.protocol.OFPortMod;
Ayaka Koshibe5460d622015-05-14 12:19:19 -070096import org.projectfloodlight.openflow.protocol.OFPortOptical;
Yafit Hadara9a73de2015-09-06 13:52:52 +030097import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportLayerClass;
98import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportSignalType;
alshabibafc514a2014-12-01 14:44:05 -080099import org.projectfloodlight.openflow.protocol.OFPortReason;
alshabib4680bb62014-09-04 17:15:08 -0700100import org.projectfloodlight.openflow.protocol.OFPortState;
sangho538108b2015-04-08 14:29:20 -0700101import org.projectfloodlight.openflow.protocol.OFPortStatsEntry;
Laszlo Papp7cf60372018-01-11 00:06:43 +0000102import org.projectfloodlight.openflow.protocol.OFPortStatsPropOptical;
sangho538108b2015-04-08 14:29:20 -0700103import org.projectfloodlight.openflow.protocol.OFPortStatsReply;
alshabiba14f3642014-09-05 09:31:31 -0700104import org.projectfloodlight.openflow.protocol.OFPortStatus;
sangho538108b2015-04-08 14:29:20 -0700105import org.projectfloodlight.openflow.protocol.OFStatsReply;
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700106import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
sangho538108b2015-04-08 14:29:20 -0700107import org.projectfloodlight.openflow.protocol.OFStatsType;
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700108import org.projectfloodlight.openflow.protocol.OFVersion;
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -0700109import org.projectfloodlight.openflow.protocol.ver14.OFOpticalPortFeaturesSerializerVer14;
Laszlo Papp7cf60372018-01-11 00:06:43 +0000110import org.projectfloodlight.openflow.protocol.ver14.OFPortStatsOpticalFlagsSerializerVer14;
Saurav Dasa2d37502016-03-25 17:50:40 -0700111import org.projectfloodlight.openflow.types.OFPort;
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700112import org.projectfloodlight.openflow.types.PortSpeed;
tomb5a46e62014-08-26 14:20:00 -0700113import org.slf4j.Logger;
tom5f38b3a2014-08-27 23:50:54 -0700114
Marc De Leenheer8aba62f2017-04-25 14:33:37 -0700115import java.util.ArrayList;
116import java.util.Collection;
117import java.util.Collections;
118import java.util.Comparator;
119import java.util.Dictionary;
Jimmy Jine9b7a022016-08-12 16:56:48 -0700120import java.util.EnumSet;
Marc De Leenheer8aba62f2017-04-25 14:33:37 -0700121import java.util.HashMap;
122import java.util.HashSet;
123import java.util.List;
Thomas Vachuska5b38dc02018-05-10 15:24:40 -0700124import java.util.Map;
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800125import java.util.Optional;
Marc De Leenheer8aba62f2017-04-25 14:33:37 -0700126import java.util.Properties;
127import java.util.Set;
128import java.util.Timer;
129
130import static com.google.common.base.Preconditions.checkArgument;
131import static com.google.common.base.Strings.isNullOrEmpty;
132import static org.onlab.util.Tools.get;
133import static org.onosproject.net.DeviceId.deviceId;
134import static org.onosproject.net.Port.Type.COPPER;
135import static org.onosproject.net.Port.Type.FIBER;
136import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
137import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
138import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription;
139import static org.onosproject.net.optical.device.OtuPortHelper.otuPortDescription;
140import static org.onosproject.openflow.controller.Dpid.dpid;
141import static org.onosproject.openflow.controller.Dpid.uri;
142import static org.slf4j.LoggerFactory.getLogger;
tom782a7cf2014-09-11 23:58:38 -0700143
tomb5a46e62014-08-26 14:20:00 -0700144/**
tomb1260e42014-08-26 18:39:57 -0700145 * Provider which uses an OpenFlow controller to detect network
tome06f8552014-08-26 16:58:42 -0700146 * infrastructure devices.
tomb5a46e62014-08-26 14:20:00 -0700147 */
tomb1260e42014-08-26 18:39:57 -0700148@Component(immediate = true)
tomab21e7c2014-08-26 15:23:08 -0700149public class OpenFlowDeviceProvider extends AbstractProvider implements DeviceProvider {
tomb5a46e62014-08-26 14:20:00 -0700150
alshabiba89cc582014-09-09 16:43:00 -0700151 private static final Logger LOG = getLogger(OpenFlowDeviceProvider.class);
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700152
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800153 // TODO Some duplicate with one defined in OpticalAnnotations
154 // slice out optical specific handling and consolidate.
155 /**
156 * Annotation key for minimum frequency in Hz.
157 * Value is expected to be an integer.
158 */
159 public static final String AK_MIN_FREQ_HZ = "minFrequency";
160
161 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000162 * Annotation key for minimum lambda in nm.
163 * Value is expected to be an integer.
164 */
165 public static final String AK_MIN_LMDA_NM = "minLambda";
166
167 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800168 * Annotation key for maximum frequency in Hz.
169 * Value is expected be an integer.
170 */
171 public static final String AK_MAX_FREQ_HZ = "maxFrequency";
172
173 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000174 * Annotation key for maximum lambda in nm.
175 * Value is expected be an integer.
176 */
177 public static final String AK_MAX_LMDA_NM = "maxLambda";
178
179 /**
180 * Annotation key for grid frequency in Hz.
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800181 * Value is expected to be an integer.
182 */
183 public static final String AK_GRID_HZ = "grid";
184
Laszlo Papp20cfb6f2018-01-08 16:06:53 +0000185 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000186 * Annotation key for grid lambda in nm.
187 * Value is expected to be an integer.
188 */
189 public static final String AK_GRID_LMDA_NM = "gridLambda";
190
191 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800192 * Annotation key for minimum frequency in Hz.
193 * Value is expected to be an integer.
194 */
195 public static final String AK_TX_MIN_FREQ_HZ = "txMinFrequency";
196
197 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000198 * Annotation key for minimum lambda in nm.
199 * Value is expected to be an integer.
200 */
201 public static final String AK_TX_MIN_LMDA_NM = "txMinLambda";
202
203 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800204 * Annotation key for maximum frequency in Hz.
205 * Value is expected be an integer.
206 */
207 public static final String AK_TX_MAX_FREQ_HZ = "txMaxFrequency";
208
209 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000210 * Annotation key for maximum lambda in nm.
211 * Value is expected be an integer.
212 */
213 public static final String AK_TX_MAX_LMDA_NM = "txMaxLambda";
214
215 /**
216 * Annotation key for grid frequency in Hz.
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800217 * Value is expected to be an integer.
218 */
219 public static final String AK_TX_GRID_HZ = "txGrid";
220
221 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000222 * Annotation key for grid lambda in nm.
223 * Value is expected to be an integer.
224 */
225 public static final String AK_TX_GRID_LMDA_NM = "txGridLambda";
226
227 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800228 * Annotation key for minimum frequency in Hz.
229 * Value is expected to be an integer.
230 */
231 public static final String AK_RX_MIN_FREQ_HZ = "rxMinFrequency";
232
233 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000234 * Annotation key for minimum lambda in nm.
235 * Value is expected to be an integer.
236 */
237 public static final String AK_RX_MIN_LMDA_NM = "rxMinLambda";
238
239 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800240 * Annotation key for maximum frequency in Hz.
241 * Value is expected be an integer.
242 */
243 public static final String AK_RX_MAX_FREQ_HZ = "rxMaxFrequency";
244
245 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000246 * Annotation key for maximum lambda in nm.
247 * Value is expected be an integer.
248 */
249 public static final String AK_RX_MAX_LMDA_NM = "rxMaxLambda";
250
251 /**
252 * Annotation key for grid frequency in Hz.
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800253 * Value is expected to be an integer.
254 */
255 public static final String AK_RX_GRID_HZ = "rxGrid";
256
Laszlo Papp20cfb6f2018-01-08 16:06:53 +0000257 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000258 * Annotation key for grid lambda in nm.
259 * Value is expected to be an integer.
260 */
261 public static final String AK_RX_GRID_LMDA_NM = "rxGridLambda";
262
263 /**
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000264 * Annotation key for indicating frequency must be used instead of
265 * wavelength for port tuning.
266 * Value is expected to be "enabled" or "disabled"
267 */
268 public static final String AK_USE_FREQ_FEATURE = "useFreqFeature";
269
270 /**
Laszlo Papp20cfb6f2018-01-08 16:06:53 +0000271 * Annotation key for minimum transmit power in dBm*10.
272 * Value is expected to be an integer.
273 */
274 public static final String AK_TX_PWR_MIN = "txPowerMin";
275
276 /**
277 * Annotation key for maximum transmit power in dBm*10.
278 * Value is expected to be an integer.
279 */
280 public static final String AK_TX_PWR_MAX = "txPowerMax";
281
Laszlo Papp7cf60372018-01-11 00:06:43 +0000282
283
284 // Port Stats annotations
285
286 /**
287 * Annotation key for transmit frequency in Hz.
288 * Value is expected be an integer.
289 */
290 public static final String AK_TX_FREQ_HZ = "txFrequency";
291
292 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000293 * Annotation key for transmit lambda in nm.
294 * Value is expected be an integer.
295 */
296 public static final String AK_TX_LMDA_NM = "txLambda";
297
298 /**
299 * Annotation key for transmit offset frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000300 * Value is expected be an integer.
301 */
302 public static final String AK_TX_OFFSET_HZ = "txOffset";
303
304 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000305 * Annotation key for transmit offset in nm.
306 * Value is expected be an integer.
307 */
308 public static final String AK_TX_OFFSET_LMDA_NM = "txOffsetLambda";
309
310 /**
311 * Annotation key for transmit grid spacing frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000312 * Value is expected be an integer.
313 */
314 public static final String AK_TX_GRID_SPAN_HZ = "txGridSpan";
315
316 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000317 * Annotation key for transmit grid spacing lambda in nm.
318 * Value is expected be an integer.
319 */
320 public static final String AK_TX_GRID_SPAN_LMDA_NM = "txGridSpanLambda";
321
322 /**
Laszlo Papp7cf60372018-01-11 00:06:43 +0000323 * Annotation key for receive frequency in Hz.
324 * Value is expected be an integer.
325 */
326 public static final String AK_RX_FREQ_HZ = "rxFrequency";
327
328 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000329 * Annotation key for receive lambda in nm.
330 * Value is expected be an integer.
331 */
332 public static final String AK_RX_LMDA_NM = "rxLambda";
333
334 /**
335 * Annotation key for receive offset frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000336 * Value is expected be an integer.
337 */
338 public static final String AK_RX_OFFSET_HZ = "rxOffset";
339
340 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000341 * Annotation key for receive offset lambda in nm.
342 * Value is expected be an integer.
343 */
344 public static final String AK_RX_OFFSET_LMDA_NM = "rxOffsetLambda";
345
346 /**
347 * Annotation key for receive grid spacing frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000348 * Value is expected be an integer.
349 */
350 public static final String AK_RX_GRID_SPAN_HZ = "rxGridSpan";
351
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000352 /**
353 * Annotation key for receive grid spacing lambda in nm.
354 * Value is expected be an integer.
355 */
356 public static final String AK_RX_GRID_SPAN_LMDA_NM = "rxGridSpanLambda";
357
Laszlo Papp7cf60372018-01-11 00:06:43 +0000358 /**
359 * Annotation key for transmit power in dBm*10.
360 * Value is expected to be an integer.
361 */
362 public static final String AK_TX_PWR = "txPower";
363
364 /**
365 * Annotation key for receive power feature.
366 * Value is expected to be "enabled" or "disabled"
367 */
368 public static final String AK_RX_PWR_FEATURE = "rxPwrFeature";
369
370 /**
371 * Annotation key for receive power in dBm*10.
372 * Value is expected to be an integer.
373 */
374 public static final String AK_RX_PWR = "rxPower";
375
376 /**
377 * Annotation key for transmit bias feature.
378 * Value is expected to be "enabled" or "disabled"
379 */
380 public static final String AK_TX_BIAS_FEATURE = "txBiasFeature";
381
382 /**
383 * Annotation key for transmit bias current in mA*10.
384 * Value is expected to be an integer.
385 */
386 public static final String AK_BIAS_CURRENT = "biasCurrent";
387
388 /**
389 * Annotation key for transmit temperature feature.
390 * Value is expected to be "enabled" or "disabled"
391 */
392 public static final String AK_TX_TEMP_FEATURE = "txTempFeature";
393
394 /**
395 * Annotation key for transmit laser temperature in C*10.
396 * Value is expected to be an integer.
397 */
398 public static final String AK_TEMPERATURE = "temperature";
399
400
401 // Common feature annotations
402
403 /**
404 * Annotation key for transmit tune feature.
405 * Value is expected to be "enabled" or "disabled"
406 */
407 public static final String AK_TX_TUNE_FEATURE = "txTuneFeature";
408
409 /**
410 * Annotation key for receive tune feature.
411 * Value is expected to be "enabled" or "disabled"
412 */
413 public static final String AK_RX_TUNE_FEATURE = "rxTuneFeature";
414
415 /**
416 * Annotation key for transmit power feature.
417 * Value is expected to be "enabled" or "disabled"
418 */
419 public static final String AK_TX_PWR_FEATURE = "txPwrFeature";
420
421
Charles Chan25b77322015-12-13 01:00:56 -0800422 //TODO consider renaming KBPS and MBPS (as they are used to convert by division)
423 private static final long KBPS = 1_000;
Ray Milkey3717e602018-02-01 13:49:47 -0800424 private static final long MBPS = 1_000L * 1_000L;
Rimon Ashkenazye3201032016-01-11 14:27:30 +0200425 private static final Frequency FREQ50 = Frequency.ofGHz(50);
426 private static final Frequency FREQ191_7 = Frequency.ofGHz(191_700);
Sho SHIMIZU00762ee2016-01-05 16:32:24 -0800427 private static final Frequency FREQ4_4 = Frequency.ofGHz(4_400);
tomb5a46e62014-08-26 14:20:00 -0700428
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000429 private static final long C = 299792458; // speed of light in m/s
Thomas Vachuska164ecf62018-05-08 17:29:55 -0700430 public static final String SCHEME = "of";
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000431
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700432 @Reference(cardinality = ReferenceCardinality.MANDATORY)
tom96dfcab2014-08-28 09:26:03 -0700433 protected DeviceProviderRegistry providerRegistry;
tomab21e7c2014-08-26 15:23:08 -0700434
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700435 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuska164ecf62018-05-08 17:29:55 -0700436 protected DeviceService deviceService;
437
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700438 @Reference(cardinality = ReferenceCardinality.MANDATORY)
tom5f38b3a2014-08-27 23:50:54 -0700439 protected OpenFlowController controller;
440
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700441 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200442 protected ComponentConfigService cfgService;
443
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700444 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Victor Silvaac8dab02016-11-28 16:33:08 -0300445 protected DriverService driverService;
446
tomab21e7c2014-08-26 15:23:08 -0700447 private DeviceProviderService providerService;
tomb5a46e62014-08-26 14:20:00 -0700448
sangho538108b2015-04-08 14:29:20 -0700449 private final InternalDeviceProvider listener = new InternalDeviceProvider();
450
Simon Hunt7a307652016-06-23 01:17:29 -0700451 private static final String POLL_PROP_NAME = "portStatsPollFrequency";
452 private static final int POLL_INTERVAL = 5;
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700453 //@Property(name = POLL_PROP_NAME, intValue = POLL_INTERVAL,
454 //label = "Frequency (in seconds) for polling switch Port statistics")
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200455 private int portStatsPollFrequency = POLL_INTERVAL;
sangho538108b2015-04-08 14:29:20 -0700456
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000457 private static final String PROP_FREQ = "propertyFrequency";
458 private static final boolean DEFAULT_PROP_FREQ = true;
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700459 //@Property(name = PROP_FREQ, boolValue = DEFAULT_PROP_FREQ,
460 //label = "It indicates frequency must be used instead of wavelength for port tuning.")
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000461 private static boolean propFreq = DEFAULT_PROP_FREQ;
462
Victor Silvaff5871b2016-10-04 18:08:47 -0300463 private final Timer timer = new Timer("onos-openflow-portstats-collector");
sangyun-han07a572f2016-07-29 21:14:27 +0900464
Thomas Vachuska5b38dc02018-05-10 15:24:40 -0700465 private Map<Dpid, PortStatsCollector> collectors = Maps.newConcurrentMap();
tomd40fc7a2014-09-04 16:41:10 -0700466
tomab21e7c2014-08-26 15:23:08 -0700467 /**
468 * Creates an OpenFlow device provider.
469 */
470 public OpenFlowDeviceProvider() {
Thomas Vachuska164ecf62018-05-08 17:29:55 -0700471 super(new ProviderId(SCHEME, "org.onosproject.provider.openflow"));
tomab21e7c2014-08-26 15:23:08 -0700472 }
473
tomb5a46e62014-08-26 14:20:00 -0700474 @Activate
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200475 public void activate(ComponentContext context) {
476 cfgService.registerProperties(getClass());
tom96dfcab2014-08-28 09:26:03 -0700477 providerService = providerRegistry.register(this);
tomd40fc7a2014-09-04 16:41:10 -0700478 controller.addListener(listener);
sangho538108b2015-04-08 14:29:20 -0700479 controller.addEventListener(listener);
Jian Li152b8852015-12-07 14:47:25 -0800480
Victor Silva7944d142016-07-08 00:14:55 -0300481 modified(context);
482
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700483 connectInitialDevices();
alshabiba89cc582014-09-09 16:43:00 -0700484 LOG.info("Started");
tomb5a46e62014-08-26 14:20:00 -0700485 }
486
487 @Deactivate
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200488 public void deactivate(ComponentContext context) {
489 cfgService.unregisterProperties(getClass(), false);
Ray Milkey7abe50b2016-04-13 11:57:44 -0700490 listener.disable();
tomd40fc7a2014-09-04 16:41:10 -0700491 controller.removeListener(listener);
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700492 providerRegistry.unregister(this);
Thomas Vachuska74bcd922015-06-02 13:08:57 -0700493 collectors.values().forEach(PortStatsCollector::stop);
Thomas Vachuskaa394b952016-06-14 15:02:09 -0700494 collectors.clear();
tomab21e7c2014-08-26 15:23:08 -0700495 providerService = null;
alshabiba89cc582014-09-09 16:43:00 -0700496 LOG.info("Stopped");
tomb5a46e62014-08-26 14:20:00 -0700497 }
498
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200499 @Modified
500 public void modified(ComponentContext context) {
Victor Silva7944d142016-07-08 00:14:55 -0300501 Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200502 int newPortStatsPollFrequency;
503 try {
Simon Hunt7a307652016-06-23 01:17:29 -0700504 String s = get(properties, POLL_PROP_NAME);
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200505 newPortStatsPollFrequency = isNullOrEmpty(s) ? portStatsPollFrequency : Integer.parseInt(s.trim());
506
507 } catch (NumberFormatException | ClassCastException e) {
508 newPortStatsPollFrequency = portStatsPollFrequency;
509 }
510
511 if (newPortStatsPollFrequency != portStatsPollFrequency) {
512 portStatsPollFrequency = newPortStatsPollFrequency;
513 collectors.values().forEach(psc -> psc.adjustPollInterval(portStatsPollFrequency));
514 }
515
516 LOG.info("Settings: portStatsPollFrequency={}", portStatsPollFrequency);
517 }
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700518
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700519 private void connectInitialDevices() {
520 for (OpenFlowSwitch sw : controller.getSwitches()) {
521 try {
522 listener.switchAdded(new Dpid(sw.getId()));
523 } catch (Exception e) {
524 LOG.warn("Failed initially adding {} : {}", sw.getStringId(), e.getMessage());
525 LOG.debug("Error details:", e);
526 // disconnect to trigger switch-add later
527 sw.disconnectSwitch();
528 }
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700529 }
530 }
531
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700532 @Override
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700533 public boolean isReachable(DeviceId deviceId) {
534 OpenFlowSwitch sw = controller.getSwitch(dpid(deviceId.uri()));
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700535 return sw != null && sw.isConnected();
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700536 }
537
tomab21e7c2014-08-26 15:23:08 -0700538 @Override
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800539 public void triggerProbe(DeviceId deviceId) {
Madan Jampanic3328762015-05-31 12:39:27 -0700540 LOG.debug("Triggering probe on device {}", deviceId);
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700541
Yuta HIGUCHI802d0e82014-10-31 16:07:37 -0700542 final Dpid dpid = dpid(deviceId.uri());
543 OpenFlowSwitch sw = controller.getSwitch(dpid);
544 if (sw == null || !sw.isConnected()) {
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800545 LOG.error("Failed to probe device {} on sw={}", deviceId, sw);
Yuta HIGUCHI802d0e82014-10-31 16:07:37 -0700546 providerService.deviceDisconnected(deviceId);
Thomas Vachuska74bcd922015-06-02 13:08:57 -0700547 return;
Yuta HIGUCHI802d0e82014-10-31 16:07:37 -0700548 } else {
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800549 LOG.trace("Confirmed device {} connection", deviceId);
Yuta HIGUCHI802d0e82014-10-31 16:07:37 -0700550 }
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700551
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700552 // Prompt an update of port information. We can use any XID for this.
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700553 OFFactory fact = sw.factory();
554 switch (fact.getVersion()) {
555 case OF_10:
556 sw.sendMsg(fact.buildFeaturesRequest().setXid(0).build());
557 break;
558 case OF_13:
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700559 case OF_14:
560 case OF_15:
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700561 sw.sendMsg(fact.buildPortDescStatsRequest().setXid(0).build());
562 break;
563 default:
564 LOG.warn("Unhandled protocol version");
565 }
tomab21e7c2014-08-26 15:23:08 -0700566 }
567
568 @Override
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700569 public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
alshabibf1216ed2014-09-03 11:53:54 -0700570 switch (newRole) {
tom782a7cf2014-09-11 23:58:38 -0700571 case MASTER:
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700572 controller.setRole(dpid(deviceId.uri()), RoleState.MASTER);
tom782a7cf2014-09-11 23:58:38 -0700573 break;
574 case STANDBY:
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700575 controller.setRole(dpid(deviceId.uri()), RoleState.EQUAL);
tom782a7cf2014-09-11 23:58:38 -0700576 break;
577 case NONE:
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700578 controller.setRole(dpid(deviceId.uri()), RoleState.SLAVE);
tom782a7cf2014-09-11 23:58:38 -0700579 break;
580 default:
581 LOG.error("Unknown Mastership state : {}", newRole);
alshabibf1216ed2014-09-03 11:53:54 -0700582
583 }
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800584 LOG.debug("Accepting mastership role change to {} for device {}", newRole, deviceId);
tomab21e7c2014-08-26 15:23:08 -0700585 }
586
Saurav Dasa2d37502016-03-25 17:50:40 -0700587 @Override
588 public void changePortState(DeviceId deviceId, PortNumber portNumber,
589 boolean enable) {
590 final Dpid dpid = dpid(deviceId.uri());
591 OpenFlowSwitch sw = controller.getSwitch(dpid);
592 if (sw == null || !sw.isConnected()) {
593 LOG.error("Failed to change portState on device {}", deviceId);
594 return;
595 }
596 OFPortMod.Builder pmb = sw.factory().buildPortMod();
597 OFPort port = OFPort.of((int) portNumber.toLong());
598 pmb.setPortNo(port);
Jimmy Jine9b7a022016-08-12 16:56:48 -0700599 Set<OFPortConfig> portConfig = EnumSet.noneOf(OFPortConfig.class);
600 if (!enable) {
601 portConfig.add(OFPortConfig.PORT_DOWN);
Saurav Dasa2d37502016-03-25 17:50:40 -0700602 }
Jimmy Jine9b7a022016-08-12 16:56:48 -0700603 pmb.setConfig(portConfig);
604 Set<OFPortConfig> portMask = EnumSet.noneOf(OFPortConfig.class);
605 portMask.add(OFPortConfig.PORT_DOWN);
606 pmb.setMask(portMask);
Saurav Dasa2d37502016-03-25 17:50:40 -0700607 pmb.setAdvertise(0x0);
608 for (OFPortDesc pd : sw.getPorts()) {
609 if (pd.getPortNo().equals(port)) {
610 pmb.setHwAddr(pd.getHwAddr());
611 break;
612 }
613 }
614 sw.sendMsg(Collections.singletonList(pmb.build()));
615 }
616
Thomas Vachuska5b38dc02018-05-10 15:24:40 -0700617 @Override
618 public void triggerDisconnect(DeviceId deviceId) {
619 Dpid dpid = dpid(deviceId.uri());
620 OpenFlowSwitch sw = controller.getSwitch(dpid);
621 if (sw != null) {
622 LOG.debug("Forcing disconnect for device {}", deviceId);
623 // TODO: Further consolidate clean-up on device disconnect
624 listener.switchRemoved(dpid);
625 sw.disconnectSwitch();
626 }
627 }
628
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700629 private void pushPortMetrics(Dpid dpid, List<OFPortStatsEntry> portStatsEntries) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800630 DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
Ray Milkey3c4124a2016-08-31 12:09:06 -0700631 Collection<PortStatistics> stats =
632 buildPortStatistics(deviceId, ImmutableList.copyOf(portStatsEntries));
sangho538108b2015-04-08 14:29:20 -0700633 providerService.updatePortStatistics(deviceId, stats);
634 }
635
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000636 private static String lambdaToAnnotationHz(long lambda) {
637 // ref. OF1.5: wavelength (lambda) as nm * 100
638
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000639 // f = c / λ
640 // (m/s) * (nm/m) / (nm * 100) * 100
641 // annotations is in Hz
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000642 return Long.toString(lambda == 0 ? lambda : (C * 1_000_000_000 / lambda * 100));
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000643 }
Laszlo Papp7cf60372018-01-11 00:06:43 +0000644
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000645 private static String mhzToAnnotationNm(long freqMhz) {
646 // λ = c / f
647 // (m/s) * (nm/m) / (1000000 * 1/s)
648 // annotations is in nm
649 return Long.toString(freqMhz == 0 ? freqMhz : (C * 1_000_000_000 / Frequency.ofMHz(freqMhz).asHz()));
650 }
651
652
Laszlo Papp7cf60372018-01-11 00:06:43 +0000653 private static String mhzToAnnotation(long freqMhz) {
654 return Long.toString(Frequency.ofMHz(freqMhz).asHz());
655 }
656
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000657 private static String freqLmdaToAnnotation(long freqLmda, boolean useFreq) {
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000658 if (useFreq) {
659 if (propFreq) {
660 mhzToAnnotation(freqLmda);
661 } else {
662 mhzToAnnotationNm(freqLmda);
663 }
664 } else if (propFreq) {
665 lambdaToAnnotationHz(freqLmda);
666 }
667 return Double.toString(freqLmda / 100.0);
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000668 }
669
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700670 private Collection<PortStatistics> buildPortStatistics(DeviceId deviceId,
671 List<OFPortStatsEntry> entries) {
sangho538108b2015-04-08 14:29:20 -0700672 HashSet<PortStatistics> stats = Sets.newHashSet();
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000673 final Dpid dpid = dpid(deviceId.uri());
674 OpenFlowSwitch sw = controller.getSwitch(dpid);
sangho538108b2015-04-08 14:29:20 -0700675
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700676 for (OFPortStatsEntry entry : entries) {
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700677 try {
Thomas Vachuska4e6025e2015-06-03 11:25:21 -0700678 if (entry == null || entry.getPortNo() == null || entry.getPortNo().getPortNumber() < 0) {
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700679 continue;
680 }
Laszlo Papp7cf60372018-01-11 00:06:43 +0000681 DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
Laszlo Papp9dfb5122018-01-12 21:10:13 +0000682 boolean propSupported = entry.getVersion().getWireVersion() >= OFVersion.OF_14.getWireVersion();
683 Optional<OFPortStatsPropOptical> optical = propSupported ?
684 entry.getProperties().stream()
Laszlo Papp7cf60372018-01-11 00:06:43 +0000685 .filter(OFPortStatsPropOptical.class::isInstance)
686 .map(OFPortStatsPropOptical.class::cast)
Laszlo Papp9dfb5122018-01-12 21:10:13 +0000687 .findAny() : Optional.empty();
Laszlo Papp7cf60372018-01-11 00:06:43 +0000688 if (optical.isPresent()) {
689 long flags = optical.get().getFlags();
690
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000691 boolean useFreq = false;
692 for (OFPortDesc pd : sw.getPorts()) {
693 if (pd.getPortNo().equals(entry.getPortNo())) {
694 for (OFPortDescProp prop : pd.getProperties()) {
695 if (prop instanceof OFPortDescPropOptical) {
696 OFPortDescPropOptical oprop = (OFPortDescPropOptical) prop;
697 long supported = oprop.getSupported();
698 int useFreqVal = OFOpticalPortFeaturesSerializerVer14.USE_FREQ_VAL;
699 if ((supported & useFreqVal) != 0) {
700 useFreq = true;
701 break;
702 }
703 }
704 }
705 }
706 }
707
Laszlo Papp7cf60372018-01-11 00:06:43 +0000708 int txTune = OFPortStatsOpticalFlagsSerializerVer14.TX_TUNE_VAL;
709 long txFreq = optical.get().getTxFreqLmda();
710 long txOffset = optical.get().getTxOffset();
711 long txGridSpan = optical.get().getTxGridSpan();
712 annotations.set(AK_TX_TUNE_FEATURE, ((flags & txTune) != 0) ? "enabled" : "disabled");
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000713 annotations.set(propFreq ? AK_TX_FREQ_HZ : AK_TX_LMDA_NM,
714 freqLmdaToAnnotation(txFreq, useFreq));
715 annotations.set(propFreq ? AK_TX_OFFSET_HZ : AK_TX_OFFSET_LMDA_NM,
716 freqLmdaToAnnotation(txOffset, useFreq));
717 annotations.set(propFreq ? AK_TX_GRID_SPAN_HZ : AK_TX_GRID_SPAN_LMDA_NM,
718 freqLmdaToAnnotation(txGridSpan, useFreq));
Laszlo Papp7cf60372018-01-11 00:06:43 +0000719
720 int rxTune = OFPortStatsOpticalFlagsSerializerVer14.RX_TUNE_VAL;
721 long rxFreq = optical.get().getRxFreqLmda();
722 long rxOffset = optical.get().getRxOffset();
723 long rxGridSpan = optical.get().getRxGridSpan();
724 annotations.set(AK_RX_TUNE_FEATURE, ((flags & rxTune) != 0) ? "enabled" : "disabled");
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000725 annotations.set(propFreq ? AK_RX_FREQ_HZ : AK_RX_LMDA_NM,
726 freqLmdaToAnnotation(rxFreq, useFreq));
727 annotations.set(propFreq ? AK_RX_OFFSET_HZ : AK_RX_OFFSET_LMDA_NM,
728 freqLmdaToAnnotation(rxOffset, useFreq));
729 annotations.set(propFreq ? AK_RX_GRID_SPAN_HZ : AK_RX_GRID_SPAN_LMDA_NM,
730 freqLmdaToAnnotation(rxGridSpan, useFreq));
Laszlo Papp7cf60372018-01-11 00:06:43 +0000731
732 int txPwrVal = OFPortStatsOpticalFlagsSerializerVer14.TX_PWR_VAL;
733 int txPwr = optical.get().getTxPwr();
734 annotations.set(AK_TX_PWR_FEATURE, ((flags & txPwrVal) != 0) ? "enabled" : "disabled");
735 annotations.set(AK_TX_PWR, Integer.toString(txPwr));
736
737 int rxPwrVal = OFPortStatsOpticalFlagsSerializerVer14.RX_PWR_VAL;
738 int rxPwr = optical.get().getRxPwr();
739 annotations.set(AK_RX_PWR_FEATURE, ((flags & rxPwrVal) != 0) ? "enabled" : "disabled");
740 annotations.set(AK_RX_PWR, Integer.toString(rxPwr));
741
742 int txBias = OFPortStatsOpticalFlagsSerializerVer14.TX_BIAS_VAL;
743 int biasCurrent = optical.get().getBiasCurrent();
744 annotations.set(AK_TX_BIAS_FEATURE, ((flags & txBias) != 0) ? "enabled" : "disabled");
745 annotations.set(AK_BIAS_CURRENT, Integer.toString(biasCurrent));
746
747 int txTemp = OFPortStatsOpticalFlagsSerializerVer14.TX_TEMP_VAL;
748 int temperature = optical.get().getTemperature();
749 annotations.set(AK_TX_TEMP_FEATURE, ((flags & txTemp) != 0) ? "enabled" : "disabled");
750 annotations.set(AK_TEMPERATURE, Integer.toString(temperature));
751 }
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700752 DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
753 DefaultPortStatistics stat = builder.setDeviceId(deviceId)
754 .setPort(entry.getPortNo().getPortNumber())
755 .setPacketsReceived(entry.getRxPackets().getValue())
756 .setPacketsSent(entry.getTxPackets().getValue())
757 .setBytesReceived(entry.getRxBytes().getValue())
758 .setBytesSent(entry.getTxBytes().getValue())
759 .setPacketsRxDropped(entry.getRxDropped().getValue())
760 .setPacketsTxDropped(entry.getTxDropped().getValue())
761 .setPacketsRxErrors(entry.getRxErrors().getValue())
762 .setPacketsTxErrors(entry.getTxErrors().getValue())
763 .setDurationSec(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationSec())
764 .setDurationNano(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationNsec())
Laszlo Papp7cf60372018-01-11 00:06:43 +0000765 .setAnnotations(annotations.build())
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700766 .build();
sangho538108b2015-04-08 14:29:20 -0700767
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700768 stats.add(stat);
769 } catch (Exception e) {
770 LOG.warn("Unable to process port stats", e);
771 }
sangho538108b2015-04-08 14:29:20 -0700772 }
773
774 return Collections.unmodifiableSet(stats);
sangho538108b2015-04-08 14:29:20 -0700775 }
776
777 private class InternalDeviceProvider implements OpenFlowSwitchListener, OpenFlowEventListener {
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700778
Srikanth Vavilapalli78baf582015-06-05 11:40:14 -0700779 private HashMap<Dpid, List<OFPortStatsEntry>> portStatsReplies = new HashMap<>();
Ray Milkey7abe50b2016-04-13 11:57:44 -0700780 private boolean isDisabled = false;
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700781
alshabibf1216ed2014-09-03 11:53:54 -0700782 @Override
tomd1900f32014-09-03 14:08:16 -0700783 public void switchAdded(Dpid dpid) {
alshabib6f5460b2014-09-03 14:46:17 -0700784 if (providerService == null) {
785 return;
786 }
tom782a7cf2014-09-11 23:58:38 -0700787 DeviceId did = deviceId(uri(dpid));
alshabib6f5460b2014-09-03 14:46:17 -0700788 OpenFlowSwitch sw = controller.getSwitch(dpid);
Lei Xudee1aff2015-10-16 00:45:10 -0500789 if (sw == null) {
sangyun-han147e6f42016-07-26 17:14:41 +0900790 LOG.error("Switch {} is not found", dpid);
Lei Xudee1aff2015-10-16 00:45:10 -0500791 return;
792 }
alshabib6f5460b2014-09-03 14:46:17 -0700793
alshabib7911a052014-10-16 17:49:37 -0700794 ChassisId cId = new ChassisId(dpid.value());
Ray Milkeye53f1712015-01-16 09:17:16 -0800795
Victor Silvaac8dab02016-11-28 16:33:08 -0300796 DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder()
andreafe3308f2015-10-06 15:51:25 -0700797 .set(AnnotationKeys.PROTOCOL, sw.factory().getVersion().toString())
798 .set(AnnotationKeys.CHANNEL_ID, sw.channelId())
Victor Silvaac8dab02016-11-28 16:33:08 -0300799 .set(AnnotationKeys.MANAGEMENT_ADDRESS, sw.channelId().split(":")[0]);
800
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800801 // FIXME following ignores driver specified by name
Victor Silvaac8dab02016-11-28 16:33:08 -0300802 Driver driver = driverService.getDriver(sw.manufacturerDescription(),
803 sw.hardwareDescription(),
804 sw.softwareDescription());
Thomas Vachuskaa79cbf72017-01-13 15:07:04 -0800805 // FIXME: The following breaks the STC tests and will require to be revisited.
806// if (driver != null) {
807// annotationsBuilder.set(AnnotationKeys.DRIVER, driver.name());
808// }
Victor Silvaac8dab02016-11-28 16:33:08 -0300809
810 SparseAnnotations annotations = annotationsBuilder.build();
Ray Milkeye53f1712015-01-16 09:17:16 -0800811
tomd1900f32014-09-03 14:08:16 -0700812 DeviceDescription description =
Marc De Leenheerb9311372015-07-09 11:36:49 -0700813 new DefaultDeviceDescription(did.uri(), sw.deviceType(),
Ray Milkeyd3edd032015-01-16 11:38:58 -0800814 sw.manufacturerDescription(),
tom782a7cf2014-09-11 23:58:38 -0700815 sw.hardwareDescription(),
816 sw.softwareDescription(),
alshabib7911a052014-10-16 17:49:37 -0700817 sw.serialNumber(),
Thomas Vachuska82041f52014-11-30 22:14:02 -0800818 cId, annotations);
tom782a7cf2014-09-11 23:58:38 -0700819 providerService.deviceConnected(did, description);
Ayaka Koshibe5460d622015-05-14 12:19:19 -0700820 providerService.updatePorts(did, buildPortDescriptions(sw));
Palash Kala496ef1a22018-03-21 14:57:50 +0900821 //sends port description stats request again if OF version supports
822 if (sw.features().getVersion().compareTo(OFVersion.OF_13) >= 0) {
823 sendPortDescStatsRequest(sw);
824 }
sangho538108b2015-04-08 14:29:20 -0700825
Laszlo Papp58174812018-01-16 13:29:47 +0000826 if (sw.features().getCapabilities().contains(OFCapabilities.PORT_STATS)) {
827 PortStatsCollector psc = new PortStatsCollector(timer, sw, portStatsPollFrequency);
828 stopCollectorIfNeeded(collectors.put(dpid, psc));
829 psc.start();
830 }
Lei Xudee1aff2015-10-16 00:45:10 -0500831
832 //figure out race condition for collectors.remove() and collectors.put()
833 if (controller.getSwitch(dpid) == null) {
834 switchRemoved(dpid);
835 }
alshabib25c8eec2014-09-04 16:41:31 -0700836 }
837
Palash Kala496ef1a22018-03-21 14:57:50 +0900838 /**
839 * Sends port description statistic request to switch if supported.
840 */
841 private void sendPortDescStatsRequest(OpenFlowSwitch sw) {
842 if (sw == null) {
843 return;
844 }
845 OFPortDescStatsRequest descStatsRequest = sw.factory().buildPortDescStatsRequest()
846 .build();
847 sw.sendMsg(descStatsRequest);
848 }
849
Thomas Vachuskaa394b952016-06-14 15:02:09 -0700850 private void stopCollectorIfNeeded(PortStatsCollector collector) {
851 if (collector != null) {
852 collector.stop();
853 }
854 }
855
alshabibf1216ed2014-09-03 11:53:54 -0700856 @Override
857 public void switchRemoved(Dpid dpid) {
Victor Silva03265dd2016-12-08 11:20:36 -0300858 stopCollectorIfNeeded(collectors.remove(dpid));
alshabib6f5460b2014-09-03 14:46:17 -0700859 if (providerService == null) {
860 return;
861 }
tom782a7cf2014-09-11 23:58:38 -0700862 providerService.deviceDisconnected(deviceId(uri(dpid)));
sangho538108b2015-04-08 14:29:20 -0700863 }
Ayaka Koshibe38594c22014-10-22 13:36:12 -0700864
865 @Override
866 public void switchChanged(Dpid dpid) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800867 LOG.debug("switchChanged({})", dpid);
Ayaka Koshibe38594c22014-10-22 13:36:12 -0700868 if (providerService == null) {
869 return;
870 }
871 DeviceId did = deviceId(uri(dpid));
872 OpenFlowSwitch sw = controller.getSwitch(dpid);
Lei Xudee1aff2015-10-16 00:45:10 -0500873 if (sw == null) {
sangyun-han147e6f42016-07-26 17:14:41 +0900874 LOG.error("Switch {} is not found", dpid);
Lei Xudee1aff2015-10-16 00:45:10 -0500875 return;
876 }
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800877 final List<PortDescription> ports = buildPortDescriptions(sw);
878 LOG.debug("switchChanged({}) {}", did, ports);
879 providerService.updatePorts(did, ports);
Ayaka Koshibe38594c22014-10-22 13:36:12 -0700880 }
881
alshabiba14f3642014-09-05 09:31:31 -0700882 @Override
883 public void portChanged(Dpid dpid, OFPortStatus status) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800884 LOG.debug("portChanged({},{})", dpid, status);
alshabibafc514a2014-12-01 14:44:05 -0800885 PortDescription portDescription = buildPortDescription(status);
Michal Machce774332017-01-25 11:02:55 +0100886 if (status.getReason() != OFPortReason.DELETE) {
887 providerService.portStatusChanged(deviceId(uri(dpid)), portDescription);
888 } else {
889 providerService.deletePort(deviceId(uri(dpid)), portDescription);
890 }
alshabibf1216ed2014-09-03 11:53:54 -0700891 }
892
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700893 @Override
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700894 public void receivedRoleReply(Dpid dpid, RoleState requested, RoleState response) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800895 LOG.debug("receivedRoleReply({},{},{})", dpid, requested, response);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700896 MastershipRole request = roleOf(requested);
897 MastershipRole reply = roleOf(response);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700898 providerService.receivedRoleReply(deviceId(uri(dpid)), request, reply);
899 }
900
901 /**
902 * Translates a RoleState to the corresponding MastershipRole.
903 *
Thomas Vachuskafc52fec2015-05-18 19:13:56 -0700904 * @param response role state
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700905 * @return a MastershipRole
906 */
907 private MastershipRole roleOf(RoleState response) {
908 switch (response) {
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700909 case MASTER:
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700910 return MastershipRole.MASTER;
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700911 case EQUAL:
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700912 return MastershipRole.STANDBY;
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700913 case SLAVE:
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700914 return MastershipRole.NONE;
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700915 default:
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700916 LOG.warn("unknown role {}", response);
917 return null;
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700918 }
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700919 }
920
alshabiba14f3642014-09-05 09:31:31 -0700921 /**
922 * Builds a list of port descriptions for a given list of ports.
tomff7eb7c2014-09-08 12:49:03 -0700923 *
alshabiba14f3642014-09-05 09:31:31 -0700924 * @return list of portdescriptions
925 */
Ayaka Koshibe5460d622015-05-14 12:19:19 -0700926 private List<PortDescription> buildPortDescriptions(OpenFlowSwitch sw) {
Yuta HIGUCHIf83c8cf2017-12-17 14:33:49 -0800927 List<OFPortDesc> ofPorts = sw.getPorts();
928 final List<PortDescription> portDescs = new ArrayList<>(ofPorts.size());
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +0200929 if (!((Device.Type.ROADM.equals(sw.deviceType())) ||
MaoLuc201ae42017-02-06 17:57:01 -0800930 (Device.Type.OTN.equals(sw.deviceType())) ||
931 (Device.Type.OPTICAL_AMPLIFIER.equals(sw.deviceType())))) {
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800932 // build regular (=non-optical) Device ports
Yuta HIGUCHIf83c8cf2017-12-17 14:33:49 -0800933 ofPorts.forEach(port -> portDescs.add(buildPortDescription(port)));
Yafit Hadara9a73de2015-09-06 13:52:52 +0300934 }
Marc De Leenheerb9311372015-07-09 11:36:49 -0700935
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800936 // TODO handle Optical Device, but plain OF devices(1.4 and later)
937
Marc De Leenheerb9311372015-07-09 11:36:49 -0700938 OpenFlowOpticalSwitch opsw;
939 switch (sw.deviceType()) {
940 case ROADM:
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +0200941 case OTN:
MaoLuc201ae42017-02-06 17:57:01 -0800942 case OPTICAL_AMPLIFIER:
Marc De Leenheerb9311372015-07-09 11:36:49 -0700943 opsw = (OpenFlowOpticalSwitch) sw;
Yafit Hadara9a73de2015-09-06 13:52:52 +0300944 List<OFPortDesc> ports = opsw.getPorts();
945 LOG.debug("SW ID {} , ETH- ODU CLT Ports {}", opsw.getId(), ports);
946 // ODU client ports are reported as ETH
947 ports.forEach(port -> portDescs.add(buildOduCltPortDescription(port)));
948
Marc De Leenheerb9311372015-07-09 11:36:49 -0700949 opsw.getPortTypes().forEach(type -> {
Yafit Hadara9a73de2015-09-06 13:52:52 +0300950 List<? extends OFObject> portsOf = opsw.getPortsOf(type);
951 LOG.debug("Ports Of{}", portsOf);
952 portsOf.forEach(
953 op -> {
Jimmy Yan4deb03b2016-06-24 10:53:54 -0700954 portDescs.add(buildPortDescription(type, op, opsw));
Yafit Hadara9a73de2015-09-06 13:52:52 +0300955 }
956 );
Marc De Leenheerb9311372015-07-09 11:36:49 -0700957 });
958 break;
959 case FIBER_SWITCH:
960 opsw = (OpenFlowOpticalSwitch) sw;
961 opsw.getPortTypes().forEach(type -> {
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -0700962 opsw.getPortsOf(type).forEach(op -> {
963 if (op instanceof OFPortDesc) {
964 // ports using standard optical extension
965 // TODO OFMessage -> PortDescription should
966 // probably be a Behaviour
967 portDescs.add(oms(buildPortDescription((OFPortDesc) op)));
968 } else if (op instanceof OFCalientPortDescStatsEntry) {
969 // calient extension
970 portDescs.add(buildPortDescription((OFCalientPortDescStatsEntry) op));
971 } else {
972 LOG.warn("Unexpected FIBER_SWITCH port {} on {}",
973 op, sw.getStringId());
974 }
975 });
Marc De Leenheerb9311372015-07-09 11:36:49 -0700976 });
977 break;
978 default:
979 break;
alshabib4680bb62014-09-04 17:15:08 -0700980 }
Marc De Leenheerb9311372015-07-09 11:36:49 -0700981
alshabib4680bb62014-09-04 17:15:08 -0700982 return portDescs;
983 }
984
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -0700985 /**
986 * Ensures returned PortDescription is an OMS port.
987 *
988 * @param descr input PortDescription
989 * @return OMS PortDescription
990 */
991 private PortDescription oms(PortDescription descr) {
992 // Hack until OFMessage -> PortDescription transformation
993 // becomes a Behaviour
994 if (descr.type() == Type.OMS) {
995 return descr;
996 }
997
998 Builder builder = DefaultAnnotations.builder();
999 builder.putAll(descr.annotations());
1000
1001 // set reasonable default when mandatory key is missing
1002 if (Strings.isNullOrEmpty(descr.annotations().value(AK_MIN_FREQ_HZ))) {
1003 builder.set(AK_MIN_FREQ_HZ, String.valueOf(Spectrum.O_BAND_MIN.asHz()));
1004 }
1005
1006 if (Strings.isNullOrEmpty(descr.annotations().value(AK_MAX_FREQ_HZ))) {
1007 builder.set(AK_MAX_FREQ_HZ, String.valueOf(Spectrum.O_BAND_MAX.asHz()));
1008 }
1009
1010 if (Strings.isNullOrEmpty(descr.annotations().value(AK_GRID_HZ))) {
1011 builder.set(AK_GRID_HZ, String.valueOf(Frequency.ofGHz(50).asHz()));
1012 }
1013
1014 return DefaultPortDescription.builder(descr)
1015 .type(Type.OMS)
1016 .annotations(builder.build())
1017 .build();
1018 }
1019
Yafit Hadara9a73de2015-09-06 13:52:52 +03001020 private PortDescription buildOduCltPortDescription(OFPortDesc port) {
1021 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
1022 boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) &&
1023 !port.getConfig().contains(OFPortConfig.PORT_DOWN);
Rimon Ashkenazyd15ebf52016-01-06 14:36:13 +02001024 Long portSpeedInMbps = portSpeed(port);
Toru Furusawa72ee30c2016-01-08 13:29:04 -08001025 CltSignalType sigType = null;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001026
Rimon Ashkenazyd15ebf52016-01-06 14:36:13 +02001027 switch (portSpeedInMbps.toString()) {
1028 case "1000":
Toru Furusawa72ee30c2016-01-08 13:29:04 -08001029 sigType = CltSignalType.CLT_1GBE;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001030 break;
Rimon Ashkenazyd15ebf52016-01-06 14:36:13 +02001031 case "10000":
Toru Furusawa72ee30c2016-01-08 13:29:04 -08001032 sigType = CltSignalType.CLT_10GBE;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001033 break;
Rimon Ashkenazyd15ebf52016-01-06 14:36:13 +02001034 case "40000":
Toru Furusawa72ee30c2016-01-08 13:29:04 -08001035 sigType = CltSignalType.CLT_40GBE;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001036 break;
Rimon Ashkenazyd15ebf52016-01-06 14:36:13 +02001037 case "100000":
Toru Furusawa72ee30c2016-01-08 13:29:04 -08001038 sigType = CltSignalType.CLT_100GBE;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001039 break;
1040 default:
Ray Milkey986a47a2018-01-25 11:38:51 -08001041 throw new IllegalArgumentException("Un recognize OduClt speed: " + portSpeedInMbps.toString());
Yafit Hadara9a73de2015-09-06 13:52:52 +03001042 }
1043
1044 SparseAnnotations annotations = buildOduCltAnnotation(port);
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -07001045 return oduCltPortDescription(portNo, enabled, sigType, annotations);
Yafit Hadara9a73de2015-09-06 13:52:52 +03001046 }
1047
1048 private SparseAnnotations buildOduCltAnnotation(OFPortDesc port) {
1049 SparseAnnotations annotations = null;
1050 String portName = Strings.emptyToNull(port.getName());
1051 if (portName != null) {
1052 annotations = DefaultAnnotations.builder()
1053 .set(AnnotationKeys.PORT_NAME, portName)
1054 .set(AnnotationKeys.STATIC_PORT, Boolean.TRUE.toString()).build();
1055 }
1056 return annotations;
1057 }
1058
Jimmy Yan4deb03b2016-06-24 10:53:54 -07001059 private PortDescription buildPortDescription(PortDescPropertyType ptype, OFObject port,
1060 OpenFlowOpticalSwitch opsw) {
yjimmyy646aa022016-07-05 12:09:50 -07001061 if (port instanceof OFPortOptical) {
Jimmy Yan4deb03b2016-06-24 10:53:54 -07001062 return buildPortDescription(ptype, (OFPortOptical) port, opsw);
Yafit Hadara9a73de2015-09-06 13:52:52 +03001063 }
1064 return buildPortDescription(ptype, (OFExpPort) port);
1065 }
1066
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +02001067 private boolean matchingOtuPortSignalTypes(OFPortOpticalTransportSignalType sigType,
1068 OduSignalType oduSignalType) {
1069 switch (sigType) {
1070 case OTU2:
1071 if (oduSignalType == OduSignalType.ODU2) {
1072 return true;
1073 }
1074 break;
1075 case OTU4:
1076 if (oduSignalType == OduSignalType.ODU4) {
1077 return true;
1078 }
1079 break;
1080 default:
1081 break;
1082 }
1083 return false;
1084 }
Yafit Hadara9a73de2015-09-06 13:52:52 +03001085 /**
1086 * Build a portDescription from a given a port description describing some
1087 * Optical port.
1088 *
1089 * @param ptype description property type.
1090 * @param port the port to build from.
1091 * @return portDescription for the port.
1092 */
1093 private PortDescription buildPortDescription(PortDescPropertyType ptype, OFExpPort port) {
1094 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
1095 boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN)
1096 && !port.getConfig().contains(OFPortConfig.PORT_DOWN);
mskalac584bd92017-11-28 15:51:17 +01001097 boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN);
1098 SparseAnnotations annotations = makePortAnnotation(port.getName(),
1099 port.getHwAddr().toString(),
1100 adminDown).build();
Yafit Hadara9a73de2015-09-06 13:52:52 +03001101
1102 OFExpPortDescPropOpticalTransport firstProp = port.getProperties().get(0);
1103 OFPortOpticalTransportSignalType sigType = firstProp.getPortSignalType();
1104
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -08001105 PortDescription portDes = null;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001106 switch (sigType) {
1107 case OMSN:
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -07001108 portDes = omsPortDescription(portNo, enabled,
Rimon Ashkenazye3201032016-01-11 14:27:30 +02001109 FREQ191_7, FREQ191_7.add(FREQ4_4), FREQ50, annotations);
Yafit Hadara9a73de2015-09-06 13:52:52 +03001110 break;
1111 case OCH:
1112 OFExpPortOpticalTransportLayerEntry entry = firstProp.getFeatures().get(0).getValue().get(0);
1113 OFPortOpticalTransportLayerClass layerClass = entry.getLayerClass();
1114 if (!OFPortOpticalTransportLayerClass.ODU.equals(layerClass)) {
1115 LOG.error("Unsupported layer Class {} ", layerClass);
1116 return null;
1117 }
1118
1119 // convert to ONOS OduSignalType
1120 OduSignalType oduSignalType = OpenFlowDeviceValueMapper.
1121 lookupOduSignalType((byte) entry.getSignalType());
1122 //OchSignal is needed for OchPortDescription constructor,
1123 //yet not relevant for tunable OCH port, creating with default parameters
1124 OchSignal signalId = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 1, 1);
1125
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -08001126 portDes = ochPortDescription(portNo, enabled,
1127 oduSignalType, true,
1128 signalId, annotations);
Yafit Hadara9a73de2015-09-06 13:52:52 +03001129
1130 break;
1131 case OTU2:
1132 case OTU4:
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +02001133 entry = firstProp.getFeatures().get(0).getValue().get(0);
1134 layerClass = entry.getLayerClass();
1135 if (!OFPortOpticalTransportLayerClass.ODU.equals(layerClass)) {
1136 LOG.error("Unsupported layer Class {} ", layerClass);
1137 return null;
1138 }
1139
1140 // convert to ONOS OduSignalType
1141 OduSignalType oduSignalTypeOtuPort = OpenFlowDeviceValueMapper.
1142 lookupOduSignalType((byte) entry.getSignalType());
1143 if (!matchingOtuPortSignalTypes(sigType, oduSignalTypeOtuPort)) {
1144 LOG.error("Wrong oduSignalType {} for OTU Port sigType {} ", oduSignalTypeOtuPort, sigType);
1145 return null;
1146 }
1147 OtuSignalType otuSignalType =
1148 ((sigType == OFPortOpticalTransportSignalType.OTU2) ? OtuSignalType.OTU2 :
1149 OtuSignalType.OTU4);
HIGUCHI Yuta5be3e822016-05-03 13:51:42 -07001150 portDes = otuPortDescription(portNo, enabled, otuSignalType, annotations);
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +02001151 break;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001152 default:
1153 break;
1154 }
1155
1156 return portDes;
1157 }
1158
alshabiba14f3642014-09-05 09:31:31 -07001159 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001160 * Creates an annotation builder for the port name if one is available.
Ray Milkeye0fade72015-01-15 13:29:47 -08001161 *
lishuai4ee42042015-11-30 17:19:21 +08001162 * @param portName the port name
1163 * @param portMac the port mac
mskalac584bd92017-11-28 15:51:17 +01001164 * @param adminDown the port admin state
1165 * @return annotation builder containing port admin state, port name
1166 * and/or port MAC if any of the two is found
Ray Milkeye0fade72015-01-15 13:29:47 -08001167 */
mskalac584bd92017-11-28 15:51:17 +01001168 private DefaultAnnotations.Builder makePortAnnotation(String portName, String portMac, boolean adminDown) {
Andrea Campanellac8b871a2017-01-19 13:53:05 -08001169 DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
lishuai4ee42042015-11-30 17:19:21 +08001170 String pName = Strings.emptyToNull(portName);
1171 String pMac = Strings.emptyToNull(portMac);
Andrea Campanellac8b871a2017-01-19 13:53:05 -08001172 if (pName != null) {
1173 builder.set(AnnotationKeys.PORT_NAME, pName);
Ray Milkeye0fade72015-01-15 13:29:47 -08001174 }
Andrea Campanellac8b871a2017-01-19 13:53:05 -08001175 if (pMac != null) {
1176 builder.set(AnnotationKeys.PORT_MAC, pMac);
1177 }
mskalac584bd92017-11-28 15:51:17 +01001178 String adminState = adminDown ? "disabled" : "enabled";
1179 builder.set(AnnotationKeys.ADMIN_STATE, adminState);
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001180 return builder;
1181 }
1182
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001183 private PortDescription buildPortDescription14(OFPortDesc port) {
1184 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
1185 boolean enabled =
1186 !port.getState().contains(OFPortState.LINK_DOWN) &&
1187 !port.getConfig().contains(OFPortConfig.PORT_DOWN);
mskalac584bd92017-11-28 15:51:17 +01001188 boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN);
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001189 Builder annotations = makePortAnnotation(port.getName(),
mskalac584bd92017-11-28 15:51:17 +01001190 port.getHwAddr().toString(),
1191 adminDown);
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001192
1193 Optional<OFPortDescPropEthernet> ether = port.getProperties().stream()
1194 .filter(OFPortDescPropEthernet.class::isInstance)
1195 .map(OFPortDescPropEthernet.class::cast)
1196 .findAny();
1197 if (ether.isPresent()) {
1198 // ethernet port
1199 // TODO parse other part of OFPortDescPropEthernet if necessary
Yuta HIGUCHI53e47962018-03-01 23:50:48 -08001200 return DefaultPortDescription.builder()
1201 .withPortNumber(portNo)
1202 .isEnabled(enabled)
1203 .type(COPPER)
1204 .portSpeed(portSpeed(port))
1205 .annotations(annotations.build())
1206 .build();
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001207 }
1208
1209 Optional<OFPortDescPropOptical> optical = port.getProperties().stream()
1210 .filter(OFPortDescPropOptical.class::isInstance)
1211 .map(OFPortDescPropOptical.class::cast)
1212 .findAny();
1213 if (optical.isPresent()) {
1214 // optical port
1215
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -07001216 // FIXME is there a OF version neutral way to access
1217 // OFOpticalPortFeaturesSerializerVer14
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001218
Laszlo Papp20cfb6f2018-01-08 16:06:53 +00001219 long supported = optical.get().getSupported();
1220 long rxMin = optical.get().getRxMinFreqLmda();
1221 long rxMax = optical.get().getRxMaxFreqLmda();
1222 long rxGrid = optical.get().getRxGridFreqLmda();
1223 long txMin = optical.get().getTxMinFreqLmda();
1224 long txMax = optical.get().getTxMaxFreqLmda();
1225 long txGrid = optical.get().getTxGridFreqLmda();
1226
1227 int txTune = OFOpticalPortFeaturesSerializerVer14.TX_TUNE_VAL;
1228 int rxTune = OFOpticalPortFeaturesSerializerVer14.RX_TUNE_VAL;
1229 annotations.set(AK_TX_TUNE_FEATURE,
1230 ((supported & txTune) != 0) ? "enabled" : "disabled");
1231 annotations.set(AK_RX_TUNE_FEATURE,
1232 ((supported & rxTune) != 0) ? "enabled" : "disabled");
1233
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001234 // wire value for OFOpticalPortFeatures.USE_FREQ
Laszlo Papp8e8ff052018-01-16 09:55:45 +00001235 boolean useFreq = (supported & OFOpticalPortFeaturesSerializerVer14.USE_FREQ_VAL) != 0;
1236 annotations.set(AK_USE_FREQ_FEATURE, useFreq ? "enabled" : "disabled");
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001237
Laszlo Pappbf2cd742018-01-16 11:49:04 +00001238 annotations.set(propFreq ? AK_RX_MIN_FREQ_HZ : AK_RX_MIN_LMDA_NM,
1239 freqLmdaToAnnotation(rxMin, useFreq));
1240 annotations.set(propFreq ? AK_RX_MAX_FREQ_HZ : AK_RX_MAX_LMDA_NM,
1241 freqLmdaToAnnotation(rxMax, useFreq));
1242 annotations.set(propFreq ? AK_RX_GRID_HZ : AK_RX_GRID_LMDA_NM,
1243 freqLmdaToAnnotation(rxGrid, useFreq));
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001244
Laszlo Pappbf2cd742018-01-16 11:49:04 +00001245 annotations.set(propFreq ? AK_TX_MIN_FREQ_HZ : AK_TX_MIN_LMDA_NM,
1246 freqLmdaToAnnotation(txMin, useFreq));
1247 annotations.set(propFreq ? AK_TX_MAX_FREQ_HZ : AK_TX_MAX_LMDA_NM,
1248 freqLmdaToAnnotation(txMax, useFreq));
1249 annotations.set(propFreq ? AK_TX_GRID_HZ : AK_TX_GRID_LMDA_NM,
1250 freqLmdaToAnnotation(txGrid, useFreq));
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001251
Laszlo Papp8e8ff052018-01-16 09:55:45 +00001252 // FIXME pretty confident this is not going to happen
1253 // unless Device models Tx/Rx ports as separate port
1254 if (rxMin == txMin) {
Laszlo Pappbf2cd742018-01-16 11:49:04 +00001255 annotations.set(propFreq ? AK_MIN_FREQ_HZ : AK_MIN_LMDA_NM,
Laszlo Papp8e8ff052018-01-16 09:55:45 +00001256 freqLmdaToAnnotation(rxMin, useFreq));
1257 }
1258 if (rxMax == txMax) {
Laszlo Pappbf2cd742018-01-16 11:49:04 +00001259 annotations.set(propFreq ? AK_MAX_FREQ_HZ : AK_MAX_LMDA_NM,
Laszlo Papp8e8ff052018-01-16 09:55:45 +00001260 freqLmdaToAnnotation(rxMax, useFreq));
1261 }
1262 if (rxGrid == txGrid) {
Laszlo Pappbf2cd742018-01-16 11:49:04 +00001263 annotations.set(propFreq ? AK_GRID_HZ : AK_GRID_LMDA_NM,
Laszlo Papp8e8ff052018-01-16 09:55:45 +00001264 freqLmdaToAnnotation(rxGrid, useFreq));
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001265 }
Laszlo Papp20cfb6f2018-01-08 16:06:53 +00001266
1267 int txPwr = OFOpticalPortFeaturesSerializerVer14.TX_PWR_VAL;
1268 long txPwrMin = optical.get().getTxPwrMin();
1269 long txPwrMax = optical.get().getTxPwrMax();
1270 annotations.set(AK_TX_PWR_FEATURE, ((supported & txPwr) != 0) ? "enabled" : "disabled");
1271 annotations.set(AK_TX_PWR_MIN, Long.toString(txPwrMin));
1272 annotations.set(AK_TX_PWR_MAX, Long.toString(txPwrMax));
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001273
1274 // TODO How to determine appropriate port type?
1275
Yuta HIGUCHI53e47962018-03-01 23:50:48 -08001276 return DefaultPortDescription.builder()
1277 .withPortNumber(portNo)
1278 .isEnabled(enabled)
1279 .type(FIBER)
1280 .portSpeed(portSpeed(port))
1281 .annotations(annotations.build())
1282 .build();
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001283 }
1284
1285 // fall back default
Yuta HIGUCHI53e47962018-03-01 23:50:48 -08001286 return DefaultPortDescription.builder()
1287 .withPortNumber(portNo)
1288 .isEnabled(enabled)
1289 .type(COPPER)
1290 .portSpeed(portSpeed(port))
1291 .annotations(annotations.build())
1292 .build();
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001293
Ray Milkeye0fade72015-01-15 13:29:47 -08001294 }
1295
1296 /**
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001297 * Build a portDescription from a given Ethernet port description.
tomff7eb7c2014-09-08 12:49:03 -07001298 *
alshabiba14f3642014-09-05 09:31:31 -07001299 * @param port the port to build from.
1300 * @return portDescription for the port.
1301 */
1302 private PortDescription buildPortDescription(OFPortDesc port) {
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001303 if (port.getVersion().wireVersion >= OFVersion.OF_14.getWireVersion()) {
1304 return buildPortDescription14(port);
1305 }
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001306 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
1307 boolean enabled =
1308 !port.getState().contains(OFPortState.LINK_DOWN) &&
1309 !port.getConfig().contains(OFPortConfig.PORT_DOWN);
1310 Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER;
mskalac584bd92017-11-28 15:51:17 +01001311 boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN);
1312 SparseAnnotations annotations = makePortAnnotation(port.getName(),
1313 port.getHwAddr().toString(),
1314 adminDown).build();
Yuta HIGUCHI53e47962018-03-01 23:50:48 -08001315 return DefaultPortDescription.builder()
1316 .withPortNumber(portNo)
1317 .isEnabled(enabled)
1318 .type(type)
1319 .portSpeed(portSpeed(port))
1320 .annotations(annotations)
1321 .build();
alshabiba14f3642014-09-05 09:31:31 -07001322 }
Ayaka Koshibeab91cc42014-09-25 10:20:52 -07001323
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001324 /**
1325 * Build a portDescription from a given a port description describing some
1326 * Optical port.
1327 *
1328 * @param port description property type.
1329 * @param port the port to build from.
1330 * @return portDescription for the port.
1331 */
Jimmy Yan4deb03b2016-06-24 10:53:54 -07001332 private PortDescription buildPortDescription(PortDescPropertyType ptype, OFPortOptical port,
1333 OpenFlowOpticalSwitch opsw) {
Jon Hallcbd1b392017-01-18 20:15:44 -08001334 checkArgument(!port.getDesc().isEmpty());
Marc De Leenheerfc913dd2015-07-30 16:04:55 -07001335
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001336 // Minimally functional fixture. This needs to be fixed as we add better support.
1337 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
Ayaka Koshibe74b55272015-05-28 15:16:04 -07001338
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001339 boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN)
1340 && !port.getConfig().contains(OFPortConfig.PORT_DOWN);
mskalac584bd92017-11-28 15:51:17 +01001341 boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN);
1342 SparseAnnotations annotations = makePortAnnotation(port.getName(),
1343 port.getHwAddr().toString(),
1344 adminDown).build();
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001345
1346 if (port.getVersion() == OFVersion.OF_13
1347 && ptype == PortDescPropertyType.OPTICAL_TRANSPORT) {
1348 // At this point, not much is carried in the optical port message.
Ayaka Koshibeae541732015-05-19 13:37:27 -07001349 LOG.debug("Optical transport port message {}", port.toString());
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001350 } else {
1351 // removable once 1.4+ support complete.
Ayaka Koshibeae541732015-05-19 13:37:27 -07001352 LOG.debug("Unsupported optical port properties");
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001353 }
Marc De Leenheerfc913dd2015-07-30 16:04:55 -07001354
1355 OFPortDescPropOpticalTransport desc = port.getDesc().get(0);
1356 switch (desc.getPortSignalType()) {
1357 // FIXME: use constants once loxi has full optical extensions
1358 case 2: // OMS port
1359 // Assume complete optical spectrum and 50 GHz grid
Jimmy Yan4deb03b2016-06-24 10:53:54 -07001360 Set<OchSignal> signals = null;
1361 if (opsw instanceof HandlerBehaviour) {
1362 DriverHandler driverHandler = ((HandlerBehaviour) opsw).handler();
1363 if (driverHandler != null && driverHandler.hasBehaviour(LambdaQuery.class)) {
1364 try {
1365 signals = driverHandler.behaviour(LambdaQuery.class).queryLambdas(portNo);
1366 } catch (NullPointerException e) {
1367 signals = null;
1368 }
1369 }
1370 }
1371 Frequency minFreq;
1372 Frequency maxFreq;
1373 Frequency channelSpacing;
1374 if (signals == null || signals.isEmpty()) {
1375 minFreq = Spectrum.U_BAND_MIN;
1376 maxFreq = Spectrum.O_BAND_MAX;
1377 channelSpacing = Frequency.ofGHz(50);
1378 } else {
1379 Comparator<OchSignal> compare =
1380 (OchSignal a, OchSignal b) -> a.spacingMultiplier() - b.spacingMultiplier();
1381 OchSignal minOch = Collections.min(signals, compare);
1382 OchSignal maxOch = Collections.max(signals, compare);
1383 minFreq = minOch.centralFrequency();
1384 maxFreq = maxOch.centralFrequency();
1385 channelSpacing = minOch.channelSpacing().frequency();
1386 }
1387 return omsPortDescription(portNo, enabled, minFreq,
1388 maxFreq, channelSpacing, annotations);
Marc De Leenheerfc913dd2015-07-30 16:04:55 -07001389 case 5: // OCH port
1390 OchSignal signal = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 0, 4);
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -08001391 return ochPortDescription(portNo, enabled, OduSignalType.ODU4,
Marc De Leenheerfc913dd2015-07-30 16:04:55 -07001392 true, signal, annotations);
1393 default:
1394 break;
1395 }
1396
Yuta HIGUCHI53e47962018-03-01 23:50:48 -08001397 return DefaultPortDescription.builder()
1398 .withPortNumber(portNo)
1399 .isEnabled(enabled)
1400 .type(FIBER)
1401 .portSpeed(0)
1402 .annotations(annotations)
1403 .build();
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001404 }
1405
Marc De Leenheerb9311372015-07-09 11:36:49 -07001406 /**
1407 * Build a portDescription from a given port description describing a fiber switch optical port.
1408 *
1409 * @param port description property type.
1410 * @param port the port to build from.
1411 * @return portDescription for the port.
1412 */
1413 private PortDescription buildPortDescription(OFCalientPortDescStatsEntry port) {
1414 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
1415
Marc De Leenheerc662d322016-02-18 16:05:10 -08001416 // Use the alias name if it's available
1417 String name = port.getName();
1418 List<OFCalientPortDescProp> props = port.getProperties();
Jon Hallcbd1b392017-01-18 20:15:44 -08001419 if (props != null && !props.isEmpty()) {
Marc De Leenheerc662d322016-02-18 16:05:10 -08001420 OFCalientPortDescPropOptical propOptical = (OFCalientPortDescPropOptical) props.get(0);
1421 if (propOptical != null) {
1422 name = propOptical.getInAlias();
1423 }
1424 }
1425
Marc De Leenheerb9311372015-07-09 11:36:49 -07001426 // FIXME when Calient OF agent reports port status
1427 boolean enabled = true;
mskalac584bd92017-11-28 15:51:17 +01001428 boolean adminDown = false;
1429 SparseAnnotations annotations = makePortAnnotation(name, port.getHwAddr().toString(), adminDown).build();
Marc De Leenheerb9311372015-07-09 11:36:49 -07001430
Marc De Leenheerfc913dd2015-07-30 16:04:55 -07001431 // S160 data sheet
1432 // Wavelength range: 1260 - 1630 nm, grid is irrelevant for this type of switch
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -07001433 return omsPortDescription(portNo, enabled,
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -07001434 Spectrum.O_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(50), annotations);
Marc De Leenheerb9311372015-07-09 11:36:49 -07001435 }
1436
alshabibafc514a2014-12-01 14:44:05 -08001437 private PortDescription buildPortDescription(OFPortStatus status) {
1438 OFPortDesc port = status.getDesc();
1439 if (status.getReason() != OFPortReason.DELETE) {
1440 return buildPortDescription(port);
1441 } else {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001442 PortDescription desc = buildPortDescription(port);
1443 if (desc.isEnabled()) {
1444 return DefaultPortDescription.builder(desc)
1445 .isEnabled(false)
1446 .build();
1447 }
1448 return desc;
alshabibafc514a2014-12-01 14:44:05 -08001449 }
1450 }
1451
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001452 /**
1453 * Returns port speed in Mbps.
1454 *
1455 * @param port description to parse
1456 * @return port speed in Mbps
1457 */
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001458 private long portSpeed(OFPortDesc port) {
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001459 if (port.getVersion().getWireVersion() >= OFVersion.OF_14.getWireVersion()) {
1460 // OFPortDescPropEthernet
1461 return port.getProperties().stream()
1462 .filter(OFPortDescPropEthernet.class::isInstance)
1463 .map(OFPortDescPropEthernet.class::cast)
1464 .mapToLong(OFPortDescPropEthernet::getCurrSpeed)
1465 .map(kbps -> kbps / KBPS)
1466 .findAny()
1467 .orElse(PortSpeed.SPEED_NONE.getSpeedBps() / MBPS);
1468 }
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001469 if (port.getVersion() == OFVersion.OF_13) {
Charles Chan25b77322015-12-13 01:00:56 -08001470 // Note: getCurrSpeed() returns a value in kbps (this also applies to OF_11 and OF_12)
1471 return port.getCurrSpeed() / KBPS;
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001472 }
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001473 // < OF1.3
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001474 PortSpeed portSpeed = PortSpeed.SPEED_NONE;
1475 for (OFPortFeatures feat : port.getCurr()) {
1476 portSpeed = PortSpeed.max(portSpeed, feat.getPortSpeed());
1477 }
Thomas Vachuska98eda532014-10-29 17:31:02 -07001478 return portSpeed.getSpeedBps() / MBPS;
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001479 }
sangho538108b2015-04-08 14:29:20 -07001480
1481 @Override
1482 public void handleMessage(Dpid dpid, OFMessage msg) {
Ray Milkey7abe50b2016-04-13 11:57:44 -07001483 if (isDisabled) {
1484 return;
sangho538108b2015-04-08 14:29:20 -07001485 }
Ray Milkey7abe50b2016-04-13 11:57:44 -07001486
1487 try {
1488 switch (msg.getType()) {
1489 case STATS_REPLY:
1490 if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) {
1491 OFPortStatsReply portStatsReply = (OFPortStatsReply) msg;
1492 List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid);
1493 if (portStatsReplyList == null) {
Madan Jampani84382b92016-06-22 08:26:49 -07001494 portStatsReplyList = Lists.newCopyOnWriteArrayList();
Ray Milkey7abe50b2016-04-13 11:57:44 -07001495 }
1496 portStatsReplyList.addAll(portStatsReply.getEntries());
1497 portStatsReplies.put(dpid, portStatsReplyList);
1498 if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
Charles Chanb3ef0db2016-05-03 11:11:00 -07001499 List<OFPortStatsEntry> statsEntries = portStatsReplies.get(dpid);
1500 if (statsEntries != null) {
1501 pushPortMetrics(dpid, statsEntries);
1502 statsEntries.clear();
1503 }
Ray Milkey7abe50b2016-04-13 11:57:44 -07001504 }
yjimmyy646aa022016-07-05 12:09:50 -07001505 } else if (((OFStatsReply) msg).getStatsType() == OFStatsType.EXPERIMENTER) {
1506 OpenFlowSwitch sw = controller.getSwitch(dpid);
sangyun-han147e6f42016-07-26 17:14:41 +09001507 if (sw == null) {
1508 LOG.error("Switch {} is not found", dpid);
1509 break;
1510 }
yjimmyy646aa022016-07-05 12:09:50 -07001511 if (sw instanceof OpenFlowOpticalSwitch) {
1512 // Optical switch uses experimenter stats message to update power
1513 List<PortDescription> portDescs =
1514 ((OpenFlowOpticalSwitch) sw).processExpPortStats(msg);
1515 if (!portDescs.isEmpty()) {
1516 providerService.updatePorts(DeviceId.deviceId(Dpid.uri(dpid)), portDescs);
1517 }
1518 }
Ray Milkey7abe50b2016-04-13 11:57:44 -07001519 }
1520 break;
1521 case ERROR:
1522 if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) {
1523 LOG.error("port mod failed");
1524 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -08001525 break;
Ray Milkey7abe50b2016-04-13 11:57:44 -07001526 default:
1527 break;
1528 }
1529 } catch (IllegalStateException e) {
1530 // system is shutting down and the providerService is no longer
1531 // valid. Messages cannot be processed.
1532 }
1533 }
1534
1535 private void disable() {
1536 isDisabled = true;
sangho538108b2015-04-08 14:29:20 -07001537 }
alshabibf1216ed2014-09-03 11:53:54 -07001538 }
Saurav Dasa2d37502016-03-25 17:50:40 -07001539
tomb5a46e62014-08-26 14:20:00 -07001540}