import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
import org.opendaylight.protocol.bgp.parser.spi.MultiPathSupport;
import org.opendaylight.protocol.bgp.parser.spi.pojo.MultiPathSupportImpl;
+import org.opendaylight.protocol.bgp.rib.impl.spi.BGPMessagesListener;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
+import org.opendaylight.protocol.bgp.rib.impl.state.BGPSessionStateImpl;
+import org.opendaylight.protocol.bgp.rib.impl.state.BGPSessionStateProvider;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.BGPSessionStats;
import org.opendaylight.protocol.bgp.rib.impl.stats.peer.BGPSessionStatsImpl;
import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
import org.opendaylight.protocol.bgp.rib.spi.State;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPSessionState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTimersState;
+import org.opendaylight.protocol.bgp.rib.spi.state.BGPTransportState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
import org.slf4j.LoggerFactory;
@VisibleForTesting
-public class BGPSessionImpl extends SimpleChannelInboundHandler<Notification> implements BGPSession, BGPSessionStats, AutoCloseable {
+public class BGPSessionImpl extends SimpleChannelInboundHandler<Notification> implements BGPSession, BGPSessionStats,
+ BGPSessionStateProvider, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(BGPSessionImpl.class);
private final Ipv4Address bgpId;
private final BGPPeerRegistry peerRegistry;
private final ChannelOutputLimiter limiter;
+ private final BGPSessionStateImpl sessionState;
private BGPSessionStatsImpl sessionStats;
- public BGPSessionImpl(final BGPSessionListener listener, final Channel channel, final Open remoteOpen, final BGPSessionPreferences localPreferences,
- final BGPPeerRegistry peerRegistry) {
+ public BGPSessionImpl(final BGPSessionListener listener, final Channel channel, final Open remoteOpen,
+ final BGPSessionPreferences localPreferences, final BGPPeerRegistry peerRegistry) {
this(listener, channel, remoteOpen, localPreferences.getHoldTime(), peerRegistry);
- this.sessionStats = new BGPSessionStatsImpl(this, remoteOpen, this.holdTimerValue, this.keepAlive, channel, Optional.of(localPreferences), this.tableTypes, this.addPathTypes);
+ this.sessionStats = new BGPSessionStatsImpl(this, remoteOpen, this.holdTimerValue, this.keepAlive, channel,
+ Optional.of(localPreferences), this.tableTypes, this.addPathTypes);
}
- public BGPSessionImpl(final BGPSessionListener listener, final Channel channel, final Open remoteOpen, final int localHoldTimer,
- final BGPPeerRegistry peerRegistry) {
+ public BGPSessionImpl(final BGPSessionListener listener, final Channel channel, final Open remoteOpen,
+ final int localHoldTimer, final BGPPeerRegistry peerRegistry) {
this.listener = Preconditions.checkNotNull(listener);
this.channel = Preconditions.checkNotNull(channel);
this.limiter = new ChannelOutputLimiter(this);
this.keepAlive = this.holdTimerValue / KA_TO_DEADTIMER_RATIO;
this.asNumber = AsNumberUtil.advertizedAsNumber(remoteOpen);
this.peerRegistry = peerRegistry;
+ this.sessionState = new BGPSessionStateImpl();
final Set<TablesKey> tts = Sets.newHashSet();
final Set<BgpTableType> tats = Sets.newHashSet();
this.bgpId = remoteOpen.getBgpIdentifier();
this.sessionStats = new BGPSessionStatsImpl(this, remoteOpen, this.holdTimerValue, this.keepAlive, channel, Optional.<BGPSessionPreferences>absent(),
this.tableTypes, this.addPathTypes);
+
+ this.sessionState.advertizeCapabilities(this.holdTimerValue, channel.remoteAddress(), channel.localAddress(),
+ this.tableTypes, remoteOpen.getBgpParameters());
}
/**
}
this.sessionStats.updateReceivedMsg(msg);
-
+ this.sessionState.messageReceived(msg);
} catch (final BGPDocumentedException e) {
this.terminate(e);
}
});
this.lastMessageSentAt = System.nanoTime();
this.sessionStats.updateSentMsg(msg);
+ this.sessionState.messageSent(msg);
return future;
}
});
this.state = State.IDLE;
removePeerSession();
+ this.sessionState.setSessionState(this.state);
}
/**
protected synchronized void sessionUp() {
this.sessionStats.startSessionStopwatch();
this.state = State.UP;
+ this.sessionState.setSessionState(this.state);
this.listener.onSessionUp(this);
}
this.close();
}
}
+
+ @Override
+ public BGPSessionState getBGPSessionState() {
+ return this.sessionState;
+ }
+
+ @Override
+ public BGPTimersState getBGPTimersState() {
+ return this.sessionState;
+ }
+
+ @Override
+ public BGPTransportState getBGPTransportState() {
+ return this.sessionState;
+ }
+
+ @Override
+ public void registerMessagesCounter(final BGPMessagesListener bgpMessagesListener) {
+ this.sessionState.registerMessagesCounter(bgpMessagesListener);
+ }
}