Add unit test for optical path intent installer
Change-Id: I01ee56480b91e6d08bd011bf591401a68e30ee27
Showing
2 changed files
with
138 additions
and
1 deletions
| ... | @@ -47,6 +47,8 @@ import org.onosproject.net.flow.criteria.Criterion.Type; | ... | @@ -47,6 +47,8 @@ import org.onosproject.net.flow.criteria.Criterion.Type; |
| 47 | import org.onosproject.net.flow.instructions.Instruction; | 47 | import org.onosproject.net.flow.instructions.Instruction; |
| 48 | import org.onosproject.net.resource.Bandwidth; | 48 | import org.onosproject.net.resource.Bandwidth; |
| 49 | import org.onosproject.net.resource.BandwidthResourceRequest; | 49 | import org.onosproject.net.resource.BandwidthResourceRequest; |
| 50 | +import org.onosproject.net.resource.Lambda; | ||
| 51 | +import org.onosproject.net.resource.LambdaResourceAllocation; | ||
| 50 | import org.onosproject.net.resource.LambdaResourceRequest; | 52 | import org.onosproject.net.resource.LambdaResourceRequest; |
| 51 | import org.onosproject.net.resource.LinkResourceAllocations; | 53 | import org.onosproject.net.resource.LinkResourceAllocations; |
| 52 | import org.onosproject.net.resource.LinkResourceListener; | 54 | import org.onosproject.net.resource.LinkResourceListener; |
| ... | @@ -155,7 +157,9 @@ public class IntentTestsMocks { | ... | @@ -155,7 +157,9 @@ public class IntentTestsMocks { |
| 155 | public static class MockLinkResourceAllocations implements LinkResourceAllocations { | 157 | public static class MockLinkResourceAllocations implements LinkResourceAllocations { |
| 156 | @Override | 158 | @Override |
| 157 | public Set<ResourceAllocation> getResourceAllocation(Link link) { | 159 | public Set<ResourceAllocation> getResourceAllocation(Link link) { |
| 158 | - return ImmutableSet.of(new MplsLabelResourceAllocation(MplsLabel.valueOf(10))); | 160 | + return ImmutableSet.of( |
| 161 | + new LambdaResourceAllocation(Lambda.valueOf(77)), | ||
| 162 | + new MplsLabelResourceAllocation(MplsLabel.valueOf(10))); | ||
| 159 | } | 163 | } |
| 160 | 164 | ||
| 161 | @Override | 165 | @Override | ... | ... |
core/net/src/test/java/org/onosproject/net/intent/impl/installer/OpticalPathIntentInstallerTest.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.net.intent.impl.installer; | ||
| 17 | + | ||
| 18 | +import java.util.Arrays; | ||
| 19 | +import java.util.Collection; | ||
| 20 | +import java.util.List; | ||
| 21 | + | ||
| 22 | +import org.junit.Before; | ||
| 23 | +import org.junit.Test; | ||
| 24 | +import org.onosproject.net.DefaultLink; | ||
| 25 | +import org.onosproject.net.DefaultPath; | ||
| 26 | +import org.onosproject.net.Link; | ||
| 27 | +import org.onosproject.net.flow.FlowRuleOperation; | ||
| 28 | +import org.onosproject.net.intent.IntentTestsMocks; | ||
| 29 | +import org.onosproject.net.intent.OpticalPathIntent; | ||
| 30 | + | ||
| 31 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
| 32 | +import static org.hamcrest.Matchers.hasSize; | ||
| 33 | +import static org.hamcrest.Matchers.notNullValue; | ||
| 34 | +import static org.onosproject.net.Link.Type.DIRECT; | ||
| 35 | +import static org.onosproject.net.NetTestTools.APP_ID; | ||
| 36 | +import static org.onosproject.net.NetTestTools.PID; | ||
| 37 | + | ||
| 38 | +public class OpticalPathIntentInstallerTest extends IntentInstallerTest { | ||
| 39 | + | ||
| 40 | + OpticalPathIntentInstaller installer; | ||
| 41 | + | ||
| 42 | + private final List<Link> links = Arrays.asList( | ||
| 43 | + new DefaultLink(PID, d1p1, d2p0, DIRECT), | ||
| 44 | + new DefaultLink(PID, d2p1, d3p1, DIRECT) | ||
| 45 | + ); | ||
| 46 | + private final int hops = links.size() + 1; | ||
| 47 | + private OpticalPathIntent intent; | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Configures objects used in all the test cases. | ||
| 51 | + */ | ||
| 52 | + @Before | ||
| 53 | + public void localSetUp() { | ||
| 54 | + installer = new OpticalPathIntentInstaller(); | ||
| 55 | + installer.coreService = testCoreService; | ||
| 56 | + installer.intentManager = | ||
| 57 | + new IntentInstallerTest.MockIntentManager(OpticalPathIntent.class); | ||
| 58 | + installer.resourceService = new IntentTestsMocks.MockResourceService(); | ||
| 59 | + | ||
| 60 | + intent = new OpticalPathIntent(APP_ID, | ||
| 61 | + d1p1, | ||
| 62 | + d3p1, | ||
| 63 | + new DefaultPath(PID, links, hops)); | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * Tests activation and deactivation of the installer. | ||
| 68 | + */ | ||
| 69 | + @Test | ||
| 70 | + public void activateDeactivate() { | ||
| 71 | + installer.activate(); | ||
| 72 | + installer.deactivate(); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * Tests installation operation of the optical path intent installer. | ||
| 77 | + */ | ||
| 78 | + @Test | ||
| 79 | + public void install() { | ||
| 80 | + installer.activate(); | ||
| 81 | + | ||
| 82 | + List<Collection<FlowRuleOperation>> operations = | ||
| 83 | + installer.install(intent); | ||
| 84 | + assertThat(operations, notNullValue()); | ||
| 85 | + assertThat(operations, hasSize(1)); | ||
| 86 | + | ||
| 87 | + Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0); | ||
| 88 | + assertThat(flowRuleOpsCollection, hasSize(hops)); | ||
| 89 | + FlowRuleOperation[] flowRuleOps = | ||
| 90 | + flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]); | ||
| 91 | + | ||
| 92 | + FlowRuleOperation op0 = flowRuleOps[0]; | ||
| 93 | + checkFlowOperation(op0, FlowRuleOperation.Type.ADD, d1p1.deviceId()); | ||
| 94 | + | ||
| 95 | + FlowRuleOperation op1 = flowRuleOps[1]; | ||
| 96 | + checkFlowOperation(op1, FlowRuleOperation.Type.ADD, d2p1.deviceId()); | ||
| 97 | + | ||
| 98 | + FlowRuleOperation op2 = flowRuleOps[2]; | ||
| 99 | + checkFlowOperation(op2, FlowRuleOperation.Type.ADD, d3p1.deviceId()); | ||
| 100 | + | ||
| 101 | + installer.deactivate(); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * Checks the uninstall operation of the optical path intent installer. | ||
| 106 | + */ | ||
| 107 | + @Test | ||
| 108 | + public void uninstall() { | ||
| 109 | + installer.activate(); | ||
| 110 | + | ||
| 111 | + List<Collection<FlowRuleOperation>> operations = | ||
| 112 | + installer.uninstall(intent); | ||
| 113 | + assertThat(operations, notNullValue()); | ||
| 114 | + assertThat(operations, hasSize(1)); | ||
| 115 | + | ||
| 116 | + Collection<FlowRuleOperation> flowRuleOpsCollection = operations.get(0); | ||
| 117 | + assertThat(flowRuleOpsCollection, hasSize(hops)); | ||
| 118 | + FlowRuleOperation[] flowRuleOps = | ||
| 119 | + flowRuleOpsCollection.toArray(new FlowRuleOperation[hops]); | ||
| 120 | + | ||
| 121 | + FlowRuleOperation op0 = flowRuleOps[0]; | ||
| 122 | + checkFlowOperation(op0, FlowRuleOperation.Type.REMOVE, d1p1.deviceId()); | ||
| 123 | + | ||
| 124 | + FlowRuleOperation op1 = flowRuleOps[1]; | ||
| 125 | + checkFlowOperation(op1, FlowRuleOperation.Type.REMOVE, d2p1.deviceId()); | ||
| 126 | + | ||
| 127 | + FlowRuleOperation op2 = flowRuleOps[2]; | ||
| 128 | + checkFlowOperation(op2, FlowRuleOperation.Type.REMOVE, d3p1.deviceId()); | ||
| 129 | + | ||
| 130 | + installer.deactivate(); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | +} |
-
Please register or login to post a comment