blob: 8cd387020c6dfdd20aefcca5e1bc0787c916f968 [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;
tomb5a46e62014-08-26 14:20:00 -070023import org.apache.felix.scr.annotations.Activate;
24import org.apache.felix.scr.annotations.Component;
25import org.apache.felix.scr.annotations.Deactivate;
Dusan Pajinbab8a5e2015-07-24 17:37:19 +020026import org.apache.felix.scr.annotations.Modified;
27import org.apache.felix.scr.annotations.Property;
tomb5a46e62014-08-26 14:20:00 -070028import org.apache.felix.scr.annotations.Reference;
29import org.apache.felix.scr.annotations.ReferenceCardinality;
Thomas Vachuskaf0397b52015-05-29 13:50:17 -070030import org.onlab.packet.ChassisId;
Marc De Leenheerb9311372015-07-09 11:36:49 -070031import org.onlab.util.Frequency;
32import org.onlab.util.Spectrum;
Yafit Hadara9a73de2015-09-06 13:52:52 +030033import org.onosproject.cfg.ComponentConfigService;
Thomas Vachuskab52a0142015-04-21 17:48:15 -070034import org.onosproject.net.AnnotationKeys;
Marc De Leenheerfc913dd2015-07-30 16:04:55 -070035import org.onosproject.net.ChannelSpacing;
Toru Furusawa72ee30c2016-01-08 13:29:04 -080036import org.onosproject.net.CltSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080037import org.onosproject.net.DefaultAnnotations;
Yuta HIGUCHI2341e602017-03-08 20:10:08 -080038import org.onosproject.net.DefaultAnnotations.Builder;
Yafit Hadara9a73de2015-09-06 13:52:52 +030039import org.onosproject.net.Device;
Brian O'Connorabafb502014-12-02 22:26:20 -080040import org.onosproject.net.DeviceId;
Marc De Leenheerfc913dd2015-07-30 16:04:55 -070041import org.onosproject.net.GridType;
Brian O'Connorabafb502014-12-02 22:26:20 -080042import org.onosproject.net.MastershipRole;
Marc De Leenheerfc913dd2015-07-30 16:04:55 -070043import org.onosproject.net.OchSignal;
44import org.onosproject.net.OduSignalType;
Rimon Ashkenazy8ebfff02016-02-01 11:56:36 +020045import org.onosproject.net.OtuSignalType;
Brian O'Connorabafb502014-12-02 22:26:20 -080046import org.onosproject.net.Port;
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -070047import org.onosproject.net.Port.Type;
Brian O'Connorabafb502014-12-02 22:26:20 -080048import org.onosproject.net.PortNumber;
49import org.onosproject.net.SparseAnnotations;
Jimmy Yan4deb03b2016-06-24 10:53:54 -070050import org.onosproject.net.behaviour.LambdaQuery;
Brian O'Connorabafb502014-12-02 22:26:20 -080051import org.onosproject.net.device.DefaultDeviceDescription;
52import org.onosproject.net.device.DefaultPortDescription;
sangho538108b2015-04-08 14:29:20 -070053import org.onosproject.net.device.DefaultPortStatistics;
Brian O'Connorabafb502014-12-02 22:26:20 -080054import org.onosproject.net.device.DeviceDescription;
55import org.onosproject.net.device.DeviceProvider;
56import org.onosproject.net.device.DeviceProviderRegistry;
57import org.onosproject.net.device.DeviceProviderService;
Thomas Vachuska164ecf62018-05-08 17:29:55 -070058import org.onosproject.net.device.DeviceService;
Brian O'Connorabafb502014-12-02 22:26:20 -080059import org.onosproject.net.device.PortDescription;
sangho538108b2015-04-08 14:29:20 -070060import org.onosproject.net.device.PortStatistics;
Victor Silvaac8dab02016-11-28 16:33:08 -030061import org.onosproject.net.driver.Driver;
Jimmy Yan4deb03b2016-06-24 10:53:54 -070062import org.onosproject.net.driver.DriverHandler;
Victor Silvaac8dab02016-11-28 16:33:08 -030063import org.onosproject.net.driver.DriverService;
Jimmy Yan4deb03b2016-06-24 10:53:54 -070064import org.onosproject.net.driver.HandlerBehaviour;
Brian O'Connorabafb502014-12-02 22:26:20 -080065import org.onosproject.net.provider.AbstractProvider;
66import org.onosproject.net.provider.ProviderId;
67import org.onosproject.openflow.controller.Dpid;
68import org.onosproject.openflow.controller.OpenFlowController;
sangho538108b2015-04-08 14:29:20 -070069import org.onosproject.openflow.controller.OpenFlowEventListener;
Ayaka Koshibe5460d622015-05-14 12:19:19 -070070import org.onosproject.openflow.controller.OpenFlowOpticalSwitch;
Brian O'Connorabafb502014-12-02 22:26:20 -080071import org.onosproject.openflow.controller.OpenFlowSwitch;
72import org.onosproject.openflow.controller.OpenFlowSwitchListener;
Ayaka Koshibe5460d622015-05-14 12:19:19 -070073import org.onosproject.openflow.controller.PortDescPropertyType;
Brian O'Connorabafb502014-12-02 22:26:20 -080074import org.onosproject.openflow.controller.RoleState;
Dusan Pajinbab8a5e2015-07-24 17:37:19 +020075import org.osgi.service.component.ComponentContext;
Marc De Leenheerc662d322016-02-18 16:05:10 -080076import org.projectfloodlight.openflow.protocol.OFCalientPortDescProp;
77import org.projectfloodlight.openflow.protocol.OFCalientPortDescPropOptical;
Marc De Leenheerb9311372015-07-09 11:36:49 -070078import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry;
Laszlo Papp58174812018-01-16 13:29:47 +000079import org.projectfloodlight.openflow.protocol.OFCapabilities;
Saurav Dasa2d37502016-03-25 17:50:40 -070080import org.projectfloodlight.openflow.protocol.OFErrorMsg;
81import org.projectfloodlight.openflow.protocol.OFErrorType;
Yafit Hadara9a73de2015-09-06 13:52:52 +030082import org.projectfloodlight.openflow.protocol.OFExpPort;
83import org.projectfloodlight.openflow.protocol.OFExpPortDescPropOpticalTransport;
84import org.projectfloodlight.openflow.protocol.OFExpPortOpticalTransportLayerEntry;
Ayaka Koshibee8708e32014-10-22 13:40:18 -070085import org.projectfloodlight.openflow.protocol.OFFactory;
sangho538108b2015-04-08 14:29:20 -070086import org.projectfloodlight.openflow.protocol.OFMessage;
Yafit Hadara9a73de2015-09-06 13:52:52 +030087import org.projectfloodlight.openflow.protocol.OFObject;
alshabib4680bb62014-09-04 17:15:08 -070088import org.projectfloodlight.openflow.protocol.OFPortConfig;
alshabib25c8eec2014-09-04 16:41:31 -070089import org.projectfloodlight.openflow.protocol.OFPortDesc;
Laszlo Papp8e8ff052018-01-16 09:55:45 +000090import org.projectfloodlight.openflow.protocol.OFPortDescProp;
Yuta HIGUCHI2341e602017-03-08 20:10:08 -080091import org.projectfloodlight.openflow.protocol.OFPortDescPropEthernet;
92import org.projectfloodlight.openflow.protocol.OFPortDescPropOptical;
Marc De Leenheerfc913dd2015-07-30 16:04:55 -070093import org.projectfloodlight.openflow.protocol.OFPortDescPropOpticalTransport;
Palash Kala496ef1a22018-03-21 14:57:50 +090094import org.projectfloodlight.openflow.protocol.OFPortDescStatsRequest;
Thomas Vachuskad16ce182014-10-29 17:25:29 -070095import org.projectfloodlight.openflow.protocol.OFPortFeatures;
Saurav Dasa2d37502016-03-25 17:50:40 -070096import org.projectfloodlight.openflow.protocol.OFPortMod;
Ayaka Koshibe5460d622015-05-14 12:19:19 -070097import org.projectfloodlight.openflow.protocol.OFPortOptical;
Yafit Hadara9a73de2015-09-06 13:52:52 +030098import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportLayerClass;
99import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportSignalType;
alshabibafc514a2014-12-01 14:44:05 -0800100import org.projectfloodlight.openflow.protocol.OFPortReason;
alshabib4680bb62014-09-04 17:15:08 -0700101import org.projectfloodlight.openflow.protocol.OFPortState;
sangho538108b2015-04-08 14:29:20 -0700102import org.projectfloodlight.openflow.protocol.OFPortStatsEntry;
Laszlo Papp7cf60372018-01-11 00:06:43 +0000103import org.projectfloodlight.openflow.protocol.OFPortStatsPropOptical;
sangho538108b2015-04-08 14:29:20 -0700104import org.projectfloodlight.openflow.protocol.OFPortStatsReply;
alshabiba14f3642014-09-05 09:31:31 -0700105import org.projectfloodlight.openflow.protocol.OFPortStatus;
sangho538108b2015-04-08 14:29:20 -0700106import org.projectfloodlight.openflow.protocol.OFStatsReply;
Thomas Vachuska893bf4b2015-05-29 18:13:18 -0700107import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
sangho538108b2015-04-08 14:29:20 -0700108import org.projectfloodlight.openflow.protocol.OFStatsType;
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700109import org.projectfloodlight.openflow.protocol.OFVersion;
Yuta HIGUCHIf42a2cc2017-05-02 17:04:31 -0700110import org.projectfloodlight.openflow.protocol.ver14.OFOpticalPortFeaturesSerializerVer14;
Laszlo Papp7cf60372018-01-11 00:06:43 +0000111import org.projectfloodlight.openflow.protocol.ver14.OFPortStatsOpticalFlagsSerializerVer14;
Saurav Dasa2d37502016-03-25 17:50:40 -0700112import org.projectfloodlight.openflow.types.OFPort;
Thomas Vachuskad16ce182014-10-29 17:25:29 -0700113import org.projectfloodlight.openflow.types.PortSpeed;
tomb5a46e62014-08-26 14:20:00 -0700114import org.slf4j.Logger;
tom5f38b3a2014-08-27 23:50:54 -0700115
Marc De Leenheer8aba62f2017-04-25 14:33:37 -0700116import java.util.ArrayList;
117import java.util.Collection;
118import java.util.Collections;
119import java.util.Comparator;
120import java.util.Dictionary;
Jimmy Jine9b7a022016-08-12 16:56:48 -0700121import java.util.EnumSet;
Marc De Leenheer8aba62f2017-04-25 14:33:37 -0700122import java.util.HashMap;
123import java.util.HashSet;
124import java.util.List;
Thomas Vachuska5b38dc02018-05-10 15:24:40 -0700125import java.util.Map;
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800126import java.util.Optional;
Marc De Leenheer8aba62f2017-04-25 14:33:37 -0700127import java.util.Properties;
128import java.util.Set;
129import java.util.Timer;
130
131import static com.google.common.base.Preconditions.checkArgument;
132import static com.google.common.base.Strings.isNullOrEmpty;
133import static org.onlab.util.Tools.get;
134import static org.onosproject.net.DeviceId.deviceId;
135import static org.onosproject.net.Port.Type.COPPER;
136import static org.onosproject.net.Port.Type.FIBER;
137import static org.onosproject.net.optical.device.OchPortHelper.ochPortDescription;
138import static org.onosproject.net.optical.device.OduCltPortHelper.oduCltPortDescription;
139import static org.onosproject.net.optical.device.OmsPortHelper.omsPortDescription;
140import static org.onosproject.net.optical.device.OtuPortHelper.otuPortDescription;
141import static org.onosproject.openflow.controller.Dpid.dpid;
142import static org.onosproject.openflow.controller.Dpid.uri;
143import 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 */
tomb1260e42014-08-26 18:39:57 -0700149@Component(immediate = true)
tomab21e7c2014-08-26 15:23:08 -0700150public class OpenFlowDeviceProvider extends AbstractProvider implements DeviceProvider {
tomb5a46e62014-08-26 14:20:00 -0700151
alshabiba89cc582014-09-09 16:43:00 -0700152 private static final Logger LOG = getLogger(OpenFlowDeviceProvider.class);
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700153
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800154 // TODO Some duplicate with one defined in OpticalAnnotations
155 // slice out optical specific handling and consolidate.
156 /**
157 * Annotation key for minimum frequency in Hz.
158 * Value is expected to be an integer.
159 */
160 public static final String AK_MIN_FREQ_HZ = "minFrequency";
161
162 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000163 * Annotation key for minimum lambda in nm.
164 * Value is expected to be an integer.
165 */
166 public static final String AK_MIN_LMDA_NM = "minLambda";
167
168 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800169 * Annotation key for maximum frequency in Hz.
170 * Value is expected be an integer.
171 */
172 public static final String AK_MAX_FREQ_HZ = "maxFrequency";
173
174 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000175 * Annotation key for maximum lambda in nm.
176 * Value is expected be an integer.
177 */
178 public static final String AK_MAX_LMDA_NM = "maxLambda";
179
180 /**
181 * Annotation key for grid frequency in Hz.
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800182 * Value is expected to be an integer.
183 */
184 public static final String AK_GRID_HZ = "grid";
185
Laszlo Papp20cfb6f2018-01-08 16:06:53 +0000186 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000187 * Annotation key for grid lambda in nm.
188 * Value is expected to be an integer.
189 */
190 public static final String AK_GRID_LMDA_NM = "gridLambda";
191
192 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800193 * Annotation key for minimum frequency in Hz.
194 * Value is expected to be an integer.
195 */
196 public static final String AK_TX_MIN_FREQ_HZ = "txMinFrequency";
197
198 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000199 * Annotation key for minimum lambda in nm.
200 * Value is expected to be an integer.
201 */
202 public static final String AK_TX_MIN_LMDA_NM = "txMinLambda";
203
204 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800205 * Annotation key for maximum frequency in Hz.
206 * Value is expected be an integer.
207 */
208 public static final String AK_TX_MAX_FREQ_HZ = "txMaxFrequency";
209
210 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000211 * Annotation key for maximum lambda in nm.
212 * Value is expected be an integer.
213 */
214 public static final String AK_TX_MAX_LMDA_NM = "txMaxLambda";
215
216 /**
217 * Annotation key for grid frequency in Hz.
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800218 * Value is expected to be an integer.
219 */
220 public static final String AK_TX_GRID_HZ = "txGrid";
221
222 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000223 * Annotation key for grid lambda in nm.
224 * Value is expected to be an integer.
225 */
226 public static final String AK_TX_GRID_LMDA_NM = "txGridLambda";
227
228 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800229 * Annotation key for minimum frequency in Hz.
230 * Value is expected to be an integer.
231 */
232 public static final String AK_RX_MIN_FREQ_HZ = "rxMinFrequency";
233
234 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000235 * Annotation key for minimum lambda in nm.
236 * Value is expected to be an integer.
237 */
238 public static final String AK_RX_MIN_LMDA_NM = "rxMinLambda";
239
240 /**
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800241 * Annotation key for maximum frequency in Hz.
242 * Value is expected be an integer.
243 */
244 public static final String AK_RX_MAX_FREQ_HZ = "rxMaxFrequency";
245
246 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000247 * Annotation key for maximum lambda in nm.
248 * Value is expected be an integer.
249 */
250 public static final String AK_RX_MAX_LMDA_NM = "rxMaxLambda";
251
252 /**
253 * Annotation key for grid frequency in Hz.
Yuta HIGUCHI2341e602017-03-08 20:10:08 -0800254 * Value is expected to be an integer.
255 */
256 public static final String AK_RX_GRID_HZ = "rxGrid";
257
Laszlo Papp20cfb6f2018-01-08 16:06:53 +0000258 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000259 * Annotation key for grid lambda in nm.
260 * Value is expected to be an integer.
261 */
262 public static final String AK_RX_GRID_LMDA_NM = "rxGridLambda";
263
264 /**
Laszlo Papp8e8ff052018-01-16 09:55:45 +0000265 * Annotation key for indicating frequency must be used instead of
266 * wavelength for port tuning.
267 * Value is expected to be "enabled" or "disabled"
268 */
269 public static final String AK_USE_FREQ_FEATURE = "useFreqFeature";
270
271 /**
Laszlo Papp20cfb6f2018-01-08 16:06:53 +0000272 * Annotation key for minimum transmit power in dBm*10.
273 * Value is expected to be an integer.
274 */
275 public static final String AK_TX_PWR_MIN = "txPowerMin";
276
277 /**
278 * Annotation key for maximum transmit power in dBm*10.
279 * Value is expected to be an integer.
280 */
281 public static final String AK_TX_PWR_MAX = "txPowerMax";
282
Laszlo Papp7cf60372018-01-11 00:06:43 +0000283
284
285 // Port Stats annotations
286
287 /**
288 * Annotation key for transmit frequency in Hz.
289 * Value is expected be an integer.
290 */
291 public static final String AK_TX_FREQ_HZ = "txFrequency";
292
293 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000294 * Annotation key for transmit lambda in nm.
295 * Value is expected be an integer.
296 */
297 public static final String AK_TX_LMDA_NM = "txLambda";
298
299 /**
300 * Annotation key for transmit offset frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000301 * Value is expected be an integer.
302 */
303 public static final String AK_TX_OFFSET_HZ = "txOffset";
304
305 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000306 * Annotation key for transmit offset in nm.
307 * Value is expected be an integer.
308 */
309 public static final String AK_TX_OFFSET_LMDA_NM = "txOffsetLambda";
310
311 /**
312 * Annotation key for transmit grid spacing frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000313 * Value is expected be an integer.
314 */
315 public static final String AK_TX_GRID_SPAN_HZ = "txGridSpan";
316
317 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000318 * Annotation key for transmit grid spacing lambda in nm.
319 * Value is expected be an integer.
320 */
321 public static final String AK_TX_GRID_SPAN_LMDA_NM = "txGridSpanLambda";
322
323 /**
Laszlo Papp7cf60372018-01-11 00:06:43 +0000324 * Annotation key for receive frequency in Hz.
325 * Value is expected be an integer.
326 */
327 public static final String AK_RX_FREQ_HZ = "rxFrequency";
328
329 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000330 * Annotation key for receive lambda in nm.
331 * Value is expected be an integer.
332 */
333 public static final String AK_RX_LMDA_NM = "rxLambda";
334
335 /**
336 * Annotation key for receive offset frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000337 * Value is expected be an integer.
338 */
339 public static final String AK_RX_OFFSET_HZ = "rxOffset";
340
341 /**
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000342 * Annotation key for receive offset lambda in nm.
343 * Value is expected be an integer.
344 */
345 public static final String AK_RX_OFFSET_LMDA_NM = "rxOffsetLambda";
346
347 /**
348 * Annotation key for receive grid spacing frequency in Hz.
Laszlo Papp7cf60372018-01-11 00:06:43 +0000349 * Value is expected be an integer.
350 */
351 public static final String AK_RX_GRID_SPAN_HZ = "rxGridSpan";
352
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000353 /**
354 * Annotation key for receive grid spacing lambda in nm.
355 * Value is expected be an integer.
356 */
357 public static final String AK_RX_GRID_SPAN_LMDA_NM = "rxGridSpanLambda";
358
Laszlo Papp7cf60372018-01-11 00:06:43 +0000359 /**
360 * Annotation key for transmit power in dBm*10.
361 * Value is expected to be an integer.
362 */
363 public static final String AK_TX_PWR = "txPower";
364
365 /**
366 * Annotation key for receive power feature.
367 * Value is expected to be "enabled" or "disabled"
368 */
369 public static final String AK_RX_PWR_FEATURE = "rxPwrFeature";
370
371 /**
372 * Annotation key for receive power in dBm*10.
373 * Value is expected to be an integer.
374 */
375 public static final String AK_RX_PWR = "rxPower";
376
377 /**
378 * Annotation key for transmit bias feature.
379 * Value is expected to be "enabled" or "disabled"
380 */
381 public static final String AK_TX_BIAS_FEATURE = "txBiasFeature";
382
383 /**
384 * Annotation key for transmit bias current in mA*10.
385 * Value is expected to be an integer.
386 */
387 public static final String AK_BIAS_CURRENT = "biasCurrent";
388
389 /**
390 * Annotation key for transmit temperature feature.
391 * Value is expected to be "enabled" or "disabled"
392 */
393 public static final String AK_TX_TEMP_FEATURE = "txTempFeature";
394
395 /**
396 * Annotation key for transmit laser temperature in C*10.
397 * Value is expected to be an integer.
398 */
399 public static final String AK_TEMPERATURE = "temperature";
400
401
402 // Common feature annotations
403
404 /**
405 * Annotation key for transmit tune feature.
406 * Value is expected to be "enabled" or "disabled"
407 */
408 public static final String AK_TX_TUNE_FEATURE = "txTuneFeature";
409
410 /**
411 * Annotation key for receive tune feature.
412 * Value is expected to be "enabled" or "disabled"
413 */
414 public static final String AK_RX_TUNE_FEATURE = "rxTuneFeature";
415
416 /**
417 * Annotation key for transmit power feature.
418 * Value is expected to be "enabled" or "disabled"
419 */
420 public static final String AK_TX_PWR_FEATURE = "txPwrFeature";
421
422
Charles Chan25b77322015-12-13 01:00:56 -0800423 //TODO consider renaming KBPS and MBPS (as they are used to convert by division)
424 private static final long KBPS = 1_000;
Ray Milkey3717e602018-02-01 13:49:47 -0800425 private static final long MBPS = 1_000L * 1_000L;
Rimon Ashkenazye3201032016-01-11 14:27:30 +0200426 private static final Frequency FREQ50 = Frequency.ofGHz(50);
427 private static final Frequency FREQ191_7 = Frequency.ofGHz(191_700);
Sho SHIMIZU00762ee2016-01-05 16:32:24 -0800428 private static final Frequency FREQ4_4 = Frequency.ofGHz(4_400);
tomb5a46e62014-08-26 14:20:00 -0700429
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000430 private static final long C = 299792458; // speed of light in m/s
Thomas Vachuska164ecf62018-05-08 17:29:55 -0700431 public static final String SCHEME = "of";
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000432
tomb5a46e62014-08-26 14:20:00 -0700433 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
tom96dfcab2014-08-28 09:26:03 -0700434 protected DeviceProviderRegistry providerRegistry;
tomab21e7c2014-08-26 15:23:08 -0700435
tom5f38b3a2014-08-27 23:50:54 -0700436 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Thomas Vachuska164ecf62018-05-08 17:29:55 -0700437 protected DeviceService deviceService;
438
439 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
tom5f38b3a2014-08-27 23:50:54 -0700440 protected OpenFlowController controller;
441
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200442 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
443 protected ComponentConfigService cfgService;
444
Victor Silvaac8dab02016-11-28 16:33:08 -0300445 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
446 protected DriverService driverService;
447
tomab21e7c2014-08-26 15:23:08 -0700448 private DeviceProviderService providerService;
tomb5a46e62014-08-26 14:20:00 -0700449
sangho538108b2015-04-08 14:29:20 -0700450 private final InternalDeviceProvider listener = new InternalDeviceProvider();
451
Simon Hunt7a307652016-06-23 01:17:29 -0700452 private static final String POLL_PROP_NAME = "portStatsPollFrequency";
453 private static final int POLL_INTERVAL = 5;
454 @Property(name = POLL_PROP_NAME, intValue = POLL_INTERVAL,
Dusan Pajinbab8a5e2015-07-24 17:37:19 +0200455 label = "Frequency (in seconds) for polling switch Port statistics")
456 private int portStatsPollFrequency = POLL_INTERVAL;
sangho538108b2015-04-08 14:29:20 -0700457
Laszlo Pappbf2cd742018-01-16 11:49:04 +0000458 private static final String PROP_FREQ = "propertyFrequency";
459 private static final boolean DEFAULT_PROP_FREQ = true;
460 @Property(name = PROP_FREQ, boolValue = DEFAULT_PROP_FREQ,
461 label = "It indicates frequency must be used instead of wavelength for port tuning.")
462 private static boolean propFreq = DEFAULT_PROP_FREQ;
463
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 {
Simon Hunt7a307652016-06-23 01:17:29 -0700505 String s = get(properties, POLL_PROP_NAME);
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}