[CORD-653] Fix host monitor and provide utility functions
Changes:
- fixes host monitor generating correct probe;
- provides and tests utility functions to calculate well known address;
- provides utility functions to craft ndp solicit and ndp adv;
- provides utility functions to craft arp request;
- provides utility functions to craft icmp and icmpv6 response;
Change-Id: I5a4fa89e549fd665a48e51ba3438932849f6627c
diff --git a/utils/misc/src/main/java/org/onlab/packet/ICMP6.java b/utils/misc/src/main/java/org/onlab/packet/ICMP6.java
index 64552bd..4e6139b 100644
--- a/utils/misc/src/main/java/org/onlab/packet/ICMP6.java
+++ b/utils/misc/src/main/java/org/onlab/packet/ICMP6.java
@@ -373,4 +373,48 @@
.add("checksum", Short.toString(checksum))
.toString();
}
+
+ /**
+ * Builds an ICMPv6 reply using the supplied ICMPv6 request.
+ *
+ * @param ethRequest the Ethernet packet containing the ICMPv6 ECHO request
+ * @return the Ethernet packet containing the ICMPv6 ECHO reply
+ */
+ public static Ethernet buildIcmp6Reply(Ethernet ethRequest) {
+
+ if (ethRequest.getEtherType() != Ethernet.TYPE_IPV6) {
+ return null;
+ }
+
+ IPv6 ipv6Request = (IPv6) ethRequest.getPayload();
+
+ if (ipv6Request.getNextHeader() != IPv6.PROTOCOL_ICMP6) {
+ return null;
+ }
+
+ Ethernet ethReply = new Ethernet();
+
+
+ IPv6 ipv6Reply = new IPv6();
+
+ byte[] destAddress = ipv6Request.getDestinationAddress();
+ ipv6Reply.setDestinationAddress(ipv6Request.getSourceAddress());
+ ipv6Reply.setSourceAddress(destAddress);
+ ipv6Reply.setHopLimit((byte) 64);
+ ipv6Reply.setNextHeader(IPv6.PROTOCOL_ICMP6);
+
+ ICMP6 icmpv6Reply = new ICMP6();
+ icmpv6Reply.setPayload(ipv6Request.getPayload().getPayload());
+ icmpv6Reply.setIcmpType(ICMP6.ECHO_REPLY);
+ icmpv6Reply.setIcmpCode((byte) 0);
+ ipv6Reply.setPayload(icmpv6Reply);
+
+ ethReply.setEtherType(Ethernet.TYPE_IPV6);
+ ethReply.setVlanID(ethRequest.getVlanID());
+ ethReply.setDestinationMACAddress(ethRequest.getSourceMACAddress());
+ ethReply.setSourceMACAddress(ethRequest.getDestinationMACAddress());
+ ethReply.setPayload(ipv6Reply);
+
+ return ethReply;
+ }
}