/** * 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()); } }
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; }
private ForwardingObjective buildForwardingObjective(TrafficSelector selector, Integer nextId, int priority) { return DefaultForwardingObjective.builder() .withMeta(selector) .withSelector(selector) .nextStep(nextId) .fromApp(appId) .withPriority(priority) .withFlag(ForwardingObjective.Flag.SPECIFIC) .makePermanent() .add(); }
/** * 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()); } } }
@Override public void programTunnelIn(DeviceId deviceId, SegmentationId segmentationId, Iterable<PortNumber> localTunnelPorts, Objective.Operation type) { if (localTunnelPorts == null) { log.info("No tunnel port in device"); return; } Sets.newHashSet(localTunnelPorts).stream().forEach(tp -> { TrafficSelector selector = DefaultTrafficSelector.builder() .matchInPort(tp).add(Criteria.matchTunnelId(Long .parseLong(segmentationId.toString()))) .build(); TrafficTreatment treatment = DefaultTrafficTreatment.builder() .build(); ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment).withSelector(selector) .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) .withPriority(L2_CLASSIFIER_PRIORITY); if (type.equals(Objective.Operation.ADD)) { log.debug("programTunnelIn-->ADD"); flowObjectiveService.forward(deviceId, objective.add()); } else { log.debug("programTunnelIn-->REMOVE"); flowObjectiveService.forward(deviceId, objective.remove()); } }); }
/** * Install a rule for pushing unique global labels to the device. * * @param deviceId device to which flow should be pushed * @param labelId label for the device * @param type type of operation */ private void installNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, Objective.Operation type) { checkNotNull(flowObjectiveService); checkNotNull(appId); TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() .withSelector(selectorBuilder.build()).withTreatment(treatment) .withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent(); if (type.equals(Objective.Operation.ADD)) { flowObjectiveService.forward(deviceId, forwardingObjective.add()); } else { flowObjectiveService.forward(deviceId, forwardingObjective.remove()); } }
.builder().withTreatment(treatment.build()) .withSelector(selector).fromApp(appId).makePermanent() .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY);
@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()); } } }
@Override public void programLocalIn(DeviceId deviceId, SegmentationId segmentationId, PortNumber inPort, MacAddress srcMac, ApplicationId appid, Objective.Operation type) { TrafficSelector selector = DefaultTrafficSelector.builder() .matchInPort(inPort).matchEthSrc(srcMac).build(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.add(Instructions .modTunnelId(Long.parseLong(segmentationId.toString()))); ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment.build()) .withSelector(selector).fromApp(appId).makePermanent() .withFlag(Flag.SPECIFIC).withPriority(L2_CLASSIFIER_PRIORITY); if (type.equals(Objective.Operation.ADD)) { log.debug("programLocalIn-->ADD"); flowObjectiveService.forward(deviceId, objective.add()); } else { log.debug("programLocalIn-->REMOVE"); flowObjectiveService.forward(deviceId, objective.remove()); } }
@Override public void programL3InPortClassifierRules(DeviceId deviceId, PortNumber inPort, MacAddress srcMac, MacAddress dstMac, SegmentationId actionVni, Objective.Operation type) { TrafficSelector selector = DefaultTrafficSelector.builder() .matchInPort(inPort).matchEthSrc(srcMac).matchEthDst(dstMac) .build(); TrafficTreatment treatment = DefaultTrafficTreatment.builder() .setTunnelId(Long.parseLong(actionVni.segmentationId())).build(); ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment).withSelector(selector) .fromApp(appId).withFlag(Flag.SPECIFIC) .withPriority(L3_CLASSIFIER_PRIORITY); if (type.equals(Objective.Operation.ADD)) { log.debug("L3InternalClassifierRules-->ADD"); flowObjectiveService.forward(deviceId, objective.add()); } else { log.debug("L3InternalClassifierRules-->REMOVE"); flowObjectiveService.forward(deviceId, objective.remove()); } }
private void installLocalLabelRule(DeviceId deviceId, LabelResourceId labelId, PortNumber portNum, TunnelId tunnelId, Boolean isBos, Long labelType, Objective.Operation type) { checkNotNull(flowObjectiveService); checkNotNull(appId); TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); selectorBuilder.matchInPort(portNum); selectorBuilder.matchTunnelId(Long.parseLong(tunnelId.id())); selectorBuilder.matchMplsBos(isBos); selectorBuilder.matchMetadata(labelType); TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() .withSelector(selectorBuilder.build()) .withTreatment(treatment) .withFlag(ForwardingObjective.Flag.VERSATILE) .fromApp(appId) .makePermanent(); if (type.equals(Objective.Operation.ADD)) { flowObjectiveService.forward(deviceId, forwardingObjective.add()); } else { flowObjectiveService.forward(deviceId, forwardingObjective.remove()); } } }
/** * 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(); }
private void setFlowRuleForTunnelTag(DeviceId deviceId, Port port, String vni) { TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); sBuilder.matchEthType(Ethernet.TYPE_IPV4) .matchInPort(port.number()); tBuilder.setTunnelId(Long.parseLong(vni)); ForwardingObjective fo = DefaultForwardingObjective.builder() .withSelector(sBuilder.build()) .withTreatment(tBuilder.build()) .withPriority(TUNNELTAG_RULE_PRIORITY) .withFlag(ForwardingObjective.Flag.SPECIFIC) .fromApp(appId) .add(); flowObjectiveService.forward(deviceId, fo); }
public static ForwardingObjective composeOverride(ForwardingObjective fo, int priorityAddend) { return DefaultForwardingObjective.builder() .fromApp(fo.appId()) .makePermanent() .withFlag(fo.flag()) .withPriority(fo.priority() + priorityAddend) .withSelector(fo.selector()) .withTreatment(fo.treatment()) .add(); }
/** * Install a rule for pushing node labels to the device of other nodes. * * @param deviceId device to which flow should be pushed * @param labelId label for the device * @param ipPrefix device for which label is pushed * @param type type of operation * @param bBos is this the end of sync push */ public void advertiseNodeLabelRule(DeviceId deviceId, LabelResourceId labelId, IpPrefix ipPrefix, Objective.Operation type, boolean bBos) { checkNotNull(flowObjectiveService); checkNotNull(appId); TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); selectorBuilder.matchMplsLabel(MplsLabel.mplsLabel(labelId.id().intValue())); selectorBuilder.matchIPSrc(ipPrefix); if (bBos) { selectorBuilder.matchMplsBos(bBos); } TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); ForwardingObjective.Builder forwardingObjective = DefaultForwardingObjective.builder() .withSelector(selectorBuilder.build()).withTreatment(treatment) .withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makePermanent(); if (type.equals(Objective.Operation.ADD)) { flowObjectiveService.forward(deviceId, forwardingObjective.add()); } else { flowObjectiveService.forward(deviceId, forwardingObjective.remove()); } }
@Override public void programL3ExPortClassifierRules(DeviceId deviceId, PortNumber inPort, IpAddress dstIp, Objective.Operation type) { TrafficSelector selector = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4).matchInPort(inPort) .matchIPDst(IpPrefix.valueOf(dstIp, 32)).build(); TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment).withSelector(selector) .fromApp(appId).withFlag(Flag.SPECIFIC) .withPriority(L3_CLASSIFIER_PRIORITY); if (type.equals(Objective.Operation.ADD)) { log.debug("L3ExToInClassifierRules-->ADD"); flowObjectiveService.forward(deviceId, objective.add()); } else { log.debug("L3ExToInClassifierRules-->REMOVE"); flowObjectiveService.forward(deviceId, objective.remove()); } }
@Override public void programRules(DeviceId deviceId, IpAddress dstIp, MacAddress ethSrc, IpAddress ipDst, SegmentationId actionVni, Objective.Operation type) { TrafficSelector selector = DefaultTrafficSelector.builder() .matchEthType(Ethernet.TYPE_IPV4) .matchIPDst(IpPrefix.valueOf(dstIp, PREFIX_LENGTH)).build(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.setEthSrc(ethSrc).setIpDst(ipDst) .setTunnelId(Long.parseLong(actionVni.segmentationId())); ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment.build()) .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC) .withPriority(DNAT_PRIORITY); if (type.equals(Objective.Operation.ADD)) { log.debug("RouteRules-->ADD"); flowObjectiveService.forward(deviceId, objective.add()); } else { log.debug("RouteRules-->REMOVE"); flowObjectiveService.forward(deviceId, objective.remove()); } } }
@Override public void programRouteRules(DeviceId deviceId, SegmentationId l3Vni, IpAddress dstVmIP, SegmentationId dstVni, MacAddress dstVmGwMac, MacAddress dstVmMac, Operation type) { TrafficSelector selector = DefaultTrafficSelector.builder() .matchEthType(IP_TYPE) .matchTunnelId(Long.parseLong(l3Vni.segmentationId())) .matchIPDst(IpPrefix.valueOf(dstVmIP, PREFIX_LENGTH)).build(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.setEthSrc(dstVmGwMac) .setEthDst(dstVmMac) .add(Instructions.modTunnelId(Long.parseLong(dstVni .segmentationId()))); ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment.build()) .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC) .withPriority(L3FWD_PRIORITY); if (type.equals(Objective.Operation.ADD)) { log.debug("RouteRules-->ADD"); flowObjectiveService.forward(deviceId, objective.add()); } else { log.debug("RouteRules-->REMOVE"); flowObjectiveService.forward(deviceId, objective.remove()); } }
private ForwardingObjective.Builder createPeerObjBuilder( int nextId, IpPrefix ipAddresses) { TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); sbuilder.matchEthType(EthType.EtherType.IPV4.ethType().toShort()); sbuilder.matchIPDst(ipAddresses); DefaultForwardingObjective.Builder builder = DefaultForwardingObjective.builder() .withSelector(sbuilder.build()) .fromApp(appId) .withPriority(getPriorityFromPrefix(ipAddresses)) .withFlag(ForwardingObjective.Flag.SPECIFIC); if (nextId != -1) { builder.nextStep(nextId); } return builder; }
@Override public void programArpClassifierRules(DeviceId deviceId, IpAddress dstIp, SegmentationId actionVni, Objective.Operation type) { TrafficSelector selector = DefaultTrafficSelector.builder() .matchEthType(ETH_TYPE.ethType().toShort()) .matchArpTpa(Ip4Address.valueOf(dstIp.toString())) .build(); TrafficTreatment treatment = DefaultTrafficTreatment.builder() .setTunnelId(Long.parseLong(actionVni.segmentationId())) .build(); ForwardingObjective.Builder objective = DefaultForwardingObjective .builder().withTreatment(treatment).withSelector(selector) .fromApp(appId).withFlag(Flag.SPECIFIC) .withPriority(ARP_CLASSIFIER_PRIORITY); if (type.equals(Objective.Operation.ADD)) { log.debug("ArpClassifierRules-->ADD"); flowObjectiveService.forward(deviceId, objective.add()); } else { log.debug("ArpClassifierRules-->REMOVE"); flowObjectiveService.forward(deviceId, objective.remove()); } }