Fix race condition - if the device manager is not ready when a packet arrives, drop it rather than NPE

Change-Id: I601b4ce1d449b169059a3390441dcfa58b800db3
diff --git a/core/net/src/main/java/org/onosproject/net/packet/impl/PacketDriverProvider.java b/core/net/src/main/java/org/onosproject/net/packet/impl/PacketDriverProvider.java
index 78d1a75..be9551f 100644
--- a/core/net/src/main/java/org/onosproject/net/packet/impl/PacketDriverProvider.java
+++ b/core/net/src/main/java/org/onosproject/net/packet/impl/PacketDriverProvider.java
@@ -61,6 +61,10 @@
     }
 
     private PacketProgrammable getPacketProgrammable(DeviceId deviceId) {
+        if (deviceService == null) {
+            log.debug("Packet encountered but device service is not ready, dropping");
+            return null;
+        }
         Device device = deviceService.getDevice(deviceId);
         if (device.is(PacketProgrammable.class)) {
             return device.as(PacketProgrammable.class);
diff --git a/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java b/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java
index bace763..1ecf5b4 100644
--- a/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java
+++ b/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java
@@ -130,8 +130,8 @@
         appId = coreService.getAppId(CoreService.CORE_APP_NAME);
         store.setDelegate(delegate);
         deviceService.addListener(deviceListener);
-        store.existingRequests().forEach(this::pushToAllDevices);
         defaultProvider.init(deviceService);
+        store.existingRequests().forEach(this::pushToAllDevices);
         log.info("Started");
     }