Add ReplyRecord field into Map-Request message

Change-Id: Ia9850bade2ee1ab654a7fb58a5ff00ebfd52a19e
diff --git a/protocols/lisp/ctl/src/test/java/org/onosproject/lisp/ctl/impl/LispMessageDecoderTest.java b/protocols/lisp/ctl/src/test/java/org/onosproject/lisp/ctl/impl/LispMessageDecoderTest.java
index d3e74b3..b937118 100644
--- a/protocols/lisp/ctl/src/test/java/org/onosproject/lisp/ctl/impl/LispMessageDecoderTest.java
+++ b/protocols/lisp/ctl/src/test/java/org/onosproject/lisp/ctl/impl/LispMessageDecoderTest.java
@@ -55,9 +55,11 @@
         byte[] messageData = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
         byte[] eidData = {0x0, 0x1, 0x0, 0x0, 0x0, 0x0};
         byte[] rlocData = {0x0, 0x1, 0x0, 0x0, 0x0, 0x0};
+        byte[] replyRecord = {0x0, 0x0, 0x0, 0x1};
         buffer.writeBytes(messageData);
         buffer.writeBytes(eidData);
         buffer.writeBytes(rlocData);
+        buffer.writeBytes(replyRecord);
         return buffer;
     }
 
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java
index 9055e409..7af4fa0 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java
@@ -50,6 +50,7 @@
     private final boolean smr;
     private final boolean pitr;
     private final boolean smrInvoked;
+    private final int replyRecord;
 
     static final RequestWriter WRITER;
     static {
@@ -69,11 +70,14 @@
      * @param smr            smr flag
      * @param pitr           pitr flag
      * @param smrInvoked     smrInvoked flag
+     * @param replyReocrd    size of map-reply record
      */
     private DefaultLispMapRequest(long nonce, LispAfiAddress sourceEid,
-                                  List<LispAfiAddress> itrRlocs, List<LispEidRecord> eidRecords,
-                                  boolean authoritative, boolean mapDataPresent, boolean probe,
-                                  boolean smr, boolean pitr, boolean smrInvoked) {
+                                  List<LispAfiAddress> itrRlocs,
+                                  List<LispEidRecord> eidRecords,
+                                  boolean authoritative, boolean mapDataPresent,
+                                  boolean probe, boolean smr, boolean pitr,
+                                  boolean smrInvoked, int replyReocrd) {
         this.nonce = nonce;
         this.sourceEid = sourceEid;
         this.itrRlocs = itrRlocs;
@@ -84,6 +88,7 @@
         this.smr = smr;
         this.pitr = pitr;
         this.smrInvoked = smrInvoked;
+        this.replyRecord = replyReocrd;
     }
 
     @Override
@@ -157,6 +162,11 @@
     }
 
     @Override
+    public int getReplyRecord() {
+        return replyRecord;
+    }
+
+    @Override
     public String toString() {
         return toStringHelper(this)
                 .add("type", getType())
@@ -169,7 +179,8 @@
                 .add("probe", probe)
                 .add("SMR", smr)
                 .add("Proxy ITR", pitr)
-                .add("SMR Invoked", smrInvoked).toString();
+                .add("SMR Invoked", smrInvoked)
+                .add("Size of reply record", replyRecord).toString();
     }
 
     @Override
@@ -188,13 +199,14 @@
                 Objects.equal(probe, that.probe) &&
                 Objects.equal(smr, that.smr) &&
                 Objects.equal(pitr, that.pitr) &&
