InternalFSM { void handleEvent(FSMEvent event) { FSMChannel channel = null; InternalFSMChannelManager channelManager = null; if(event instanceof FSMEvent.ChannelFSMEvent) { channel = ((FSMEvent.ChannelFSMEvent)event).getChannel(); if(connectedChannelManager.isManagedChannel(channel)) channelManager = connectedChannelManager; else if(activeChannelManager.isManagedChannel(channel)) channelManager = activeChannelManager; } switch(event.getType()) { case AutomaticStart: case ManualStart: handleStartEvent(event.getType()); break; case AutomaticStop: case ManualStop: handleStopEvent(event.getType()); break; case ConnectRetryTimer_Expires: handleConnectRetryTimerExpiredEvent(); break; case IdleHoldTimer_Expires: handleIdleHoldTimerExpiredEvent(); break; case TcpConnectionConfirmed: if(channel != null) handleTcpConnectionConfirmed(channel); else haveFSMError = true; break; case Tcp_CR_Acked: if(channel != null) handleTcpConnectionAcked(channel); else haveFSMError = true; break; case TcpConnectionFails: if(channel != null) handleTcpConnectionFails(channel); else haveFSMError = true; break; case DelayOpenTimer_Expires: handleDelayOpenTimerExpiredEvent(); break; case HoldTimer_Expires: handleHoldTimerExpiredEvent(); break; case BGPOpen: if(channel != null && channelManager != null) handleBgpOpenEvent(channel, channelManager); else haveFSMError = true; break; case KeepAliveMsg: handleKeepaliveMessageEvent(); break; case KeepaliveTimer_Expires: handleKeepaliveTimerExpiresEvent(); break; case NotifyMsg: handleNotifyMessageEvent(); break; case NotifyMsgVerErr: handleNotifyMessageVersionErrorEvent(); break; case BGPOpenMsgErr: handleBGPOpenMessageErrorEvent(); break; case BGPHeaderErr: handleBGPHeaderErrorEvent(); break; case UpdateMsg: handleUpdateMessageEvent(); break; case UpdateMsgErr: handleUpdateMessageErrorEvent(); break; } if(channelManager != null) channelManager.pushInboundFSMEvent(event.getType()); if(haveFSMError) { switch(state) { case Established: case OpenConfirm: case OpenSent: connectedChannelManager.fireSendInternalErrorNotification(); activeChannelManager.fireSendInternalErrorNotification(); break; } connectRetryCounter++; moveStateToIdle(); haveFSMError = false; } } InternalFSM(); Date getDelayOpenTimerDueWhen(); boolean isKeepaliveTimerRunning(); Date getKeepaliveTimerDueWhen(); void flagFSMError();  }
@Test public void testTransitionOpenSentOnConnectedChannelByBgpOpen() throws Exception { initializeFSMToOpenSentState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.bgpOpen(connectedBundle.getChannel())); assertMachineInOpenConfirmState(connectedBundle, true); }
@Test public void testTransitionOpenSentOnActiveChannelByBgpOpen() throws Exception { initializeFSMToOpenSentState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.bgpOpen(activeBundle.getChannel())); assertMachineInOpenConfirmState(activeBundle, true); }
@Test public void testTransitionOpenSentOnConnectedChannelTcpConnectionConfirmedByBgpOpenLowerLocalBgpIdentifier() throws Exception { initializeFSMToOpenSentState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionConfirmed(activeBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(activeBundle.getChannel())); verify(callbacks).fireSendCeaseNotification(connectedBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(connectedBundle.getMatcherArg()); assertMachineInOpenConfirm(activeBundle, true, 1, false); }
@Test public void testTransitionOpenSentOnConnectedChannelTcpConnectionConfirmedByBgpOpenHigherBgpIdentifier() throws Exception { initializeFSMToOpenSentState(connectedBundle, "peer9"); fsm.handleEvent(FSMEvent.tcpConnectionConfirmed(activeBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(activeBundle.getChannel())); assertMachineInOpenConfirmState(connectedBundle, true); verify(callbacks).fireSendCeaseNotification(activeBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(activeBundle.getMatcherArg()); }
@Test public void testTransitionOpenSentOnActiveChannelTcpConnectionRequestAckedByBgpOpenLowerLocalBgpIdentifier() throws Exception { initializeFSMToOpenSentState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionRequestAcked(connectedBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(connectedBundle.getChannel())); assertMachineInOpenConfirmState(activeBundle, true); verify(callbacks).fireSendCeaseNotification(connectedBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(connectedBundle.getMatcherArg()); }
@Test public void testTransitionOpenSentOnActiveChannelTcpConnectionRequestAckedByBgpOpenHigherBgpIdentifier() throws Exception { initializeFSMToOpenSentState(activeBundle, "peer9"); fsm.handleEvent(FSMEvent.tcpConnectionRequestAcked(connectedBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(connectedBundle.getChannel())); verify(callbacks).fireSendCeaseNotification(activeBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(activeBundle.getMatcherArg()); assertMachineInOpenConfirm(connectedBundle, true, 1, false); }
@Test public void testTransitionOpenConfirmOnConnectedChannelByBgpOpen() throws Exception { initializeFSMToOpenConfirmState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.bgpOpen(connectedBundle.getChannel())); assertMachineInIdleState(connectedBundle, false); }
@Test public void testTransitionOpenConfirmOnActiveChannelByBgpOpen() throws Exception { initializeFSMToOpenConfirmState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.bgpOpen(activeBundle.getChannel())); assertMachineInIdleState(activeBundle, false); }
@Test public void testTransitionOpenConfirmOnConnectedChannelByKeepaliveMessage() throws Exception { initializeFSMToOpenConfirmState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.keepAliveMessage()); assertMachineInEstablishedState(connectedBundle, true); }
@Test public void testTransitionOpenConfirmOnActiveChannelByKeepaliveMessage() throws Exception { initializeFSMToOpenConfirmState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.keepAliveMessage()); assertMachineInEstablishedState(activeBundle, true); }
@Test public void testTransitionOpenConfirmOnConnectedChannelTcpConnectionConfirmedByBgpOpenLowerLocalBgpIdentifier() throws Exception { initializeFSMToOpenConfirmState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionConfirmed(activeBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(activeBundle.getChannel())); verify(callbacks).fireSendCeaseNotification(connectedBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(connectedBundle.getMatcherArg()); assertMachineInOpenConfirm(activeBundle, true, 0, false); }
@Test public void testTransitionOpenConfirmOnConnectedChannelTcpConnectionConfirmedByBgpOpenHigherBgpIdentifier() throws Exception { initializeFSMToOpenConfirmState(connectedBundle, "peer9"); fsm.handleEvent(FSMEvent.tcpConnectionConfirmed(activeBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(activeBundle.getChannel())); assertMachineInOpenConfirmState(connectedBundle, true); verify(callbacks).fireSendCeaseNotification(activeBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(activeBundle.getMatcherArg()); }
@Test public void testTransitionOpenConfirmOnActiveChannelTcpConnectionRequestAckedByBgpOpenLowerLocalBgpIdentifier() throws Exception { initializeFSMToOpenConfirmState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionRequestAcked(connectedBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(connectedBundle.getChannel())); assertMachineInOpenConfirmState(activeBundle, true); verify(callbacks).fireSendCeaseNotification(connectedBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(connectedBundle.getMatcherArg()); }
@Test public void testTransitionOpenConfirmOnActiveChannelTcpConnectionRequestAckedByBgpOpenHigherBgpIdentifier() throws Exception { initializeFSMToOpenConfirmState(activeBundle, "peer9"); fsm.handleEvent(FSMEvent.tcpConnectionRequestAcked(connectedBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(connectedBundle.getChannel())); verify(callbacks).fireSendCeaseNotification(activeBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(activeBundle.getMatcherArg()); assertMachineInOpenConfirm(activeBundle, true, 1, false); }
@Test public void testTransitionOpenConfirmOnConnectedChannelTcpConnectionConfirmedByKeepaliveTimerExpires() throws Exception { initializeFSMToOpenConfirmState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionConfirmed(activeBundle.getChannel())); fsm.handleEvent(FSMEvent.keepaliveTimerExpires()); assertMachineInOpenConfirm(connectedBundle, true, 2); verify(callbacks, never()).fireSendKeepaliveMessage(activeBundle.getMatcherArg()); }
@Test public void testTransitionOpenConfirmOnActiveChannelTcpConnectionRequestAckedByKeepaliveTimerExpires() throws Exception { initializeFSMToOpenConfirmState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionRequestAcked(connectedBundle.getChannel())); fsm.handleEvent(FSMEvent.keepaliveTimerExpires()); assertMachineInOpenConfirm(activeBundle, true, 2); verify(callbacks, never()).fireSendKeepaliveMessage(connectedBundle.getMatcherArg()); }
@Test public void testTransitionOpenConfirmOnConnectedChannelTcpConnectionConfirmedByKeepaliveMessage() throws Exception { initializeFSMToOpenConfirmState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionConfirmed(activeBundle.getChannel())); fsm.handleEvent(FSMEvent.keepAliveMessage()); assertMachineInEstablishedState(connectedBundle, true); verify(callbacks).fireDisconnectRemotePeer(activeBundle.getMatcherArg()); }
@Test public void testTransitionOpenConfirmOnActiveChannelTcpConnectionRequestAckedByKeepaliveMessage() throws Exception { initializeFSMToOpenConfirmState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionRequestAcked(connectedBundle.getChannel())); fsm.handleEvent(FSMEvent.keepAliveMessage()); assertMachineInEstablishedState(activeBundle, true); verify(callbacks).fireDisconnectRemotePeer(connectedBundle.getMatcherArg()); }
@Test public void testTransitionEstablishedOnConnectedChannelByBgpOpen() throws Exception { initializeFSMToEstablishedState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.bgpOpen(connectedBundle.getChannel())); assertMachineInIdleState(connectedBundle, false); }
@Test public void testTransitionEstablishedOnActiveChannelByBgpOpen() throws Exception { initializeFSMToEstablishedState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.bgpOpen(connectedBundle.getChannel())); assertMachineInIdleState(activeBundle, false); }
@Test public void testTransitionEstablishedOnConnectedChannelByKeepaliveMessage() throws Exception { initializeFSMToEstablishedState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.keepAliveMessage()); assertMachineInEstablishedState(connectedBundle, true); }
@Test public void testTransitionEstablishedOnActiveChannelByKeepaliveMessage() throws Exception { initializeFSMToEstablishedState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.keepAliveMessage()); assertMachineInEstablishedState(activeBundle, true); }
@Test public void testTransitionEstablishedOnConnectedChannelTcpConnectionConfirmedByBgpOpenOnEstablishedChannel() throws Exception { initializeFSMToEstablishedState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionConfirmed(activeBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(connectedBundle.getChannel())); assertMachineInIdleState(connectedBundle, false); verify(callbacks).fireDisconnectRemotePeer(activeBundle.getMatcherArg()); }
@Test public void testTransitionEstablishedOnActiveChannelTcpConnectionRequestAckedByBgpOpenOnEstablishedChannel() throws Exception { initializeFSMToEstablishedState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionRequestAcked(connectedBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(activeBundle.getChannel())); assertMachineInIdleState(activeBundle, false); verify(callbacks).fireDisconnectRemotePeer(connectedBundle.getMatcherArg()); }
@Test public void testTransitionEstablishedOnConnectedChannelTcpConnectionConfirmedByBgpOpenOnSecondChannelLowerLocalBgpIdentifier() throws Exception { initializeFSMToEstablishedState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionConfirmed(activeBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(activeBundle.getChannel())); assertMachineInIdleState(connectedBundle, false); verify(callbacks).fireSendCeaseNotification(connectedBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(activeBundle.getMatcherArg()); }
@Test public void testTransitionEstablishedOnActiveChannelTcpConnectionRequestAckedByBgpOpenOnSecondChannelLowerLocalBgpIdentifier() throws Exception { initializeFSMToEstablishedState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionRequestAcked(connectedBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(connectedBundle.getChannel())); assertMachineInIdleState(activeBundle, false); verify(callbacks).fireSendCeaseNotification(connectedBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(connectedBundle.getMatcherArg()); }
@Test public void testTransitionEstablishedOnConnectedChannelTcpConnectionConfirmedByBgpOpenOnSecondChannelHigherLocalBgpIdentifier() throws Exception { initializeFSMToEstablishedState(connectedBundle, "peer9"); fsm.handleEvent(FSMEvent.tcpConnectionConfirmed(activeBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(activeBundle.getChannel())); assertMachineInEstablishedState(connectedBundle, true); verify(callbacks).fireSendCeaseNotification(activeBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(activeBundle.getMatcherArg()); }
@Test public void testTransitionEstablishedOnActiveChannelTcpConnectionRequestAckedByBgpOpenOnSecondChannelHigherLocalBgpIdentifier() throws Exception { initializeFSMToEstablishedState(activeBundle, "peer9"); fsm.handleEvent(FSMEvent.tcpConnectionRequestAcked(connectedBundle.getChannel())); fsm.handleEvent(FSMEvent.bgpOpen(connectedBundle.getChannel())); assertMachineInEstablishedState(connectedBundle, true, 0); verify(callbacks).fireSendCeaseNotification(activeBundle.getMatcherArg()); verify(callbacks).fireDisconnectRemotePeer(activeBundle.getMatcherArg()); }
@Test public void testTransitionEstablishedOnConnectedChannelTcpConnectionConfirmedByKeepaliveMessage() throws Exception { initializeFSMToEstablishedState(connectedBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionConfirmed(activeBundle.getChannel())); fsm.handleEvent(FSMEvent.keepAliveMessage()); assertMachineInEstablishedState(connectedBundle, true); verify(callbacks, never()).fireDisconnectRemotePeer(activeBundle.getMatcherArg()); }
@Test public void testTransitionEstablishedOnActiveChannelTcpConnectionRequestAckedByKeepaliveMessage() throws Exception { initializeFSMToEstablishedState(activeBundle, "peer1"); fsm.handleEvent(FSMEvent.tcpConnectionRequestAcked(connectedBundle.getChannel())); fsm.handleEvent(FSMEvent.keepAliveMessage()); assertMachineInEstablishedState(activeBundle, true); verify(callbacks, never()).fireDisconnectRemotePeer(connectedBundle.getMatcherArg()); }