@Test public void testSameDeviceCompilation() { String[] ingress = {"i1", "i2"}; String egress = "i1"; MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); assertThat(intent, is(notNullValue())); final String[] hops = {"i1", "i2"}; MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); assertThat(compiler, is(notNullValue())); List<Intent> result = compiler.compile(intent, null); assertThat(result, is(notNullValue())); assertThat(result, hasSize(1)); Intent resultIntent = result.get(0); assertThat(resultIntent, instanceOf(LinkCollectionIntent.class)); if (resultIntent instanceof LinkCollectionIntent) { LinkCollectionIntent linkIntent = (LinkCollectionIntent) resultIntent; assertThat(linkIntent.links(), hasSize(ingress.length)); assertThat(linkIntent.links(), linksHasPath("i2", "i1")); } }
@Override public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable) { Map<DeviceId, Link> links = new HashMap<>(); ConnectPoint egressPoint = intent.egressPoint(); final boolean allowMissingPaths = intentAllowsPartialFailure(intent); boolean partialTree = false; boolean anyMissingPaths = false; for (ConnectPoint ingressPoint : intent.ingressPoints()) { if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { if (deviceService.isAvailable(ingressPoint.deviceId())) { partialTree = true; } else { anyMissingPaths = true; } continue; } Path path = getPath(ingressPoint, intent.egressPoint()); if (path != null) { partialTree = true; for (Link link : path.links()) { if (links.containsKey(link.dst().deviceId())) { links.put(link.src().deviceId(), link); break; } links.put(link.src().deviceId(), link); } } else { anyMissingPaths = true; } } if (!partialTree) { throw new IntentException("Could not find any paths between ingress and egress points."); } else if (!allowMissingPaths && anyMissingPaths) { throw new IntentException("Missing some paths between ingress and egress ports."); } Intent result = LinkCollectionIntent.builder() .appId(intent.appId()) .selector(intent.selector()) .treatment(intent.treatment()) .links(Sets.newHashSet(links.values())) .ingressPoints(intent.ingressPoints()) .egressPoints(ImmutableSet.of(intent.egressPoint())) .priority(intent.priority()) .constraints(intent.constraints()) .build(); return Collections.singletonList(result); }
MultiPointToSinglePointIntentCompiler implements IntentCompiler<MultiPointToSinglePointIntent> { @Override public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable) { Map<DeviceId, Link> links = new HashMap<>(); ConnectPoint egressPoint = intent.egressPoint(); final boolean allowMissingPaths = intentAllowsPartialFailure(intent); boolean partialTree = false; boolean anyMissingPaths = false; for (ConnectPoint ingressPoint : intent.ingressPoints()) { if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { if (deviceService.isAvailable(ingressPoint.deviceId())) { partialTree = true; } else { anyMissingPaths = true; } continue; } Path path = getPath(ingressPoint, intent.egressPoint()); if (path != null) { partialTree = true; for (Link link : path.links()) { if (links.containsKey(link.dst().deviceId())) { links.put(link.src().deviceId(), link); break; } links.put(link.src().deviceId(), link); } } else { anyMissingPaths = true; } } if (!partialTree) { throw new IntentException("Could not find any paths between ingress and egress points."); } else if (!allowMissingPaths && anyMissingPaths) { throw new IntentException("Missing some paths between ingress and egress ports."); } Intent result = LinkCollectionIntent.builder() .appId(intent.appId()) .selector(intent.selector()) .treatment(intent.treatment()) .links(Sets.newHashSet(links.values())) .ingressPoints(intent.ingressPoints()) .egressPoints(ImmutableSet.of(intent.egressPoint())) .priority(intent.priority()) .constraints(intent.constraints()) .build(); return Collections.singletonList(result); } }
MultiPointToSinglePointIntentCompiler implements IntentCompiler<MultiPointToSinglePointIntent> { @Override public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable) { Map<DeviceId, Link> links = new HashMap<>(); ConnectPoint egressPoint = intent.egressPoint(); final boolean allowMissingPaths = intentAllowsPartialFailure(intent); boolean partialTree = false; boolean anyMissingPaths = false; for (ConnectPoint ingressPoint : intent.ingressPoints()) { if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { if (deviceService.isAvailable(ingressPoint.deviceId())) { partialTree = true; } else { anyMissingPaths = true; } continue; } Path path = getPath(ingressPoint, intent.egressPoint()); if (path != null) { partialTree = true; for (Link link : path.links()) { if (links.containsKey(link.dst().deviceId())) { links.put(link.src().deviceId(), link); break; } links.put(link.src().deviceId(), link); } } else { anyMissingPaths = true; } } if (!partialTree) { throw new IntentException("Could not find any paths between ingress and egress points."); } else if (!allowMissingPaths && anyMissingPaths) { throw new IntentException("Missing some paths between ingress and egress ports."); } Intent result = LinkCollectionIntent.builder() .appId(intent.appId()) .selector(intent.selector()) .treatment(intent.treatment()) .links(Sets.newHashSet(links.values())) .ingressPoints(intent.ingressPoints()) .egressPoints(ImmutableSet.of(intent.egressPoint())) .priority(intent.priority()) .constraints(intent.constraints()) .build(); return Collections.singletonList(result); }  }
MultiPointToSinglePointIntentCompiler implements IntentCompiler<MultiPointToSinglePointIntent> { @Override public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable) { Map<DeviceId, Link> links = new HashMap<>(); ConnectPoint egressPoint = intent.egressPoint(); final boolean allowMissingPaths = intentAllowsPartialFailure(intent); boolean partialTree = false; boolean anyMissingPaths = false; for (ConnectPoint ingressPoint : intent.ingressPoints()) { if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { if (deviceService.isAvailable(ingressPoint.deviceId())) { partialTree = true; } else { anyMissingPaths = true; } continue; } Path path = getPath(ingressPoint, intent.egressPoint()); if (path != null) { partialTree = true; for (Link link : path.links()) { if (links.containsKey(link.dst().deviceId())) { links.put(link.src().deviceId(), link); break; } links.put(link.src().deviceId(), link); } } else { anyMissingPaths = true; } } if (!partialTree) { throw new IntentException("Could not find any paths between ingress and egress points."); } else if (!allowMissingPaths && anyMissingPaths) { throw new IntentException("Missing some paths between ingress and egress ports."); } Intent result = LinkCollectionIntent.builder() .appId(intent.appId()) .selector(intent.selector()) .treatment(intent.treatment()) .links(Sets.newHashSet(links.values())) .ingressPoints(intent.ingressPoints()) .egressPoints(ImmutableSet.of(intent.egressPoint())) .priority(intent.priority()) .constraints(intent.constraints()) .build(); return Collections.singletonList(result); }  @Activate void activate(); @Deactivate void deactivate(); @Override List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable); }
MultiPointToSinglePointIntentCompiler implements IntentCompiler<MultiPointToSinglePointIntent> { @Override public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable) { Map<DeviceId, Link> links = new HashMap<>(); ConnectPoint egressPoint = intent.egressPoint(); final boolean allowMissingPaths = intentAllowsPartialFailure(intent); boolean partialTree = false; boolean anyMissingPaths = false; for (ConnectPoint ingressPoint : intent.ingressPoints()) { if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { if (deviceService.isAvailable(ingressPoint.deviceId())) { partialTree = true; } else { anyMissingPaths = true; } continue; } Path path = getPath(ingressPoint, intent.egressPoint()); if (path != null) { partialTree = true; for (Link link : path.links()) { if (links.containsKey(link.dst().deviceId())) { links.put(link.src().deviceId(), link); break; } links.put(link.src().deviceId(), link); } } else { anyMissingPaths = true; } } if (!partialTree) { throw new IntentException("Could not find any paths between ingress and egress points."); } else if (!allowMissingPaths && anyMissingPaths) { throw new IntentException("Missing some paths between ingress and egress ports."); } Intent result = LinkCollectionIntent.builder() .appId(intent.appId()) .selector(intent.selector()) .treatment(intent.treatment()) .links(Sets.newHashSet(links.values())) .ingressPoints(intent.ingressPoints()) .egressPoints(ImmutableSet.of(intent.egressPoint())) .priority(intent.priority()) .constraints(intent.constraints()) .build(); return Collections.singletonList(result); }  @Activate void activate(); @Deactivate void deactivate(); @Override List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable);  }