blob: 611733971daa14ec55e95c0344683dc1ad2ed6b0 [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;
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700142import static org.onosproject.provider.of.device.impl.OsgiPropertyConstants.*;
Marc De Leenheer8aba62f2017-04-25 14:33:37 -0700143import static org.slf4j.LoggerFactory.getLogger;
tom782a7cf2014-09-11 23:58:38 -0700144
tomb5a46e62014-08-26 14:20:00 -0700145/**
tomb1260e42014-08-26 18:39:57 -0700146 * Provider which uses an OpenFlow controller to detect network
tome06f8552014-08-26 16:58:42 -0700147 * infrastructure devices.
tomb5a46e62014-08-26 14:20:00 -0700148 */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700149@Component(immediate = true,
150 property = {
151 POLL_FREQ + ":Integer=" + POLL_FREQ_DEFAULT,
152 PROP_FREQ + ":Boolean=" + PROP_FREQ_DEFAULT,
153 })
tomab21e7c2014-08-26 15:23:08 -0700154public class OpenFlowDeviceProvider extends AbstractProvider implements DeviceProvider {
tomb5a46e62014-08-26 14:20:00 -0700155
alshabiba89cc582014-09-09 16:43:00 -0700156 private static final Logger LOG = getLogger(OpenFlowDeviceProvider.class);
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700157
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800158 // TODO Some duplicate with one defined in OpticalAnnotations
159 // slice out optical specific handling and consolidate.
160 /**
161 * Annotation key for minimum frequency in Hz.
162 * Value is expected to be an integer.
163 */
164 public static final String AK_MIN_FREQ_HZ = "minFrequency";
165
166 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000167 * Annotation key for minimum lambda in nm.
168 * Value is expected to be an integer.
169 */
170 public static final String AK_MIN_LMDA_NM = "minLambda";
171
172 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800173 * Annotation key for maximum frequency in Hz.
174 * Value is expected be an integer.
175 */
176 public static final String AK_MAX_FREQ_HZ = "maxFrequency";
177
178 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000179 * Annotation key for maximum lambda in nm.
180 * Value is expected be an integer.
181 */
182 public static final String AK_MAX_LMDA_NM = "maxLambda";
183
184 /**
185 * Annotation key for grid frequency in Hz.
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800186 * Value is expected to be an integer.
187 */
188 public static final String AK_GRID_HZ = "grid";
189
Laszlo Papp20cfb6f2018-01-08 16:06:53 +0000190 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000191 * Annotation key for grid lambda in nm.
192 * Value is expected to be an integer.
193 */
194 public static final String AK_GRID_LMDA_NM = "gridLambda";
195
196 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800197 * Annotation key for minimum frequency in Hz.
198 * Value is expected to be an integer.
199 */
200 public static final String AK_TX_MIN_FREQ_HZ = "txMinFrequency";
201
202 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000203 * Annotation key for minimum lambda in nm.
204 * Value is expected to be an integer.
205 */
206 public static final String AK_TX_MIN_LMDA_NM = "txMinLambda";
207
208 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800209 * Annotation key for maximum frequency in Hz.
210 * Value is expected be an integer.
211 */
212 public static final String AK_TX_MAX_FREQ_HZ = "txMaxFrequency";
213
214 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000215 * Annotation key for maximum lambda in nm.
216 * Value is expected be an integer.
217 */
218 public static final String AK_TX_MAX_LMDA_NM = "txMaxLambda";
219
220 /**
221 * Annotation key for grid frequency in Hz.
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800222 * Value is expected to be an integer.
223 */
224 public static final String AK_TX_GRID_HZ = "txGrid";
225
226 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000227 * Annotation key for grid lambda in nm.
228 * Value is expected to be an integer.
229 */
230 public static final String AK_TX_GRID_LMDA_NM = "txGridLambda";
231
232 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800233 * Annotation key for minimum frequency in Hz.
234 * Value is expected to be an integer.
235 */
236 public static final String AK_RX_MIN_FREQ_HZ = "rxMinFrequency";
237
238 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000239 * Annotation key for minimum lambda in nm.
240 * Value is expected to be an integer.
241 */
242 public static final String AK_RX_MIN_LMDA_NM = "rxMinLambda";
243
244 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800245 * Annotation key for maximum frequency in Hz.
246 * Value is expected be an integer.
247 */
248 public static final String AK_RX_MAX_FREQ_HZ = "rxMaxFrequency";
249
250 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000251 * Annotation key for maximum lambda in nm.
252 * Value is expected be an integer.
253 */
254 public static final String AK_RX_MAX_LMDA_NM = "rxMaxLambda";
255
256 /**
257 * Annotation key for grid frequency in Hz.
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800258 * Value is expected to be an integer.
259 */
260 public static final String AK_RX_GRID_HZ = "rxGrid";
261
Laszlo Papp20cfb6f2018-01-08 16:06:53 +0000262 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000263 * Annotation key for grid lambda in nm.
264 * Value is expected to be an integer.
265 */
266 public static final String AK_RX_GRID_LMDA_NM = "rxGridLambda";
267
268 /**
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000269 * Annotation key for indicating frequency must be used instead of
270 * wavelength for port tuning.
271 * Value is expected to be "enabled" or "disabled"
272 */
273 public static final String AK_USE_FREQ_FEATURE = "useFreqFeature";
274
275 /**
Laszlo Papp20cfb6f2018-01-08 16:06:53 +0000276 * Annotation key for minimum transmit power in dBm*10.
277 * Value is expected to be an integer.
278 */
279 public static final String AK_TX_PWR_MIN = "txPowerMin";
280
281 /**
282 * Annotation key for maximum transmit power in dBm*10.
283 * Value is expected to be an integer.
284 */
285 public static final String AK_TX_PWR_MAX = "txPowerMax";
286
Laszlo Papp7cf60372018-01-11 00:06:43 +0000287
288
289 // Port Stats annotations
290
291 /**
292 * Annotation key for transmit frequency in Hz.
293 * Value is expected be an integer.
294 */
295 public static final String AK_TX_FREQ_HZ = "txFrequency";
296
297 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000298 * Annotation key for transmit lambda in nm.
299 * Value is expected be an integer.
300 */
301 public static final String AK_TX_LMDA_NM = "txLambda";
302
303 /**
304 * Annotation key for transmit offset frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000305 * Value is expected be an integer.
306 */
307 public static final String AK_TX_OFFSET_HZ = "txOffset";
308
309 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000310 * Annotation key for transmit offset in nm.
311 * Value is expected be an integer.
312 */
313 public static final String AK_TX_OFFSET_LMDA_NM = "txOffsetLambda";
314
315 /**
316 * Annotation key for transmit grid spacing frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000317 * Value is expected be an integer.
318 */
319 public static final String AK_TX_GRID_SPAN_HZ = "txGridSpan";
320
321 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000322 * Annotation key for transmit grid spacing lambda in nm.
323 * Value is expected be an integer.
324 */
325 public static final String AK_TX_GRID_SPAN_LMDA_NM = "txGridSpanLambda";
326
327 /**
Laszlo Papp7cf60372018-01-11 00:06:43 +0000328 * Annotation key for receive frequency in Hz.
329 * Value is expected be an integer.
330 */
331 public static final String AK_RX_FREQ_HZ = "rxFrequency";
332
333 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000334 * Annotation key for receive lambda in nm.
335 * Value is expected be an integer.
336 */
337 public static final String AK_RX_LMDA_NM = "rxLambda";
338
339 /**
340 * Annotation key for receive offset frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000341 * Value is expected be an integer.
342 */
343 public static final String AK_RX_OFFSET_HZ = "rxOffset";
344
345 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000346 * Annotation key for receive offset lambda in nm.
347 * Value is expected be an integer.
348 */
349 public static final String AK_RX_OFFSET_LMDA_NM = "rxOffsetLambda";
350
351 /**
352 * Annotation key for receive grid spacing frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000353 * Value is expected be an integer.
354 */
355 public static final String AK_RX_GRID_SPAN_HZ = "rxGridSpan";
356
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000357 /**
358 * Annotation key for receive grid spacing lambda in nm.
359 * Value is expected be an integer.
360 */
361 public static final String AK_RX_GRID_SPAN_LMDA_NM = "rxGridSpanLambda";
362
Laszlo Papp7cf60372018-01-11 00:06:43 +0000363 /**
364 * Annotation key for transmit power in dBm*10.
365 * Value is expected to be an integer.
366 */
367 public static final String AK_TX_PWR = "txPower";
368
369 /**
370 * Annotation key for receive power feature.
371 * Value is expected to be "enabled" or "disabled"
372 */
373 public static final String AK_RX_PWR_FEATURE = "rxPwrFeature";
374
375 /**
376 * Annotation key for receive power in dBm*10.
377 * Value is expected to be an integer.
378 */
379 public static final String AK_RX_PWR = "rxPower";
380
381 /**
382 * Annotation key for transmit bias feature.
383 * Value is expected to be "enabled" or "disabled"
384 */
385 public static final String AK_TX_BIAS_FEATURE = "txBiasFeature";
386
387 /**
388 * Annotation key for transmit bias current in mA*10.
389 * Value is expected to be an integer.
390 */
391 public static final String AK_BIAS_CURRENT = "biasCurrent";
392
393 /**
394 * Annotation key for transmit temperature feature.
395 * Value is expected to be "enabled" or "disabled"
396 */
397 public static final String AK_TX_TEMP_FEATURE = "txTempFeature";
398
399 /**
400 * Annotation key for transmit laser temperature in C*10.
401 * Value is expected to be an integer.
402 */
403 public static final String AK_TEMPERATURE = "temperature";
404
405
406 // Common feature annotations
407
408 /**
409 * Annotation key for transmit tune feature.
410 * Value is expected to be "enabled" or "disabled"
411 */
412 public static final String AK_TX_TUNE_FEATURE = "txTuneFeature";
413
414 /**
415 * Annotation key for receive tune feature.
416 * Value is expected to be "enabled" or "disabled"
417 */
418 public static final String AK_RX_TUNE_FEATURE = "rxTuneFeature";
419
420 /**
421 * Annotation key for transmit power feature.
422 * Value is expected to be "enabled" or "disabled"
423 */
424 public static final String AK_TX_PWR_FEATURE = "txPwrFeature";
425
426
Charles Chan25b77322015-12-13 01:00:56 -0800427 //TODO consider renaming KBPS and MBPS (as they are used to convert by division)
428 private static final long KBPS = 1_000;
Ray Milkey3717e602018-02-01 13:49:47 -0800429 private static final long MBPS = 1_000L * 1_000L;
Rimon Ashkenazye3201032016-01-11 14:27:30 +0200430 private static final Frequency FREQ50 = Frequency.ofGHz(50);
431 private static final Frequency FREQ191_7 = Frequency.ofGHz(191_700);
Sho SHIMIZU00762ee2016-01-05 16:32:24 -0800432 private static final Frequency FREQ4_4 = Frequency.ofGHz(4_400);
tomb5a46e62014-08-26 14:20:00 -0700433
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000434 private static final long C = 299792458; // speed of light in m/s
Thomas Vachuska164ecf62018-05-08 17:29:55 -0700435 public static final String SCHEME = "of";
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000436
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700437 @Reference(cardinality = ReferenceCardinality.MANDATORY)
tom96dfcab2014-08-28 09:26:03 -0700438 protected DeviceProviderRegistry providerRegistry;
tomab21e7c2014-08-26 15:23:08 -0700439
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700440 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuska164ecf62018-05-08 17:29:55 -0700441 protected DeviceService deviceService;
442
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700443 @Reference(cardinality = ReferenceCardinality.MANDATORY)
tom5f38b3a2014-08-27 23:50:54 -0700444 protected OpenFlowController controller;
445
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700446 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200447 protected ComponentConfigService cfgService;
448
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700449 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Victor Silvaac8dab02016-11-28 16:33:08 -0300450 protected DriverService driverService;
451
tomab21e7c2014-08-26 15:23:08 -0700452 private DeviceProviderService providerService;
tomb5a46e62014-08-26 14:20:00 -0700453
sangho538108b2015-04-08 14:29:20 -0700454 private final InternalDeviceProvider listener = new InternalDeviceProvider();
455
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700456 //@Property(name = POLL_PROP_NAME, intValue = POLL_INTERVAL,
457 //label = "Frequency (in seconds) for polling switch Port statistics")
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700458 private int portStatsPollFrequency = POLL_FREQ_DEFAULT;
sangho538108b2015-04-08 14:29:20 -0700459
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700460 //@Property(name = PROP_FREQ, boolValue = DEFAULT_PROP_FREQ,
461 //label = "It indicates frequency must be used instead of wavelength for port tuning.")
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700462 private static boolean propFreq = PROP_FREQ_DEFAULT;
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000463
Victor Silvaff5871b2016-10-04 18:08:47 -0300464 private final Timer timer = new Timer("onos-openflow-portstats-collector");
sangyun-han07a572f2016-07-29 21:14:27 +0900465
Thomas Vachuska5b38dc02018-05-10 15:24:40 -0700466 private Map<Dpid, PortStatsCollector> collectors = Maps.newConcurrentMap();
tomd40fc7a2014-09-04 16:41:10 -0700467
tomab21e7c2014-08-26 15:23:08 -0700468 /**
469 * Creates an OpenFlow device provider.
470 */
471 public OpenFlowDeviceProvider() {
Thomas Vachuska164ecf62018-05-08 17:29:55 -0700472 super(new ProviderId(SCHEME, "org.onosproject.provider.openflow"));
tomab21e7c2014-08-26 15:23:08 -0700473 }
474
tomb5a46e62014-08-26 14:20:00 -0700475 @Activate
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200476 public void activate(ComponentContext context) {
477 cfgService.registerProperties(getClass());
tom96dfcab2014-08-28 09:26:03 -0700478 providerService = providerRegistry.register(this);
tomd40fc7a2014-09-04 16:41:10 -0700479 controller.addListener(listener);
sangho538108b2015-04-08 14:29:20 -0700480 controller.addEventListener(listener);
Jian Li152b8852015-12-07 14:47:25 -0800481
Victor Silva7944d142016-07-08 00:14:55 -0300482 modified(context);
483
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700484 connectInitialDevices();
alshabiba89cc582014-09-09 16:43:00 -0700485 LOG.info("Started");
tomb5a46e62014-08-26 14:20:00 -0700486 }
487
488 @Deactivate
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200489 public void deactivate(ComponentContext context) {
490 cfgService.unregisterProperties(getClass(), false);
Ray Milkey7abe50b2016-04-13 11:57:44 -0700491 listener.disable();
tomd40fc7a2014-09-04 16:41:10 -0700492 controller.removeListener(listener);
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700493 providerRegistry.unregister(this);
Thomas Vachuska74bcd922015-06-02 13:08:57 -0700494 collectors.values().forEach(PortStatsCollector::stop);
Thomas Vachuskaa394b952016-06-14 15:02:09 -0700495 collectors.clear();
tomab21e7c2014-08-26 15:23:08 -0700496 providerService = null;
alshabiba89cc582014-09-09 16:43:00 -0700497 LOG.info("Stopped");
tomb5a46e62014-08-26 14:20:00 -0700498 }
499
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200500 @Modified
501 public void modified(ComponentContext context) {
Victor Silva7944d142016-07-08 00:14:55 -0300502 Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200503 int newPortStatsPollFrequency;
504 try {
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700505 String s = get(properties, POLL_FREQ);
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200506 newPortStatsPollFrequency = isNullOrEmpty(s) ? portStatsPollFrequency : Integer.parseInt(s.trim());
507
508 } catch (NumberFormatException | ClassCastException e) {
509 newPortStatsPollFrequency = portStatsPollFrequency;
510 }
511
512 if (newPortStatsPollFrequency != portStatsPollFrequency) {
513 portStatsPollFrequency = newPortStatsPollFrequency;
514 collectors.values().forEach(psc -> psc.adjustPollInterval(portStatsPollFrequency));
515 }
516
517 LOG.info("Settings: portStatsPollFrequency={}", portStatsPollFrequency);
518 }
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700519
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700520 private void connectInitialDevices() {
521 for (OpenFlowSwitch sw : controller.getSwitches()) {
522 try {
523 listener.switchAdded(new Dpid(sw.getId()));
524 } catch (Exception e) {
525 LOG.warn("Failed initially adding {} : {}", sw.getStringId(), e.getMessage());
526 LOG.debug("Error details:", e);
527 // disconnect to trigger switch-add later
528 sw.disconnectSwitch();
529 }
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700530 }
531 }
532
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700533 @Override
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700534 public boolean isReachable(DeviceId deviceId) {
535 OpenFlowSwitch sw = controller.getSwitch(dpid(deviceId.uri()));
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700536 return sw != null && sw.isConnected();
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700537 }
538
tomab21e7c2014-08-26 15:23:08 -0700539 @Override
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800540 public void triggerProbe(DeviceId deviceId) {
Madan Jampanic3328762015-05-31 12:39:27 -0700541 LOG.debug("Triggering probe on device {}", deviceId);
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700542
Yuta HIGUCHI802d0e82014-10-31 16:07:37 -0700543 final Dpid dpid = dpid(deviceId.uri());
544 OpenFlowSwitch sw = controller.getSwitch(dpid);
545 if (sw == null || !sw.isConnected()) {
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800546 LOG.error("Failed to probe device {} on sw={}", deviceId, sw);
Yuta HIGUCHI802d0e82014-10-31 16:07:37 -0700547 providerService.deviceDisconnected(deviceId);
Thomas Vachuska74bcd922015-06-02 13:08:57 -0700548 return;
Yuta HIGUCHI802d0e82014-10-31 16:07:37 -0700549 } else {
Ayaka Koshibe78bcbc12014-11-19 14:28:58 -0800550 LOG.trace("Confirmed device {} connection", deviceId);
Yuta HIGUCHI802d0e82014-10-31 16:07:37 -0700551 }
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700552
Ayaka Koshibee60d4522014-10-28 15:07:00 -0700553 // Prompt an update of port information. We can use any XID for this.
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700554 OFFactory fact = sw.factory();
555 switch (fact.getVersion()) {
556 case OF_10:
557 sw.sendMsg(fact.buildFeaturesRequest().setXid(0).build());
558 break;
559 case OF_13:
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -0700560 case OF_14:
561 case OF_15:
Ayaka Koshibee8708e32014-10-22 13:40:18 -0700562 sw.sendMsg(fact.buildPortDescStatsRequest().setXid(0).build());
563 break;
564 default:
565 LOG.warn("Unhandled protocol version");
566 }
tomab21e7c2014-08-26 15:23:08 -0700567 }
568
569 @Override
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700570 public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
alshabibf1216ed2014-09-03 11:53:54 -0700571 switch (newRole) {
tom782a7cf2014-09-11 23:58:38 -0700572 case MASTER:
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700573 controller.setRole(dpid(deviceId.uri()), RoleState.MASTER);
tom782a7cf2014-09-11 23:58:38 -0700574 break;
575 case STANDBY:
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700576 controller.setRole(dpid(deviceId.uri()), RoleState.EQUAL);
tom782a7cf2014-09-11 23:58:38 -0700577 break;
578 case NONE:
Yuta HIGUCHI54815322014-10-31 23:17:08 -0700579 controller.setRole(dpid(deviceId.uri()), RoleState.SLAVE);
tom782a7cf2014-09-11 23:58:38 -0700580 break;
581 default:
582 LOG.error("Unknown Mastership state : {}", newRole);
alshabibf1216ed2014-09-03 11:53:54 -0700583
584 }
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800585 LOG.debug("Accepting mastership role change to {} for device {}", newRole, deviceId);
tomab21e7c2014-08-26 15:23:08 -0700586 }
587
Saurav Dasa2d37502016-03-25 17:50:40 -0700588 @Override
589 public void changePortState(DeviceId deviceId, PortNumber portNumber,
590 boolean enable) {
591 final Dpid dpid = dpid(deviceId.uri());
592 OpenFlowSwitch sw = controller.getSwitch(dpid);
593 if (sw == null || !sw.isConnected()) {
594 LOG.error("Failed to change portState on device {}", deviceId);
595 return;
596 }
597 OFPortMod.Builder pmb = sw.factory().buildPortMod();
598 OFPort port = OFPort.of((int) portNumber.toLong());
599 pmb.setPortNo(port);
Jimmy Jine9b7a022016-08-12 16:56:48 -0700600 Set<OFPortConfig> portConfig = EnumSet.noneOf(OFPortConfig.class);
601 if (!enable) {
602 portConfig.add(OFPortConfig.PORT_DOWN);
Saurav Dasa2d37502016-03-25 17:50:40 -0700603 }
Jimmy Jine9b7a022016-08-12 16:56:48 -0700604 pmb.setConfig(portConfig);
605 Set<OFPortConfig> portMask = EnumSet.noneOf(OFPortConfig.class);
606 portMask.add(OFPortConfig.PORT_DOWN);
607 pmb.setMask(portMask);
Saurav Dasa2d37502016-03-25 17:50:40 -0700608 pmb.setAdvertise(0x0);
609 for (OFPortDesc pd : sw.getPorts()) {
610 if (pd.getPortNo().equals(port)) {
611 pmb.setHwAddr(pd.getHwAddr());
612 break;
613 }
614 }
615 sw.sendMsg(Collections.singletonList(pmb.build()));
616 }
617
Thomas Vachuska5b38dc02018-05-10 15:24:40 -0700618 @Override
619 public void triggerDisconnect(DeviceId deviceId) {
620 Dpid dpid = dpid(deviceId.uri());
621 OpenFlowSwitch sw = controller.getSwitch(dpid);
622 if (sw != null) {
623 LOG.debug("Forcing disconnect for device {}", deviceId);
624 // TODO: Further consolidate clean-up on device disconnect
625 listener.switchRemoved(dpid);
626 sw.disconnectSwitch();
627 }
628 }
629
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700630 private void pushPortMetrics(Dpid dpid, List<OFPortStatsEntry> portStatsEntries) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800631 DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
Ray Milkey3c4124a2016-08-31 12:09:06 -0700632 Collection<PortStatistics> stats =
633 buildPortStatistics(deviceId, ImmutableList.copyOf(portStatsEntries));
sangho538108b2015-04-08 14:29:20 -0700634 providerService.updatePortStatistics(deviceId, stats);
635 }
636
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000637 private static String lambdaToAnnotationHz(long lambda) {
638 // ref. OF1.5: wavelength (lambda) as nm * 100
639
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000640 // f = c / λ
641 // (m/s) * (nm/m) / (nm * 100) * 100
642 // annotations is in Hz
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000643 return Long.toString(lambda == 0 ? lambda : (C * 1_000_000_000 / lambda * 100));
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000644 }
Laszlo Papp7cf60372018-01-11 00:06:43 +0000645
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000646 private static String mhzToAnnotationNm(long freqMhz) {
647 // λ = c / f
648 // (m/s) * (nm/m) / (1000000 * 1/s)
649 // annotations is in nm
650 return Long.toString(freqMhz == 0 ? freqMhz : (C * 1_000_000_000 / Frequency.ofMHz(freqMhz).asHz()));
651 }
652
653
Laszlo Papp7cf60372018-01-11 00:06:43 +0000654 private static String mhzToAnnotation(long freqMhz) {
655 return Long.toString(Frequency.ofMHz(freqMhz).asHz());
656 }
657
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000658 private static String freqLmdaToAnnotation(long freqLmda, boolean useFreq) {
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000659 if (useFreq) {
660 if (propFreq) {
661 mhzToAnnotation(freqLmda);
662 } else {
663 mhzToAnnotationNm(freqLmda);
664 }
665 } else if (propFreq) {
666 lambdaToAnnotationHz(freqLmda);
667 }
668 return Double.toString(freqLmda / 100.0);
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000669 }
670
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700671 private Collection<PortStatistics> buildPortStatistics(DeviceId deviceId,
672 List<OFPortStatsEntry> entries) {
sangho538108b2015-04-08 14:29:20 -0700673 HashSet<PortStatistics> stats = Sets.newHashSet();
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000674 final Dpid dpid = dpid(deviceId.uri());
675 OpenFlowSwitch sw = controller.getSwitch(dpid);
sangho538108b2015-04-08 14:29:20 -0700676
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700677 for (OFPortStatsEntry entry : entries) {
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700678 try {
Thomas Vachuska4e6025e2015-06-03 11:25:21 -0700679 if (entry == null || entry.getPortNo() == null || entry.getPortNo().getPortNumber() < 0) {
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700680 continue;
681 }
Laszlo Papp7cf60372018-01-11 00:06:43 +0000682 DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
Laszlo Papp9dfb5122018-01-12 21:10:13 +0000683 boolean propSupported = entry.getVersion().getWireVersion() >= OFVersion.OF_14.getWireVersion();
684 Optional<OFPortStatsPropOptical> optical = propSupported ?
685 entry.getProperties().stream()
Laszlo Papp7cf60372018-01-11 00:06:43 +0000686 .filter(OFPortStatsPropOptical.class::isInstance)
687 .map(OFPortStatsPropOptical.class::cast)
Laszlo Papp9dfb5122018-01-12 21:10:13 +0000688 .findAny() : Optional.empty();
Laszlo Papp7cf60372018-01-11 00:06:43 +0000689 if (optical.isPresent()) {
690 long flags = optical.get().getFlags();
691
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000692 boolean useFreq = false;
693 for (OFPortDesc pd : sw.getPorts()) {
694 if (pd.getPortNo().equals(entry.getPortNo())) {
695 for (OFPortDescProp prop : pd.getProperties()) {
696 if (prop instanceof OFPortDescPropOptical) {
697 OFPortDescPropOptical oprop = (OFPortDescPropOptical) prop;
698 long supported = oprop.getSupported();
699 int useFreqVal = OFOpticalPortFeaturesSerializerVer14.USE_FREQ_VAL;
700 if ((supported & useFreqVal) != 0) {
701 useFreq = true;
702 break;
703 }
704 }
705 }
706 }
707 }
708
Laszlo Papp7cf60372018-01-11 00:06:43 +0000709 int txTune = OFPortStatsOpticalFlagsSerializerVer14.TX_TUNE_VAL;
710 long txFreq = optical.get().getTxFreqLmda();
711 long txOffset = optical.get().getTxOffset();
712 long txGridSpan = optical.get().getTxGridSpan();
713 annotations.set(AK_TX_TUNE_FEATURE, ((flags & txTune) != 0) ? "enabled" : "disabled");
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000714 annotations.set(propFreq ? AK_TX_FREQ_HZ : AK_TX_LMDA_NM,
715 freqLmdaToAnnotation(txFreq, useFreq));
716 annotations.set(propFreq ? AK_TX_OFFSET_HZ : AK_TX_OFFSET_LMDA_NM,
717 freqLmdaToAnnotation(txOffset, useFreq));
718 annotations.set(propFreq ? AK_TX_GRID_SPAN_HZ : AK_TX_GRID_SPAN_LMDA_NM,
719 freqLmdaToAnnotation(txGridSpan, useFreq));
Laszlo Papp7cf60372018-01-11 00:06:43 +0000720
721 int rxTune = OFPortStatsOpticalFlagsSerializerVer14.RX_TUNE_VAL;
722 long rxFreq = optical.get().getRxFreqLmda();
723 long rxOffset = optical.get().getRxOffset();
724 long rxGridSpan = optical.get().getRxGridSpan();
725 annotations.set(AK_RX_TUNE_FEATURE, ((flags & rxTune) != 0) ? "enabled" : "disabled");
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000726 annotations.set(propFreq ? AK_RX_FREQ_HZ : AK_RX_LMDA_NM,
727 freqLmdaToAnnotation(rxFreq, useFreq));
728 annotations.set(propFreq ? AK_RX_OFFSET_HZ : AK_RX_OFFSET_LMDA_NM,
729 freqLmdaToAnnotation(rxOffset, useFreq));
730 annotations.set(propFreq ? AK_RX_GRID_SPAN_HZ : AK_RX_GRID_SPAN_LMDA_NM,
731 freqLmdaToAnnotation(rxGridSpan, useFreq));
Laszlo Papp7cf60372018-01-11 00:06:43 +0000732
733 int txPwrVal = OFPortStatsOpticalFlagsSerializerVer14.TX_PWR_VAL;
734 int txPwr = optical.get().getTxPwr();
735 annotations.set(AK_TX_PWR_FEATURE, ((flags & txPwrVal) != 0) ? "enabled" : "disabled");
736 annotations.set(AK_TX_PWR, Integer.toString(txPwr));
737
738 int rxPwrVal = OFPortStatsOpticalFlagsSerializerVer14.RX_PWR_VAL;
739 int rxPwr = optical.get().getRxPwr();
740 annotations.set(AK_RX_PWR_FEATURE, ((flags & rxPwrVal) != 0) ? "enabled" : "disabled");
741 annotations.set(AK_RX_PWR, Integer.toString(rxPwr));
742
743 int txBias = OFPortStatsOpticalFlagsSerializerVer14.TX_BIAS_VAL;
744 int biasCurrent = optical.get().getBiasCurrent();
745 annotations.set(AK_TX_BIAS_FEATURE, ((flags & txBias) != 0) ? "enabled" : "disabled");
746 annotations.set(AK_BIAS_CURRENT, Integer.toString(biasCurrent));
747
748 int txTemp = OFPortStatsOpticalFlagsSerializerVer14.TX_TEMP_VAL;
749 int temperature = optical.get().getTemperature();
750 annotations.set(AK_TX_TEMP_FEATURE, ((flags & txTemp) != 0) ? "enabled" : "disabled");
751 annotations.set(AK_TEMPERATURE, Integer.toString(temperature));
752 }
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700753 DefaultPortStatistics.Builder builder = DefaultPortStatistics.builder();
754 DefaultPortStatistics stat = builder.setDeviceId(deviceId)
755 .setPort(entry.getPortNo().getPortNumber())
756 .setPacketsReceived(entry.getRxPackets().getValue())
757 .setPacketsSent(entry.getTxPackets().getValue())
758 .setBytesReceived(entry.getRxBytes().getValue())
759 .setBytesSent(entry.getTxBytes().getValue())
760 .setPacketsRxDropped(entry.getRxDropped().getValue())
761 .setPacketsTxDropped(entry.getTxDropped().getValue())
762 .setPacketsRxErrors(entry.getRxErrors().getValue())
763 .setPacketsTxErrors(entry.getTxErrors().getValue())
764 .setDurationSec(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationSec())
765 .setDurationNano(entry.getVersion() == OFVersion.OF_10 ? 0 : entry.getDurationNsec())
Laszlo Papp7cf60372018-01-11 00:06:43 +0000766 .setAnnotations(annotations.build())
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700767 .build();
sangho538108b2015-04-08 14:29:20 -0700768
Thomas Vachuskaf0397b52015-05-29 13:50:17 -0700769 stats.add(stat);
770 } catch (Exception e) {
771 LOG.warn("Unable to process port stats", e);
772 }
sangho538108b2015-04-08 14:29:20 -0700773 }
774
775 return Collections.unmodifiableSet(stats);
sangho538108b2015-04-08 14:29:20 -0700776 }
777
778 private class InternalDeviceProvider implements OpenFlowSwitchListener, OpenFlowEventListener {
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700779
Srikanth Vavilapalli78baf582015-06-05 11:40:14 -0700780 private HashMap<Dpid, List<OFPortStatsEntry>> portStatsReplies = new HashMap<>();
Ray Milkey7abe50b2016-04-13 11:57:44 -0700781 private boolean isDisabled = false;
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700782
alshabibf1216ed2014-09-03 11:53:54 -0700783 @Override
tomd1900f32014-09-03 14:08:16 -0700784 public void switchAdded(Dpid dpid) {
alshabib6f5460b2014-09-03 14:46:17 -0700785 if (providerService == null) {
786 return;
787 }
tom782a7cf2014-09-11 23:58:38 -0700788 DeviceId did = deviceId(uri(dpid));
alshabib6f5460b2014-09-03 14:46:17 -0700789 OpenFlowSwitch sw = controller.getSwitch(dpid);
Lei Xudee1aff2015-10-16 00:45:10 -0500790 if (sw == null) {
sangyun-han147e6f42016-07-26 17:14:41 +0900791 LOG.error("Switch {} is not found", dpid);
Lei Xudee1aff2015-10-16 00:45:10 -0500792 return;
793 }
alshabib6f5460b2014-09-03 14:46:17 -0700794
alshabib7911a052014-10-16 17:49:37 -0700795 ChassisId cId = new ChassisId(dpid.value());
Ray Milkeye53f1712015-01-16 09:17:16 -0800796
Victor Silvaac8dab02016-11-28 16:33:08 -0300797 DefaultAnnotations.Builder annotationsBuilder = DefaultAnnotations.builder()
andreafe3308f2015-10-06 15:51:25 -0700798 .set(AnnotationKeys.PROTOCOL, sw.factory().getVersion().toString())
799 .set(AnnotationKeys.CHANNEL_ID, sw.channelId())
Victor Silvaac8dab02016-11-28 16:33:08 -0300800 .set(AnnotationKeys.MANAGEMENT_ADDRESS, sw.channelId().split(":")[0]);
801
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800802 // FIXME following ignores driver specified by name
Victor Silvaac8dab02016-11-28 16:33:08 -0300803 Driver driver = driverService.getDriver(sw.manufacturerDescription(),
804 sw.hardwareDescription(),
805 sw.softwareDescription());
Thomas Vachuskaa79cbf72017-01-13 15:07:04 -0800806 // FIXME: The following breaks the STC tests and will require to be revisited.
807// if (driver != null) {
808// annotationsBuilder.set(AnnotationKeys.DRIVER, driver.name());
809// }
Victor Silvaac8dab02016-11-28 16:33:08 -0300810
811 SparseAnnotations annotations = annotationsBuilder.build();
Ray Milkeye53f1712015-01-16 09:17:16 -0800812
tomd1900f32014-09-03 14:08:16 -0700813 DeviceDescription description =
Marc De Leenheerb9311372015-07-09 11:36:49 -0700814 new DefaultDeviceDescription(did.uri(), sw.deviceType(),
Ray Milkeyd3edd032015-01-16 11:38:58 -0800815 sw.manufacturerDescription(),
tom782a7cf2014-09-11 23:58:38 -0700816 sw.hardwareDescription(),
817 sw.softwareDescription(),
alshabib7911a052014-10-16 17:49:37 -0700818 sw.serialNumber(),
Thomas Vachuska82041f52014-11-30 22:14:02 -0800819 cId, annotations);
tom782a7cf2014-09-11 23:58:38 -0700820 providerService.deviceConnected(did, description);
Ayaka Koshibe5460d622015-05-14 12:19:19 -0700821 providerService.updatePorts(did, buildPortDescriptions(sw));
Palash Kala496ef1a22018-03-21 14:57:50 +0900822 //sends port description stats request again if OF version supports
823 if (sw.features().getVersion().compareTo(OFVersion.OF_13) >= 0) {
824 sendPortDescStatsRequest(sw);
825 }
sangho538108b2015-04-08 14:29:20 -0700826
Laszlo Papp58174812018-01-16 13:29:47 +0000827 if (sw.features().getCapabilities().contains(OFCapabilities.PORT_STATS)) {
828 PortStatsCollector psc = new PortStatsCollector(timer, sw, portStatsPollFrequency);
829 stopCollectorIfNeeded(collectors.put(dpid, psc));
830 psc.start();
831 }
Lei Xudee1aff2015-10-16 00:45:10 -0500832
833 //figure out race condition for collectors.remove() and collectors.put()
834 if (controller.getSwitch(dpid) == null) {
835 switchRemoved(dpid);
836 }
alshabib25c8eec2014-09-04 16:41:31 -0700837 }
838
Palash Kala496ef1a22018-03-21 14:57:50 +0900839 /**
840 * Sends port description statistic request to switch if supported.
841 */
842 private void sendPortDescStatsRequest(OpenFlowSwitch sw) {
843 if (sw == null) {
844 return;
845 }
846 OFPortDescStatsRequest descStatsRequest = sw.factory().buildPortDescStatsRequest()
847 .build();
848 sw.sendMsg(descStatsRequest);
849 }
850
Thomas Vachuskaa394b952016-06-14 15:02:09 -0700851 private void stopCollectorIfNeeded(PortStatsCollector collector) {
852 if (collector != null) {
853 collector.stop();
854 }
855 }
856
alshabibf1216ed2014-09-03 11:53:54 -0700857 @Override
858 public void switchRemoved(Dpid dpid) {
Victor Silva03265dd2016-12-08 11:20:36 -0300859 stopCollectorIfNeeded(collectors.remove(dpid));
alshabib6f5460b2014-09-03 14:46:17 -0700860 if (providerService == null) {
861 return;
862 }
tom782a7cf2014-09-11 23:58:38 -0700863 providerService.deviceDisconnected(deviceId(uri(dpid)));
sangho538108b2015-04-08 14:29:20 -0700864 }
Ayaka Koshibe38594c22014-10-22 13:36:12 -0700865
866 @Override
867 public void switchChanged(Dpid dpid) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800868 LOG.debug("switchChanged({})", dpid);
Ayaka Koshibe38594c22014-10-22 13:36:12 -0700869 if (providerService == null) {
870 return;
871 }
872 DeviceId did = deviceId(uri(dpid));
873 OpenFlowSwitch sw = controller.getSwitch(dpid);
Lei Xudee1aff2015-10-16 00:45:10 -0500874 if (sw == null) {
sangyun-han147e6f42016-07-26 17:14:41 +0900875 LOG.error("Switch {} is not found", dpid);
Lei Xudee1aff2015-10-16 00:45:10 -0500876 return;
877 }
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800878 final List<PortDescription> ports = buildPortDescriptions(sw);
879 LOG.debug("switchChanged({}) {}", did, ports);
880 providerService.updatePorts(did, ports);
Ayaka Koshibe38594c22014-10-22 13:36:12 -0700881 }
882
alshabiba14f3642014-09-05 09:31:31 -0700883 @Override
884 public void portChanged(Dpid dpid, OFPortStatus status) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800885 LOG.debug("portChanged({},{})", dpid, status);
alshabibafc514a2014-12-01 14:44:05 -0800886 PortDescription portDescription = buildPortDescription(status);
Michal Machce774332017-01-25 11:02:55 +0100887 if (status.getReason() != OFPortReason.DELETE) {
888 providerService.portStatusChanged(deviceId(uri(dpid)), portDescription);
889 } else {
890 providerService.deletePort(deviceId(uri(dpid)), portDescription);
891 }
alshabibf1216ed2014-09-03 11:53:54 -0700892 }
893
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700894 @Override
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700895 public void receivedRoleReply(Dpid dpid, RoleState requested, RoleState response) {
HIGUCHI Yuta1979f552015-12-28 21:24:26 -0800896 LOG.debug("receivedRoleReply({},{},{})", dpid, requested, response);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700897 MastershipRole request = roleOf(requested);
898 MastershipRole reply = roleOf(response);
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700899 providerService.receivedRoleReply(deviceId(uri(dpid)), request, reply);
900 }
901
902 /**
903 * Translates a RoleState to the corresponding MastershipRole.
904 *
Thomas Vachuskafc52fec2015-05-18 19:13:56 -0700905 * @param response role state
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700906 * @return a MastershipRole
907 */
908 private MastershipRole roleOf(RoleState response) {
909 switch (response) {
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700910 case MASTER:
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700911 return MastershipRole.MASTER;
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700912 case EQUAL:
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700913 return MastershipRole.STANDBY;
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700914 case SLAVE:
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700915 return MastershipRole.NONE;
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700916 default:
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700917 LOG.warn("unknown role {}", response);
918 return null;
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700919 }
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700920 }
921
alshabiba14f3642014-09-05 09:31:31 -0700922 /**
923 * Builds a list of port descriptions for a given list of ports.
tomff7eb7c2014-09-08 12:49:03 -0700924 *
alshabiba14f3642014-09-05 09:31:31 -0700925 * @return list of portdescriptions
926 */
Ayaka Koshibe5460d622015-05-14 12:19:19 -0700927 private List<PortDescription> buildPortDescriptions(OpenFlowSwitch sw) {
Yuta HIGUCHIf83c8cf2017-12-17 14:33:49 -0800928 List<OFPortDesc> ofPorts = sw.getPorts();
929 final List<PortDescription> portDescs = new ArrayList<>(ofPorts.size());
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +0200930 if (!((Device.Type.ROADM.equals(sw.deviceType())) ||
MaoLuc201ae42017-02-06 17:57:01 -0800931 (Device.Type.OTN.equals(sw.deviceType())) ||
932 (Device.Type.OPTICAL_AMPLIFIER.equals(sw.deviceType())))) {
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800933 // build regular (=non-optical) Device ports
Yuta HIGUCHIf83c8cf2017-12-17 14:33:49 -0800934 ofPorts.forEach(port -> portDescs.add(buildPortDescription(port)));
Yafit Hadara9a73de2015-09-06 13:52:52 +0300935 }
Marc De Leenheerb9311372015-07-09 11:36:49 -0700936
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800937 // TODO handle Optical Device, but plain OF devices(1.4 and later)
938
Marc De Leenheerb9311372015-07-09 11:36:49 -0700939 OpenFlowOpticalSwitch opsw;
940 switch (sw.deviceType()) {
941 case ROADM:
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +0200942 case OTN:
MaoLuc201ae42017-02-06 17:57:01 -0800943 case OPTICAL_AMPLIFIER:
Marc De Leenheerb9311372015-07-09 11:36:49 -0700944 opsw = (OpenFlowOpticalSwitch) sw;
Yafit Hadara9a73de2015-09-06 13:52:52 +0300945 List<OFPortDesc> ports = opsw.getPorts();
946 LOG.debug("SW ID {} , ETH- ODU CLT Ports {}", opsw.getId(), ports);
947 // ODU client ports are reported as ETH
948 ports.forEach(port -> portDescs.add(buildOduCltPortDescription(port)));
949
Marc De Leenheerb9311372015-07-09 11:36:49 -0700950 opsw.getPortTypes().forEach(type -> {
Yafit Hadara9a73de2015-09-06 13:52:52 +0300951 List<? extends OFObject> portsOf = opsw.getPortsOf(type);
952 LOG.debug("Ports Of{}", portsOf);
953 portsOf.forEach(
954 op -> {
Jimmy Yan4deb03b2016-06-24 10:53:54 -0700955 portDescs.add(buildPortDescription(type, op, opsw));
Yafit Hadara9a73de2015-09-06 13:52:52 +0300956 }
957 );
Marc De Leenheerb9311372015-07-09 11:36:49 -0700958 });
959 break;
960 case FIBER_SWITCH:
961 opsw = (OpenFlowOpticalSwitch) sw;
962 opsw.getPortTypes().forEach(type -> {
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -0700963 opsw.getPortsOf(type).forEach(op -> {
964 if (op instanceof OFPortDesc) {
965 // ports using standard optical extension
966 // TODO OFMessage -> PortDescription should
967 // probably be a Behaviour
968 portDescs.add(oms(buildPortDescription((OFPortDesc) op)));
969 } else if (op instanceof OFCalientPortDescStatsEntry) {
970 // calient extension
971 portDescs.add(buildPortDescription((OFCalientPortDescStatsEntry) op));
972 } else {
973 LOG.warn("Unexpected FIBER_SWITCH port {} on {}",
974 op, sw.getStringId());
975 }
976 });
Marc De Leenheerb9311372015-07-09 11:36:49 -0700977 });
978 break;
979 default:
980 break;
alshabib4680bb62014-09-04 17:15:08 -0700981 }
Marc De Leenheerb9311372015-07-09 11:36:49 -0700982
alshabib4680bb62014-09-04 17:15:08 -0700983 return portDescs;
984 }
985
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -0700986 /**
987 * Ensures returned PortDescription is an OMS port.
988 *
989 * @param descr input PortDescription
990 * @return OMS PortDescription
991 */
992 private PortDescription oms(PortDescription descr) {
993 // Hack until OFMessage -> PortDescription transformation
994 // becomes a Behaviour
995 if (descr.type() == Type.OMS) {
996 return descr;
997 }
998
999 Builder builder = DefaultAnnotations.builder();
1000 builder.putAll(descr.annotations());
1001
1002 // set reasonable default when mandatory key is missing
1003 if (Strings.isNullOrEmpty(descr.annotations().value(AK_MIN_FREQ_HZ))) {
1004 builder.set(AK_MIN_FREQ_HZ, String.valueOf(Spectrum.O_BAND_MIN.asHz()));
1005 }
1006
1007 if (Strings.isNullOrEmpty(descr.annotations().value(AK_MAX_FREQ_HZ))) {
1008 builder.set(AK_MAX_FREQ_HZ, String.valueOf(Spectrum.O_BAND_MAX.asHz()));
1009 }
1010
1011 if (Strings.isNullOrEmpty(descr.annotations().value(AK_GRID_HZ))) {
1012 builder.set(AK_GRID_HZ, String.valueOf(Frequency.ofGHz(50).asHz()));
1013 }
1014
1015 return DefaultPortDescription.builder(descr)
1016 .type(Type.OMS)
1017 .annotations(builder.build())
1018 .build();
1019 }
1020
Yafit Hadara9a73de2015-09-06 13:52:52 +03001021 private PortDescription buildOduCltPortDescription(OFPortDesc port) {
1022 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
1023 boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) &&
1024 !port.getConfig().contains(OFPortConfig.PORT_DOWN);
Rimon Ashkenazyd15ebf52016-01-06 14:36:13 +02001025 Long portSpeedInMbps = portSpeed(port);
Toru Furusawa72ee30c2016-01-08 13:29:04 -08001026 CltSignalType sigType = null;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001027
Rimon Ashkenazyd15ebf52016-01-06 14:36:13 +02001028 switch (portSpeedInMbps.toString()) {
1029 case "1000":
Toru Furusawa72ee30c2016-01-08 13:29:04 -08001030 sigType = CltSignalType.CLT_1GBE;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001031 break;
Rimon Ashkenazyd15ebf52016-01-06 14:36:13 +02001032 case "10000":
Toru Furusawa72ee30c2016-01-08 13:29:04 -08001033 sigType = CltSignalType.CLT_10GBE;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001034 break;
Rimon Ashkenazyd15ebf52016-01-06 14:36:13 +02001035 case "40000":
Toru Furusawa72ee30c2016-01-08 13:29:04 -08001036 sigType = CltSignalType.CLT_40GBE;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001037 break;
Rimon Ashkenazyd15ebf52016-01-06 14:36:13 +02001038 case "100000":
Toru Furusawa72ee30c2016-01-08 13:29:04 -08001039 sigType = CltSignalType.CLT_100GBE;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001040 break;
1041 default:
Ray Milkey986a47a2018-01-25 11:38:51 -08001042 throw new IllegalArgumentException("Un recognize OduClt speed: " + portSpeedInMbps.toString());
Yafit Hadara9a73de2015-09-06 13:52:52 +03001043 }
1044
1045 SparseAnnotations annotations = buildOduCltAnnotation(port);
HIGUCHI Yuta4c0ef6b2016-05-02 19:45:41 -07001046 return oduCltPortDescription(portNo, enabled, sigType, annotations);
Yafit Hadara9a73de2015-09-06 13:52:52 +03001047 }
1048
1049 private SparseAnnotations buildOduCltAnnotation(OFPortDesc port) {
1050 SparseAnnotations annotations = null;
1051 String portName = Strings.emptyToNull(port.getName());
1052 if (portName != null) {
1053 annotations = DefaultAnnotations.builder()
1054 .set(AnnotationKeys.PORT_NAME, portName)
1055 .set(AnnotationKeys.STATIC_PORT, Boolean.TRUE.toString()).build();
1056 }
1057 return annotations;
1058 }
1059
Jimmy Yan4deb03b2016-06-24 10:53:54 -07001060 private PortDescription buildPortDescription(PortDescPropertyType ptype, OFObject port,
1061 OpenFlowOpticalSwitch opsw) {
yjimmyy646aa022016-07-05 12:09:50 -07001062 if (port instanceof OFPortOptical) {
Jimmy Yan4deb03b2016-06-24 10:53:54 -07001063 return buildPortDescription(ptype, (OFPortOptical) port, opsw);
Yafit Hadara9a73de2015-09-06 13:52:52 +03001064 }
1065 return buildPortDescription(ptype, (OFExpPort) port);
1066 }
1067
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +02001068 private boolean matchingOtuPortSignalTypes(OFPortOpticalTransportSignalType sigType,
1069 OduSignalType oduSignalType) {
1070 switch (sigType) {
1071 case OTU2:
1072 if (oduSignalType == OduSignalType.ODU2) {
1073 return true;
1074 }
1075 break;
1076 case OTU4:
1077 if (oduSignalType == OduSignalType.ODU4) {
1078 return true;
1079 }
1080 break;
1081 default:
1082 break;
1083 }
1084 return false;
1085 }
Yafit Hadara9a73de2015-09-06 13:52:52 +03001086 /**
1087 * Build a portDescription from a given a port description describing some
1088 * Optical port.
1089 *
1090 * @param ptype description property type.
1091 * @param port the port to build from.
1092 * @return portDescription for the port.
1093 */
1094 private PortDescription buildPortDescription(PortDescPropertyType ptype, OFExpPort port) {
1095 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
1096 boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN)
1097 && !port.getConfig().contains(OFPortConfig.PORT_DOWN);
mskalac584bd92017-11-28 15:51:17 +01001098 boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN);
1099 SparseAnnotations annotations = makePortAnnotation(port.getName(),
1100 port.getHwAddr().toString(),
1101 adminDown).build();
Yafit Hadara9a73de2015-09-06 13:52:52 +03001102
1103 OFExpPortDescPropOpticalTransport firstProp = port.getProperties().get(0);
1104 OFPortOpticalTransportSignalType sigType = firstProp.getPortSignalType();
1105
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -08001106 PortDescription portDes = null;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001107 switch (sigType) {
1108 case OMSN:
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -07001109 portDes = omsPortDescription(portNo, enabled,
Rimon Ashkenazye3201032016-01-11 14:27:30 +02001110 FREQ191_7, FREQ191_7.add(FREQ4_4), FREQ50, annotations);
Yafit Hadara9a73de2015-09-06 13:52:52 +03001111 break;
1112 case OCH:
1113 OFExpPortOpticalTransportLayerEntry entry = firstProp.getFeatures().get(0).getValue().get(0);
1114 OFPortOpticalTransportLayerClass layerClass = entry.getLayerClass();
1115 if (!OFPortOpticalTransportLayerClass.ODU.equals(layerClass)) {
1116 LOG.error("Unsupported layer Class {} ", layerClass);
1117 return null;
1118 }
1119
1120 // convert to ONOS OduSignalType
1121 OduSignalType oduSignalType = OpenFlowDeviceValueMapper.
1122 lookupOduSignalType((byte) entry.getSignalType());
1123 //OchSignal is needed for OchPortDescription constructor,
1124 //yet not relevant for tunable OCH port, creating with default parameters
1125 OchSignal signalId = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 1, 1);
1126
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -08001127 portDes = ochPortDescription(portNo, enabled,
1128 oduSignalType, true,
1129 signalId, annotations);
Yafit Hadara9a73de2015-09-06 13:52:52 +03001130
1131 break;
1132 case OTU2:
1133 case OTU4:
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +02001134 entry = firstProp.getFeatures().get(0).getValue().get(0);
1135 layerClass = entry.getLayerClass();
1136 if (!OFPortOpticalTransportLayerClass.ODU.equals(layerClass)) {
1137 LOG.error("Unsupported layer Class {} ", layerClass);
1138 return null;
1139 }
1140
1141 // convert to ONOS OduSignalType
1142 OduSignalType oduSignalTypeOtuPort = OpenFlowDeviceValueMapper.
1143 lookupOduSignalType((byte) entry.getSignalType());
1144 if (!matchingOtuPortSignalTypes(sigType, oduSignalTypeOtuPort)) {
1145 LOG.error("Wrong oduSignalType {} for OTU Port sigType {} ", oduSignalTypeOtuPort, sigType);
1146 return null;
1147 }
1148 OtuSignalType otuSignalType =
1149 ((sigType == OFPortOpticalTransportSignalType.OTU2) ? OtuSignalType.OTU2 :
1150 OtuSignalType.OTU4);
HIGUCHI Yuta5be3e822016-05-03 13:51:42 -07001151 portDes = otuPortDescription(portNo, enabled, otuSignalType, annotations);
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +02001152 break;
Yafit Hadara9a73de2015-09-06 13:52:52 +03001153 default:
1154 break;
1155 }
1156
1157 return portDes;
1158 }
1159
alshabiba14f3642014-09-05 09:31:31 -07001160 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001161 * Creates an annotation builder for the port name if one is available.
Ray Milkeye0fade72015-01-15 13:29:47 -08001162 *
lishuai4ee42042015-11-30 17:19:21 +08001163 * @param portName the port name
1164 * @param portMac the port mac
mskalac584bd92017-11-28 15:51:17 +01001165 * @param adminDown the port admin state
1166 * @return annotation builder containing port admin state, port name
1167 * and/or port MAC if any of the two is found
Ray Milkeye0fade72015-01-15 13:29:47 -08001168 */
mskalac584bd92017-11-28 15:51:17 +01001169 private DefaultAnnotations.Builder makePortAnnotation(String portName, String portMac, boolean adminDown) {
Andrea Campanellac8b871a2017-01-19 13:53:05 -08001170 DefaultAnnotations.Builder builder = DefaultAnnotations.builder();
lishuai4ee42042015-11-30 17:19:21 +08001171 String pName = Strings.emptyToNull(portName);
1172 String pMac = Strings.emptyToNull(portMac);
Andrea Campanellac8b871a2017-01-19 13:53:05 -08001173 if (pName != null) {
1174 builder.set(AnnotationKeys.PORT_NAME, pName);
Ray Milkeye0fade72015-01-15 13:29:47 -08001175 }
Andrea Campanellac8b871a2017-01-19 13:53:05 -08001176 if (pMac != null) {
1177 builder.set(AnnotationKeys.PORT_MAC, pMac);
1178 }
mskalac584bd92017-11-28 15:51:17 +01001179 String adminState = adminDown ? "disabled" : "enabled";
1180 builder.set(AnnotationKeys.ADMIN_STATE, adminState);
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001181 return builder;
1182 }
1183
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001184 private PortDescription buildPortDescription14(OFPortDesc port) {
1185 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
1186 boolean enabled =
1187 !port.getState().contains(OFPortState.LINK_DOWN) &&
1188 !port.getConfig().contains(OFPortConfig.PORT_DOWN);
mskalac584bd92017-11-28 15:51:17 +01001189 boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN);
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001190 Builder annotations = makePortAnnotation(port.getName(),
mskalac584bd92017-11-28 15:51:17 +01001191 port.getHwAddr().toString(),
1192 adminDown);
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001193
1194 Optional<OFPortDescPropEthernet> ether = port.getProperties().stream()
1195 .filter(OFPortDescPropEthernet.class::isInstance)
1196 .map(OFPortDescPropEthernet.class::cast)
1197 .findAny();
1198 if (ether.isPresent()) {
1199 // ethernet port
1200 // TODO parse other part of OFPortDescPropEthernet if necessary
Yuta HIGUCHI53e47962018-03-01 23:50:48 -08001201 return DefaultPortDescription.builder()
1202 .withPortNumber(portNo)
1203 .isEnabled(enabled)
1204 .type(COPPER)
1205 .portSpeed(portSpeed(port))
1206 .annotations(annotations.build())
1207 .build();
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001208 }
1209
1210 Optional<OFPortDescPropOptical> optical = port.getProperties().stream()
1211 .filter(OFPortDescPropOptical.class::isInstance)
1212 .map(OFPortDescPropOptical.class::cast)
1213 .findAny();
1214 if (optical.isPresent()) {
1215 // optical port
1216
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -07001217 // FIXME is there a OF version neutral way to access
1218 // OFOpticalPortFeaturesSerializerVer14
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001219
Laszlo Papp20cfb6f2018-01-08 16:06:53 +00001220 long supported = optical.get().getSupported();
1221 long rxMin = optical.get().getRxMinFreqLmda();
1222 long rxMax = optical.get().getRxMaxFreqLmda();
1223 long rxGrid = optical.get().getRxGridFreqLmda();
1224 long txMin = optical.get().getTxMinFreqLmda();
1225 long txMax = optical.get().getTxMaxFreqLmda();
1226 long txGrid = optical.get().getTxGridFreqLmda();
1227
1228 int txTune = OFOpticalPortFeaturesSerializerVer14.TX_TUNE_VAL;
1229 int rxTune = OFOpticalPortFeaturesSerializerVer14.RX_TUNE_VAL;
1230 annotations.set(AK_TX_TUNE_FEATURE,
1231 ((supported & txTune) != 0) ? "enabled" : "disabled");
1232 annotations.set(AK_RX_TUNE_FEATURE,
1233 ((supported & rxTune) != 0) ? "enabled" : "disabled");
1234
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001235 // wire value for OFOpticalPortFeatures.USE_FREQ
Laszlo Papp8e8ff052018-01-16 09:55:45 +00001236 boolean useFreq = (supported & OFOpticalPortFeaturesSerializerVer14.USE_FREQ_VAL) != 0;
1237 annotations.set(AK_USE_FREQ_FEATURE, useFreq ? "enabled" : "disabled");
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001238
Laszlo Pappbf2cd742018-01-16 11:49:04 +00001239 annotations.set(propFreq ? AK_RX_MIN_FREQ_HZ : AK_RX_MIN_LMDA_NM,
1240 freqLmdaToAnnotation(rxMin, useFreq));
1241 annotations.set(propFreq ? AK_RX_MAX_FREQ_HZ : AK_RX_MAX_LMDA_NM,
1242 freqLmdaToAnnotation(rxMax, useFreq));
1243 annotations.set(propFreq ? AK_RX_GRID_HZ : AK_RX_GRID_LMDA_NM,
1244 freqLmdaToAnnotation(rxGrid, useFreq));
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001245
Laszlo Pappbf2cd742018-01-16 11:49:04 +00001246 annotations.set(propFreq ? AK_TX_MIN_FREQ_HZ : AK_TX_MIN_LMDA_NM,
1247 freqLmdaToAnnotation(txMin, useFreq));
1248 annotations.set(propFreq ? AK_TX_MAX_FREQ_HZ : AK_TX_MAX_LMDA_NM,
1249 freqLmdaToAnnotation(txMax, useFreq));
1250 annotations.set(propFreq ? AK_TX_GRID_HZ : AK_TX_GRID_LMDA_NM,
1251 freqLmdaToAnnotation(txGrid, useFreq));
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001252
Laszlo Papp8e8ff052018-01-16 09:55:45 +00001253 // FIXME pretty confident this is not going to happen
1254 // unless Device models Tx/Rx ports as separate port
1255 if (rxMin == txMin) {
Laszlo Pappbf2cd742018-01-16 11:49:04 +00001256 annotations.set(propFreq ? AK_MIN_FREQ_HZ : AK_MIN_LMDA_NM,
Laszlo Papp8e8ff052018-01-16 09:55:45 +00001257 freqLmdaToAnnotation(rxMin, useFreq));
1258 }
1259 if (rxMax == txMax) {
Laszlo Pappbf2cd742018-01-16 11:49:04 +00001260 annotations.set(propFreq ? AK_MAX_FREQ_HZ : AK_MAX_LMDA_NM,
Laszlo Papp8e8ff052018-01-16 09:55:45 +00001261 freqLmdaToAnnotation(rxMax, useFreq));
1262 }
1263 if (rxGrid == txGrid) {
Laszlo Pappbf2cd742018-01-16 11:49:04 +00001264 annotations.set(propFreq ? AK_GRID_HZ : AK_GRID_LMDA_NM,
Laszlo Papp8e8ff052018-01-16 09:55:45 +00001265 freqLmdaToAnnotation(rxGrid, useFreq));
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001266 }
Laszlo Papp20cfb6f2018-01-08 16:06:53 +00001267
1268 int txPwr = OFOpticalPortFeaturesSerializerVer14.TX_PWR_VAL;
1269 long txPwrMin = optical.get().getTxPwrMin();
1270 long txPwrMax = optical.get().getTxPwrMax();
1271 annotations.set(AK_TX_PWR_FEATURE, ((supported & txPwr) != 0) ? "enabled" : "disabled");
1272 annotations.set(AK_TX_PWR_MIN, Long.toString(txPwrMin));
1273 annotations.set(AK_TX_PWR_MAX, Long.toString(txPwrMax));
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001274
1275 // TODO How to determine appropriate port type?
1276
Yuta HIGUCHI53e47962018-03-01 23:50:48 -08001277 return DefaultPortDescription.builder()
1278 .withPortNumber(portNo)
1279 .isEnabled(enabled)
1280 .type(FIBER)
1281 .portSpeed(portSpeed(port))
1282 .annotations(annotations.build())
1283 .build();
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001284 }
1285
1286 // fall back default
Yuta HIGUCHI53e47962018-03-01 23:50:48 -08001287 return DefaultPortDescription.builder()
1288 .withPortNumber(portNo)
1289 .isEnabled(enabled)
1290 .type(COPPER)
1291 .portSpeed(portSpeed(port))
1292 .annotations(annotations.build())
1293 .build();
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001294
Ray Milkeye0fade72015-01-15 13:29:47 -08001295 }
1296
1297 /**
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001298 * Build a portDescription from a given Ethernet port description.
tomff7eb7c2014-09-08 12:49:03 -07001299 *
alshabiba14f3642014-09-05 09:31:31 -07001300 * @param port the port to build from.
1301 * @return portDescription for the port.
1302 */
1303 private PortDescription buildPortDescription(OFPortDesc port) {
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001304 if (port.getVersion().wireVersion >= OFVersion.OF_14.getWireVersion()) {
1305 return buildPortDescription14(port);
1306 }
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001307 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
1308 boolean enabled =
1309 !port.getState().contains(OFPortState.LINK_DOWN) &&
1310 !port.getConfig().contains(OFPortConfig.PORT_DOWN);
1311 Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER;
mskalac584bd92017-11-28 15:51:17 +01001312 boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN);
1313 SparseAnnotations annotations = makePortAnnotation(port.getName(),
1314 port.getHwAddr().toString(),
1315 adminDown).build();
Yuta HIGUCHI53e47962018-03-01 23:50:48 -08001316 return DefaultPortDescription.builder()
1317 .withPortNumber(portNo)
1318 .isEnabled(enabled)
1319 .type(type)
1320 .portSpeed(portSpeed(port))
1321 .annotations(annotations)
1322 .build();
alshabiba14f3642014-09-05 09:31:31 -07001323 }
Ayaka Koshibeab91cc42014-09-25 10:20:52 -07001324
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001325 /**
1326 * Build a portDescription from a given a port description describing some
1327 * Optical port.
1328 *
1329 * @param port description property type.
1330 * @param port the port to build from.
1331 * @return portDescription for the port.
1332 */
Jimmy Yan4deb03b2016-06-24 10:53:54 -07001333 private PortDescription buildPortDescription(PortDescPropertyType ptype, OFPortOptical port,
1334 OpenFlowOpticalSwitch opsw) {
Jon Hallcbd1b392017-01-18 20:15:44 -08001335 checkArgument(!port.getDesc().isEmpty());
Marc De Leenheerfc913dd2015-07-30 16:04:55 -07001336
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001337 // Minimally functional fixture. This needs to be fixed as we add better support.
1338 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
Ayaka Koshibe74b55272015-05-28 15:16:04 -07001339
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001340 boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN)
1341 && !port.getConfig().contains(OFPortConfig.PORT_DOWN);
mskalac584bd92017-11-28 15:51:17 +01001342 boolean adminDown = port.getConfig().contains(OFPortConfig.PORT_DOWN);
1343 SparseAnnotations annotations = makePortAnnotation(port.getName(),
1344 port.getHwAddr().toString(),
1345 adminDown).build();
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001346
1347 if (port.getVersion() == OFVersion.OF_13
1348 && ptype == PortDescPropertyType.OPTICAL_TRANSPORT) {
1349 // At this point, not much is carried in the optical port message.
Ayaka Koshibeae541732015-05-19 13:37:27 -07001350 LOG.debug("Optical transport port message {}", port.toString());
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001351 } else {
1352 // removable once 1.4+ support complete.
Ayaka Koshibeae541732015-05-19 13:37:27 -07001353 LOG.debug("Unsupported optical port properties");
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001354 }
Marc De Leenheerfc913dd2015-07-30 16:04:55 -07001355
1356 OFPortDescPropOpticalTransport desc = port.getDesc().get(0);
1357 switch (desc.getPortSignalType()) {
1358 // FIXME: use constants once loxi has full optical extensions
1359 case 2: // OMS port
1360 // Assume complete optical spectrum and 50 GHz grid
Jimmy Yan4deb03b2016-06-24 10:53:54 -07001361 Set<OchSignal> signals = null;
1362 if (opsw instanceof HandlerBehaviour) {
1363 DriverHandler driverHandler = ((HandlerBehaviour) opsw).handler();
1364 if (driverHandler != null && driverHandler.hasBehaviour(LambdaQuery.class)) {
1365 try {
1366 signals = driverHandler.behaviour(LambdaQuery.class).queryLambdas(portNo);
1367 } catch (NullPointerException e) {
1368 signals = null;
1369 }
1370 }
1371 }
1372 Frequency minFreq;
1373 Frequency maxFreq;
1374 Frequency channelSpacing;
1375 if (signals == null || signals.isEmpty()) {
1376 minFreq = Spectrum.U_BAND_MIN;
1377 maxFreq = Spectrum.O_BAND_MAX;
1378 channelSpacing = Frequency.ofGHz(50);
1379 } else {
1380 Comparator<OchSignal> compare =
1381 (OchSignal a, OchSignal b) -> a.spacingMultiplier() - b.spacingMultiplier();
1382 OchSignal minOch = Collections.min(signals, compare);
1383 OchSignal maxOch = Collections.max(signals, compare);
1384 minFreq = minOch.centralFrequency();
1385 maxFreq = maxOch.centralFrequency();
1386 channelSpacing = minOch.channelSpacing().frequency();
1387 }
1388 return omsPortDescription(portNo, enabled, minFreq,
1389 maxFreq, channelSpacing, annotations);
Marc De Leenheerfc913dd2015-07-30 16:04:55 -07001390 case 5: // OCH port
1391 OchSignal signal = new OchSignal(GridType.DWDM, ChannelSpacing.CHL_50GHZ, 0, 4);
HIGUCHI Yuta34a3f692016-01-09 21:08:57 -08001392 return ochPortDescription(portNo, enabled, OduSignalType.ODU4,
Marc De Leenheerfc913dd2015-07-30 16:04:55 -07001393 true, signal, annotations);
1394 default:
1395 break;
1396 }
1397
Yuta HIGUCHI53e47962018-03-01 23:50:48 -08001398 return DefaultPortDescription.builder()
1399 .withPortNumber(portNo)
1400 .isEnabled(enabled)
1401 .type(FIBER)
1402 .portSpeed(0)
1403 .annotations(annotations)
1404 .build();
Ayaka Koshibe5460d622015-05-14 12:19:19 -07001405 }
1406
Marc De Leenheerb9311372015-07-09 11:36:49 -07001407 /**
1408 * Build a portDescription from a given port description describing a fiber switch optical port.
1409 *
1410 * @param port description property type.
1411 * @param port the port to build from.
1412 * @return portDescription for the port.
1413 */
1414 private PortDescription buildPortDescription(OFCalientPortDescStatsEntry port) {
1415 PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber());
1416
Marc De Leenheerc662d322016-02-18 16:05:10 -08001417 // Use the alias name if it's available
1418 String name = port.getName();
1419 List<OFCalientPortDescProp> props = port.getProperties();
Jon Hallcbd1b392017-01-18 20:15:44 -08001420 if (props != null && !props.isEmpty()) {
Marc De Leenheerc662d322016-02-18 16:05:10 -08001421 OFCalientPortDescPropOptical propOptical = (OFCalientPortDescPropOptical) props.get(0);
1422 if (propOptical != null) {
1423 name = propOptical.getInAlias();
1424 }
1425 }
1426
Marc De Leenheerb9311372015-07-09 11:36:49 -07001427 // FIXME when Calient OF agent reports port status
1428 boolean enabled = true;
mskalac584bd92017-11-28 15:51:17 +01001429 boolean adminDown = false;
1430 SparseAnnotations annotations = makePortAnnotation(name, port.getHwAddr().toString(), adminDown).build();
Marc De Leenheerb9311372015-07-09 11:36:49 -07001431
Marc De Leenheerfc913dd2015-07-30 16:04:55 -07001432 // S160 data sheet
1433 // Wavelength range: 1260 - 1630 nm, grid is irrelevant for this type of switch
HIGUCHI Yuta95d83e82016-04-26 12:13:48 -07001434 return omsPortDescription(portNo, enabled,
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -07001435 Spectrum.O_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(50), annotations);
Marc De Leenheerb9311372015-07-09 11:36:49 -07001436 }
1437
alshabibafc514a2014-12-01 14:44:05 -08001438 private PortDescription buildPortDescription(OFPortStatus status) {
1439 OFPortDesc port = status.getDesc();
1440 if (status.getReason() != OFPortReason.DELETE) {
1441 return buildPortDescription(port);
1442 } else {
Yuta HIGUCHI6512f3e2017-05-18 17:21:24 -07001443 PortDescription desc = buildPortDescription(port);
1444 if (desc.isEnabled()) {
1445 return DefaultPortDescription.builder(desc)
1446 .isEnabled(false)
1447 .build();
1448 }
1449 return desc;
alshabibafc514a2014-12-01 14:44:05 -08001450 }
1451 }
1452
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001453 /**
1454 * Returns port speed in Mbps.
1455 *
1456 * @param port description to parse
1457 * @return port speed in Mbps
1458 */
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001459 private long portSpeed(OFPortDesc port) {
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001460 if (port.getVersion().getWireVersion() >= OFVersion.OF_14.getWireVersion()) {
1461 // OFPortDescPropEthernet
1462 return port.getProperties().stream()
1463 .filter(OFPortDescPropEthernet.class::isInstance)
1464 .map(OFPortDescPropEthernet.class::cast)
1465 .mapToLong(OFPortDescPropEthernet::getCurrSpeed)
1466 .map(kbps -> kbps / KBPS)
1467 .findAny()
1468 .orElse(PortSpeed.SPEED_NONE.getSpeedBps() / MBPS);
1469 }
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001470 if (port.getVersion() == OFVersion.OF_13) {
Charles Chan25b77322015-12-13 01:00:56 -08001471 // Note: getCurrSpeed() returns a value in kbps (this also applies to OF_11 and OF_12)
1472 return port.getCurrSpeed() / KBPS;
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001473 }
Yuta HIGUCHI2341e602017-03-08 20:10:08 -08001474 // < OF1.3
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001475 PortSpeed portSpeed = PortSpeed.SPEED_NONE;
1476 for (OFPortFeatures feat : port.getCurr()) {
1477 portSpeed = PortSpeed.max(portSpeed, feat.getPortSpeed());
1478 }
Thomas Vachuska98eda532014-10-29 17:31:02 -07001479 return portSpeed.getSpeedBps() / MBPS;
Thomas Vachuskad16ce182014-10-29 17:25:29 -07001480 }
sangho538108b2015-04-08 14:29:20 -07001481
1482 @Override
1483 public void handleMessage(Dpid dpid, OFMessage msg) {
Ray Milkey7abe50b2016-04-13 11:57:44 -07001484 if (isDisabled) {
1485 return;
sangho538108b2015-04-08 14:29:20 -07001486 }
Ray Milkey7abe50b2016-04-13 11:57:44 -07001487
1488 try {
1489 switch (msg.getType()) {
1490 case STATS_REPLY:
1491 if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) {
1492 OFPortStatsReply portStatsReply = (OFPortStatsReply) msg;
1493 List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid);
1494 if (portStatsReplyList == null) {
Madan Jampani84382b92016-06-22 08:26:49 -07001495 portStatsReplyList = Lists.newCopyOnWriteArrayList();
Ray Milkey7abe50b2016-04-13 11:57:44 -07001496 }
1497 portStatsReplyList.addAll(portStatsReply.getEntries());
1498 portStatsReplies.put(dpid, portStatsReplyList);
1499 if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
Charles Chanb3ef0db2016-05-03 11:11:00 -07001500 List<OFPortStatsEntry> statsEntries = portStatsReplies.get(dpid);
1501 if (statsEntries != null) {
1502 pushPortMetrics(dpid, statsEntries);
1503 statsEntries.clear();
1504 }
Ray Milkey7abe50b2016-04-13 11:57:44 -07001505 }
yjimmyy646aa022016-07-05 12:09:50 -07001506 } else if (((OFStatsReply) msg).getStatsType() == OFStatsType.EXPERIMENTER) {
1507 OpenFlowSwitch sw = controller.getSwitch(dpid);
sangyun-han147e6f42016-07-26 17:14:41 +09001508 if (sw == null) {
1509 LOG.error("Switch {} is not found", dpid);
1510 break;
1511 }
yjimmyy646aa022016-07-05 12:09:50 -07001512 if (sw instanceof OpenFlowOpticalSwitch) {
1513 // Optical switch uses experimenter stats message to update power
1514 List<PortDescription> portDescs =
1515 ((OpenFlowOpticalSwitch) sw).processExpPortStats(msg);
1516 if (!portDescs.isEmpty()) {
1517 providerService.updatePorts(DeviceId.deviceId(Dpid.uri(dpid)), portDescs);
1518 }
1519 }
Ray Milkey7abe50b2016-04-13 11:57:44 -07001520 }
1521 break;
1522 case ERROR:
1523 if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) {
1524 LOG.error("port mod failed");
1525 }
Ray Milkeyd6a67c32018-02-02 10:30:35 -08001526 break;
Ray Milkey7abe50b2016-04-13 11:57:44 -07001527 default:
1528 break;
1529 }
1530 } catch (IllegalStateException e) {
1531 // system is shutting down and the providerService is no longer
1532 // valid. Messages cannot be processed.
1533 }
1534 }
1535
1536 private void disable() {
1537 isDisabled = true;
sangho538108b2015-04-08 14:29:20 -07001538 }
alshabibf1216ed2014-09-03 11:53:54 -07001539 }
Saurav Dasa2d37502016-03-25 17:50:40 -07001540
tomb5a46e62014-08-26 14:20:00 -07001541}