Search in sources :

Example 6 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 7 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)

Example 8 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 9 with VplsOperation

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

the class VplsManagerTest method testStoreDelegate.

/**
 * Pass different VPLS store event to store delegate.
 * Include these cases:
 * <ul>
 *     <li>VPLS added</li>
 *     <li>VPLS updated</li>
 *     <li>VPLS state updated</li>
 *     <li>VPLS removed</li>
 * </ul>
 */
@Test
public void testStoreDelegate() {
    // Add
    VplsData vplsData = vplsManager.createVpls(VPLS1, NONE);
    VplsStoreEvent event = new VplsStoreEvent(VplsStoreEvent.Type.ADD, vplsData);
    vplsStore.delegate().notify(event);
    VplsOperation vplsOperation = vplsOperationService.operation();
    assertEquals(vplsOperation.op(), VplsOperation.Operation.ADD);
    assertEquals(vplsOperation.vpls(), vplsData);
    vplsOperationService.clear();
    // Update info
    vplsData.encapsulationType(EncapsulationType.VLAN);
    vplsData.state(UPDATING);
    event = new VplsStoreEvent(VplsStoreEvent.Type.UPDATE, vplsData);
    vplsStore.delegate().notify(event);
    vplsOperation = vplsOperationService.operation();
    assertEquals(vplsOperation.op(), VplsOperation.Operation.UPDATE);
    assertEquals(vplsOperation.vpls(), vplsData);
    vplsOperationService.clear();
    // Update state (no operation)
    vplsData.state(VplsData.VplsState.ADDED);
    event = new VplsStoreEvent(VplsStoreEvent.Type.UPDATE, vplsData);
    vplsStore.delegate().notify(event);
    vplsOperation = vplsOperationService.operation();
    assertNull(vplsOperation);
    vplsOperationService.clear();
    // Remove
    event = new VplsStoreEvent(VplsStoreEvent.Type.REMOVE, vplsData);
    vplsStore.delegate().notify(event);
    vplsOperation = vplsOperationService.operation();
    assertEquals(vplsOperation.op(), VplsOperation.Operation.REMOVE);
    assertEquals(vplsOperation.vpls(), vplsData);
    vplsOperationService.clear();
}
Also used : VplsStoreEvent(org.onosproject.vpls.store.VplsStoreEvent) VplsData(org.onosproject.vpls.api.VplsData) VplsOperation(org.onosproject.vpls.api.VplsOperation) Test(org.junit.Test)

Example 10 with VplsOperation

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

the class VplsOperationManagerTest method testOptimizeOperationsNoOptimize.

/**
 * Optimize operations which don't need to be optimized.
 */
@Test
public void testOptimizeOperationsNoOptimize() {
    // empty queue
    Deque<VplsOperation> operations = new ArrayDeque<>();
    VplsOperation vplsOperation = VplsOperationManager.getOptimizedVplsOperation(operations);
    assertNull(vplsOperation);
    // one operation
    VplsData vplsData = VplsData.of(VPLS1);
    vplsOperation = VplsOperation.of(vplsData, VplsOperation.Operation.ADD);
    operations.add(vplsOperation);
    VplsOperation result = VplsOperationManager.getOptimizedVplsOperation(operations);
    assertEquals(vplsOperation, result);
}
Also used : VplsOperation(org.onosproject.vpls.api.VplsOperation) VplsData(org.onosproject.vpls.api.VplsData) ArrayDeque(java.util.ArrayDeque) 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