use of org.onosproject.net.flowobjective.ObjectiveError in project onos by opennetworkinglab.
the class VirtualNetworkPacketManager method removeRule.
/**
* Removes packet intercept flow rules from the device.
*
* @param device the device to remove the rules deom
* @param request the packet request
*/
private void removeRule(Device device, PacketRequest request) {
if (!device.type().equals(Device.Type.VIRTUAL)) {
return;
}
ForwardingObjective forwarding = createBuilder(request).remove(new ObjectiveContext() {
@Override
public void onError(Objective objective, ObjectiveError error) {
log.warn("Failed to withdraw packet request {} from {}: {}", request, device.id(), error);
}
});
objectiveService.forward(device.id(), forwarding);
}
use of org.onosproject.net.flowobjective.ObjectiveError in project onos by opennetworkinglab.
the class InOrderFlowObjectiveManagerTest method forwardTimeout.
@Test
public void forwardTimeout() {
final AtomicInteger counter = new AtomicInteger(0);
ForwardingObjective fwdTimeout = buildFwdObjective(S1, NID2).add(new ObjectiveContext() {
@Override
public void onError(Objective objective, ObjectiveError error) {
if (Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
counter.incrementAndGet();
}
}
});
List<ForwardingObjective> expectFwdObjsTimeout = Lists.newCopyOnWriteArrayList(Lists.newArrayList(fwdTimeout, FWD1, FWD2));
// Reduce timeout so the unit test doesn't have to wait many seconds
internalSetup(TIMEOUT_THRESH);
expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(1);
expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(2);
replay(mgr.flowObjectiveStore);
// Force this objective to time out
offset = mgr.objectiveTimeoutMs * 3;
expectFwdObjsTimeout.forEach(fwdObj -> mgr.forward(DEV1, fwdObj));
// Wait for the pipeline operation to complete
int expectedTime = (bound + offset) * 3;
assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFwdObjsTimeout.size(), actualObjs.size()));
assertAfter(expectedTime, expectedTime * 5, () -> assertTrue(counter.get() != 0));
assertTrue(actualObjs.indexOf(fwdTimeout) < actualObjs.indexOf(FWD1));
verify(mgr.flowObjectiveStore);
}
use of org.onosproject.net.flowobjective.ObjectiveError in project onos by opennetworkinglab.
the class Ofdpa2Pipeline method sendForwards.
// Builds the batch using the accumulated flow rules
private void sendForwards(List<Pair<ForwardingObjective, Collection<FlowRule>>> pairs) {
FlowRuleOperations.Builder flowOpsBuilder = FlowRuleOperations.builder();
log.debug("Sending {} fwd-objs", pairs.size());
List<Objective> fwdObjs = Lists.newArrayList();
// Iterates over all accumulated flow rules and then build an unique batch
pairs.forEach(pair -> {
ForwardingObjective fwd = pair.getLeft();
Collection<FlowRule> rules = pair.getRight();
switch(fwd.op()) {
case ADD:
rules.stream().filter(Objects::nonNull).forEach(flowOpsBuilder::add);
log.debug("Applying a add fwd-obj {} to sw:{}", fwd.id(), deviceId);
fwdObjs.add(fwd);
break;
case REMOVE:
rules.stream().filter(Objects::nonNull).forEach(flowOpsBuilder::remove);
log.debug("Deleting a flow rule to sw:{}", deviceId);
fwdObjs.add(fwd);
break;
default:
fail(fwd, ObjectiveError.UNKNOWN);
log.warn("Unknown forwarding type {}", fwd.op());
}
});
// Finally applies the operations
flowRuleService.apply(flowOpsBuilder.build(new FlowRuleOperationsContext() {
@Override
public void onSuccess(FlowRuleOperations ops) {
log.trace("Flow rule operations onSuccess {}", ops);
fwdObjs.forEach(OfdpaPipelineUtility::pass);
}
@Override
public void onError(FlowRuleOperations ops) {
ObjectiveError error = ObjectiveError.FLOWINSTALLATIONFAILED;
log.warn("Flow rule operations onError {}. Reason = {}", ops, error);
fwdObjs.forEach(fwdObj -> fail(fwdObj, error));
}
}));
}
use of org.onosproject.net.flowobjective.ObjectiveError in project onos by opennetworkinglab.
the class FabricPipeliner method next.
@Override
public void next(NextObjective obj) {
if (obj.op() == Objective.Operation.VERIFY) {
if (obj.type() != NextObjective.Type.HASHED) {
log.warn("VERIFY operation not yet supported for NextObjective {}, will return failure :(", obj.type());
fail(obj, ObjectiveError.UNSUPPORTED);
return;
}
if (log.isTraceEnabled()) {
log.trace("Verify NextObjective {} in dev {}", obj, deviceId);
}
ObjectiveError error = handleVerify(obj);
if (error == null) {
success(obj);
} else {
fail(obj, error);
}
return;
}
if (obj.op() == Objective.Operation.MODIFY && obj.type() != SIMPLE) {
log.warn("MODIFY operation not yet supported for NextObjective {}, will return failure :(", obj.type());
if (log.isTraceEnabled()) {
log.trace("Objective {}", obj);
}
fail(obj, ObjectiveError.UNSUPPORTED);
return;
}
final ObjectiveTranslation result = nextTranslator.translate(obj);
handleResult(obj, result);
}
use of org.onosproject.net.flowobjective.ObjectiveError in project onos by opennetworkinglab.
the class Dhcp4HandlerImpl method processIgnoreVlanRule.
/**
* Process the ignore rules.
*
* @param deviceId the device id
* @param vlanId the vlan to be ignored
* @param op the operation, ADD to install; REMOVE to uninstall rules
*/
private void processIgnoreVlanRule(DeviceId deviceId, VlanId vlanId, Objective.Operation op) {
AtomicInteger installedCount = new AtomicInteger(DHCP_SELECTORS.size());
DHCP_SELECTORS.forEach(trafficSelector -> {
TrafficSelector selector = DefaultTrafficSelector.builder(trafficSelector).matchVlanId(vlanId).build();
ForwardingObjective.Builder builder = DefaultForwardingObjective.builder().withFlag(ForwardingObjective.Flag.VERSATILE).withSelector(selector).withPriority(IGNORE_CONTROL_PRIORITY).withTreatment(DefaultTrafficTreatment.emptyTreatment()).fromApp(appId);
ObjectiveContext objectiveContext = new ObjectiveContext() {
@Override
public void onSuccess(Objective objective) {
log.info("Ignore rule {} (Vlan id {}, device {}, selector {})", op, vlanId, deviceId, selector);
int countDown = installedCount.decrementAndGet();
if (countDown != 0) {
return;
}
switch(op) {
case ADD:
ignoredVlans.put(deviceId, vlanId);
break;
case REMOVE:
ignoredVlans.remove(deviceId, vlanId);
break;
default:
log.warn("Unsupported objective operation {}", op);
break;
}
}
@Override
public void onError(Objective objective, ObjectiveError error) {
log.warn("Can't {} ignore rule (vlan id {}, selector {}, device {}) due to {}", op, vlanId, selector, deviceId, error);
}
};
ForwardingObjective fwd;
switch(op) {
case ADD:
fwd = builder.add(objectiveContext);
break;
case REMOVE:
fwd = builder.remove(objectiveContext);
break;
default:
log.warn("Unsupported objective operation {}", op);
return;
}
Device device = deviceService.getDevice(deviceId);
if (device == null || !device.is(Pipeliner.class)) {
log.warn("Device {} is not available now, wait until device is available", deviceId);
return;
}
flowObjectiveService.apply(deviceId, fwd);
});
}
Aggregations