2 * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.lispflowmapping.southbound;
10 import com.google.common.util.concurrent.Futures;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.nio.ByteBuffer;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.opendaylight.lispflowmapping.lisp.serializer.MapNotifySerializer;
16 import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer;
17 import org.opendaylight.lispflowmapping.lisp.serializer.MapReplySerializer;
18 import org.opendaylight.lispflowmapping.lisp.serializer.MapRequestSerializer;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MessageType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.GetStatsInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.GetStatsOutput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.GetStatsOutputBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.OdlLispSbService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.ResetStatsInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.ResetStatsOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.ResetStatsOutputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyInput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapNotifyOutputBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRegisterInput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRegisterOutput;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRegisterOutputBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapReplyInput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapReplyOutput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapReplyOutputBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRequestInput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRequestOutput;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.SendMapRequestOutputBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.ctrl.msg.stats.ControlMessage;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.ctrl.msg.stats.ControlMessageBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.get.stats.output.ControlMessageStatsBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.sb.rev150904.get.stats.output.MapRegisterCacheStatsBuilder;
43 import org.opendaylight.yangtools.yang.common.ErrorTag;
44 import org.opendaylight.yangtools.yang.common.ErrorType;
45 import org.opendaylight.yangtools.yang.common.RpcResult;
46 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * This class holds all RPCs methods for LispSouthbound Plugin.
54 * @author Florin Coras (fcoras@cisco.com)
55 * @author Lorand Jakab (lojakab@cisco.com)
57 public class LispSouthboundRPC implements OdlLispSbService {
59 protected static final Logger LOG = LoggerFactory.getLogger(LispSouthboundRPC.class);
61 private final LispSouthboundPlugin lispSbPlugin;
63 public LispSouthboundRPC(LispSouthboundPlugin lispSbPlugin) {
64 this.lispSbPlugin = lispSbPlugin;
69 public ListenableFuture<RpcResult<SendMapNotifyOutput>> sendMapNotify(SendMapNotifyInput mapNotifyInput) {
70 LOG.trace("sendMapNotify called!!");
71 if (mapNotifyInput != null) {
72 ByteBuffer outBuffer = MapNotifySerializer.getInstance().serialize(mapNotifyInput.getMapNotify());
73 lispSbPlugin.handleSerializedLispBuffer(mapNotifyInput.getTransportAddress(), outBuffer,
74 MessageType.MapNotify);
76 LOG.warn("MapNotify was null");
77 return Futures.immediateFuture(RpcResultBuilder.<SendMapNotifyOutput>failed().build());
79 return Futures.immediateFuture(RpcResultBuilder.<SendMapNotifyOutput>success(
80 new SendMapNotifyOutputBuilder().build()).build());
84 public ListenableFuture<RpcResult<SendMapReplyOutput>> sendMapReply(SendMapReplyInput mapReplyInput) {
85 LOG.trace("sendMapReply called!!");
86 if (mapReplyInput != null) {
87 ByteBuffer outBuffer = MapReplySerializer.getInstance().serialize(mapReplyInput.getMapReply());
88 lispSbPlugin.handleSerializedLispBuffer(mapReplyInput.getTransportAddress(), outBuffer,
89 MessageType.MapReply);
91 LOG.warn("MapReply was null");
92 return Futures.immediateFuture(RpcResultBuilder.<SendMapReplyOutput>failed().build());
94 return Futures.immediateFuture(RpcResultBuilder.<SendMapReplyOutput>success(
95 new SendMapReplyOutputBuilder().build()).build());
99 public ListenableFuture<RpcResult<SendMapRequestOutput>> sendMapRequest(SendMapRequestInput mapRequestInput) {
100 LOG.trace("sendMapRequest called!!");
101 if (mapRequestInput != null) {
102 ByteBuffer outBuffer = MapRequestSerializer.getInstance().serialize(mapRequestInput.getMapRequest());
103 lispSbPlugin.handleSerializedLispBuffer(mapRequestInput.getTransportAddress(), outBuffer,
104 MessageType.MapRequest);
106 LOG.debug("MapRequest was null");
107 return Futures.immediateFuture(RpcResultBuilder.<SendMapRequestOutput>failed().build());
109 return Futures.immediateFuture(RpcResultBuilder.<SendMapRequestOutput>success(
110 new SendMapRequestOutputBuilder().build()).build());
114 public ListenableFuture<RpcResult<SendMapRegisterOutput>> sendMapRegister(SendMapRegisterInput mapRegisterInput) {
115 LOG.trace("sendMapRegister called!!");
116 if (mapRegisterInput != null) {
117 ByteBuffer outBuffer = MapRegisterSerializer.getInstance().serialize(mapRegisterInput.getMapRegister());
118 lispSbPlugin.handleSerializedLispBuffer(mapRegisterInput.getTransportAddress(), outBuffer,
119 MessageType.MapRegister);
121 LOG.debug("MapRegister was null");
122 return Futures.immediateFuture(RpcResultBuilder.<SendMapRegisterOutput>failed().build());
124 return Futures.immediateFuture(RpcResultBuilder.<SendMapRegisterOutput>success(
125 new SendMapRegisterOutputBuilder().build()).build());
129 public ListenableFuture<RpcResult<GetStatsOutput>> getStats(GetStatsInput input) {
130 LOG.trace("getStats called!!");
132 RpcResultBuilder<GetStatsOutput> rpcResultBuilder;
134 ConcurrentLispSouthboundStats stats = lispSbPlugin.getStats();
137 rpcResultBuilder = RpcResultBuilder.<GetStatsOutput>failed()
138 .withError(ErrorType.APPLICATION, ErrorTag.DATA_MISSING, "No stats found");
140 rpcResultBuilder = RpcResultBuilder.success(createGetStatsOutput(stats));
142 return Futures.immediateFuture(rpcResultBuilder.build());
146 public ListenableFuture<RpcResult<ResetStatsOutput>> resetStats(ResetStatsInput input) {
147 LOG.trace("resetStats called!!");
149 ConcurrentLispSouthboundStats stats = lispSbPlugin.getStats();
152 return Futures.immediateFuture(RpcResultBuilder.<ResetStatsOutput>failed()
153 .withError(ErrorType.APPLICATION, ErrorTag.DATA_MISSING, "No stats found")
157 return Futures.immediateFuture(RpcResultBuilder.<ResetStatsOutput>success(
158 new ResetStatsOutputBuilder().build()).build());
162 private static GetStatsOutput createGetStatsOutput(ConcurrentLispSouthboundStats stats) {
163 long[] rxStats = stats.getRx();
164 long[] txStats = stats.getTx();
166 ControlMessageStatsBuilder cmsb = new ControlMessageStatsBuilder();
167 cmsb.setRxUnknown(stats.getRxUnknown());
168 cmsb.setTxErrors(stats.getTxErrors());
170 List<ControlMessage> messages = new ArrayList<ControlMessage>();
171 for (int i = 0; i <= ConcurrentLispSouthboundStats.MAX_LISP_TYPES; i++) {
172 if (MessageType.forValue(i) == null) {
175 ControlMessageBuilder cmb = new ControlMessageBuilder();
176 cmb.setMsgType(MessageType.forValue(i));
177 cmb.setRxCount(rxStats[i]);
178 cmb.setTxCount(txStats[i]);
179 messages.add(cmb.build());
182 cmsb.setControlMessage(messages);
184 MapRegisterCacheStatsBuilder mrcsb = new MapRegisterCacheStatsBuilder();
185 mrcsb.setHits(stats.getCacheHits());
186 mrcsb.setMisses(stats.getCacheMisses());
188 return new GetStatsOutputBuilder().setControlMessageStats(cmsb.build())
189 .setMapRegisterCacheStats(mrcsb.build()).build();