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.SingleDstTreeFlow; |
| 5 | import net.onrc.onos.api.flowmanager.Tree; |
| 6 | import net.onrc.onos.api.newintent.Intent; |
| 7 | import net.onrc.onos.api.newintent.MultiPointToSinglePointIntent; |
| 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.SwitchPort; |
| 14 | import org.junit.Before; |
| 15 | import org.junit.Test; |
| 16 | |
| 17 | import java.util.Arrays; |
| 18 | import java.util.HashSet; |
| 19 | import java.util.List; |
| 20 | |
| 21 | import static org.hamcrest.Matchers.hasItems; |
| 22 | import static org.hamcrest.Matchers.hasSize; |
| 23 | import static org.hamcrest.Matchers.is; |
| 24 | import static org.junit.Assert.assertThat; |
| 25 | |
| 26 | /** |
| 27 | * Suites of test of {@link MultiPointToSinglePointIntentCompiler}. |
| 28 | */ |
| 29 | public class MultiPointToSinglePointIntentCompilerTest extends IntentCompilerTest { |
| 30 | |
| 31 | private MultiPointToSinglePointIntentCompiler sut; |
| 32 | |
| 33 | @Before |
| 34 | public void setUp() { |
| 35 | sut = new MultiPointToSinglePointIntentCompiler( |
| 36 | intentIdGenerator, |
| 37 | flowIdGenerator, |
| 38 | topologyService |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Checks the compilation result. |
| 44 | */ |
| 45 | @Test |
| 46 | public void testCompilation() { |
| 47 | MultiPointToSinglePointIntent intent = new MultiPointToSinglePointIntent( |
| 48 | intentIdGenerator.getNewId(), |
| 49 | new PacketMatchBuilder().build(), |
| 50 | Actions.nullAction(), |
| 51 | new HashSet<>(Arrays.asList( |
| 52 | new SwitchPort(dpid4, port43), |
| 53 | new SwitchPort(dpid2, port23) |
| 54 | )), |
| 55 | new SwitchPort(dpid1, port1h) |
| 56 | ); |
| 57 | List<Intent> compiled = sut.compile(intent); |
| 58 | |
| 59 | assertThat(compiled, hasSize(1)); |
| 60 | |
| 61 | SingleDstTreeFlowIntent lower = (SingleDstTreeFlowIntent) compiled.get(0); |
| 62 | assertTree(lower.getTree()); |
| 63 | } |
| 64 | |
| 65 | private void assertTree(SingleDstTreeFlow actual) { |
| 66 | assertThat(actual.getId(), is(flowId)); |
| 67 | assertThat(actual.getIngressPorts(), hasSize(2)); |
| 68 | assertThat(actual.getIngressPorts(), hasItems(new SwitchPort(dpid4, port43), new SwitchPort(dpid2, port23))); |
| 69 | assertThat(actual.getMatch(), is((Match) new PacketMatchBuilder().build())); |
| 70 | assertThat(actual.getEgressActions(), hasSize(1)); |
| 71 | assertThat(actual.getEgressActions().get(0), is((Action) new OutputAction(port1h))); |
| 72 | |
| 73 | Tree tree = new Tree(); |
| 74 | tree.add(new FlowLink(dpid1, port14, dpid4, port41)); |
| 75 | tree.add(new FlowLink(dpid1, port12, dpid2, port21)); |
| 76 | assertThat(actual.getTree(), is(tree)); |
| 77 | } |
| 78 | } |