blob: 285b397a74cff5f46c76a8343fec0776e60664db [file] [log] [blame]
Jian Li451cea32016-10-04 15:27:50 +09001/*
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 */
16package org.onosproject.lisp.ctl;
17
Jian Li1118c122016-11-01 21:58:15 +090018import org.onosproject.lisp.msg.protocols.LispEncapsulatedControl;
19import org.onosproject.lisp.msg.protocols.LispMapRecord;
Jian Liafe2d3f2016-11-01 02:49:07 +090020import org.onosproject.lisp.msg.protocols.LispMapReply;
Jian Li1118c122016-11-01 21:58:15 +090021import org.onosproject.lisp.msg.protocols.LispMapRequest;
22import org.onosproject.lisp.msg.protocols.DefaultLispMapReply.DefaultReplyBuilder;
23
Jian Li451cea32016-10-04 15:27:50 +090024import org.onosproject.lisp.msg.protocols.LispMessage;
Jian Li1118c122016-11-01 21:58:15 +090025import org.onosproject.lisp.msg.types.LispIpAddress;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
29import java.net.InetSocketAddress;
30import java.util.List;
Jian Li451cea32016-10-04 15:27:50 +090031
32/**
33 * LISP map resolver class.
34 * Handles map-request message and acknowledges with map-reply message.
35 */
Jian Li6322a362016-10-31 00:57:19 +090036public class LispMapResolver {
37
Jian Li1118c122016-11-01 21:58:15 +090038 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
Jian Li2c8a2a42016-11-24 02:51:03 +090057 // TODO: for now we always generate map-reply message and send to ITR
Jian Li1118c122016-11-01 21:58:15 +090058 // 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 Li451cea32016-10-04 15:27:50 +090087 }
88}