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