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
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 ba691fd..35bb730 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 @@
// 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) {