use of org.projectfloodlight.openflow.protocol.OFBarrierRequest in project open-kilda by telstra.
the class SessionServiceTest method barrierInTheMiddle.
@Test
public void barrierInTheMiddle() throws Exception {
IOFSwitch sw = createMock(IOFSwitch.class);
setupSwitchMock(sw, dpId);
swWriteAlwaysSuccess(sw);
doneWithSetUp(sw);
OFFactory ofFactory = sw.getOFFactory();
OFPacketOut pktOut = makePacketOut(ofFactory, 1);
OFBarrierRequest barrier = ofFactory.barrierRequest();
CompletableFuture<Optional<OFMessage>> pktOutFuture;
CompletableFuture<Optional<OFMessage>> barrierFuture;
try (Session session = subject.open(context, sw)) {
pktOutFuture = session.write(pktOut);
barrierFuture = session.write(barrier);
}
Assert.assertFalse(pktOutFuture.isDone());
Assert.assertFalse(barrierFuture.isDone());
subject.handleResponse(sw.getId(), ofFactory.buildBarrierReply().setXid(barrier.getXid()).build());
Assert.assertFalse(pktOutFuture.isDone());
Assert.assertTrue(barrierFuture.isDone());
completeSessions(sw);
Assert.assertTrue(pktOutFuture.isDone());
Assert.assertTrue(barrierFuture.isDone());
Optional<OFMessage> barrierResponse = barrierFuture.get();
Assert.assertTrue(barrierResponse.isPresent());
Assert.assertEquals(OFType.BARRIER_REPLY, barrierResponse.get().getType());
Assert.assertEquals(barrier.getXid(), barrierResponse.get().getXid());
}
use of org.projectfloodlight.openflow.protocol.OFBarrierRequest in project open-kilda by telstra.
the class SwitchManager method sendBarrierRequest.
private OFBarrierReply sendBarrierRequest(IOFSwitch sw) {
OFFactory ofFactory = sw.getOFFactory();
OFBarrierRequest barrierRequest = ofFactory.buildBarrierRequest().build();
OFBarrierReply result = null;
try {
ListenableFuture<OFBarrierReply> future = sw.writeRequest(barrierRequest);
result = future.get(10, TimeUnit.SECONDS);
} catch (ExecutionException | TimeoutException e) {
logger.error("Could not get a barrier reply for {}.", sw.getId(), e);
} catch (InterruptedException e) {
logger.error("Could not get a barrier reply for {}.", sw.getId(), e);
Thread.currentThread().interrupt();
}
return result;
}
use of org.projectfloodlight.openflow.protocol.OFBarrierRequest 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