@Test public void testForwardPathCompilation() { Optional<MplsLabel> ingressLabel = Optional.of(MplsLabel.mplsLabel(10)); Optional<MplsLabel> egressLabel = Optional.of(MplsLabel.mplsLabel(20)); MplsIntent intent = makeIntent("d1", ingressLabel, "d8", egressLabel); assertThat(intent, is(notNullValue())); String[] hops = {"d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8"}; MplsIntentCompiler compiler = makeCompiler(hops); assertThat(compiler, is(notNullValue())); List<Intent> result = compiler.compile(intent, null); assertThat(result, is(Matchers.notNullValue())); assertThat(result, hasSize(1)); Intent forwardResultIntent = result.get(0); assertThat(forwardResultIntent instanceof MplsPathIntent, is(true)); if (forwardResultIntent instanceof MplsPathIntent) { MplsPathIntent forwardPathIntent = (MplsPathIntent) forwardResultIntent; assertThat(forwardPathIntent.path().links(), hasSize(hops.length + 1)); assertThat(forwardPathIntent.path().links(), linksHasPath("d1", "d2")); assertThat(forwardPathIntent.path().links(), linksHasPath("d2", "d3")); assertThat(forwardPathIntent.path().links(), linksHasPath("d3", "d4")); assertThat(forwardPathIntent.path().links(), linksHasPath("d4", "d5")); assertThat(forwardPathIntent.path().links(), linksHasPath("d5", "d6")); assertThat(forwardPathIntent.path().links(), linksHasPath("d6", "d7")); assertThat(forwardPathIntent.path().links(), linksHasPath("d7", "d8")); assertEquals(forwardPathIntent.egressLabel(), egressLabel); assertEquals(forwardPathIntent.ingressLabel(), ingressLabel); } }
@Override public List<Intent> compile(MplsIntent intent, List<Intent> installable) { ConnectPoint ingressPoint = intent.ingressPoint(); ConnectPoint egressPoint = intent.egressPoint(); if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false)); return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent)); } List<Link> links = new ArrayList<>(); Path path = getPath(intent, ingressPoint.deviceId(), egressPoint.deviceId()); links.add(createEdgeLink(ingressPoint, true)); links.addAll(path.links()); links.add(createEdgeLink(egressPoint, false)); return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), path.annotations()), intent)); }
MplsIntentCompiler extends ConnectivityIntentCompiler<MplsIntent> { @Override public List<Intent> compile(MplsIntent intent, List<Intent> installable) { ConnectPoint ingressPoint = intent.ingressPoint(); ConnectPoint egressPoint = intent.egressPoint(); if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false)); return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent)); } List<Link> links = new ArrayList<>(); Path path = getPath(intent, ingressPoint.deviceId(), egressPoint.deviceId()); links.add(createEdgeLink(ingressPoint, true)); links.addAll(path.links()); links.add(createEdgeLink(egressPoint, false)); return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), path.annotations()), intent)); } }
MplsIntentCompiler extends ConnectivityIntentCompiler<MplsIntent> { @Override public List<Intent> compile(MplsIntent intent, List<Intent> installable) { ConnectPoint ingressPoint = intent.ingressPoint(); ConnectPoint egressPoint = intent.egressPoint(); if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false)); return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent)); } List<Link> links = new ArrayList<>(); Path path = getPath(intent, ingressPoint.deviceId(), egressPoint.deviceId()); links.add(createEdgeLink(ingressPoint, true)); links.addAll(path.links()); links.add(createEdgeLink(egressPoint, false)); return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), path.annotations()), intent)); }  }
MplsIntentCompiler extends ConnectivityIntentCompiler<MplsIntent> { @Override public List<Intent> compile(MplsIntent intent, List<Intent> installable) { ConnectPoint ingressPoint = intent.ingressPoint(); ConnectPoint egressPoint = intent.egressPoint(); if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false)); return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent)); } List<Link> links = new ArrayList<>(); Path path = getPath(intent, ingressPoint.deviceId(), egressPoint.deviceId()); links.add(createEdgeLink(ingressPoint, true)); links.addAll(path.links()); links.add(createEdgeLink(egressPoint, false)); return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), path.annotations()), intent)); }  @Activate void activate(); @Deactivate void deactivate(); @Override List<Intent> compile(MplsIntent intent, List<Intent> installable); }
MplsIntentCompiler extends ConnectivityIntentCompiler<MplsIntent> { @Override public List<Intent> compile(MplsIntent intent, List<Intent> installable) { ConnectPoint ingressPoint = intent.ingressPoint(); ConnectPoint egressPoint = intent.egressPoint(); if (ingressPoint.deviceId().equals(egressPoint.deviceId())) { List<Link> links = asList(createEdgeLink(ingressPoint, true), createEdgeLink(egressPoint, false)); return asList(createPathIntent(new DefaultPath(PID, links, DEFAULT_COST), intent)); } List<Link> links = new ArrayList<>(); Path path = getPath(intent, ingressPoint.deviceId(), egressPoint.deviceId()); links.add(createEdgeLink(ingressPoint, true)); links.addAll(path.links()); links.add(createEdgeLink(egressPoint, false)); return asList(createPathIntent(new DefaultPath(PID, links, path.cost(), path.annotations()), intent)); }  @Activate void activate(); @Deactivate void deactivate(); @Override List<Intent> compile(MplsIntent intent, List<Intent> installable); static final int DEFAULT_COST; }