Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.provider.lisp.mapping.util; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onlab.packet.IpPrefix; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 23 | import org.onlab.packet.MacAddress; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 24 | import org.onosproject.lisp.msg.protocols.DefaultLispLocator.DefaultLocatorBuilder; |
| 25 | import org.onosproject.lisp.msg.protocols.DefaultLispMapNotify.DefaultNotifyBuilder; |
| 26 | import org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.DefaultMapRecordBuilder; |
| 27 | import org.onosproject.lisp.msg.protocols.DefaultLispMapReply.DefaultReplyBuilder; |
| 28 | import org.onosproject.lisp.msg.protocols.LispLocator; |
| 29 | import org.onosproject.lisp.msg.protocols.LispLocator.LocatorBuilder; |
| 30 | import org.onosproject.lisp.msg.protocols.LispMapNotify; |
| 31 | import org.onosproject.lisp.msg.protocols.LispMapNotify.NotifyBuilder; |
| 32 | import org.onosproject.lisp.msg.protocols.LispMapRecord; |
| 33 | import org.onosproject.lisp.msg.protocols.LispMapRecord.MapRecordBuilder; |
| 34 | import org.onosproject.lisp.msg.protocols.LispMapReply; |
| 35 | import org.onosproject.lisp.msg.protocols.LispMapReply.ReplyBuilder; |
| 36 | import org.onosproject.lisp.msg.protocols.LispMapReplyAction; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 37 | import org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum; |
| 38 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
| 39 | import org.onosproject.lisp.msg.types.LispAsAddress; |
| 40 | import org.onosproject.lisp.msg.types.LispDistinguishedNameAddress; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 41 | import org.onosproject.lisp.msg.types.LispIpv4Address; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 42 | import org.onosproject.lisp.msg.types.LispIpv6Address; |
| 43 | import org.onosproject.lisp.msg.types.LispMacAddress; |
| 44 | import org.onosproject.lisp.msg.types.lcaf.LispAppDataLcafAddress; |
| 45 | import org.onosproject.lisp.msg.types.lcaf.LispAsLcafAddress; |
| 46 | import org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum; |
| 47 | import org.onosproject.lisp.msg.types.lcaf.LispGeoCoordinateLcafAddress; |
| 48 | import org.onosproject.lisp.msg.types.lcaf.LispLcafAddress; |
| 49 | import org.onosproject.lisp.msg.types.lcaf.LispListLcafAddress; |
| 50 | import org.onosproject.lisp.msg.types.lcaf.LispMulticastLcafAddress; |
| 51 | import org.onosproject.lisp.msg.types.lcaf.LispNatLcafAddress; |
| 52 | import org.onosproject.lisp.msg.types.lcaf.LispNonceLcafAddress; |
| 53 | import org.onosproject.lisp.msg.types.lcaf.LispSegmentLcafAddress; |
| 54 | import org.onosproject.lisp.msg.types.lcaf.LispSourceDestLcafAddress; |
| 55 | import org.onosproject.lisp.msg.types.lcaf.LispTeLcafAddress; |
| 56 | import org.onosproject.lisp.msg.types.lcaf.LispTeRecord; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 57 | import org.onosproject.mapping.MappingEntry; |
| 58 | import org.onosproject.mapping.MappingKey; |
| 59 | import org.onosproject.mapping.MappingTreatment; |
| 60 | import org.onosproject.mapping.MappingValue; |
| 61 | import org.onosproject.mapping.actions.MappingAction; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 62 | import org.onosproject.mapping.addresses.ASMappingAddress; |
| 63 | import org.onosproject.mapping.addresses.DNMappingAddress; |
| 64 | import org.onosproject.mapping.addresses.EthMappingAddress; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 65 | import org.onosproject.mapping.addresses.IPMappingAddress; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 66 | import org.onosproject.mapping.addresses.MappingAddress; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 67 | import org.onosproject.net.DeviceId; |
| 68 | |
| 69 | import java.util.List; |
| 70 | |
| 71 | import static org.hamcrest.MatcherAssert.assertThat; |
| 72 | import static org.hamcrest.Matchers.is; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 73 | import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.AS; |
| 74 | import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.DISTINGUISHED_NAME; |
| 75 | import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.IP4; |
| 76 | import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.IP6; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 77 | import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.MAC; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 78 | import static org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum.UNKNOWN; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 79 | |
| 80 | /** |
| 81 | * Mapping entry builder unit test. |
| 82 | */ |
| 83 | public class MappingEntryBuilderTest { |
| 84 | |
| 85 | private static final String IP_RECORD_ADDRESS = "192.168.1.1"; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 86 | private static final int IP_RECORD_MASK_LENGTH = 32; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 87 | private static final int IP_LOCATOR_MASK_LENGTH = 32; |
| 88 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 89 | private static final LispAfiAddress IPV4_ADDRESS_1 = |
| 90 | new LispIpv4Address(IpAddress.valueOf("1.2.3.4")); |
| 91 | private static final LispAfiAddress IPV4_ADDRESS_2 = |
| 92 | new LispIpv4Address(IpAddress.valueOf("5.6.7.8")); |
| 93 | private static final LispAfiAddress IPV6_ADDRESS = |
| 94 | new LispIpv6Address(IpAddress.valueOf( |
| 95 | "1111:2222:3333:4444:5555:6666:7777:8885")); |
| 96 | private static final LispAfiAddress MAC_ADDRESS = |
| 97 | new LispMacAddress(MacAddress.valueOf("00:00:00:00:00:01")); |
| 98 | |
| 99 | private static final IpPrefix IPV4_MAPPING_ADDRESS_1 = IpPrefix.valueOf("1.2.3.4/32"); |
| 100 | private static final IpPrefix IPV4_MAPPING_ADDRESS_2 = IpPrefix.valueOf("5.6.7.8/32"); |
| 101 | |
| 102 | private static final IpPrefix IPV6_MAPPING_ADDRESS = |
| 103 | IpPrefix.valueOf("1111:2222:3333:4444:5555:6666:7777:8885/128"); |
| 104 | private static final MacAddress MAC_MAPPING_ADDRESS = |
| 105 | MacAddress.valueOf("00:00:00:00:00:01"); |
| 106 | |
| 107 | private static final byte UNIQUE_BYTE = (byte) 0x01; |
| 108 | private static final int UNIQUE_INT = 1; |
| 109 | private static final short UNIQUE_SHORT = 1; |
| 110 | private static final boolean UNIQUE_BOOLEAN = true; |
| 111 | private static final long UNIQUE_LONG = 1L; |
| 112 | private static final String UNIQUE_STRING = "onos"; |
| 113 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 114 | private static final String AUTH_KEY = "onos"; |
| 115 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 116 | private static final DeviceId DEVICE_ID = DeviceId.deviceId("lisp:10.1.1.2"); |
| 117 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 118 | @Before |
| 119 | public void setUp() { |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 120 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Test |
| 124 | public void testMapReplyConversion() { |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 125 | |
| 126 | ReplyBuilder replyBuilder = new DefaultReplyBuilder(); |
| 127 | |
| 128 | List<LispMapRecord> records = ImmutableList.of(getMapRecord(IP4, UNKNOWN)); |
| 129 | |
| 130 | LispMapReply mapReply = replyBuilder |
| 131 | .withIsEtr(true) |
| 132 | .withIsProbe(false) |
| 133 | .withIsSecurity(true) |
| 134 | .withNonce(UNIQUE_LONG) |
| 135 | .withMapRecords(records) |
| 136 | .build(); |
| 137 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 138 | List<LispMapRecord> replyRecords = mapReply.getMapRecords(); |
| 139 | |
| 140 | assertThat(replyRecords.size(), is(1)); |
| 141 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 142 | testMapRecordConversion(replyRecords.get(0)); |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | @Test |
| 146 | public void testMapNotifyConversion() { |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 147 | |
| 148 | List<LispMapRecord> records = ImmutableList.of(getMapRecord(IP4, UNKNOWN)); |
| 149 | |
| 150 | NotifyBuilder notifyBuilder = new DefaultNotifyBuilder(); |
| 151 | |
| 152 | LispMapNotify mapNotify = notifyBuilder |
| 153 | .withKeyId(UNIQUE_SHORT) |
| 154 | .withAuthKey(AUTH_KEY) |
| 155 | .withNonce(UNIQUE_LONG) |
| 156 | .withMapRecords(records) |
| 157 | .build(); |
| 158 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 159 | List<LispMapRecord> notifyRecords = mapNotify.getMapRecords(); |
| 160 | |
| 161 | assertThat(notifyRecords.size(), is(1)); |
| 162 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 163 | testMapRecordConversion(notifyRecords.get(0)); |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 164 | } |
| 165 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 166 | @Test |
| 167 | public void testIpv4AddressConversion() { |
| 168 | IPMappingAddress address = (IPMappingAddress) getMappingAddressByAfiType(IP4, UNKNOWN); |
| 169 | assertThat(address.ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 170 | } |
| 171 | |
| 172 | @Test |
| 173 | public void testIpv6AddressConversion() { |
| 174 | IPMappingAddress address = (IPMappingAddress) getMappingAddressByAfiType(IP6, UNKNOWN); |
| 175 | assertThat(address.ip(), is(IPV6_MAPPING_ADDRESS)); |
| 176 | } |
| 177 | |
| 178 | @Test |
| 179 | public void testMacAddressConversion() { |
| 180 | EthMappingAddress address = (EthMappingAddress) getMappingAddressByAfiType(MAC, UNKNOWN); |
| 181 | assertThat(address.mac(), is(MAC_MAPPING_ADDRESS)); |
| 182 | } |
| 183 | |
| 184 | @Test |
| 185 | public void testAsAddressConversion() { |
| 186 | ASMappingAddress address = (ASMappingAddress) getMappingAddressByAfiType(AS, UNKNOWN); |
| 187 | assertThat(address.asNumber(), is(String.valueOf(UNIQUE_INT))); |
| 188 | } |
| 189 | |
| 190 | @Test |
| 191 | public void testDnAddressConversion() { |
| 192 | DNMappingAddress address = (DNMappingAddress) |
| 193 | getMappingAddressByAfiType(DISTINGUISHED_NAME, UNKNOWN); |
| 194 | assertThat(address.name(), is(UNIQUE_STRING)); |
| 195 | } |
| 196 | |
| 197 | @Test |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 198 | public void testTeLcafAddressConversion() { |
| 199 | // TODO: need to compare TeRecord list |
| 200 | } |
| 201 | |
| 202 | private MappingAddress getMappingAddressByAfiType(AddressFamilyIdentifierEnum afiType, |
| 203 | LispCanonicalAddressFormatEnum lcafType) { |
| 204 | LispMapRecord record = getMapRecord(afiType, lcafType); |
| 205 | MappingEntry entry = new MappingEntryBuilder(DEVICE_ID, record).build(); |
| 206 | return entry.value().treatments().get(0).address(); |
| 207 | } |
| 208 | |
| 209 | private void testMapRecordConversion(LispMapRecord record) { |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 210 | MappingEntry mappingEntry = |
| 211 | new MappingEntryBuilder(DEVICE_ID, record).build(); |
| 212 | MappingKey key = mappingEntry.key(); |
| 213 | MappingValue value = mappingEntry.value(); |
| 214 | |
| 215 | IPMappingAddress recordAddress = (IPMappingAddress) key.address(); |
| 216 | |
| 217 | assertThat(recordAddress.ip(), is(IpPrefix.valueOf(IP_RECORD_ADDRESS + "/" + |
| 218 | IP_RECORD_MASK_LENGTH))); |
| 219 | |
| 220 | assertThat(value.action().type(), is(MappingAction.Type.NATIVE_FORWARD)); |
| 221 | |
| 222 | assertThat(value.treatments().size(), is(1)); |
| 223 | |
| 224 | MappingTreatment treatment = value.treatments().get(0); |
| 225 | IPMappingAddress locatorAddress = (IPMappingAddress) treatment.address(); |
| 226 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 227 | assertThat(locatorAddress.ip(), is(IpPrefix.valueOf(IPV4_ADDRESS_1 + "/" + |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 228 | IP_LOCATOR_MASK_LENGTH))); |
| 229 | } |
| 230 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 231 | /** |
| 232 | * Obtains a MapRecord instance. |
| 233 | * |
| 234 | * @param afiType AFI address type |
| 235 | * @param lcafType LCAF address type |
| 236 | * @return a MapRecord instance |
| 237 | */ |
| 238 | private LispMapRecord getMapRecord(AddressFamilyIdentifierEnum afiType, |
| 239 | LispCanonicalAddressFormatEnum lcafType) { |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 240 | MapRecordBuilder recordBuilder = new DefaultMapRecordBuilder(); |
| 241 | |
| 242 | LispIpv4Address recordAddress = |
| 243 | new LispIpv4Address(IpAddress.valueOf(IP_RECORD_ADDRESS)); |
| 244 | |
| 245 | LocatorBuilder locatorBuilder = new DefaultLocatorBuilder(); |
| 246 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 247 | LispAfiAddress locatorAddress = getAfiAddress(afiType, lcafType); |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 248 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 249 | LispLocator locator = locatorBuilder |
| 250 | .withPriority(UNIQUE_BYTE) |
| 251 | .withWeight(UNIQUE_BYTE) |
| 252 | .withMulticastPriority(UNIQUE_BYTE) |
| 253 | .withMulticastWeight(UNIQUE_BYTE) |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 254 | .withLocalLocator(true) |
| 255 | .withRlocProbed(false) |
| 256 | .withRouted(true) |
| 257 | .withLocatorAfi(locatorAddress) |
| 258 | .build(); |
| 259 | |
| 260 | return recordBuilder |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 261 | .withRecordTtl(UNIQUE_INT) |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 262 | .withIsAuthoritative(true) |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 263 | .withMapVersionNumber(UNIQUE_SHORT) |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 264 | .withMaskLength((byte) IP_RECORD_MASK_LENGTH) |
| 265 | .withAction(LispMapReplyAction.NativelyForward) |
| 266 | .withEidPrefixAfi(recordAddress) |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 267 | .withLocators(ImmutableList.of(locator)) |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 268 | .build(); |
| 269 | } |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * Obtains the AFI address with respect to the AFI address type. |
| 273 | * |
| 274 | * @param afiType AFI address type |
| 275 | * @param lcafType LCAF address type |
| 276 | * @return AFI address instance |
| 277 | */ |
| 278 | private LispAfiAddress getAfiAddress(AddressFamilyIdentifierEnum afiType, |
| 279 | LispCanonicalAddressFormatEnum lcafType) { |
| 280 | switch (afiType) { |
| 281 | case IP4: |
| 282 | return IPV4_ADDRESS_1; |
| 283 | case IP6: |
| 284 | return IPV6_ADDRESS; |
| 285 | case AS: |
| 286 | return new LispAsAddress(UNIQUE_INT); |
| 287 | case DISTINGUISHED_NAME: |
| 288 | return new LispDistinguishedNameAddress(UNIQUE_STRING); |
| 289 | case MAC: |
| 290 | return MAC_ADDRESS; |
| 291 | case LCAF: |
| 292 | return getLcafAddress(lcafType); |
| 293 | default: |
| 294 | return null; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * Obtains the LCAF address with respect to the LCAF type. |
| 300 | * |
| 301 | * @param type LCAF type |
| 302 | * @return LCAF address instance |
| 303 | */ |
| 304 | private LispLcafAddress getLcafAddress(LispCanonicalAddressFormatEnum type) { |
| 305 | |
| 306 | List<LispAfiAddress> afiAddresses = |
| 307 | ImmutableList.of(IPV4_ADDRESS_1, IPV6_ADDRESS); |
| 308 | |
| 309 | switch (type) { |
| 310 | case LIST: |
| 311 | return new LispListLcafAddress(afiAddresses); |
| 312 | case SEGMENT: |
| 313 | return new LispSegmentLcafAddress.SegmentAddressBuilder() |
| 314 | .withIdMaskLength(UNIQUE_BYTE) |
| 315 | .withInstanceId(UNIQUE_INT) |
| 316 | .withAddress(IPV4_ADDRESS_1) |
| 317 | .build(); |
| 318 | case AS: |
| 319 | return new LispAsLcafAddress.AsAddressBuilder() |
| 320 | .withAsNumber(UNIQUE_INT) |
| 321 | .withAddress(IPV4_ADDRESS_1) |
| 322 | .build(); |
| 323 | case APPLICATION_DATA: |
| 324 | return new LispAppDataLcafAddress.AppDataAddressBuilder() |
| 325 | .withProtocol(UNIQUE_BYTE) |
| 326 | .withIpTos(UNIQUE_SHORT) |
| 327 | .withLocalPortLow(UNIQUE_SHORT) |
| 328 | .withLocalPortHigh(UNIQUE_SHORT) |
| 329 | .withRemotePortLow(UNIQUE_SHORT) |
| 330 | .withRemotePortHigh(UNIQUE_SHORT) |
| 331 | .withAddress(IPV4_ADDRESS_1) |
| 332 | .build(); |
| 333 | case GEO_COORDINATE: |
| 334 | return new LispGeoCoordinateLcafAddress.GeoCoordinateAddressBuilder() |
| 335 | .withIsNorth(UNIQUE_BOOLEAN) |
| 336 | .withLatitudeDegree(UNIQUE_SHORT) |
| 337 | .withLatitudeMinute(UNIQUE_BYTE) |
| 338 | .withLatitudeSecond(UNIQUE_BYTE) |
| 339 | .withIsEast(UNIQUE_BOOLEAN) |
| 340 | .withLongitudeDegree(UNIQUE_SHORT) |
| 341 | .withLongitudeMinute(UNIQUE_BYTE) |
| 342 | .withLongitudeSecond(UNIQUE_BYTE) |
| 343 | .withAltitude(UNIQUE_INT) |
| 344 | .withAddress(IPV4_ADDRESS_1) |
| 345 | .build(); |
| 346 | case NAT: |
| 347 | return new LispNatLcafAddress.NatAddressBuilder() |
| 348 | .withLength(UNIQUE_SHORT) |
| 349 | .withMsUdpPortNumber(UNIQUE_SHORT) |
| 350 | .withEtrUdpPortNumber(UNIQUE_SHORT) |
| 351 | .withGlobalEtrRlocAddress(IPV4_ADDRESS_1) |
| 352 | .withMsRlocAddress(IPV4_ADDRESS_1) |
| 353 | .withPrivateEtrRlocAddress(IPV4_ADDRESS_1) |
| 354 | .withRtrRlocAddresses(afiAddresses) |
| 355 | .build(); |
| 356 | case NONCE: |
| 357 | return new LispNonceLcafAddress.NonceAddressBuilder() |
| 358 | .withNonce(UNIQUE_INT) |
| 359 | .withAddress(IPV4_ADDRESS_1) |
| 360 | .build(); |
| 361 | case MULTICAST: |
| 362 | return new LispMulticastLcafAddress.MulticastAddressBuilder() |
| 363 | .withInstanceId(UNIQUE_INT) |
| 364 | .withSrcMaskLength(UNIQUE_BYTE) |
| 365 | .withGrpMaskLength(UNIQUE_BYTE) |
| 366 | .withSrcAddress(IPV4_ADDRESS_1) |
| 367 | .withGrpAddress(IPV4_ADDRESS_1) |
| 368 | .build(); |
| 369 | case TRAFFIC_ENGINEERING: |
| 370 | LispTeRecord.TeRecordBuilder recordBuilder1 = new LispTeRecord.TeRecordBuilder(); |
| 371 | |
| 372 | recordBuilder1.withIsLookup(UNIQUE_BOOLEAN); |
| 373 | recordBuilder1.withIsRlocProbe(UNIQUE_BOOLEAN); |
| 374 | recordBuilder1.withIsStrict(UNIQUE_BOOLEAN); |
| 375 | recordBuilder1.withRtrRlocAddress(IPV4_ADDRESS_1); |
| 376 | LispTeRecord record1 = recordBuilder1.build(); |
| 377 | |
| 378 | LispTeRecord.TeRecordBuilder recordBuilder2 = new LispTeRecord.TeRecordBuilder(); |
| 379 | |
| 380 | recordBuilder2.withIsLookup(UNIQUE_BOOLEAN); |
| 381 | recordBuilder2.withIsRlocProbe(UNIQUE_BOOLEAN); |
| 382 | recordBuilder2.withIsStrict(UNIQUE_BOOLEAN); |
| 383 | recordBuilder2.withRtrRlocAddress(IPV4_ADDRESS_2); |
| 384 | LispTeRecord record2 = recordBuilder2.build(); |
| 385 | |
| 386 | return new LispTeLcafAddress.TeAddressBuilder() |
| 387 | .withTeRecords(ImmutableList.of(record1, record2)) |
| 388 | .build(); |
| 389 | case SOURCE_DEST: |
| 390 | return new LispSourceDestLcafAddress.SourceDestAddressBuilder() |
| 391 | .withReserved(UNIQUE_SHORT) |
| 392 | .withSrcMaskLength(UNIQUE_BYTE) |
| 393 | .withDstMaskLength(UNIQUE_BYTE) |
| 394 | .withSrcPrefix(IPV4_ADDRESS_1) |
| 395 | .withDstPrefix(IPV4_ADDRESS_2) |
| 396 | .build(); |
| 397 | case UNKNOWN: |
| 398 | case UNSPECIFIED: |
| 399 | default: |
| 400 | return null; |
| 401 | } |
| 402 | } |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 403 | } |