Sho SHIMIZU | 913969b | 2014-08-18 15:04:21 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.newintent; |
| 2 | |
| 3 | import net.onrc.onos.api.flowmanager.FakeFlowManagerService; |
| 4 | import net.onrc.onos.api.flowmanager.FlowId; |
| 5 | import net.onrc.onos.api.flowmanager.FlowLink; |
| 6 | import net.onrc.onos.api.flowmanager.FlowManagerService; |
| 7 | import net.onrc.onos.api.flowmanager.PacketPathFlow; |
| 8 | import net.onrc.onos.api.flowmanager.Path; |
| 9 | import net.onrc.onos.api.newintent.IntentId; |
| 10 | import net.onrc.onos.core.matchaction.action.Action; |
| 11 | import net.onrc.onos.core.matchaction.match.PacketMatch; |
| 12 | import net.onrc.onos.core.matchaction.match.PacketMatchBuilder; |
| 13 | import net.onrc.onos.core.util.SwitchPort; |
| 14 | import org.junit.Test; |
| 15 | |
| 16 | import java.util.Arrays; |
| 17 | import java.util.Collections; |
| 18 | |
| 19 | import static net.onrc.onos.api.flowmanager.FlowState.COMPILED; |
| 20 | import static net.onrc.onos.api.flowmanager.FlowState.INSTALLED; |
| 21 | import static net.onrc.onos.api.flowmanager.FlowState.SUBMITTED; |
| 22 | import static net.onrc.onos.api.flowmanager.FlowState.WITHDRAWING; |
| 23 | |
| 24 | /** |
| 25 | * Suites of test of {@link PathFlowIntentInstaller}. |
| 26 | */ |
| 27 | public 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 | } |