1 package org.opendaylight.controller.config.yang.bgp.rib.impl;
3 import com.google.common.base.Objects;
4 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
5 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
6 import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
7 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
8 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
9 import org.opendaylight.protocol.bgp.rib.impl.spi.ReusableBGPPeer;
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
14 * Registry of BGP peers that allows only one connection per 2 peers
16 public class StrictBgpPeerRegistryModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractStrictBgpPeerRegistryModule {
17 public StrictBgpPeerRegistryModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
18 super(identifier, dependencyResolver);
21 public StrictBgpPeerRegistryModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final org.opendaylight.controller.config.yang.bgp.rib.impl.StrictBgpPeerRegistryModule oldModule, final java.lang.AutoCloseable oldInstance) {
22 super(identifier, dependencyResolver, oldModule, oldInstance);
26 public void customValidation() {
27 // add custom validation form module attributes here.
31 public java.lang.AutoCloseable createInstance() {
32 return new GlobalBGPPeerRegistryWrapper(StrictBGPPeerRegistry.GLOBAL);
35 // TODO backwards compatibility, peer-registry has to be mandatory attribute for peers
37 * Wrapper for BGPPeerRegistry that prevents from executing close method
39 private static final class GlobalBGPPeerRegistryWrapper implements BGPPeerRegistry, AutoCloseable {
40 private final StrictBGPPeerRegistry global;
42 public GlobalBGPPeerRegistryWrapper(final StrictBGPPeerRegistry global) {
47 public BGPSessionPreferences getPeerPreferences(final IpAddress ip) {
48 return global.getPeerPreferences(ip);
52 public BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId) throws BGPDocumentedException {
53 return global.getPeer(ip, sourceId, remoteId);
57 public boolean isPeerConfigured(final IpAddress ip) {
58 return global.isPeerConfigured(ip);
62 public void removePeer(final IpAddress ip) {
63 global.removePeer(ip);
67 public void addPeer(final IpAddress ip, final ReusableBGPPeer peer, final BGPSessionPreferences preferences) {
68 global.addPeer(ip, peer, preferences);
72 public void close() throws Exception {
73 // DO nothing, do not close the global instance
77 public String toString() {
78 return Objects.toStringHelper(this)