blob: 6795d722b3301073075d67ebd8b774c812920cf0 [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.SingleDstTreeFlow;
5import net.onrc.onos.api.flowmanager.Tree;
6import net.onrc.onos.api.newintent.Intent;
7import net.onrc.onos.api.newintent.MultiPointToSinglePointIntent;
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.SwitchPort;
14import org.junit.Before;
15import org.junit.Test;
16
17import java.util.Arrays;
18import java.util.HashSet;
19import java.util.List;
20
21import static org.hamcrest.Matchers.hasItems;
22import static org.hamcrest.Matchers.hasSize;
23import static org.hamcrest.Matchers.is;
24import static org.junit.Assert.assertThat;
25
26/**
27 * Suites of test of {@link MultiPointToSinglePointIntentCompiler}.
28 */
29public 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}