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