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; |
| 24 | import org.onosproject.drivers.lisp.extensions.LispAppDataAddress; |
| 25 | import org.onosproject.drivers.lisp.extensions.LispGcAddress; |
| 26 | import org.onosproject.drivers.lisp.extensions.LispListAddress; |
| 27 | import org.onosproject.drivers.lisp.extensions.LispMulticastAddress; |
| 28 | import org.onosproject.drivers.lisp.extensions.LispNatAddress; |
| 29 | import org.onosproject.drivers.lisp.extensions.LispNonceAddress; |
| 30 | import org.onosproject.drivers.lisp.extensions.LispSegmentAddress; |
| 31 | import org.onosproject.drivers.lisp.extensions.LispSrcDstAddress; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 32 | import org.onosproject.lisp.msg.protocols.DefaultLispLocator.DefaultLocatorBuilder; |
| 33 | import org.onosproject.lisp.msg.protocols.DefaultLispMapNotify.DefaultNotifyBuilder; |
| 34 | import org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.DefaultMapRecordBuilder; |
| 35 | import org.onosproject.lisp.msg.protocols.DefaultLispMapReply.DefaultReplyBuilder; |
| 36 | import org.onosproject.lisp.msg.protocols.LispLocator; |
| 37 | import org.onosproject.lisp.msg.protocols.LispLocator.LocatorBuilder; |
| 38 | import org.onosproject.lisp.msg.protocols.LispMapNotify; |
| 39 | import org.onosproject.lisp.msg.protocols.LispMapNotify.NotifyBuilder; |
| 40 | import org.onosproject.lisp.msg.protocols.LispMapRecord; |
| 41 | import org.onosproject.lisp.msg.protocols.LispMapRecord.MapRecordBuilder; |
| 42 | import org.onosproject.lisp.msg.protocols.LispMapReply; |
| 43 | import org.onosproject.lisp.msg.protocols.LispMapReply.ReplyBuilder; |
| 44 | import org.onosproject.lisp.msg.protocols.LispMapReplyAction; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 45 | import org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum; |
| 46 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
| 47 | import org.onosproject.lisp.msg.types.LispAsAddress; |
| 48 | import org.onosproject.lisp.msg.types.LispDistinguishedNameAddress; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 49 | import org.onosproject.lisp.msg.types.LispIpv4Address; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 50 | import org.onosproject.lisp.msg.types.LispIpv6Address; |
| 51 | import org.onosproject.lisp.msg.types.LispMacAddress; |
| 52 | import org.onosproject.lisp.msg.types.lcaf.LispAppDataLcafAddress; |
| 53 | import org.onosproject.lisp.msg.types.lcaf.LispAsLcafAddress; |
| 54 | import org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum; |
| 55 | import org.onosproject.lisp.msg.types.lcaf.LispGeoCoordinateLcafAddress; |
| 56 | import org.onosproject.lisp.msg.types.lcaf.LispLcafAddress; |
| 57 | import org.onosproject.lisp.msg.types.lcaf.LispListLcafAddress; |
| 58 | import org.onosproject.lisp.msg.types.lcaf.LispMulticastLcafAddress; |
| 59 | import org.onosproject.lisp.msg.types.lcaf.LispNatLcafAddress; |
| 60 | import org.onosproject.lisp.msg.types.lcaf.LispNonceLcafAddress; |
| 61 | import org.onosproject.lisp.msg.types.lcaf.LispSegmentLcafAddress; |
| 62 | import org.onosproject.lisp.msg.types.lcaf.LispSourceDestLcafAddress; |
| 63 | import org.onosproject.lisp.msg.types.lcaf.LispTeLcafAddress; |
| 64 | import org.onosproject.lisp.msg.types.lcaf.LispTeRecord; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 65 | import org.onosproject.mapping.MappingEntry; |
| 66 | import org.onosproject.mapping.MappingKey; |
| 67 | import org.onosproject.mapping.MappingTreatment; |
| 68 | import org.onosproject.mapping.MappingValue; |
| 69 | import org.onosproject.mapping.actions.MappingAction; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 70 | import org.onosproject.mapping.addresses.ASMappingAddress; |
| 71 | import org.onosproject.mapping.addresses.DNMappingAddress; |
| 72 | import org.onosproject.mapping.addresses.EthMappingAddress; |
| 73 | import org.onosproject.mapping.addresses.ExtensionMappingAddressWrapper; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 74 | import org.onosproject.mapping.addresses.IPMappingAddress; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 75 | import org.onosproject.mapping.addresses.MappingAddress; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 76 | import org.onosproject.net.DeviceId; |
| 77 | |
| 78 | import java.util.List; |
| 79 | |
| 80 | import static org.hamcrest.MatcherAssert.assertThat; |
| 81 | import static org.hamcrest.Matchers.is; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 82 | import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.AS; |
| 83 | import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.DISTINGUISHED_NAME; |
| 84 | import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.IP4; |
| 85 | import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.IP6; |
| 86 | import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.LCAF; |
| 87 | import static org.onosproject.lisp.msg.types.AddressFamilyIdentifierEnum.MAC; |
| 88 | import static org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum.APPLICATION_DATA; |
| 89 | import static org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum.GEO_COORDINATE; |
| 90 | import static org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum.LIST; |
| 91 | import static org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum.MULTICAST; |
| 92 | import static org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum.NAT; |
| 93 | import static org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum.NONCE; |
| 94 | import static org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum.SEGMENT; |
| 95 | import static org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum.SOURCE_DEST; |
| 96 | import static org.onosproject.lisp.msg.types.lcaf.LispCanonicalAddressFormatEnum.UNKNOWN; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Mapping entry builder unit test. |
| 100 | */ |
| 101 | public class MappingEntryBuilderTest { |
| 102 | |
| 103 | private static final String IP_RECORD_ADDRESS = "192.168.1.1"; |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 104 | private static final int IP_RECORD_MASK_LENGTH = 32; |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 105 | private static final int IP_LOCATOR_MASK_LENGTH = 32; |
| 106 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 107 | private static final LispAfiAddress IPV4_ADDRESS_1 = |
| 108 | new LispIpv4Address(IpAddress.valueOf("1.2.3.4")); |
| 109 | private static final LispAfiAddress IPV4_ADDRESS_2 = |
| 110 | new LispIpv4Address(IpAddress.valueOf("5.6.7.8")); |
| 111 | private static final LispAfiAddress IPV6_ADDRESS = |
| 112 | new LispIpv6Address(IpAddress.valueOf( |
| 113 | "1111:2222:3333:4444:5555:6666:7777:8885")); |
| 114 | private static final LispAfiAddress MAC_ADDRESS = |
| 115 | new LispMacAddress(MacAddress.valueOf("00:00:00:00:00:01")); |
| 116 | |
| 117 | private static final IpPrefix IPV4_MAPPING_ADDRESS_1 = IpPrefix.valueOf("1.2.3.4/32"); |
| 118 | private static final IpPrefix IPV4_MAPPING_ADDRESS_2 = IpPrefix.valueOf("5.6.7.8/32"); |
| 119 | |
| 120 | private static final IpPrefix IPV6_MAPPING_ADDRESS = |
| 121 | IpPrefix.valueOf("1111:2222:3333:4444:5555:6666:7777:8885/128"); |
| 122 | private static final MacAddress MAC_MAPPING_ADDRESS = |
| 123 | MacAddress.valueOf("00:00:00:00:00:01"); |
| 124 | |
| 125 | private static final byte UNIQUE_BYTE = (byte) 0x01; |
| 126 | private static final int UNIQUE_INT = 1; |
| 127 | private static final short UNIQUE_SHORT = 1; |
| 128 | private static final boolean UNIQUE_BOOLEAN = true; |
| 129 | private static final long UNIQUE_LONG = 1L; |
| 130 | private static final String UNIQUE_STRING = "onos"; |
| 131 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 132 | private static final String AUTH_KEY = "onos"; |
| 133 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 134 | private static final DeviceId DEVICE_ID = DeviceId.deviceId("lisp:10.1.1.2"); |
| 135 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 136 | @Before |
| 137 | public void setUp() { |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 138 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | @Test |
| 142 | public void testMapReplyConversion() { |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 143 | |
| 144 | ReplyBuilder replyBuilder = new DefaultReplyBuilder(); |
| 145 | |
| 146 | List<LispMapRecord> records = ImmutableList.of(getMapRecord(IP4, UNKNOWN)); |
| 147 | |
| 148 | LispMapReply mapReply = replyBuilder |
| 149 | .withIsEtr(true) |
| 150 | .withIsProbe(false) |
| 151 | .withIsSecurity(true) |
| 152 | .withNonce(UNIQUE_LONG) |
| 153 | .withMapRecords(records) |
| 154 | .build(); |
| 155 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 156 | List<LispMapRecord> replyRecords = mapReply.getMapRecords(); |
| 157 | |
| 158 | assertThat(replyRecords.size(), is(1)); |
| 159 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 160 | testMapRecordConversion(replyRecords.get(0)); |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | @Test |
| 164 | public void testMapNotifyConversion() { |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 165 | |
| 166 | List<LispMapRecord> records = ImmutableList.of(getMapRecord(IP4, UNKNOWN)); |
| 167 | |
| 168 | NotifyBuilder notifyBuilder = new DefaultNotifyBuilder(); |
| 169 | |
| 170 | LispMapNotify mapNotify = notifyBuilder |
| 171 | .withKeyId(UNIQUE_SHORT) |
| 172 | .withAuthKey(AUTH_KEY) |
| 173 | .withNonce(UNIQUE_LONG) |
| 174 | .withMapRecords(records) |
| 175 | .build(); |
| 176 | |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 177 | List<LispMapRecord> notifyRecords = mapNotify.getMapRecords(); |
| 178 | |
| 179 | assertThat(notifyRecords.size(), is(1)); |
| 180 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 181 | testMapRecordConversion(notifyRecords.get(0)); |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 182 | } |
| 183 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 184 | @Test |
| 185 | public void testIpv4AddressConversion() { |
| 186 | IPMappingAddress address = (IPMappingAddress) getMappingAddressByAfiType(IP4, UNKNOWN); |
| 187 | assertThat(address.ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 188 | } |
| 189 | |
| 190 | @Test |
| 191 | public void testIpv6AddressConversion() { |
| 192 | IPMappingAddress address = (IPMappingAddress) getMappingAddressByAfiType(IP6, UNKNOWN); |
| 193 | assertThat(address.ip(), is(IPV6_MAPPING_ADDRESS)); |
| 194 | } |
| 195 | |
| 196 | @Test |
| 197 | public void testMacAddressConversion() { |
| 198 | EthMappingAddress address = (EthMappingAddress) getMappingAddressByAfiType(MAC, UNKNOWN); |
| 199 | assertThat(address.mac(), is(MAC_MAPPING_ADDRESS)); |
| 200 | } |
| 201 | |
| 202 | @Test |
| 203 | public void testAsAddressConversion() { |
| 204 | ASMappingAddress address = (ASMappingAddress) getMappingAddressByAfiType(AS, UNKNOWN); |
| 205 | assertThat(address.asNumber(), is(String.valueOf(UNIQUE_INT))); |
| 206 | } |
| 207 | |
| 208 | @Test |
| 209 | public void testDnAddressConversion() { |
| 210 | DNMappingAddress address = (DNMappingAddress) |
| 211 | getMappingAddressByAfiType(DISTINGUISHED_NAME, UNKNOWN); |
| 212 | assertThat(address.name(), is(UNIQUE_STRING)); |
| 213 | } |
| 214 | |
| 215 | @Test |
| 216 | public void testListLcafAddressConversion() { |
| 217 | LispListAddress address = (LispListAddress) ((ExtensionMappingAddressWrapper) |
| 218 | getMappingAddressByAfiType(LCAF, LIST)).extensionMappingAddress(); |
| 219 | assertThat(((IPMappingAddress) address.getIpv4()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 220 | assertThat(((IPMappingAddress) address.getIpv6()).ip(), is(IPV6_MAPPING_ADDRESS)); |
| 221 | } |
| 222 | |
| 223 | @Test |
| 224 | public void testSegmentLcafAddressConversion() { |
| 225 | LispSegmentAddress address = (LispSegmentAddress) ((ExtensionMappingAddressWrapper) |
| 226 | getMappingAddressByAfiType(LCAF, SEGMENT)).extensionMappingAddress(); |
| 227 | assertThat(((IPMappingAddress) address.getAddress()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 228 | assertThat(address.getInstanceId(), is(UNIQUE_INT)); |
| 229 | } |
| 230 | |
| 231 | @Test |
| 232 | public void testAsLcafAddressConversion() { |
| 233 | org.onosproject.drivers.lisp.extensions.LispAsAddress address = |
| 234 | (org.onosproject.drivers.lisp.extensions.LispAsAddress) |
| 235 | ((ExtensionMappingAddressWrapper) |
| 236 | getMappingAddressByAfiType(LCAF, |
| 237 | LispCanonicalAddressFormatEnum.AS)).extensionMappingAddress(); |
| 238 | assertThat(((IPMappingAddress) address.getAddress()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 239 | assertThat(address.getAsNumber(), is(UNIQUE_INT)); |
| 240 | } |
| 241 | |
| 242 | @Test |
| 243 | public void testAppDataLcafAddressConversion() { |
| 244 | LispAppDataAddress address = (LispAppDataAddress) ((ExtensionMappingAddressWrapper) |
| 245 | getMappingAddressByAfiType(LCAF, APPLICATION_DATA)).extensionMappingAddress(); |
| 246 | assertThat(((IPMappingAddress) address.getAddress()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 247 | assertThat(address.getProtocol(), is(UNIQUE_BYTE)); |
| 248 | assertThat(address.getIpTos(), is(UNIQUE_INT)); |
| 249 | assertThat(address.getLocalPortLow(), is(UNIQUE_SHORT)); |
| 250 | assertThat(address.getLocalPortHigh(), is(UNIQUE_SHORT)); |
| 251 | assertThat(address.getRemotePortLow(), is(UNIQUE_SHORT)); |
| 252 | assertThat(address.getRemotePortHigh(), is(UNIQUE_SHORT)); |
| 253 | } |
| 254 | |
| 255 | @Test |
| 256 | public void testGcLcafAddressConversion() { |
| 257 | LispGcAddress address = (LispGcAddress) ((ExtensionMappingAddressWrapper) |
| 258 | getMappingAddressByAfiType(LCAF, GEO_COORDINATE)).extensionMappingAddress(); |
| 259 | assertThat(((IPMappingAddress) address.getAddress()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 260 | assertThat(address.isNorth(), is(UNIQUE_BOOLEAN)); |
| 261 | assertThat(address.getLatitudeDegree(), is(UNIQUE_SHORT)); |
| 262 | assertThat(address.getLatitudeMinute(), is(UNIQUE_BYTE)); |
| 263 | assertThat(address.getLatitudeSecond(), is(UNIQUE_BYTE)); |
| 264 | assertThat(address.isEast(), is(UNIQUE_BOOLEAN)); |
| 265 | assertThat(address.getLongitudeDegree(), is(UNIQUE_SHORT)); |
| 266 | assertThat(address.getLongitudeMinute(), is(UNIQUE_BYTE)); |
| 267 | assertThat(address.getLongitudeSecond(), is(UNIQUE_BYTE)); |
| 268 | assertThat(address.getAltitude(), is(UNIQUE_INT)); |
| 269 | } |
| 270 | |
| 271 | @Test |
| 272 | public void testNatLcafAddressConversion() { |
| 273 | LispNatAddress address = (LispNatAddress) ((ExtensionMappingAddressWrapper) |
| 274 | getMappingAddressByAfiType(LCAF, NAT)).extensionMappingAddress(); |
| 275 | assertThat(((IPMappingAddress) |
| 276 | address.getPrivateEtrRlocAddress()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 277 | assertThat(((IPMappingAddress) |
| 278 | address.getGlobalEtrRlocAddress()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 279 | assertThat(((IPMappingAddress) |
| 280 | address.getMsRlocAddress()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 281 | assertThat(address.getEtrUdpPortNumber(), is(UNIQUE_SHORT)); |
| 282 | assertThat(address.getMsUdpPortNumber(), is(UNIQUE_SHORT)); |
| 283 | // TODO: need to compare RtrRlocAddresses |
| 284 | } |
| 285 | |
| 286 | @Test |
| 287 | public void testNonceLcafAddressConversion() { |
| 288 | LispNonceAddress address = (LispNonceAddress) ((ExtensionMappingAddressWrapper) |
| 289 | getMappingAddressByAfiType(LCAF, NONCE)).extensionMappingAddress(); |
| 290 | assertThat(((IPMappingAddress) address.getAddress()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 291 | assertThat(address.getNonce(), is(UNIQUE_INT)); |
| 292 | } |
| 293 | |
| 294 | @Test |
| 295 | public void testMulticastLcafAddressConversion() { |
| 296 | LispMulticastAddress address = (LispMulticastAddress) ((ExtensionMappingAddressWrapper) |
| 297 | getMappingAddressByAfiType(LCAF, MULTICAST)).extensionMappingAddress(); |
| 298 | assertThat(((IPMappingAddress) address.getSrcAddress()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 299 | assertThat(((IPMappingAddress) address.getGrpAddress()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 300 | assertThat(address.getInstanceId(), is(UNIQUE_INT)); |
| 301 | assertThat(address.getSrcMaskLength(), is(UNIQUE_BYTE)); |
| 302 | assertThat(address.getGrpMaskLength(), is(UNIQUE_BYTE)); |
| 303 | } |
| 304 | |
| 305 | @Test |
| 306 | public void testSrcDstLcafAddressConversion() { |
| 307 | LispSrcDstAddress address = (LispSrcDstAddress) ((ExtensionMappingAddressWrapper) |
| 308 | getMappingAddressByAfiType(LCAF, SOURCE_DEST)).extensionMappingAddress(); |
| 309 | assertThat(((IPMappingAddress) address.getSrcPrefix()).ip(), is(IPV4_MAPPING_ADDRESS_1)); |
| 310 | assertThat(((IPMappingAddress) address.getDstPrefix()).ip(), is(IPV4_MAPPING_ADDRESS_2)); |
| 311 | assertThat(address.getSrcMaskLength(), is(UNIQUE_BYTE)); |
| 312 | assertThat(address.getDstMaskLength(), is(UNIQUE_BYTE)); |
| 313 | } |
| 314 | |
| 315 | @Test |
| 316 | public void testTeLcafAddressConversion() { |
| 317 | // TODO: need to compare TeRecord list |
| 318 | } |
| 319 | |
| 320 | private MappingAddress getMappingAddressByAfiType(AddressFamilyIdentifierEnum afiType, |
| 321 | LispCanonicalAddressFormatEnum lcafType) { |
| 322 | LispMapRecord record = getMapRecord(afiType, lcafType); |
| 323 | MappingEntry entry = new MappingEntryBuilder(DEVICE_ID, record).build(); |
| 324 | return entry.value().treatments().get(0).address(); |
| 325 | } |
| 326 | |
| 327 | private void testMapRecordConversion(LispMapRecord record) { |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 328 | MappingEntry mappingEntry = |
| 329 | new MappingEntryBuilder(DEVICE_ID, record).build(); |
| 330 | MappingKey key = mappingEntry.key(); |
| 331 | MappingValue value = mappingEntry.value(); |
| 332 | |
| 333 | IPMappingAddress recordAddress = (IPMappingAddress) key.address(); |
| 334 | |
| 335 | assertThat(recordAddress.ip(), is(IpPrefix.valueOf(IP_RECORD_ADDRESS + "/" + |
| 336 | IP_RECORD_MASK_LENGTH))); |
| 337 | |
| 338 | assertThat(value.action().type(), is(MappingAction.Type.NATIVE_FORWARD)); |
| 339 | |
| 340 | assertThat(value.treatments().size(), is(1)); |
| 341 | |
| 342 | MappingTreatment treatment = value.treatments().get(0); |
| 343 | IPMappingAddress locatorAddress = (IPMappingAddress) treatment.address(); |
| 344 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 345 | assertThat(locatorAddress.ip(), is(IpPrefix.valueOf(IPV4_ADDRESS_1 + "/" + |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 346 | IP_LOCATOR_MASK_LENGTH))); |
| 347 | } |
| 348 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 349 | /** |
| 350 | * Obtains a MapRecord instance. |
| 351 | * |
| 352 | * @param afiType AFI address type |
| 353 | * @param lcafType LCAF address type |
| 354 | * @return a MapRecord instance |
| 355 | */ |
| 356 | private LispMapRecord getMapRecord(AddressFamilyIdentifierEnum afiType, |
| 357 | LispCanonicalAddressFormatEnum lcafType) { |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 358 | MapRecordBuilder recordBuilder = new DefaultMapRecordBuilder(); |
| 359 | |
| 360 | LispIpv4Address recordAddress = |
| 361 | new LispIpv4Address(IpAddress.valueOf(IP_RECORD_ADDRESS)); |
| 362 | |
| 363 | LocatorBuilder locatorBuilder = new DefaultLocatorBuilder(); |
| 364 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 365 | LispAfiAddress locatorAddress = getAfiAddress(afiType, lcafType); |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 366 | |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 367 | LispLocator locator = locatorBuilder |
| 368 | .withPriority(UNIQUE_BYTE) |
| 369 | .withWeight(UNIQUE_BYTE) |
| 370 | .withMulticastPriority(UNIQUE_BYTE) |
| 371 | .withMulticastWeight(UNIQUE_BYTE) |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 372 | .withLocalLocator(true) |
| 373 | .withRlocProbed(false) |
| 374 | .withRouted(true) |
| 375 | .withLocatorAfi(locatorAddress) |
| 376 | .build(); |
| 377 | |
| 378 | return recordBuilder |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 379 | .withRecordTtl(UNIQUE_INT) |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 380 | .withIsAuthoritative(true) |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 381 | .withMapVersionNumber(UNIQUE_SHORT) |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 382 | .withMaskLength((byte) IP_RECORD_MASK_LENGTH) |
| 383 | .withAction(LispMapReplyAction.NativelyForward) |
| 384 | .withEidPrefixAfi(recordAddress) |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 385 | .withLocators(ImmutableList.of(locator)) |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 386 | .build(); |
| 387 | } |
Jian Li | 0f0d748 | 2017-03-20 15:16:13 +0900 | [diff] [blame] | 388 | |
| 389 | /** |
| 390 | * Obtains the AFI address with respect to the AFI address type. |
| 391 | * |
| 392 | * @param afiType AFI address type |
| 393 | * @param lcafType LCAF address type |
| 394 | * @return AFI address instance |
| 395 | */ |
| 396 | private LispAfiAddress getAfiAddress(AddressFamilyIdentifierEnum afiType, |
| 397 | LispCanonicalAddressFormatEnum lcafType) { |
| 398 | switch (afiType) { |
| 399 | case IP4: |
| 400 | return IPV4_ADDRESS_1; |
| 401 | case IP6: |
| 402 | return IPV6_ADDRESS; |
| 403 | case AS: |
| 404 | return new LispAsAddress(UNIQUE_INT); |
| 405 | case DISTINGUISHED_NAME: |
| 406 | return new LispDistinguishedNameAddress(UNIQUE_STRING); |
| 407 | case MAC: |
| 408 | return MAC_ADDRESS; |
| 409 | case LCAF: |
| 410 | return getLcafAddress(lcafType); |
| 411 | default: |
| 412 | return null; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Obtains the LCAF address with respect to the LCAF type. |
| 418 | * |
| 419 | * @param type LCAF type |
| 420 | * @return LCAF address instance |
| 421 | */ |
| 422 | private LispLcafAddress getLcafAddress(LispCanonicalAddressFormatEnum type) { |
| 423 | |
| 424 | List<LispAfiAddress> afiAddresses = |
| 425 | ImmutableList.of(IPV4_ADDRESS_1, IPV6_ADDRESS); |
| 426 | |
| 427 | switch (type) { |
| 428 | case LIST: |
| 429 | return new LispListLcafAddress(afiAddresses); |
| 430 | case SEGMENT: |
| 431 | return new LispSegmentLcafAddress.SegmentAddressBuilder() |
| 432 | .withIdMaskLength(UNIQUE_BYTE) |
| 433 | .withInstanceId(UNIQUE_INT) |
| 434 | .withAddress(IPV4_ADDRESS_1) |
| 435 | .build(); |
| 436 | case AS: |
| 437 | return new LispAsLcafAddress.AsAddressBuilder() |
| 438 | .withAsNumber(UNIQUE_INT) |
| 439 | .withAddress(IPV4_ADDRESS_1) |
| 440 | .build(); |
| 441 | case APPLICATION_DATA: |
| 442 | return new LispAppDataLcafAddress.AppDataAddressBuilder() |
| 443 | .withProtocol(UNIQUE_BYTE) |
| 444 | .withIpTos(UNIQUE_SHORT) |
| 445 | .withLocalPortLow(UNIQUE_SHORT) |
| 446 | .withLocalPortHigh(UNIQUE_SHORT) |
| 447 | .withRemotePortLow(UNIQUE_SHORT) |
| 448 | .withRemotePortHigh(UNIQUE_SHORT) |
| 449 | .withAddress(IPV4_ADDRESS_1) |
| 450 | .build(); |
| 451 | case GEO_COORDINATE: |
| 452 | return new LispGeoCoordinateLcafAddress.GeoCoordinateAddressBuilder() |
| 453 | .withIsNorth(UNIQUE_BOOLEAN) |
| 454 | .withLatitudeDegree(UNIQUE_SHORT) |
| 455 | .withLatitudeMinute(UNIQUE_BYTE) |
| 456 | .withLatitudeSecond(UNIQUE_BYTE) |
| 457 | .withIsEast(UNIQUE_BOOLEAN) |
| 458 | .withLongitudeDegree(UNIQUE_SHORT) |
| 459 | .withLongitudeMinute(UNIQUE_BYTE) |
| 460 | .withLongitudeSecond(UNIQUE_BYTE) |
| 461 | .withAltitude(UNIQUE_INT) |
| 462 | .withAddress(IPV4_ADDRESS_1) |
| 463 | .build(); |
| 464 | case NAT: |
| 465 | return new LispNatLcafAddress.NatAddressBuilder() |
| 466 | .withLength(UNIQUE_SHORT) |
| 467 | .withMsUdpPortNumber(UNIQUE_SHORT) |
| 468 | .withEtrUdpPortNumber(UNIQUE_SHORT) |
| 469 | .withGlobalEtrRlocAddress(IPV4_ADDRESS_1) |
| 470 | .withMsRlocAddress(IPV4_ADDRESS_1) |
| 471 | .withPrivateEtrRlocAddress(IPV4_ADDRESS_1) |
| 472 | .withRtrRlocAddresses(afiAddresses) |
| 473 | .build(); |
| 474 | case NONCE: |
| 475 | return new LispNonceLcafAddress.NonceAddressBuilder() |
| 476 | .withNonce(UNIQUE_INT) |
| 477 | .withAddress(IPV4_ADDRESS_1) |
| 478 | .build(); |
| 479 | case MULTICAST: |
| 480 | return new LispMulticastLcafAddress.MulticastAddressBuilder() |
| 481 | .withInstanceId(UNIQUE_INT) |
| 482 | .withSrcMaskLength(UNIQUE_BYTE) |
| 483 | .withGrpMaskLength(UNIQUE_BYTE) |
| 484 | .withSrcAddress(IPV4_ADDRESS_1) |
| 485 | .withGrpAddress(IPV4_ADDRESS_1) |
| 486 | .build(); |
| 487 | case TRAFFIC_ENGINEERING: |
| 488 | LispTeRecord.TeRecordBuilder recordBuilder1 = new LispTeRecord.TeRecordBuilder(); |
| 489 | |
| 490 | recordBuilder1.withIsLookup(UNIQUE_BOOLEAN); |
| 491 | recordBuilder1.withIsRlocProbe(UNIQUE_BOOLEAN); |
| 492 | recordBuilder1.withIsStrict(UNIQUE_BOOLEAN); |
| 493 | recordBuilder1.withRtrRlocAddress(IPV4_ADDRESS_1); |
| 494 | LispTeRecord record1 = recordBuilder1.build(); |
| 495 | |
| 496 | LispTeRecord.TeRecordBuilder recordBuilder2 = new LispTeRecord.TeRecordBuilder(); |
| 497 | |
| 498 | recordBuilder2.withIsLookup(UNIQUE_BOOLEAN); |
| 499 | recordBuilder2.withIsRlocProbe(UNIQUE_BOOLEAN); |
| 500 | recordBuilder2.withIsStrict(UNIQUE_BOOLEAN); |
| 501 | recordBuilder2.withRtrRlocAddress(IPV4_ADDRESS_2); |
| 502 | LispTeRecord record2 = recordBuilder2.build(); |
| 503 | |
| 504 | return new LispTeLcafAddress.TeAddressBuilder() |
| 505 | .withTeRecords(ImmutableList.of(record1, record2)) |
| 506 | .build(); |
| 507 | case SOURCE_DEST: |
| 508 | return new LispSourceDestLcafAddress.SourceDestAddressBuilder() |
| 509 | .withReserved(UNIQUE_SHORT) |
| 510 | .withSrcMaskLength(UNIQUE_BYTE) |
| 511 | .withDstMaskLength(UNIQUE_BYTE) |
| 512 | .withSrcPrefix(IPV4_ADDRESS_1) |
| 513 | .withDstPrefix(IPV4_ADDRESS_2) |
| 514 | .build(); |
| 515 | case UNKNOWN: |
| 516 | case UNSPECIFIED: |
| 517 | default: |
| 518 | return null; |
| 519 | } |
| 520 | } |
Jian Li | b8436bb | 2017-02-23 03:39:08 +0900 | [diff] [blame] | 521 | } |