Search in sources :

Example 1 with VplsOperation

use of org.onosproject.vpls.api.VplsOperation in project onos by opennetworkinglab.

the class VplsOperationManager method getOptimizedVplsOperation.

/**
 * Optimizes the VPLS operation queue and return a single VPLS operation to
 * execute.
 *
 * @param operations the queue to be optimized
 * @return optimized VPLS operation from the queue
 */
protected static VplsOperation getOptimizedVplsOperation(Deque<VplsOperation> operations) {
    if (operations.isEmpty()) {
        return null;
    }
    // no need to optimize if the queue contains only one operation
    if (operations.size() == 1) {
        return operations.getFirst();
    }
    final VplsOperation firstOperation = operations.peekFirst();
    final VplsOperation lastOperation = operations.peekLast();
    final VplsOperation.Operation firstOp = firstOperation.op();
    final VplsOperation.Operation lastOp = lastOperation.op();
    if (firstOp.equals(VplsOperation.Operation.REMOVE)) {
        if (lastOp.equals(VplsOperation.Operation.REMOVE)) {
            // case 1: both first and last operation are REMOVE; do remove
            return firstOperation;
        } else if (lastOp.equals(VplsOperation.Operation.ADD)) {
            // case 2: if first is REMOVE, and last is ADD; do update
            return VplsOperation.of(lastOperation.vpls(), VplsOperation.Operation.UPDATE);
        } else {
            // case 3: first is REMOVE, last is UPDATE; do update
            return lastOperation;
        }
    } else if (firstOp.equals(VplsOperation.Operation.ADD)) {
        if (lastOp.equals(VplsOperation.Operation.REMOVE)) {
            // case 4: first is ADD, last is REMOVE; nothing to do
            return null;
        } else if (lastOp.equals(VplsOperation.Operation.ADD)) {
            // case 5: both first and last are ADD, do add
            return VplsOperation.of(lastOperation.vpls(), VplsOperation.Operation.ADD);
        } else {
            // case 6: first is ADD and last is update, do add
            return VplsOperation.of(lastOperation.vpls(), VplsOperation.Operation.ADD);
        }
    } else {
        if (lastOp.equals(VplsOperation.Operation.REMOVE)) {
            // case 7: last is remove, do remove
            return lastOperation;
        } else if (lastOp.equals(VplsOperation.Operation.ADD)) {
            // case 8: do update only
            return VplsOperation.of(lastOperation.vpls(), VplsOperation.Operation.UPDATE);
        } else {
            // only need last UPDATE operation
            return VplsOperation.of(lastOperation.vpls(), VplsOperation.Operation.UPDATE);
        }
    }
}
Also used : VplsOperation(org.onosproject.vpls.api.VplsOperation)

Example 2 with VplsOperation

use of org.onosproject.vpls.api.VplsOperation in project onos by opennetworkinglab.

the class VplsOperationManagerTest method testSubmitAddOperationFail.

/**
 * Submits an ADD operation to the operation manager; check the VPLS state
 * from store if Intent install failed.
 */
@Test
public void testSubmitAddOperationFail() {
    vplsOperationManager.intentService = new AlwaysFailureIntentService();
    VplsData vplsData = VplsData.of(VPLS1);
    vplsData.addInterfaces(ImmutableSet.of(V100H1, V100H2));
    VplsOperation vplsOperation = VplsOperation.of(vplsData, VplsOperation.Operation.ADD);
    vplsOperationManager.submit(vplsOperation);
    assertAfter(OPERATION_DELAY, OPERATION_DURATION, () -> {
        Collection<VplsData> vplss = vplsOperationManager.vplsStore.getAllVpls();
        assertEquals(1, vplss.size());
        VplsData result = vplss.iterator().next();
        assertEquals(vplsData, result);
        assertEquals(VplsData.VplsState.FAILED, result.state());
    });
}
Also used : VplsData(org.onosproject.vpls.api.VplsData) VplsOperation(org.onosproject.vpls.api.VplsOperation) Test(org.junit.Test)

