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