From 73f9aeaa11fead280f72da1b79c4af9806c70c19 Mon Sep 17 00:00:00 2001 From: Laszlo Papp Date: Mon, 15 Jan 2018 19:23:45 +0000 Subject: [PATCH] Avoid division by zero Nothing stops an OF agent to return zero for lambda values and ONOS probably ought to not crash then. One use case for this is when only one direction is supported on a port, for example tx. Unfortunately, the openflow specification does not separate the directions into different properties, so the agent implementation has to return some frequency value for rx in this case even if only the tx direction is supported. However, anything non-zero would probably be untruthful as it would indicate valid reading to the end user. Even zero will be problematic for unsupported power reading in a direction as 0 dBm is a valid value, but not sure how to deal with any better. Change-Id: I2597bd7d577d9c2e1a3b44421fe505b8b3b6cc92 --- .../provider/of/device/impl/OpenFlowDeviceProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java b/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java index ba691fdf10..35bb730a54 100644 --- a/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java +++ b/providers/openflow/device/src/main/java/org/onosproject/provider/of/device/impl/OpenFlowDeviceProvider.java @@ -994,7 +994,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr // f = c / λ // (m/s) * (nm/m) / (nm * 100) * 100 // annotations is in Hz - return Long.toString(c * 1_000_000_000 / lambda * 100); + return Long.toString(lambda == 0 ? lambda : (c * 1_000_000_000 / lambda * 100)); } private PortDescription buildPortDescription14(OFPortDesc port) {