Fix npe when one of the address is not configured

Change-Id: If42b4d35bc20060db0bc0fe2699e3b375c2cf9f8
diff --git a/src/main/java/org/onosproject/segmentrouting/ArpHandler.java b/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
index 8ef889f..30c6ada 100644
--- a/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
+++ b/src/main/java/org/onosproject/segmentrouting/ArpHandler.java
@@ -192,7 +192,10 @@
         /*
          * Retrieves device info.
          */
-        getSenderInfo(senderMacAddress, senderIpAddress, deviceId, targetAddress);
+        if (!getSenderInfo(senderMacAddress, senderIpAddress, deviceId, targetAddress)) {
+            log.warn("Aborting sendArpRequest, we cannot get all the information needed");
+            return;
+        }
         /*
          * Creates the request.
          */
diff --git a/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java b/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
index 1594364..9675620 100644
--- a/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
+++ b/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java
@@ -431,7 +431,10 @@
         /*
          * Retrieves device info.
          */
-        getSenderInfo(senderMacAddress, senderIpAddress, deviceId, targetAddress);
+        if (!getSenderInfo(senderMacAddress, senderIpAddress, deviceId, targetAddress)) {
+            log.warn("Aborting sendNdpRequest, we cannot get all the information needed");
+            return;
+        }
         /*
          * We have to compute the dst mac address and dst
          * ip address.
diff --git a/src/main/java/org/onosproject/segmentrouting/SegmentRoutingNeighbourHandler.java b/src/main/java/org/onosproject/segmentrouting/SegmentRoutingNeighbourHandler.java
index 1d9a2fc..0fa077b 100644
--- a/src/main/java/org/onosproject/segmentrouting/SegmentRoutingNeighbourHandler.java
+++ b/src/main/java/org/onosproject/segmentrouting/SegmentRoutingNeighbourHandler.java
@@ -73,28 +73,37 @@
      * @param ip where to copy the ip
      * @param deviceId the device id
      * @param targetAddress the target address
+     * @return true if it was possible to get the necessary info.
+     * False for errors
      */
-    protected void getSenderInfo(byte[] mac,
+    protected boolean getSenderInfo(byte[] mac,
                                  byte[] ip,
                                  DeviceId deviceId,
                                  IpAddress targetAddress) {
         byte[] senderMacAddress;
         byte[] senderIpAddress;
+        IpAddress sender;
         try {
             senderMacAddress = config.getDeviceMac(deviceId).toBytes();
             if (targetAddress.isIp4()) {
-                senderIpAddress = config.getRouterIpAddressForASubnetHost(targetAddress.getIp4Address())
-                        .toOctets();
+                sender = config.getRouterIpAddressForASubnetHost(targetAddress.getIp4Address());
+
             } else {
-                senderIpAddress = config.getRouterIpAddressForASubnetHost(targetAddress.getIp6Address())
-                        .toOctets();
+                sender = config.getRouterIpAddressForASubnetHost(targetAddress.getIp6Address());
             }
+            // If sender is null we abort.
+            if (sender == null) {
+                log.warn("Sender ip is null. Aborting getSenderInfo");
+                return false;
+            }
+            senderIpAddress = sender.toOctets();
         } catch (DeviceConfigNotFoundException e) {
-            log.warn(e.getMessage() + " Aborting sendArpRequest.");
-            return;
+            log.warn(e.getMessage() + " Aborting getSenderInfo");
+            return false;
         }
         System.arraycopy(senderMacAddress, 0, mac, 0, senderMacAddress.length);
         System.arraycopy(senderIpAddress, 0, ip, 0, senderIpAddress.length);
+        return true;
     }
 
     /**