Search in sources :

Example 1 with SwitchWriteException

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

the class SessionServiceTest method switchWriteError.

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

Example 2 with SwitchWriteException

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

the class Session method write.

/**
 * Send OF message to the switch and register it in session to trace possible responses.
 */
public CompletableFuture<Optional<OFMessage>> write(OFMessage message) {
    ensureOpen();
    CompletableFuture<Optional<OFMessage>> future = prepareRequest(message);
    try {
        actualWrite(message);
    } catch (SwitchWriteException e) {
        future.completeExceptionally(e);
    } catch (Exception e) {
        SwitchWriteException writeError = new SwitchWriteException(sw.getId(), message, e);
        future.completeExceptionally(writeError);
    }
    return future;
}
Also used : Optional(java.util.Optional) SwitchWriteException(org.openkilda.floodlight.error.SwitchWriteException) SessionConnectionLostException(org.openkilda.floodlight.error.SessionConnectionLostException) SessionCloseException(org.openkilda.floodlight.error.SessionCloseException) SessionErrorResponseException(org.openkilda.floodlight.error.SessionErrorResponseException) SessionRevertException(org.openkilda.floodlight.error.SessionRevertException) SwitchWriteException(org.openkilda.floodlight.error.SwitchWriteException)

Example 3 with SwitchWriteException

use of org.openkilda.floodlight.error.SwitchWriteException 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)3 SwitchWriteException (org.openkilda.floodlight.error.SwitchWriteException)3 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)2 SessionCloseException (org.openkilda.floodlight.error.SessionCloseException)2 SessionConnectionLostException (org.openkilda.floodlight.error.SessionConnectionLostException)2 SessionErrorResponseException (org.openkilda.floodlight.error.SessionErrorResponseException)2 SessionRevertException (org.openkilda.floodlight.error.SessionRevertException)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 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