blob: 7c1e1b1efbe8a61f3b0c305735e93d40f6735b75 [file] [log] [blame]
Jian Li451175e2016-07-19 23:22:20 +09001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.lisp.msg.protocols;
17
Jian Li20850d32016-08-04 02:15:57 +090018import com.google.common.base.Objects;
Jian Lif59c0ad2016-08-02 18:11:30 +090019import com.google.common.collect.ImmutableList;
20import com.google.common.collect.Lists;
Jian Li451175e2016-07-19 23:22:20 +090021import io.netty.buffer.ByteBuf;
Jian Li47671902016-08-11 01:18:18 +090022import org.onlab.util.ByteOperator;
Jian Li5e505c62016-12-05 02:44:24 +090023import org.onosproject.lisp.msg.protocols.LispEidRecord.EidRecordReader;
24import org.onosproject.lisp.msg.types.LispAfiAddress;
Jian Li26069e22016-08-10 22:00:52 +090025import org.onosproject.lisp.msg.exceptions.LispParseError;
Jian Lia7b394d2016-08-21 23:11:46 +090026import org.onosproject.lisp.msg.exceptions.LispReaderException;
Jian Liedc5db12016-08-23 17:30:19 +090027import org.onosproject.lisp.msg.exceptions.LispWriterException;
Jian Li5e505c62016-12-05 02:44:24 +090028import org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressReader;
29import org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressWriter;
Jian Li719b3bf2016-07-22 00:38:29 +090030
31import java.util.List;
Jian Li451175e2016-07-19 23:22:20 +090032
Jian Li20850d32016-08-04 02:15:57 +090033import static com.google.common.base.MoreObjects.toStringHelper;
Jian Lie4ba2a42016-08-29 20:24:15 +090034import static com.google.common.base.Preconditions.checkArgument;
Jian Liedc5db12016-08-23 17:30:19 +090035import static org.onosproject.lisp.msg.protocols.LispEidRecord.EidRecordWriter;
Jian Li20850d32016-08-04 02:15:57 +090036
Jian Li451175e2016-07-19 23:22:20 +090037/**
38 * Default LISP map request message class.
39 */
Jian Liafe2d3f2016-11-01 02:49:07 +090040public final class DefaultLispMapRequest extends AbstractLispMessage
41 implements LispMapRequest {
Jian Lif59c0ad2016-08-02 18:11:30 +090042
43 private final long nonce;
Jian Lif59c0ad2016-08-02 18:11:30 +090044 private final LispAfiAddress sourceEid;
45 private final List<LispAfiAddress> itrRlocs;
46 private final List<LispEidRecord> eidRecords;
47 private final boolean authoritative;
48 private final boolean mapDataPresent;
49 private final boolean probe;
50 private final boolean smr;
51 private final boolean pitr;
52 private final boolean smrInvoked;
Jian Li3e1bac22016-12-06 02:08:12 +090053 private final int replyRecord;
Jian Lif59c0ad2016-08-02 18:11:30 +090054
Yoonseon Hanca814bf2016-09-12 11:37:48 -070055 static final RequestWriter WRITER;
56 static {
57 WRITER = new RequestWriter();
58 }
59
Jian Lif59c0ad2016-08-02 18:11:30 +090060 /**
61 * A private constructor that protects object instantiation from external.
62 *
63 * @param nonce nonce
Jian Lif59c0ad2016-08-02 18:11:30 +090064 * @param sourceEid source EID address
65 * @param itrRlocs a collection of ITR RLOCs
66 * @param eidRecords a collection of EID records
67 * @param authoritative authoritative flag
68 * @param mapDataPresent map data present flag
69 * @param probe probe flag
70 * @param smr smr flag
71 * @param pitr pitr flag
72 * @param smrInvoked smrInvoked flag
Jian Li3e1bac22016-12-06 02:08:12 +090073 * @param replyReocrd size of map-reply record
Jian Lif59c0ad2016-08-02 18:11:30 +090074 */
Jian Li42b3e432016-08-31 01:05:20 +090075 private DefaultLispMapRequest(long nonce, LispAfiAddress sourceEid,
Jian Li3e1bac22016-12-06 02:08:12 +090076 List<LispAfiAddress> itrRlocs,
77 List<LispEidRecord> eidRecords,
78 boolean authoritative, boolean mapDataPresent,
79 boolean probe, boolean smr, boolean pitr,
80 boolean smrInvoked, int replyReocrd) {
Jian Lif59c0ad2016-08-02 18:11:30 +090081 this.nonce = nonce;
Jian Lif59c0ad2016-08-02 18:11:30 +090082 this.sourceEid = sourceEid;
83 this.itrRlocs = itrRlocs;
84 this.eidRecords = eidRecords;
85 this.authoritative = authoritative;
86 this.mapDataPresent = mapDataPresent;
87 this.probe = probe;
88 this.smr = smr;
89 this.pitr = pitr;
90 this.smrInvoked = smrInvoked;
Jian Li3e1bac22016-12-06 02:08:12 +090091 this.replyRecord = replyReocrd;
Jian Lif59c0ad2016-08-02 18:11:30 +090092 }
93
Jian Li451175e2016-07-19 23:22:20 +090094 @Override
95 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +090096 return LispType.LISP_MAP_REQUEST;
Jian Li451175e2016-07-19 23:22:20 +090097 }
98
99 @Override
Yoonseon Hanca814bf2016-09-12 11:37:48 -0700100 public void writeTo(ByteBuf byteBuf) throws LispWriterException {
101 WRITER.writeTo(byteBuf, this);
Jian Li451175e2016-07-19 23:22:20 +0900102 }
103
104 @Override
105 public Builder createBuilder() {
Jian Li525fded2016-08-04 01:15:33 +0900106 return new DefaultRequestBuilder();
Jian Li451175e2016-07-19 23:22:20 +0900107 }
Jian Li719b3bf2016-07-22 00:38:29 +0900108
109 @Override
110 public boolean isAuthoritative() {
Jian Liedc5db12016-08-23 17:30:19 +0900111 return authoritative;
Jian Lif59c0ad2016-08-02 18:11:30 +0900112 }
113
114 @Override
115 public boolean isMapDataPresent() {
Jian Liedc5db12016-08-23 17:30:19 +0900116 return mapDataPresent;
Jian Li719b3bf2016-07-22 00:38:29 +0900117 }
118
119 @Override
120 public boolean isProbe() {
Jian Liedc5db12016-08-23 17:30:19 +0900121 return probe;
Jian Li719b3bf2016-07-22 00:38:29 +0900122 }
123
124 @Override
125 public boolean isSmr() {
Jian Liedc5db12016-08-23 17:30:19 +0900126 return smr;
Jian Li719b3bf2016-07-22 00:38:29 +0900127 }
128
129 @Override
130 public boolean isPitr() {
Jian Liedc5db12016-08-23 17:30:19 +0900131 return pitr;
Jian Li719b3bf2016-07-22 00:38:29 +0900132 }
133
134 @Override
135 public boolean isSmrInvoked() {
Jian Liedc5db12016-08-23 17:30:19 +0900136 return smrInvoked;
Jian Li719b3bf2016-07-22 00:38:29 +0900137 }
138
139 @Override
Jian Li42b3e432016-08-31 01:05:20 +0900140 public int getRecordCount() {
141 return eidRecords.size();
Jian Li719b3bf2016-07-22 00:38:29 +0900142 }
143
144 @Override
145 public long getNonce() {
Jian Liedc5db12016-08-23 17:30:19 +0900146 return nonce;
Jian Li719b3bf2016-07-22 00:38:29 +0900147 }
148
149 @Override
150 public LispAfiAddress getSourceEid() {
Jian Liedc5db12016-08-23 17:30:19 +0900151 return sourceEid;
Jian Li719b3bf2016-07-22 00:38:29 +0900152 }
153
154 @Override
155 public List<LispAfiAddress> getItrRlocs() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900156 return ImmutableList.copyOf(itrRlocs);
Jian Li719b3bf2016-07-22 00:38:29 +0900157 }
158
159 @Override
Jian Li10a09062016-07-26 23:58:50 +0900160 public List<LispEidRecord> getEids() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900161 return ImmutableList.copyOf(eidRecords);
Jian Li719b3bf2016-07-22 00:38:29 +0900162 }
163
Jian Li20850d32016-08-04 02:15:57 +0900164 @Override
Jian Li3e1bac22016-12-06 02:08:12 +0900165 public int getReplyRecord() {
166 return replyRecord;
167 }
168
169 @Override
Jian Li20850d32016-08-04 02:15:57 +0900170 public String toString() {
171 return toStringHelper(this)
172 .add("type", getType())
173 .add("nonce", nonce)
Jian Li20850d32016-08-04 02:15:57 +0900174 .add("source EID", sourceEid)
175 .add("ITR rlocs", itrRlocs)
176 .add("EID records", eidRecords)
177 .add("authoritative", authoritative)
178 .add("mapDataPresent", mapDataPresent)
179 .add("probe", probe)
180 .add("SMR", smr)
181 .add("Proxy ITR", pitr)
Jian Li3e1bac22016-12-06 02:08:12 +0900182 .add("SMR Invoked", smrInvoked)
183 .add("Size of reply record", replyRecord).toString();
Jian Li20850d32016-08-04 02:15:57 +0900184 }
185
186 @Override
187 public boolean equals(Object o) {
188 if (this == o) {
189 return true;
190 }
191 if (o == null || getClass() != o.getClass()) {
192 return false;
193 }
194 DefaultLispMapRequest that = (DefaultLispMapRequest) o;
195 return Objects.equal(nonce, that.nonce) &&
Jian Li20850d32016-08-04 02:15:57 +0900196 Objects.equal(sourceEid, that.sourceEid) &&
Jian Li20850d32016-08-04 02:15:57 +0900197 Objects.equal(authoritative, that.authoritative) &&
198 Objects.equal(mapDataPresent, that.mapDataPresent) &&
199 Objects.equal(probe, that.probe) &&
200 Objects.equal(smr, that.smr) &&
201 Objects.equal(pitr, that.pitr) &&
Jian Li3e1bac22016-12-06 02:08:12 +0900202 Objects.equal(smrInvoked, that.smrInvoked) &&
203 Objects.equal(replyRecord, that.replyRecord);
Jian Li20850d32016-08-04 02:15:57 +0900204 }
205
206 @Override
207 public int hashCode() {
Jian Li42b3e432016-08-31 01:05:20 +0900208 return Objects.hashCode(nonce, sourceEid, authoritative,
Jian Li3e1bac22016-12-06 02:08:12 +0900209 mapDataPresent, probe, smr, pitr, smrInvoked, replyRecord);
Jian Li20850d32016-08-04 02:15:57 +0900210 }
211
Jian Li719b3bf2016-07-22 00:38:29 +0900212 public static final class DefaultRequestBuilder implements RequestBuilder {
213
Jian Lif59c0ad2016-08-02 18:11:30 +0900214 private long nonce;
Jian Lif59c0ad2016-08-02 18:11:30 +0900215 private LispAfiAddress sourceEid;
216 private List<LispAfiAddress> itrRlocs = Lists.newArrayList();
217 private List<LispEidRecord> eidRecords = Lists.newArrayList();
218 private boolean authoritative;
219 private boolean mapDataPresent;
220 private boolean probe;
221 private boolean smr;
222 private boolean pitr;
223 private boolean smrInvoked;
Jian Li3e1bac22016-12-06 02:08:12 +0900224 private int replyRecord;
Jian Li719b3bf2016-07-22 00:38:29 +0900225
226 @Override
227 public LispType getType() {
Jian Lif59c0ad2016-08-02 18:11:30 +0900228 return LispType.LISP_MAP_REQUEST;
Jian Li719b3bf2016-07-22 00:38:29 +0900229 }
230
231 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900232 public RequestBuilder withIsAuthoritative(boolean authoritative) {
233 this.authoritative = authoritative;
234 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900235 }
236
237 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900238 public RequestBuilder withIsProbe(boolean probe) {
239 this.probe = probe;
240 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900241 }
242
243 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900244 public RequestBuilder withIsMapDataPresent(boolean mapDataPresent) {
245 this.mapDataPresent = mapDataPresent;
246 return this;
247 }
248
Jian Lif59c0ad2016-08-02 18:11:30 +0900249 @Override
250 public RequestBuilder withIsSmr(boolean smr) {
251 this.smr = smr;
252 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900253 }
254
255 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900256 public RequestBuilder withIsPitr(boolean pitr) {
257 this.pitr = pitr;
258 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900259 }
260
261 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900262 public RequestBuilder withIsSmrInvoked(boolean smrInvoked) {
263 this.smrInvoked = smrInvoked;
264 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900265 }
266
267 @Override
Jian Li719b3bf2016-07-22 00:38:29 +0900268 public RequestBuilder withNonce(long nonce) {
Jian Lif59c0ad2016-08-02 18:11:30 +0900269 this.nonce = nonce;
270 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900271 }
272
273 @Override
Jian Lif59c0ad2016-08-02 18:11:30 +0900274 public RequestBuilder withSourceEid(LispAfiAddress sourceEid) {
275 this.sourceEid = sourceEid;
276 return this;
277 }
278
279 @Override
Jian Li47671902016-08-11 01:18:18 +0900280 public RequestBuilder withItrRlocs(List<LispAfiAddress> itrRlocs) {
Jian Lie4ba2a42016-08-29 20:24:15 +0900281 if (itrRlocs != null) {
282 this.itrRlocs = ImmutableList.copyOf(itrRlocs);
Jian Lie4ba2a42016-08-29 20:24:15 +0900283 }
Jian Lif59c0ad2016-08-02 18:11:30 +0900284 return this;
Jian Li719b3bf2016-07-22 00:38:29 +0900285 }
286
287 @Override
Jian Li47671902016-08-11 01:18:18 +0900288 public RequestBuilder withEidRecords(List<LispEidRecord> records) {
Jian Lie4ba2a42016-08-29 20:24:15 +0900289 if (records != null) {
290 this.eidRecords = ImmutableList.copyOf(records);
Jian Lie4ba2a42016-08-29 20:24:15 +0900291 }
Jian Lif59c0ad2016-08-02 18:11:30 +0900292 return this;
293 }
294
295 @Override
Jian Li3e1bac22016-12-06 02:08:12 +0900296 public RequestBuilder withReplyRecord(int replyRecord) {
297 this.replyRecord = replyRecord;
298 return this;
299 }
300
301 @Override
Jian Li525fded2016-08-04 01:15:33 +0900302 public LispMapRequest build() {
Jian Lie4ba2a42016-08-29 20:24:15 +0900303
Jian Li347c51e2017-01-18 14:08:50 -0800304 checkArgument((itrRlocs != null) && (!itrRlocs.isEmpty()), "Must have an ITR RLOC entry");
Jian Lie4ba2a42016-08-29 20:24:15 +0900305
Jian Li42b3e432016-08-31 01:05:20 +0900306 return new DefaultLispMapRequest(nonce, sourceEid, itrRlocs, eidRecords,
Jian Li3e1bac22016-12-06 02:08:12 +0900307 authoritative, mapDataPresent, probe, smr, pitr, smrInvoked, replyRecord);
Jian Li719b3bf2016-07-22 00:38:29 +0900308 }
309 }
Jian Li26069e22016-08-10 22:00:52 +0900310
311 /**
Jian Liedc5db12016-08-23 17:30:19 +0900312 * A LISP message reader for MapRequest message.
Jian Li26069e22016-08-10 22:00:52 +0900313 */
Jian Liedc5db12016-08-23 17:30:19 +0900314 public static final class RequestReader implements LispMessageReader<LispMapRequest> {
Jian Li26069e22016-08-10 22:00:52 +0900315
Jian Li47671902016-08-11 01:18:18 +0900316 private static final int AUTHORITATIVE_INDEX = 3;
317 private static final int MAP_DATA_PRESENT_INDEX = 2;
318 private static final int PROBE_INDEX = 1;
319 private static final int SMR_INDEX = 0;
320 private static final int PITR_INDEX = 7;
321 private static final int SMR_INVOKED_INDEX = 6;
322
Jian Li26069e22016-08-10 22:00:52 +0900323 @Override
Jian Lia7b394d2016-08-21 23:11:46 +0900324 public LispMapRequest readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException {
Jian Li47671902016-08-11 01:18:18 +0900325
326 if (byteBuf.readerIndex() != 0) {
327 return null;
328 }
329
330 byte typeWithFlags = byteBuf.readByte();
331
332 // authoritative -> 1 bit
333 boolean authoritative = ByteOperator.getBit(typeWithFlags, AUTHORITATIVE_INDEX);
334
335 // mapDataPresent -> 1 bit
336 boolean mapDataPresent = ByteOperator.getBit(typeWithFlags, MAP_DATA_PRESENT_INDEX);
337
338 // probe -> 1 bit
339 boolean probe = ByteOperator.getBit(typeWithFlags, PROBE_INDEX);
340
341 // smr -> 1 bit
342 boolean smr = ByteOperator.getBit(typeWithFlags, SMR_INDEX);
343
344 byte reservedWithFlags = byteBuf.readByte();
345
346 // pitr -> 1 bit
347 boolean pitr = ByteOperator.getBit(reservedWithFlags, PITR_INDEX);
348
349 // smrInvoked -> 1 bit
350 boolean smrInvoked = ByteOperator.getBit(reservedWithFlags, SMR_INVOKED_INDEX);
351
352 // let's skip reserved field, only obtains ITR counter value
353 // assume that first 3 bits are all set as 0,
354 // remain 5 bits represent Itr Rloc Counter (IRC)
Jian Lie4ba2a42016-08-29 20:24:15 +0900355 int irc = byteBuf.readUnsignedByte();
Jian Li47671902016-08-11 01:18:18 +0900356
357 // record count -> 8 bits
Jian Lie4ba2a42016-08-29 20:24:15 +0900358 int recordCount = byteBuf.readUnsignedByte();
Jian Li47671902016-08-11 01:18:18 +0900359
360 // nonce -> 64 bits
361 long nonce = byteBuf.readLong();
362
Jian Li5e505c62016-12-05 02:44:24 +0900363 LispAfiAddress sourceEid = new AfiAddressReader().readFrom(byteBuf);
Jian Li47671902016-08-11 01:18:18 +0900364
Jian Lia7b394d2016-08-21 23:11:46 +0900365 // deserialize a collection of RLOC addresses
366 List<LispAfiAddress> itrRlocs = Lists.newArrayList();
Jian Lif11594a2016-10-31 18:16:02 +0900367 for (int i = 0; i < irc + 1; i++) {
Jian Li5e505c62016-12-05 02:44:24 +0900368 itrRlocs.add(new AfiAddressReader().readFrom(byteBuf));
Jian Lia7b394d2016-08-21 23:11:46 +0900369 }
Jian Li47671902016-08-11 01:18:18 +0900370
Jian Lia7b394d2016-08-21 23:11:46 +0900371 // deserialize a collection of EID records
372 List<LispEidRecord> eidRecords = Lists.newArrayList();
373 for (int i = 0; i < recordCount; i++) {
Jian Li5e505c62016-12-05 02:44:24 +0900374 eidRecords.add(new EidRecordReader().readFrom(byteBuf));
Jian Lia7b394d2016-08-21 23:11:46 +0900375 }
Jian Li47671902016-08-11 01:18:18 +0900376
Jian Li3e1bac22016-12-06 02:08:12 +0900377 // reply record -> 32 bits
Jian Liaf729412017-04-07 00:47:56 +0900378 int replyRecord = 0;
379
380 // only obtains the reply record when map data present bit is set
381 if (mapDataPresent) {
382 replyRecord = byteBuf.readInt();
383 }
Jian Li3e1bac22016-12-06 02:08:12 +0900384
Jian Li47671902016-08-11 01:18:18 +0900385 return new DefaultRequestBuilder()
386 .withIsAuthoritative(authoritative)
387 .withIsMapDataPresent(mapDataPresent)
388 .withIsProbe(probe)
389 .withIsSmr(smr)
390 .withIsPitr(pitr)
391 .withIsSmrInvoked(smrInvoked)
392 .withNonce(nonce)
Jian Lia7b394d2016-08-21 23:11:46 +0900393 .withSourceEid(sourceEid)
394 .withEidRecords(eidRecords)
395 .withItrRlocs(itrRlocs)
Jian Li3e1bac22016-12-06 02:08:12 +0900396 .withReplyRecord(replyRecord)
Jian Li47671902016-08-11 01:18:18 +0900397 .build();
Jian Li26069e22016-08-10 22:00:52 +0900398 }
399 }
Jian Liedc5db12016-08-23 17:30:19 +0900400
401 /**
402 * A LISP message writer for MapRequest message.
403 */
404 public static final class RequestWriter implements LispMessageWriter<LispMapRequest> {
405
Jian Liedc5db12016-08-23 17:30:19 +0900406 private static final int REQUEST_SHIFT_BIT = 4;
407
408 private static final int AUTHORITATIVE_SHIFT_BIT = 3;
409 private static final int MAP_DATA_PRESENT_SHIFT_BIT = 2;
410 private static final int PROBE_SHIFT_BIT = 1;
411
412 private static final int PITR_SHIFT_BIT = 7;
413 private static final int SMR_INVOKED_SHIFT_BIT = 6;
414
415 private static final int ENABLE_BIT = 1;
416 private static final int DISABLE_BIT = 0;
417
Jian Liedc5db12016-08-23 17:30:19 +0900418 @Override
419 public void writeTo(ByteBuf byteBuf, LispMapRequest message) throws LispWriterException {
420
421 // specify LISP message type
Jian Licbc57e32016-09-14 09:06:54 +0900422 byte msgType = (byte) (LispType.LISP_MAP_REQUEST.getTypeCode() << REQUEST_SHIFT_BIT);
Jian Liedc5db12016-08-23 17:30:19 +0900423
424 // authoritative flag
425 byte authoritative = DISABLE_BIT;
426 if (message.isAuthoritative()) {
427 authoritative = (byte) (ENABLE_BIT << AUTHORITATIVE_SHIFT_BIT);
428 }
429
430 // map data present flag
431 byte mapDataPresent = DISABLE_BIT;
432 if (message.isMapDataPresent()) {
433 mapDataPresent = (byte) (ENABLE_BIT << MAP_DATA_PRESENT_SHIFT_BIT);
434 }
435
436 // probe flag
437 byte probe = DISABLE_BIT;
438 if (message.isProbe()) {
439 probe = (byte) (ENABLE_BIT << PROBE_SHIFT_BIT);
440 }
441
442 // SMR flag
443 byte smr = DISABLE_BIT;
444 if (message.isSmr()) {
445 smr = (byte) ENABLE_BIT;
446 }
447
448 byteBuf.writeByte((byte) (msgType + authoritative + mapDataPresent + probe + smr));
449
450 // PITR flag bit
451 byte pitr = DISABLE_BIT;
452 if (message.isPitr()) {
453 pitr = (byte) (ENABLE_BIT << PITR_SHIFT_BIT);
454 }
455
456 // SMR invoked flag bit
457 byte smrInvoked = DISABLE_BIT;
458 if (message.isSmrInvoked()) {
459 smrInvoked = (byte) (ENABLE_BIT << SMR_INVOKED_SHIFT_BIT);
460 }
461
462 byteBuf.writeByte((byte) (pitr + smrInvoked));
463
Jian Lie4ba2a42016-08-29 20:24:15 +0900464 // ITR Rloc count
Jian Lif11594a2016-10-31 18:16:02 +0900465 byteBuf.writeByte((byte) message.getItrRlocs().size() - 1);
Jian Liedc5db12016-08-23 17:30:19 +0900466
467 // record count
Jian Li42b3e432016-08-31 01:05:20 +0900468 byteBuf.writeByte(message.getEids().size());
Jian Liedc5db12016-08-23 17:30:19 +0900469
470 // nonce
471 byteBuf.writeLong(message.getNonce());
472
473 // Source EID AFI with Source EID address
474 AfiAddressWriter afiAddressWriter = new AfiAddressWriter();
475 afiAddressWriter.writeTo(byteBuf, message.getSourceEid());
476
477 // ITR RLOCs
478 List<LispAfiAddress> rlocs = message.getItrRlocs();
Jian Li3282a342017-05-23 14:30:15 +0900479 for (LispAfiAddress rloc : rlocs) {
480 afiAddressWriter.writeTo(byteBuf, rloc);
Jian Liedc5db12016-08-23 17:30:19 +0900481 }
482
483 // EID records
484 EidRecordWriter recordWriter = new EidRecordWriter();
485 List<LispEidRecord> records = message.getEids();
486
Jian Li3282a342017-05-23 14:30:15 +0900487 for (LispEidRecord record : records) {
488 recordWriter.writeTo(byteBuf, record);
Jian Liedc5db12016-08-23 17:30:19 +0900489 }
490
Jian Li3e1bac22016-12-06 02:08:12 +0900491 // reply record
492 byteBuf.writeInt(message.getReplyRecord());
Jian Liedc5db12016-08-23 17:30:19 +0900493 }
494 }
Jian Li451175e2016-07-19 23:22:20 +0900495}