use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.
the class DefaultL2TunnelHandler method deployPseudoWireTerm.
/**
* Handles the tunnel termination, which consists in the creation
* of a forwarding objective and a next objective.
*
* @param l2Tunnel the tunnel to terminate
* @param egress the egress point
* @param egressVlan the expected vlan at egress
* @param direction the direction
* @return the result of the operation
*/
private Result deployPseudoWireTerm(L2Tunnel l2Tunnel, ConnectPoint egress, VlanId egressVlan, Direction direction, boolean oneHop) {
log.debug("Started deploying termination objectives for pseudowire {} , direction {}.", l2Tunnel.tunnelId(), direction == FWD ? "forward" : "reverse");
// We create the group relative to the termination.
NextObjective.Builder nextObjectiveBuilder = createNextObjective(TERMINATION, egress, null, l2Tunnel, egress.deviceId(), oneHop, egressVlan);
if (nextObjectiveBuilder == null) {
return INTERNAL_ERROR;
}
TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(egressVlan).build();
nextObjectiveBuilder.withMeta(metadata);
int nextId = srManager.flowObjectiveService.allocateNextId();
if (nextId < 0) {
log.warn("Not able to allocate a next id for initiation");
return INTERNAL_ERROR;
}
nextObjectiveBuilder.withId(nextId);
String key = generateKey(l2Tunnel.tunnelId(), direction);
l2TerminationNextObjStore.put(key, nextObjectiveBuilder.add());
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Termination l2 tunnel rule for {} populated", l2Tunnel.tunnelId()), (objective, error) -> {
log.warn("Failed to populate termination l2 tunnel rule for {}: {}", l2Tunnel.tunnelId(), error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObjective = nextObjectiveBuilder.add(context);
srManager.flowObjectiveService.next(egress.deviceId(), nextObjective);
log.debug("Termination next objective for {} not found. Creating new NextObj with id={}", l2Tunnel.tunnelId(), nextObjective.id());
// We create the flow relative to the termination.
ForwardingObjective.Builder fwdBuilder = createTermFwdObjective(l2Tunnel.pwLabel(), l2Tunnel.tunnelId(), egress.port(), nextObjective.id());
context = new DefaultObjectiveContext((objective) -> log.debug("FwdObj for tunnel termination {} populated", l2Tunnel.tunnelId()), (objective, error) -> log.warn("Failed to populate fwdrObj" + " for tunnel termination {} : {}", l2Tunnel.tunnelId(), error));
srManager.flowObjectiveService.forward(egress.deviceId(), fwdBuilder.add(context));
log.debug("Creating new FwdObj for termination NextObj with id={} for tunnel {}", nextId, l2Tunnel.tunnelId());
return SUCCESS;
}
use of org.onosproject.net.flowobjective.Objective 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.Objective 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.Objective in project onos by opennetworkinglab.
the class LinkCollectionIntentFlowObjectiveCompiler method createBroadcastObjective.
private List<Objective> createBroadcastObjective(ForwardingInstructions instructions, Set<TrafficTreatment> treatmentsWithDifferentPort, LinkCollectionIntent intent) {
List<Objective> objectives = Lists.newArrayList();
ForwardingObjective forwardingObjective;
NextObjective nextObjective;
Integer nextId = flowObjectiveService.allocateNextId();
forwardingObjective = buildForwardingObjective(instructions.selector(), nextId, intent.priority());
DefaultNextObjective.Builder nxBuilder = DefaultNextObjective.builder();
nxBuilder.withId(nextId).withMeta(instructions.selector()).withType(NextObjective.Type.BROADCAST).fromApp(appId).withPriority(intent.priority()).makePermanent();
treatmentsWithDifferentPort.forEach(nxBuilder::addTreatment);
nextObjective = nxBuilder.add();
objectives.add(forwardingObjective);
objectives.add(nextObjective);
return objectives;
}
use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method testRemoveIgnoreVlan.
/**
* "IgnoreVlan" policy should be removed when the config removed.
*/
@Test
public void testRemoveIgnoreVlan() {
v4Handler.ignoredVlans.put(DEV_1_ID, IGNORED_VLAN);
v4Handler.ignoredVlans.put(DEV_2_ID, IGNORED_VLAN);
v6Handler.ignoredVlans.put(DEV_1_ID, IGNORED_VLAN);
v6Handler.ignoredVlans.put(DEV_2_ID, IGNORED_VLAN);
IgnoreDhcpConfig config = new IgnoreDhcpConfig();
Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
expectLastCall().times(DHCP_SELECTORS.size());
Capture<Objective> capturedFromDev2 = newCapture(CaptureType.ALL);
flowObjectiveService.apply(eq(DEV_2_ID), capture(capturedFromDev2));
expectLastCall().times(DHCP_SELECTORS.size());
replay(flowObjectiveService);
manager.removeConfig(config);
verify(flowObjectiveService);
List<Objective> objectivesFromDev1 = capturedFromDev1.getValues();
List<Objective> objectivesFromDev2 = capturedFromDev2.getValues();
assertTrue(objectivesFromDev1.containsAll(objectivesFromDev2));
assertTrue(objectivesFromDev2.containsAll(objectivesFromDev1));
for (int index = 0; index < objectivesFromDev1.size(); index++) {
TrafficSelector selector = DefaultTrafficSelector.builder(DHCP_SELECTORS.get(index)).matchVlanId(IGNORED_VLAN).build();
ForwardingObjective fwd = (ForwardingObjective) objectivesFromDev1.get(index);
assertEquals(selector, fwd.selector());
assertEquals(DefaultTrafficTreatment.emptyTreatment(), fwd.treatment());
assertEquals(IGNORE_CONTROL_PRIORITY, fwd.priority());
assertEquals(ForwardingObjective.Flag.VERSATILE, fwd.flag());
assertEquals(Objective.Operation.REMOVE, fwd.op());
fwd.context().ifPresent(ctx -> {
ctx.onSuccess(fwd);
});
}
objectivesFromDev2.forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
assertEquals(0, v4Handler.ignoredVlans.size());
assertEquals(0, v6Handler.ignoredVlans.size());
}
Aggregations