Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Sho SHIMIZU | 6c28f83 | 2015-02-20 16:12:19 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.impl.compiler; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 17 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 19 | import org.hamcrest.Matchers; |
Ray Milkey | 40f50b9 | 2014-11-07 13:25:53 -0800 | [diff] [blame] | 20 | import org.junit.Test; |
Sho SHIMIZU | 6d01d3d | 2015-05-08 14:08:36 -0700 | [diff] [blame] | 21 | import org.onlab.util.Bandwidth; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.TestApplicationId; |
| 23 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.net.ConnectPoint; |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 25 | import org.onosproject.net.DeviceId; |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 26 | import org.onosproject.net.FilteredConnectPoint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 27 | import org.onosproject.net.Link; |
Daniele Moro | 3a6e151 | 2017-12-22 12:14:44 +0100 | [diff] [blame] | 28 | import org.onosproject.net.NetTestTools; |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 29 | import org.onosproject.net.PortNumber; |
| 30 | import org.onosproject.net.ResourceGroup; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.net.flow.TrafficSelector; |
| 32 | import org.onosproject.net.flow.TrafficTreatment; |
| 33 | import org.onosproject.net.intent.AbstractIntentTest; |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 34 | import org.onosproject.net.intent.Constraint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import org.onosproject.net.intent.Intent; |
| 36 | import org.onosproject.net.intent.IntentTestsMocks; |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 37 | import org.onosproject.net.intent.Key; |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 38 | import org.onosproject.net.intent.LinkCollectionIntent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 39 | import org.onosproject.net.intent.PointToPointIntent; |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 40 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
Sho SHIMIZU | 6c28f83 | 2015-02-20 16:12:19 -0800 | [diff] [blame] | 41 | import org.onosproject.net.intent.impl.PathNotFoundException; |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 42 | import org.onosproject.net.resource.ContinuousResource; |
| 43 | import org.onosproject.net.resource.MockResourceService; |
| 44 | import org.onosproject.net.resource.ResourceAllocation; |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 45 | import org.onosproject.net.resource.ResourceService; |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 46 | import org.onosproject.net.resource.Resources; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 47 | |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 48 | import java.util.Collections; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 49 | import java.util.List; |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 50 | import java.util.Set; |
Yuta HIGUCHI | 652f27f | 2016-10-31 16:54:30 -0700 | [diff] [blame] | 51 | import java.util.stream.Collectors; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 52 | |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 53 | import static org.hamcrest.CoreMatchers.instanceOf; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 54 | import static org.hamcrest.MatcherAssert.assertThat; |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 55 | import static org.hamcrest.Matchers.*; |
| 56 | import static org.junit.Assert.assertEquals; |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 57 | import static org.junit.Assert.fail; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 58 | import static org.onosproject.net.intent.LinksHaveEntryWithSourceDestinationPairMatcher.linksHasPath; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * Unit tests for the HostToHost intent compiler. |
| 62 | */ |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 63 | public class PointToPointIntentCompilerTest extends AbstractIntentTest { |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 64 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 65 | private static final ApplicationId APPID = new TestApplicationId("foo"); |
| 66 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 67 | private static final String S1 = "s1"; |
| 68 | private static final String S2 = "s2"; |
| 69 | private static final String S3 = "s3"; |
| 70 | private static final String S4 = "s4"; |
| 71 | private static final String S5 = "s5"; |
| 72 | private static final String S6 = "s6"; |
| 73 | private static final String S7 = "s7"; |
| 74 | private static final String S8 = "s8"; |
| 75 | |
| 76 | private static final DeviceId DID_1 = DeviceId.deviceId("of:" + S1); |
| 77 | private static final DeviceId DID_2 = DeviceId.deviceId("of:" + S2); |
| 78 | private static final DeviceId DID_3 = DeviceId.deviceId("of:" + S3); |
| 79 | private static final DeviceId DID_8 = DeviceId.deviceId("of:" + S8); |
| 80 | |
| 81 | private static final PortNumber PORT_1 = PortNumber.portNumber(1); |
| 82 | private static final PortNumber PORT_2 = PortNumber.portNumber(2); |
| 83 | |
| 84 | private static final double BPS_TO_RESERVE = 100.0; |
| 85 | |
| 86 | private static final ContinuousResource RESOURCE_SW1_P1 = |
| 87 | Resources.continuous(DID_1, PORT_1, Bandwidth.class) |
| 88 | .resource(BPS_TO_RESERVE); |
| 89 | private static final ContinuousResource RESOURCE_SW1_P2 = |
| 90 | Resources.continuous(DID_1, PORT_2, Bandwidth.class) |
| 91 | .resource(BPS_TO_RESERVE); |
| 92 | private static final ContinuousResource RESOURCE_SW2_P1 = |
| 93 | Resources.continuous(DID_2, PORT_1, Bandwidth.class) |
| 94 | .resource(BPS_TO_RESERVE); |
| 95 | private static final ContinuousResource RESOURCE_SW2_P2 = |
| 96 | Resources.continuous(DID_2, PORT_2, Bandwidth.class) |
| 97 | .resource(BPS_TO_RESERVE); |
| 98 | private static final ContinuousResource RESOURCE_SW3_P1 = |
| 99 | Resources.continuous(DID_3, PORT_1, Bandwidth.class) |
| 100 | .resource(BPS_TO_RESERVE); |
| 101 | private static final ContinuousResource RESOURCE_SW3_P2 = |
| 102 | Resources.continuous(DID_3, PORT_2, Bandwidth.class) |
| 103 | .resource(BPS_TO_RESERVE); |
| 104 | |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 105 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 106 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 107 | |
| 108 | /** |
| 109 | * Creates a PointToPoint intent based on ingress and egress device Ids. |
| 110 | * |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 111 | * @param ingress the ingress connect point |
| 112 | * @param egress the egress connect point |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 113 | * @return PointToPointIntent for the two devices |
| 114 | */ |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 115 | private PointToPointIntent makeIntent(ConnectPoint ingress, ConnectPoint egress) { |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 116 | return PointToPointIntent.builder() |
| 117 | .appId(APPID) |
| 118 | .selector(selector) |
| 119 | .treatment(treatment) |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 120 | .filteredIngressPoint(new FilteredConnectPoint(ingress)) |
| 121 | .filteredEgressPoint(new FilteredConnectPoint(egress)) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 122 | .build(); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /** |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 126 | * Creates a PointToPoint intent based on ingress and egress deviceIds and |
| 127 | * constraints. |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 128 | * |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 129 | * @param ingress the ingress connect point |
| 130 | * @param egress the egress connect point |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 131 | * @param constraints constraints |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 132 | * @return the PointToPointIntent connecting the two connect points with |
| 133 | * constraints |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 134 | */ |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 135 | private PointToPointIntent makeIntent(ConnectPoint ingress, |
| 136 | ConnectPoint egress, |
| 137 | List<Constraint> constraints) { |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 138 | return PointToPointIntent.builder() |
| 139 | .appId(APPID) |
| 140 | .selector(selector) |
| 141 | .treatment(treatment) |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 142 | .filteredIngressPoint(new FilteredConnectPoint(ingress)) |
| 143 | .filteredEgressPoint(new FilteredConnectPoint(egress)) |
| 144 | .constraints(constraints) |
| 145 | .build(); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Creates a PointToPoint intent based on ingress and egress deviceIds, |
| 150 | * constraints and a resource group. |
| 151 | * |
| 152 | * @param ingress the ingress connect point |
| 153 | * @param egress the egress connect point |
| 154 | * @param constraints constraints |
| 155 | * @param resourceGroup the resource group |
| 156 | * @return the PointToPointIntent connecting the two connect points with |
| 157 | * constraints |
| 158 | */ |
| 159 | private PointToPointIntent makeIntent(ConnectPoint ingress, |
| 160 | ConnectPoint egress, |
| 161 | List<Constraint> constraints, |
| 162 | ResourceGroup resourceGroup) { |
| 163 | return PointToPointIntent.builder() |
| 164 | .appId(APPID) |
| 165 | .resourceGroup(resourceGroup) |
| 166 | .selector(selector) |
| 167 | .treatment(treatment) |
| 168 | .filteredIngressPoint(new FilteredConnectPoint(ingress)) |
| 169 | .filteredEgressPoint(new FilteredConnectPoint(egress)) |
| 170 | .constraints(constraints) |
| 171 | .build(); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Creates a PointToPoint intent based on an intent key, ingress and egress |
| 176 | * deviceIds, constraints and a resource group. |
| 177 | * |
| 178 | * @param key the intent key |
| 179 | * @param ingress the ingress connect point |
| 180 | * @param egress the egress connect point |
| 181 | * @param constraints constraints |
| 182 | * @param resourceGroup the resource group |
| 183 | * @return the PointToPointIntent connecting the two connect points with |
| 184 | * constraints |
| 185 | */ |
| 186 | private PointToPointIntent makeIntent(Key key, |
| 187 | ConnectPoint ingress, |
| 188 | ConnectPoint egress, |
| 189 | List<Constraint> constraints, |
| 190 | ResourceGroup resourceGroup) { |
| 191 | return PointToPointIntent.builder() |
| 192 | .appId(APPID) |
| 193 | .key(key) |
| 194 | .resourceGroup(resourceGroup) |
| 195 | .selector(selector) |
| 196 | .treatment(treatment) |
| 197 | .filteredIngressPoint(new FilteredConnectPoint(ingress)) |
| 198 | .filteredEgressPoint(new FilteredConnectPoint(egress)) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 199 | .constraints(constraints) |
| 200 | .build(); |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
Daniele Moro | 3a6e151 | 2017-12-22 12:14:44 +0100 | [diff] [blame] | 204 | * Creates a PointToPoint intent based on ingress and egress deviceIds |
| 205 | * and a suggested path. |
| 206 | * @param ingress the ingress connect point |
| 207 | * @param egress the egress connect point |
| 208 | * @param suggestedPath the suggested path |
| 209 | * @return the PointToPointIntent connecting the two connect points with |
| 210 | * the suggested path (if available) |
| 211 | */ |
| 212 | private PointToPointIntent makeIntentSuggestedPath(ConnectPoint ingress, |
| 213 | ConnectPoint egress, |
| 214 | List<Link> suggestedPath) { |
| 215 | return PointToPointIntent.builder() |
| 216 | .appId(APPID) |
| 217 | .selector(selector) |
| 218 | .treatment(treatment) |
| 219 | .filteredIngressPoint(new FilteredConnectPoint(ingress)) |
| 220 | .filteredEgressPoint(new FilteredConnectPoint(egress)) |
| 221 | .suggestedPath(suggestedPath) |
| 222 | .build(); |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Creates a PointToPoint intent based on ingress and egress deviceIds and |
| 227 | * constraints with a suggested path. |
| 228 | * |
| 229 | * @param ingress the ingress connect point |
| 230 | * @param egress the egress connect point |
| 231 | * @param suggestedPath the suggested path |
| 232 | * @param constraints constraints |
| 233 | * @return the PointToPointIntent connecting the two connect points with |
| 234 | * constraints and a suggested path |
| 235 | */ |
| 236 | private PointToPointIntent makeIntentSuggestedPath(ConnectPoint ingress, |
| 237 | ConnectPoint egress, |
| 238 | List<Link> suggestedPath, |
| 239 | List<Constraint> constraints) { |
| 240 | return PointToPointIntent.builder() |
| 241 | .appId(APPID) |
| 242 | .selector(selector) |
| 243 | .treatment(treatment) |
| 244 | .filteredIngressPoint(new FilteredConnectPoint(ingress)) |
| 245 | .filteredEgressPoint(new FilteredConnectPoint(egress)) |
| 246 | .constraints(constraints) |
| 247 | .suggestedPath(suggestedPath) |
| 248 | .build(); |
| 249 | } |
| 250 | |
| 251 | /** |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 252 | * Creates a compiler for HostToHost intents. |
| 253 | * |
| 254 | * @param hops string array describing the path hops to use when compiling |
| 255 | * @return HostToHost intent compiler |
| 256 | */ |
| 257 | private PointToPointIntentCompiler makeCompiler(String[] hops) { |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 258 | return makeCompiler(hops, null); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 261 | /** |
Daniele Moro | 3a6e151 | 2017-12-22 12:14:44 +0100 | [diff] [blame] | 262 | * Creates a compiler for PointToPoint intents with suggested paths. |
| 263 | * |
| 264 | * @param paths all the possible paths in the network |
| 265 | * @return PointToPoint intent compiler |
| 266 | */ |
| 267 | private PointToPointIntentCompiler makeCompilerSuggestedPath(String[][] paths) { |
| 268 | final PointToPointIntentCompiler compiler = new PointToPointIntentCompiler(); |
| 269 | compiler.pathService = new IntentTestsMocks.MockMultiplePathService(paths); |
| 270 | compiler.linkService = new IntentTestsMocks.MockLinkService(paths); |
| 271 | return compiler; |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Creates a point to point intent compiler for suggested path case. |
| 276 | * |
| 277 | * @param paths all the possible paths in the network |
| 278 | * @param resourceService service to use for resource allocation requests |
| 279 | * @return point to point compiler |
| 280 | */ |
| 281 | private PointToPointIntentCompiler makeCompilerSuggestedPath(String[][] paths, |
| 282 | ResourceService resourceService) { |
| 283 | final PointToPointIntentCompiler compiler = new PointToPointIntentCompiler(); |
| 284 | compiler.pathService = new IntentTestsMocks.MockMultiplePathService(paths); |
| 285 | compiler.linkService = new IntentTestsMocks.MockLinkService(paths); |
| 286 | |
| 287 | if (resourceService == null) { |
| 288 | compiler.resourceService = new MockResourceService(); |
| 289 | } else { |
| 290 | compiler.resourceService = resourceService; |
| 291 | } |
| 292 | |
| 293 | return compiler; |
| 294 | } |
| 295 | |
| 296 | /** |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 297 | * Creates a point to point intent compiler for a three switch linear |
| 298 | * topology. |
| 299 | * |
| 300 | * @param resourceService service to use for resource allocation requests |
| 301 | * @return point to point compiler |
| 302 | */ |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 303 | private PointToPointIntentCompiler makeCompiler(String[] hops, |
| 304 | ResourceService resourceService) { |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 305 | final PointToPointIntentCompiler compiler = new PointToPointIntentCompiler(); |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 306 | compiler.pathService = new IntentTestsMocks.MockPathService(hops); |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 307 | |
| 308 | if (resourceService == null) { |
| 309 | compiler.resourceService = new MockResourceService(); |
| 310 | } else { |
| 311 | compiler.resourceService = resourceService; |
| 312 | } |
| 313 | |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 314 | return compiler; |
| 315 | } |
| 316 | |
| 317 | /** |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 318 | * Tests a pair of devices in an 8 hop path, forward direction. |
| 319 | */ |
Ray Milkey | 40f50b9 | 2014-11-07 13:25:53 -0800 | [diff] [blame] | 320 | @Test |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 321 | public void testForwardPathCompilation() { |
| 322 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 323 | PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), |
| 324 | new ConnectPoint(DID_8, PORT_1)); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 325 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 326 | String[] hops = {S1, S2, S3, S4, S5, S6, S7, S8}; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 327 | PointToPointIntentCompiler compiler = makeCompiler(hops); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 328 | |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 329 | List<Intent> result = compiler.compile(intent, null); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 330 | assertThat(result, is(Matchers.notNullValue())); |
| 331 | assertThat(result, hasSize(1)); |
| 332 | Intent forwardResultIntent = result.get(0); |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 333 | assertThat(forwardResultIntent instanceof LinkCollectionIntent, is(true)); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 334 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 335 | if (forwardResultIntent instanceof LinkCollectionIntent) { |
| 336 | LinkCollectionIntent forwardIntent = (LinkCollectionIntent) forwardResultIntent; |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 337 | FilteredConnectPoint ingressPoint = new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)); |
| 338 | FilteredConnectPoint egressPoint = new FilteredConnectPoint(new ConnectPoint(DID_8, PORT_1)); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 339 | // 7 links for the hops, plus one default lnk on ingress and egress |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 340 | assertThat(forwardIntent.links(), hasSize(hops.length - 1)); |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 341 | assertThat(forwardIntent.links(), linksHasPath(S1, S2)); |
| 342 | assertThat(forwardIntent.links(), linksHasPath(S2, S3)); |
| 343 | assertThat(forwardIntent.links(), linksHasPath(S3, S4)); |
| 344 | assertThat(forwardIntent.links(), linksHasPath(S4, S5)); |
| 345 | assertThat(forwardIntent.links(), linksHasPath(S5, S6)); |
| 346 | assertThat(forwardIntent.links(), linksHasPath(S6, S7)); |
| 347 | assertThat(forwardIntent.links(), linksHasPath(S7, S8)); |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 348 | assertThat(forwardIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint))); |
| 349 | assertThat(forwardIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint))); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 350 | } |
Yuta HIGUCHI | 652f27f | 2016-10-31 16:54:30 -0700 | [diff] [blame] | 351 | assertThat("key is inherited", forwardResultIntent.key(), is(intent.key())); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Tests a pair of devices in an 8 hop path, forward direction. |
| 356 | */ |
Ray Milkey | 40f50b9 | 2014-11-07 13:25:53 -0800 | [diff] [blame] | 357 | @Test |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 358 | public void testReversePathCompilation() { |
| 359 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 360 | PointToPointIntent intent = makeIntent(new ConnectPoint(DID_8, PORT_1), |
| 361 | new ConnectPoint(DID_1, PORT_1)); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 362 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 363 | String[] hops = {S1, S2, S3, S4, S5, S6, S7, S8}; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 364 | PointToPointIntentCompiler compiler = makeCompiler(hops); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 365 | |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 366 | List<Intent> result = compiler.compile(intent, null); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 367 | assertThat(result, is(Matchers.notNullValue())); |
| 368 | assertThat(result, hasSize(1)); |
| 369 | Intent reverseResultIntent = result.get(0); |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 370 | assertThat(reverseResultIntent instanceof LinkCollectionIntent, is(true)); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 371 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 372 | if (reverseResultIntent instanceof LinkCollectionIntent) { |
| 373 | LinkCollectionIntent reverseLinkCollectionIntent = (LinkCollectionIntent) reverseResultIntent; |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 374 | FilteredConnectPoint egressPoint = new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)); |
| 375 | FilteredConnectPoint ingressPoint = new FilteredConnectPoint(new ConnectPoint(DID_8, PORT_1)); |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 376 | assertThat(reverseLinkCollectionIntent.links(), hasSize(hops.length - 1)); |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 377 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S2, S1)); |
| 378 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S3, S2)); |
| 379 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S4, S3)); |
| 380 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S5, S4)); |
| 381 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S6, S5)); |
| 382 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S7, S6)); |
| 383 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath(S8, S7)); |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 384 | assertThat(reverseLinkCollectionIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint))); |
| 385 | assertThat(reverseLinkCollectionIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint))); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 386 | } |
Yuta HIGUCHI | 652f27f | 2016-10-31 16:54:30 -0700 | [diff] [blame] | 387 | assertThat("key is inherited", reverseResultIntent.key(), is(intent.key())); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 388 | } |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 389 | |
| 390 | /** |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 391 | * Tests the compilation of an intent which designates two different ports |
| 392 | * on the same switch. |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 393 | */ |
| 394 | @Test |
| 395 | public void testSameSwitchDifferentPortsIntentCompilation() { |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 396 | FilteredConnectPoint src = |
| 397 | new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)); |
| 398 | FilteredConnectPoint dst = |
| 399 | new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_2)); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 400 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 401 | PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), |
| 402 | new ConnectPoint(DID_1, PORT_2)); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 403 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 404 | String[] hops = {S1}; |
| 405 | PointToPointIntentCompiler compiler = makeCompiler(hops); |
| 406 | |
| 407 | List<Intent> compiled = compiler.compile(intent, null); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 408 | |
Yuta HIGUCHI | 652f27f | 2016-10-31 16:54:30 -0700 | [diff] [blame] | 409 | assertThat("key is inherited", |
| 410 | compiled.stream().map(Intent::key).collect(Collectors.toList()), |
| 411 | everyItem(is(intent.key()))); |
| 412 | |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 413 | assertThat(compiled, hasSize(1)); |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 414 | assertThat(compiled.get(0), is(instanceOf(LinkCollectionIntent.class))); |
| 415 | LinkCollectionIntent linkCollectionIntent = (LinkCollectionIntent) compiled.get(0); |
| 416 | Set<Link> links = linkCollectionIntent.links(); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 417 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 418 | assertThat(links, hasSize(0)); |
| 419 | assertThat(linkCollectionIntent.filteredIngressPoints(), is(ImmutableSet.of(src))); |
| 420 | assertThat(linkCollectionIntent.filteredEgressPoints(), is(ImmutableSet.of(dst))); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 421 | } |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 422 | |
| 423 | /** |
| 424 | * Tests that requests with sufficient available bandwidth succeed. |
| 425 | */ |
| 426 | @Test |
| 427 | public void testBandwidthConstrainedIntentSuccess() { |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 428 | final double bpsTotal = 1000.0; |
| 429 | final double bpsToReserve = 100.0; |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 430 | |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 431 | final ResourceService resourceService = |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 432 | MockResourceService.makeCustomBandwidthResourceService(bpsTotal); |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 433 | final List<Constraint> constraints = |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 434 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(bpsToReserve))); |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 435 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 436 | final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), |
| 437 | new ConnectPoint(DID_3, PORT_2), |
| 438 | constraints); |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 439 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 440 | String[] hops = {S1, S2, S3}; |
| 441 | final PointToPointIntentCompiler compiler = makeCompiler(hops, |
| 442 | resourceService); |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 443 | |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 444 | final List<Intent> compiledIntents = compiler.compile(intent, null); |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 445 | |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 446 | assertThat(compiledIntents, Matchers.notNullValue()); |
| 447 | assertThat(compiledIntents, hasSize(1)); |
Yuta HIGUCHI | 652f27f | 2016-10-31 16:54:30 -0700 | [diff] [blame] | 448 | |
| 449 | assertThat("key is inherited", |
| 450 | compiledIntents.stream().map(Intent::key).collect(Collectors.toList()), |
| 451 | everyItem(is(intent.key()))); |
| 452 | |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Tests that requests with insufficient available bandwidth fail. |
| 457 | */ |
| 458 | @Test |
| 459 | public void testBandwidthConstrainedIntentFailure() { |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 460 | final double bpsTotal = 10.0; |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 461 | |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 462 | final ResourceService resourceService = |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 463 | MockResourceService.makeCustomBandwidthResourceService(bpsTotal); |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 464 | final List<Constraint> constraints = |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 465 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE))); |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 466 | |
| 467 | try { |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 468 | final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), |
| 469 | new ConnectPoint(DID_3, PORT_2), |
| 470 | constraints); |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 471 | |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 472 | String[] hops = {S1, S2, S3}; |
| 473 | final PointToPointIntentCompiler compiler = makeCompiler(hops, |
| 474 | resourceService); |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 475 | |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 476 | compiler.compile(intent, null); |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 477 | |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 478 | fail("Point to Point compilation with insufficient bandwidth does " |
| 479 | + "not throw exception."); |
| 480 | } catch (PathNotFoundException noPath) { |
| 481 | assertThat(noPath.getMessage(), containsString("No path")); |
| 482 | } |
| 483 | } |
Luca Prete | de10c78 | 2017-01-05 17:23:08 -0800 | [diff] [blame] | 484 | |
| 485 | /** |
| 486 | * Tests if bandwidth resources get allocated correctly. An intent with a |
| 487 | * key only is submitted. |
| 488 | */ |
| 489 | @Test |
| 490 | public void testBandwidthConstrainedIntentAllocation() { |
| 491 | final double bpsTotal = 1000.0; |
| 492 | |
| 493 | String[] hops = {S1, S2, S3}; |
| 494 | |
| 495 | final ResourceService resourceService = |
| 496 | MockResourceService.makeCustomBandwidthResourceService(bpsTotal); |
| 497 | final List<Constraint> constraints = |
| 498 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE))); |
| 499 | |
| 500 | final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), |
| 501 | new ConnectPoint(DID_3, PORT_2), |
| 502 | constraints); |
| 503 | |
| 504 | PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService); |
| 505 | |
| 506 | compiler.compile(intent, null); |
| 507 | |
| 508 | Key intentKey = intent.key(); |
| 509 | |
| 510 | ResourceAllocation rAOne = new ResourceAllocation(RESOURCE_SW1_P1, intentKey); |
| 511 | ResourceAllocation rATwo = new ResourceAllocation(RESOURCE_SW1_P2, intentKey); |
| 512 | ResourceAllocation rAThree = new ResourceAllocation(RESOURCE_SW2_P1, intentKey); |
| 513 | ResourceAllocation rAFour = new ResourceAllocation(RESOURCE_SW2_P2, intentKey); |
| 514 | ResourceAllocation rAFive = new ResourceAllocation(RESOURCE_SW3_P1, intentKey); |
| 515 | ResourceAllocation rASix = new ResourceAllocation(RESOURCE_SW3_P2, intentKey); |
| 516 | |
| 517 | Set<ResourceAllocation> expectedresourceAllocations = |
| 518 | ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix); |
| 519 | |
| 520 | Set<ResourceAllocation> resourceAllocations = |
| 521 | ImmutableSet.copyOf(resourceService.getResourceAllocations(intentKey)); |
| 522 | |
| 523 | assertThat(resourceAllocations, hasSize(6)); |
| 524 | assertEquals(expectedresourceAllocations, resourceAllocations); |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Tests if bandwidth resources get allocated correctly using the resource |
| 529 | * group. An intent with a resource group is submitted. |
| 530 | */ |
| 531 | @Test |
| 532 | public void testRGBandwidthConstrainedIntentAllocation() { |
| 533 | final double bpsTotal = 1000.0; |
| 534 | |
| 535 | ResourceGroup resourceGroup = ResourceGroup.of(100); |
| 536 | |
| 537 | String[] hops = {S1, S2, S3}; |
| 538 | |
| 539 | final ResourceService resourceService = |
| 540 | MockResourceService.makeCustomBandwidthResourceService(bpsTotal); |
| 541 | final List<Constraint> constraints = |
| 542 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE))); |
| 543 | |
| 544 | final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), |
| 545 | new ConnectPoint(DID_3, PORT_2), |
| 546 | constraints, |
| 547 | resourceGroup); |
| 548 | |
| 549 | PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService); |
| 550 | |
| 551 | compiler.compile(intent, null); |
| 552 | |
| 553 | ResourceAllocation rAOne = new ResourceAllocation(RESOURCE_SW1_P1, resourceGroup); |
| 554 | ResourceAllocation rATwo = new ResourceAllocation(RESOURCE_SW1_P2, resourceGroup); |
| 555 | ResourceAllocation rAThree = new ResourceAllocation(RESOURCE_SW2_P1, resourceGroup); |
| 556 | ResourceAllocation rAFour = new ResourceAllocation(RESOURCE_SW2_P2, resourceGroup); |
| 557 | ResourceAllocation rAFive = new ResourceAllocation(RESOURCE_SW3_P1, resourceGroup); |
| 558 | ResourceAllocation rASix = new ResourceAllocation(RESOURCE_SW3_P2, resourceGroup); |
| 559 | |
| 560 | Set<ResourceAllocation> expectedresourceAllocations = |
| 561 | ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix); |
| 562 | |
| 563 | Set<ResourceAllocation> resourceAllocations = |
| 564 | ImmutableSet.copyOf(resourceService.getResourceAllocations(resourceGroup)); |
| 565 | |
| 566 | assertThat(resourceAllocations, hasSize(6)); |
| 567 | assertEquals(expectedresourceAllocations, resourceAllocations); |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Tests that bandwidth resources don't get allocated twice if the intent |
| 572 | * is submitted twice. |
| 573 | */ |
| 574 | @Test |
| 575 | public void testTwoBandwidthConstrainedIntentAllocation() { |
| 576 | final double bpsTotal = 1000.0; |
| 577 | |
| 578 | String[] hops = {S1, S2, S3}; |
| 579 | |
| 580 | final ResourceService resourceService = |
| 581 | MockResourceService.makeCustomBandwidthResourceService(bpsTotal); |
| 582 | final List<Constraint> constraints = |
| 583 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE))); |
| 584 | |
| 585 | final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), |
| 586 | new ConnectPoint(DID_3, PORT_2), |
| 587 | constraints); |
| 588 | |
| 589 | PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService); |
| 590 | |
| 591 | compiler.compile(intent, null); |
| 592 | |
| 593 | // Resubmit the same intent |
| 594 | compiler.compile(intent, null); |
| 595 | |
| 596 | Key intentKey = intent.key(); |
| 597 | |
| 598 | ResourceAllocation rAOne = new ResourceAllocation(RESOURCE_SW1_P1, intentKey); |
| 599 | ResourceAllocation rATwo = new ResourceAllocation(RESOURCE_SW1_P2, intentKey); |
| 600 | ResourceAllocation rAThree = new ResourceAllocation(RESOURCE_SW2_P1, intentKey); |
| 601 | ResourceAllocation rAFour = new ResourceAllocation(RESOURCE_SW2_P2, intentKey); |
| 602 | ResourceAllocation rAFive = new ResourceAllocation(RESOURCE_SW3_P1, intentKey); |
| 603 | ResourceAllocation rASix = new ResourceAllocation(RESOURCE_SW3_P2, intentKey); |
| 604 | |
| 605 | Set<ResourceAllocation> expectedresourceAllocations = |
| 606 | ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix); |
| 607 | |
| 608 | Set<ResourceAllocation> resourceAllocations = |
| 609 | ImmutableSet.copyOf(resourceService.getResourceAllocations(intentKey)); |
| 610 | |
| 611 | assertThat(resourceAllocations, hasSize(6)); |
| 612 | assertEquals(expectedresourceAllocations, resourceAllocations); |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * Tests if bandwidth resources get allocated correctly using groups. |
| 617 | * An intent asks to allocate bandwidth using the intent key as a reference. |
| 618 | * Then, the intent is submitted with the same key and a group set. |
| 619 | * Previous allocations should be released and new resources should be |
| 620 | * allocated using the group. |
| 621 | */ |
| 622 | @Test |
| 623 | public void testKeyRGBandwidthConstrainedIntentAllocation() { |
| 624 | final double bpsTotal = 1000.0; |
| 625 | |
| 626 | String[] hops = {S1, S2, S3}; |
| 627 | |
| 628 | final ResourceService resourceService = |
| 629 | MockResourceService.makeCustomBandwidthResourceService(bpsTotal); |
| 630 | final List<Constraint> constraints = |
| 631 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE))); |
| 632 | |
| 633 | final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), |
| 634 | new ConnectPoint(DID_3, PORT_2), |
| 635 | constraints); |
| 636 | |
| 637 | PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService); |
| 638 | |
| 639 | compiler.compile(intent, null); |
| 640 | |
| 641 | Key intentKey = intent.key(); |
| 642 | |
| 643 | ResourceGroup resourceGroup = ResourceGroup.of(100); |
| 644 | |
| 645 | final PointToPointIntent newIntent = makeIntent(intentKey, |
| 646 | new ConnectPoint(DID_1, PORT_1), |
| 647 | new ConnectPoint(DID_3, PORT_2), |
| 648 | constraints, |
| 649 | resourceGroup); |
| 650 | |
| 651 | compiler.compile(newIntent, null); |
| 652 | |
| 653 | ResourceAllocation rAOne = new ResourceAllocation(RESOURCE_SW1_P1, resourceGroup); |
| 654 | ResourceAllocation rATwo = new ResourceAllocation(RESOURCE_SW1_P2, resourceGroup); |
| 655 | ResourceAllocation rAThree = new ResourceAllocation(RESOURCE_SW2_P1, resourceGroup); |
| 656 | ResourceAllocation rAFour = new ResourceAllocation(RESOURCE_SW2_P2, resourceGroup); |
| 657 | ResourceAllocation rAFive = new ResourceAllocation(RESOURCE_SW3_P1, resourceGroup); |
| 658 | ResourceAllocation rASix = new ResourceAllocation(RESOURCE_SW3_P2, resourceGroup); |
| 659 | |
| 660 | Set<ResourceAllocation> expectedresourceAllocations = |
| 661 | ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix); |
| 662 | |
| 663 | Set<ResourceAllocation> resourceAllocations = |
| 664 | ImmutableSet.copyOf(resourceService.getResourceAllocations(resourceGroup)); |
| 665 | |
| 666 | assertThat(resourceAllocations, hasSize(6)); |
| 667 | assertEquals(expectedresourceAllocations, resourceAllocations); |
| 668 | } |
Daniele Moro | 3a6e151 | 2017-12-22 12:14:44 +0100 | [diff] [blame] | 669 | |
| 670 | /** |
| 671 | * Test if a suggested path is correctly applied. |
| 672 | */ |
| 673 | @Test |
| 674 | public void testSuggestedPath() { |
| 675 | String[] suggestedPathHops = {S1, S3, S4, S5, S6, S8}; |
| 676 | List<Link> suggestedPath = NetTestTools.createPath(suggestedPathHops).links(); |
| 677 | |
| 678 | PointToPointIntent intent = makeIntentSuggestedPath(new ConnectPoint(DID_1, PORT_1), |
| 679 | new ConnectPoint(DID_8, PORT_2), |
| 680 | suggestedPath); |
| 681 | |
| 682 | String[][] paths = {{S1, S2, S8}, suggestedPathHops}; |
| 683 | PointToPointIntentCompiler compiler = makeCompilerSuggestedPath(paths); |
| 684 | |
| 685 | List<Intent> result = compiler.compile(intent, null); |
| 686 | assertThat(result, is(Matchers.notNullValue())); |
| 687 | assertThat(result, hasSize(1)); |
| 688 | Intent resultIntent = result.get(0); |
| 689 | assertThat(resultIntent instanceof LinkCollectionIntent, is(true)); |
| 690 | |
| 691 | if (resultIntent instanceof LinkCollectionIntent) { |
| 692 | LinkCollectionIntent resultLinkIntent = (LinkCollectionIntent) resultIntent; |
| 693 | FilteredConnectPoint ingressPoint = new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)); |
| 694 | FilteredConnectPoint egressPoint = new FilteredConnectPoint(new ConnectPoint(DID_8, PORT_2)); |
| 695 | // 5 links for the hops, plus one default link on ingress and egress |
| 696 | assertThat(resultLinkIntent.links(), hasSize(suggestedPathHops.length - 1)); |
| 697 | assertThat(resultLinkIntent.links(), linksHasPath(S1, S3)); |
| 698 | assertThat(resultLinkIntent.links(), linksHasPath(S3, S4)); |
| 699 | assertThat(resultLinkIntent.links(), linksHasPath(S4, S5)); |
| 700 | assertThat(resultLinkIntent.links(), linksHasPath(S5, S6)); |
| 701 | assertThat(resultLinkIntent.links(), linksHasPath(S6, S8)); |
| 702 | assertThat(resultLinkIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint))); |
| 703 | assertThat(resultLinkIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint))); |
| 704 | } |
| 705 | assertThat("key is inherited", resultIntent.key(), is(intent.key())); |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Test that if a suggested path isn't available it applies another available path. |
| 710 | */ |
| 711 | @Test |
| 712 | public void testSuggestedPathNotAvailable() { |
| 713 | String[] suggestedPathHops = {S1, S3, S8}; |
| 714 | String[] shortestPath = {S1, S2, S8}; |
| 715 | List<Link> suggestedPath = NetTestTools.createPath(suggestedPathHops).links(); |
| 716 | |
| 717 | PointToPointIntent intent = makeIntentSuggestedPath(new ConnectPoint(DID_1, PORT_1), |
| 718 | new ConnectPoint(DID_8, PORT_2), |
| 719 | suggestedPath); |
| 720 | |
| 721 | String[][] path = {shortestPath}; |
| 722 | PointToPointIntentCompiler compiler = makeCompilerSuggestedPath(path); |
| 723 | |
| 724 | List<Intent> result = compiler.compile(intent, null); |
| 725 | assertThat(result, is(Matchers.notNullValue())); |
| 726 | assertThat(result, hasSize(1)); |
| 727 | Intent resultIntent = result.get(0); |
| 728 | assertThat(resultIntent instanceof LinkCollectionIntent, is(true)); |
| 729 | |
| 730 | if (resultIntent instanceof LinkCollectionIntent) { |
| 731 | LinkCollectionIntent resultLinkIntent = (LinkCollectionIntent) resultIntent; |
| 732 | FilteredConnectPoint ingressPoint = new FilteredConnectPoint(new ConnectPoint(DID_1, PORT_1)); |
| 733 | FilteredConnectPoint egressPoint = new FilteredConnectPoint(new ConnectPoint(DID_8, PORT_2)); |
| 734 | // 5 links for the hops, plus one default link on ingress and egress |
| 735 | assertThat(resultLinkIntent.links(), hasSize(shortestPath.length - 1)); |
| 736 | assertThat(resultLinkIntent.links(), linksHasPath(S1, S2)); |
| 737 | assertThat(resultLinkIntent.links(), linksHasPath(S2, S8)); |
| 738 | assertThat(resultLinkIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint))); |
| 739 | assertThat(resultLinkIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint))); |
| 740 | } |
| 741 | assertThat("key is inherited", resultIntent.key(), is(intent.key())); |
| 742 | } |
| 743 | |
| 744 | /** |
| 745 | * Tests that requests with suggested path |
| 746 | * and with sufficient available bandwidth succeed. |
| 747 | */ |
| 748 | @Test |
| 749 | public void testSuggestedPathBandwidthConstrainedIntentSuccess() { |
| 750 | final double bpsTotal = 1000.0; |
| 751 | final double bpsToReserve = 100.0; |
| 752 | |
| 753 | final ResourceService resourceService = |
| 754 | MockResourceService.makeCustomBandwidthResourceService(bpsTotal); |
| 755 | final List<Constraint> constraints = |
| 756 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(bpsToReserve))); |
| 757 | |
| 758 | String[] suggestedPathHops = {S1, S4, S5, S3}; |
| 759 | List<Link> suggestedPath = NetTestTools.createPath(suggestedPathHops).links(); |
| 760 | |
| 761 | final PointToPointIntent intent = makeIntentSuggestedPath( |
| 762 | new ConnectPoint(DID_1, PORT_1), |
| 763 | new ConnectPoint(DID_3, PORT_2), |
| 764 | suggestedPath, |
| 765 | constraints); |
| 766 | |
| 767 | String[][] hops = {{S1, S2, S3}, suggestedPathHops}; |
| 768 | final PointToPointIntentCompiler compiler = makeCompilerSuggestedPath(hops, |
| 769 | resourceService); |
| 770 | |
| 771 | final List<Intent> compiledIntents = compiler.compile(intent, null); |
| 772 | |
| 773 | assertThat(compiledIntents, Matchers.notNullValue()); |
| 774 | assertThat(compiledIntents, hasSize(1)); |
| 775 | |
| 776 | assertThat("key is inherited", |
| 777 | compiledIntents.stream().map(Intent::key).collect(Collectors.toList()), |
| 778 | everyItem(is(intent.key()))); |
| 779 | |
| 780 | } |
| 781 | |
| 782 | /** |
| 783 | * Tests that requests with insufficient available bandwidth fail. |
| 784 | */ |
| 785 | @Test |
| 786 | public void testSuggestedPathBandwidthConstrainedIntentFailure() { |
| 787 | final double bpsTotal = 10.0; |
| 788 | |
| 789 | final ResourceService resourceService = |
| 790 | MockResourceService.makeCustomBandwidthResourceService(bpsTotal); |
| 791 | final List<Constraint> constraints = |
| 792 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE))); |
| 793 | |
| 794 | String[] suggestedPathHops = {S1, S4, S5, S3}; |
| 795 | List<Link> suggestedPath = NetTestTools.createPath(suggestedPathHops).links(); |
| 796 | |
| 797 | try { |
| 798 | final PointToPointIntent intent = makeIntentSuggestedPath( |
| 799 | new ConnectPoint(DID_1, PORT_1), |
| 800 | new ConnectPoint(DID_3, PORT_2), |
| 801 | suggestedPath, |
| 802 | constraints); |
| 803 | |
| 804 | String[][] paths = {{S1, S2, S3}, suggestedPathHops}; |
| 805 | final PointToPointIntentCompiler compiler = makeCompilerSuggestedPath(paths, |
| 806 | resourceService); |
| 807 | |
| 808 | compiler.compile(intent, null); |
| 809 | |
| 810 | fail("Point to Point compilation with insufficient bandwidth does " |
| 811 | + "not throw exception."); |
| 812 | } catch (PathNotFoundException noPath) { |
| 813 | assertThat(noPath.getMessage(), containsString("No path")); |
| 814 | } |
| 815 | } |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 816 | } |