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.RpcError;
44 import org.opendaylight.yangtools.yang.common.RpcResult;
45 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * This class holds all RPCs methods for LispSouthbound Plugin.
53 * @author Florin Coras (fcoras@cisco.com)
54 * @author Lorand Jakab (lojakab@cisco.com)
56 public class LispSouthboundRPC implements OdlLispSbService {
58 protected static final Logger LOG = LoggerFactory.getLogger(LispSouthboundRPC.class);
60 private final LispSouthboundPlugin lispSbPlugin;
62 public LispSouthboundRPC(LispSouthboundPlugin lispSbPlugin) {
63 this.lispSbPlugin = lispSbPlugin;
68 public ListenableFuture<RpcResult<SendMapNotifyOutput>> sendMapNotify(SendMapNotifyInput mapNotifyInput) {
69 LOG.trace("sendMapNotify called!!");
70 if (mapNotifyInput != null) {
71 ByteBuffer outBuffer = MapNotifySerializer.getInstance().serialize(mapNotifyInput.getMapNotify());
72 lispSbPlugin.handleSerializedLispBuffer(mapNotifyInput.getTransportAddress(), outBuffer,
73 MessageType.MapNotify);
75 LOG.warn("MapNotify was null");
76 return Futures.immediateFuture(RpcResultBuilder.<SendMapNotifyOutput>failed().build());
78 return Futures.immediateFuture(RpcResultBuilder.<SendMapNotifyOutput>success(
79 new SendMapNotifyOutputBuilder().build()).build());
83 public ListenableFuture<RpcResult<SendMapReplyOutput>> sendMapReply(SendMapReplyInput mapReplyInput) {
84 LOG.trace("sendMapReply called!!");
85 if (mapReplyInput != null) {
86 ByteBuffer outBuffer = MapReplySerializer.getInstance().serialize(mapReplyInput.getMapReply());
87 lispSbPlugin.handleSerializedLispBuffer(mapReplyInput.getTransportAddress(), outBuffer,
88 MessageType.MapReply);
90 LOG.warn("MapReply was null");
91 return Futures.immediateFuture(RpcResultBuilder.<SendMapReplyOutput>failed().build());
93 return Futures.immediateFuture(RpcResultBuilder.<SendMapReplyOutput>success(
94 new SendMapReplyOutputBuilder().build()).build());
98 public ListenableFuture<RpcResult<SendMapRequestOutput>> sendMapRequest(SendMapRequestInput mapRequestInput) {
99 LOG.trace("sendMapRequest called!!");
100 if (mapRequestInput != null) {
101 ByteBuffer outBuffer = MapRequestSerializer.getInstance().serialize(mapRequestInput.getMapRequest());
102 lispSbPlugin.handleSerializedLispBuffer(mapRequestInput.getTransportAddress(), outBuffer,
103 MessageType.MapRequest);
105 LOG.debug("MapRequest was null");
106 return Futures.immediateFuture(RpcResultBuilder.<SendMapRequestOutput>failed().build());
108 return Futures.immediateFuture(RpcResultBuilder.<SendMapRequestOutput>success(
109 new SendMapRequestOutputBuilder().build()).build());
113 public ListenableFuture<RpcResult<SendMapRegisterOutput>> sendMapRegister(SendMapRegisterInput mapRegisterInput) {
114 LOG.trace("sendMapRegister called!!");
115 if (mapRegisterInput != null) {
116 ByteBuffer outBuffer = MapRegisterSerializer.getInstance().serialize(mapRegisterInput.getMapRegister());
117 lispSbPlugin.handleSerializedLispBuffer(mapRegisterInput.getTransportAddress(), outBuffer,
118 MessageType.MapRegister);
120 LOG.debug("MapRegister was null");
121 return Futures.immediateFuture(RpcResultBuilder.<SendMapRegisterOutput>failed().build());
123 return Futures.immediateFuture(RpcResultBuilder.<SendMapRegisterOutput>success(
124 new SendMapRegisterOutputBuilder().build()).build());
128 public ListenableFuture<RpcResult<GetStatsOutput>> getStats(GetStatsInput input) {
129 LOG.trace("getStats called!!");
131 RpcResultBuilder<GetStatsOutput> rpcResultBuilder;
133 ConcurrentLispSouthboundStats stats = lispSbPlugin.getStats();
136 rpcResultBuilder = RpcResultBuilder.<GetStatsOutput>failed()
137 .withError(RpcError.ErrorType.APPLICATION, "data-missing", "No stats found");
139 rpcResultBuilder = RpcResultBuilder.success(createGetStatsOutput(stats));
141 return Futures.immediateFuture(rpcResultBuilder.build());
145 public ListenableFuture<RpcResult<ResetStatsOutput>> resetStats(ResetStatsInput input) {
146 LOG.trace("resetStats called!!");
148 ConcurrentLispSouthboundStats stats = lispSbPlugin.getStats();
151 return Futures.immediateFuture(RpcResultBuilder.<ResetStatsOutput>failed()
152 .withError(RpcError.ErrorType.APPLICATION, "data-missing", "No stats found")
156 return Futures.immediateFuture(RpcResultBuilder.<ResetStatsOutput>success(
157 new ResetStatsOutputBuilder().build()).build());
161 private static GetStatsOutput createGetStatsOutput(ConcurrentLispSouthboundStats stats) {
162 long[] rxStats = stats.getRx();
163 long[] txStats = stats.getTx();
165 ControlMessageStatsBuilder cmsb = new ControlMessageStatsBuilder();
166 cmsb.setRxUnknown(stats.getRxUnknown());
167 cmsb.setTxErrors(stats.getTxErrors());
169 List<ControlMessage> messages = new ArrayList<ControlMessage>();
170 for (int i = 0; i <= ConcurrentLispSouthboundStats.MAX_LISP_TYPES; i++) {
171 if (MessageType.forValue(i) == null) {
174 ControlMessageBuilder cmb = new ControlMessageBuilder();
175 cmb.setMsgType(MessageType.forValue(i));
176 cmb.setRxCount(rxStats[i]);
177 cmb.setTxCount(txStats[i]);
178 messages.add(cmb.build());
181 cmsb.setControlMessage(messages);
183 MapRegisterCacheStatsBuilder mrcsb = new MapRegisterCacheStatsBuilder();
184 mrcsb.setHits(stats.getCacheHits());
185 mrcsb.setMisses(stats.getCacheMisses());
187 return new GetStatsOutputBuilder().setControlMessageStats(cmsb.build())
188 .setMapRegisterCacheStats(mrcsb.build()).build();