VOL-432 : NPE in ONOS dhcpl2relay app
Also some other fixes found during testing

Change-Id: I0dd047827e5144a36717e09f5c5dccf9d3371589
diff --git a/src/main/java/org/opencord/dhcpl2relay/DhcpL2Relay.java b/src/main/java/org/opencord/dhcpl2relay/DhcpL2Relay.java
index ec4a726..29965dd 100755
--- a/src/main/java/org/opencord/dhcpl2relay/DhcpL2Relay.java
+++ b/src/main/java/org/opencord/dhcpl2relay/DhcpL2Relay.java
@@ -77,6 +77,7 @@
 import org.slf4j.LoggerFactory;
 
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.Map;
 import java.util.List;
@@ -139,7 +140,7 @@
     protected boolean option82 = true;
 
     @Property(name = "enableDhcpBroadcastReplies", boolValue = false,
-            label = "Add option 82 to relayed packets")
+            label = "Ask the DHCP Server to send back replies as L2 broadcast")
     protected boolean enableDhcpBroadcastReplies = false;
 
     private DhcpRelayPacketProcessor dhcpRelayPacketProcessor =
@@ -202,6 +203,11 @@
         if (o != null) {
             option82 = o;
         }
+
+        o = Tools.isPropertyEnabled(properties, "enableDhcpBroadcastReplies");
+        if (o != null) {
+            enableDhcpBroadcastReplies = o;
+        }
     }
 
     /**
@@ -562,6 +568,10 @@
 
             MacAddress dstMac = valueOf(dhcpPayload.getClientHardwareAddress());
             ConnectPoint subsCp = getConnectPointOfClient(dstMac);
+            // If we can't find the subscriber, can't process further
+            if (subsCp == null) {
+                return null;
+            }
             // if it's an ACK packet store the information for display purpose
             if (getDhcpPacketType(dhcpPayload) == DHCPPacketType.DHCPACK) {
 
@@ -575,7 +585,12 @@
 
                     String circuitId = "None";
                     if (circuitIds.size() == 1) {
-                        circuitId = circuitIds.get(0).getData().toString();
+                        byte[] array = circuitIds.get(0).getData();
+
+                        try {
+                            // we leave the first two bytes as they are the id and length
+                            circuitId = new String(Arrays.copyOfRange(array, 2, array.length), "UTF-8");
+                        } catch (Exception e) { }
                     }
 
                     IpAddress ip = IpAddress.valueOf(dhcpPayload.getYourIPAddress());