2 * Copyright (c) 2016 Cisco Systems, Inc. and others. 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.protocol.bgp.rib.impl;
10 import com.google.common.base.Function;
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.JdkFutureAdapters;
14 import io.netty.channel.ChannelFuture;
16 import java.util.concurrent.Future;
17 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefresh;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.RouteRefreshBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.BgpPeerRpcService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.peer.rpc.rev160322.RouteRefreshRequestInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
23 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class BgpPeerRpc implements BgpPeerRpcService {
31 private static final Logger LOG = LoggerFactory.getLogger(BgpPeerRpc.class);
32 private static final String FAILURE_MSG = "Failed to send Route Refresh message";
34 private final BGPSession session;
35 private final Set<TablesKey> supportedFamilies;
37 BgpPeerRpc(final BGPSession session, final Set<TablesKey> supportedFamilies) {
38 this.session = Preconditions.checkNotNull(session);
39 this.supportedFamilies = Preconditions.checkNotNull(supportedFamilies);
43 public Future<RpcResult<Void>> routeRefreshRequest(final RouteRefreshRequestInput input) {
44 final ChannelFuture f = sendRRMessage(input);
46 return Futures.transform(JdkFutureAdapters.listenInPoolThread(f), new Function<Void, RpcResult<Void>>() {
48 public RpcResult<Void> apply(final Void input) {
50 return RpcResultBuilder.<Void>success().build();
52 return RpcResultBuilder.<Void>failed().withError(ErrorType.RPC, FAILURE_MSG).build();
57 return RpcResultBuilder.<Void>failed().withError(ErrorType.RPC, FAILURE_MSG + " due to unsupported address families.").buildFuture();
60 private ChannelFuture sendRRMessage(final RouteRefreshRequestInput input) {
61 if (!this.supportedFamilies.contains(new TablesKey(input.getAfi(), input.getSafi()))) {
62 LOG.info("Unsupported afi/safi: {}, {}.", input.getAfi(), input.getSafi());
65 final RouteRefresh msg = new RouteRefreshBuilder().setAfi(input.getAfi()).setSafi(input.getSafi()).build();
66 return ((BGPSessionImpl) this.session).getLimiter().writeAndFlush(msg);