blob: 337cf33663d9017a28a5c873b8b91db50221db5c [file] [log] [blame]
Sho SHIMIZUf7b693e2014-08-15 16:17:13 -07001package net.onrc.onos.core.newintent;
2
3import net.onrc.onos.api.flowmanager.FlowLink;
4import net.onrc.onos.api.flowmanager.Path;
5import net.onrc.onos.api.flowmanager.PathFlow;
6import net.onrc.onos.api.newintent.Intent;
7import net.onrc.onos.api.newintent.PathIntent;
8import net.onrc.onos.core.matchaction.action.Action;
9import net.onrc.onos.core.matchaction.action.Actions;
10import net.onrc.onos.core.matchaction.action.OutputAction;
11import net.onrc.onos.core.matchaction.match.Match;
12import net.onrc.onos.core.matchaction.match.PacketMatchBuilder;
13import net.onrc.onos.core.util.LinkTuple;
14import net.onrc.onos.core.util.SwitchPort;
15import org.junit.Before;
16import org.junit.Test;
17
18import java.util.Arrays;
19import java.util.List;
20
21import static org.hamcrest.Matchers.hasSize;
22import static org.hamcrest.Matchers.is;
23import static org.junit.Assert.assertThat;
24
25/**
26 * Suites of test of {@link PathIntentCompiler}.
27 */
28public class PathIntentCompilerTest extends IntentCompilerTest {
29
30 private PathIntentCompiler sut;
31
32 @Before
33 public void setUp() {
34 sut = new PathIntentCompiler(intentIdGenerator, flowIdGenerator);
35 }
36
37 /**
38 * Checks the compilation result.
39 */
40 @Test
41 public void testCompilation() {
42 PathIntent intent = new PathIntent(
43 intentIdGenerator.getNewId(),
44 new PacketMatchBuilder().build(),
45 Actions.nullAction(),
46 new SwitchPort(dpid1, port1h),
47 new SwitchPort(dpid3, port3h),
48 Arrays.asList(
49 new LinkTuple(dpid1, port12, dpid2, port21),
50 new LinkTuple(dpid2, port23, dpid3, port32)
51 ));
52 List<Intent> compiled = sut.compile(intent);
53
54 assertThat(compiled, hasSize(1));
55
56 PathFlowIntent lower = (PathFlowIntent) compiled.get(0);
57 assertPathFlow(lower.getFlow());
58 }
59
60 private void assertPathFlow(PathFlow actual) {
61 assertThat(actual.getId(), is(flowId));
62 assertThat(actual.getIngressPortNumber(), is(port1h));
63 assertThat(actual.getMatch(), is((Match) new PacketMatchBuilder().build()));
64 assertThat(actual.getEgressActions(), hasSize(1));
65 assertThat(actual.getEgressActions().get(0), is((Action) new OutputAction(port3h)));
66
67 Path path = new Path(Arrays.asList(
68 new FlowLink(dpid1, port12, dpid2, port21),
69 new FlowLink(dpid2, port23, dpid3, port32)
70 ));
71 assertThat(actual.getPath(), is(path));
72 }
73}