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 | */ |
| 16 | package org.onosproject.lisp.ctl; |
| 17 | |
Jian Li | 1118c12 | 2016-11-01 21:58:15 +0900 | [diff] [blame^] | 18 | import org.onosproject.lisp.msg.protocols.LispEncapsulatedControl; |
| 19 | import org.onosproject.lisp.msg.protocols.LispMapRecord; |
Jian Li | afe2d3f | 2016-11-01 02:49:07 +0900 | [diff] [blame] | 20 | import org.onosproject.lisp.msg.protocols.LispMapReply; |
Jian Li | 1118c12 | 2016-11-01 21:58:15 +0900 | [diff] [blame^] | 21 | import org.onosproject.lisp.msg.protocols.LispMapRequest; |
| 22 | import org.onosproject.lisp.msg.protocols.DefaultLispMapReply.DefaultReplyBuilder; |
| 23 | |
Jian Li | 451cea3 | 2016-10-04 15:27:50 +0900 | [diff] [blame] | 24 | import org.onosproject.lisp.msg.protocols.LispMessage; |
Jian Li | 1118c12 | 2016-11-01 21:58:15 +0900 | [diff] [blame^] | 25 | import org.onosproject.lisp.msg.types.LispIpAddress; |
| 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | |
| 29 | import java.net.InetSocketAddress; |
| 30 | import java.util.List; |
Jian Li | 451cea3 | 2016-10-04 15:27:50 +0900 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * LISP map resolver class. |
| 34 | * Handles map-request message and acknowledges with map-reply message. |
| 35 | */ |
Jian Li | 6322a36 | 2016-10-31 00:57:19 +0900 | [diff] [blame] | 36 | public class LispMapResolver { |
| 37 | |
Jian Li | 1118c12 | 2016-11-01 21:58:15 +0900 | [diff] [blame^] | 38 | private static final Logger log = LoggerFactory.getLogger(LispMapResolver.class); |
| 39 | |
| 40 | private LispEidRlocMap eidRlocMap; |
| 41 | |
| 42 | LispMapResolver() { |
| 43 | eidRlocMap = LispEidRlocMap.getInstance(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Handles encapsulated control message and replies with map-reply message. |
| 48 | * |
| 49 | * @param message encapsulated control message |
| 50 | * @return map-reply message |
| 51 | */ |
| 52 | public LispMessage processMapRequest(LispMessage message) { |
| 53 | |
| 54 | LispEncapsulatedControl ecm = (LispEncapsulatedControl) message; |
| 55 | LispMapRequest request = (LispMapRequest) ecm.getControlMessage(); |
| 56 | |
| 57 | // TODO: for now we always generate map-notify message and send to ITR |
| 58 | // no matter proxy bit is set or not |
| 59 | |
| 60 | // build map-reply message |
| 61 | LispMapReply.ReplyBuilder replyBuilder = new DefaultReplyBuilder(); |
| 62 | replyBuilder.withNonce(request.getNonce()); |
| 63 | replyBuilder.withIsEtr(false); |
| 64 | replyBuilder.withIsSecurity(false); |
| 65 | replyBuilder.withIsProbe(request.isProbe()); |
| 66 | |
| 67 | List<LispMapRecord> mapRecords = eidRlocMap.getMapRecordByEidRecords(request.getEids()); |
| 68 | |
| 69 | if (mapRecords.size() == 0) { |
| 70 | log.warn("Map information is not found."); |
| 71 | } else { |
| 72 | replyBuilder.withMapRecords(mapRecords); |
| 73 | } |
| 74 | |
| 75 | LispMapReply reply = replyBuilder.build(); |
| 76 | |
| 77 | if (request.getItrRlocs() != null && request.getItrRlocs().size() > 0) { |
| 78 | LispIpAddress itr = (LispIpAddress) request.getItrRlocs().get(0); |
| 79 | InetSocketAddress address = new InetSocketAddress(itr.getAddress().toInetAddress(), |
| 80 | ecm.innerUdp().getSourcePort()); |
| 81 | reply.configSender(address); |
| 82 | } else { |
| 83 | log.warn("No ITR RLOC is found, cannot respond back to ITR."); |
| 84 | } |
| 85 | |
| 86 | return reply; |
Jian Li | 451cea3 | 2016-10-04 15:27:50 +0900 | [diff] [blame] | 87 | } |
| 88 | } |