Search in sources :

Example 1 with SessionCloseException

use of org.openkilda.floodlight.error.SessionCloseException in project open-kilda by telstra.

the class SessionServiceTest method sessionBarrierWriteError.

@Test
public void sessionBarrierWriteError() throws Exception {
    IOFSwitch sw = createMock(IOFSwitch.class);
    setupSwitchMock(sw, dpId);
    swWriteSecondFail(sw);
    doneWithSetUp(sw);
    CompletableFuture<Optional<OFMessage>> future = null;
    try (Session session = subject.open(context, sw)) {
        future = session.write(makePacketOut(sw.getOFFactory(), 1));
    }
    try {
        future.get(1, TimeUnit.SECONDS);
        Assert.fail();
    } catch (ExecutionException e) {
        Assert.assertNotNull(e.getCause());
        Assert.assertTrue(e.getCause() instanceof SessionCloseException);
    }
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) Optional(java.util.Optional) SessionCloseException(org.openkilda.floodlight.error.SessionCloseException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 2 with SessionCloseException

use of org.openkilda.floodlight.error.SessionCloseException in project open-kilda by telstra.

the class Session method close.

@Override
public void close() {
    if (error) {
        SessionRevertException e = new SessionRevertException(sw.getId());
        incompleteRequestsStream().forEach(entry -> entry.completeExceptionally(e));
        return;
    }
    if (closingBarrier != null) {
        throw new IllegalStateException("Session already closed");
    }
    OFBarrierRequest barrier = sw.getOFFactory().barrierRequest();
    closingBarrier = prepareRequest(barrier);
    try {
        actualWrite(barrier);
    } catch (SwitchWriteException e) {
        closingBarrier.completeExceptionally(e);
        SessionCloseException closeError = new SessionCloseException(sw.getId());
        incompleteRequestsStream().forEach(entry -> entry.completeExceptionally(closeError));
    }
}
Also used : SessionConnectionLostException(org.openkilda.floodlight.error.SessionConnectionLostException) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) SessionCloseException(org.openkilda.floodlight.error.SessionCloseException) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MessageContext(org.openkilda.messaging.MessageContext) Set(java.util.Set) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException) CompletableFuture(java.util.concurrent.CompletableFuture) IOFSwitch(net.floodlightcontroller.core.IOFSwitch) CorrelationContext(org.openkilda.floodlight.utils.CorrelationContext) Stream(java.util.stream.Stream) ImmutableList(com.google.common.collect.ImmutableList) SessionRevertException(org.openkilda.floodlight.error.SessionRevertException) Map(java.util.Map) SwitchWriteException(org.openkilda.floodlight.error.SwitchWriteException) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) Optional(java.util.Optional) OFErrorMsg(org.projectfloodlight.openflow.protocol.OFErrorMsg) OFType(org.projectfloodlight.openflow.protocol.OFType) OFBarrierRequest(org.projectfloodlight.openflow.protocol.OFBarrierRequest) SessionRevertException(org.openkilda.floodlight.error.SessionRevertException) OFBarrierRequest(org.projectfloodlight.openflow.protocol.OFBarrierRequest) SessionCloseException(org.openkilda.floodlight.error.SessionCloseException) SwitchWriteException(org.openkilda.floodlight.error.SwitchWriteException)

Aggregations

Optional (java.util.Optional)2 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)2 SessionCloseException (org.openkilda.floodlight.error.SessionCloseException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Stream (java.util.stream.Stream)1 Test (org.junit.Test)1 SessionConnectionLostException (org.openkilda.floodlight.error.SessionConnectionLostException)1 SessionErrorResponseException (org.openkilda.floodlight.error.SessionErrorResponseException)1 SessionRevertException (org.openkilda.floodlight.error.SessionRevertException)1 SwitchWriteException (org.openkilda.floodlight.error.SwitchWriteException)1 CorrelationContext (org.openkilda.floodlight.utils.CorrelationContext)1 MessageContext (org.openkilda.messaging.MessageContext)1 OFBarrierRequest (org.projectfloodlight.openflow.protocol.OFBarrierRequest)1 OFErrorMsg (org.projectfloodlight.openflow.protocol.OFErrorMsg)1