@Test public void testCompile() { sut.activate(); List<Intent> compiled = sut.compile(intent, Collections.emptyList()); assertThat(compiled, hasSize(1)); Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); assertThat(rules, hasSize(links.size())); FlowRule rule1 = rules.stream() .filter(rule -> rule.deviceId().equals(d1p0.deviceId())) .findFirst() .get(); assertThat(rule1.selector(), is( DefaultTrafficSelector.builder(intent.selector()).matchInPort(d1p1.port()).build() )); assertThat(rule1.treatment(), is( DefaultTrafficTreatment.builder(intent.treatment()).setOutput(d1p1.port()).build() )); assertThat(rule1.priority(), is(intent.priority())); FlowRule rule2 = rules.stream() .filter(rule -> rule.deviceId().equals(d2p0.deviceId())) .findFirst() .get(); assertThat(rule2.selector(), is( DefaultTrafficSelector.builder(intent.selector()).matchInPort(d2p0.port()).build() )); assertThat(rule2.treatment(), is( DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build() )); assertThat(rule2.priority(), is(intent.priority())); FlowRule rule3 = rules.stream() .filter(rule -> rule.deviceId().equals(d3p0.deviceId())) .findFirst() .get(); assertThat(rule3.selector(), is( DefaultTrafficSelector.builder(intent.selector()).matchInPort(d3p1.port()).build() )); assertThat(rule3.treatment(), is( DefaultTrafficTreatment.builder().setOutput(d3p1.port()).build() )); assertThat(rule3.priority(), is(intent.priority())); sut.deactivate(); }
@Override public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) { SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create(); SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); for (Link link : intent.links()) { inputPorts.put(link.dst().deviceId(), link.dst().port()); outputPorts.put(link.src().deviceId(), link.src().port()); } for (ConnectPoint ingressPoint : intent.ingressPoints()) { inputPorts.put(ingressPoint.deviceId(), ingressPoint.port()); } for (ConnectPoint egressPoint : intent.egressPoints()) { outputPorts.put(egressPoint.deviceId(), egressPoint.port()); } List<FlowRule> rules = new ArrayList<>(); for (DeviceId deviceId: outputPorts.keys()) { rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId))); } return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources())); }
LinkCollectionIntentCompiler implements IntentCompiler<LinkCollectionIntent> { @Override public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) { SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create(); SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); for (Link link : intent.links()) { inputPorts.put(link.dst().deviceId(), link.dst().port()); outputPorts.put(link.src().deviceId(), link.src().port()); } for (ConnectPoint ingressPoint : intent.ingressPoints()) { inputPorts.put(ingressPoint.deviceId(), ingressPoint.port()); } for (ConnectPoint egressPoint : intent.egressPoints()) { outputPorts.put(egressPoint.deviceId(), egressPoint.port()); } List<FlowRule> rules = new ArrayList<>(); for (DeviceId deviceId: outputPorts.keys()) { rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId))); } return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources())); } }
LinkCollectionIntentCompiler implements IntentCompiler<LinkCollectionIntent> { @Override public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) { SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create(); SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); for (Link link : intent.links()) { inputPorts.put(link.dst().deviceId(), link.dst().port()); outputPorts.put(link.src().deviceId(), link.src().port()); } for (ConnectPoint ingressPoint : intent.ingressPoints()) { inputPorts.put(ingressPoint.deviceId(), ingressPoint.port()); } for (ConnectPoint egressPoint : intent.egressPoints()) { outputPorts.put(egressPoint.deviceId(), egressPoint.port()); } List<FlowRule> rules = new ArrayList<>(); for (DeviceId deviceId: outputPorts.keys()) { rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId))); } return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources())); }  }
LinkCollectionIntentCompiler implements IntentCompiler<LinkCollectionIntent> { @Override public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) { SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create(); SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); for (Link link : intent.links()) { inputPorts.put(link.dst().deviceId(), link.dst().port()); outputPorts.put(link.src().deviceId(), link.src().port()); } for (ConnectPoint ingressPoint : intent.ingressPoints()) { inputPorts.put(ingressPoint.deviceId(), ingressPoint.port()); } for (ConnectPoint egressPoint : intent.egressPoints()) { outputPorts.put(egressPoint.deviceId(), egressPoint.port()); } List<FlowRule> rules = new ArrayList<>(); for (DeviceId deviceId: outputPorts.keys()) { rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId))); } return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources())); }  @Activate void activate(); @Deactivate void deactivate(); @Override List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable); }
LinkCollectionIntentCompiler implements IntentCompiler<LinkCollectionIntent> { @Override public List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable) { SetMultimap<DeviceId, PortNumber> inputPorts = HashMultimap.create(); SetMultimap<DeviceId, PortNumber> outputPorts = HashMultimap.create(); for (Link link : intent.links()) { inputPorts.put(link.dst().deviceId(), link.dst().port()); outputPorts.put(link.src().deviceId(), link.src().port()); } for (ConnectPoint ingressPoint : intent.ingressPoints()) { inputPorts.put(ingressPoint.deviceId(), ingressPoint.port()); } for (ConnectPoint egressPoint : intent.egressPoints()) { outputPorts.put(egressPoint.deviceId(), egressPoint.port()); } List<FlowRule> rules = new ArrayList<>(); for (DeviceId deviceId: outputPorts.keys()) { rules.addAll(createRules(intent, deviceId, inputPorts.get(deviceId), outputPorts.get(deviceId))); } return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources())); }  @Activate void activate(); @Deactivate void deactivate(); @Override List<Intent> compile(LinkCollectionIntent intent, List<Intent> installable);  }