private void setSecurityGroupRule(DeviceId id, OpenstackSecurityGroupRule sgRule, Ip4Address vmIp, IpPrefix remoteIp) { ForwardingObjective.Builder foBuilder = buildFlowObjective(id, sgRule, vmIp, remoteIp); if (foBuilder != null) { flowObjectiveService.forward(id, foBuilder.add()); } }
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; }
/** * Applies all contexts to flow objective service. */ public void apply() { if (pendingContexts.isEmpty()) { moveNextPendingToPending(); } final Set<ObjectiveContext> contextsToApply = pendingContexts(); contextsToApply.forEach(ctx -> { FlowObjectiveInstallationContext foiCtx = (FlowObjectiveInstallationContext) ctx; flowObjectiveService.apply(foiCtx.deviceId, foiCtx.objective); }); }
int nextId = flowObjectiveService.allocateNextId(); NextObjective.Builder nextBuilder = DefaultNextObjective.builder() .withId(nextId) flowObjectiveService.next(deviceId, nextObjective); flowObjectiveService.forward(deviceId, fob);
int nextId = flowObjectiveService.allocateNextId(); NextObjective.Builder nextObjBuilder = DefaultNextObjective .builder().withId(nextId) nextId, deviceId, portNumber, vlanId); if (install) { flowObjectiveService.next(deviceId, nextObjBuilder.add()); } else { flowObjectiveService.next(deviceId, nextObjBuilder.remove());
private void sendFilteringObjective(boolean install, FilteringObjective.Builder fob, Interface intf) { ObjectiveContext context = new DefaultObjectiveContext( (objective) -> log.info("Installed filter for interface {}", intf), (objective, error) -> log.error("Failed to install filter for interface {}: {}", intf, error)); FilteringObjective filter = install ? fob.add(context) : fob.remove(context); flowObjectiveService.filter(deviceId, filter); }
@Override protected void doExecute() { if (please == null || !please.equals(CONFIRM_PHRASE)) { print("WARNING: System may enter an unpredictable state if the flow obj queues are force emptied." + "Enter confirmation phrase to continue."); return; } try { FlowObjectiveService service = get(FlowObjectiveService.class); service.clearQueue(); } catch (ServiceNotFoundException e) { print("FlowObjectiveService unavailable"); } }
private int createPeerGroup(MacAddress srcMac, MacAddress dstMac, VlanId vlanId, DeviceId deviceId, PortNumber port) { int nextId = flowObjectiveService.allocateNextId(); NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder() .withId(nextId) .withType(NextObjective.Type.SIMPLE) .fromApp(appId); TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder(); ttBuilder.setEthSrc(srcMac); ttBuilder.setEthDst(dstMac); ttBuilder.setOutput(port); nextObjBuilder.addTreatment(ttBuilder.build()); TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(); VlanId matchVlanId = (vlanId.equals(VlanId.NONE)) ? VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN) : vlanId; metabuilder.matchVlanId(matchVlanId); nextObjBuilder.withMeta(metabuilder.build()); flowObjectiveService.next(deviceId, nextObjBuilder.add()); return nextId; }
private void removeSecurityGroupRule(DeviceId id, OpenstackSecurityGroupRule sgRule, Ip4Address vmIp, IpPrefix remoteIp) { ForwardingObjective.Builder foBuilder = buildFlowObjective(id, sgRule, vmIp, remoteIp); if (foBuilder != null) { flowObjectiveService.forward(id, foBuilder.remove()); } }
private List<Objective> createSimpleNextObjective(ForwardingInstructions instructions, 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(); nextObjective = nxBuilder.withId(nextId) .withMeta(instructions.selector()) .addTreatment(instructions.treatment()) .withType(NextObjective.Type.SIMPLE) .fromApp(appId) .makePermanent() .withPriority(intent.priority()) .add(); objectives.add(forwardingObjective); objectives.add(nextObjective); return objectives; }
ctx.setObjective(newObj, ctx.deviceId); ctx.increaseRetryValue(); flowObjectiveService.apply(ctx.deviceId, ctx.objective); } else { pendingContexts.remove(ctx); flowObjectiveService.apply(ctx.deviceId, ctx.objective); break; case GROUPMISSING: ctx.setObjective(newObj, ctx.deviceId); ctx.increaseRetryValue(); flowObjectiveService.apply(ctx.deviceId, ctx.objective); } else if (ctx.objective.op() == Objective.Operation.REMOVE || ctx.objective.op() == Objective.Operation.REMOVE_FROM_EXISTING) { flowObjectiveService.apply(ctx.deviceId, ctx.objective); flowObjectiveService.apply(ctx.deviceId, ctx.objective); break; default:
private synchronized void deleteRoute(ResolvedRoute route) { //Integer nextId = nextHops.get(route.nextHop()); /* Group group = deleteNextHop(route.prefix()); if (group == null) { log.warn("Group not found when deleting {}", route); return; }*/ flowObjectiveService.forward(deviceId, generateRibForwardingObj(route.prefix(), null).remove()); }
.withId(flowObjectiveService.allocateNextId()) .addTreatment(treatment) .withType(NextObjective.Type.SIMPLE)
flowObjectiveService.apply(nextContext.deviceId, nextContext.objective); intentInstallationContext.removePendingContext(this); contextsToApply.forEach(ctx -> { FlowObjectiveInstallationContext foiCtx = (FlowObjectiveInstallationContext) ctx; flowObjectiveService.apply(foiCtx.deviceId, foiCtx.objective); });
private void updateRoute(ResolvedRoute route) { addNextHop(route); Integer nextId; synchronized (this) { nextId = nextHops.get(route.nextHop()); } flowObjectiveService.forward(deviceId, generateRibForwardingObj(route.prefix(), nextId).add()); log.trace("Sending forwarding objective {} -> nextId:{}", route, nextId); }
/** * Send service-function-forwarder to OVS. * * @param selector traffic selector * @param treatment traffic treatment * @param deviceId device id * @param type operation type * @param priority priority of classifier */ public void sendSfcRule(TrafficSelector.Builder selector, TrafficTreatment.Builder treatment, DeviceId deviceId, Objective.Operation type, int priority) { log.info("Sending sfc flow rule. Selector {}, Treatment {}", selector.toString(), treatment.toString()); ForwardingObjective.Builder objective = DefaultForwardingObjective.builder().withTreatment(treatment.build()) .withSelector(selector.build()).fromApp(appId).makePermanent().withFlag(Flag.VERSATILE) .withPriority(priority); if (type.equals(Objective.Operation.ADD)) { log.debug("flowClassifierRules-->ADD"); flowObjectiveService.forward(deviceId, objective.add()); } else { log.debug("flowClassifierRules-->REMOVE"); flowObjectiveService.forward(deviceId, objective.remove()); } }
@Override public void removeSnatRules(DeviceId deviceId, TrafficSelector selector, TrafficTreatment treatment, int priority, Objective.Operation type) { ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment).withSelector(selector) .fromApp(appId).withFlag(Flag.SPECIFIC).withPriority(priority); if (type.equals(Objective.Operation.ADD)) { flowObjectiveService.forward(deviceId, objective.add()); } else { flowObjectiveService.forward(deviceId, objective.remove()); } } }
/** * Send bgp flow forwarder to bgp provider. * * @param selector traffic selector * @param treatment traffic treatment * @param deviceId device id * @param type operation type */ public void sendBgpFlowRuleForwarder(TrafficSelector.Builder selector, TrafficTreatment.Builder treatment, DeviceId deviceId, Objective.Operation type) { ForwardingObjective.Builder objective = DefaultForwardingObjective.builder().withTreatment(treatment.build()) .withSelector(selector.build()).fromApp(appId).makePermanent().withFlag(Flag.VERSATILE); if (type.equals(Objective.Operation.ADD)) { log.debug("ADD"); flowObjectiveService.forward(deviceId, objective.add()); } else { log.debug("REMOVE"); flowObjectiveService.forward(deviceId, objective.remove()); } } }
/** * 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.SWITCH)) { 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); }