Fix an NPE that happens when DHCP server is not discovered yet
Also address the following issues:
- HOST_MOVED can include both movement and IP update. We should update server info when we see a HOST_MOVED event.
- Over 2k lines in this class
- Fix typo in extractClientId method name
Change-Id: I238027e650fb6b15c29b363caa09539170bdd3a4
diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java
index 81748c6..9b3097e 100644
--- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java
+++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/Dhcp6HandlerUtil.java
@@ -22,6 +22,7 @@
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.VlanId;
+import org.onlab.packet.dhcp.Dhcp6ClientIdOption;
import org.onlab.packet.dhcp.Dhcp6RelayOption;
import org.onlab.packet.dhcp.Dhcp6Option;
@@ -611,4 +612,34 @@
}
return true;
}
+
+ /**
+ * extract from dhcp6 packet ClientIdOption.
+ *
+ * @param directConnFlag directly connected host
+ * @param dhcp6Payload the dhcp6 payload
+ * @return Dhcp6ClientIdOption clientIdOption, or null if not exists.
+ */
+ static Dhcp6ClientIdOption extractClientId(Boolean directConnFlag, DHCP6 dhcp6Payload) {
+ Dhcp6ClientIdOption clientIdOption;
+
+ if (directConnFlag) {
+ clientIdOption = dhcp6Payload.getOptions()
+ .stream()
+ .filter(opt -> opt instanceof Dhcp6ClientIdOption)
+ .map(opt -> (Dhcp6ClientIdOption) opt)
+ .findFirst()
+ .orElse(null);
+ } else {
+ DHCP6 leafDhcp = Dhcp6HandlerUtil.getDhcp6Leaf(dhcp6Payload);
+ clientIdOption = leafDhcp.getOptions()
+ .stream()
+ .filter(opt -> opt instanceof Dhcp6ClientIdOption)
+ .map(opt -> (Dhcp6ClientIdOption) opt)
+ .findFirst()
+ .orElse(null);
+ }
+
+ return clientIdOption;
+ }
}