Committed by
Gerrit Code Review
Add NotNull and Argument check during object build for LISP object
Also correct IP enumeration type into IP4. Change-Id: Id970ee608c885826cfd2de7b5448b2bc451e079f
Showing
15 changed files
with
78 additions
and
48 deletions
... | @@ -24,6 +24,7 @@ import org.onosproject.lisp.msg.exceptions.LispWriterException; | ... | @@ -24,6 +24,7 @@ import org.onosproject.lisp.msg.exceptions.LispWriterException; |
24 | import org.onosproject.lisp.msg.types.LispAfiAddress; | 24 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
25 | 25 | ||
26 | import static com.google.common.base.MoreObjects.toStringHelper; | 26 | import static com.google.common.base.MoreObjects.toStringHelper; |
27 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
27 | import static org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressWriter; | 28 | import static org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressWriter; |
28 | 29 | ||
29 | /** | 30 | /** |
... | @@ -209,6 +210,9 @@ public final class DefaultLispLocatorRecord implements LispLocatorRecord { | ... | @@ -209,6 +210,9 @@ public final class DefaultLispLocatorRecord implements LispLocatorRecord { |
209 | 210 | ||
210 | @Override | 211 | @Override |
211 | public LispLocatorRecord build() { | 212 | public LispLocatorRecord build() { |
213 | + | ||
214 | + checkNotNull(locatorAfi, "Must specify a locator address"); | ||
215 | + | ||
212 | return new DefaultLispLocatorRecord(priority, weight, multicastPriority, | 216 | return new DefaultLispLocatorRecord(priority, weight, multicastPriority, |
213 | multicastWeight, localLocator, rlocProbed, routed, locatorAfi); | 217 | multicastWeight, localLocator, rlocProbed, routed, locatorAfi); |
214 | } | 218 | } | ... | ... |
... | @@ -152,7 +152,7 @@ public final class DefaultLispMapNotify implements LispMapNotify { | ... | @@ -152,7 +152,7 @@ public final class DefaultLispMapNotify implements LispMapNotify { |
152 | private short authDataLength; | 152 | private short authDataLength; |
153 | private byte[] authenticationData; | 153 | private byte[] authenticationData; |
154 | private byte recordCount; | 154 | private byte recordCount; |
155 | - private List<LispMapRecord> mapRecords; | 155 | + private List<LispMapRecord> mapRecords = Lists.newArrayList(); |
156 | 156 | ||
157 | @Override | 157 | @Override |
158 | public LispType getType() { | 158 | public LispType getType() { |
... | @@ -197,8 +197,6 @@ public final class DefaultLispMapNotify implements LispMapNotify { | ... | @@ -197,8 +197,6 @@ public final class DefaultLispMapNotify implements LispMapNotify { |
197 | public NotifyBuilder withMapRecords(List<LispMapRecord> mapRecords) { | 197 | public NotifyBuilder withMapRecords(List<LispMapRecord> mapRecords) { |
198 | if (mapRecords != null) { | 198 | if (mapRecords != null) { |
199 | this.mapRecords = ImmutableList.copyOf(mapRecords); | 199 | this.mapRecords = ImmutableList.copyOf(mapRecords); |
200 | - } else { | ||
201 | - this.mapRecords = Lists.newArrayList(); | ||
202 | } | 200 | } |
203 | return this; | 201 | return this; |
204 | } | 202 | } |
... | @@ -210,10 +208,6 @@ public final class DefaultLispMapNotify implements LispMapNotify { | ... | @@ -210,10 +208,6 @@ public final class DefaultLispMapNotify implements LispMapNotify { |
210 | authenticationData = new byte[0]; | 208 | authenticationData = new byte[0]; |
211 | } | 209 | } |
212 | 210 | ||
213 | - if (mapRecords == null) { | ||
214 | - mapRecords = Lists.newArrayList(); | ||
215 | - } | ||
216 | - | ||
217 | return new DefaultLispMapNotify(nonce, keyId, authDataLength, | 211 | return new DefaultLispMapNotify(nonce, keyId, authDataLength, |
218 | authenticationData, recordCount, mapRecords); | 212 | authenticationData, recordCount, mapRecords); |
219 | } | 213 | } | ... | ... |
... | @@ -28,6 +28,7 @@ import org.onosproject.lisp.msg.types.LispAfiAddress; | ... | @@ -28,6 +28,7 @@ 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.checkNotNull; | ||
31 | import static org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressWriter; | 32 | import static org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressWriter; |
32 | import static org.onosproject.lisp.msg.protocols.DefaultLispLocatorRecord.LocatorRecordWriter; | 33 | import static org.onosproject.lisp.msg.protocols.DefaultLispLocatorRecord.LocatorRecordWriter; |
33 | 34 | ||
... | @@ -163,7 +164,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { | ... | @@ -163,7 +164,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { |
163 | private boolean authoritative; | 164 | private boolean authoritative; |
164 | private short mapVersionNumber; | 165 | private short mapVersionNumber; |
165 | private LispAfiAddress eidPrefixAfi; | 166 | private LispAfiAddress eidPrefixAfi; |
166 | - private List<LispLocatorRecord> locatorRecords; | 167 | + private List<LispLocatorRecord> locatorRecords = Lists.newArrayList(); |
167 | 168 | ||
168 | @Override | 169 | @Override |
169 | public MapRecordBuilder withRecordTtl(int recordTtl) { | 170 | public MapRecordBuilder withRecordTtl(int recordTtl) { |
... | @@ -211,8 +212,6 @@ public final class DefaultLispMapRecord implements LispMapRecord { | ... | @@ -211,8 +212,6 @@ public final class DefaultLispMapRecord implements LispMapRecord { |
211 | public MapRecordBuilder withLocators(List<LispLocatorRecord> records) { | 212 | public MapRecordBuilder withLocators(List<LispLocatorRecord> records) { |
212 | if (records != null) { | 213 | if (records != null) { |
213 | this.locatorRecords = ImmutableList.copyOf(records); | 214 | this.locatorRecords = ImmutableList.copyOf(records); |
214 | - } else { | ||
215 | - this.locatorRecords = Lists.newArrayList(); | ||
216 | } | 215 | } |
217 | return this; | 216 | return this; |
218 | } | 217 | } |
... | @@ -220,9 +219,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { | ... | @@ -220,9 +219,7 @@ public final class DefaultLispMapRecord implements LispMapRecord { |
220 | @Override | 219 | @Override |
221 | public LispMapRecord build() { | 220 | public LispMapRecord build() { |
222 | 221 | ||
223 | - if (locatorRecords == null) { | 222 | + checkNotNull(eidPrefixAfi, "Must specify an EID prefix"); |
224 | - locatorRecords = Lists.newArrayList(); | ||
225 | - } | ||
226 | 223 | ||
227 | return new DefaultLispMapRecord(recordTtl, locatorCount, maskLength, | 224 | return new DefaultLispMapRecord(recordTtl, locatorCount, maskLength, |
228 | action, authoritative, mapVersionNumber, eidPrefixAfi, locatorRecords); | 225 | action, authoritative, mapVersionNumber, eidPrefixAfi, locatorRecords); | ... | ... |
... | @@ -175,9 +175,9 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -175,9 +175,9 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
175 | private long nonce; | 175 | private long nonce; |
176 | private short keyId; | 176 | private short keyId; |
177 | private short authDataLength; | 177 | private short authDataLength; |
178 | - private byte[] authenticationData; | 178 | + private byte[] authenticationData = new byte[0]; |
179 | private byte recordCount; | 179 | private byte recordCount; |
180 | - private List<LispMapRecord> mapRecords; | 180 | + private List<LispMapRecord> mapRecords = Lists.newArrayList(); |
181 | private boolean proxyMapReply; | 181 | private boolean proxyMapReply; |
182 | private boolean wantMapNotify; | 182 | private boolean wantMapNotify; |
183 | 183 | ||
... | @@ -226,8 +226,6 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -226,8 +226,6 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
226 | public RegisterBuilder withAuthenticationData(byte[] authenticationData) { | 226 | public RegisterBuilder withAuthenticationData(byte[] authenticationData) { |
227 | if (authenticationData != null) { | 227 | if (authenticationData != null) { |
228 | this.authenticationData = authenticationData; | 228 | this.authenticationData = authenticationData; |
229 | - } else { | ||
230 | - this.authenticationData = new byte[0]; | ||
231 | } | 229 | } |
232 | return this; | 230 | return this; |
233 | } | 231 | } |
... | @@ -236,22 +234,12 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -236,22 +234,12 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
236 | public RegisterBuilder withMapRecords(List<LispMapRecord> mapRecords) { | 234 | public RegisterBuilder withMapRecords(List<LispMapRecord> mapRecords) { |
237 | if (mapRecords != null) { | 235 | if (mapRecords != null) { |
238 | this.mapRecords = ImmutableList.copyOf(mapRecords); | 236 | this.mapRecords = ImmutableList.copyOf(mapRecords); |
239 | - } else { | ||
240 | - this.mapRecords = Lists.newArrayList(); | ||
241 | } | 237 | } |
242 | return this; | 238 | return this; |
243 | } | 239 | } |
244 | 240 | ||
245 | @Override | 241 | @Override |
246 | public LispMapRegister build() { | 242 | public LispMapRegister build() { |
247 | - if (authenticationData == null) { | ||
248 | - authenticationData = new byte[0]; | ||
249 | - } | ||
250 | - | ||
251 | - if (mapRecords == null) { | ||
252 | - mapRecords = Lists.newArrayList(); | ||
253 | - } | ||
254 | - | ||
255 | return new DefaultLispMapRegister(nonce, keyId, authDataLength, | 243 | return new DefaultLispMapRegister(nonce, keyId, authDataLength, |
256 | authenticationData, recordCount, mapRecords, proxyMapReply, wantMapNotify); | 244 | authenticationData, recordCount, mapRecords, proxyMapReply, wantMapNotify); |
257 | } | 245 | } | ... | ... |
... | @@ -146,7 +146,7 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -146,7 +146,7 @@ public final class DefaultLispMapReply implements LispMapReply { |
146 | private boolean probe; | 146 | private boolean probe; |
147 | private boolean etr; | 147 | private boolean etr; |
148 | private boolean security; | 148 | private boolean security; |
149 | - private List<LispMapRecord> mapRecords; | 149 | + private List<LispMapRecord> mapRecords = Lists.newArrayList(); |
150 | 150 | ||
151 | @Override | 151 | @Override |
152 | public LispType getType() { | 152 | public LispType getType() { |
... | @@ -185,22 +185,14 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -185,22 +185,14 @@ 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 | if (this.mapRecords != null) { |
190 | this.mapRecords = ImmutableList.copyOf(mapRecords); | 189 | this.mapRecords = ImmutableList.copyOf(mapRecords); |
191 | - } else { | ||
192 | - this.mapRecords = Lists.newArrayList(); | ||
193 | } | 190 | } |
194 | return this; | 191 | return this; |
195 | } | 192 | } |
196 | 193 | ||
197 | @Override | 194 | @Override |
198 | public LispMapReply build() { | 195 | public LispMapReply build() { |
199 | - | ||
200 | - if (mapRecords == null) { | ||
201 | - mapRecords = Lists.newArrayList(); | ||
202 | - } | ||
203 | - | ||
204 | return new DefaultLispMapReply(nonce, recordCount, probe, etr, security, mapRecords); | 196 | return new DefaultLispMapReply(nonce, recordCount, probe, etr, security, mapRecords); |
205 | } | 197 | } |
206 | } | 198 | } | ... | ... |
... | @@ -270,23 +270,16 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -270,23 +270,16 @@ 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 | if (itrRlocs != null) { |
275 | this.itrRlocs = ImmutableList.copyOf(itrRlocs); | 274 | this.itrRlocs = ImmutableList.copyOf(itrRlocs); |
276 | - } else { | ||
277 | - this.itrRlocs = Lists.newArrayList(); | ||
278 | } | 275 | } |
279 | - | ||
280 | return this; | 276 | return this; |
281 | } | 277 | } |
282 | 278 | ||
283 | @Override | 279 | @Override |
284 | public RequestBuilder withEidRecords(List<LispEidRecord> records) { | 280 | public RequestBuilder withEidRecords(List<LispEidRecord> records) { |
285 | - | ||
286 | if (records != null) { | 281 | if (records != null) { |
287 | this.eidRecords = ImmutableList.copyOf(records); | 282 | this.eidRecords = ImmutableList.copyOf(records); |
288 | - } else { | ||
289 | - this.eidRecords = Lists.newArrayList(); | ||
290 | } | 283 | } |
291 | return this; | 284 | return this; |
292 | } | 285 | } | ... | ... |
... | @@ -21,6 +21,7 @@ import org.onosproject.lisp.msg.exceptions.LispReaderException; | ... | @@ -21,6 +21,7 @@ import org.onosproject.lisp.msg.exceptions.LispReaderException; |
21 | import org.onosproject.lisp.msg.exceptions.LispWriterException; | 21 | import org.onosproject.lisp.msg.exceptions.LispWriterException; |
22 | import org.onosproject.lisp.msg.types.LispAfiAddress; | 22 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
23 | 23 | ||
24 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
24 | import static org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressWriter; | 25 | import static org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressWriter; |
25 | 26 | ||
26 | /** | 27 | /** |
... | @@ -39,6 +40,9 @@ public final class LispEidRecord { | ... | @@ -39,6 +40,9 @@ public final class LispEidRecord { |
39 | */ | 40 | */ |
40 | public LispEidRecord(byte maskLength, LispAfiAddress prefix) { | 41 | public LispEidRecord(byte maskLength, LispAfiAddress prefix) { |
41 | this.maskLength = maskLength; | 42 | this.maskLength = maskLength; |
43 | + | ||
44 | + checkNotNull(prefix, "Must specify an address prefix"); | ||
45 | + | ||
42 | this.prefix = prefix; | 46 | this.prefix = prefix; |
43 | } | 47 | } |
44 | 48 | ... | ... |
... | @@ -26,7 +26,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -26,7 +26,7 @@ package org.onosproject.lisp.msg.types; |
26 | public enum AddressFamilyIdentifierEnum { | 26 | public enum AddressFamilyIdentifierEnum { |
27 | 27 | ||
28 | NO_ADDRESS(0), // Reserved | 28 | NO_ADDRESS(0), // Reserved |
29 | - IP(1), // IP (IP version 4) | 29 | + IP4(1), // IP4 (IP version 4) |
30 | IP6(2), // IP6 (IP version 6) | 30 | IP6(2), // IP6 (IP version 6) |
31 | DNS(16), // Domain Name System | 31 | DNS(16), // Domain Name System |
32 | DISTINGUISHED_NAME(17), // Distinguished Name | 32 | DISTINGUISHED_NAME(17), // Distinguished Name | ... | ... |
... | @@ -90,7 +90,7 @@ public abstract class LispAfiAddress { | ... | @@ -90,7 +90,7 @@ public abstract class LispAfiAddress { |
90 | short afiCode = (short) byteBuf.getUnsignedShort(index); | 90 | short afiCode = (short) byteBuf.getUnsignedShort(index); |
91 | 91 | ||
92 | // handle IPv4 and IPv6 address | 92 | // handle IPv4 and IPv6 address |
93 | - if (afiCode == IP.getIanaCode() || | 93 | + if (afiCode == IP4.getIanaCode() || |
94 | afiCode == IP6.getIanaCode()) { | 94 | afiCode == IP6.getIanaCode()) { |
95 | return new LispIpAddress.IpAddressReader().readFrom(byteBuf); | 95 | return new LispIpAddress.IpAddressReader().readFrom(byteBuf); |
96 | } | 96 | } |
... | @@ -131,7 +131,7 @@ public abstract class LispAfiAddress { | ... | @@ -131,7 +131,7 @@ public abstract class LispAfiAddress { |
131 | byteBuf.writeShort(address.getAfi().getIanaCode()); | 131 | byteBuf.writeShort(address.getAfi().getIanaCode()); |
132 | 132 | ||
133 | switch (address.getAfi()) { | 133 | switch (address.getAfi()) { |
134 | - case IP: | 134 | + case IP4: |
135 | new LispIpAddress.IpAddressWriter().writeTo(byteBuf, (LispIpv4Address) address); | 135 | new LispIpAddress.IpAddressWriter().writeTo(byteBuf, (LispIpv4Address) address); |
136 | break; | 136 | break; |
137 | case IP6: | 137 | case IP6: | ... | ... |
... | @@ -25,6 +25,7 @@ import java.util.Arrays; | ... | @@ -25,6 +25,7 @@ import java.util.Arrays; |
25 | import java.util.Objects; | 25 | import java.util.Objects; |
26 | 26 | ||
27 | import static com.google.common.base.MoreObjects.toStringHelper; | 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
28 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
28 | 29 | ||
29 | /** | 30 | /** |
30 | * Application data type LCAF address class. | 31 | * Application data type LCAF address class. |
... | @@ -308,6 +309,9 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -308,6 +309,9 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
308 | * @return LispAddDataLcafAddress instance | 309 | * @return LispAddDataLcafAddress instance |
309 | */ | 310 | */ |
310 | public LispAppDataLcafAddress build() { | 311 | public LispAppDataLcafAddress build() { |
312 | + | ||
313 | + checkNotNull(address, "Must specify an address"); | ||
314 | + | ||
311 | return new LispAppDataLcafAddress(reserved1, reserved2, flag, length, | 315 | return new LispAppDataLcafAddress(reserved1, reserved2, flag, length, |
312 | protocol, ipTos, localPortLow, localPortHigh, remotePortLow, | 316 | protocol, ipTos, localPortLow, localPortHigh, remotePortLow, |
313 | remotePortHigh, address); | 317 | remotePortHigh, address); | ... | ... |
... | @@ -35,7 +35,7 @@ public class LispIpv4Address extends LispIpAddress { | ... | @@ -35,7 +35,7 @@ public class LispIpv4Address extends LispIpAddress { |
35 | * @param address IP address | 35 | * @param address IP address |
36 | */ | 36 | */ |
37 | public LispIpv4Address(IpAddress address) { | 37 | public LispIpv4Address(IpAddress address) { |
38 | - super(address, AddressFamilyIdentifierEnum.IP); | 38 | + super(address, AddressFamilyIdentifierEnum.IP4); |
39 | checkArgument(address.isIp4()); | 39 | checkArgument(address.isIp4()); |
40 | } | 40 | } |
41 | 41 | ... | ... |
... | @@ -19,6 +19,8 @@ import io.netty.buffer.ByteBuf; | ... | @@ -19,6 +19,8 @@ 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.exceptions.LispReaderException; |
21 | import org.onosproject.lisp.msg.exceptions.LispWriterException; | 21 | import org.onosproject.lisp.msg.exceptions.LispWriterException; |
22 | +import org.slf4j.Logger; | ||
23 | +import org.slf4j.LoggerFactory; | ||
22 | 24 | ||
23 | import java.util.Objects; | 25 | import java.util.Objects; |
24 | 26 | ||
... | @@ -41,6 +43,8 @@ import static org.onosproject.lisp.msg.types.LispCanonicalAddressFormatEnum.*; | ... | @@ -41,6 +43,8 @@ import static org.onosproject.lisp.msg.types.LispCanonicalAddressFormatEnum.*; |
41 | */ | 43 | */ |
42 | public class LispLcafAddress extends LispAfiAddress { | 44 | public class LispLcafAddress extends LispAfiAddress { |
43 | 45 | ||
46 | + private static final Logger log = LoggerFactory.getLogger(LispLcafAddress.class); | ||
47 | + | ||
44 | private final LispCanonicalAddressFormatEnum lcafType; | 48 | private final LispCanonicalAddressFormatEnum lcafType; |
45 | private final byte reserved1; | 49 | private final byte reserved1; |
46 | private final byte reserved2; | 50 | private final byte reserved2; |
... | @@ -369,6 +373,8 @@ public class LispLcafAddress extends LispAfiAddress { | ... | @@ -369,6 +373,8 @@ public class LispLcafAddress extends LispAfiAddress { |
369 | return new LispSourceDestLcafAddress.SourceDestLcafAddressReader().readFrom(byteBuf); | 373 | return new LispSourceDestLcafAddress.SourceDestLcafAddressReader().readFrom(byteBuf); |
370 | } | 374 | } |
371 | 375 | ||
376 | + log.warn("Unsupported LCAF type, please specify a correct LCAF type"); | ||
377 | + | ||
372 | return null; | 378 | return null; |
373 | } | 379 | } |
374 | } | 380 | } |
... | @@ -397,7 +403,9 @@ public class LispLcafAddress extends LispAfiAddress { | ... | @@ -397,7 +403,9 @@ public class LispLcafAddress extends LispAfiAddress { |
397 | new LispSourceDestLcafAddress.SourceDestLcafAddressWriter().writeTo(byteBuf, | 403 | new LispSourceDestLcafAddress.SourceDestLcafAddressWriter().writeTo(byteBuf, |
398 | (LispSourceDestLcafAddress) address); | 404 | (LispSourceDestLcafAddress) address); |
399 | break; | 405 | break; |
400 | - default: break; // TODO: need to log warning message | 406 | + default: |
407 | + log.warn("Unsupported LCAF type, please specify a correct LCAF type"); | ||
408 | + break; | ||
401 | } | 409 | } |
402 | } | 410 | } |
403 | } | 411 | } | ... | ... |
... | @@ -25,6 +25,7 @@ import java.util.List; | ... | @@ -25,6 +25,7 @@ import java.util.List; |
25 | import java.util.Objects; | 25 | import java.util.Objects; |
26 | 26 | ||
27 | import static com.google.common.base.MoreObjects.toStringHelper; | 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
28 | +import static com.google.common.base.Preconditions.checkArgument; | ||
28 | 29 | ||
29 | /** | 30 | /** |
30 | * List type LCAF address class. | 31 | * List type LCAF address class. |
... | @@ -67,6 +68,10 @@ public final class LispListLcafAddress extends LispLcafAddress { | ... | @@ -67,6 +68,10 @@ public final class LispListLcafAddress extends LispLcafAddress { |
67 | */ | 68 | */ |
68 | public LispListLcafAddress(List<LispAfiAddress> addresses) { | 69 | public LispListLcafAddress(List<LispAfiAddress> addresses) { |
69 | super(LispCanonicalAddressFormatEnum.LIST, LENGTH); | 70 | super(LispCanonicalAddressFormatEnum.LIST, LENGTH); |
71 | + | ||
72 | + checkArgument(checkAddressValidity(addresses), "Malformed addresses, please " + | ||
73 | + "specify IPv4 address first, and then specify IPv6 address"); | ||
74 | + | ||
70 | this.addresses = addresses; | 75 | this.addresses = addresses; |
71 | } | 76 | } |
72 | 77 | ||
... | @@ -81,10 +86,42 @@ public final class LispListLcafAddress extends LispLcafAddress { | ... | @@ -81,10 +86,42 @@ public final class LispListLcafAddress extends LispLcafAddress { |
81 | public LispListLcafAddress(byte reserved1, byte reserved2, byte flag, | 86 | public LispListLcafAddress(byte reserved1, byte reserved2, byte flag, |
82 | List<LispAfiAddress> addresses) { | 87 | List<LispAfiAddress> addresses) { |
83 | super(LispCanonicalAddressFormatEnum.LIST, reserved1, flag, reserved2, LENGTH); | 88 | super(LispCanonicalAddressFormatEnum.LIST, reserved1, flag, reserved2, LENGTH); |
89 | + | ||
90 | + checkArgument(checkAddressValidity(addresses), "Malformed addresses, please " + | ||
91 | + "specify IPv4 address first, and then specify IPv6 address"); | ||
92 | + | ||
84 | this.addresses = addresses; | 93 | this.addresses = addresses; |
85 | } | 94 | } |
86 | 95 | ||
87 | /** | 96 | /** |
97 | + * Checks the validity of a collection of input addresses. | ||
98 | + * | ||
99 | + * @param addresses a collection of addresses | ||
100 | + * @return validity result | ||
101 | + */ | ||
102 | + private boolean checkAddressValidity(List<LispAfiAddress> addresses) { | ||
103 | + // we need to make sure that the address collection is comprised of | ||
104 | + // one IPv4 address and one IPv6 address | ||
105 | + | ||
106 | + if (addresses == null || addresses.size() != 2) { | ||
107 | + return false; | ||
108 | + } | ||
109 | + | ||
110 | + LispAfiAddress ipv4 = addresses.get(0); | ||
111 | + LispAfiAddress ipv6 = addresses.get(1); | ||
112 | + | ||
113 | + if (ipv4.getAfi() != AddressFamilyIdentifierEnum.IP4) { | ||
114 | + return false; | ||
115 | + } | ||
116 | + | ||
117 | + if (ipv6.getAfi() != AddressFamilyIdentifierEnum.IP6) { | ||
118 | + return false; | ||
119 | + } | ||
120 | + | ||
121 | + return true; | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
88 | * Obtains a set of AFI addresses including IPv4 and IPv6. | 125 | * Obtains a set of AFI addresses including IPv4 and IPv6. |
89 | * | 126 | * |
90 | * @return a set of AFI addresses | 127 | * @return a set of AFI addresses | ... | ... |
... | @@ -23,6 +23,7 @@ import org.onosproject.lisp.msg.exceptions.LispWriterException; | ... | @@ -23,6 +23,7 @@ import org.onosproject.lisp.msg.exceptions.LispWriterException; |
23 | import java.util.Objects; | 23 | import java.util.Objects; |
24 | 24 | ||
25 | import static com.google.common.base.MoreObjects.toStringHelper; | 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
26 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
26 | 27 | ||
27 | /** | 28 | /** |
28 | * Instance ID type LCAF address class. | 29 | * Instance ID type LCAF address class. |
... | @@ -181,6 +182,9 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { | ... | @@ -181,6 +182,9 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { |
181 | * @return LispSegmentLcafAddress instance | 182 | * @return LispSegmentLcafAddress instance |
182 | */ | 183 | */ |
183 | public LispSegmentLcafAddress build() { | 184 | public LispSegmentLcafAddress build() { |
185 | + | ||
186 | + checkNotNull(address, "Must specify an address"); | ||
187 | + | ||
184 | return new LispSegmentLcafAddress(reserved1, idMaskLength, flag, | 188 | return new LispSegmentLcafAddress(reserved1, idMaskLength, flag, |
185 | length, instanceId, address); | 189 | length, instanceId, address); |
186 | } | 190 | } | ... | ... |
... | @@ -23,6 +23,7 @@ import org.onosproject.lisp.msg.exceptions.LispWriterException; | ... | @@ -23,6 +23,7 @@ import org.onosproject.lisp.msg.exceptions.LispWriterException; |
23 | import java.util.Objects; | 23 | import java.util.Objects; |
24 | 24 | ||
25 | import static com.google.common.base.MoreObjects.toStringHelper; | 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
26 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
26 | 27 | ||
27 | /** | 28 | /** |
28 | * Source/Dest key type LCAF address class. | 29 | * Source/Dest key type LCAF address class. |
... | @@ -248,6 +249,10 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { | ... | @@ -248,6 +249,10 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { |
248 | * @return LispSourceDestLcafAddress instance | 249 | * @return LispSourceDestLcafAddress instance |
249 | */ | 250 | */ |
250 | public LispSourceDestLcafAddress build() { | 251 | public LispSourceDestLcafAddress build() { |
252 | + | ||
253 | + checkNotNull(srcPrefix, "Must specify a source address prefix"); | ||
254 | + checkNotNull(dstPrefix, "Must specify a destination address prefix"); | ||
255 | + | ||
251 | return new LispSourceDestLcafAddress(reserved1, reserved2, flag, length, | 256 | return new LispSourceDestLcafAddress(reserved1, reserved2, flag, length, |
252 | reserved, srcMaskLength, dstMaskLength, srcPrefix, dstPrefix); | 257 | reserved, srcMaskLength, dstMaskLength, srcPrefix, dstPrefix); |
253 | } | 258 | } | ... | ... |
-
Please register or login to post a comment