[WIP] Fix RouteHandlere NPE
Change-Id: Ic5711365a5e82ba2465be8b0734898561d93d76a
diff --git a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RouteHandler.java b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RouteHandler.java
index d97b5ac..bb9f202 100644
--- a/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RouteHandler.java
+++ b/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RouteHandler.java
@@ -27,6 +27,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Objects;
+
/**
* Handles RouteEvent and manages routing entries.
*/
@@ -55,6 +57,11 @@
}
private void processRouteAddedInternal(ResolvedRoute route) {
+ if (!isReady()) {
+ log.info("System is not ready. Skip adding route for {}", route.prefix());
+ return;
+ }
+
IpPrefix prefix = route.prefix();
MacAddress nextHopMac = route.nextHopMac();
VlanId nextHopVlan = route.nextHopVlan();
@@ -78,6 +85,11 @@
}
private void processRouteRemovedInternal(ResolvedRoute route) {
+ if (!isReady()) {
+ log.info("System is not ready. Skip removing route for {}", route.prefix());
+ return;
+ }
+
IpPrefix prefix = route.prefix();
MacAddress nextHopMac = route.nextHopMac();
VlanId nextHopVlan = route.nextHopVlan();
@@ -88,4 +100,10 @@
srManager.routingRulePopulator.revokeRoute(
location.deviceId(), prefix, nextHopMac, nextHopVlan, location.port());
}
+
+ private boolean isReady() {
+ return Objects.nonNull(srManager.deviceConfiguration) &&
+ Objects.nonNull(srManager.defaultRoutingHandler) &&
+ Objects.nonNull(srManager.routingRulePopulator);
+ }
}