Committed by
Thomas Vachuska
Add unit tests for LISP control message serializer and deserializer
Change-Id: Id517db99635ad8e055d6581e5c0f3ac9f45f2869
Showing
12 changed files
with
308 additions
and
54 deletions
... | @@ -99,7 +99,11 @@ public final class DefaultLispMapNotify implements LispMapNotify { | ... | @@ -99,7 +99,11 @@ public final class DefaultLispMapNotify implements LispMapNotify { |
99 | 99 | ||
100 | @Override | 100 | @Override |
101 | public byte[] getAuthenticationData() { | 101 | public byte[] getAuthenticationData() { |
102 | + if (authenticationData != null && authenticationData.length != 0) { | ||
102 | return ImmutableByteSequence.copyFrom(authenticationData).asArray(); | 103 | return ImmutableByteSequence.copyFrom(authenticationData).asArray(); |
104 | + } else { | ||
105 | + return new byte[0]; | ||
106 | + } | ||
103 | } | 107 | } |
104 | 108 | ||
105 | @Override | 109 | @Override |
... | @@ -132,12 +136,13 @@ public final class DefaultLispMapNotify implements LispMapNotify { | ... | @@ -132,12 +136,13 @@ public final class DefaultLispMapNotify implements LispMapNotify { |
132 | Objects.equal(recordCount, that.recordCount) && | 136 | Objects.equal(recordCount, that.recordCount) && |
133 | Objects.equal(keyId, that.keyId) && | 137 | Objects.equal(keyId, that.keyId) && |
134 | Objects.equal(authDataLength, that.authDataLength) && | 138 | Objects.equal(authDataLength, that.authDataLength) && |
135 | - Objects.equal(authenticationData, that.authenticationData); | 139 | + Arrays.equals(authenticationData, that.authenticationData); |
136 | } | 140 | } |
137 | 141 | ||
138 | @Override | 142 | @Override |
139 | public int hashCode() { | 143 | public int hashCode() { |
140 | - return Objects.hashCode(nonce, recordCount, keyId, authDataLength, authenticationData); | 144 | + return Objects.hashCode(nonce, recordCount, keyId, authDataLength) + |
145 | + Arrays.hashCode(authenticationData); | ||
141 | } | 146 | } |
142 | 147 | ||
143 | public static final class DefaultNotifyBuilder implements NotifyBuilder { | 148 | public static final class DefaultNotifyBuilder implements NotifyBuilder { |
... | @@ -180,18 +185,35 @@ public final class DefaultLispMapNotify implements LispMapNotify { | ... | @@ -180,18 +185,35 @@ public final class DefaultLispMapNotify implements LispMapNotify { |
180 | 185 | ||
181 | @Override | 186 | @Override |
182 | public NotifyBuilder withAuthenticationData(byte[] authenticationData) { | 187 | public NotifyBuilder withAuthenticationData(byte[] authenticationData) { |
188 | + if (authenticationData != null) { | ||
183 | this.authenticationData = authenticationData; | 189 | this.authenticationData = authenticationData; |
190 | + } else { | ||
191 | + this.authenticationData = new byte[0]; | ||
192 | + } | ||
184 | return this; | 193 | return this; |
185 | } | 194 | } |
186 | 195 | ||
187 | @Override | 196 | @Override |
188 | public NotifyBuilder withMapRecords(List<LispMapRecord> mapRecords) { | 197 | public NotifyBuilder withMapRecords(List<LispMapRecord> mapRecords) { |
198 | + if (mapRecords != null) { | ||
189 | this.mapRecords = ImmutableList.copyOf(mapRecords); | 199 | this.mapRecords = ImmutableList.copyOf(mapRecords); |
200 | + } else { | ||
201 | + this.mapRecords = Lists.newArrayList(); | ||
202 | + } | ||
190 | return this; | 203 | return this; |
191 | } | 204 | } |
192 | 205 | ||
193 | @Override | 206 | @Override |
194 | public LispMapNotify build() { | 207 | public LispMapNotify build() { |
208 | + | ||
209 | + if (authenticationData == null) { | ||
210 | + authenticationData = new byte[0]; | ||
211 | + } | ||
212 | + | ||
213 | + if (mapRecords == null) { | ||
214 | + mapRecords = Lists.newArrayList(); | ||
215 | + } | ||
216 | + | ||
195 | return new DefaultLispMapNotify(nonce, keyId, authDataLength, | 217 | return new DefaultLispMapNotify(nonce, keyId, authDataLength, |
196 | authenticationData, recordCount, mapRecords); | 218 | authenticationData, recordCount, mapRecords); |
197 | } | 219 | } | ... | ... |
... | @@ -209,12 +209,21 @@ public final class DefaultLispMapRecord implements LispMapRecord { | ... | @@ -209,12 +209,21 @@ public final class DefaultLispMapRecord implements LispMapRecord { |
209 | 209 | ||
210 | @Override | 210 | @Override |
211 | public MapRecordBuilder withLocators(List<LispLocatorRecord> records) { | 211 | public MapRecordBuilder withLocators(List<LispLocatorRecord> records) { |
212 | + if (records != null) { | ||
212 | this.locatorRecords = ImmutableList.copyOf(records); | 213 | this.locatorRecords = ImmutableList.copyOf(records); |
214 | + } else { | ||
215 | + this.locatorRecords = Lists.newArrayList(); | ||
216 | + } | ||
213 | return this; | 217 | return this; |
214 | } | 218 | } |
215 | 219 | ||
216 | @Override | 220 | @Override |
217 | public LispMapRecord build() { | 221 | public LispMapRecord build() { |
222 | + | ||
223 | + if (locatorRecords == null) { | ||
224 | + locatorRecords = Lists.newArrayList(); | ||
225 | + } | ||
226 | + | ||
218 | return new DefaultLispMapRecord(recordTtl, locatorCount, maskLength, | 227 | return new DefaultLispMapRecord(recordTtl, locatorCount, maskLength, |
219 | action, authoritative, mapVersionNumber, eidPrefixAfi, locatorRecords); | 228 | action, authoritative, mapVersionNumber, eidPrefixAfi, locatorRecords); |
220 | } | 229 | } |
... | @@ -228,6 +237,8 @@ public final class DefaultLispMapRecord implements LispMapRecord { | ... | @@ -228,6 +237,8 @@ public final class DefaultLispMapRecord implements LispMapRecord { |
228 | private static final int AUTHORITATIVE_INDEX = 4; | 237 | private static final int AUTHORITATIVE_INDEX = 4; |
229 | private static final int RESERVED_SKIP_LENGTH = 1; | 238 | private static final int RESERVED_SKIP_LENGTH = 1; |
230 | 239 | ||
240 | + private static final int REPLY_ACTION_SHIFT_BIT = 5; | ||
241 | + | ||
231 | @Override | 242 | @Override |
232 | public LispMapRecord readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { | 243 | public LispMapRecord readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
233 | 244 | ||
... | @@ -235,17 +246,22 @@ public final class DefaultLispMapRecord implements LispMapRecord { | ... | @@ -235,17 +246,22 @@ public final class DefaultLispMapRecord implements LispMapRecord { |
235 | int recordTtl = byteBuf.readInt(); | 246 | int recordTtl = byteBuf.readInt(); |
236 | 247 | ||
237 | // Locator count -> 8 bits | 248 | // Locator count -> 8 bits |
238 | - int locatorCount = byteBuf.readUnsignedShort(); | 249 | + int locatorCount = byteBuf.readUnsignedByte(); |
239 | 250 | ||
240 | // EID mask length -> 8 bits | 251 | // EID mask length -> 8 bits |
241 | byte maskLength = (byte) byteBuf.readUnsignedByte(); | 252 | byte maskLength = (byte) byteBuf.readUnsignedByte(); |
242 | 253 | ||
243 | - // TODO: need to de-serialize LispMapReplyAction | 254 | + byte actionWithFlag = (byte) byteBuf.readUnsignedByte(); |
244 | 255 | ||
245 | - byte actionWithFlag = byteBuf.readByte(); | 256 | + // action -> 3 bit |
257 | + int actionByte = actionWithFlag >> REPLY_ACTION_SHIFT_BIT; | ||
258 | + LispMapReplyAction action = LispMapReplyAction.valueOf(actionByte); | ||
259 | + if (action == null) { | ||
260 | + action = LispMapReplyAction.NoAction; | ||
261 | + } | ||
246 | 262 | ||
247 | // authoritative flag -> 1 bit | 263 | // authoritative flag -> 1 bit |
248 | - boolean authoritative = ByteOperator.getBit(actionWithFlag, AUTHORITATIVE_INDEX); | 264 | + boolean authoritative = ByteOperator.getBit((byte) (actionWithFlag >> AUTHORITATIVE_INDEX), 0); |
249 | 265 | ||
250 | // let's skip the reserved field | 266 | // let's skip the reserved field |
251 | byteBuf.skipBytes(RESERVED_SKIP_LENGTH); | 267 | byteBuf.skipBytes(RESERVED_SKIP_LENGTH); |
... | @@ -264,6 +280,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { | ... | @@ -264,6 +280,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { |
264 | .withRecordTtl(recordTtl) | 280 | .withRecordTtl(recordTtl) |
265 | .withLocatorCount(locatorCount) | 281 | .withLocatorCount(locatorCount) |
266 | .withMaskLength(maskLength) | 282 | .withMaskLength(maskLength) |
283 | + .withAction(action) | ||
267 | .withAuthoritative(authoritative) | 284 | .withAuthoritative(authoritative) |
268 | .withMapVersionNumber(mapVersionNumber) | 285 | .withMapVersionNumber(mapVersionNumber) |
269 | .withLocators(locators) | 286 | .withLocators(locators) |
... | @@ -301,9 +318,8 @@ public final class DefaultLispMapRecord implements LispMapRecord { | ... | @@ -301,9 +318,8 @@ public final class DefaultLispMapRecord implements LispMapRecord { |
301 | // authoritative bit | 318 | // authoritative bit |
302 | byte authoritative = DISABLE_BIT; | 319 | byte authoritative = DISABLE_BIT; |
303 | if (message.isAuthoritative()) { | 320 | if (message.isAuthoritative()) { |
304 | - authoritative = ENABLE_BIT; | 321 | + authoritative = ENABLE_BIT << AUTHORITATIVE_FLAG_SHIFT_BIT; |
305 | } | 322 | } |
306 | - authoritative = (byte) (authoritative << AUTHORITATIVE_FLAG_SHIFT_BIT); | ||
307 | 323 | ||
308 | byteBuf.writeByte((byte) (action + authoritative)); | 324 | byteBuf.writeByte((byte) (action + authoritative)); |
309 | 325 | ... | ... |
... | @@ -29,6 +29,8 @@ import java.util.Arrays; | ... | @@ -29,6 +29,8 @@ import java.util.Arrays; |
29 | import java.util.List; | 29 | import java.util.List; |
30 | 30 | ||
31 | import static com.google.common.base.MoreObjects.toStringHelper; | 31 | import static com.google.common.base.MoreObjects.toStringHelper; |
32 | +import static org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.MapRecordReader; | ||
33 | +import static org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.MapRecordWriter; | ||
32 | 34 | ||
33 | 35 | ||
34 | /** | 36 | /** |
... | @@ -117,7 +119,11 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -117,7 +119,11 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
117 | 119 | ||
118 | @Override | 120 | @Override |
119 | public byte[] getAuthenticationData() { | 121 | public byte[] getAuthenticationData() { |
120 | - return ImmutableByteSequence.copyFrom(this.authenticationData).asArray(); | 122 | + if (authenticationData != null && authenticationData.length != 0) { |
123 | + return ImmutableByteSequence.copyFrom(authenticationData).asArray(); | ||
124 | + } else { | ||
125 | + return new byte[0]; | ||
126 | + } | ||
121 | } | 127 | } |
122 | 128 | ||
123 | @Override | 129 | @Override |
... | @@ -153,7 +159,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -153,7 +159,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
153 | Objects.equal(recordCount, that.recordCount) && | 159 | Objects.equal(recordCount, that.recordCount) && |
154 | Objects.equal(keyId, that.keyId) && | 160 | Objects.equal(keyId, that.keyId) && |
155 | Objects.equal(authDataLength, that.authDataLength) && | 161 | Objects.equal(authDataLength, that.authDataLength) && |
156 | - Objects.equal(authenticationData, that.authenticationData) && | 162 | + Arrays.equals(authenticationData, that.authenticationData) && |
157 | Objects.equal(proxyMapReply, that.proxyMapReply) && | 163 | Objects.equal(proxyMapReply, that.proxyMapReply) && |
158 | Objects.equal(wantMapNotify, that.wantMapNotify); | 164 | Objects.equal(wantMapNotify, that.wantMapNotify); |
159 | } | 165 | } |
... | @@ -161,7 +167,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -161,7 +167,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
161 | @Override | 167 | @Override |
162 | public int hashCode() { | 168 | public int hashCode() { |
163 | return Objects.hashCode(nonce, recordCount, keyId, authDataLength, | 169 | return Objects.hashCode(nonce, recordCount, keyId, authDataLength, |
164 | - authenticationData, proxyMapReply, wantMapNotify); | 170 | + proxyMapReply, wantMapNotify) + Arrays.hashCode(authenticationData); |
165 | } | 171 | } |
166 | 172 | ||
167 | public static final class DefaultRegisterBuilder implements RegisterBuilder { | 173 | public static final class DefaultRegisterBuilder implements RegisterBuilder { |
... | @@ -218,18 +224,34 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -218,18 +224,34 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
218 | 224 | ||
219 | @Override | 225 | @Override |
220 | public RegisterBuilder withAuthenticationData(byte[] authenticationData) { | 226 | public RegisterBuilder withAuthenticationData(byte[] authenticationData) { |
227 | + if (authenticationData != null) { | ||
221 | this.authenticationData = authenticationData; | 228 | this.authenticationData = authenticationData; |
229 | + } else { | ||
230 | + this.authenticationData = new byte[0]; | ||
231 | + } | ||
222 | return this; | 232 | return this; |
223 | } | 233 | } |
224 | 234 | ||
225 | @Override | 235 | @Override |
226 | public RegisterBuilder withMapRecords(List<LispMapRecord> mapRecords) { | 236 | public RegisterBuilder withMapRecords(List<LispMapRecord> mapRecords) { |
237 | + if (mapRecords != null) { | ||
227 | this.mapRecords = ImmutableList.copyOf(mapRecords); | 238 | this.mapRecords = ImmutableList.copyOf(mapRecords); |
239 | + } else { | ||
240 | + this.mapRecords = Lists.newArrayList(); | ||
241 | + } | ||
228 | return this; | 242 | return this; |
229 | } | 243 | } |
230 | 244 | ||
231 | @Override | 245 | @Override |
232 | public LispMapRegister build() { | 246 | public LispMapRegister build() { |
247 | + if (authenticationData == null) { | ||
248 | + authenticationData = new byte[0]; | ||
249 | + } | ||
250 | + | ||
251 | + if (mapRecords == null) { | ||
252 | + mapRecords = Lists.newArrayList(); | ||
253 | + } | ||
254 | + | ||
233 | return new DefaultLispMapRegister(nonce, keyId, authDataLength, | 255 | return new DefaultLispMapRegister(nonce, keyId, authDataLength, |
234 | authenticationData, recordCount, mapRecords, proxyMapReply, wantMapNotify); | 256 | authenticationData, recordCount, mapRecords, proxyMapReply, wantMapNotify); |
235 | } | 257 | } |
... | @@ -280,7 +302,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -280,7 +302,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
280 | 302 | ||
281 | List<LispMapRecord> mapRecords = Lists.newArrayList(); | 303 | List<LispMapRecord> mapRecords = Lists.newArrayList(); |
282 | for (int i = 0; i < recordCount; i++) { | 304 | for (int i = 0; i < recordCount; i++) { |
283 | - mapRecords.add(new DefaultLispMapRecord.MapRecordReader().readFrom(byteBuf)); | 305 | + mapRecords.add(new MapRecordReader().readFrom(byteBuf)); |
284 | } | 306 | } |
285 | 307 | ||
286 | return new DefaultRegisterBuilder() | 308 | return new DefaultRegisterBuilder() |
... | @@ -360,7 +382,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -360,7 +382,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
360 | // TODO: need to implement MAC authentication mechanism | 382 | // TODO: need to implement MAC authentication mechanism |
361 | 383 | ||
362 | // serialize map records | 384 | // serialize map records |
363 | - DefaultLispMapRecord.MapRecordWriter writer = new DefaultLispMapRecord.MapRecordWriter(); | 385 | + MapRecordWriter writer = new MapRecordWriter(); |
364 | List<LispMapRecord> records = message.getMapRecords(); | 386 | List<LispMapRecord> records = message.getMapRecords(); |
365 | 387 | ||
366 | for (int i = 0; i < records.size(); i++) { | 388 | for (int i = 0; i < records.size(); i++) { | ... | ... |
... | @@ -185,12 +185,22 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -185,12 +185,22 @@ public final class DefaultLispMapReply implements LispMapReply { |
185 | 185 | ||
186 | @Override | 186 | @Override |
187 | public ReplyBuilder withMapRecords(List<LispMapRecord> mapRecords) { | 187 | public ReplyBuilder withMapRecords(List<LispMapRecord> mapRecords) { |
188 | + | ||
189 | + if (this.mapRecords != null) { | ||
188 | this.mapRecords = ImmutableList.copyOf(mapRecords); | 190 | this.mapRecords = ImmutableList.copyOf(mapRecords); |
191 | + } else { | ||
192 | + this.mapRecords = Lists.newArrayList(); | ||
193 | + } | ||
189 | return this; | 194 | return this; |
190 | } | 195 | } |
191 | 196 | ||
192 | @Override | 197 | @Override |
193 | public LispMapReply build() { | 198 | public LispMapReply build() { |
199 | + | ||
200 | + if (mapRecords == null) { | ||
201 | + mapRecords = Lists.newArrayList(); | ||
202 | + } | ||
203 | + | ||
194 | return new DefaultLispMapReply(nonce, recordCount, probe, etr, security, mapRecords); | 204 | return new DefaultLispMapReply(nonce, recordCount, probe, etr, security, mapRecords); |
195 | } | 205 | } |
196 | } | 206 | } | ... | ... |
... | @@ -28,6 +28,8 @@ import org.onosproject.lisp.msg.types.LispAfiAddress; | ... | @@ -28,6 +28,8 @@ import org.onosproject.lisp.msg.types.LispAfiAddress; |
28 | import java.util.List; | 28 | import java.util.List; |
29 | 29 | ||
30 | import static com.google.common.base.MoreObjects.toStringHelper; | 30 | import static com.google.common.base.MoreObjects.toStringHelper; |
31 | +import static com.google.common.base.Preconditions.checkArgument; | ||
32 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
31 | import static org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressWriter; | 33 | import static org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressWriter; |
32 | import static org.onosproject.lisp.msg.protocols.LispEidRecord.EidRecordWriter; | 34 | import static org.onosproject.lisp.msg.protocols.LispEidRecord.EidRecordWriter; |
33 | 35 | ||
... | @@ -179,8 +181,6 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -179,8 +181,6 @@ public final class DefaultLispMapRequest implements LispMapRequest { |
179 | return Objects.equal(nonce, that.nonce) && | 181 | return Objects.equal(nonce, that.nonce) && |
180 | Objects.equal(recordCount, that.recordCount) && | 182 | Objects.equal(recordCount, that.recordCount) && |
181 | Objects.equal(sourceEid, that.sourceEid) && | 183 | Objects.equal(sourceEid, that.sourceEid) && |
182 | - Objects.equal(itrRlocs, that.itrRlocs) && | ||
183 | - Objects.equal(eidRecords, that.eidRecords) && | ||
184 | Objects.equal(authoritative, that.authoritative) && | 184 | Objects.equal(authoritative, that.authoritative) && |
185 | Objects.equal(mapDataPresent, that.mapDataPresent) && | 185 | Objects.equal(mapDataPresent, that.mapDataPresent) && |
186 | Objects.equal(probe, that.probe) && | 186 | Objects.equal(probe, that.probe) && |
... | @@ -191,8 +191,8 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -191,8 +191,8 @@ public final class DefaultLispMapRequest implements LispMapRequest { |
191 | 191 | ||
192 | @Override | 192 | @Override |
193 | public int hashCode() { | 193 | public int hashCode() { |
194 | - return Objects.hashCode(nonce, recordCount, sourceEid, itrRlocs, eidRecords, | 194 | + return Objects.hashCode(nonce, recordCount, sourceEid, authoritative, |
195 | - authoritative, mapDataPresent, probe, smr, pitr, smrInvoked); | 195 | + mapDataPresent, probe, smr, pitr, smrInvoked); |
196 | } | 196 | } |
197 | 197 | ||
198 | public static final class DefaultRequestBuilder implements RequestBuilder { | 198 | public static final class DefaultRequestBuilder implements RequestBuilder { |
... | @@ -270,18 +270,33 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -270,18 +270,33 @@ public final class DefaultLispMapRequest implements LispMapRequest { |
270 | 270 | ||
271 | @Override | 271 | @Override |
272 | public RequestBuilder withItrRlocs(List<LispAfiAddress> itrRlocs) { | 272 | public RequestBuilder withItrRlocs(List<LispAfiAddress> itrRlocs) { |
273 | + | ||
274 | + if (itrRlocs != null) { | ||
273 | this.itrRlocs = ImmutableList.copyOf(itrRlocs); | 275 | this.itrRlocs = ImmutableList.copyOf(itrRlocs); |
276 | + } else { | ||
277 | + this.itrRlocs = Lists.newArrayList(); | ||
278 | + } | ||
279 | + | ||
274 | return this; | 280 | return this; |
275 | } | 281 | } |
276 | 282 | ||
277 | @Override | 283 | @Override |
278 | public RequestBuilder withEidRecords(List<LispEidRecord> records) { | 284 | public RequestBuilder withEidRecords(List<LispEidRecord> records) { |
285 | + | ||
286 | + if (records != null) { | ||
279 | this.eidRecords = ImmutableList.copyOf(records); | 287 | this.eidRecords = ImmutableList.copyOf(records); |
288 | + } else { | ||
289 | + this.eidRecords = Lists.newArrayList(); | ||
290 | + } | ||
280 | return this; | 291 | return this; |
281 | } | 292 | } |
282 | 293 | ||
283 | @Override | 294 | @Override |
284 | public LispMapRequest build() { | 295 | public LispMapRequest build() { |
296 | + | ||
297 | + checkNotNull(sourceEid, "Must have a source EID"); | ||
298 | + checkArgument((itrRlocs != null) && (itrRlocs.size() > 0), "Must have an ITR RLOC entry"); | ||
299 | + | ||
285 | return new DefaultLispMapRequest(nonce, recordCount, sourceEid, itrRlocs, | 300 | return new DefaultLispMapRequest(nonce, recordCount, sourceEid, itrRlocs, |
286 | eidRecords, authoritative, mapDataPresent, probe, smr, pitr, smrInvoked); | 301 | eidRecords, authoritative, mapDataPresent, probe, smr, pitr, smrInvoked); |
287 | } | 302 | } |
... | @@ -331,10 +346,10 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -331,10 +346,10 @@ public final class DefaultLispMapRequest implements LispMapRequest { |
331 | // let's skip reserved field, only obtains ITR counter value | 346 | // let's skip reserved field, only obtains ITR counter value |
332 | // assume that first 3 bits are all set as 0, | 347 | // assume that first 3 bits are all set as 0, |
333 | // remain 5 bits represent Itr Rloc Counter (IRC) | 348 | // remain 5 bits represent Itr Rloc Counter (IRC) |
334 | - int irc = byteBuf.readUnsignedShort(); | 349 | + int irc = byteBuf.readUnsignedByte(); |
335 | 350 | ||
336 | // record count -> 8 bits | 351 | // record count -> 8 bits |
337 | - int recordCount = byteBuf.readUnsignedShort(); | 352 | + int recordCount = byteBuf.readUnsignedByte(); |
338 | 353 | ||
339 | // nonce -> 64 bits | 354 | // nonce -> 64 bits |
340 | long nonce = byteBuf.readLong(); | 355 | long nonce = byteBuf.readLong(); |
... | @@ -387,8 +402,6 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -387,8 +402,6 @@ public final class DefaultLispMapRequest implements LispMapRequest { |
387 | private static final int ENABLE_BIT = 1; | 402 | private static final int ENABLE_BIT = 1; |
388 | private static final int DISABLE_BIT = 0; | 403 | private static final int DISABLE_BIT = 0; |
389 | 404 | ||
390 | - private static final int UNUSED_ZERO = 0; | ||
391 | - | ||
392 | @Override | 405 | @Override |
393 | public void writeTo(ByteBuf byteBuf, LispMapRequest message) throws LispWriterException { | 406 | public void writeTo(ByteBuf byteBuf, LispMapRequest message) throws LispWriterException { |
394 | 407 | ||
... | @@ -435,8 +448,8 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -435,8 +448,8 @@ public final class DefaultLispMapRequest implements LispMapRequest { |
435 | 448 | ||
436 | byteBuf.writeByte((byte) (pitr + smrInvoked)); | 449 | byteBuf.writeByte((byte) (pitr + smrInvoked)); |
437 | 450 | ||
438 | - // TODO: ITR RLOC count | 451 | + // ITR Rloc count |
439 | - byteBuf.writeByte((byte) UNUSED_ZERO); | 452 | + byteBuf.writeByte((byte) message.getItrRlocs().size()); |
440 | 453 | ||
441 | // record count | 454 | // record count |
442 | byteBuf.writeByte(message.getRecordCount()); | 455 | byteBuf.writeByte(message.getRecordCount()); | ... | ... |
... | @@ -16,11 +16,19 @@ | ... | @@ -16,11 +16,19 @@ |
16 | package org.onosproject.lisp.msg.protocols; | 16 | package org.onosproject.lisp.msg.protocols; |
17 | 17 | ||
18 | import com.google.common.testing.EqualsTester; | 18 | import com.google.common.testing.EqualsTester; |
19 | +import io.netty.buffer.ByteBuf; | ||
20 | +import io.netty.buffer.Unpooled; | ||
19 | import org.junit.Before; | 21 | import org.junit.Before; |
20 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | +import org.onlab.packet.IpAddress; | ||
24 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
25 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
26 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
27 | +import org.onosproject.lisp.msg.types.LispIpv4Address; | ||
21 | 28 | ||
22 | import static org.hamcrest.MatcherAssert.assertThat; | 29 | import static org.hamcrest.MatcherAssert.assertThat; |
23 | import static org.hamcrest.Matchers.is; | 30 | import static org.hamcrest.Matchers.is; |
31 | +import static org.onosproject.lisp.msg.protocols.DefaultLispLocatorRecord.*; | ||
24 | 32 | ||
25 | /** | 33 | /** |
26 | * Unit tests for DefaultLispLocatorRecord class. | 34 | * Unit tests for DefaultLispLocatorRecord class. |
... | @@ -35,7 +43,9 @@ public final class DefaultLispLocatorRecordTest { | ... | @@ -35,7 +43,9 @@ public final class DefaultLispLocatorRecordTest { |
35 | public void setup() { | 43 | public void setup() { |
36 | 44 | ||
37 | LispLocatorRecord.LocatorRecordBuilder builder1 = | 45 | LispLocatorRecord.LocatorRecordBuilder builder1 = |
38 | - new DefaultLispLocatorRecord.DefaultLocatorRecordBuilder(); | 46 | + new DefaultLocatorRecordBuilder(); |
47 | + | ||
48 | + LispIpv4Address ipv4Locator1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
39 | 49 | ||
40 | record1 = builder1 | 50 | record1 = builder1 |
41 | .withPriority((byte) 0x01) | 51 | .withPriority((byte) 0x01) |
... | @@ -45,10 +55,11 @@ public final class DefaultLispLocatorRecordTest { | ... | @@ -45,10 +55,11 @@ public final class DefaultLispLocatorRecordTest { |
45 | .withLocalLocator(true) | 55 | .withLocalLocator(true) |
46 | .withRlocProbed(false) | 56 | .withRlocProbed(false) |
47 | .withRouted(true) | 57 | .withRouted(true) |
58 | + .withLocatorAfi(ipv4Locator1) | ||
48 | .build(); | 59 | .build(); |
49 | 60 | ||
50 | LispLocatorRecord.LocatorRecordBuilder builder2 = | 61 | LispLocatorRecord.LocatorRecordBuilder builder2 = |
51 | - new DefaultLispLocatorRecord.DefaultLocatorRecordBuilder(); | 62 | + new DefaultLocatorRecordBuilder(); |
52 | 63 | ||
53 | sameAsRecord1 = builder2 | 64 | sameAsRecord1 = builder2 |
54 | .withPriority((byte) 0x01) | 65 | .withPriority((byte) 0x01) |
... | @@ -58,10 +69,13 @@ public final class DefaultLispLocatorRecordTest { | ... | @@ -58,10 +69,13 @@ public final class DefaultLispLocatorRecordTest { |
58 | .withLocalLocator(true) | 69 | .withLocalLocator(true) |
59 | .withRlocProbed(false) | 70 | .withRlocProbed(false) |
60 | .withRouted(true) | 71 | .withRouted(true) |
72 | + .withLocatorAfi(ipv4Locator1) | ||
61 | .build(); | 73 | .build(); |
62 | 74 | ||
63 | LispLocatorRecord.LocatorRecordBuilder builder3 = | 75 | LispLocatorRecord.LocatorRecordBuilder builder3 = |
64 | - new DefaultLispLocatorRecord.DefaultLocatorRecordBuilder(); | 76 | + new DefaultLocatorRecordBuilder(); |
77 | + | ||
78 | + LispIpv4Address ipv4Locator2 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2")); | ||
65 | 79 | ||
66 | record2 = builder3 | 80 | record2 = builder3 |
67 | .withPriority((byte) 0x02) | 81 | .withPriority((byte) 0x02) |
... | @@ -71,6 +85,7 @@ public final class DefaultLispLocatorRecordTest { | ... | @@ -71,6 +85,7 @@ public final class DefaultLispLocatorRecordTest { |
71 | .withLocalLocator(false) | 85 | .withLocalLocator(false) |
72 | .withRlocProbed(true) | 86 | .withRlocProbed(true) |
73 | .withRouted(false) | 87 | .withRouted(false) |
88 | + .withLocatorAfi(ipv4Locator2) | ||
74 | .build(); | 89 | .build(); |
75 | } | 90 | } |
76 | 91 | ||
... | @@ -85,6 +100,8 @@ public final class DefaultLispLocatorRecordTest { | ... | @@ -85,6 +100,8 @@ public final class DefaultLispLocatorRecordTest { |
85 | public void testConstruction() { | 100 | public void testConstruction() { |
86 | DefaultLispLocatorRecord record = (DefaultLispLocatorRecord) record1; | 101 | DefaultLispLocatorRecord record = (DefaultLispLocatorRecord) record1; |
87 | 102 | ||
103 | + LispIpv4Address ipv4Locator = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
104 | + | ||
88 | assertThat(record.getPriority(), is((byte) 0x01)); | 105 | assertThat(record.getPriority(), is((byte) 0x01)); |
89 | assertThat(record.getWeight(), is((byte) 0x01)); | 106 | assertThat(record.getWeight(), is((byte) 0x01)); |
90 | assertThat(record.getMulticastPriority(), is((byte) 0x01)); | 107 | assertThat(record.getMulticastPriority(), is((byte) 0x01)); |
... | @@ -92,5 +109,20 @@ public final class DefaultLispLocatorRecordTest { | ... | @@ -92,5 +109,20 @@ public final class DefaultLispLocatorRecordTest { |
92 | assertThat(record.isLocalLocator(), is(true)); | 109 | assertThat(record.isLocalLocator(), is(true)); |
93 | assertThat(record.isRlocProbed(), is(false)); | 110 | assertThat(record.isRlocProbed(), is(false)); |
94 | assertThat(record.isRouted(), is(true)); | 111 | assertThat(record.isRouted(), is(true)); |
112 | + assertThat(record.getLocatorAfi(), is(ipv4Locator)); | ||
113 | + } | ||
114 | + | ||
115 | + @Test | ||
116 | + public void testSerialization() throws LispReaderException, LispWriterException, LispParseError { | ||
117 | + ByteBuf byteBuf = Unpooled.buffer(); | ||
118 | + | ||
119 | + LocatorRecordWriter writer = new LocatorRecordWriter(); | ||
120 | + writer.writeTo(byteBuf, record1); | ||
121 | + | ||
122 | + LocatorRecordReader reader = new LocatorRecordReader(); | ||
123 | + LispLocatorRecord deserialized = reader.readFrom(byteBuf); | ||
124 | + | ||
125 | + new EqualsTester() | ||
126 | + .addEqualityGroup(record1, deserialized).testEquals(); | ||
95 | } | 127 | } |
96 | } | 128 | } | ... | ... |
... | @@ -16,11 +16,17 @@ | ... | @@ -16,11 +16,17 @@ |
16 | package org.onosproject.lisp.msg.protocols; | 16 | package org.onosproject.lisp.msg.protocols; |
17 | 17 | ||
18 | import com.google.common.testing.EqualsTester; | 18 | import com.google.common.testing.EqualsTester; |
19 | +import io.netty.buffer.ByteBuf; | ||
20 | +import io.netty.buffer.Unpooled; | ||
19 | import org.junit.Before; | 21 | import org.junit.Before; |
20 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
24 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
25 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
21 | 26 | ||
22 | import static org.hamcrest.MatcherAssert.assertThat; | 27 | import static org.hamcrest.MatcherAssert.assertThat; |
23 | import static org.hamcrest.Matchers.is; | 28 | import static org.hamcrest.Matchers.is; |
29 | +import static org.onosproject.lisp.msg.protocols.DefaultLispMapNotify.*; | ||
24 | 30 | ||
25 | /** | 31 | /** |
26 | * Unit tests for DefaultLispMapNotify class. | 32 | * Unit tests for DefaultLispMapNotify class. |
... | @@ -35,25 +41,25 @@ public final class DefaultLispMapNotifyTest { | ... | @@ -35,25 +41,25 @@ public final class DefaultLispMapNotifyTest { |
35 | public void setup() { | 41 | public void setup() { |
36 | 42 | ||
37 | LispMapNotify.NotifyBuilder builder1 = | 43 | LispMapNotify.NotifyBuilder builder1 = |
38 | - new DefaultLispMapNotify.DefaultNotifyBuilder(); | 44 | + new DefaultNotifyBuilder(); |
39 | 45 | ||
40 | notify1 = builder1 | 46 | notify1 = builder1 |
41 | .withKeyId((short) 1) | 47 | .withKeyId((short) 1) |
42 | .withNonce(1L) | 48 | .withNonce(1L) |
43 | - .withRecordCount((byte) 0x01) | 49 | + .withRecordCount((byte) 0) |
44 | .build(); | 50 | .build(); |
45 | 51 | ||
46 | LispMapNotify.NotifyBuilder builder2 = | 52 | LispMapNotify.NotifyBuilder builder2 = |
47 | - new DefaultLispMapNotify.DefaultNotifyBuilder(); | 53 | + new DefaultNotifyBuilder(); |
48 | 54 | ||
49 | sameAsNotify1 = builder2 | 55 | sameAsNotify1 = builder2 |
50 | .withKeyId((short) 1) | 56 | .withKeyId((short) 1) |
51 | .withNonce(1L) | 57 | .withNonce(1L) |
52 | - .withRecordCount((byte) 0x01) | 58 | + .withRecordCount((byte) 0) |
53 | .build(); | 59 | .build(); |
54 | 60 | ||
55 | LispMapNotify.NotifyBuilder builder3 = | 61 | LispMapNotify.NotifyBuilder builder3 = |
56 | - new DefaultLispMapNotify.DefaultNotifyBuilder(); | 62 | + new DefaultNotifyBuilder(); |
57 | 63 | ||
58 | notify2 = builder3 | 64 | notify2 = builder3 |
59 | .withKeyId((short) 2) | 65 | .withKeyId((short) 2) |
... | @@ -75,6 +81,20 @@ public final class DefaultLispMapNotifyTest { | ... | @@ -75,6 +81,20 @@ public final class DefaultLispMapNotifyTest { |
75 | 81 | ||
76 | assertThat(notify.getKeyId(), is((short) 1)); | 82 | assertThat(notify.getKeyId(), is((short) 1)); |
77 | assertThat(notify.getNonce(), is(1L)); | 83 | assertThat(notify.getNonce(), is(1L)); |
78 | - assertThat(notify.getRecordCount(), is((byte) 0x01)); | 84 | + assertThat(notify.getRecordCount(), is((byte) 0)); |
85 | + } | ||
86 | + | ||
87 | + @Test | ||
88 | + public void testSerialization() throws LispReaderException, LispWriterException, LispParseError { | ||
89 | + ByteBuf byteBuf = Unpooled.buffer(); | ||
90 | + | ||
91 | + NotifyWriter writer = new NotifyWriter(); | ||
92 | + writer.writeTo(byteBuf, notify1); | ||
93 | + | ||
94 | + NotifyReader reader = new NotifyReader(); | ||
95 | + LispMapNotify deserialized = reader.readFrom(byteBuf); | ||
96 | + | ||
97 | + new EqualsTester() | ||
98 | + .addEqualityGroup(notify1, deserialized).testEquals(); | ||
79 | } | 99 | } |
80 | } | 100 | } | ... | ... |
... | @@ -16,11 +16,19 @@ | ... | @@ -16,11 +16,19 @@ |
16 | package org.onosproject.lisp.msg.protocols; | 16 | package org.onosproject.lisp.msg.protocols; |
17 | 17 | ||
18 | import com.google.common.testing.EqualsTester; | 18 | import com.google.common.testing.EqualsTester; |
19 | +import io.netty.buffer.ByteBuf; | ||
20 | +import io.netty.buffer.Unpooled; | ||
19 | import org.junit.Before; | 21 | import org.junit.Before; |
20 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | +import org.onlab.packet.IpAddress; | ||
24 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
25 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
26 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
27 | +import org.onosproject.lisp.msg.types.LispIpv4Address; | ||
21 | 28 | ||
22 | import static org.hamcrest.MatcherAssert.assertThat; | 29 | import static org.hamcrest.MatcherAssert.assertThat; |
23 | import static org.hamcrest.Matchers.is; | 30 | import static org.hamcrest.Matchers.is; |
31 | +import static org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.*; | ||
24 | 32 | ||
25 | /** | 33 | /** |
26 | * Unit tests for DefaultLispMapRecord class. | 34 | * Unit tests for DefaultLispMapRecord class. |
... | @@ -35,29 +43,37 @@ public final class DefaultLispMapRecordTest { | ... | @@ -35,29 +43,37 @@ public final class DefaultLispMapRecordTest { |
35 | public void setup() { | 43 | public void setup() { |
36 | 44 | ||
37 | LispMapRecord.MapRecordBuilder builder1 = | 45 | LispMapRecord.MapRecordBuilder builder1 = |
38 | - new DefaultLispMapRecord.DefaultMapRecordBuilder(); | 46 | + new DefaultMapRecordBuilder(); |
47 | + | ||
48 | + LispIpv4Address ipv4Locator1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
39 | 49 | ||
40 | record1 = builder1 | 50 | record1 = builder1 |
41 | .withRecordTtl(100) | 51 | .withRecordTtl(100) |
42 | .withAuthoritative(true) | 52 | .withAuthoritative(true) |
43 | - .withLocatorCount(100) | 53 | + .withLocatorCount(0) |
44 | .withMapVersionNumber((short) 1) | 54 | .withMapVersionNumber((short) 1) |
45 | .withMaskLength((byte) 0x01) | 55 | .withMaskLength((byte) 0x01) |
56 | + .withAction(LispMapReplyAction.NativelyForward) | ||
57 | + .withEidPrefixAfi(ipv4Locator1) | ||
46 | .build(); | 58 | .build(); |
47 | 59 | ||
48 | LispMapRecord.MapRecordBuilder builder2 = | 60 | LispMapRecord.MapRecordBuilder builder2 = |
49 | - new DefaultLispMapRecord.DefaultMapRecordBuilder(); | 61 | + new DefaultMapRecordBuilder(); |
50 | 62 | ||
51 | sameAsRecord1 = builder2 | 63 | sameAsRecord1 = builder2 |
52 | .withRecordTtl(100) | 64 | .withRecordTtl(100) |
53 | .withAuthoritative(true) | 65 | .withAuthoritative(true) |
54 | - .withLocatorCount(100) | 66 | + .withLocatorCount(0) |
55 | .withMapVersionNumber((short) 1) | 67 | .withMapVersionNumber((short) 1) |
56 | .withMaskLength((byte) 0x01) | 68 | .withMaskLength((byte) 0x01) |
69 | + .withAction(LispMapReplyAction.NativelyForward) | ||
70 | + .withEidPrefixAfi(ipv4Locator1) | ||
57 | .build(); | 71 | .build(); |
58 | 72 | ||
59 | LispMapRecord.MapRecordBuilder builder3 = | 73 | LispMapRecord.MapRecordBuilder builder3 = |
60 | - new DefaultLispMapRecord.DefaultMapRecordBuilder(); | 74 | + new DefaultMapRecordBuilder(); |
75 | + | ||
76 | + LispIpv4Address ipv4Locator2 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2")); | ||
61 | 77 | ||
62 | record2 = builder3 | 78 | record2 = builder3 |
63 | .withRecordTtl(200) | 79 | .withRecordTtl(200) |
... | @@ -65,6 +81,8 @@ public final class DefaultLispMapRecordTest { | ... | @@ -65,6 +81,8 @@ public final class DefaultLispMapRecordTest { |
65 | .withLocatorCount(200) | 81 | .withLocatorCount(200) |
66 | .withMapVersionNumber((short) 2) | 82 | .withMapVersionNumber((short) 2) |
67 | .withMaskLength((byte) 0x02) | 83 | .withMaskLength((byte) 0x02) |
84 | + .withAction(LispMapReplyAction.Drop) | ||
85 | + .withEidPrefixAfi(ipv4Locator2) | ||
68 | .build(); | 86 | .build(); |
69 | } | 87 | } |
70 | 88 | ||
... | @@ -79,10 +97,28 @@ public final class DefaultLispMapRecordTest { | ... | @@ -79,10 +97,28 @@ public final class DefaultLispMapRecordTest { |
79 | public void testConstruction() { | 97 | public void testConstruction() { |
80 | DefaultLispMapRecord record = (DefaultLispMapRecord) record1; | 98 | DefaultLispMapRecord record = (DefaultLispMapRecord) record1; |
81 | 99 | ||
100 | + LispIpv4Address ipv4Locator = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
101 | + | ||
82 | assertThat(record.getRecordTtl(), is(100)); | 102 | assertThat(record.getRecordTtl(), is(100)); |
83 | assertThat(record.isAuthoritative(), is(true)); | 103 | assertThat(record.isAuthoritative(), is(true)); |
84 | - assertThat(record.getLocatorCount(), is(100)); | 104 | + assertThat(record.getLocatorCount(), is(0)); |
85 | assertThat(record.getMapVersionNumber(), is((short) 1)); | 105 | assertThat(record.getMapVersionNumber(), is((short) 1)); |
86 | assertThat(record.getMaskLength(), is((byte) 0x01)); | 106 | assertThat(record.getMaskLength(), is((byte) 0x01)); |
107 | + assertThat(record.getAction(), is(LispMapReplyAction.NativelyForward)); | ||
108 | + assertThat(record.getEidPrefixAfi(), is(ipv4Locator)); | ||
109 | + } | ||
110 | + | ||
111 | + @Test | ||
112 | + public void testSerialization() throws LispReaderException, LispWriterException, LispParseError { | ||
113 | + ByteBuf byteBuf = Unpooled.buffer(); | ||
114 | + | ||
115 | + MapRecordWriter writer = new MapRecordWriter(); | ||
116 | + writer.writeTo(byteBuf, record1); | ||
117 | + | ||
118 | + MapRecordReader reader = new MapRecordReader(); | ||
119 | + LispMapRecord deserialized = reader.readFrom(byteBuf); | ||
120 | + | ||
121 | + new EqualsTester() | ||
122 | + .addEqualityGroup(record1, deserialized).testEquals(); | ||
87 | } | 123 | } |
88 | } | 124 | } | ... | ... |
... | @@ -16,8 +16,15 @@ | ... | @@ -16,8 +16,15 @@ |
16 | package org.onosproject.lisp.msg.protocols; | 16 | package org.onosproject.lisp.msg.protocols; |
17 | 17 | ||
18 | import com.google.common.testing.EqualsTester; | 18 | import com.google.common.testing.EqualsTester; |
19 | +import io.netty.buffer.ByteBuf; | ||
20 | +import io.netty.buffer.Unpooled; | ||
19 | import org.junit.Before; | 21 | import org.junit.Before; |
20 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
24 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
25 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
26 | +import org.onosproject.lisp.msg.protocols.DefaultLispMapRegister.RegisterReader; | ||
27 | +import org.onosproject.lisp.msg.protocols.DefaultLispMapRegister.RegisterWriter; | ||
21 | 28 | ||
22 | import static org.hamcrest.MatcherAssert.assertThat; | 29 | import static org.hamcrest.MatcherAssert.assertThat; |
23 | import static org.hamcrest.Matchers.is; | 30 | import static org.hamcrest.Matchers.is; |
... | @@ -42,7 +49,7 @@ public final class DefaultLispMapRegisterTest { | ... | @@ -42,7 +49,7 @@ public final class DefaultLispMapRegisterTest { |
42 | .withIsWantMapNotify(false) | 49 | .withIsWantMapNotify(false) |
43 | .withKeyId((short) 1) | 50 | .withKeyId((short) 1) |
44 | .withNonce(1L) | 51 | .withNonce(1L) |
45 | - .withRecordCount((byte) 0x01) | 52 | + .withRecordCount((byte) 0) |
46 | .build(); | 53 | .build(); |
47 | 54 | ||
48 | LispMapRegister.RegisterBuilder builder2 = | 55 | LispMapRegister.RegisterBuilder builder2 = |
... | @@ -53,7 +60,7 @@ public final class DefaultLispMapRegisterTest { | ... | @@ -53,7 +60,7 @@ public final class DefaultLispMapRegisterTest { |
53 | .withIsWantMapNotify(false) | 60 | .withIsWantMapNotify(false) |
54 | .withKeyId((short) 1) | 61 | .withKeyId((short) 1) |
55 | .withNonce(1L) | 62 | .withNonce(1L) |
56 | - .withRecordCount((byte) 0x01) | 63 | + .withRecordCount((byte) 0) |
57 | .build(); | 64 | .build(); |
58 | 65 | ||
59 | LispMapRegister.RegisterBuilder builder3 = | 66 | LispMapRegister.RegisterBuilder builder3 = |
... | @@ -83,6 +90,20 @@ public final class DefaultLispMapRegisterTest { | ... | @@ -83,6 +90,20 @@ public final class DefaultLispMapRegisterTest { |
83 | assertThat(register.isWantMapNotify(), is(false)); | 90 | assertThat(register.isWantMapNotify(), is(false)); |
84 | assertThat(register.getKeyId(), is((short) 1)); | 91 | assertThat(register.getKeyId(), is((short) 1)); |
85 | assertThat(register.getNonce(), is(1L)); | 92 | assertThat(register.getNonce(), is(1L)); |
86 | - assertThat(register.getRecordCount(), is((byte) 0x01)); | 93 | + assertThat(register.getRecordCount(), is((byte) 0)); |
94 | + } | ||
95 | + | ||
96 | + @Test | ||
97 | + public void testSerialization() throws LispReaderException, LispWriterException, LispParseError { | ||
98 | + ByteBuf byteBuf = Unpooled.buffer(); | ||
99 | + | ||
100 | + RegisterWriter writer = new RegisterWriter(); | ||
101 | + writer.writeTo(byteBuf, register1); | ||
102 | + | ||
103 | + RegisterReader reader = new RegisterReader(); | ||
104 | + LispMapRegister deserialized = reader.readFrom(byteBuf); | ||
105 | + | ||
106 | + new EqualsTester() | ||
107 | + .addEqualityGroup(register1, deserialized).testEquals(); | ||
87 | } | 108 | } |
88 | } | 109 | } | ... | ... |
... | @@ -16,8 +16,15 @@ | ... | @@ -16,8 +16,15 @@ |
16 | package org.onosproject.lisp.msg.protocols; | 16 | package org.onosproject.lisp.msg.protocols; |
17 | 17 | ||
18 | import com.google.common.testing.EqualsTester; | 18 | import com.google.common.testing.EqualsTester; |
19 | +import io.netty.buffer.ByteBuf; | ||
20 | +import io.netty.buffer.Unpooled; | ||
19 | import org.junit.Before; | 21 | import org.junit.Before; |
20 | import org.junit.Test; | 22 | import org.junit.Test; |
23 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
24 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
25 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
26 | +import org.onosproject.lisp.msg.protocols.DefaultLispMapReply.ReplyReader; | ||
27 | +import org.onosproject.lisp.msg.protocols.DefaultLispMapReply.ReplyWriter; | ||
21 | 28 | ||
22 | import static org.hamcrest.MatcherAssert.assertThat; | 29 | import static org.hamcrest.MatcherAssert.assertThat; |
23 | import static org.hamcrest.Matchers.is; | 30 | import static org.hamcrest.Matchers.is; |
... | @@ -42,7 +49,7 @@ public final class DefaultLispMapReplyTest { | ... | @@ -42,7 +49,7 @@ public final class DefaultLispMapReplyTest { |
42 | .withIsProbe(false) | 49 | .withIsProbe(false) |
43 | .withIsSecurity(true) | 50 | .withIsSecurity(true) |
44 | .withNonce(1L) | 51 | .withNonce(1L) |
45 | - .withRecordCount((byte) 0x01) | 52 | + .withRecordCount((byte) 0) |
46 | .build(); | 53 | .build(); |
47 | 54 | ||
48 | LispMapReply.ReplyBuilder builder2 = | 55 | LispMapReply.ReplyBuilder builder2 = |
... | @@ -53,7 +60,7 @@ public final class DefaultLispMapReplyTest { | ... | @@ -53,7 +60,7 @@ public final class DefaultLispMapReplyTest { |
53 | .withIsProbe(false) | 60 | .withIsProbe(false) |
54 | .withIsSecurity(true) | 61 | .withIsSecurity(true) |
55 | .withNonce(1L) | 62 | .withNonce(1L) |
56 | - .withRecordCount((byte) 0x01) | 63 | + .withRecordCount((byte) 0) |
57 | .build(); | 64 | .build(); |
58 | 65 | ||
59 | LispMapReply.ReplyBuilder builder3 = | 66 | LispMapReply.ReplyBuilder builder3 = |
... | @@ -82,6 +89,19 @@ public final class DefaultLispMapReplyTest { | ... | @@ -82,6 +89,19 @@ public final class DefaultLispMapReplyTest { |
82 | assertThat(reply.isProbe(), is(false)); | 89 | assertThat(reply.isProbe(), is(false)); |
83 | assertThat(reply.isSecurity(), is(true)); | 90 | assertThat(reply.isSecurity(), is(true)); |
84 | assertThat(reply.getNonce(), is(1L)); | 91 | assertThat(reply.getNonce(), is(1L)); |
85 | - assertThat(reply.getRecordCount(), is((byte) 0x01)); | 92 | + assertThat(reply.getRecordCount(), is((byte) 0)); |
93 | + } | ||
94 | + | ||
95 | + @Test | ||
96 | + public void testSerialization() throws LispReaderException, LispWriterException, LispParseError { | ||
97 | + ByteBuf byteBuf = Unpooled.buffer(); | ||
98 | + ReplyWriter writer = new ReplyWriter(); | ||
99 | + writer.writeTo(byteBuf, reply1); | ||
100 | + | ||
101 | + ReplyReader reader = new ReplyReader(); | ||
102 | + LispMapReply deserialized = reader.readFrom(byteBuf); | ||
103 | + | ||
104 | + new EqualsTester() | ||
105 | + .addEqualityGroup(reply1, deserialized).testEquals(); | ||
86 | } | 106 | } |
87 | } | 107 | } | ... | ... |
... | @@ -15,12 +15,24 @@ | ... | @@ -15,12 +15,24 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.protocols; | 16 | package org.onosproject.lisp.msg.protocols; |
17 | 17 | ||
18 | +import com.google.common.collect.ImmutableList; | ||
18 | import com.google.common.testing.EqualsTester; | 19 | import com.google.common.testing.EqualsTester; |
20 | +import io.netty.buffer.ByteBuf; | ||
21 | +import io.netty.buffer.Unpooled; | ||
19 | import org.junit.Before; | 22 | import org.junit.Before; |
20 | import org.junit.Test; | 23 | import org.junit.Test; |
24 | +import org.onlab.packet.IpAddress; | ||
25 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
26 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
27 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
28 | +import org.onosproject.lisp.msg.types.LispAfiAddress; | ||
29 | +import org.onosproject.lisp.msg.types.LispIpv4Address; | ||
30 | + | ||
31 | +import java.util.List; | ||
21 | 32 | ||
22 | import static org.hamcrest.MatcherAssert.assertThat; | 33 | import static org.hamcrest.MatcherAssert.assertThat; |
23 | import static org.hamcrest.Matchers.is; | 34 | import static org.hamcrest.Matchers.is; |
35 | +import static org.onosproject.lisp.msg.protocols.DefaultLispMapRequest.*; | ||
24 | 36 | ||
25 | /** | 37 | /** |
26 | * Unit tests for DefaultLispMapRequest class. | 38 | * Unit tests for DefaultLispMapRequest class. |
... | @@ -34,8 +46,14 @@ public final class DefaultLispMapRequestTest { | ... | @@ -34,8 +46,14 @@ public final class DefaultLispMapRequestTest { |
34 | @Before | 46 | @Before |
35 | public void setup() { | 47 | public void setup() { |
36 | 48 | ||
37 | - LispMapRequest.RequestBuilder builder1 = | 49 | + RequestBuilder builder1 = new DefaultRequestBuilder(); |
38 | - new DefaultLispMapRequest.DefaultRequestBuilder(); | 50 | + |
51 | + LispIpv4Address ipv4Eid1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | ||
52 | + | ||
53 | + LispIpv4Address ipv4Rloc1 = new LispIpv4Address(IpAddress.valueOf("10.1.1.1")); | ||
54 | + LispIpv4Address ipv4Rloc2 = new LispIpv4Address(IpAddress.valueOf("10.1.1.2")); | ||
55 | + | ||
56 | + List<LispAfiAddress> rlocs1 = ImmutableList.of(ipv4Rloc1, ipv4Rloc2); | ||
39 | 57 | ||
40 | request1 = builder1 | 58 | request1 = builder1 |
41 | .withIsAuthoritative(true) | 59 | .withIsAuthoritative(true) |
... | @@ -44,12 +62,13 @@ public final class DefaultLispMapRequestTest { | ... | @@ -44,12 +62,13 @@ public final class DefaultLispMapRequestTest { |
44 | .withIsProbe(false) | 62 | .withIsProbe(false) |
45 | .withIsSmr(true) | 63 | .withIsSmr(true) |
46 | .withIsSmrInvoked(false) | 64 | .withIsSmrInvoked(false) |
65 | + .withSourceEid(ipv4Eid1) | ||
66 | + .withItrRlocs(rlocs1) | ||
47 | .withNonce(1L) | 67 | .withNonce(1L) |
48 | - .withRecordCount((byte) 0x01) | 68 | + .withRecordCount((byte) 0) |
49 | .build(); | 69 | .build(); |
50 | 70 | ||
51 | - LispMapRequest.RequestBuilder builder2 = | 71 | + RequestBuilder builder2 = new DefaultRequestBuilder(); |
52 | - new DefaultLispMapRequest.DefaultRequestBuilder(); | ||
53 | 72 | ||
54 | sameAsRequest1 = builder2 | 73 | sameAsRequest1 = builder2 |
55 | .withIsAuthoritative(true) | 74 | .withIsAuthoritative(true) |
... | @@ -58,12 +77,20 @@ public final class DefaultLispMapRequestTest { | ... | @@ -58,12 +77,20 @@ public final class DefaultLispMapRequestTest { |
58 | .withIsProbe(false) | 77 | .withIsProbe(false) |
59 | .withIsSmr(true) | 78 | .withIsSmr(true) |
60 | .withIsSmrInvoked(false) | 79 | .withIsSmrInvoked(false) |
80 | + .withSourceEid(ipv4Eid1) | ||
81 | + .withItrRlocs(rlocs1) | ||
61 | .withNonce(1L) | 82 | .withNonce(1L) |
62 | - .withRecordCount((byte) 0x01) | 83 | + .withRecordCount((byte) 0) |
63 | .build(); | 84 | .build(); |
64 | 85 | ||
65 | - LispMapRequest.RequestBuilder builder3 = | 86 | + RequestBuilder builder3 = new DefaultRequestBuilder(); |
66 | - new DefaultLispMapRequest.DefaultRequestBuilder(); | 87 | + |
88 | + LispIpv4Address ipv4Eid2 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2")); | ||
89 | + | ||
90 | + LispIpv4Address ipv4Rloc3 = new LispIpv4Address(IpAddress.valueOf("10.1.1.1")); | ||
91 | + LispIpv4Address ipv4Rloc4 = new LispIpv4Address(IpAddress.valueOf("10.1.1.2")); | ||
92 | + | ||
93 | + List<LispAfiAddress> rlocs2 = ImmutableList.of(ipv4Rloc3, ipv4Rloc4); | ||
67 | 94 | ||
68 | request2 = builder3 | 95 | request2 = builder3 |
69 | .withIsAuthoritative(false) | 96 | .withIsAuthoritative(false) |
... | @@ -72,6 +99,8 @@ public final class DefaultLispMapRequestTest { | ... | @@ -72,6 +99,8 @@ public final class DefaultLispMapRequestTest { |
72 | .withIsProbe(true) | 99 | .withIsProbe(true) |
73 | .withIsSmr(false) | 100 | .withIsSmr(false) |
74 | .withIsSmrInvoked(true) | 101 | .withIsSmrInvoked(true) |
102 | + .withSourceEid(ipv4Eid2) | ||
103 | + .withItrRlocs(rlocs2) | ||
75 | .withNonce(2L) | 104 | .withNonce(2L) |
76 | .withRecordCount((byte) 0x02) | 105 | .withRecordCount((byte) 0x02) |
77 | .build(); | 106 | .build(); |
... | @@ -95,6 +124,19 @@ public final class DefaultLispMapRequestTest { | ... | @@ -95,6 +124,19 @@ public final class DefaultLispMapRequestTest { |
95 | assertThat(request.isSmr(), is(true)); | 124 | assertThat(request.isSmr(), is(true)); |
96 | assertThat(request.isSmrInvoked(), is(false)); | 125 | assertThat(request.isSmrInvoked(), is(false)); |
97 | assertThat(request.getNonce(), is(1L)); | 126 | assertThat(request.getNonce(), is(1L)); |
98 | - assertThat(request.getRecordCount(), is((byte) 0x01)); | 127 | + assertThat(request.getRecordCount(), is((byte) 0)); |
128 | + } | ||
129 | + | ||
130 | + @Test | ||
131 | + public void testSerialization() throws LispReaderException, LispWriterException, LispParseError { | ||
132 | + ByteBuf byteBuf = Unpooled.buffer(); | ||
133 | + RequestWriter writer = new RequestWriter(); | ||
134 | + writer.writeTo(byteBuf, request1); | ||
135 | + | ||
136 | + RequestReader reader = new RequestReader(); | ||
137 | + LispMapRequest deserialized = reader.readFrom(byteBuf); | ||
138 | + | ||
139 | + new EqualsTester() | ||
140 | + .addEqualityGroup(request1, deserialized).testEquals(); | ||
99 | } | 141 | } |
100 | } | 142 | } | ... | ... |
... | @@ -61,7 +61,7 @@ public final class ByteOperator { | ... | @@ -61,7 +61,7 @@ public final class ByteOperator { |
61 | * @param decimal decimal formatted integer | 61 | * @param decimal decimal formatted integer |
62 | * @return hex formatted integer | 62 | * @return hex formatted integer |
63 | */ | 63 | */ |
64 | - private static int getHex(int decimal) { | 64 | + public static int getHex(int decimal) { |
65 | return Integer.valueOf(String.valueOf(decimal), 16); | 65 | return Integer.valueOf(String.valueOf(decimal), 16); |
66 | } | 66 | } |
67 | } | 67 | } | ... | ... |
-
Please register or login to post a comment