Example 3 with VplsOperation

use of org.onosproject.vpls.api.VplsOperation in project onos by opennetworkinglab.

the class VplsOperationManagerTest method testOptimizeOperationsAToR.

/**
 * Optimize operations with first is ADD operation and last is REMOVE
 * operation.
 */
@Test
public void testOptimizeOperationsAToR() {
    Deque<VplsOperation> operations = new ArrayDeque<>();
    VplsData vplsData = VplsData.of(VPLS1);
    vplsData.addInterfaces(ImmutableSet.of(V100H1));
    VplsOperation vplsOperation = VplsOperation.of(vplsData, VplsOperation.Operation.ADD);
    operations.add(vplsOperation);
    vplsOperation = VplsOperation.of(vplsData, VplsOperation.Operation.REMOVE);
    operations.add(vplsOperation);
    vplsOperation = VplsOperationManager.getOptimizedVplsOperation(operations);
    assertNull(vplsOperation);
}
Also used : VplsOperation(org.onosproject.vpls.api.VplsOperation) VplsData(org.onosproject.vpls.api.VplsData) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Example 4 with VplsOperation

use of org.onosproject.vpls.api.VplsOperation in project onos by opennetworkinglab.

the class VplsOperationManagerTest method testOptimizeOperationsRToU.

/**
 * Optimize operations with first is REMOVE operation and last is UPDATE
 * operation.
 */
@Test
public void testOptimizeOperationsRToU() {
    Deque<VplsOperation> operations = new ArrayDeque<>();
    VplsData vplsData = VplsData.of(VPLS1);
    vplsData.addInterfaces(ImmutableSet.of(V100H1));
    VplsOperation vplsOperation = VplsOperation.of(vplsData, VplsOperation.Operation.REMOVE);
    operations.add(vplsOperation);
    vplsData = VplsData.of(VPLS1, EncapsulationType.VLAN);
    vplsData.addInterfaces(ImmutableSet.of(V100H1, V100H2));
    vplsOperation = VplsOperation.of(vplsData, VplsOperation.Operation.UPDATE);
    operations.add(vplsOperation);
    vplsOperation = VplsOperationManager.getOptimizedVplsOperation(operations);
    assertEquals(VplsOperation.of(vplsData, VplsOperation.Operation.UPDATE), vplsOperation);
}
Also used : VplsOperation(org.onosproject.vpls.api.VplsOperation) VplsData(org.onosproject.vpls.api.VplsData) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Example 5 with VplsOperation

use of org.onosproject.vpls.api.VplsOperation in project onos by opennetworkinglab.

the class VplsOperationManagerTest method testSubmitRemoveOperation.

/**
 * Submits an REMOVE operation to the operation manager; check if the VPLS
 * store changed after a period.
 */
@Test
public void testSubmitRemoveOperation() {
    VplsData vplsData = VplsData.of(VPLS1);
    vplsData.addInterfaces(ImmutableSet.of(V100H1, V100H2));
    vplsData.state(VplsData.VplsState.REMOVING);
    VplsOperation vplsOperation = VplsOperation.of(vplsData, VplsOperation.Operation.REMOVE);
    vplsOperationManager.submit(vplsOperation);
    assertAfter(OPERATION_DELAY, OPERATION_DURATION, () -> {
        Collection<VplsData> vplss = vplsOperationManager.vplsStore.getAllVpls();
        assertEquals(0, vplss.size());
    });
}
Also used : VplsData(org.onosproject.vpls.api.VplsData) VplsOperation(org.onosproject.vpls.api.VplsOperation) Test(org.junit.Test)

Aggregations

VplsOperation (org.onosproject.vpls.api.VplsOperation)19 Test (org.junit.Test)18 VplsData (org.onosproject.vpls.api.VplsData)18 ArrayDeque (java.util.ArrayDeque)10 Intent (org.onosproject.net.intent.Intent)2 Ignore (org.junit.Ignore)1 VplsStoreEvent (org.onosproject.vpls.store.VplsStoreEvent)1