Sho SHIMIZU | f7b693e | 2014-08-15 16:17:13 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.newintent; |
| 2 | |
| 3 | import net.onrc.onos.api.flowmanager.FlowLink; |
| 4 | import net.onrc.onos.api.flowmanager.Path; |
| 5 | import net.onrc.onos.api.flowmanager.PathFlow; |
| 6 | import net.onrc.onos.api.newintent.Intent; |
| 7 | import net.onrc.onos.api.newintent.PathIntent; |
| 8 | import net.onrc.onos.core.matchaction.action.Action; |
| 9 | import net.onrc.onos.core.matchaction.action.Actions; |
| 10 | import net.onrc.onos.core.matchaction.action.OutputAction; |
| 11 | import net.onrc.onos.core.matchaction.match.Match; |
| 12 | import net.onrc.onos.core.matchaction.match.PacketMatchBuilder; |
| 13 | import net.onrc.onos.core.util.LinkTuple; |
| 14 | import net.onrc.onos.core.util.SwitchPort; |
| 15 | import org.junit.Before; |
| 16 | import org.junit.Test; |
| 17 | |
| 18 | import java.util.Arrays; |
| 19 | import java.util.List; |
| 20 | |
| 21 | import static org.hamcrest.Matchers.hasSize; |
| 22 | import static org.hamcrest.Matchers.is; |
| 23 | import static org.junit.Assert.assertThat; |
| 24 | |
| 25 | /** |
| 26 | * Suites of test of {@link PathIntentCompiler}. |
| 27 | */ |
| 28 | public 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 | } |