Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.lisp.msg.protocols; |
| 17 | |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 18 | import com.google.common.base.Objects; |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableList; |
| 20 | import com.google.common.collect.Lists; |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 21 | import io.netty.buffer.ByteBuf; |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 22 | import org.onlab.util.ByteOperator; |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 23 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
Jian Li | a7b394d | 2016-08-21 23:11:46 +0900 | [diff] [blame] | 24 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 25 | import org.onosproject.lisp.msg.exceptions.LispWriterException; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 26 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
| 27 | |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 28 | import java.util.List; |
| 29 | |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 30 | import static com.google.common.base.MoreObjects.toStringHelper; |
Jian Li | d4e6370 | 2016-08-30 18:29:20 +0900 | [diff] [blame] | 31 | import static com.google.common.base.Preconditions.checkNotNull; |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 32 | import static org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressWriter; |
| 33 | import static org.onosproject.lisp.msg.protocols.DefaultLispLocatorRecord.LocatorRecordWriter; |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 34 | |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 35 | /** |
| 36 | * Default implementation of LispMapRecord. |
| 37 | */ |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 38 | public final class DefaultLispMapRecord implements LispMapRecord { |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 39 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 40 | private final int recordTtl; |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 41 | private final byte maskLength; |
| 42 | private final LispMapReplyAction action; |
| 43 | private final boolean authoritative; |
| 44 | private final short mapVersionNumber; |
| 45 | private final LispAfiAddress eidPrefixAfi; |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 46 | private final List<LispLocatorRecord> locatorRecords; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 47 | |
Yoonseon Han | ca814bf | 2016-09-12 11:37:48 -0700 | [diff] [blame] | 48 | static final MapRecordWriter WRITER; |
| 49 | static { |
| 50 | WRITER = new MapRecordWriter(); |
| 51 | } |
| 52 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 53 | /** |
| 54 | * A private constructor that protects object instantiation from external. |
| 55 | * |
| 56 | * @param recordTtl record time-to-live value |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 57 | * @param maskLength mask length |
| 58 | * @param action lisp map reply action |
| 59 | * @param authoritative authoritative flag |
| 60 | * @param mapVersionNumber map version number |
| 61 | * @param eidPrefixAfi EID prefix AFI address |
| 62 | */ |
Jian Li | 42b3e43 | 2016-08-31 01:05:20 +0900 | [diff] [blame] | 63 | private DefaultLispMapRecord(int recordTtl, byte maskLength, |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 64 | LispMapReplyAction action, boolean authoritative, |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 65 | short mapVersionNumber, LispAfiAddress eidPrefixAfi, |
| 66 | List<LispLocatorRecord> locatorRecords) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 67 | this.recordTtl = recordTtl; |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 68 | this.maskLength = maskLength; |
| 69 | this.action = action; |
| 70 | this.authoritative = authoritative; |
| 71 | this.mapVersionNumber = mapVersionNumber; |
| 72 | this.eidPrefixAfi = eidPrefixAfi; |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 73 | this.locatorRecords = locatorRecords; |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 77 | public int getRecordTtl() { |
| 78 | return recordTtl; |
| 79 | } |
| 80 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 81 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 82 | public int getLocatorCount() { |
Jian Li | 42b3e43 | 2016-08-31 01:05:20 +0900 | [diff] [blame] | 83 | return locatorRecords.size(); |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 84 | } |
| 85 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 86 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 87 | public byte getMaskLength() { |
| 88 | return maskLength; |
| 89 | } |
| 90 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 91 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 92 | public LispMapReplyAction getAction() { |
| 93 | return action; |
| 94 | } |
| 95 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 96 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 97 | public boolean isAuthoritative() { |
| 98 | return authoritative; |
| 99 | } |
| 100 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 101 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 102 | public short getMapVersionNumber() { |
| 103 | return mapVersionNumber; |
| 104 | } |
| 105 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 106 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 107 | public LispAfiAddress getEidPrefixAfi() { |
| 108 | return eidPrefixAfi; |
| 109 | } |
| 110 | |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 111 | @Override |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 112 | public List<LispLocatorRecord> getLocators() { |
| 113 | return ImmutableList.copyOf(locatorRecords); |
| 114 | } |
| 115 | |
| 116 | @Override |
Yoonseon Han | ca814bf | 2016-09-12 11:37:48 -0700 | [diff] [blame] | 117 | public void writeTo(ByteBuf byteBuf) throws LispWriterException { |
| 118 | WRITER.writeTo(byteBuf, this); |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 122 | public String toString() { |
| 123 | return toStringHelper(this) |
| 124 | .add("record TTL", recordTtl) |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 125 | .add("maskLength", maskLength) |
| 126 | .add("action", action) |
| 127 | .add("authoritative", authoritative) |
| 128 | .add("mapVersionNumber", mapVersionNumber) |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 129 | .add("EID prefix AFI address", eidPrefixAfi) |
| 130 | .add("locator records", locatorRecords).toString(); |
| 131 | |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public boolean equals(Object o) { |
| 136 | if (this == o) { |
| 137 | return true; |
| 138 | } |
| 139 | if (o == null || getClass() != o.getClass()) { |
| 140 | return false; |
| 141 | } |
| 142 | DefaultLispMapRecord that = (DefaultLispMapRecord) o; |
| 143 | return Objects.equal(recordTtl, that.recordTtl) && |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 144 | Objects.equal(maskLength, that.maskLength) && |
| 145 | Objects.equal(action, that.action) && |
| 146 | Objects.equal(authoritative, that.authoritative) && |
| 147 | Objects.equal(mapVersionNumber, that.mapVersionNumber) && |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 148 | Objects.equal(eidPrefixAfi, that.eidPrefixAfi) && |
| 149 | Objects.equal(locatorRecords, that.locatorRecords); |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public int hashCode() { |
Jian Li | 42b3e43 | 2016-08-31 01:05:20 +0900 | [diff] [blame] | 154 | return Objects.hashCode(recordTtl, maskLength, action, |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 155 | authoritative, mapVersionNumber, eidPrefixAfi, locatorRecords); |
Jian Li | 18f3bce | 2016-08-04 17:36:41 +0900 | [diff] [blame] | 156 | } |
| 157 | |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 158 | public static final class DefaultMapRecordBuilder implements MapRecordBuilder { |
| 159 | |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 160 | private int recordTtl; |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 161 | private byte maskLength; |
| 162 | private LispMapReplyAction action; |
| 163 | private boolean authoritative; |
| 164 | private short mapVersionNumber; |
| 165 | private LispAfiAddress eidPrefixAfi; |
Jian Li | d4e6370 | 2016-08-30 18:29:20 +0900 | [diff] [blame] | 166 | private List<LispLocatorRecord> locatorRecords = Lists.newArrayList(); |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 167 | |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 168 | @Override |
| 169 | public MapRecordBuilder withRecordTtl(int recordTtl) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 170 | this.recordTtl = recordTtl; |
| 171 | return this; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | @Override |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 175 | public MapRecordBuilder withMaskLength(byte maskLength) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 176 | this.maskLength = maskLength; |
| 177 | return this; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public MapRecordBuilder withAction(LispMapReplyAction action) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 182 | this.action = action; |
| 183 | return this; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public MapRecordBuilder withAuthoritative(boolean authoritative) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 188 | this.authoritative = authoritative; |
| 189 | return this; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | @Override |
| 193 | public MapRecordBuilder withMapVersionNumber(short mapVersionNumber) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 194 | this.mapVersionNumber = mapVersionNumber; |
| 195 | return this; |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | @Override |
| 199 | public MapRecordBuilder withEidPrefixAfi(LispAfiAddress prefix) { |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 200 | this.eidPrefixAfi = prefix; |
| 201 | return this; |
| 202 | } |
| 203 | |
| 204 | @Override |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 205 | public MapRecordBuilder withLocators(List<LispLocatorRecord> records) { |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 206 | if (records != null) { |
| 207 | this.locatorRecords = ImmutableList.copyOf(records); |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 208 | } |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 209 | return this; |
| 210 | } |
| 211 | |
| 212 | @Override |
Jian Li | 631e62a | 2016-08-03 22:42:00 +0900 | [diff] [blame] | 213 | public LispMapRecord build() { |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 214 | |
Jian Li | d4e6370 | 2016-08-30 18:29:20 +0900 | [diff] [blame] | 215 | checkNotNull(eidPrefixAfi, "Must specify an EID prefix"); |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 216 | |
Jian Li | 42b3e43 | 2016-08-31 01:05:20 +0900 | [diff] [blame] | 217 | return new DefaultLispMapRecord(recordTtl, maskLength, action, |
| 218 | authoritative, mapVersionNumber, eidPrefixAfi, locatorRecords); |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 219 | } |
| 220 | } |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 221 | |
| 222 | /** |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 223 | * A LISP message reader for MapRecord portion. |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 224 | */ |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 225 | public static final class MapRecordReader implements LispMessageReader<LispMapRecord> { |
| 226 | |
| 227 | private static final int AUTHORITATIVE_INDEX = 4; |
| 228 | private static final int RESERVED_SKIP_LENGTH = 1; |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 229 | |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 230 | private static final int REPLY_ACTION_SHIFT_BIT = 5; |
| 231 | |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 232 | @Override |
Jian Li | a7b394d | 2016-08-21 23:11:46 +0900 | [diff] [blame] | 233 | public LispMapRecord readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 234 | |
| 235 | // Record TTL -> 32 bits |
| 236 | int recordTtl = byteBuf.readInt(); |
| 237 | |
| 238 | // Locator count -> 8 bits |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 239 | int locatorCount = byteBuf.readUnsignedByte(); |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 240 | |
| 241 | // EID mask length -> 8 bits |
| 242 | byte maskLength = (byte) byteBuf.readUnsignedByte(); |
| 243 | |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 244 | byte actionWithFlag = (byte) byteBuf.readUnsignedByte(); |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 245 | |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 246 | // action -> 3 bit |
| 247 | int actionByte = actionWithFlag >> REPLY_ACTION_SHIFT_BIT; |
| 248 | LispMapReplyAction action = LispMapReplyAction.valueOf(actionByte); |
| 249 | if (action == null) { |
| 250 | action = LispMapReplyAction.NoAction; |
| 251 | } |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 252 | |
| 253 | // authoritative flag -> 1 bit |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 254 | boolean authoritative = ByteOperator.getBit((byte) (actionWithFlag >> AUTHORITATIVE_INDEX), 0); |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 255 | |
| 256 | // let's skip the reserved field |
| 257 | byteBuf.skipBytes(RESERVED_SKIP_LENGTH); |
| 258 | |
| 259 | // Map version number -> 12 bits, we treat Rsvd field is all zero |
| 260 | short mapVersionNumber = (short) byteBuf.readUnsignedShort(); |
| 261 | |
Jian Li | a7b394d | 2016-08-21 23:11:46 +0900 | [diff] [blame] | 262 | LispAfiAddress eidPrefixAfi = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 263 | |
| 264 | List<LispLocatorRecord> locators = Lists.newArrayList(); |
| 265 | for (int i = 0; i < locatorCount; i++) { |
| 266 | locators.add(new DefaultLispLocatorRecord.LocatorRecordReader().readFrom(byteBuf)); |
| 267 | } |
| 268 | |
| 269 | return new DefaultMapRecordBuilder() |
| 270 | .withRecordTtl(recordTtl) |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 271 | .withMaskLength(maskLength) |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 272 | .withAction(action) |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 273 | .withAuthoritative(authoritative) |
| 274 | .withMapVersionNumber(mapVersionNumber) |
| 275 | .withLocators(locators) |
Jian Li | a7b394d | 2016-08-21 23:11:46 +0900 | [diff] [blame] | 276 | .withEidPrefixAfi(eidPrefixAfi) |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 277 | .build(); |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 278 | } |
| 279 | } |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 280 | |
| 281 | /** |
| 282 | * A LISP message writer for MapRecord portion. |
| 283 | */ |
| 284 | public static final class MapRecordWriter implements LispMessageWriter<LispMapRecord> { |
| 285 | |
| 286 | private static final int REPLY_ACTION_SHIFT_BIT = 5; |
| 287 | private static final int AUTHORITATIVE_FLAG_SHIFT_BIT = 4; |
| 288 | |
| 289 | private static final int ENABLE_BIT = 1; |
| 290 | private static final int DISABLE_BIT = 0; |
| 291 | |
| 292 | @Override |
| 293 | public void writeTo(ByteBuf byteBuf, LispMapRecord message) throws LispWriterException { |
| 294 | |
| 295 | // record TTL |
| 296 | byteBuf.writeInt(message.getRecordTtl()); |
| 297 | |
| 298 | // locator count |
Jian Li | 42b3e43 | 2016-08-31 01:05:20 +0900 | [diff] [blame] | 299 | byteBuf.writeByte((byte) message.getLocators().size()); |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 300 | |
| 301 | // EID mask length |
| 302 | byteBuf.writeByte(message.getMaskLength()); |
| 303 | |
| 304 | // reply action |
| 305 | byte action = (byte) (message.getAction().getAction() << REPLY_ACTION_SHIFT_BIT); |
| 306 | |
| 307 | // authoritative bit |
| 308 | byte authoritative = DISABLE_BIT; |
| 309 | if (message.isAuthoritative()) { |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 310 | authoritative = ENABLE_BIT << AUTHORITATIVE_FLAG_SHIFT_BIT; |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 311 | } |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 312 | |
| 313 | byteBuf.writeByte((byte) (action + authoritative)); |
| 314 | |
| 315 | // fill zero into reserved field |
| 316 | byteBuf.writeByte((short) 0); |
| 317 | |
| 318 | // map version number |
| 319 | byteBuf.writeShort(message.getMapVersionNumber()); |
| 320 | |
| 321 | // EID prefix AFI with EID prefix |
| 322 | AfiAddressWriter afiAddressWriter = new AfiAddressWriter(); |
| 323 | afiAddressWriter.writeTo(byteBuf, message.getEidPrefixAfi()); |
| 324 | |
| 325 | // serialize locator |
| 326 | LocatorRecordWriter recordWriter = new LocatorRecordWriter(); |
| 327 | List<LispLocatorRecord> locators = message.getLocators(); |
| 328 | for (int i = 0; i < locators.size(); i++) { |
| 329 | recordWriter.writeTo(byteBuf, locators.get(i)); |
| 330 | } |
| 331 | } |
| 332 | } |
Jian Li | 10a0906 | 2016-07-26 23:58:50 +0900 | [diff] [blame] | 333 | } |