1 package org.opendaylight.controller.config.yang.bgp.rib.impl;
3 import com.google.common.base.Objects;
5 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
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.protocol.bgp.rib.spi.BGPSessionListener;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
15 * Registry of BGP peers that allows only one connection per 2 peers
17 public class StrictBgpPeerRegistryModule extends org.opendaylight.controller.config.yang.bgp.rib.impl.AbstractStrictBgpPeerRegistryModule {
18 public StrictBgpPeerRegistryModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
19 super(identifier, dependencyResolver);
22 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) {
23 super(identifier, dependencyResolver, oldModule, oldInstance);
27 public void customValidation() {
28 // add custom validation form module attributes here.
32 public java.lang.AutoCloseable createInstance() {
33 return new GlobalBGPPeerRegistryWrapper(StrictBGPPeerRegistry.GLOBAL);
36 // TODO backwards compatibility, peer-registry has to be mandatory attribute for peers
38 * Wrapper for BGPPeerRegistry that prevents from executing close method
40 private static final class GlobalBGPPeerRegistryWrapper implements BGPPeerRegistry, AutoCloseable {
41 private final StrictBGPPeerRegistry global;
43 public GlobalBGPPeerRegistryWrapper(final StrictBGPPeerRegistry global) {
48 public BGPSessionPreferences getPeerPreferences(final IpAddress ip) {
49 return global.getPeerPreferences(ip);
53 public BGPSessionListener getPeer(final IpAddress ip, final Ipv4Address sourceId, final Ipv4Address remoteId) throws BGPDocumentedException {
54 return global.getPeer(ip, sourceId, remoteId);
58 public boolean isPeerConfigured(final IpAddress ip) {
59 return global.isPeerConfigured(ip);
63 public void removePeer(final IpAddress ip) {
64 global.removePeer(ip);
68 public void addPeer(final IpAddress ip, final ReusableBGPPeer peer, final BGPSessionPreferences preferences) {
69 global.addPeer(ip, peer, preferences);
74 // DO nothing, do not close the global instance
78 public String toString() {
79 return Objects.toStringHelper(this)