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);
}
}
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;
}
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));
}
}
Aggregations