Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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; |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 25 | import org.onosproject.net.FilteredConnectPoint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import org.onosproject.net.Link; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 27 | import org.onosproject.net.flow.TrafficSelector; |
| 28 | import org.onosproject.net.flow.TrafficTreatment; |
| 29 | import org.onosproject.net.intent.AbstractIntentTest; |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 30 | import org.onosproject.net.intent.Constraint; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 31 | import org.onosproject.net.intent.Intent; |
| 32 | import org.onosproject.net.intent.IntentTestsMocks; |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 33 | import org.onosproject.net.intent.LinkCollectionIntent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.net.intent.PointToPointIntent; |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 35 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
Sho SHIMIZU | 6c28f83 | 2015-02-20 16:12:19 -0800 | [diff] [blame] | 36 | import org.onosproject.net.intent.impl.PathNotFoundException; |
Sho SHIMIZU | e18cb12 | 2016-02-22 21:04:56 -0800 | [diff] [blame] | 37 | import org.onosproject.net.resource.ResourceService; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 38 | |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 39 | import java.util.Collections; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 40 | import java.util.List; |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 41 | import java.util.Set; |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 42 | |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 43 | import static org.hamcrest.CoreMatchers.instanceOf; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 44 | import static org.hamcrest.MatcherAssert.assertThat; |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 45 | import static org.hamcrest.Matchers.containsString; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 46 | import static org.hamcrest.Matchers.hasSize; |
| 47 | import static org.hamcrest.Matchers.is; |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 48 | import static org.junit.Assert.fail; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 49 | import static org.onosproject.net.DeviceId.deviceId; |
| 50 | import static org.onosproject.net.NetTestTools.APP_ID; |
| 51 | import static org.onosproject.net.NetTestTools.connectPoint; |
| 52 | import static org.onosproject.net.PortNumber.portNumber; |
| 53 | import static org.onosproject.net.intent.LinksHaveEntryWithSourceDestinationPairMatcher.linksHasPath; |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Unit tests for the HostToHost intent compiler. |
| 57 | */ |
Ray Milkey | 37f6a38 | 2014-11-25 14:54:42 -0800 | [diff] [blame] | 58 | public class PointToPointIntentCompilerTest extends AbstractIntentTest { |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 59 | |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 60 | private static final ApplicationId APPID = new TestApplicationId("foo"); |
| 61 | |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 62 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 63 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 64 | |
| 65 | /** |
| 66 | * Creates a PointToPoint intent based on ingress and egress device Ids. |
| 67 | * |
| 68 | * @param ingressIdString string for id of ingress device |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 69 | * @param egressIdString string for id of egress device |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 70 | * @return PointToPointIntent for the two devices |
| 71 | */ |
| 72 | private PointToPointIntent makeIntent(String ingressIdString, |
| 73 | String egressIdString) { |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 74 | return PointToPointIntent.builder() |
| 75 | .appId(APPID) |
| 76 | .selector(selector) |
| 77 | .treatment(treatment) |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 78 | .filteredIngressPoint(new FilteredConnectPoint(connectPoint(ingressIdString, 1))) |
| 79 | .filteredEgressPoint(new FilteredConnectPoint(connectPoint(egressIdString, 1))) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 80 | .build(); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /** |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 84 | * Creates a PointToPoint intent based on ingress and egress deviceIds and constraints. |
| 85 | * |
| 86 | * @param ingressIdString string for id of ingress device |
| 87 | * @param egressIdString string for id of egress device |
| 88 | * @param constraints constraints |
| 89 | * @return PointToPointIntent for the two device with constraints |
| 90 | */ |
| 91 | private PointToPointIntent makeIntent(String ingressIdString, |
| 92 | String egressIdString, List<Constraint> constraints) { |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 93 | return PointToPointIntent.builder() |
| 94 | .appId(APPID) |
| 95 | .selector(selector) |
| 96 | .treatment(treatment) |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 97 | .filteredIngressPoint(new FilteredConnectPoint(connectPoint(ingressIdString, 1))) |
| 98 | .filteredEgressPoint(new FilteredConnectPoint(connectPoint(egressIdString, 1))) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 99 | .constraints(constraints) |
| 100 | .build(); |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 104 | * Creates a compiler for HostToHost intents. |
| 105 | * |
| 106 | * @param hops string array describing the path hops to use when compiling |
| 107 | * @return HostToHost intent compiler |
| 108 | */ |
| 109 | private PointToPointIntentCompiler makeCompiler(String[] hops) { |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 110 | PointToPointIntentCompiler compiler = new PointToPointIntentCompiler(); |
Ray Milkey | 40f50b9 | 2014-11-07 13:25:53 -0800 | [diff] [blame] | 111 | compiler.pathService = new IntentTestsMocks.MockPathService(hops); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 112 | return compiler; |
| 113 | } |
| 114 | |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 115 | /** |
| 116 | * Creates a point to point intent compiler for a three switch linear |
| 117 | * topology. |
| 118 | * |
| 119 | * @param resourceService service to use for resource allocation requests |
| 120 | * @return point to point compiler |
| 121 | */ |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 122 | private PointToPointIntentCompiler makeCompiler(String[] hops, ResourceService resourceService) { |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 123 | final PointToPointIntentCompiler compiler = new PointToPointIntentCompiler(); |
| 124 | compiler.resourceService = resourceService; |
| 125 | compiler.pathService = new IntentTestsMocks.MockPathService(hops); |
| 126 | return compiler; |
| 127 | } |
| 128 | |
| 129 | /** |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 130 | * Tests a pair of devices in an 8 hop path, forward direction. |
| 131 | */ |
Ray Milkey | 40f50b9 | 2014-11-07 13:25:53 -0800 | [diff] [blame] | 132 | @Test |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 133 | public void testForwardPathCompilation() { |
| 134 | |
| 135 | PointToPointIntent intent = makeIntent("d1", "d8"); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 136 | |
| 137 | String[] hops = {"d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8"}; |
| 138 | PointToPointIntentCompiler compiler = makeCompiler(hops); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 139 | |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 140 | List<Intent> result = compiler.compile(intent, null); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 141 | assertThat(result, is(Matchers.notNullValue())); |
| 142 | assertThat(result, hasSize(1)); |
| 143 | Intent forwardResultIntent = result.get(0); |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 144 | assertThat(forwardResultIntent instanceof LinkCollectionIntent, is(true)); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 145 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 146 | if (forwardResultIntent instanceof LinkCollectionIntent) { |
| 147 | LinkCollectionIntent forwardIntent = (LinkCollectionIntent) forwardResultIntent; |
| 148 | FilteredConnectPoint ingressPoint = new FilteredConnectPoint(connectPoint("d1", 1)); |
| 149 | FilteredConnectPoint egressPoint = new FilteredConnectPoint(connectPoint("d8", 1)); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 150 | // 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^] | 151 | assertThat(forwardIntent.links(), hasSize(hops.length - 1)); |
| 152 | assertThat(forwardIntent.links(), linksHasPath("d1", "d2")); |
| 153 | assertThat(forwardIntent.links(), linksHasPath("d2", "d3")); |
| 154 | assertThat(forwardIntent.links(), linksHasPath("d3", "d4")); |
| 155 | assertThat(forwardIntent.links(), linksHasPath("d4", "d5")); |
| 156 | assertThat(forwardIntent.links(), linksHasPath("d5", "d6")); |
| 157 | assertThat(forwardIntent.links(), linksHasPath("d6", "d7")); |
| 158 | assertThat(forwardIntent.links(), linksHasPath("d7", "d8")); |
| 159 | assertThat(forwardIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint))); |
| 160 | assertThat(forwardIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint))); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Tests a pair of devices in an 8 hop path, forward direction. |
| 166 | */ |
Ray Milkey | 40f50b9 | 2014-11-07 13:25:53 -0800 | [diff] [blame] | 167 | @Test |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 168 | public void testReversePathCompilation() { |
| 169 | |
| 170 | PointToPointIntent intent = makeIntent("d8", "d1"); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 171 | |
| 172 | String[] hops = {"d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8"}; |
| 173 | PointToPointIntentCompiler compiler = makeCompiler(hops); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 174 | |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 175 | List<Intent> result = compiler.compile(intent, null); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 176 | assertThat(result, is(Matchers.notNullValue())); |
| 177 | assertThat(result, hasSize(1)); |
| 178 | Intent reverseResultIntent = result.get(0); |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 179 | assertThat(reverseResultIntent instanceof LinkCollectionIntent, is(true)); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 180 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 181 | if (reverseResultIntent instanceof LinkCollectionIntent) { |
| 182 | LinkCollectionIntent reverseLinkCollectionIntent = (LinkCollectionIntent) reverseResultIntent; |
| 183 | FilteredConnectPoint egressPoint = new FilteredConnectPoint(connectPoint("d1", 1)); |
| 184 | FilteredConnectPoint ingressPoint = new FilteredConnectPoint(connectPoint("d8", 1)); |
| 185 | assertThat(reverseLinkCollectionIntent.links(), hasSize(hops.length - 1)); |
| 186 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d2", "d1")); |
| 187 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d3", "d2")); |
| 188 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d4", "d3")); |
| 189 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d5", "d4")); |
| 190 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d6", "d5")); |
| 191 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d7", "d6")); |
| 192 | assertThat(reverseLinkCollectionIntent.links(), linksHasPath("d8", "d7")); |
| 193 | assertThat(reverseLinkCollectionIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint))); |
| 194 | assertThat(reverseLinkCollectionIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint))); |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 195 | } |
| 196 | } |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * Tests compilation of the intent which designates two different ports on the same switch. |
| 200 | */ |
| 201 | @Test |
| 202 | public void testSameSwitchDifferentPortsIntentCompilation() { |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 203 | FilteredConnectPoint src = new FilteredConnectPoint(new ConnectPoint(deviceId("1"), portNumber(1))); |
| 204 | FilteredConnectPoint dst = new FilteredConnectPoint(new ConnectPoint(deviceId("1"), portNumber(2))); |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 205 | PointToPointIntent intent = PointToPointIntent.builder() |
| 206 | .appId(APP_ID) |
| 207 | .selector(selector) |
| 208 | .treatment(treatment) |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 209 | .filteredIngressPoint(src) |
| 210 | .filteredEgressPoint(dst) |
Ray Milkey | 3e3ec5f | 2015-03-17 17:00:38 -0700 | [diff] [blame] | 211 | .build(); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 212 | |
| 213 | String[] hops = {"1"}; |
| 214 | PointToPointIntentCompiler sut = makeCompiler(hops); |
| 215 | |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 216 | List<Intent> compiled = sut.compile(intent, null); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 217 | |
| 218 | assertThat(compiled, hasSize(1)); |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 219 | assertThat(compiled.get(0), is(instanceOf(LinkCollectionIntent.class))); |
| 220 | LinkCollectionIntent linkCollectionIntent = (LinkCollectionIntent) compiled.get(0); |
| 221 | Set<Link> links = linkCollectionIntent.links(); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 222 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame^] | 223 | assertThat(links, hasSize(0)); |
| 224 | assertThat(linkCollectionIntent.filteredIngressPoints(), is(ImmutableSet.of(src))); |
| 225 | assertThat(linkCollectionIntent.filteredEgressPoints(), is(ImmutableSet.of(dst))); |
Sho SHIMIZU | de8e6b5 | 2014-11-13 11:23:17 -0800 | [diff] [blame] | 226 | } |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * Tests that requests with sufficient available bandwidth succeed. |
| 230 | */ |
| 231 | @Test |
| 232 | public void testBandwidthConstrainedIntentSuccess() { |
| 233 | |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 234 | final ResourceService resourceService = |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 235 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(1000.0); |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 236 | final List<Constraint> constraints = |
Sho SHIMIZU | a88db49 | 2015-11-23 13:21:04 -0800 | [diff] [blame] | 237 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(100.0))); |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 238 | |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 239 | final PointToPointIntent intent = makeIntent("s1", "s3", constraints); |
| 240 | |
| 241 | String[] hops = {"s1", "s2", "s3"}; |
| 242 | final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService); |
| 243 | |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 244 | final List<Intent> compiledIntents = compiler.compile(intent, null); |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 245 | |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 246 | assertThat(compiledIntents, Matchers.notNullValue()); |
| 247 | assertThat(compiledIntents, hasSize(1)); |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Tests that requests with insufficient available bandwidth fail. |
| 252 | */ |
| 253 | @Test |
| 254 | public void testBandwidthConstrainedIntentFailure() { |
| 255 | |
Sho SHIMIZU | b1681bd | 2016-02-22 12:47:50 -0800 | [diff] [blame] | 256 | final ResourceService resourceService = |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 257 | IntentTestsMocks.MockResourceService.makeBandwidthResourceService(10.0); |
Sho SHIMIZU | 98ffca8 | 2015-05-11 08:39:24 -0700 | [diff] [blame] | 258 | final List<Constraint> constraints = |
Sho SHIMIZU | a88db49 | 2015-11-23 13:21:04 -0800 | [diff] [blame] | 259 | Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(100.0))); |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 260 | |
| 261 | try { |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 262 | final PointToPointIntent intent = makeIntent("s1", "s3", constraints); |
| 263 | |
| 264 | String[] hops = {"s1", "s2", "s3"}; |
| 265 | final PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService); |
| 266 | |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 267 | compiler.compile(intent, null); |
Sho SHIMIZU | b705217 | 2015-02-20 11:09:21 -0800 | [diff] [blame] | 268 | |
Sho SHIMIZU | 0e73880 | 2015-02-20 10:23:28 -0800 | [diff] [blame] | 269 | fail("Point to Point compilation with insufficient bandwidth does " |
| 270 | + "not throw exception."); |
| 271 | } catch (PathNotFoundException noPath) { |
| 272 | assertThat(noPath.getMessage(), containsString("No path")); |
| 273 | } |
| 274 | } |
Ray Milkey | c0fa4db | 2014-10-17 08:49:54 -0700 | [diff] [blame] | 275 | } |