Jian Li | 451cea3 | 2016-10-04 15:27:50 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-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 | */ |
Jian Li | 5e505c6 | 2016-12-05 02:44:24 +0900 | [diff] [blame] | 16 | package org.onosproject.lisp.ctl.impl; |
Jian Li | 451cea3 | 2016-10-04 15:27:50 +0900 | [diff] [blame] | 17 | |
Jian Li | b86d8ad | 2017-05-03 02:53:44 +0900 | [diff] [blame^] | 18 | import com.google.common.collect.ImmutableList; |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 19 | import org.onlab.packet.IpAddress; |
Jian Li | b86d8ad | 2017-05-03 02:53:44 +0900 | [diff] [blame^] | 20 | import org.onosproject.lisp.ctl.LispRouter; |
| 21 | import org.onosproject.lisp.ctl.LispRouterFactory; |
| 22 | import org.onosproject.lisp.ctl.impl.util.LispMapUtil; |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 23 | import org.onosproject.lisp.msg.authentication.LispAuthenticationConfig; |
Jian Li | 5e505c6 | 2016-12-05 02:44:24 +0900 | [diff] [blame] | 24 | import org.onosproject.lisp.msg.protocols.DefaultLispInfoReply.DefaultInfoReplyBuilder; |
| 25 | import org.onosproject.lisp.msg.protocols.DefaultLispInfoRequest.DefaultInfoRequestBuilder; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 26 | import org.onosproject.lisp.msg.protocols.DefaultLispMapNotify.DefaultNotifyBuilder; |
| 27 | import org.onosproject.lisp.msg.protocols.DefaultLispMapRegister.DefaultRegisterBuilder; |
Jian Li | b86d8ad | 2017-05-03 02:53:44 +0900 | [diff] [blame^] | 28 | import org.onosproject.lisp.msg.protocols.DefaultLispMapRequest.DefaultRequestBuilder; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 29 | import org.onosproject.lisp.msg.protocols.LispEidRecord; |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 30 | import org.onosproject.lisp.msg.protocols.LispInfoReply; |
| 31 | import org.onosproject.lisp.msg.protocols.LispInfoReply.InfoReplyBuilder; |
| 32 | import org.onosproject.lisp.msg.protocols.LispInfoRequest; |
| 33 | import org.onosproject.lisp.msg.protocols.LispInfoRequest.InfoRequestBuilder; |
Jian Li | afe2d3f | 2016-11-01 02:49:07 +0900 | [diff] [blame] | 34 | import org.onosproject.lisp.msg.protocols.LispMapNotify; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 35 | import org.onosproject.lisp.msg.protocols.LispMapNotify.NotifyBuilder; |
Jian Li | b86d8ad | 2017-05-03 02:53:44 +0900 | [diff] [blame^] | 36 | import org.onosproject.lisp.msg.protocols.LispMapRecord; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 37 | import org.onosproject.lisp.msg.protocols.LispMapRegister; |
| 38 | import org.onosproject.lisp.msg.protocols.LispMapRegister.RegisterBuilder; |
Jian Li | b86d8ad | 2017-05-03 02:53:44 +0900 | [diff] [blame^] | 39 | import org.onosproject.lisp.msg.protocols.LispMapRequest; |
| 40 | import org.onosproject.lisp.msg.protocols.LispMapRequest.RequestBuilder; |
Jian Li | 451cea3 | 2016-10-04 15:27:50 +0900 | [diff] [blame] | 41 | import org.onosproject.lisp.msg.protocols.LispMessage; |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 42 | import org.onosproject.lisp.msg.types.LispAfiAddress; |
| 43 | import org.onosproject.lisp.msg.types.LispIpv4Address; |
| 44 | import org.onosproject.lisp.msg.types.LispIpv6Address; |
Jian Li | f31019a | 2017-02-05 07:57:46 +0900 | [diff] [blame] | 45 | import org.onosproject.lisp.msg.types.lcaf.LispNatLcafAddress.NatAddressBuilder; |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 46 | import org.onosproject.lisp.msg.types.LispNoAddress; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 47 | import org.slf4j.Logger; |
| 48 | import org.slf4j.LoggerFactory; |
| 49 | |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 50 | import java.net.InetAddress; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 51 | import java.net.InetSocketAddress; |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 52 | import java.net.UnknownHostException; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 53 | import java.util.Arrays; |
Jian Li | b86d8ad | 2017-05-03 02:53:44 +0900 | [diff] [blame^] | 54 | import java.util.Collection; |
| 55 | import java.util.List; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 56 | |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 57 | import static org.onlab.packet.IpAddress.valueOf; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 58 | import static org.onosproject.lisp.msg.authentication.LispAuthenticationKeyEnum.valueOf; |
Jian Li | 451cea3 | 2016-10-04 15:27:50 +0900 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * LISP map server class. |
| 62 | * Handles map-register message and acknowledges with map-notify message. |
| 63 | */ |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 64 | public final class LispMapServer { |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 65 | |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 66 | private static final Logger log = LoggerFactory.getLogger(LispMapServer.class); |
| 67 | |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame] | 68 | private static final int MAP_NOTIFY_PORT = 4342; |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 69 | private static final int INFO_REPLY_PORT = 4342; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 70 | |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 71 | private static final String INVALID_AUTHENTICATION_DATA_MSG = |
| 72 | "Unmatched authentication data of {}."; |
| 73 | private static final String FAILED_TO_FORMULATE_NAT_MSG = |
| 74 | "Fails during formulate NAT address."; |
| 75 | |
Jian Li | b86d8ad | 2017-05-03 02:53:44 +0900 | [diff] [blame^] | 76 | private boolean enableSmr = false; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 77 | |
Jian Li | 29986d8 | 2016-12-01 03:25:12 +0900 | [diff] [blame] | 78 | private LispMappingDatabase mapDb = LispMappingDatabase.getInstance(); |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 79 | private LispAuthenticationConfig authConfig = LispAuthenticationConfig.getInstance(); |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 80 | |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 81 | // non-instantiable (except for our Singleton) |
| 82 | private LispMapServer() { |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 83 | } |
| 84 | |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 85 | static LispMapServer getInstance() { |
Jian Li | 29986d8 | 2016-12-01 03:25:12 +0900 | [diff] [blame] | 86 | return SingletonHelper.INSTANCE; |
| 87 | } |
| 88 | |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 89 | /** |
Jian Li | b86d8ad | 2017-05-03 02:53:44 +0900 | [diff] [blame^] | 90 | * Enable LISP Map server sends SMR(Solicit Map Request) message. |
| 91 | * |
| 92 | * @param enable whether enable or disable sending SMR |
| 93 | */ |
| 94 | public void enableSmr(boolean enable) { |
| 95 | this.enableSmr = enable; |
| 96 | } |
| 97 | |
| 98 | /** |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 99 | * Handles map-register message and replies with map-notify message. |
| 100 | * |
| 101 | * @param message map-register message |
| 102 | * @return map-notify message |
| 103 | */ |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 104 | LispMapNotify processMapRegister(LispMessage message) { |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 105 | |
| 106 | LispMapRegister register = (LispMapRegister) message; |
| 107 | |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame] | 108 | if (!checkMapRegisterAuthData(register)) { |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 109 | log.warn(INVALID_AUTHENTICATION_DATA_MSG, "Map-Register"); |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 110 | return null; |
| 111 | } |
| 112 | |
Jian Li | 29986d8 | 2016-12-01 03:25:12 +0900 | [diff] [blame] | 113 | register.getMapRecords().forEach(mapRecord -> { |
| 114 | LispEidRecord eidRecord = |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 115 | new LispEidRecord(mapRecord.getMaskLength(), |
| 116 | mapRecord.getEidPrefixAfi()); |
Jian Li | 29986d8 | 2016-12-01 03:25:12 +0900 | [diff] [blame] | 117 | |
Jian Li | b86d8ad | 2017-05-03 02:53:44 +0900 | [diff] [blame^] | 118 | LispMapRecord oldMapRecord = mapDb.getMapRecordByEidRecord(eidRecord, |
| 119 | register.isProxyMapReply()); |
| 120 | if (oldMapRecord == null) { |
| 121 | mapDb.putMapRecord(eidRecord, mapRecord, register.isProxyMapReply()); |
| 122 | } else { |
| 123 | if (oldMapRecord.getMapVersionNumber() <= mapRecord.getMapVersionNumber()) { |
| 124 | mapDb.putMapRecord(eidRecord, mapRecord, register.isProxyMapReply()); |
| 125 | |
| 126 | if (enableSmr) { |
| 127 | sendSmrMessage(eidRecord); |
| 128 | } |
| 129 | } |
| 130 | } |
Jian Li | 29986d8 | 2016-12-01 03:25:12 +0900 | [diff] [blame] | 131 | }); |
| 132 | |
Jian Li | 2c8a2a4 | 2016-11-24 02:51:03 +0900 | [diff] [blame] | 133 | // we only acknowledge back to ETR when want-map-notify bit is set to true |
| 134 | // otherwise, we do not acknowledge back to ETR |
| 135 | if (register.isWantMapNotify()) { |
| 136 | NotifyBuilder notifyBuilder = new DefaultNotifyBuilder(); |
| 137 | notifyBuilder.withKeyId(authConfig.lispAuthKeyId()); |
| 138 | notifyBuilder.withAuthDataLength(valueOf(authConfig.lispAuthKeyId()).getHashLength()); |
| 139 | notifyBuilder.withAuthKey(authConfig.lispAuthKey()); |
| 140 | notifyBuilder.withNonce(register.getNonce()); |
| 141 | notifyBuilder.withMapRecords(register.getMapRecords()); |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 142 | |
Jian Li | 2c8a2a4 | 2016-11-24 02:51:03 +0900 | [diff] [blame] | 143 | LispMapNotify notify = notifyBuilder.build(); |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 144 | |
Jian Li | 2c8a2a4 | 2016-11-24 02:51:03 +0900 | [diff] [blame] | 145 | InetSocketAddress address = |
| 146 | new InetSocketAddress(register.getSender().getAddress(), MAP_NOTIFY_PORT); |
| 147 | notify.configSender(address); |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 148 | |
Jian Li | 2c8a2a4 | 2016-11-24 02:51:03 +0900 | [diff] [blame] | 149 | return notify; |
| 150 | } |
| 151 | |
| 152 | return null; |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /** |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 156 | * Handles info-request message and replies with info-reply message. |
| 157 | * |
| 158 | * @param message info-request message |
| 159 | * @return info-reply message |
| 160 | */ |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 161 | LispInfoReply processInfoRequest(LispMessage message) { |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 162 | LispInfoRequest request = (LispInfoRequest) message; |
| 163 | |
| 164 | if (!checkInfoRequestAuthData(request)) { |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 165 | log.warn(INVALID_AUTHENTICATION_DATA_MSG, "Info-Request"); |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 166 | return null; |
| 167 | } |
| 168 | |
| 169 | NatAddressBuilder natBuilder = new NatAddressBuilder(); |
| 170 | try { |
| 171 | LispAfiAddress msAddress = |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 172 | new LispIpv4Address(valueOf(InetAddress.getLocalHost())); |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 173 | natBuilder.withMsRlocAddress(msAddress); |
| 174 | natBuilder.withMsUdpPortNumber((short) INFO_REPLY_PORT); |
| 175 | |
| 176 | // try to extract global ETR RLOC address from info-request |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 177 | IpAddress globalRlocIp = valueOf(request.getSender().getAddress()); |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 178 | LispAfiAddress globalRlocAddress; |
| 179 | if (globalRlocIp.isIp4()) { |
| 180 | globalRlocAddress = new LispIpv4Address(globalRlocIp); |
| 181 | } else { |
| 182 | globalRlocAddress = new LispIpv6Address(globalRlocIp); |
| 183 | } |
| 184 | natBuilder.withGlobalEtrRlocAddress(globalRlocAddress); |
| 185 | natBuilder.withEtrUdpPortNumber((short) request.getSender().getPort()); |
| 186 | natBuilder.withPrivateEtrRlocAddress(new LispNoAddress()); |
| 187 | |
| 188 | // TODO: need to specify RTR addresses |
| 189 | |
| 190 | } catch (UnknownHostException e) { |
Jian Li | cdbc087 | 2016-12-05 17:23:53 +0900 | [diff] [blame] | 191 | log.warn(FAILED_TO_FORMULATE_NAT_MSG, e); |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 192 | } |
| 193 | |
Jian Li | 5e505c6 | 2016-12-05 02:44:24 +0900 | [diff] [blame] | 194 | InfoReplyBuilder replyBuilder = new DefaultInfoReplyBuilder(); |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 195 | replyBuilder.withKeyId(request.getKeyId()); |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 196 | replyBuilder.withAuthDataLength(valueOf(authConfig.lispAuthKeyId()).getHashLength()); |
| 197 | replyBuilder.withAuthKey(authConfig.lispAuthKey()); |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 198 | replyBuilder.withNonce(request.getNonce()); |
| 199 | replyBuilder.withEidPrefix(request.getPrefix()); |
| 200 | replyBuilder.withMaskLength(request.getMaskLength()); |
| 201 | replyBuilder.withTtl(request.getTtl()); |
| 202 | replyBuilder.withNatLcafAddress(natBuilder.build()); |
| 203 | replyBuilder.withIsInfoReply(true); |
| 204 | |
| 205 | LispInfoReply reply = replyBuilder.build(); |
| 206 | reply.configSender(request.getSender()); |
| 207 | |
| 208 | return reply; |
| 209 | } |
| 210 | |
| 211 | /** |
Jian Li | 51aaca1 | 2016-11-11 01:56:15 +0900 | [diff] [blame] | 212 | * Checks the integrity of the received map-register message by calculating |
| 213 | * authentication data from received map-register message. |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 214 | * |
Jian Li | 51aaca1 | 2016-11-11 01:56:15 +0900 | [diff] [blame] | 215 | * @param register map-register message |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 216 | * @return evaluation result |
| 217 | */ |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame] | 218 | private boolean checkMapRegisterAuthData(LispMapRegister register) { |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 219 | RegisterBuilder registerBuilder = new DefaultRegisterBuilder(); |
| 220 | registerBuilder.withKeyId(register.getKeyId()); |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 221 | registerBuilder.withAuthKey(authConfig.lispAuthKey()); |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 222 | registerBuilder.withNonce(register.getNonce()); |
| 223 | registerBuilder.withIsProxyMapReply(register.isProxyMapReply()); |
| 224 | registerBuilder.withIsWantMapNotify(register.isWantMapNotify()); |
| 225 | registerBuilder.withMapRecords(register.getMapRecords()); |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 226 | |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame] | 227 | LispMapRegister authRegister = registerBuilder.build(); |
Jian Li | 24f6cc0 | 2016-11-01 16:38:40 +0900 | [diff] [blame] | 228 | |
Jian Li | d1a109e | 2016-11-12 09:00:42 +0900 | [diff] [blame] | 229 | return Arrays.equals(authRegister.getAuthData(), register.getAuthData()); |
Jian Li | 451cea3 | 2016-10-04 15:27:50 +0900 | [diff] [blame] | 230 | } |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 231 | |
| 232 | /** |
| 233 | * Checks the integrity of the received info-request message by calculating |
| 234 | * authentication data from received info-request message. |
| 235 | * |
| 236 | * @param request info-request message |
| 237 | * @return evaluation result |
| 238 | */ |
| 239 | private boolean checkInfoRequestAuthData(LispInfoRequest request) { |
| 240 | InfoRequestBuilder requestBuilder = new DefaultInfoRequestBuilder(); |
| 241 | requestBuilder.withKeyId(request.getKeyId()); |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 242 | requestBuilder.withAuthKey(authConfig.lispAuthKey()); |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 243 | requestBuilder.withNonce(request.getNonce()); |
| 244 | requestBuilder.withTtl(request.getTtl()); |
| 245 | requestBuilder.withEidPrefix(request.getPrefix()); |
| 246 | requestBuilder.withIsInfoReply(request.isInfoReply()); |
| 247 | requestBuilder.withMaskLength(request.getMaskLength()); |
| 248 | |
yoonseon | 980cd7c | 2016-11-18 14:18:46 -0800 | [diff] [blame] | 249 | LispInfoRequest authRequest = requestBuilder.build(); |
Jian Li | 6ef1b3f | 2016-11-12 18:16:06 +0900 | [diff] [blame] | 250 | |
| 251 | return Arrays.equals(authRequest.getAuthData(), request.getAuthData()); |
| 252 | } |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 253 | |
| 254 | /** |
Jian Li | b86d8ad | 2017-05-03 02:53:44 +0900 | [diff] [blame^] | 255 | * Sends SMR (Solicit Map Request) to their subscribers. |
| 256 | * |
| 257 | * @param eidRecord the updated EID |
| 258 | */ |
| 259 | private void sendSmrMessage(LispEidRecord eidRecord) { |
| 260 | |
| 261 | RequestBuilder builder = new DefaultRequestBuilder(); |
| 262 | |
| 263 | LispAfiAddress msAddress = null; |
| 264 | try { |
| 265 | msAddress = new LispIpv4Address(IpAddress.valueOf(InetAddress.getLocalHost())); |
| 266 | } catch (UnknownHostException e) { |
| 267 | log.warn("Source EID is not found, {}", e.getMessage()); |
| 268 | } |
| 269 | |
| 270 | LispMapRequest msg = builder.withIsSmr(true) |
| 271 | .withIsSmrInvoked(true) |
| 272 | .withIsProbe(false) |
| 273 | .withIsPitr(false) |
| 274 | .withIsAuthoritative(false) |
| 275 | .withIsMapDataPresent(false) |
| 276 | .withSourceEid(msAddress) |
| 277 | .withEidRecords(ImmutableList.of(eidRecord)) |
| 278 | .build(); |
| 279 | |
| 280 | LispRouterFactory routerFactory = LispRouterFactory.getInstance(); |
| 281 | Collection<LispRouter> routers = routerFactory.getRouters(); |
| 282 | routers.forEach(router -> { |
| 283 | if (isInEidRecordRange(eidRecord, router.getEidRecords())) { |
| 284 | router.sendMessage(msg); |
| 285 | } |
| 286 | }); |
| 287 | } |
| 288 | |
| 289 | private boolean isInEidRecordRange(LispEidRecord originalRecord, List<LispEidRecord> records) { |
| 290 | |
| 291 | for (LispEidRecord record : records) { |
| 292 | return LispMapUtil.isInRange(record, originalRecord) || |
| 293 | LispMapUtil.isInRange(originalRecord, record); |
| 294 | } |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | /** |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 299 | * Prevents object instantiation from external. |
| 300 | */ |
Jian Li | 29986d8 | 2016-12-01 03:25:12 +0900 | [diff] [blame] | 301 | private static final class SingletonHelper { |
| 302 | private static final String ILLEGAL_ACCESS_MSG = "Should not instantiate this class."; |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 303 | private static final LispMapServer INSTANCE = new LispMapServer(); |
Jian Li | 29986d8 | 2016-12-01 03:25:12 +0900 | [diff] [blame] | 304 | |
| 305 | private SingletonHelper() { |
| 306 | throw new IllegalAccessError(ILLEGAL_ACCESS_MSG); |
| 307 | } |
Jian Li | 712ec05 | 2016-11-22 03:23:54 +0900 | [diff] [blame] | 308 | } |
Jian Li | 451cea3 | 2016-10-04 15:27:50 +0900 | [diff] [blame] | 309 | } |