Search in sources :

Example 1 with OFBarrierRequest

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());
}
Also used : IOFSwitch(net.floodlightcontroller.core.IOFSwitch) Optional(java.util.Optional) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFBarrierRequest(org.projectfloodlight.openflow.protocol.OFBarrierRequest) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut) Test(org.junit.Test)

Example 2 with OFBarrierRequest

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;
}
Also used : OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) OFBarrierReply(org.projectfloodlight.openflow.protocol.OFBarrierReply) OFBarrierRequest(org.projectfloodlight.openflow.protocol.OFBarrierRequest) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with OFBarrierRequest

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

OFBarrierRequest (org.projectfloodlight.openflow.protocol.OFBarrierRequest)3 Optional (java.util.Optional)2 IOFSwitch (net.floodlightcontroller.core.IOFSwitch)2 OFFactory (org.projectfloodlight.openflow.protocol.OFFactory)2 OFMessage (org.projectfloodlight.openflow.protocol.OFMessage)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 TimeoutException (java.util.concurrent.TimeoutException)1 Stream (java.util.stream.Stream)1 Test (org.junit.Test)1 SessionCloseException (org.openkilda.floodlight.error.SessionCloseException)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