* 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;
import com.google.common.base.MoreObjects;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
-import org.opendaylight.protocol.bgp.rib.impl.spi.AdjRIBsOutRegistration;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionStatistics;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.ReusableBGPPeer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* Class representing a peer. We have a single instance for each peer, which provides translation from BGP events into
* RIB actions.
@GuardedBy("this")
private final Set<TablesKey> tables = new HashSet<>();
- private final RIB rib;
- private final String name;
-
@GuardedBy("this")
private BGPSession session;
@GuardedBy("this")
private byte[] rawIdentifier;
@GuardedBy("this")
- private AdjRIBsOutRegistration reg;
+ private DOMTransactionChain chain;
+ @GuardedBy("this")
+ private AdjRibInWriter ribWriter;
+ private final RIB rib;
+ private final String name;
private BGPPeerRuntimeRegistrator registrator;
private BGPPeerRuntimeRegistration runtimeReg;
private long sessionEstablishedCounter = 0L;
- @GuardedBy("this")
- private AdjRibInWriter ribWriter;
-
public BGPPeer(final String name, final RIB rib) {
this.rib = Preconditions.checkNotNull(rib);
this.name = name;
+ this.chain = rib.createPeerChain(this);
- final DOMTransactionChain chain = rib.createPeerChain(this);
// FIXME: make this configurable
final PeerRole role = PeerRole.Ibgp;
-
- this.ribWriter = AdjRibInWriter.create(rib.getYangRibId(), role, chain);
+ this.ribWriter = AdjRibInWriter.create(rib.getYangRibId(), role, this.chain);
}
@Override
return;
}
final Update message = (Update) msg;
- //this.rib.updateTables(this, message);
+
// update AdjRibs
final Attributes attrs = message.getAttributes();
MpReachNlri mpReach = null;
@Override
public synchronized void onSessionUp(final BGPSession session) {
LOG.info("Session with peer {} went up with tables: {}", this.name, session.getAdvertisedTableTypes());
-
this.session = session;
this.rawIdentifier = InetAddresses.forString(session.getBgpId().getValue()).getAddress();
for (final BgpTableType t : session.getAdvertisedTableTypes()) {
final TablesKey key = new TablesKey(t.getAfi(), t.getSafi());
-
this.tables.add(key);
- this.rib.initTable(this, key);
- }
- this.ribWriter = this.ribWriter.transform(RouterIds.createPeerId(session.getBgpId()), this.rib.getRibSupportContext(), this.tables, false);
-
- // Not particularly nice, but what can
- if (session instanceof BGPSessionImpl) {
- this.reg = this.rib.registerRIBsOut(this, new SessionRIBsOut((BGPSessionImpl) session));
+ // not particularly nice
+ if (session instanceof BGPSessionImpl) {
+ AdjRibOutListener.create(key, this.rib.getYangRibId(), ((RIBImpl)this.rib).getService(), this.rib.getRibSupportContext(), ((BGPSessionImpl) session).getLimiter());
+ }
}
+ this.ribWriter = this.ribWriter.transform(RouterIds.createPeerId(session.getBgpId()), this.rib.getRibSupportContext(), this.tables, false);
this.sessionEstablishedCounter++;
if (this.registrator != null) {
this.runtimeReg = this.registrator.register(this);
private synchronized void cleanup() {
// FIXME: BUG-196: support graceful restart
this.ribWriter.cleanTables(this.tables);
- for (final TablesKey key : this.tables) {
- this.rib.clearTable(this, key);
- }
-
- if (this.reg != null) {
- this.reg.close();
- this.reg = null;
- }
-
+ this.chain.close();
this.tables.clear();
}
return this.name;
}
- protected RIB getRib() {
- return this.rib;
- }
-
@Override
public void releaseConnection() {
dropConnection();
@Override
public void onTransactionChainFailed(final TransactionChain<?, ?> chain, final AsyncTransaction<?, ?> transaction, final Throwable cause) {
- // TODO Auto-generated method stub
-
+ LOG.error("Transaction chain failed.", cause);
+ this.dropConnection();
+ this.chain = this.rib.createPeerChain(this);
}
@Override
public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
- // TODO Auto-generated method stub
+ LOG.debug("Transaction chain {} successfull.", chain);
}
}