blob: a653bdc9867c52372457deacf1a1c89da8d3d381 [file] [log] [blame]
Sho SHIMIZU913969b2014-08-18 15:04:21 -07001package net.onrc.onos.core.newintent;
2
3import net.onrc.onos.api.flowmanager.FakeFlowManagerService;
4import net.onrc.onos.api.flowmanager.FlowId;
5import net.onrc.onos.api.flowmanager.FlowLink;
6import net.onrc.onos.api.flowmanager.FlowManagerService;
7import net.onrc.onos.api.flowmanager.SingleDstTreeFlow;
8import net.onrc.onos.api.flowmanager.Tree;
9import net.onrc.onos.api.newintent.IntentId;
10import net.onrc.onos.core.matchaction.action.Action;
11import net.onrc.onos.core.matchaction.match.PacketMatchBuilder;
12import net.onrc.onos.core.util.SwitchPort;
13import org.junit.Test;
14
15import java.util.Arrays;
16import java.util.Collections;
17
18import static net.onrc.onos.api.flowmanager.FlowState.COMPILED;
19import static net.onrc.onos.api.flowmanager.FlowState.INSTALLED;
20import static net.onrc.onos.api.flowmanager.FlowState.SUBMITTED;
21import static net.onrc.onos.api.flowmanager.FlowState.WITHDRAWING;
22
23/**
24 * Suites of test of {@link SingleDstTreeFlowIntentInstaller}.
25 */
26public class SingleDstTreeFlowIntentInstallerTest {
27 private final SwitchPort port12 = new SwitchPort(1, (short) 1);
28 private final SwitchPort port13 = new SwitchPort(1, (short) 2);
29 private final SwitchPort port21 = new SwitchPort(2, (short) 2);
30 private final SwitchPort ingress1 = new SwitchPort(2, (short) 100);
31 private final SwitchPort ingress2 = new SwitchPort(3, (short) 101);
32 private final FlowId flowId = new FlowId(1);
33
34 /**
35 * Tests intent installation that the state is changed
36 * to SUBMITTED, COMPILED, then INSTALLED.
37 */
38 @Test
39 public void testNormalStateTransition() {
40 FlowManagerService flowManager =
41 new FakeFlowManagerService(flowId, false, SUBMITTED, COMPILED, INSTALLED);
42 SingleDstTreeFlowIntentInstaller sut =
43 new SingleDstTreeFlowIntentInstaller(flowManager);
44
45 Tree tree = createTree();
46 SingleDstTreeFlowIntent intent = new SingleDstTreeFlowIntent(new IntentId(1), createFlow(tree));
47
48 sut.install(intent);
49 }
50
51 /**
52 * Tests intent installation that addFlow() returns null.
53 */
54 @Test(expected = IntentInstallationException.class)
55 public void testInstallationFails() {
56 FlowManagerService flowManager =
57 new FakeFlowManagerService(flowId, true, SUBMITTED);
58 SingleDstTreeFlowIntentInstaller sut =
59 new SingleDstTreeFlowIntentInstaller(flowManager);
60
61 Tree tree = createTree();
62 SingleDstTreeFlowIntent intent = new SingleDstTreeFlowIntent(new IntentId(1), createFlow(tree));
63
64 sut.install(intent);
65 }
66
67 /**
68 * Tests intent removal that removeFlow() returns null.
69 */
70 @Test(expected = IntentRemovalException.class)
71 public void testRemovalFails() {
72 FlowManagerService flowManager =
73 new FakeFlowManagerService(flowId, true, WITHDRAWING);
74 SingleDstTreeFlowIntentInstaller sut =
75 new SingleDstTreeFlowIntentInstaller(flowManager);
76
77 Tree tree = createTree();
78 SingleDstTreeFlowIntent intent = new SingleDstTreeFlowIntent(new IntentId(1), createFlow(tree));
79
80 sut.remove(intent);
81 }
82
83 private SingleDstTreeFlow createFlow(Tree tree) {
84 return new SingleDstTreeFlow(
85 flowId,
86 new PacketMatchBuilder().build(),
87 Arrays.asList(ingress1, ingress2),
88 tree,
89 Collections.<Action>emptyList()
90 );
91 }
92
93 private Tree createTree() {
94 Tree tree = new Tree();
95 tree.add(new FlowLink(port12, port21));
96 tree.add(new FlowLink(port13, port13));
97 return tree;
98 }
99}