blob: 99863d9195193ed7018ec19ed6546e648a5f5fb1 [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.PacketPathFlow;
8import net.onrc.onos.api.flowmanager.Path;
9import net.onrc.onos.api.newintent.IntentId;
10import net.onrc.onos.core.matchaction.action.Action;
11import net.onrc.onos.core.matchaction.match.PacketMatch;
12import net.onrc.onos.core.matchaction.match.PacketMatchBuilder;
13import net.onrc.onos.core.util.SwitchPort;
14import org.junit.Test;
15
16import java.util.Arrays;
17import java.util.Collections;
18
19import static net.onrc.onos.api.flowmanager.FlowState.COMPILED;
20import static net.onrc.onos.api.flowmanager.FlowState.INSTALLED;
21import static net.onrc.onos.api.flowmanager.FlowState.SUBMITTED;
22import static net.onrc.onos.api.flowmanager.FlowState.WITHDRAWING;
23
24/**
25 * Suites of test of {@link PathFlowIntentInstaller}.
26 */
27public class PathFlowIntentInstallerTest {
28 private final FlowId flowId = new FlowId(1);
29 private final IntentId intentId = new IntentId(1);
30 private final PacketMatch match = new PacketMatchBuilder().build();
31 private SwitchPort src = new SwitchPort(1, (short) 1);
32 private SwitchPort dst = new SwitchPort(2, (short) 2);
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 PathFlowIntentInstaller sut =
43 new PathFlowIntentInstaller(flowManager);
44
45 PacketPathFlow flow = createFlow();
46 PathFlowIntent intent = new PathFlowIntent(intentId, flow);
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 PathFlowIntentInstaller sut =
59 new PathFlowIntentInstaller(flowManager);
60
61 PacketPathFlow flow = createFlow();
62 PathFlowIntent intent = new PathFlowIntent(intentId, flow);
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 PathFlowIntentInstaller sut =
75 new PathFlowIntentInstaller(flowManager);
76
77 PacketPathFlow flow = createFlow();
78 PathFlowIntent intent = new PathFlowIntent(intentId, flow);
79
80 sut.remove(intent);
81 }
82
83 private PacketPathFlow createFlow() {
84 return new PacketPathFlow(flowId, match, src.getPortNumber(),
85 new Path(Arrays.asList(new FlowLink(src, dst))),
86 Collections.<Action>emptyList(), 0, 0);
87 }
88}