-                Objects.equal(smrInvoked, that.smrInvoked);
+                Objects.equal(smrInvoked, that.smrInvoked) &&
+                Objects.equal(replyRecord, that.replyRecord);
     }
 
     @Override
     public int hashCode() {
         return Objects.hashCode(nonce, sourceEid, authoritative,
-                mapDataPresent, probe, smr, pitr, smrInvoked);
+                mapDataPresent, probe, smr, pitr, smrInvoked, replyRecord);
     }
 
     public static final class DefaultRequestBuilder implements RequestBuilder {
@@ -209,6 +221,7 @@
         private boolean smr;
         private boolean pitr;
         private boolean smrInvoked;
+        private int replyRecord;
 
         @Override
         public LispType getType() {
@@ -280,12 +293,18 @@
         }
 
         @Override
+        public RequestBuilder withReplyRecord(int replyRecord) {
+            this.replyRecord = replyRecord;
+            return this;
+        }
+
+        @Override
         public LispMapRequest build() {
 
             checkArgument((itrRlocs != null) && (itrRlocs.size() > 0), "Must have an ITR RLOC entry");
 
             return new DefaultLispMapRequest(nonce, sourceEid, itrRlocs, eidRecords,
-                    authoritative, mapDataPresent, probe, smr, pitr, smrInvoked);
+                    authoritative, mapDataPresent, probe, smr, pitr, smrInvoked, replyRecord);
         }
     }
 
@@ -355,6 +374,9 @@
                 eidRecords.add(new EidRecordReader().readFrom(byteBuf));
             }
 
+            // reply record -> 32 bits
+            int replyRecord = byteBuf.readInt();
+
             return new DefaultRequestBuilder()
                         .withIsAuthoritative(authoritative)
                         .withIsMapDataPresent(mapDataPresent)
@@ -366,6 +388,7 @@
                         .withSourceEid(sourceEid)
                         .withEidRecords(eidRecords)
                         .withItrRlocs(itrRlocs)
+                        .withReplyRecord(replyRecord)
                         .build();
         }
     }
@@ -460,7 +483,8 @@
                 recordWriter.writeTo(byteBuf, records.get(i));
             }
 
-            // TODO: handle Map-Reply record
+            // reply record
+            byteBuf.writeInt(message.getReplyRecord());
         }
     }
 }
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapRequest.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapRequest.java
index aeaa21c..58113c6 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapRequest.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapRequest.java
@@ -133,6 +133,13 @@
     List<LispEidRecord> getEids();
 
     /**
+     * Obtains the size of map-reply record.
+     *
+     * @return the size of map-reply record
+     */
+    int getReplyRecord();
+
+    /**
      * A builder of LISP map request message.
      */
     interface RequestBuilder extends Builder {
@@ -218,6 +225,14 @@
         RequestBuilder withEidRecords(List<LispEidRecord> records);
 
         /**
+         * Sets the size of map-reply record.
+         *
+         * @param replyRecord the size of map-reply record
+         * @return RequestBuilder object
+         */
+        RequestBuilder withReplyRecord(int replyRecord);
+
+        /**
          * Builds LISP map request message.
          *
          * @return LISP map request message
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequestTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequestTest.java
index 79e4a5c..1b88aa6 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequestTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequestTest.java
@@ -70,6 +70,7 @@
                         .withItrRlocs(rlocs1)
                         .withEidRecords(records1)
                         .withNonce(1L)
+                        .withReplyRecord(1)
                         .build();
 
         RequestBuilder builder2 = new DefaultRequestBuilder();
@@ -86,6 +87,7 @@
                         .withItrRlocs(rlocs1)
                         .withEidRecords(records2)
                         .withNonce(1L)
+                        .withReplyRecord(1)
                         .build();
 
         RequestBuilder builder3 = new DefaultRequestBuilder();
@@ -107,6 +109,7 @@
                         .withSourceEid(ipv4Eid2)
                         .withItrRlocs(rlocs2)
                         .withNonce(2L)
+                        .withReplyRecord(2)
                         .build();
     }
 
@@ -134,6 +137,7 @@
         assertThat(request.isSmrInvoked(), is(false));
         assertThat(request.getNonce(), is(1L));
         assertThat(request.getRecordCount(), is(2));
+        assertThat(request.getReplyRecord(), is(1));
     }
 
     @Test