use of org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason in project bgpcep by opendaylight.
the class BGPSessionImplTest method testSessionRecoveryOnException.
@Test
public void testSessionRecoveryOnException() throws Exception {
final BGPSessionListener listener = mock(BGPSessionListener.class);
Mockito.doThrow(new RuntimeException("Mocked runtime exception.")).when(listener).onSessionUp(Matchers.any());
this.bgpSession = Mockito.spy(new BGPSessionImpl(listener, this.speakerListener, this.classicOpen, this.classicOpen.getHoldTimer(), null));
this.bgpSession.setChannelExtMsgCoder(this.classicOpen);
Mockito.verify(this.bgpSession, Mockito.never()).handleException(Matchers.any());
Mockito.verify(this.bgpSession, Mockito.never()).writeAndFlush(Matchers.any(Notification.class));
Mockito.verify(this.bgpSession, Mockito.never()).terminate(Matchers.any(BGPDocumentedException.class));
try {
this.bgpSession.sessionUp();
// expect the exception to be populated
Assert.fail();
} catch (final RuntimeException ignored) {
}
Assert.assertNotEquals(State.UP, this.bgpSession.getState());
Mockito.verify(this.bgpSession).handleException(Matchers.any());
Mockito.verify(this.bgpSession).writeAndFlush(Matchers.any(Notification.class));
Mockito.verify(this.bgpSession).terminate(Matchers.any(BGPDocumentedException.class));
Mockito.verify(listener).onSessionTerminated(this.bgpSession, new BGPTerminationReason(BGPError.CEASE));
}
use of org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason in project bgpcep by opendaylight.
the class BGPSessionImpl method notifyTerminationReasonAndCloseWithoutMessage.
private synchronized void notifyTerminationReasonAndCloseWithoutMessage(final Short errorCode, final Short errorSubcode) {
this.terminationReasonNotified = true;
this.closeWithoutMessage();
this.listener.onSessionTerminated(this, new BGPTerminationReason(BGPError.forValue(errorCode, errorSubcode)));
}
use of org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason in project bgpcep by opendaylight.
the class EventBusRegistration method sendMessage.
private static void sendMessage(final BGPSessionListener listener, final Notification message) {
if (BGPMock.CONNECTION_LOST_MAGIC_MSG.equals(message)) {
listener.onSessionTerminated(null, new BGPTerminationReason(BGPError.CEASE));
} else if (message instanceof Open) {
final Set<BgpTableType> tts = Sets.newHashSet();
final List<AddressFamilies> addPathCapabilitiesList = Lists.newArrayList();
for (final BgpParameters param : ((Open) message).getBgpParameters()) {
for (final OptionalCapabilities capa : param.getOptionalCapabilities()) {
final CParameters cParam = capa.getCParameters();
if (cParam.getAugmentation(CParameters1.class) == null) {
continue;
}
if (cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability() != null) {
final MultiprotocolCapability p = cParam.getAugmentation(CParameters1.class).getMultiprotocolCapability();
LOG.debug("Adding open parameter {}", p);
final BgpTableType type = new BgpTableTypeImpl(p.getAfi(), p.getSafi());
tts.add(type);
} else if (cParam.getAugmentation(CParameters1.class).getAddPathCapability() != null) {
final AddPathCapability addPathCap = cParam.getAugmentation(CParameters1.class).getAddPathCapability();
addPathCapabilitiesList.addAll(addPathCap.getAddressFamilies());
}
}
}
listener.onSessionUp(new MockBGPSession(tts));
} else if (!(message instanceof Keepalive)) {
try {
listener.onMessage(new MockBGPSession(), message);
} catch (BGPDocumentedException e) {
LOG.warn("Exception encountered while handling message", e);
}
}
}
Aggregations