Committed by
Thomas Vachuska
[ONOS-4718] Deserialize addresses from LISP control message class
With this commit, we try to deserilize all LispAfiAddress from all LISP control message classes. Change-Id: Iaf911bff90c45a70859285e426dc1649c3e6db32
Showing
17 changed files
with
458 additions
and
87 deletions
| ... | @@ -19,6 +19,7 @@ import com.google.common.base.Objects; | ... | @@ -19,6 +19,7 @@ import com.google.common.base.Objects; |
| 19 | import io.netty.buffer.ByteBuf; | 19 | import io.netty.buffer.ByteBuf; |
| 20 | import org.onlab.util.ByteOperator; | 20 | import org.onlab.util.ByteOperator; |
| 21 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 21 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
| 22 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
| 22 | import org.onosproject.lisp.msg.types.LispAfiAddress; | 23 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
| 23 | 24 | ||
| 24 | import static com.google.common.base.MoreObjects.toStringHelper; | 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
| ... | @@ -222,7 +223,7 @@ public final class DefaultLispLocatorRecord implements LispLocatorRecord { | ... | @@ -222,7 +223,7 @@ public final class DefaultLispLocatorRecord implements LispLocatorRecord { |
| 222 | private static final int ROUTED_INDEX = 0; | 223 | private static final int ROUTED_INDEX = 0; |
| 223 | 224 | ||
| 224 | @Override | 225 | @Override |
| 225 | - public LispLocatorRecord readFrom(ByteBuf byteBuf) throws LispParseError { | 226 | + public LispLocatorRecord readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
| 226 | 227 | ||
| 227 | // priority -> 8 bits | 228 | // priority -> 8 bits |
| 228 | byte priority = (byte) byteBuf.readUnsignedByte(); | 229 | byte priority = (byte) byteBuf.readUnsignedByte(); |
| ... | @@ -250,7 +251,7 @@ public final class DefaultLispLocatorRecord implements LispLocatorRecord { | ... | @@ -250,7 +251,7 @@ public final class DefaultLispLocatorRecord implements LispLocatorRecord { |
| 250 | // routed flag -> 1 bit | 251 | // routed flag -> 1 bit |
| 251 | boolean routed = ByteOperator.getBit(flags, ROUTED_INDEX); | 252 | boolean routed = ByteOperator.getBit(flags, ROUTED_INDEX); |
| 252 | 253 | ||
| 253 | - // TODO: de-serialize ITR-RLOC AFI and address | 254 | + LispAfiAddress address = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
| 254 | 255 | ||
| 255 | return new DefaultLocatorRecordBuilder() | 256 | return new DefaultLocatorRecordBuilder() |
| 256 | .withPriority(priority) | 257 | .withPriority(priority) |
| ... | @@ -260,6 +261,7 @@ public final class DefaultLispLocatorRecord implements LispLocatorRecord { | ... | @@ -260,6 +261,7 @@ public final class DefaultLispLocatorRecord implements LispLocatorRecord { |
| 260 | .withLocalLocator(localLocator) | 261 | .withLocalLocator(localLocator) |
| 261 | .withRlocProbed(rlocProbed) | 262 | .withRlocProbed(rlocProbed) |
| 262 | .withRouted(routed) | 263 | .withRouted(routed) |
| 264 | + .withLocatorAfi(address) | ||
| 263 | .build(); | 265 | .build(); |
| 264 | } | 266 | } |
| 265 | } | 267 | } | ... | ... |
| ... | @@ -21,6 +21,7 @@ import com.google.common.collect.Lists; | ... | @@ -21,6 +21,7 @@ import com.google.common.collect.Lists; |
| 21 | import io.netty.buffer.ByteBuf; | 21 | import io.netty.buffer.ByteBuf; |
| 22 | import org.onlab.util.ImmutableByteSequence; | 22 | import org.onlab.util.ImmutableByteSequence; |
| 23 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 23 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
| 24 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
| 24 | 25 | ||
| 25 | import java.util.List; | 26 | import java.util.List; |
| 26 | 27 | ||
| ... | @@ -183,7 +184,7 @@ public final class DefaultLispMapNotify implements LispMapNotify { | ... | @@ -183,7 +184,7 @@ public final class DefaultLispMapNotify implements LispMapNotify { |
| 183 | private static final int RESERVED_SKIP_LENGTH = 3; | 184 | private static final int RESERVED_SKIP_LENGTH = 3; |
| 184 | 185 | ||
| 185 | @Override | 186 | @Override |
| 186 | - public LispMapNotify readFrom(ByteBuf byteBuf) throws LispParseError { | 187 | + public LispMapNotify readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
| 187 | 188 | ||
| 188 | if (byteBuf.readerIndex() != 0) { | 189 | if (byteBuf.readerIndex() != 0) { |
| 189 | return null; | 190 | return null; | ... | ... |
| ... | @@ -21,6 +21,7 @@ import com.google.common.collect.Lists; | ... | @@ -21,6 +21,7 @@ import com.google.common.collect.Lists; |
| 21 | import io.netty.buffer.ByteBuf; | 21 | import io.netty.buffer.ByteBuf; |
| 22 | import org.onlab.util.ByteOperator; | 22 | import org.onlab.util.ByteOperator; |
| 23 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 23 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
| 24 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
| 24 | import org.onosproject.lisp.msg.types.LispAfiAddress; | 25 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
| 25 | 26 | ||
| 26 | import java.util.List; | 27 | import java.util.List; |
| ... | @@ -225,7 +226,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { | ... | @@ -225,7 +226,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { |
| 225 | private static final int RESERVED_SKIP_LENGTH = 1; | 226 | private static final int RESERVED_SKIP_LENGTH = 1; |
| 226 | 227 | ||
| 227 | @Override | 228 | @Override |
| 228 | - public LispMapRecord readFrom(ByteBuf byteBuf) throws LispParseError { | 229 | + public LispMapRecord readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
| 229 | 230 | ||
| 230 | // Record TTL -> 32 bits | 231 | // Record TTL -> 32 bits |
| 231 | int recordTtl = byteBuf.readInt(); | 232 | int recordTtl = byteBuf.readInt(); |
| ... | @@ -249,7 +250,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { | ... | @@ -249,7 +250,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { |
| 249 | // Map version number -> 12 bits, we treat Rsvd field is all zero | 250 | // Map version number -> 12 bits, we treat Rsvd field is all zero |
| 250 | short mapVersionNumber = (short) byteBuf.readUnsignedShort(); | 251 | short mapVersionNumber = (short) byteBuf.readUnsignedShort(); |
| 251 | 252 | ||
| 252 | - // TODO: need to de-serialize EID AFI address | 253 | + LispAfiAddress eidPrefixAfi = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
| 253 | 254 | ||
| 254 | List<LispLocatorRecord> locators = Lists.newArrayList(); | 255 | List<LispLocatorRecord> locators = Lists.newArrayList(); |
| 255 | for (int i = 0; i < locatorCount; i++) { | 256 | for (int i = 0; i < locatorCount; i++) { |
| ... | @@ -263,6 +264,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { | ... | @@ -263,6 +264,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { |
| 263 | .withAuthoritative(authoritative) | 264 | .withAuthoritative(authoritative) |
| 264 | .withMapVersionNumber(mapVersionNumber) | 265 | .withMapVersionNumber(mapVersionNumber) |
| 265 | .withLocators(locators) | 266 | .withLocators(locators) |
| 267 | + .withEidPrefixAfi(eidPrefixAfi) | ||
| 266 | .build(); | 268 | .build(); |
| 267 | } | 269 | } |
| 268 | } | 270 | } | ... | ... |
| ... | @@ -22,6 +22,7 @@ import io.netty.buffer.ByteBuf; | ... | @@ -22,6 +22,7 @@ import io.netty.buffer.ByteBuf; |
| 22 | import org.onlab.util.ByteOperator; | 22 | import org.onlab.util.ByteOperator; |
| 23 | import org.onlab.util.ImmutableByteSequence; | 23 | import org.onlab.util.ImmutableByteSequence; |
| 24 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 24 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
| 25 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
| 25 | 26 | ||
| 26 | import java.util.List; | 27 | import java.util.List; |
| 27 | 28 | ||
| ... | @@ -110,7 +111,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -110,7 +111,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
| 110 | } | 111 | } |
| 111 | 112 | ||
| 112 | @Override | 113 | @Override |
| 113 | - public List<LispMapRecord> getLispRecords() { | 114 | + public List<LispMapRecord> getMapRecords() { |
| 114 | return ImmutableList.copyOf(mapRecords); | 115 | return ImmutableList.copyOf(mapRecords); |
| 115 | } | 116 | } |
| 116 | 117 | ||
| ... | @@ -224,7 +225,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -224,7 +225,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
| 224 | private static final int RESERVED_SKIP_LENGTH = 1; | 225 | private static final int RESERVED_SKIP_LENGTH = 1; |
| 225 | 226 | ||
| 226 | @Override | 227 | @Override |
| 227 | - public LispMapRegister readFrom(ByteBuf byteBuf) throws LispParseError { | 228 | + public LispMapRegister readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
| 228 | 229 | ||
| 229 | if (byteBuf.readerIndex() != 0) { | 230 | if (byteBuf.readerIndex() != 0) { |
| 230 | return null; | 231 | return null; | ... | ... |
| ... | @@ -16,9 +16,14 @@ | ... | @@ -16,9 +16,14 @@ |
| 16 | package org.onosproject.lisp.msg.protocols; | 16 | package org.onosproject.lisp.msg.protocols; |
| 17 | 17 | ||
| 18 | import com.google.common.base.Objects; | 18 | import com.google.common.base.Objects; |
| 19 | +import com.google.common.collect.ImmutableList; | ||
| 20 | +import com.google.common.collect.Lists; | ||
| 19 | import io.netty.buffer.ByteBuf; | 21 | import io.netty.buffer.ByteBuf; |
| 20 | import org.onlab.util.ByteOperator; | 22 | import org.onlab.util.ByteOperator; |
| 21 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 23 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
| 24 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
| 25 | + | ||
| 26 | +import java.util.List; | ||
| 22 | 27 | ||
| 23 | import static com.google.common.base.MoreObjects.toStringHelper; | 28 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 24 | 29 | ||
| ... | @@ -32,6 +37,7 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -32,6 +37,7 @@ public final class DefaultLispMapReply implements LispMapReply { |
| 32 | private final boolean probe; | 37 | private final boolean probe; |
| 33 | private final boolean etr; | 38 | private final boolean etr; |
| 34 | private final boolean security; | 39 | private final boolean security; |
| 40 | + private final List<LispMapRecord> mapRecords; | ||
| 35 | 41 | ||
| 36 | /** | 42 | /** |
| 37 | * A private constructor that protects object instantiation from external. | 43 | * A private constructor that protects object instantiation from external. |
| ... | @@ -43,12 +49,13 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -43,12 +49,13 @@ public final class DefaultLispMapReply implements LispMapReply { |
| 43 | * @param security security flag | 49 | * @param security security flag |
| 44 | */ | 50 | */ |
| 45 | private DefaultLispMapReply(long nonce, byte recordCount, boolean probe, | 51 | private DefaultLispMapReply(long nonce, byte recordCount, boolean probe, |
| 46 | - boolean etr, boolean security) { | 52 | + boolean etr, boolean security, List<LispMapRecord> mapRecords) { |
| 47 | this.nonce = nonce; | 53 | this.nonce = nonce; |
| 48 | this.recordCount = recordCount; | 54 | this.recordCount = recordCount; |
| 49 | this.probe = probe; | 55 | this.probe = probe; |
| 50 | this.etr = etr; | 56 | this.etr = etr; |
| 51 | this.security = security; | 57 | this.security = security; |
| 58 | + this.mapRecords = mapRecords; | ||
| 52 | } | 59 | } |
| 53 | 60 | ||
| 54 | @Override | 61 | @Override |
| ... | @@ -92,6 +99,11 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -92,6 +99,11 @@ public final class DefaultLispMapReply implements LispMapReply { |
| 92 | } | 99 | } |
| 93 | 100 | ||
| 94 | @Override | 101 | @Override |
| 102 | + public List<LispMapRecord> getMapRecords() { | ||
| 103 | + return ImmutableList.copyOf(mapRecords); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + @Override | ||
| 95 | public String toString() { | 107 | public String toString() { |
| 96 | return toStringHelper(this) | 108 | return toStringHelper(this) |
| 97 | .add("type", getType()) | 109 | .add("type", getType()) |
| ... | @@ -99,7 +111,8 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -99,7 +111,8 @@ public final class DefaultLispMapReply implements LispMapReply { |
| 99 | .add("recordCount", recordCount) | 111 | .add("recordCount", recordCount) |
| 100 | .add("probe", probe) | 112 | .add("probe", probe) |
| 101 | .add("etr", etr) | 113 | .add("etr", etr) |
| 102 | - .add("security", security).toString(); | 114 | + .add("security", security) |
| 115 | + .add("map records", mapRecords).toString(); | ||
| 103 | } | 116 | } |
| 104 | 117 | ||
| 105 | @Override | 118 | @Override |
| ... | @@ -115,12 +128,13 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -115,12 +128,13 @@ public final class DefaultLispMapReply implements LispMapReply { |
| 115 | Objects.equal(recordCount, that.recordCount) && | 128 | Objects.equal(recordCount, that.recordCount) && |
| 116 | Objects.equal(probe, that.probe) && | 129 | Objects.equal(probe, that.probe) && |
| 117 | Objects.equal(etr, that.etr) && | 130 | Objects.equal(etr, that.etr) && |
| 118 | - Objects.equal(security, that.security); | 131 | + Objects.equal(security, that.security) && |
| 132 | + Objects.equal(mapRecords, that.mapRecords); | ||
| 119 | } | 133 | } |
| 120 | 134 | ||
| 121 | @Override | 135 | @Override |
| 122 | public int hashCode() { | 136 | public int hashCode() { |
| 123 | - return Objects.hashCode(nonce, recordCount, probe, etr, security); | 137 | + return Objects.hashCode(nonce, recordCount, probe, etr, security, mapRecords); |
| 124 | } | 138 | } |
| 125 | 139 | ||
| 126 | public static final class DefaultReplyBuilder implements ReplyBuilder { | 140 | public static final class DefaultReplyBuilder implements ReplyBuilder { |
| ... | @@ -130,6 +144,7 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -130,6 +144,7 @@ public final class DefaultLispMapReply implements LispMapReply { |
| 130 | private boolean probe; | 144 | private boolean probe; |
| 131 | private boolean etr; | 145 | private boolean etr; |
| 132 | private boolean security; | 146 | private boolean security; |
| 147 | + private List<LispMapRecord> mapRecords; | ||
| 133 | 148 | ||
| 134 | @Override | 149 | @Override |
| 135 | public LispType getType() { | 150 | public LispType getType() { |
| ... | @@ -167,8 +182,14 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -167,8 +182,14 @@ public final class DefaultLispMapReply implements LispMapReply { |
| 167 | } | 182 | } |
| 168 | 183 | ||
| 169 | @Override | 184 | @Override |
| 185 | + public ReplyBuilder withMapRecords(List<LispMapRecord> mapRecords) { | ||
| 186 | + this.mapRecords = ImmutableList.copyOf(mapRecords); | ||
| 187 | + return this; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + @Override | ||
| 170 | public LispMapReply build() { | 191 | public LispMapReply build() { |
| 171 | - return new DefaultLispMapReply(nonce, recordCount, probe, etr, security); | 192 | + return new DefaultLispMapReply(nonce, recordCount, probe, etr, security, mapRecords); |
| 172 | } | 193 | } |
| 173 | } | 194 | } |
| 174 | 195 | ||
| ... | @@ -183,7 +204,7 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -183,7 +204,7 @@ public final class DefaultLispMapReply implements LispMapReply { |
| 183 | private static final int RESERVED_SKIP_LENGTH = 2; | 204 | private static final int RESERVED_SKIP_LENGTH = 2; |
| 184 | 205 | ||
| 185 | @Override | 206 | @Override |
| 186 | - public LispMapReply readFrom(ByteBuf byteBuf) throws LispParseError { | 207 | + public LispMapReply readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
| 187 | 208 | ||
| 188 | if (byteBuf.readerIndex() != 0) { | 209 | if (byteBuf.readerIndex() != 0) { |
| 189 | return null; | 210 | return null; |
| ... | @@ -209,7 +230,10 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -209,7 +230,10 @@ public final class DefaultLispMapReply implements LispMapReply { |
| 209 | // nonce -> 64 bits | 230 | // nonce -> 64 bits |
| 210 | long nonce = byteBuf.readLong(); | 231 | long nonce = byteBuf.readLong(); |
| 211 | 232 | ||
| 212 | - // TODO: need to de-serialize EID-RLOC records | 233 | + List<LispMapRecord> mapRecords = Lists.newArrayList(); |
| 234 | + for (int i = 0; i < recordCount; i++) { | ||
| 235 | + mapRecords.add(new DefaultLispMapRecord.MapRecordReader().readFrom(byteBuf)); | ||
| 236 | + } | ||
| 213 | 237 | ||
| 214 | return new DefaultReplyBuilder() | 238 | return new DefaultReplyBuilder() |
| 215 | .withIsProbe(probe) | 239 | .withIsProbe(probe) | ... | ... |
| ... | @@ -21,6 +21,7 @@ import com.google.common.collect.Lists; | ... | @@ -21,6 +21,7 @@ import com.google.common.collect.Lists; |
| 21 | import io.netty.buffer.ByteBuf; | 21 | import io.netty.buffer.ByteBuf; |
| 22 | import org.onlab.util.ByteOperator; | 22 | import org.onlab.util.ByteOperator; |
| 23 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 23 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
| 24 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
| 24 | import org.onosproject.lisp.msg.types.LispAfiAddress; | 25 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
| 25 | 26 | ||
| 26 | import java.util.List; | 27 | import java.util.List; |
| ... | @@ -296,7 +297,7 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -296,7 +297,7 @@ public final class DefaultLispMapRequest implements LispMapRequest { |
| 296 | private static final int SMR_INVOKED_INDEX = 6; | 297 | private static final int SMR_INVOKED_INDEX = 6; |
| 297 | 298 | ||
| 298 | @Override | 299 | @Override |
| 299 | - public LispMapRequest readFrom(ByteBuf byteBuf) throws LispParseError { | 300 | + public LispMapRequest readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
| 300 | 301 | ||
| 301 | if (byteBuf.readerIndex() != 0) { | 302 | if (byteBuf.readerIndex() != 0) { |
| 302 | return null; | 303 | return null; |
| ... | @@ -335,11 +336,19 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -335,11 +336,19 @@ public final class DefaultLispMapRequest implements LispMapRequest { |
| 335 | // nonce -> 64 bits | 336 | // nonce -> 64 bits |
| 336 | long nonce = byteBuf.readLong(); | 337 | long nonce = byteBuf.readLong(); |
| 337 | 338 | ||
| 338 | - // TODO: de-serialize source EID AFI and address | 339 | + LispAfiAddress sourceEid = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
| 339 | 340 | ||
| 340 | - // TODO: de-serialize ITR-RLOC AFI and address | 341 | + // deserialize a collection of RLOC addresses |
| 342 | + List<LispAfiAddress> itrRlocs = Lists.newArrayList(); | ||
| 343 | + for (int i = 0; i < irc; i++) { | ||
| 344 | + itrRlocs.add(new LispAfiAddress.AfiAddressReader().readFrom(byteBuf)); | ||
| 345 | + } | ||
| 341 | 346 | ||
| 342 | - // TODO: de-serialize EID-RECORD | 347 | + // deserialize a collection of EID records |
| 348 | + List<LispEidRecord> eidRecords = Lists.newArrayList(); | ||
| 349 | + for (int i = 0; i < recordCount; i++) { | ||
| 350 | + eidRecords.add(new LispEidRecord.EidRecordReader().readFrom(byteBuf)); | ||
| 351 | + } | ||
| 343 | 352 | ||
| 344 | return new DefaultRequestBuilder() | 353 | return new DefaultRequestBuilder() |
| 345 | .withIsAuthoritative(authoritative) | 354 | .withIsAuthoritative(authoritative) |
| ... | @@ -350,6 +359,9 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -350,6 +359,9 @@ public final class DefaultLispMapRequest implements LispMapRequest { |
| 350 | .withIsSmrInvoked(smrInvoked) | 359 | .withIsSmrInvoked(smrInvoked) |
| 351 | .withNonce(nonce) | 360 | .withNonce(nonce) |
| 352 | .withRecordCount((byte) recordCount) | 361 | .withRecordCount((byte) recordCount) |
| 362 | + .withSourceEid(sourceEid) | ||
| 363 | + .withEidRecords(eidRecords) | ||
| 364 | + .withItrRlocs(itrRlocs) | ||
| 353 | .build(); | 365 | .build(); |
| 354 | } | 366 | } |
| 355 | } | 367 | } | ... | ... |
| ... | @@ -17,6 +17,7 @@ package org.onosproject.lisp.msg.protocols; | ... | @@ -17,6 +17,7 @@ package org.onosproject.lisp.msg.protocols; |
| 17 | 17 | ||
| 18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
| 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
| 20 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
| 20 | import org.onosproject.lisp.msg.types.LispAfiAddress; | 21 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
| 21 | 22 | ||
| 22 | /** | 23 | /** |
| ... | @@ -59,20 +60,19 @@ public final class LispEidRecord { | ... | @@ -59,20 +60,19 @@ public final class LispEidRecord { |
| 59 | /** | 60 | /** |
| 60 | * A private LISP message reader for EidRecord portion. | 61 | * A private LISP message reader for EidRecord portion. |
| 61 | */ | 62 | */ |
| 62 | - private static class EidRecordReader implements LispMessageReader<LispEidRecord> { | 63 | + public static class EidRecordReader implements LispMessageReader<LispEidRecord> { |
| 63 | 64 | ||
| 64 | private static final int RESERVED_SKIP_LENGTH = 1; | 65 | private static final int RESERVED_SKIP_LENGTH = 1; |
| 65 | 66 | ||
| 66 | @Override | 67 | @Override |
| 67 | - public LispEidRecord readFrom(ByteBuf byteBuf) throws LispParseError { | 68 | + public LispEidRecord readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
| 68 | 69 | ||
| 69 | // let's skip the reserved field | 70 | // let's skip the reserved field |
| 70 | byteBuf.skipBytes(RESERVED_SKIP_LENGTH); | 71 | byteBuf.skipBytes(RESERVED_SKIP_LENGTH); |
| 71 | 72 | ||
| 72 | short maskLength = (short) byteBuf.readUnsignedShort(); | 73 | short maskLength = (short) byteBuf.readUnsignedShort(); |
| 73 | 74 | ||
| 74 | - // TODO: need to de-serialize AFI address | 75 | + LispAfiAddress prefix = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
| 75 | - LispAfiAddress prefix = null; | ||
| 76 | 76 | ||
| 77 | return new LispEidRecord((byte) maskLength, prefix); | 77 | return new LispEidRecord((byte) maskLength, prefix); |
| 78 | } | 78 | } | ... | ... |
| ... | @@ -103,7 +103,7 @@ public interface LispMapRegister extends LispMessage { | ... | @@ -103,7 +103,7 @@ public interface LispMapRegister extends LispMessage { |
| 103 | * | 103 | * |
| 104 | * @return a collection of records | 104 | * @return a collection of records |
| 105 | */ | 105 | */ |
| 106 | - List<LispMapRecord> getLispRecords(); | 106 | + List<LispMapRecord> getMapRecords(); |
| 107 | 107 | ||
| 108 | /** | 108 | /** |
| 109 | * A builder of LISP map register message. | 109 | * A builder of LISP map register message. | ... | ... |
| ... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.lisp.msg.protocols; | 16 | package org.onosproject.lisp.msg.protocols; |
| 17 | 17 | ||
| 18 | +import java.util.List; | ||
| 19 | + | ||
| 18 | /** | 20 | /** |
| 19 | * LISP map reply message interface. | 21 | * LISP map reply message interface. |
| 20 | * <p> | 22 | * <p> |
| ... | @@ -86,6 +88,13 @@ public interface LispMapReply extends LispMessage { | ... | @@ -86,6 +88,13 @@ public interface LispMapReply extends LispMessage { |
| 86 | long getNonce(); | 88 | long getNonce(); |
| 87 | 89 | ||
| 88 | /** | 90 | /** |
| 91 | + * Obtains map records. | ||
| 92 | + * | ||
| 93 | + * @return map records | ||
| 94 | + */ | ||
| 95 | + List<LispMapRecord> getMapRecords(); | ||
| 96 | + | ||
| 97 | + /** | ||
| 89 | * A builder of LISP map reply message. | 98 | * A builder of LISP map reply message. |
| 90 | */ | 99 | */ |
| 91 | interface ReplyBuilder extends Builder { | 100 | interface ReplyBuilder extends Builder { |
| ... | @@ -131,6 +140,14 @@ public interface LispMapReply extends LispMessage { | ... | @@ -131,6 +140,14 @@ public interface LispMapReply extends LispMessage { |
| 131 | ReplyBuilder withNonce(long nonce); | 140 | ReplyBuilder withNonce(long nonce); |
| 132 | 141 | ||
| 133 | /** | 142 | /** |
| 143 | + * Sets a collection of map records. | ||
| 144 | + * | ||
| 145 | + * @param mapRecords a collection of map records | ||
| 146 | + * @return ReplyBuilder object | ||
| 147 | + */ | ||
| 148 | + ReplyBuilder withMapRecords(List<LispMapRecord> mapRecords); | ||
| 149 | + | ||
| 150 | + /** | ||
| 134 | * Builds LISP map reply message. | 151 | * Builds LISP map reply message. |
| 135 | * | 152 | * |
| 136 | * @return LISP map reply message | 153 | * @return LISP map reply message | ... | ... |
| ... | @@ -17,6 +17,7 @@ package org.onosproject.lisp.msg.protocols; | ... | @@ -17,6 +17,7 @@ package org.onosproject.lisp.msg.protocols; |
| 17 | 17 | ||
| 18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
| 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
| 20 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
| 20 | 21 | ||
| 21 | /** | 22 | /** |
| 22 | * An interface for de-serializing LISP control message. | 23 | * An interface for de-serializing LISP control message. |
| ... | @@ -30,5 +31,5 @@ public interface LispMessageReader<T> { | ... | @@ -30,5 +31,5 @@ public interface LispMessageReader<T> { |
| 30 | * @return LISP message instance | 31 | * @return LISP message instance |
| 31 | * @throws LispParseError LISP control message parse error | 32 | * @throws LispParseError LISP control message parse error |
| 32 | */ | 33 | */ |
| 33 | - T readFrom(ByteBuf byteBuf) throws LispParseError; | 34 | + T readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException; |
| 34 | } | 35 | } | ... | ... |
| ... | @@ -15,8 +15,14 @@ | ... | @@ -15,8 +15,14 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
| 17 | 17 | ||
| 18 | +import io.netty.buffer.ByteBuf; | ||
| 19 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
| 20 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
| 21 | + | ||
| 18 | import java.util.Objects; | 22 | import java.util.Objects; |
| 19 | 23 | ||
| 24 | +import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.*; | ||
| 25 | + | ||
| 20 | /** | 26 | /** |
| 21 | * LISP Locator address typed by Address Family Identifier (AFI). | 27 | * LISP Locator address typed by Address Family Identifier (AFI). |
| 22 | */ | 28 | */ |
| ... | @@ -67,4 +73,45 @@ public abstract class LispAfiAddress { | ... | @@ -67,4 +73,45 @@ public abstract class LispAfiAddress { |
| 67 | } | 73 | } |
| 68 | return true; | 74 | return true; |
| 69 | } | 75 | } |
| 76 | + | ||
| 77 | + public static class AfiAddressReader implements LispAddressReader<LispAfiAddress> { | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public LispAfiAddress readFrom(ByteBuf byteBuf) | ||
| 81 | + throws LispParseError, LispReaderException { | ||
| 82 | + | ||
| 83 | + int index = byteBuf.readerIndex(); | ||
| 84 | + | ||
| 85 | + // AFI code -> 16 bits | ||
| 86 | + short afiCode = (short) byteBuf.getUnsignedShort(index); | ||
| 87 | + | ||
| 88 | + // handle IPv4 and IPv6 address | ||
| 89 | + if (afiCode == IP.getIanaCode() || | ||
| 90 | + afiCode == IP6.getIanaCode()) { | ||
| 91 | + return new LispIpAddress.IpAddressReader().readFrom(byteBuf); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + // handle distinguished name address | ||
| 95 | + if (afiCode == DISTINGUISHED_NAME.getIanaCode()) { | ||
| 96 | + return new LispDistinguishedNameAddress.DistinguishedNameAddressReader().readFrom(byteBuf); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + // handle MAC address | ||
| 100 | + if (afiCode == MAC.getIanaCode()) { | ||
| 101 | + return new LispMacAddress.MacAddressReader().readFrom(byteBuf); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + // handle LCAF address | ||
| 105 | + if (afiCode == LCAF.getIanaCode()) { | ||
| 106 | + return new LispLcafAddress.LcafAddressReader().readFrom(byteBuf); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + // handle autonomous system address | ||
| 110 | + if (afiCode == AS.getIanaCode()) { | ||
| 111 | + return new LispAsAddress.AsAddressReader().readFrom(byteBuf); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + return null; | ||
| 115 | + } | ||
| 116 | + } | ||
| 70 | } | 117 | } | ... | ... |
| ... | @@ -60,6 +60,8 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -60,6 +60,8 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 60 | private LispAfiAddress address; | 60 | private LispAfiAddress address; |
| 61 | 61 | ||
| 62 | /** | 62 | /** |
| 63 | + * Initializes application data type LCAF address. | ||
| 64 | + * | ||
| 63 | * @param protocol protocol number | 65 | * @param protocol protocol number |
| 64 | * @param ipTos IP type of service | 66 | * @param ipTos IP type of service |
| 65 | * @param localPortLow low-ranged local port number | 67 | * @param localPortLow low-ranged local port number |
| ... | @@ -82,6 +84,35 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -82,6 +84,35 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 82 | } | 84 | } |
| 83 | 85 | ||
| 84 | /** | 86 | /** |
| 87 | + * Initializes application data type LCAF address. | ||
| 88 | + * | ||
| 89 | + * @param reserved1 reserved1 | ||
| 90 | + * @param reserved2 reserved2 | ||
| 91 | + * @param flag flag | ||
| 92 | + * @param length length | ||
| 93 | + * @param protocol protocol number | ||
| 94 | + * @param ipTos IP type of service | ||
| 95 | + * @param localPortLow low-ranged local port number | ||
| 96 | + * @param localPortHigh high-ranged local port number | ||
| 97 | + * @param remotePortLow low-ranged remote port number | ||
| 98 | + * @param remotePortHigh high-ranged remote port number | ||
| 99 | + * @param address address | ||
| 100 | + */ | ||
| 101 | + private LispAppDataLcafAddress(byte reserved1, byte reserved2, byte flag, short length, | ||
| 102 | + byte protocol, int ipTos, short localPortLow, | ||
| 103 | + short localPortHigh, short remotePortLow, | ||
| 104 | + short remotePortHigh, LispAfiAddress address) { | ||
| 105 | + super(LispCanonicalAddressFormatEnum.APPLICATION_DATA, reserved1, reserved2, flag, length); | ||
| 106 | + this.protocol = protocol; | ||
| 107 | + this.ipTos = ipTos; | ||
| 108 | + this.localPortLow = localPortLow; | ||
| 109 | + this.localPortHigh = localPortHigh; | ||
| 110 | + this.remotePortLow = remotePortLow; | ||
| 111 | + this.remotePortHigh = remotePortHigh; | ||
| 112 | + this.address = address; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /** | ||
| 85 | * Obtains protocol number. | 116 | * Obtains protocol number. |
| 86 | * | 117 | * |
| 87 | * @return protocol number | 118 | * @return protocol number |
| ... | @@ -182,7 +213,8 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -182,7 +213,8 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 182 | .toString(); | 213 | .toString(); |
| 183 | } | 214 | } |
| 184 | 215 | ||
| 185 | - public static final class AppDataAddressBuilder { | 216 | + public static final class AppDataAddressBuilder |
| 217 | + extends LcafAddressBuilder<AppDataAddressBuilder> { | ||
| 186 | private byte protocol; | 218 | private byte protocol; |
| 187 | private int ipTos; | 219 | private int ipTos; |
| 188 | private short localPortLow; | 220 | private short localPortLow; |
| ... | @@ -197,7 +229,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -197,7 +229,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 197 | * @param protocol protocol number | 229 | * @param protocol protocol number |
| 198 | * @return AppDataAddressBuilder object | 230 | * @return AppDataAddressBuilder object |
| 199 | */ | 231 | */ |
| 200 | - AppDataAddressBuilder withProtocol(byte protocol) { | 232 | + public AppDataAddressBuilder withProtocol(byte protocol) { |
| 201 | this.protocol = protocol; | 233 | this.protocol = protocol; |
| 202 | return this; | 234 | return this; |
| 203 | } | 235 | } |
| ... | @@ -208,7 +240,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -208,7 +240,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 208 | * @param ipTos IP type of service | 240 | * @param ipTos IP type of service |
| 209 | * @return AppDataAddressBuilder object | 241 | * @return AppDataAddressBuilder object |
| 210 | */ | 242 | */ |
| 211 | - AppDataAddressBuilder withIpTos(int ipTos) { | 243 | + public AppDataAddressBuilder withIpTos(int ipTos) { |
| 212 | this.ipTos = ipTos; | 244 | this.ipTos = ipTos; |
| 213 | return this; | 245 | return this; |
| 214 | } | 246 | } |
| ... | @@ -219,7 +251,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -219,7 +251,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 219 | * @param localPortLow low-ranged local port number | 251 | * @param localPortLow low-ranged local port number |
| 220 | * @return AppDataAddressBuilder object | 252 | * @return AppDataAddressBuilder object |
| 221 | */ | 253 | */ |
| 222 | - AppDataAddressBuilder withLocalPortLow(short localPortLow) { | 254 | + public AppDataAddressBuilder withLocalPortLow(short localPortLow) { |
| 223 | this.localPortLow = localPortLow; | 255 | this.localPortLow = localPortLow; |
| 224 | return this; | 256 | return this; |
| 225 | } | 257 | } |
| ... | @@ -230,7 +262,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -230,7 +262,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 230 | * @param localPortHigh high-ranged local port number | 262 | * @param localPortHigh high-ranged local port number |
| 231 | * @return AppDataAddressBuilder object | 263 | * @return AppDataAddressBuilder object |
| 232 | */ | 264 | */ |
| 233 | - AppDataAddressBuilder withLocalPortHigh(short localPortHigh) { | 265 | + public AppDataAddressBuilder withLocalPortHigh(short localPortHigh) { |
| 234 | this.localPortHigh = localPortHigh; | 266 | this.localPortHigh = localPortHigh; |
| 235 | return this; | 267 | return this; |
| 236 | } | 268 | } |
| ... | @@ -241,7 +273,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -241,7 +273,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 241 | * @param remotePortLow low-ranged remote port number | 273 | * @param remotePortLow low-ranged remote port number |
| 242 | * @return AppDataAddressBuilder object | 274 | * @return AppDataAddressBuilder object |
| 243 | */ | 275 | */ |
| 244 | - AppDataAddressBuilder withRemotePortLow(short remotePortLow) { | 276 | + public AppDataAddressBuilder withRemotePortLow(short remotePortLow) { |
| 245 | this.remotePortLow = remotePortLow; | 277 | this.remotePortLow = remotePortLow; |
| 246 | return this; | 278 | return this; |
| 247 | } | 279 | } |
| ... | @@ -252,7 +284,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -252,7 +284,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 252 | * @param remotePortHigh high-ranged remote port number | 284 | * @param remotePortHigh high-ranged remote port number |
| 253 | * @return AppDataAddressBuilder object | 285 | * @return AppDataAddressBuilder object |
| 254 | */ | 286 | */ |
| 255 | - AppDataAddressBuilder withRemotePortHigh(short remotePortHigh) { | 287 | + public AppDataAddressBuilder withRemotePortHigh(short remotePortHigh) { |
| 256 | this.remotePortHigh = remotePortHigh; | 288 | this.remotePortHigh = remotePortHigh; |
| 257 | return this; | 289 | return this; |
| 258 | } | 290 | } |
| ... | @@ -263,7 +295,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -263,7 +295,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 263 | * @param address AFI address | 295 | * @param address AFI address |
| 264 | * @return AppDataAddressBuilder object | 296 | * @return AppDataAddressBuilder object |
| 265 | */ | 297 | */ |
| 266 | - AppDataAddressBuilder withAddress(LispAfiAddress address) { | 298 | + public AppDataAddressBuilder withAddress(LispAfiAddress address) { |
| 267 | this.address = address; | 299 | this.address = address; |
| 268 | return this; | 300 | return this; |
| 269 | } | 301 | } |
| ... | @@ -273,9 +305,10 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -273,9 +305,10 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 273 | * | 305 | * |
| 274 | * @return LispAddDataLcafAddress instance | 306 | * @return LispAddDataLcafAddress instance |
| 275 | */ | 307 | */ |
| 276 | - LispAppDataLcafAddress build() { | 308 | + public LispAppDataLcafAddress build() { |
| 277 | - return new LispAppDataLcafAddress(protocol, ipTos, localPortLow, | 309 | + return new LispAppDataLcafAddress(reserved1, reserved2, flag, length, |
| 278 | - localPortHigh, remotePortLow, remotePortHigh, address); | 310 | + protocol, ipTos, localPortLow, localPortHigh, remotePortLow, |
| 311 | + remotePortHigh, address); | ||
| 279 | } | 312 | } |
| 280 | } | 313 | } |
| 281 | 314 | ||
| ... | @@ -288,6 +321,8 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -288,6 +321,8 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 288 | @Override | 321 | @Override |
| 289 | public LispAppDataLcafAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { | 322 | public LispAppDataLcafAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
| 290 | 323 | ||
| 324 | + LispLcafAddress lcafAddress = LispLcafAddress.deserializeCommon(byteBuf); | ||
| 325 | + | ||
| 291 | byte[] ipTosByte = new byte[3]; | 326 | byte[] ipTosByte = new byte[3]; |
| 292 | byteBuf.readBytes(ipTosByte); | 327 | byteBuf.readBytes(ipTosByte); |
| 293 | 328 | ||
| ... | @@ -298,17 +333,21 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -298,17 +333,21 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
| 298 | short remotePortLow = (short) byteBuf.readUnsignedShort(); | 333 | short remotePortLow = (short) byteBuf.readUnsignedShort(); |
| 299 | short remotePortHigh = (short) byteBuf.readUnsignedShort(); | 334 | short remotePortHigh = (short) byteBuf.readUnsignedShort(); |
| 300 | 335 | ||
| 301 | - LispAfiAddress address = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | 336 | + LispAfiAddress address = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
| 302 | 337 | ||
| 303 | return new AppDataAddressBuilder() | 338 | return new AppDataAddressBuilder() |
| 304 | - .withProtocol(protocol) | 339 | + .withReserved1(lcafAddress.getReserved1()) |
| 305 | - .withIpTos(ipTos) | 340 | + .withReserved2(lcafAddress.getReserved2()) |
| 306 | - .withLocalPortLow(localPortLow) | 341 | + .withFlag(lcafAddress.getFlag()) |
| 307 | - .withLocalPortHigh(localPortHigh) | 342 | + .withLength(lcafAddress.getLength()) |
| 308 | - .withRemotePortLow(remotePortLow) | 343 | + .withProtocol(protocol) |
| 309 | - .withRemotePortHigh(remotePortHigh) | 344 | + .withIpTos(ipTos) |
| 310 | - .withAddress(address) | 345 | + .withLocalPortLow(localPortLow) |
| 311 | - .build(); | 346 | + .withLocalPortHigh(localPortHigh) |
| 347 | + .withRemotePortLow(remotePortLow) | ||
| 348 | + .withRemotePortHigh(remotePortHigh) | ||
| 349 | + .withAddress(address) | ||
| 350 | + .build(); | ||
| 312 | } | 351 | } |
| 313 | 352 | ||
| 314 | /** | 353 | /** | ... | ... |
| ... | @@ -15,9 +15,14 @@ | ... | @@ -15,9 +15,14 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
| 17 | 17 | ||
| 18 | +import io.netty.buffer.ByteBuf; | ||
| 19 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
| 20 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
| 21 | + | ||
| 18 | import java.util.Objects; | 22 | import java.util.Objects; |
| 19 | 23 | ||
| 20 | import static com.google.common.base.MoreObjects.toStringHelper; | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | +import static org.onosproject.lisp.msg.types.LispCanonicalAddressFormatEnum.*; | ||
| 21 | 26 | ||
| 22 | /** | 27 | /** |
| 23 | * LISP Canonical Address Formatted address class. | 28 | * LISP Canonical Address Formatted address class. |
| ... | @@ -35,11 +40,11 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -35,11 +40,11 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
| 35 | */ | 40 | */ |
| 36 | public class LispLcafAddress extends LispAfiAddress { | 41 | public class LispLcafAddress extends LispAfiAddress { |
| 37 | 42 | ||
| 38 | - protected final LispCanonicalAddressFormatEnum lcafType; | 43 | + private final LispCanonicalAddressFormatEnum lcafType; |
| 39 | - protected final byte reserved1; | 44 | + private final byte reserved1; |
| 40 | - protected final byte reserved2; | 45 | + private final byte reserved2; |
| 41 | - protected final byte flag; | 46 | + private final byte flag; |
| 42 | - protected final byte length; | 47 | + private final short length; |
| 43 | 48 | ||
| 44 | /** | 49 | /** |
| 45 | * Initializes LCAF address. | 50 | * Initializes LCAF address. |
| ... | @@ -51,7 +56,7 @@ public class LispLcafAddress extends LispAfiAddress { | ... | @@ -51,7 +56,7 @@ public class LispLcafAddress extends LispAfiAddress { |
| 51 | * @param length length field | 56 | * @param length length field |
| 52 | */ | 57 | */ |
| 53 | protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, | 58 | protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, |
| 54 | - byte reserved1, byte reserved2, byte flag, byte length) { | 59 | + byte reserved1, byte reserved2, byte flag, short length) { |
| 55 | super(AddressFamilyIdentifierEnum.LCAF); | 60 | super(AddressFamilyIdentifierEnum.LCAF); |
| 56 | this.lcafType = lcafType; | 61 | this.lcafType = lcafType; |
| 57 | this.reserved1 = reserved1; | 62 | this.reserved1 = reserved1; |
| ... | @@ -69,7 +74,7 @@ public class LispLcafAddress extends LispAfiAddress { | ... | @@ -69,7 +74,7 @@ public class LispLcafAddress extends LispAfiAddress { |
| 69 | * @param length length field | 74 | * @param length length field |
| 70 | */ | 75 | */ |
| 71 | protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, | 76 | protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, |
| 72 | - byte reserved2, byte flag, byte length) { | 77 | + byte reserved2, byte flag, short length) { |
| 73 | super(AddressFamilyIdentifierEnum.LCAF); | 78 | super(AddressFamilyIdentifierEnum.LCAF); |
| 74 | this.lcafType = lcafType; | 79 | this.lcafType = lcafType; |
| 75 | this.reserved2 = reserved2; | 80 | this.reserved2 = reserved2; |
| ... | @@ -86,7 +91,7 @@ public class LispLcafAddress extends LispAfiAddress { | ... | @@ -86,7 +91,7 @@ public class LispLcafAddress extends LispAfiAddress { |
| 86 | * @param length length field | 91 | * @param length length field |
| 87 | */ | 92 | */ |
| 88 | protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, | 93 | protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, |
| 89 | - byte reserved2, byte length) { | 94 | + byte reserved2, short length) { |
| 90 | super(AddressFamilyIdentifierEnum.LCAF); | 95 | super(AddressFamilyIdentifierEnum.LCAF); |
| 91 | this.lcafType = lcafType; | 96 | this.lcafType = lcafType; |
| 92 | this.reserved2 = reserved2; | 97 | this.reserved2 = reserved2; |
| ... | @@ -114,6 +119,21 @@ public class LispLcafAddress extends LispAfiAddress { | ... | @@ -114,6 +119,21 @@ public class LispLcafAddress extends LispAfiAddress { |
| 114 | * Initializes LCAF address. | 119 | * Initializes LCAF address. |
| 115 | * | 120 | * |
| 116 | * @param lcafType LCAF type | 121 | * @param lcafType LCAF type |
| 122 | + * @param length length field | ||
| 123 | + */ | ||
| 124 | + protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, short length) { | ||
| 125 | + super(AddressFamilyIdentifierEnum.LCAF); | ||
| 126 | + this.lcafType = lcafType; | ||
| 127 | + this.reserved1 = 0; | ||
| 128 | + this.reserved2 = 0; | ||
| 129 | + this.flag = 0; | ||
| 130 | + this.length = length; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + /** | ||
| 134 | + * Initializes LCAF address. | ||
| 135 | + * | ||
| 136 | + * @param lcafType LCAF type | ||
| 117 | */ | 137 | */ |
| 118 | protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType) { | 138 | protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType) { |
| 119 | super(AddressFamilyIdentifierEnum.LCAF); | 139 | super(AddressFamilyIdentifierEnum.LCAF); |
| ... | @@ -165,10 +185,37 @@ public class LispLcafAddress extends LispAfiAddress { | ... | @@ -165,10 +185,37 @@ public class LispLcafAddress extends LispAfiAddress { |
| 165 | * | 185 | * |
| 166 | * @return LCAF length value | 186 | * @return LCAF length value |
| 167 | */ | 187 | */ |
| 168 | - public byte getLength() { | 188 | + public short getLength() { |
| 169 | return length; | 189 | return length; |
| 170 | } | 190 | } |
| 171 | 191 | ||
| 192 | + /** | ||
| 193 | + * Deserializes common fields from byte buffer. | ||
| 194 | + * | ||
| 195 | + * @param byteBuf byte buffer | ||
| 196 | + * @return LispLcafAddress with filled common data fields | ||
| 197 | + */ | ||
| 198 | + public static LispLcafAddress deserializeCommon(ByteBuf byteBuf) { | ||
| 199 | + | ||
| 200 | + // reserved1 -> 8 bits | ||
| 201 | + byte reserved1 = (byte) byteBuf.readUnsignedByte(); | ||
| 202 | + | ||
| 203 | + // flags -> 8 bits | ||
| 204 | + byte flag = (byte) byteBuf.readUnsignedByte(); | ||
| 205 | + | ||
| 206 | + // LCAF type -> 8 bits | ||
| 207 | + byte lcafType = (byte) byteBuf.readUnsignedByte(); | ||
| 208 | + | ||
| 209 | + // reserved2 -> 8bits | ||
| 210 | + byte reserved2 = (byte) byteBuf.readUnsignedByte(); | ||
| 211 | + | ||
| 212 | + // length -> 16 bits | ||
| 213 | + short length = (short) byteBuf.readUnsignedShort(); | ||
| 214 | + | ||
| 215 | + return new LispLcafAddress(LispCanonicalAddressFormatEnum.valueOf(lcafType), | ||
| 216 | + reserved1, reserved2, flag, length); | ||
| 217 | + } | ||
| 218 | + | ||
| 172 | @Override | 219 | @Override |
| 173 | public int hashCode() { | 220 | public int hashCode() { |
| 174 | return Objects.hash(lcafType, reserved1, reserved2, flag, length); | 221 | return Objects.hash(lcafType, reserved1, reserved2, flag, length); |
| ... | @@ -201,4 +248,110 @@ public class LispLcafAddress extends LispAfiAddress { | ... | @@ -201,4 +248,110 @@ public class LispLcafAddress extends LispAfiAddress { |
| 201 | .add("length", length) | 248 | .add("length", length) |
| 202 | .toString(); | 249 | .toString(); |
| 203 | } | 250 | } |
| 251 | + | ||
| 252 | + protected static class LcafAddressBuilder<T> { | ||
| 253 | + | ||
| 254 | + protected byte reserved1; | ||
| 255 | + protected byte flag; | ||
| 256 | + protected byte lcafType; | ||
| 257 | + protected byte reserved2; | ||
| 258 | + protected short length; | ||
| 259 | + | ||
| 260 | + /** | ||
| 261 | + * Sets reserved1 value. | ||
| 262 | + * | ||
| 263 | + * @param reserved1 reserved1 value | ||
| 264 | + * @return LcafAddressBuilder object | ||
| 265 | + */ | ||
| 266 | + public T withReserved1(byte reserved1) { | ||
| 267 | + this.reserved1 = reserved1; | ||
| 268 | + return (T) this; | ||
| 269 | + } | ||
| 270 | + | ||
| 271 | + /** | ||
| 272 | + * Sets flag. | ||
| 273 | + * | ||
| 274 | + * @param flag flag boolean | ||
| 275 | + * @return LcafAddressBuilder object | ||
| 276 | + */ | ||
| 277 | + public T withFlag(byte flag) { | ||
| 278 | + this.flag = flag; | ||
| 279 | + return (T) this; | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + /** | ||
| 283 | + * Sets LCAF type. | ||
| 284 | + * | ||
| 285 | + * @param lcafType LCAF type | ||
| 286 | + * @return LcafAddressBuilder object | ||
| 287 | + */ | ||
| 288 | + public T withLcafType(byte lcafType) { | ||
| 289 | + this.lcafType = lcafType; | ||
| 290 | + return (T) this; | ||
| 291 | + } | ||
| 292 | + | ||
| 293 | + /** | ||
| 294 | + * Sets reserved2 value. | ||
| 295 | + * | ||
| 296 | + * @param reserved2 reserved2 value | ||
| 297 | + * @return LcafAddressBuilder object | ||
| 298 | + */ | ||
| 299 | + public T withReserved2(byte reserved2) { | ||
| 300 | + this.reserved2 = reserved2; | ||
| 301 | + return (T) this; | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + /** | ||
| 305 | + * Sets length value. | ||
| 306 | + * | ||
| 307 | + * @param length length value | ||
| 308 | + * @return LcafAddressBuilder object | ||
| 309 | + */ | ||
| 310 | + public T withLength(short length) { | ||
| 311 | + this.length = length; | ||
| 312 | + return (T) this; | ||
| 313 | + } | ||
| 314 | + | ||
| 315 | + /** | ||
| 316 | + * Builds LispLcafAddress object. | ||
| 317 | + * | ||
| 318 | + * @return LispLcafAddress instance | ||
| 319 | + */ | ||
| 320 | + public LispLcafAddress build() { | ||
| 321 | + return new LispLcafAddress(LispCanonicalAddressFormatEnum.valueOf(lcafType), | ||
| 322 | + reserved1, reserved2, flag, length); | ||
| 323 | + } | ||
| 324 | + } | ||
| 325 | + | ||
| 326 | + public static class LcafAddressReader implements LispAddressReader<LispLcafAddress> { | ||
| 327 | + | ||
| 328 | + private static final int LCAF_TYPE_FIELD_INDEX = 4; | ||
| 329 | + | ||
| 330 | + @Override | ||
| 331 | + public LispLcafAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { | ||
| 332 | + | ||
| 333 | + int index = byteBuf.readerIndex(); | ||
| 334 | + | ||
| 335 | + // LCAF type -> 8 bits | ||
| 336 | + byte lcafType = (byte) byteBuf.getUnsignedByte(index + LCAF_TYPE_FIELD_INDEX); | ||
| 337 | + | ||
| 338 | + if (lcafType == APPLICATION_DATA.getLispCode()) { | ||
| 339 | + return new LispAppDataLcafAddress.AppDataLcafAddressReader().readFrom(byteBuf); | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + if (lcafType == LIST.getLispCode()) { | ||
| 343 | + return new LispListLcafAddress.ListLcafAddressReader().readFrom(byteBuf); | ||
| 344 | + } | ||
| 345 | + | ||
| 346 | + if (lcafType == SEGMENT.getLispCode()) { | ||
| 347 | + return new LispSegmentLcafAddress.SegmentLcafAddressReader().readFrom(byteBuf); | ||
| 348 | + } | ||
| 349 | + | ||
| 350 | + if (lcafType == SOURCE_DEST.getLispCode()) { | ||
| 351 | + return new LispSourceDestLcafAddress.SourceDestLcafAddressReader().readFrom(byteBuf); | ||
| 352 | + } | ||
| 353 | + | ||
| 354 | + return null; | ||
| 355 | + } | ||
| 356 | + } | ||
| 204 | } | 357 | } | ... | ... |
| ... | @@ -56,7 +56,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -56,7 +56,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
| 56 | */ | 56 | */ |
| 57 | public final class LispListLcafAddress extends LispLcafAddress { | 57 | public final class LispListLcafAddress extends LispLcafAddress { |
| 58 | 58 | ||
| 59 | - private static final byte LENGTH = 24; | 59 | + private static final short LENGTH = 24; |
| 60 | List<LispAfiAddress> addresses; | 60 | List<LispAfiAddress> addresses; |
| 61 | 61 | ||
| 62 | /** | 62 | /** |
| ... | @@ -70,6 +70,20 @@ public final class LispListLcafAddress extends LispLcafAddress { | ... | @@ -70,6 +70,20 @@ public final class LispListLcafAddress extends LispLcafAddress { |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | /** | 72 | /** |
| 73 | + * Initializes list type LCAF address. | ||
| 74 | + * | ||
| 75 | + * @param reserved1 reserved1 field | ||
| 76 | + * @param flag flag | ||
| 77 | + * @param reserved2 reserved2 field | ||
| 78 | + * @param addresses a set of IPv4 and IPv6 addresses | ||
| 79 | + */ | ||
| 80 | + public LispListLcafAddress(byte reserved1, byte reserved2, byte flag, | ||
| 81 | + List<LispAfiAddress> addresses) { | ||
| 82 | + super(LispCanonicalAddressFormatEnum.LIST, reserved1, flag, reserved2, LENGTH); | ||
| 83 | + this.addresses = addresses; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 73 | * Obtains a set of AFI addresses including IPv4 and IPv6. | 87 | * Obtains a set of AFI addresses including IPv4 and IPv6. |
| 74 | * | 88 | * |
| 75 | * @return a set of AFI addresses | 89 | * @return a set of AFI addresses |
| ... | @@ -111,11 +125,13 @@ public final class LispListLcafAddress extends LispLcafAddress { | ... | @@ -111,11 +125,13 @@ public final class LispListLcafAddress extends LispLcafAddress { |
| 111 | @Override | 125 | @Override |
| 112 | public LispListLcafAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { | 126 | public LispListLcafAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
| 113 | 127 | ||
| 128 | + LispLcafAddress lcafAddress = LispLcafAddress.deserializeCommon(byteBuf); | ||
| 114 | 129 | ||
| 115 | - LispAfiAddress ipv4 = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | 130 | + LispAfiAddress ipv4 = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
| 116 | - LispAfiAddress ipv6 = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | 131 | + LispAfiAddress ipv6 = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
| 117 | 132 | ||
| 118 | - return new LispListLcafAddress(ImmutableList.of(ipv4, ipv6)); | 133 | + return new LispListLcafAddress(lcafAddress.getReserved1(), lcafAddress.getReserved2(), |
| 134 | + lcafAddress.getFlag(), ImmutableList.of(ipv4, ipv6)); | ||
| 119 | } | 135 | } |
| 120 | } | 136 | } |
| 121 | } | 137 | } | ... | ... |
| ... | @@ -53,8 +53,8 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { | ... | @@ -53,8 +53,8 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { |
| 53 | * Initializes segment type LCAF address. | 53 | * Initializes segment type LCAF address. |
| 54 | * | 54 | * |
| 55 | * @param idMaskLength Id mask length | 55 | * @param idMaskLength Id mask length |
| 56 | - * @param instanceId instance id | 56 | + * @param instanceId instance id |
| 57 | - * @param address address | 57 | + * @param address address |
| 58 | */ | 58 | */ |
| 59 | private LispSegmentLcafAddress(byte idMaskLength, int instanceId, LispAfiAddress address) { | 59 | private LispSegmentLcafAddress(byte idMaskLength, int instanceId, LispAfiAddress address) { |
| 60 | super(LispCanonicalAddressFormatEnum.SEGMENT, idMaskLength); | 60 | super(LispCanonicalAddressFormatEnum.SEGMENT, idMaskLength); |
| ... | @@ -63,6 +63,23 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { | ... | @@ -63,6 +63,23 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | /** | 65 | /** |
| 66 | + * Initializes segment type LCAF address. | ||
| 67 | + * | ||
| 68 | + * @param reserved1 reserved1 | ||
| 69 | + * @param idMaskLength ID mask length | ||
| 70 | + * @param flag flag | ||
| 71 | + * @param length length | ||
| 72 | + * @param instanceId instance id | ||
| 73 | + * @param address address | ||
| 74 | + */ | ||
| 75 | + private LispSegmentLcafAddress(byte reserved1, byte idMaskLength, byte flag, short length, | ||
| 76 | + int instanceId, LispAfiAddress address) { | ||
| 77 | + super(LispCanonicalAddressFormatEnum.SEGMENT, reserved1, idMaskLength, flag, length); | ||
| 78 | + this.address = address; | ||
| 79 | + this.instanceId = instanceId; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 66 | * Obtains address. | 83 | * Obtains address. |
| 67 | * | 84 | * |
| 68 | * @return address | 85 | * @return address |
| ... | @@ -86,12 +103,12 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { | ... | @@ -86,12 +103,12 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { |
| 86 | * @return id mask length | 103 | * @return id mask length |
| 87 | */ | 104 | */ |
| 88 | public byte getIdMaskLength() { | 105 | public byte getIdMaskLength() { |
| 89 | - return reserved2; | 106 | + return getReserved2(); |
| 90 | } | 107 | } |
| 91 | 108 | ||
| 92 | @Override | 109 | @Override |
| 93 | public int hashCode() { | 110 | public int hashCode() { |
| 94 | - return Objects.hash(address, instanceId, reserved2); | 111 | + return Objects.hash(address, instanceId, getReserved2()); |
| 95 | } | 112 | } |
| 96 | 113 | ||
| 97 | @Override | 114 | @Override |
| ... | @@ -103,8 +120,8 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { | ... | @@ -103,8 +120,8 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { |
| 103 | if (obj instanceof LispSegmentLcafAddress) { | 120 | if (obj instanceof LispSegmentLcafAddress) { |
| 104 | final LispSegmentLcafAddress other = (LispSegmentLcafAddress) obj; | 121 | final LispSegmentLcafAddress other = (LispSegmentLcafAddress) obj; |
| 105 | return Objects.equals(this.address, other.address) && | 122 | return Objects.equals(this.address, other.address) && |
| 106 | - Objects.equals(this.instanceId, other.instanceId) && | 123 | + Objects.equals(this.instanceId, other.instanceId) && |
| 107 | - Objects.equals(this.reserved2, other.reserved2); | 124 | + Objects.equals(this.getReserved2(), other.getReserved2()); |
| 108 | } | 125 | } |
| 109 | return false; | 126 | return false; |
| 110 | } | 127 | } |
| ... | @@ -114,11 +131,12 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { | ... | @@ -114,11 +131,12 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { |
| 114 | return toStringHelper(this) | 131 | return toStringHelper(this) |
| 115 | .add("address", address) | 132 | .add("address", address) |
| 116 | .add("instanceId", instanceId) | 133 | .add("instanceId", instanceId) |
| 117 | - .add("idMaskLength", reserved2) | 134 | + .add("idMaskLength", getReserved2()) |
| 118 | .toString(); | 135 | .toString(); |
| 119 | } | 136 | } |
| 120 | 137 | ||
| 121 | - public static final class SegmentAddressBuilder { | 138 | + public static final class SegmentAddressBuilder |
| 139 | + extends LcafAddressBuilder<SegmentAddressBuilder> { | ||
| 122 | private byte idMaskLength; | 140 | private byte idMaskLength; |
| 123 | private LispAfiAddress address; | 141 | private LispAfiAddress address; |
| 124 | private int instanceId; | 142 | private int instanceId; |
| ... | @@ -162,7 +180,8 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { | ... | @@ -162,7 +180,8 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { |
| 162 | * @return LispSegmentLcafAddress instance | 180 | * @return LispSegmentLcafAddress instance |
| 163 | */ | 181 | */ |
| 164 | public LispSegmentLcafAddress build() { | 182 | public LispSegmentLcafAddress build() { |
| 165 | - return new LispSegmentLcafAddress(idMaskLength, instanceId, address); | 183 | + return new LispSegmentLcafAddress(reserved1, idMaskLength, flag, |
| 184 | + length, instanceId, address); | ||
| 166 | } | 185 | } |
| 167 | } | 186 | } |
| 168 | 187 | ||
| ... | @@ -170,22 +189,27 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { | ... | @@ -170,22 +189,27 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { |
| 170 | * Segment LCAF address reader class. | 189 | * Segment LCAF address reader class. |
| 171 | */ | 190 | */ |
| 172 | public static class SegmentLcafAddressReader | 191 | public static class SegmentLcafAddressReader |
| 173 | - implements LispAddressReader<LispSegmentLcafAddress> { | 192 | + implements LispAddressReader<LispSegmentLcafAddress> { |
| 174 | 193 | ||
| 175 | @Override | 194 | @Override |
| 176 | public LispSegmentLcafAddress readFrom(ByteBuf byteBuf) | 195 | public LispSegmentLcafAddress readFrom(ByteBuf byteBuf) |
| 177 | - throws LispParseError, LispReaderException { | 196 | + throws LispParseError, LispReaderException { |
| 197 | + | ||
| 198 | + LispLcafAddress lcafAddress = LispLcafAddress.deserializeCommon(byteBuf); | ||
| 199 | + | ||
| 200 | + byte idMaskLength = lcafAddress.getReserved2(); | ||
| 178 | 201 | ||
| 179 | - // TODO: need to de-serialize IdMaskLength | ||
| 180 | - byte idMaskLength = 0x01; | ||
| 181 | int instanceId = (int) byteBuf.readUnsignedInt(); | 202 | int instanceId = (int) byteBuf.readUnsignedInt(); |
| 182 | - LispAfiAddress address = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | 203 | + LispAfiAddress address = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
| 183 | 204 | ||
| 184 | return new SegmentAddressBuilder() | 205 | return new SegmentAddressBuilder() |
| 185 | - .withIdMaskLength(idMaskLength) | 206 | + .withReserved1(lcafAddress.getReserved1()) |
| 186 | - .withInstanceId(instanceId) | 207 | + .withFlag(lcafAddress.getFlag()) |
| 187 | - .withAddress(address) | 208 | + .withLength(lcafAddress.getLength()) |
| 188 | - .build(); | 209 | + .withIdMaskLength(idMaskLength) |
| 210 | + .withInstanceId(instanceId) | ||
| 211 | + .withAddress(address) | ||
| 212 | + .build(); | ||
| 189 | } | 213 | } |
| 190 | } | 214 | } |
| 191 | } | 215 | } | ... | ... |
| ... | @@ -76,6 +76,31 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { | ... | @@ -76,6 +76,31 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | /** | 78 | /** |
| 79 | + * Initializes source/dest key type LCAF address. | ||
| 80 | + * | ||
| 81 | + * @param reserved1 reserved1 | ||
| 82 | + * @param reserved2 reserved2 | ||
| 83 | + * @param flag flag | ||
| 84 | + * @param length length | ||
| 85 | + * @param reserved reserved | ||
| 86 | + * @param srcMaskLength source mask length | ||
| 87 | + * @param dstMaskLength destination mask length | ||
| 88 | + * @param srcPrefix source address prefix | ||
| 89 | + * @param dstPrefix destination address prefix | ||
| 90 | + */ | ||
| 91 | + private LispSourceDestLcafAddress(byte reserved1, byte reserved2, byte flag, short length, | ||
| 92 | + short reserved, byte srcMaskLength, | ||
| 93 | + byte dstMaskLength, LispAfiAddress srcPrefix, | ||
| 94 | + LispAfiAddress dstPrefix) { | ||
| 95 | + super(LispCanonicalAddressFormatEnum.SOURCE_DEST, reserved1, reserved2, flag, length); | ||
| 96 | + this.reserved = reserved; | ||
| 97 | + this.srcMaskLength = srcMaskLength; | ||
| 98 | + this.dstMaskLength = dstMaskLength; | ||
| 99 | + this.srcPrefix = srcPrefix; | ||
| 100 | + this.dstPrefix = dstPrefix; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + /** | ||
| 79 | * Obtains source address prefix. | 104 | * Obtains source address prefix. |
| 80 | * | 105 | * |
| 81 | * @return source address prefix | 106 | * @return source address prefix |
| ... | @@ -153,7 +178,8 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { | ... | @@ -153,7 +178,8 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { |
| 153 | .toString(); | 178 | .toString(); |
| 154 | } | 179 | } |
| 155 | 180 | ||
| 156 | - public static final class SourceDestAddressBuilder { | 181 | + public static final class SourceDestAddressBuilder |
| 182 | + extends LcafAddressBuilder<SourceDestAddressBuilder> { | ||
| 157 | private LispAfiAddress srcPrefix; | 183 | private LispAfiAddress srcPrefix; |
| 158 | private LispAfiAddress dstPrefix; | 184 | private LispAfiAddress dstPrefix; |
| 159 | private byte srcMaskLength; | 185 | private byte srcMaskLength; |
| ... | @@ -221,8 +247,8 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { | ... | @@ -221,8 +247,8 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { |
| 221 | * @return LispSourceDestLcafAddress instance | 247 | * @return LispSourceDestLcafAddress instance |
| 222 | */ | 248 | */ |
| 223 | public LispSourceDestLcafAddress build() { | 249 | public LispSourceDestLcafAddress build() { |
| 224 | - return new LispSourceDestLcafAddress(reserved, srcMaskLength, | 250 | + return new LispSourceDestLcafAddress(reserved1, reserved2, flag, length, |
| 225 | - dstMaskLength, srcPrefix, dstPrefix); | 251 | + reserved, srcMaskLength, dstMaskLength, srcPrefix, dstPrefix); |
| 226 | } | 252 | } |
| 227 | } | 253 | } |
| 228 | 254 | ||
| ... | @@ -235,20 +261,26 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { | ... | @@ -235,20 +261,26 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { |
| 235 | @Override | 261 | @Override |
| 236 | public LispSourceDestLcafAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { | 262 | public LispSourceDestLcafAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { |
| 237 | 263 | ||
| 264 | + LispLcafAddress lcafAddress = LispLcafAddress.deserializeCommon(byteBuf); | ||
| 265 | + | ||
| 238 | short reserved = byteBuf.readShort(); | 266 | short reserved = byteBuf.readShort(); |
| 239 | byte srcMaskLength = (byte) byteBuf.readUnsignedByte(); | 267 | byte srcMaskLength = (byte) byteBuf.readUnsignedByte(); |
| 240 | byte dstMaskLength = (byte) byteBuf.readUnsignedByte(); | 268 | byte dstMaskLength = (byte) byteBuf.readUnsignedByte(); |
| 241 | 269 | ||
| 242 | - LispAfiAddress srcPrefix = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | 270 | + LispAfiAddress srcPrefix = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
| 243 | - LispAfiAddress dstPrefix = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | 271 | + LispAfiAddress dstPrefix = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); |
| 244 | 272 | ||
| 245 | return new SourceDestAddressBuilder() | 273 | return new SourceDestAddressBuilder() |
| 246 | - .withReserved(reserved) | 274 | + .withReserved1(lcafAddress.getReserved1()) |
| 247 | - .withSrcMaskLength(srcMaskLength) | 275 | + .withReserved2(lcafAddress.getReserved2()) |
| 248 | - .withDstMaskLength(dstMaskLength) | 276 | + .withFlag(lcafAddress.getFlag()) |
| 249 | - .withSrcPrefix(srcPrefix) | 277 | + .withLength(lcafAddress.getLength()) |
| 250 | - .withDstPrefix(dstPrefix) | 278 | + .withReserved(reserved) |
| 251 | - .build(); | 279 | + .withSrcMaskLength(srcMaskLength) |
| 280 | + .withDstMaskLength(dstMaskLength) | ||
| 281 | + .withSrcPrefix(srcPrefix) | ||
| 282 | + .withDstPrefix(dstPrefix) | ||
| 283 | + .build(); | ||
| 252 | } | 284 | } |
| 253 | } | 285 | } |
| 254 | } | 286 | } | ... | ... |
| ... | @@ -57,6 +57,6 @@ public class LispLcafAddressTest { | ... | @@ -57,6 +57,6 @@ public class LispLcafAddressTest { |
| 57 | assertThat(lcafAddress.getReserved1(), is((byte) 0x01)); | 57 | assertThat(lcafAddress.getReserved1(), is((byte) 0x01)); |
| 58 | assertThat(lcafAddress.getReserved2(), is((byte) 0x01)); | 58 | assertThat(lcafAddress.getReserved2(), is((byte) 0x01)); |
| 59 | assertThat(lcafAddress.getFlag(), is((byte) 0x01)); | 59 | assertThat(lcafAddress.getFlag(), is((byte) 0x01)); |
| 60 | - assertThat(lcafAddress.getLength(), is((byte) 0x01)); | 60 | + assertThat(lcafAddress.getLength(), is((short) 1)); |
| 61 | } | 61 | } |
| 62 | } | 62 | } | ... | ... |
-
Please register or login to post a comment