import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Preconditions;
-import java.util.Comparator;
+import com.google.common.net.InetAddresses;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.concurrent.GuardedBy;
-import org.opendaylight.protocol.bgp.parser.BGPSession;
-import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
+import org.opendaylight.protocol.bgp.rib.impl.spi.AdjRIBsOutRegistration;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.ReusableBGPPeer;
+import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
+import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
import org.opendaylight.protocol.bgp.rib.spi.Peer;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.PathAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Update;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
private final RIB rib;
private final String name;
- private Comparator<PathAttributes> comparator;
+ @GuardedBy("this")
private BGPSession session;
+ @GuardedBy("this")
+ private byte[] rawIdentifier;
+ @GuardedBy("this")
+ private AdjRIBsOutRegistration reg;
public BGPPeer(final String name, final RIB rib) {
this.rib = Preconditions.checkNotNull(rib);
LOG.info("Session with peer {} went up with tables: {}", this.name, session.getAdvertisedTableTypes());
this.session = session;
- this.comparator = new BGPObjectComparator(this.rib.getLocalAs(), rib.getBgpIdentifier(), session.getBgpId());
+ 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);
}
+
+ // Not particularly nice, but what can
+ if (session instanceof BGPSessionImpl) {
+ reg = rib.registerRIBsOut(this, new SessionRIBsOut((BGPSessionImpl) session));
+ }
}
private synchronized void cleanup() {
this.rib.clearTable(this, key);
}
+ if (this.reg != null) {
+ this.reg.close();
+ this.reg = null;
+ }
+
this.tables.clear();
- this.session = null;
- this.comparator = null;
}
@Override
public void onSessionDown(final BGPSession session, final Exception e) {
LOG.info("Session with peer {} went down", this.name, e);
- cleanup();
+ releaseConnection();
}
@Override
public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
LOG.info("Session with peer {} terminated: {}", this.name, cause);
- cleanup();
+ releaseConnection();
}
@Override
return this.name;
}
- @Override
- public Comparator<PathAttributes> getComparator() {
- return this.comparator;
- }
-
protected RIB getRib() {
- return rib;
+ return this.rib;
}
@Override
cleanup();
}
+ @GuardedBy("this")
private void dropConnection() {
if (this.session != null) {
this.session.close();
this.session = null;
}
}
+
+ @Override
+ public synchronized byte[] getRawIdentifier() {
+ return rawIdentifier;
+ }
}