FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector)
private FlowRule createFlowRule(OpticalOduIntent intent, DeviceId deviceId, TrafficSelector selector, TrafficTreatment treat) { return DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector) .withTreatment(treat) .withPriority(intent.priority()) .fromApp(appId) .makePermanent() .build(); }
protected List<FlowRule> processEthDstOnlyFilter(EthCriterion ethCriterion, ApplicationId applicationId) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); selector.matchEthType(Ethernet.TYPE_IPV4); selector.matchEthDst(ethCriterion.mac()); treatment.transition(UNICAST_ROUTING_TABLE); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(DEFAULT_PRIORITY) .fromApp(applicationId) .makePermanent() .forTable(TMAC_TABLE).build(); return ImmutableList.<FlowRule>builder().add(rule).build(); }
protected List<FlowRule> processEthDstOnlyFilter(EthCriterion ethCriterion, ApplicationId applicationId, int priority) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); selector.matchEthType(Ethernet.TYPE_IPV4); selector.matchEthDst(ethCriterion.mac()); treatment.transition(TABLE_IPV4_UNICAST); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(priority) .fromApp(applicationId) .makePermanent() .forTable(TABLE_TMAC).build(); return ImmutableList.<FlowRule>builder().add(rule).build(); }
protected List<FlowRule> processMcastEthDstFilter(EthCriterion ethCriterion, ApplicationId applicationId) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); selector.matchEthType(Ethernet.TYPE_IPV4); selector.matchEthDstMasked(ethCriterion.mac(), ethCriterion.mask()); treatment.transition(MULTICAST_ROUTING_TABLE); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(DEFAULT_PRIORITY) .fromApp(applicationId) .makePermanent() .forTable(TMAC_TABLE).build(); return ImmutableList.<FlowRule>builder().add(rule).build(); }
private Collection<FlowRule> processForward(ForwardingObjective fwd) { log.debug("Processing forwarding object"); FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(fwd.selector()) .withTreatment(fwd.treatment()) .withPriority(fwd.priority()) .fromApp(fwd.appId()) .forTable(SOFTWARE_TABLE_START); if (fwd.permanent()) { ruleBuilder.makePermanent(); } else { ruleBuilder.makeTemporary(TIME_OUT); } return Collections.singletonList(ruleBuilder.build()); }
FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(instructions.selector())
@Override protected List<FlowRule> processEthDstOnlyFilter(EthCriterion ethCriterion, ApplicationId applicationId) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); selector.matchEthType(Ethernet.TYPE_IPV4); selector.matchEthDst(ethCriterion.mac()); /* * Note: CpqD switches do not handle MPLS-related operation properly * for a packet with VLAN tag. We pop VLAN here as a workaround. * Side effect: HostService learns redundant hosts with same MAC but * different VLAN. No known side effect on the network reachability. */ treatment.popVlan(); treatment.transition(UNICAST_ROUTING_TABLE); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(DEFAULT_PRIORITY) .fromApp(applicationId) .makePermanent() .forTable(TMAC_TABLE).build(); return ImmutableList.<FlowRule>builder().add(rule).build(); }
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) { log.debug("Processing versatile forwarding objective"); TrafficSelector selector = fwd.selector(); TrafficTreatment tb = fwd.treatment(); FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()) .forDevice(deviceId).withSelector(selector).withTreatment(tb).makeTemporary(TIME_OUT); ruleBuilder.withPriority(fwd.priority()); if (fwd.priority() == 100) { ruleBuilder.forTable(ENCAP_OUTPUT_TABLE); } else if (fwd.priority() == 200) { ruleBuilder.forTable(TUN_SEND_TABLE); } else { ruleBuilder.forTable(CLASSIFIER_TABLE); } if (fwd.permanent()) { ruleBuilder.makePermanent(); } return Collections.singletonList(ruleBuilder.build()); }
private void processClassifierTable(boolean install) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(MAC_TABLE); FlowRule rule; rule = DefaultFlowRule.builder().forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(TABLE_MISS_PRIORITY).fromApp(appId) .makePermanent().forTable(CLASSIFIER_TABLE).build(); applyRules(install, rule); }
private void processArpTable(boolean install) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(MAC_TABLE); FlowRule rule; rule = DefaultFlowRule.builder().forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(TABLE_MISS_PRIORITY).fromApp(appId) .makePermanent().forTable(ARP_TABLE).build(); applyRules(install, rule); }
private Collection<FlowRule> processVersatile(ForwardingObjective forwardingObjective) { log.debug("Processing versatile forwarding objective"); FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(forwardingObjective.selector()) .withTreatment(forwardingObjective.treatment()) .withPriority(forwardingObjective.priority()) .fromApp(forwardingObjective.appId()); if (forwardingObjective.permanent()) { ruleBuilder.makePermanent(); } else { ruleBuilder.makeTemporary(TIME_OUT); } //ARP & DHCP Rule EthTypeCriterion ethCriterion = (EthTypeCriterion) forwardingObjective.selector().getCriterion(Criterion.Type.ETH_TYPE); UdpPortCriterion udpPortCriterion = (UdpPortCriterion) forwardingObjective .selector().getCriterion(Criterion.Type.UDP_DST); if (ethCriterion != null) { if (ethCriterion.ethType().toShort() == Ethernet.TYPE_ARP || ethCriterion.ethType().toShort() == Ethernet.TYPE_LLDP) { ruleBuilder.forTable(VNI_TABLE); return Collections.singletonList(ruleBuilder.build()); } else if (udpPortCriterion != null && udpPortCriterion.udpPort().toInt() == DHCP_SERVER_PORT) { ruleBuilder.forTable(VNI_TABLE); return Collections.singletonList(ruleBuilder.build()); } } return Collections.emptySet(); }
private void processDnatTable(boolean install) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(MAC_TABLE); FlowRule rule; rule = DefaultFlowRule.builder().forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(TABLE_MISS_PRIORITY).fromApp(appId) .makePermanent().forTable(DNAT_TABLE).build(); applyRules(install, rule); }
private void processMacTable(boolean install) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.drop(); FlowRule rule; rule = DefaultFlowRule.builder().forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(TABLE_MISS_PRIORITY).fromApp(appId) .makePermanent().forTable(MAC_TABLE).build(); applyRules(install, rule); }
private void processL3fwdTable(boolean install) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(SNAT_TABLE); FlowRule rule; rule = DefaultFlowRule.builder().forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(TABLE_MISS_PRIORITY).fromApp(appId) .makePermanent().forTable(L3FWD_TABLE).build(); applyRules(install, rule); }
/** * Manufactures flow rule with treatment that is defined by failover * group and traffic selector determined by ingress port of the intent. * * @param intent intent which is being compiled (for appId) * @return a list of a singular flow rule with fast failover * outport traffic treatment */ private List<FlowRule> createFailoverFlowRules(PointToPointIntent intent) { List<FlowRule> flowRules = new ArrayList<>(); ConnectPoint ingress = intent.filteredIngressPoint().connectPoint(); DeviceId deviceId = ingress.deviceId(); // flow rule with failover traffic treatment TrafficSelector trafficSelector = DefaultTrafficSelector.builder(intent.selector()) .matchInPort(ingress.port()).build(); FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); flowRules.add(flowRuleBuilder.withSelector(trafficSelector) .withTreatment(buildFailoverTreatment(deviceId, makeGroupKey(intent.id()))) .fromApp(intent.appId()) .makePermanent() .forDevice(deviceId) .withPriority(PRIORITY) .build()); return flowRules; }
private void processForwardingTable(boolean install) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.drop(); FlowRule flowRule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(DROP_PRIORITY) .fromApp(appId) .makePermanent() .forTable(FORWARDING_TABLE) .build(); applyRules(install, flowRule); }
private void buildAndApplyRule(FilteringObjective filter, TrafficSelector selector, TrafficTreatment treatment) { FlowRule rule = DefaultFlowRule.builder() .fromApp(filter.appId()) .forDevice(deviceId) .forTable(0) .makePermanent() .withSelector(selector) .withTreatment(treatment) .withPriority(filter.priority()) .build(); FlowRuleOperations.Builder opsBuilder = FlowRuleOperations.builder(); switch (filter.type()) { case PERMIT: opsBuilder.add(rule); break; case DENY: opsBuilder.remove(rule); break; default: log.warn("Unknown filter type : {}", filter.type()); fail(filter, ObjectiveError.UNSUPPORTED); } applyFlowRules(opsBuilder, filter); }