Jian Li | 451175e | 2016-07-19 23:22:20 +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 | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 18 | import com.google.common.base.Objects; |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableList; |
| 20 | import com.google.common.collect.Lists; |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 21 | import io.netty.buffer.ByteBuf; |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 22 | import io.netty.buffer.Unpooled; |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 23 | import org.onlab.util.ImmutableByteSequence; |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 24 | import org.onosproject.lisp.msg.authentication.LispAuthenticationFactory; |
| 25 | import org.onosproject.lisp.msg.authentication.LispAuthenticationKeyEnum; |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 26 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
Jian Li | a7b394d | 2016-08-21 23:11:46 +0900 | [diff] [blame] | 27 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 28 | import org.onosproject.lisp.msg.exceptions.LispWriterException; |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 29 | import org.slf4j.Logger; |
| 30 | import org.slf4j.LoggerFactory; |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 31 | |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 32 | import java.util.Arrays; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 33 | import java.util.List; |
| 34 | |
Jian Li | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 35 | import static com.google.common.base.MoreObjects.toStringHelper; |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 36 | import static org.onosproject.lisp.msg.authentication.LispAuthenticationKeyEnum.valueOf; |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 37 | import static org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.MapRecordWriter; |
Jian Li | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 38 | |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 39 | /** |
| 40 | * Default LISP map notify message class. |
| 41 | */ |
Jian Li | afe2d3f | 2016-11-01 02:49:07 +0900 | [diff] [blame] | 42 | public final class DefaultLispMapNotify extends AbstractLispMessage |
| 43 | implements LispMapNotify { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 44 | |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 45 | private static final Logger log = LoggerFactory.getLogger(DefaultLispMapNotify.class); |
| 46 | |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 47 | private final long nonce; |
| 48 | private final short keyId; |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 49 | private final short authDataLength; |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 50 | private final byte[] authData; |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 51 | private final List<LispMapRecord> mapRecords; |
| 52 | |
Yoonseon Han | ca814bf | 2016-09-12 11:37:48 -0700 | [diff] [blame] | 53 | static final NotifyWriter WRITER; |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 54 | |
Yoonseon Han | ca814bf | 2016-09-12 11:37:48 -0700 | [diff] [blame] | 55 | static { |
| 56 | WRITER = new NotifyWriter(); |
| 57 | } |
| 58 | |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 59 | /** |
| 60 | * A private constructor that protects object instantiation from external. |
| 61 | * |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 62 | * @param nonce nonce |
| 63 | * @param keyId key identifier |
| 64 | * @param authData authentication data |
| 65 | * @param mapRecords a collection of map records |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 66 | */ |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 67 | private DefaultLispMapNotify(long nonce, short keyId, short authDataLength, |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 68 | byte[] authData, List<LispMapRecord> mapRecords) { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 69 | this.nonce = nonce; |
| 70 | this.keyId = keyId; |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 71 | this.authDataLength = authDataLength; |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 72 | this.authData = authData; |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 73 | this.mapRecords = mapRecords; |
| 74 | } |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 75 | |
| 76 | @Override |
| 77 | public LispType getType() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 78 | return LispType.LISP_MAP_NOTIFY; |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Override |
Yoonseon Han | ca814bf | 2016-09-12 11:37:48 -0700 | [diff] [blame] | 82 | public void writeTo(ByteBuf byteBuf) throws LispWriterException { |
| 83 | WRITER.writeTo(byteBuf, this); |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public Builder createBuilder() { |
Jian Li | 525fded | 2016-08-04 01:15:33 +0900 | [diff] [blame] | 88 | return new DefaultNotifyBuilder(); |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 89 | } |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 90 | |
| 91 | @Override |
| 92 | public long getNonce() { |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 93 | return nonce; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
Jian Li | 42b3e43 | 2016-08-31 01:05:20 +0900 | [diff] [blame] | 97 | public int getRecordCount() { |
| 98 | return mapRecords.size(); |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public short getKeyId() { |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 103 | return keyId; |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public short getAuthDataLength() { |
| 108 | return authDataLength; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | @Override |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 112 | public byte[] getAuthData() { |
| 113 | if (authData != null && authData.length != 0) { |
| 114 | return ImmutableByteSequence.copyFrom(authData).asArray(); |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 115 | } else { |
| 116 | return new byte[0]; |
| 117 | } |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | @Override |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 121 | public List<LispMapRecord> getMapRecords() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 122 | return ImmutableList.copyOf(mapRecords); |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 123 | } |
| 124 | |
Jian Li | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 125 | @Override |
| 126 | public String toString() { |
| 127 | return toStringHelper(this) |
| 128 | .add("type", getType()) |
| 129 | .add("nonce", nonce) |
Jian Li | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 130 | .add("keyId", keyId) |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 131 | .add("authentication data length", authDataLength) |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 132 | .add("authentication data", authData) |
Jian Li | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 133 | .add("mapRecords", mapRecords).toString(); |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public boolean equals(Object o) { |
| 138 | if (this == o) { |
| 139 | return true; |
| 140 | } |
| 141 | if (o == null || getClass() != o.getClass()) { |
| 142 | return false; |
| 143 | } |
| 144 | DefaultLispMapNotify that = (DefaultLispMapNotify) o; |
| 145 | return Objects.equal(nonce, that.nonce) && |
Jian Li | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 146 | Objects.equal(keyId, that.keyId) && |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 147 | Objects.equal(authDataLength, that.authDataLength) && |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 148 | Arrays.equals(authData, that.authData); |
Jian Li | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | @Override |
| 152 | public int hashCode() { |
Jian Li | 42b3e43 | 2016-08-31 01:05:20 +0900 | [diff] [blame] | 153 | return Objects.hashCode(nonce, keyId, authDataLength) + |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 154 | Arrays.hashCode(authData); |
Jian Li | 20850d3 | 2016-08-04 02:15:57 +0900 | [diff] [blame] | 155 | } |
| 156 | |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 157 | public static final class DefaultNotifyBuilder implements NotifyBuilder { |
| 158 | |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 159 | private long nonce; |
| 160 | private short keyId; |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 161 | private short authDataLength; |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 162 | private byte[] authData; |
| 163 | private String authKey; |
Jian Li | d4e6370 | 2016-08-30 18:29:20 +0900 | [diff] [blame] | 164 | private List<LispMapRecord> mapRecords = Lists.newArrayList(); |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 165 | |
| 166 | @Override |
| 167 | public LispType getType() { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 168 | return LispType.LISP_MAP_NOTIFY; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | @Override |
| 172 | public NotifyBuilder withNonce(long nonce) { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 173 | this.nonce = nonce; |
| 174 | return this; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | @Override |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 178 | public NotifyBuilder withKeyId(short keyId) { |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 179 | this.keyId = keyId; |
| 180 | return this; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | @Override |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 184 | public NotifyBuilder withAuthKey(String key) { |
| 185 | this.authKey = key; |
| 186 | return this; |
| 187 | } |
| 188 | |
| 189 | @Override |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 190 | public NotifyBuilder withAuthDataLength(short authDataLength) { |
| 191 | this.authDataLength = authDataLength; |
| 192 | return this; |
| 193 | } |
| 194 | |
| 195 | @Override |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 196 | public NotifyBuilder withAuthData(byte[] authData) { |
| 197 | if (authData != null) { |
| 198 | this.authData = authData; |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 199 | } else { |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 200 | this.authData = new byte[0]; |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 201 | } |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 202 | return this; |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | @Override |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 206 | public NotifyBuilder withMapRecords(List<LispMapRecord> mapRecords) { |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 207 | if (mapRecords != null) { |
| 208 | this.mapRecords = ImmutableList.copyOf(mapRecords); |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 209 | } |
Jian Li | f59c0ad | 2016-08-02 18:11:30 +0900 | [diff] [blame] | 210 | return this; |
| 211 | } |
| 212 | |
| 213 | @Override |
Jian Li | 525fded | 2016-08-04 01:15:33 +0900 | [diff] [blame] | 214 | public LispMapNotify build() { |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 215 | |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 216 | // if authentication data is not specified, we will calculate it |
| 217 | if (authData == null) { |
| 218 | LispAuthenticationFactory factory = LispAuthenticationFactory.getInstance(); |
| 219 | |
| 220 | authDataLength = LispAuthenticationKeyEnum.valueOf(keyId).getHashLength(); |
| 221 | byte[] tmpAuthData = new byte[authDataLength]; |
| 222 | Arrays.fill(tmpAuthData, (byte) 0); |
| 223 | authData = tmpAuthData; |
| 224 | |
| 225 | ByteBuf byteBuf = Unpooled.buffer(); |
| 226 | try { |
| 227 | new DefaultLispMapNotify(nonce, keyId, authDataLength, |
| 228 | authData, mapRecords).writeTo(byteBuf); |
| 229 | } catch (LispWriterException e) { |
| 230 | log.warn("Failed to serialize map notify message", e); |
| 231 | } |
| 232 | |
| 233 | byte[] bytes = new byte[byteBuf.readableBytes()]; |
| 234 | byteBuf.readBytes(bytes); |
| 235 | |
| 236 | if (authKey == null) { |
| 237 | log.warn("Must specify authentication key"); |
| 238 | } |
| 239 | |
| 240 | authData = factory.createAuthenticationData(valueOf(keyId), authKey, bytes); |
Jian Li | e4ba2a4 | 2016-08-29 20:24:15 +0900 | [diff] [blame] | 241 | } |
| 242 | |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 243 | return new DefaultLispMapNotify(nonce, keyId, authDataLength, authData, mapRecords); |
Jian Li | 719b3bf | 2016-07-22 00:38:29 +0900 | [diff] [blame] | 244 | } |
| 245 | } |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 246 | |
| 247 | /** |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 248 | * A LISP message reader for MapNotify message. |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 249 | */ |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 250 | public static final class NotifyReader implements LispMessageReader<LispMapNotify> { |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 251 | |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 252 | private static final int RESERVED_SKIP_LENGTH = 3; |
| 253 | |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 254 | @Override |
Jian Li | a7b394d | 2016-08-21 23:11:46 +0900 | [diff] [blame] | 255 | public LispMapNotify readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 256 | |
| 257 | if (byteBuf.readerIndex() != 0) { |
| 258 | return null; |
| 259 | } |
| 260 | |
| 261 | // skip first three bytes as they represent type and reserved fields |
| 262 | byteBuf.skipBytes(RESERVED_SKIP_LENGTH); |
| 263 | |
| 264 | // record count -> 8 bits |
| 265 | byte recordCount = (byte) byteBuf.readUnsignedByte(); |
| 266 | |
| 267 | // nonce -> 64 bits |
| 268 | long nonce = byteBuf.readLong(); |
| 269 | |
| 270 | // keyId -> 16 bits |
| 271 | short keyId = byteBuf.readShort(); |
| 272 | |
| 273 | // authenticationDataLength -> 16 bits |
| 274 | short authLength = byteBuf.readShort(); |
| 275 | |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 276 | // authData -> depends on the authenticationDataLength |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 277 | byte[] authData = new byte[authLength]; |
| 278 | byteBuf.readBytes(authData); |
| 279 | |
| 280 | List<LispMapRecord> mapRecords = Lists.newArrayList(); |
| 281 | for (int i = 0; i < recordCount; i++) { |
| 282 | mapRecords.add(new DefaultLispMapRecord.MapRecordReader().readFrom(byteBuf)); |
| 283 | } |
| 284 | |
| 285 | return new DefaultNotifyBuilder() |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 286 | .withNonce(nonce) |
| 287 | .withKeyId(keyId) |
| 288 | .withAuthDataLength(authLength) |
| 289 | .withAuthData(authData) |
| 290 | .withMapRecords(mapRecords) |
| 291 | .build(); |
Jian Li | 26069e2 | 2016-08-10 22:00:52 +0900 | [diff] [blame] | 292 | } |
| 293 | } |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 294 | |
| 295 | /** |
| 296 | * A LISP message reader for MapNotify message. |
| 297 | */ |
| 298 | public static final class NotifyWriter implements LispMessageWriter<LispMapNotify> { |
| 299 | |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 300 | private static final int NOTIFY_SHIFT_BIT = 4; |
| 301 | |
| 302 | private static final int UNUSED_ZERO = 0; |
| 303 | |
| 304 | @Override |
| 305 | public void writeTo(ByteBuf byteBuf, LispMapNotify message) throws LispWriterException { |
| 306 | |
| 307 | // specify LISP message type |
Jian Li | cbc57e3 | 2016-09-14 09:06:54 +0900 | [diff] [blame] | 308 | byte msgType = (byte) (LispType.LISP_MAP_NOTIFY.getTypeCode() << NOTIFY_SHIFT_BIT); |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 309 | byteBuf.writeByte(msgType); |
| 310 | |
| 311 | // reserved field |
| 312 | byteBuf.writeShort((short) UNUSED_ZERO); |
| 313 | |
| 314 | // record count |
Jian Li | 42b3e43 | 2016-08-31 01:05:20 +0900 | [diff] [blame] | 315 | byteBuf.writeByte(message.getMapRecords().size()); |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 316 | |
| 317 | // nonce |
| 318 | byteBuf.writeLong(message.getNonce()); |
| 319 | |
| 320 | // keyId |
| 321 | byteBuf.writeShort(message.getKeyId()); |
| 322 | |
Jian Li | f8c2d4a | 2016-09-15 02:33:12 +0900 | [diff] [blame] | 323 | // authentication data and its length |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 324 | if (message.getAuthData() == null) { |
Jian Li | f8c2d4a | 2016-09-15 02:33:12 +0900 | [diff] [blame] | 325 | byteBuf.writeShort((short) 0); |
| 326 | } else { |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame^] | 327 | byteBuf.writeShort(message.getAuthData().length); |
| 328 | byteBuf.writeBytes(message.getAuthData()); |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 329 | } |
| 330 | |
Jian Li | edc5db1 | 2016-08-23 17:30:19 +0900 | [diff] [blame] | 331 | // serialize map records |
| 332 | MapRecordWriter writer = new MapRecordWriter(); |
| 333 | List<LispMapRecord> records = message.getMapRecords(); |
| 334 | |
| 335 | for (int i = 0; i < records.size(); i++) { |
| 336 | writer.writeTo(byteBuf, records.get(i)); |
| 337 | } |
| 338 | } |
| 339 | } |
Jian Li | 451175e | 2016-07-19 23:22:20 +0900 | [diff] [blame] | 340 | } |