From 685bffccd16d58fc5c1dd5c118ee74aa39effa68 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Thu, 18 May 2017 16:46:46 +0200 Subject: HONEYCOMB-355: move BGP to separate distribution Given current YangBindingProviderModule implementation (HONEYCOMB-358), needed to preserve footprint of minimal distro. The change also: - reverts logger&persistence config changes introduced by https://gerrit.fd.io/r/#/c/5972/ - improves logging for BGP component initialization Change-Id: Ie223833518be21628edb7ace36c7618e427585e0 Signed-off-by: Marek Gradzki --- .../infra/distro/bgp/BgpServerProvider.java | 102 --------------------- 1 file changed, 102 deletions(-) delete mode 100644 infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/bgp/BgpServerProvider.java (limited to 'infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/bgp/BgpServerProvider.java') diff --git a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/bgp/BgpServerProvider.java b/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/bgp/BgpServerProvider.java deleted file mode 100644 index 4ade07fc1..000000000 --- a/infra/minimal-distribution/src/main/java/io/fd/honeycomb/infra/distro/bgp/BgpServerProvider.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2017 Cisco and/or its affiliates. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.fd.honeycomb.infra.distro.bgp; - -import com.google.common.base.Preconditions; -import com.google.inject.Inject; -import io.fd.honeycomb.infra.distro.ProviderTrait; -import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration; -import io.netty.channel.Channel; -import io.netty.channel.ChannelConfig; -import io.netty.channel.ChannelFuture; -import io.netty.channel.epoll.Epoll; -import io.netty.channel.epoll.EpollChannelOption; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.UnknownHostException; -import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher; -import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry; -import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences; -import org.opendaylight.protocol.bgp.rib.impl.spi.PeerRegistryListener; -import org.opendaylight.protocol.concepts.KeyMapping; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; - -public final class BgpServerProvider extends ProviderTrait { - @Inject - private HoneycombConfiguration cfg; - @Inject - private BGPPeerRegistry peerRegistry; - @Inject - private BGPDispatcher dispatcher; - - @Override - protected BgpServer create() { - // code based on org.opendaylight.controller.config.yang.bgp.rib.impl.BGPPeerAcceptorModule from Boron-SR3 - final InetAddress bindingAddress; - try { - bindingAddress = InetAddress.getByName(cfg.bgpBindingAddress.get()); - } catch (UnknownHostException e) { - throw new IllegalArgumentException("Illegal BGP binding address", e); - } - final InetSocketAddress address = new InetSocketAddress(bindingAddress, cfg.bgpPort.get()); - final ChannelFuture localServer = dispatcher.createServer(peerRegistry, address); - localServer.addListener(future -> { - Preconditions.checkArgument(future.isSuccess(), "Unable to start bgp server on %s", address, future.cause()); - final Channel channel = localServer.channel(); - if (Epoll.isAvailable()) { - peerRegistry.registerPeerRegisterListener(new PeerRegistryListenerImpl(channel.config())); - } - }); - return new BgpServer(localServer); - } - - public static final class BgpServer { - private ChannelFuture localServer; - - BgpServer(final ChannelFuture localServer) { - this.localServer = localServer; - } - - public ChannelFuture getLocalServer() { - return localServer; - } - } - - private static final class PeerRegistryListenerImpl implements PeerRegistryListener { - private final ChannelConfig channelConfig; - private final KeyMapping keys; - - PeerRegistryListenerImpl(final ChannelConfig channelConfig) { - this.channelConfig = channelConfig; - this.keys = KeyMapping.getKeyMapping(); - } - @Override - public void onPeerAdded(final IpAddress ip, final BGPSessionPreferences prefs) { - if (prefs.getMd5Password().isPresent()) { - this.keys.put(IetfInetUtil.INSTANCE.inetAddressFor(ip), prefs.getMd5Password().get()); - this.channelConfig.setOption(EpollChannelOption.TCP_MD5SIG, this.keys); - } - } - @Override - public void onPeerRemoved(final IpAddress ip) { - if (this.keys.remove(IetfInetUtil.INSTANCE.inetAddressFor(ip)) != null) { - this.channelConfig.setOption(EpollChannelOption.TCP_MD5SIG, this.keys); - } - } - } -} -- cgit 1.2.3-korg