break; case "REMOVE": forwardingObjective = builder.remove(); break; default:
public List<ForwardingObjective> getGeneratedParentForwardingObjectiveForRemove(ForwardingObjective child) { List<ForwardingObjective> fos = this.generatedParentForwardingObjectiveMap.get(forwardingObjectiveHash(child)); List<ForwardingObjective> removeFos = new ArrayList<>(); for (ForwardingObjective fo : fos) { removeFos.add(DefaultForwardingObjective.builder() .fromApp(fo.appId()) .makePermanent() .withFlag(fo.flag()) .withPriority(fo.priority()) .withSelector(fo.selector()) .withTreatment(fo.treatment()) .remove()); } return removeFos; }
/** * Builds a forwarding objective from the given selector, treatment and nextId. * * @param selector selector * @param treatment treatment to apply to packet, can be null * @param nextId next objective to point to for forwarding packet * @param add true to create an add objective, false to create a remove * objective * @return forwarding objective */ private ForwardingObjective buildForwardingObjective(TrafficSelector selector, TrafficTreatment treatment, int nextId, boolean add) { DefaultForwardingObjective.Builder fobBuilder = DefaultForwardingObjective.builder(); fobBuilder.withSelector(selector); if (treatment != null) { fobBuilder.withTreatment(treatment); } if (nextId != -1) { fobBuilder.nextStep(nextId); } fobBuilder.fromApp(appId) .withPriority(ACL_PRIORITY) .withFlag(ForwardingObjective.Flag.VERSATILE); return add ? fobBuilder.add() : fobBuilder.remove(); }
/** * Removes flow rules with the supplied information. * * @param flowObjectiveService flow objective service * @param appId application id * @param deviceId device id to remove this flow rule * @param selector traffic selector * @param flag flag * @param priority priority */ public static void removeRule(FlowObjectiveService flowObjectiveService, ApplicationId appId, DeviceId deviceId, TrafficSelector selector, ForwardingObjective.Flag flag, int priority) { ForwardingObjective fo = DefaultForwardingObjective.builder() .withSelector(selector) .withTreatment(DefaultTrafficTreatment.builder().build()) .withFlag(flag) .withPriority(priority) .fromApp(appId) .remove(); flowObjectiveService.forward(deviceId, fo); } }
/** * Removes the flow rules for traffic between VMs in the same Cnode. * * @param deviceId device id on which removed VM was run * @param vmIp ip of the removed VM * @param vni vni which removed VM was belonged */ private void removeFlowRuleForVMsInSameCnode(DeviceId deviceId, Ip4Address vmIp, long vni) { TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); sBuilder.matchEthType(Ethernet.TYPE_IPV4) .matchIPDst(vmIp.toIpPrefix()) .matchTunnelId(vni); ForwardingObjective fo = DefaultForwardingObjective.builder() .withSelector(sBuilder.build()) .withTreatment(DefaultTrafficTreatment.builder().build()) .withFlag(ForwardingObjective.Flag.SPECIFIC) .withPriority(SWITCHING_RULE_PRIORITY) .fromApp(appId) .remove(); flowObjectiveService.forward(deviceId, fo); }
/** * Removes the flow rules between traffic from VMs in different Cnode. * * @param deviceId device id * @param vmIp ip * @param vni vni which removed VM was belonged */ private void removeVxLanFlowRule(DeviceId deviceId, Ip4Address vmIp, long vni) { TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); sBuilder.matchEthType(Ethernet.TYPE_IPV4) .matchTunnelId(vni) .matchIPDst(vmIp.toIpPrefix()); ForwardingObjective fo = DefaultForwardingObjective.builder() .withSelector(sBuilder.build()) .withTreatment(DefaultTrafficTreatment.builder().build()) .withFlag(ForwardingObjective.Flag.SPECIFIC) .withPriority(SWITCHING_RULE_PRIORITY) .fromApp(appId) .remove(); flowObjectiveService.forward(deviceId, fo); }
/** * 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); }
/** * Removes flow rules for tagging tunnelId. * * @param deviceId device id * @param portNumber port number */ private void removeFlowRuleForTunnelTag(DeviceId deviceId, PortNumber portNumber) { TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); sBuilder.matchEthType(Ethernet.TYPE_IPV4) .matchInPort(portNumber); ForwardingObjective fo = DefaultForwardingObjective.builder() .withSelector(sBuilder.build()) .withTreatment(tBuilder.build()) .withPriority(TUNNELTAG_RULE_PRIORITY) .withFlag(ForwardingObjective.Flag.SPECIFIC) .fromApp(appId) .remove(); flowObjectiveService.forward(deviceId, fo); }