private Collection<FlowRule> reassemblyFlowRule(FlowRule.Builder ruleBuilder, TrafficTreatment tb, Integer transition, Integer forTable) { if (transition != null) { TrafficTreatment.Builder newTraffic = DefaultTrafficTreatment .builder(); tb.allInstructions().forEach(t -> newTraffic.add(t)); newTraffic.transition(transition); ruleBuilder.withTreatment(newTraffic.build()); } else { ruleBuilder.withTreatment(tb); } if (forTable != null) { ruleBuilder.forTable(forTable); } return Collections.singletonList(ruleBuilder.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 void processIpTable() { //table miss entry FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(ACL_TABLE); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(LOWEST_PRIORITY) .fromApp(driverId) .makePermanent() .forTable(UNICAST_ROUTING_TABLE).build(); ops = ops.add(rule); flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { @Override public void onSuccess(FlowRuleOperations ops) { log.info("Initialized IP table"); } @Override public void onError(FlowRuleOperations ops) { log.info("Failed to initialize unicast IP table"); } })); }
@Override public void createFlow(TrafficSelector originalSelector, TrafficTreatment originalTreatment, ConnectPoint ingress, ConnectPoint egress, int priority, boolean applyTreatment, List<FlowRule> rules, List<DeviceId> devices) { TrafficSelector selector = DefaultTrafficSelector.builder(originalSelector) .matchInPort(ingress.port()) .build(); TrafficTreatment.Builder treatmentBuilder; if (applyTreatment) { treatmentBuilder = DefaultTrafficTreatment.builder(originalTreatment); } else { treatmentBuilder = DefaultTrafficTreatment.builder(); } TrafficTreatment treatment = treatmentBuilder.setOutput(egress.port()).build(); rules.add(DefaultFlowRule.builder() .forDevice(ingress.deviceId()) .withSelector(selector) .withTreatment(treatment) .withPriority(priority) .fromApp(appId) .makePermanent() .build()); } }
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); }
protected void populateTableMissEntry(int tableToAdd, boolean toControllerNow, boolean toControllerWrite, boolean toTable, int tableToSend) { TrafficSelector selector = DefaultTrafficSelector.builder().build(); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); if (toControllerNow) { tBuilder.setOutput(PortNumber.CONTROLLER); } if (toControllerWrite) { tBuilder.deferred().setOutput(PortNumber.CONTROLLER); } if (toTable) { tBuilder.transition(tableToSend); } FlowRule flow = DefaultFlowRule.builder().forDevice(deviceId) .withSelector(selector).withTreatment(tBuilder.build()) .withPriority(0).fromApp(appId).makePermanent() .forTable(tableToAdd).build(); flowRuleService.applyFlowRules(flow); }
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 processAclTable(boolean install) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.wipeDeferred(); treatment.drop(); FlowRule flowRule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(DROP_PRIORITY) .fromApp(appId) .makePermanent() .forTable(ACL_TABLE) .build(); applyRules(install, flowRule); }
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()); }
private void processVniTable(boolean install) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(FORWARDING_TABLE); FlowRule flowRule = DefaultFlowRule.builder() .forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(DROP_PRIORITY) .fromApp(appId) .makePermanent() .forTable(VNI_TABLE) .build(); applyRules(install, flowRule); }
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 processSnatTable(boolean install) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); treatment.transition(MAC_TABLE); treatment.add(Instructions.createOutput(PortNumber.CONTROLLER)); FlowRule rule; rule = DefaultFlowRule.builder().forDevice(deviceId) .withSelector(selector.build()) .withTreatment(treatment.build()) .withPriority(TABLE_MISS_PRIORITY).fromApp(appId) .makePermanent().forTable(SNAT_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); }
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 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 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(); }
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 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); }