--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.config;
+
+import com.google.common.base.Strings;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
+import org.opendaylight.protocol.bgp.openconfig.spi.BGPOpenConfigMappingService;
+import org.opendaylight.protocol.bgp.rib.impl.ApplicationPeer;
+import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.Config;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.ApplicationRibId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.Tables;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+public class AppPeer implements PeerBean {
+
+ private static final QName APP_ID_QNAME = QName.create(ApplicationRib.QNAME, "id").intern();
+
+ private ApplicationPeer applicationPeer;
+ private ListenerRegistration<ApplicationPeer> registration;
+
+ @Override
+ public void start(final RIB rib, final Neighbor neighbor, final BGPOpenConfigMappingService mappingService) {
+ final ApplicationRibId appRibId = createAppRibId(neighbor);
+ this.applicationPeer = new ApplicationPeer(appRibId, neighbor.getNeighborAddress().getIpv4Address(), rib);
+ final YangInstanceIdentifier yangIId = YangInstanceIdentifier.builder().node(ApplicationRib.QNAME)
+ .nodeWithKey(ApplicationRib.QNAME, APP_ID_QNAME, appRibId.getValue()).node(Tables.QNAME).node(Tables.QNAME).build();
+ this.registration = rib.getService().registerDataTreeChangeListener(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yangIId),
+ this.applicationPeer);
+ }
+
+ @Override
+ public void close() {
+ if (this.applicationPeer != null) {
+ this.registration.close();
+ this.applicationPeer.close();
+ }
+ }
+
+ private static ApplicationRibId createAppRibId(final Neighbor neighbor) {
+ final Config config = neighbor.getConfig();
+ if (config != null && !Strings.isNullOrEmpty(config.getDescription())) {
+ return new ApplicationRibId(config.getDescription());
+ }
+ return new ApplicationRibId(neighbor.getNeighborAddress().getIpv4Address().getValue());
+ }
+
+}
@GuardedBy("this")
private final Map<InstanceIdentifier<Bgp>, RibImpl> ribs = new HashMap<>();
@GuardedBy("this")
- private final Map<InstanceIdentifier<Neighbor>, BgpPeer> peers = new HashMap<>();
+ private final Map<InstanceIdentifier<Neighbor>, PeerBean> peers = new HashMap<>();
private final DataBroker dataBroker;
@GuardedBy("this")
private boolean closed;
@Override
public synchronized void close() throws Exception {
this.registration.close();
- this.peers.values().forEach(BgpPeer::close);
+ this.peers.values().forEach(PeerBean::close);
this.peers.clear();
this.ribs.values().forEach(RibImpl::close);
this.ribs.clear();
private void onNeighborModified(final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor) {
LOG.debug("Modifing Peer instance with configuration: {}", neighbor);
//restart peer instance with a new configuration
- final BgpPeer bgpPeer = this.peers.get(getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey()));
+ final PeerBean bgpPeer = this.peers.get(getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey()));
if (bgpPeer != null) {
bgpPeer.close();
final InstanceIdentifier<Neighbor> neighborInstanceIdentifier = getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey());
private void onNeighborCreated(final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor) {
//create, start and register peer instance
LOG.debug("Creating Peer instance with configuration: {}", neighbor);
- final BgpPeer bgpPeer = (BgpPeer) this.container.getComponentInstance(InstanceType.PEER.getBeanName());
+ final PeerBean bgpPeer;
+ if (this.mappingService.isApplicationPeer(neighbor)) {
+ bgpPeer = (PeerBean) this.container.getComponentInstance(InstanceType.APP_PEER.getBeanName());
+ } else {
+ bgpPeer = (PeerBean) this.container.getComponentInstance(InstanceType.PEER.getBeanName());
+ }
final InstanceIdentifier<Neighbor> neighborInstanceIdentifier = getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey());
initiatePeerInstance(rootIdentifier, neighborInstanceIdentifier, neighbor, bgpPeer);
this.peers.put(neighborInstanceIdentifier, bgpPeer);
private void onNeighborRemoved(final InstanceIdentifier<Bgp> rootIdentifier, final Neighbor neighbor) {
//destroy peer instance
LOG.debug("Removing Peer instance: {}", rootIdentifier);
- final BgpPeer bgpPeer = this.peers.remove(getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey()));
+ final PeerBean bgpPeer = this.peers.remove(getNeighborInstanceIdentifier(rootIdentifier, neighbor.getKey()));
if (bgpPeer != null) {
bgpPeer.close();
LOG.debug("Peer instance removed {}", bgpPeer);
}
private void initiatePeerInstance(final InstanceIdentifier<Bgp> rootIdentifier, final InstanceIdentifier<Neighbor> neighborIdentifier, final Neighbor neighbor,
- final BgpPeer bgpPeer) {
+ final PeerBean bgpPeer) {
final String peerInstanceName = getNeighborInstanceName(neighborIdentifier);
final RibImpl rib = this.ribs.get(rootIdentifier);
if (rib != null) {
bgpPeer.start(rib, neighbor, this.mappingService);
- registerPeerInstance(bgpPeer, peerInstanceName);
+ if (bgpPeer instanceof BgpPeer) {
+ registerPeerInstance((BgpPeer) bgpPeer, peerInstanceName);
+ }
}
}
import org.slf4j.LoggerFactory;
-public class BgpPeer implements AutoCloseable, BGPPeerRuntimeMXBean {
+public class BgpPeer implements PeerBean, BGPPeerRuntimeMXBean {
//FIXME make configurable
private static final PortNumber PORT = new PortNumber(179);
this.peerRegistry = peerRegistry;
}
+ @Override
public void start(final RIB rib, final Neighbor neighbor, final BGPOpenConfigMappingService mappingService) {
Preconditions.checkState(this.bgpPeer == null, "Previous peer instance {} was not closed.");
this.neighborAddress = neighbor.getNeighborAddress();
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.protocol.bgp.rib.impl.config;
+
+import org.opendaylight.protocol.bgp.openconfig.spi.BGPOpenConfigMappingService;
+import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
+
+/**
+ * Common interface for BgpPeer and AppPeer beans
+ *
+ */
+public interface PeerBean extends AutoCloseable {
+
+ void start(RIB rib, Neighbor neighbor, BGPOpenConfigMappingService mappingService);
+
+ @Override
+ void close();
+
+}
RIB("ribImpl", Lists.newArrayList(RIB.class, RibReference.class)),
- PEER("bgpPeer", Collections.singletonList(BGPPeerRuntimeMXBean.class));
+ PEER("bgpPeer", Collections.singletonList(BGPPeerRuntimeMXBean.class)),
+
+ APP_PEER("appPeer", Collections.emptyList());
private final String beanName;
private final String[] services;
<argument ref="BGPPeerRegistry"/>
</bean>
+ <bean id="appPeer" class="org.opendaylight.protocol.bgp.rib.impl.config.AppPeer" scope="prototype"/>
+
</blueprint>
\ No newline at end of file