Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [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 | */ |
| 16 | package org.onosproject.net.intent.impl.compiler; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableSet; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 19 | import org.hamcrest.core.Is; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 23 | import org.onlab.packet.MacAddress; |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 24 | import org.onlab.packet.VlanId; |
Thomas Vachuska | bdbdd24 | 2016-03-01 01:55:55 -0800 | [diff] [blame] | 25 | import org.onosproject.cfg.ComponentConfigAdapter; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 26 | import org.onosproject.core.CoreService; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 27 | import org.onosproject.net.ConnectPoint; |
| 28 | import org.onosproject.net.DefaultLink; |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 29 | import org.onosproject.net.FilteredConnectPoint; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 30 | import org.onosproject.net.Link; |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 31 | import org.onosproject.net.PortNumber; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 32 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 33 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 34 | import org.onosproject.net.flow.FlowRule; |
| 35 | import org.onosproject.net.flow.TrafficSelector; |
| 36 | import org.onosproject.net.flow.TrafficTreatment; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 37 | import org.onosproject.net.flow.criteria.MplsCriterion; |
| 38 | import org.onosproject.net.flow.criteria.PortCriterion; |
| 39 | import org.onosproject.net.flow.criteria.VlanIdCriterion; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 40 | import org.onosproject.net.intent.FlowRuleIntent; |
| 41 | import org.onosproject.net.intent.Intent; |
| 42 | import org.onosproject.net.intent.IntentExtensionService; |
| 43 | import org.onosproject.net.intent.LinkCollectionIntent; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 44 | |
| 45 | import java.util.Collection; |
| 46 | import java.util.Collections; |
| 47 | import java.util.List; |
| 48 | import java.util.Set; |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 49 | import java.util.stream.Collectors; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 50 | |
| 51 | import static org.easymock.EasyMock.createMock; |
| 52 | import static org.easymock.EasyMock.expect; |
| 53 | import static org.easymock.EasyMock.replay; |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 54 | import static org.hamcrest.CoreMatchers.instanceOf; |
| 55 | import static org.hamcrest.CoreMatchers.notNullValue; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 56 | import static org.hamcrest.MatcherAssert.assertThat; |
| 57 | import static org.hamcrest.Matchers.hasSize; |
| 58 | import static org.hamcrest.Matchers.is; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 59 | import static org.onlab.packet.EthType.EtherType.IPV4; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 60 | import static org.onosproject.net.Link.Type.DIRECT; |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 61 | import static org.onosproject.net.NetTestTools.*; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 62 | import static org.onosproject.net.flow.criteria.Criterion.Type.IN_PORT; |
| 63 | import static org.onosproject.net.flow.criteria.Criterion.Type.MPLS_LABEL; |
| 64 | import static org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID; |
| 65 | import static org.onosproject.net.flow.instructions.L2ModificationInstruction.*; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 66 | |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 67 | public class LinkCollectionIntentCompilerTest extends AbstractLinkCollectionTest { |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 68 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 69 | @Before |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 70 | public void setUp() { |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 71 | sut = new LinkCollectionIntentCompiler(); |
| 72 | coreService = createMock(CoreService.class); |
| 73 | expect(coreService.registerApplication("org.onosproject.net.intent")) |
| 74 | .andReturn(appId); |
| 75 | sut.coreService = coreService; |
| 76 | |
| 77 | Intent.bindIdGenerator(idGenerator); |
| 78 | |
| 79 | intent = LinkCollectionIntent.builder() |
| 80 | .appId(APP_ID) |
| 81 | .selector(selector) |
| 82 | .treatment(treatment) |
| 83 | .links(links) |
| 84 | .ingressPoints(ImmutableSet.of(d1p1)) |
| 85 | .egressPoints(ImmutableSet.of(d3p1)) |
| 86 | .build(); |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 87 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 88 | intentExtensionService = createMock(IntentExtensionService.class); |
| 89 | intentExtensionService.registerCompiler(LinkCollectionIntent.class, sut); |
| 90 | intentExtensionService.unregisterCompiler(LinkCollectionIntent.class); |
Thomas Vachuska | bdbdd24 | 2016-03-01 01:55:55 -0800 | [diff] [blame] | 91 | |
| 92 | registrator = new IntentConfigurableRegistrator(); |
| 93 | registrator.extensionService = intentExtensionService; |
| 94 | registrator.cfgService = new ComponentConfigAdapter(); |
| 95 | registrator.activate(); |
| 96 | |
| 97 | sut.registrator = registrator; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 98 | |
Pier Ventre | 81c47bf | 2016-11-04 07:26:22 -0700 | [diff] [blame] | 99 | LinkCollectionCompiler.optimize = false; |
| 100 | LinkCollectionCompiler.copyTtl = false; |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 101 | |
Pier Ventre | 81c47bf | 2016-11-04 07:26:22 -0700 | [diff] [blame] | 102 | replay(coreService, intentExtensionService); |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 103 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @After |
| 107 | public void tearDown() { |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 108 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 109 | Intent.unbindIdGenerator(idGenerator); |
| 110 | } |
| 111 | |
| 112 | @Test |
| 113 | public void testCompile() { |
| 114 | sut.activate(); |
| 115 | |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 116 | List<Intent> compiled = sut.compile(intent, Collections.emptyList()); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 117 | assertThat(compiled, hasSize(1)); |
| 118 | |
| 119 | Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); |
| 120 | assertThat(rules, hasSize(links.size())); |
| 121 | |
| 122 | // if not found, get() raises an exception |
| 123 | FlowRule rule1 = rules.stream() |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 124 | .filter(rule -> rule.deviceId().equals(d1p10.deviceId())) |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 125 | .findFirst() |
| 126 | .get(); |
| 127 | assertThat(rule1.selector(), is( |
| 128 | DefaultTrafficSelector.builder(intent.selector()).matchInPort(d1p1.port()).build() |
| 129 | )); |
| 130 | assertThat(rule1.treatment(), is( |
| 131 | DefaultTrafficTreatment.builder(intent.treatment()).setOutput(d1p1.port()).build() |
| 132 | )); |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 133 | assertThat(rule1.priority(), is(intent.priority())); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 134 | |
| 135 | FlowRule rule2 = rules.stream() |
| 136 | .filter(rule -> rule.deviceId().equals(d2p0.deviceId())) |
| 137 | .findFirst() |
| 138 | .get(); |
| 139 | assertThat(rule2.selector(), is( |
| 140 | DefaultTrafficSelector.builder(intent.selector()).matchInPort(d2p0.port()).build() |
| 141 | )); |
| 142 | assertThat(rule2.treatment(), is( |
| 143 | DefaultTrafficTreatment.builder().setOutput(d2p1.port()).build() |
| 144 | )); |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 145 | assertThat(rule2.priority(), is(intent.priority())); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 146 | |
| 147 | FlowRule rule3 = rules.stream() |
| 148 | .filter(rule -> rule.deviceId().equals(d3p0.deviceId())) |
| 149 | .findFirst() |
| 150 | .get(); |
| 151 | assertThat(rule3.selector(), is( |
| 152 | DefaultTrafficSelector.builder(intent.selector()).matchInPort(d3p1.port()).build() |
| 153 | )); |
| 154 | assertThat(rule3.treatment(), is( |
| 155 | DefaultTrafficTreatment.builder().setOutput(d3p1.port()).build() |
| 156 | )); |
Brian O'Connor | 8113466 | 2015-06-25 17:23:33 -0400 | [diff] [blame] | 157 | assertThat(rule3.priority(), is(intent.priority())); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 158 | |
| 159 | sut.deactivate(); |
| 160 | } |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 161 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 162 | /** |
| 163 | * Single point to multi point case. |
| 164 | * -1 of1 2-1 of2 2--1 of3 2- |
| 165 | * 3 |
| 166 | * `-1 of4 2- |
| 167 | */ |
| 168 | @Test |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 169 | public void testFilteredConnectPointForSp() { |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 170 | sut.activate(); |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 171 | Set<Link> testLinks = ImmutableSet.of( |
| 172 | DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(), |
| 173 | DefaultLink.builder().providerId(PID).src(of2p2).dst(of3p1).type(DIRECT).build(), |
| 174 | DefaultLink.builder().providerId(PID).src(of2p3).dst(of4p1).type(DIRECT).build() |
| 175 | ); |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 176 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 177 | TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(vlan100Selector) |
| 178 | .matchInPort(PortNumber.portNumber(1)) |
| 179 | .build(); |
| 180 | |
| 181 | TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder() |
| 182 | .setOutput(PortNumber.portNumber(2)) |
| 183 | .build(); |
| 184 | |
| 185 | TrafficSelector expectOf2Selector = DefaultTrafficSelector.builder(vlan100Selector) |
| 186 | .matchInPort(PortNumber.portNumber(1)) |
| 187 | .build(); |
| 188 | |
| 189 | TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder() |
| 190 | .setOutput(PortNumber.portNumber(2)) |
| 191 | .setOutput(PortNumber.portNumber(3)) |
| 192 | .build(); |
| 193 | |
| 194 | TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(vlan100Selector) |
| 195 | .matchInPort(PortNumber.portNumber(1)) |
| 196 | .build(); |
| 197 | |
| 198 | TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder() |
| 199 | .setOutput(PortNumber.portNumber(2)) |
| 200 | .build(); |
| 201 | |
| 202 | TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(vlan100Selector) |
| 203 | .matchInPort(PortNumber.portNumber(1)) |
| 204 | .build(); |
| 205 | |
| 206 | TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder() |
| 207 | .setVlanId(VlanId.vlanId("200")) |
| 208 | .setOutput(PortNumber.portNumber(2)) |
| 209 | .build(); |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 210 | |
| 211 | |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 212 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 213 | Set<FilteredConnectPoint> ingress = ImmutableSet.of( |
| 214 | new FilteredConnectPoint(of1p1, vlan100Selector) |
| 215 | ); |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 216 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 217 | Set<FilteredConnectPoint> egress = ImmutableSet.of( |
| 218 | new FilteredConnectPoint(of3p2, vlan100Selector), |
| 219 | new FilteredConnectPoint(of4p2, vlan200Selector) |
| 220 | ); |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 221 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 222 | intent = LinkCollectionIntent.builder() |
| 223 | .appId(APP_ID) |
| 224 | .filteredIngressPoints(ingress) |
| 225 | .filteredEgressPoints(egress) |
| 226 | .treatment(treatment) |
| 227 | .applyTreatmentOnEgress(true) |
| 228 | .links(testLinks) |
| 229 | .build(); |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 230 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 231 | assertThat(sut, is(notNullValue())); |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 232 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 233 | List<Intent> result = sut.compile(intent, Collections.emptyList()); |
| 234 | |
| 235 | assertThat(result, is(notNullValue())); |
| 236 | assertThat(result, hasSize(1)); |
| 237 | |
| 238 | Intent resultIntent = result.get(0); |
| 239 | assertThat(resultIntent, instanceOf(FlowRuleIntent.class)); |
| 240 | |
| 241 | if (resultIntent instanceof FlowRuleIntent) { |
| 242 | FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent; |
| 243 | |
| 244 | assertThat(frIntent.flowRules(), hasSize(4)); |
| 245 | |
| 246 | List<FlowRule> deviceFlowRules; |
| 247 | FlowRule flowRule; |
| 248 | |
| 249 | // Of1 |
| 250 | deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules()); |
| 251 | assertThat(deviceFlowRules, hasSize(1)); |
| 252 | flowRule = deviceFlowRules.get(0); |
| 253 | assertThat(flowRule.selector(), is(expectOf1Selector)); |
| 254 | assertThat(flowRule.treatment(), is(expectOf1Treatment)); |
| 255 | |
| 256 | // Of2 |
| 257 | deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules()); |
| 258 | assertThat(deviceFlowRules, hasSize(1)); |
| 259 | flowRule = deviceFlowRules.get(0); |
| 260 | assertThat(flowRule.selector(), is(expectOf2Selector)); |
| 261 | assertThat(flowRule.treatment(), is(expectOf2Treatment)); |
| 262 | |
| 263 | // Of3 |
| 264 | deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules()); |
| 265 | assertThat(deviceFlowRules, hasSize(1)); |
| 266 | flowRule = deviceFlowRules.get(0); |
| 267 | assertThat(flowRule.selector(), is(expectOf3Selector)); |
| 268 | assertThat(flowRule.treatment(), is(expectOf3Treatment)); |
| 269 | |
| 270 | // Of4 |
| 271 | deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules()); |
| 272 | assertThat(deviceFlowRules, hasSize(1)); |
| 273 | flowRule = deviceFlowRules.get(0); |
| 274 | assertThat(flowRule.selector(), is(expectOf4Selector)); |
| 275 | assertThat(flowRule.treatment(), is(expectOf4Treatment)); |
| 276 | |
| 277 | } |
| 278 | sut.deactivate(); |
| 279 | } |
| 280 | |
| 281 | /** |
| 282 | * Multi point to single point intent with filtered connect point. |
| 283 | * |
| 284 | * -1 of1 2-1 of2 2-1 of4 2- |
| 285 | * 3 |
| 286 | * -1 of3 2---/ |
| 287 | */ |
| 288 | @Test |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 289 | public void testFilteredConnectPointForMp() { |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 290 | sut.activate(); |
| 291 | Set<Link> testlinks = ImmutableSet.of( |
| 292 | DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(), |
| 293 | DefaultLink.builder().providerId(PID).src(of3p2).dst(of2p3).type(DIRECT).build(), |
| 294 | DefaultLink.builder().providerId(PID).src(of2p2).dst(of4p1).type(DIRECT).build() |
| 295 | ); |
| 296 | |
| 297 | Set<FilteredConnectPoint> ingress = ImmutableSet.of( |
| 298 | new FilteredConnectPoint(of1p1, vlan100Selector), |
| 299 | new FilteredConnectPoint(of3p1, vlan100Selector) |
| 300 | ); |
| 301 | |
| 302 | Set<FilteredConnectPoint> egress = ImmutableSet.of( |
| 303 | new FilteredConnectPoint(of4p2, vlan200Selector) |
| 304 | ); |
| 305 | |
| 306 | TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(vlan100Selector) |
| 307 | .matchInPort(PortNumber.portNumber(1)) |
| 308 | .build(); |
| 309 | |
| 310 | TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder() |
| 311 | .setVlanId(VlanId.vlanId("200")) |
| 312 | .setOutput(PortNumber.portNumber(2)) |
| 313 | .build(); |
| 314 | |
| 315 | TrafficSelector expectOf2Selector1 = DefaultTrafficSelector.builder(vlan200Selector) |
| 316 | .matchInPort(PortNumber.portNumber(1)) |
| 317 | .build(); |
| 318 | |
| 319 | TrafficSelector expectOf2Selector2 = DefaultTrafficSelector.builder(vlan200Selector) |
| 320 | .matchInPort(PortNumber.portNumber(3)) |
| 321 | .build(); |
| 322 | |
| 323 | TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder() |
| 324 | .setOutput(PortNumber.portNumber(2)) |
| 325 | .build(); |
| 326 | |
| 327 | TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(vlan100Selector) |
| 328 | .matchInPort(PortNumber.portNumber(1)) |
| 329 | .build(); |
| 330 | |
| 331 | TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder() |
| 332 | .setVlanId(VlanId.vlanId("200")) |
| 333 | .setOutput(PortNumber.portNumber(2)) |
| 334 | .build(); |
| 335 | |
| 336 | TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(vlan100Selector) |
| 337 | .matchInPort(PortNumber.portNumber(1)) |
| 338 | .matchVlanId(VlanId.vlanId("200")) |
| 339 | .build(); |
| 340 | |
| 341 | TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder() |
| 342 | .setOutput(PortNumber.portNumber(2)) |
| 343 | .build(); |
| 344 | |
| 345 | intent = LinkCollectionIntent.builder() |
| 346 | .appId(APP_ID) |
| 347 | .filteredIngressPoints(ingress) |
| 348 | .filteredEgressPoints(egress) |
| 349 | .treatment(treatment) |
| 350 | .links(testlinks) |
| 351 | .build(); |
| 352 | |
| 353 | List<Intent> result = sut.compile(intent, Collections.emptyList()); |
| 354 | |
| 355 | assertThat(result, is(notNullValue())); |
| 356 | assertThat(result, hasSize(1)); |
| 357 | |
| 358 | Intent resultIntent = result.get(0); |
| 359 | assertThat(resultIntent, instanceOf(FlowRuleIntent.class)); |
| 360 | |
| 361 | if (resultIntent instanceof FlowRuleIntent) { |
| 362 | FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent; |
| 363 | assertThat(frIntent.flowRules(), hasSize(5)); |
| 364 | |
| 365 | List<FlowRule> deviceFlowRules; |
| 366 | FlowRule flowRule; |
| 367 | |
| 368 | // Of1 |
| 369 | deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules()); |
| 370 | assertThat(deviceFlowRules, hasSize(1)); |
| 371 | flowRule = deviceFlowRules.get(0); |
| 372 | assertThat(flowRule.selector(), is(expectOf1Selector)); |
| 373 | assertThat(flowRule.treatment(), is(expectOf1Treatment)); |
| 374 | |
| 375 | // Of2 (has 2 flows) |
| 376 | deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules()); |
| 377 | assertThat(deviceFlowRules, hasSize(2)); |
| 378 | flowRule = deviceFlowRules.get(0); |
| 379 | assertThat(flowRule.selector(), is(expectOf2Selector1)); |
| 380 | assertThat(flowRule.treatment(), is(expectOf2Treatment)); |
| 381 | flowRule = deviceFlowRules.get(1); |
| 382 | assertThat(flowRule.selector(), is(expectOf2Selector2)); |
| 383 | assertThat(flowRule.treatment(), is(expectOf2Treatment)); |
| 384 | |
| 385 | // Of3 |
| 386 | deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules()); |
| 387 | assertThat(deviceFlowRules, hasSize(1)); |
| 388 | flowRule = deviceFlowRules.get(0); |
| 389 | assertThat(flowRule.selector(), is(expectOf3Selector)); |
| 390 | assertThat(flowRule.treatment(), is(expectOf3Treatment)); |
| 391 | |
| 392 | // Of4 |
| 393 | deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules()); |
| 394 | assertThat(deviceFlowRules, hasSize(1)); |
| 395 | flowRule = deviceFlowRules.get(0); |
| 396 | assertThat(flowRule.selector(), is(expectOf4Selector)); |
| 397 | assertThat(flowRule.treatment(), is(expectOf4Treatment)); |
| 398 | } |
Pier Ventre | 647138f | 2016-08-26 17:32:44 -0700 | [diff] [blame] | 399 | |
| 400 | sut.deactivate(); |
| 401 | } |
| 402 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 403 | /** |
| 404 | * Single point to multi point without filtered connect point case. |
| 405 | * -1 of1 2-1 of2 2--1 of3 2- |
| 406 | * 3 |
| 407 | * `-1 of4 2- |
| 408 | */ |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 409 | @Test |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 410 | public void nonTrivialTranslationForSp() { |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 411 | sut.activate(); |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 412 | Set<Link> testLinks = ImmutableSet.of( |
| 413 | DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(), |
| 414 | DefaultLink.builder().providerId(PID).src(of2p2).dst(of3p1).type(DIRECT).build(), |
| 415 | DefaultLink.builder().providerId(PID).src(of2p3).dst(of4p1).type(DIRECT).build() |
| 416 | ); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 417 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 418 | TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(ipPrefixSelector) |
| 419 | .matchInPort(PortNumber.portNumber(1)) |
| 420 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 421 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 422 | TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder() |
| 423 | .setOutput(PortNumber.portNumber(2)) |
| 424 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 425 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 426 | TrafficSelector expectOf2Selector = DefaultTrafficSelector.builder(ipPrefixSelector) |
| 427 | .matchInPort(PortNumber.portNumber(1)) |
| 428 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 429 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 430 | TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder() |
| 431 | .setOutput(PortNumber.portNumber(2)) |
| 432 | .setOutput(PortNumber.portNumber(3)) |
| 433 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 434 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 435 | TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(ipPrefixSelector) |
| 436 | .matchInPort(PortNumber.portNumber(1)) |
| 437 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 438 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 439 | TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder(ethDstTreatment) |
| 440 | .setOutput(PortNumber.portNumber(2)) |
| 441 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 442 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 443 | TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(ipPrefixSelector) |
| 444 | .matchInPort(PortNumber.portNumber(1)) |
| 445 | .build(); |
| 446 | |
| 447 | TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder(ethDstTreatment) |
| 448 | .setOutput(PortNumber.portNumber(2)) |
| 449 | .build(); |
| 450 | |
| 451 | |
| 452 | |
| 453 | Set<ConnectPoint> ingress = ImmutableSet.of( |
| 454 | of1p1 |
| 455 | ); |
| 456 | |
| 457 | Set<ConnectPoint> egress = ImmutableSet.of( |
| 458 | of3p2, |
| 459 | of4p2 |
| 460 | ); |
| 461 | |
| 462 | intent = LinkCollectionIntent.builder() |
| 463 | .appId(APP_ID) |
| 464 | .selector(ipPrefixSelector) |
| 465 | .treatment(ethDstTreatment) |
| 466 | .ingressPoints(ingress) |
| 467 | .egressPoints(egress) |
| 468 | .applyTreatmentOnEgress(true) |
| 469 | .links(testLinks) |
| 470 | .build(); |
| 471 | |
| 472 | assertThat(sut, is(notNullValue())); |
| 473 | |
| 474 | List<Intent> result = sut.compile(intent, Collections.emptyList()); |
| 475 | |
| 476 | assertThat(result, is(notNullValue())); |
| 477 | assertThat(result, hasSize(1)); |
| 478 | |
| 479 | Intent resultIntent = result.get(0); |
| 480 | assertThat(resultIntent, instanceOf(FlowRuleIntent.class)); |
| 481 | |
| 482 | if (resultIntent instanceof FlowRuleIntent) { |
| 483 | FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent; |
| 484 | |
| 485 | assertThat(frIntent.flowRules(), hasSize(4)); |
| 486 | |
| 487 | List<FlowRule> deviceFlowRules; |
| 488 | FlowRule flowRule; |
| 489 | |
| 490 | // Of1 |
| 491 | deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules()); |
| 492 | assertThat(deviceFlowRules, hasSize(1)); |
| 493 | flowRule = deviceFlowRules.get(0); |
| 494 | assertThat(flowRule.selector(), is(expectOf1Selector)); |
| 495 | assertThat(flowRule.treatment(), is(expectOf1Treatment)); |
| 496 | |
| 497 | // Of2 |
| 498 | deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules()); |
| 499 | assertThat(deviceFlowRules, hasSize(1)); |
| 500 | flowRule = deviceFlowRules.get(0); |
| 501 | assertThat(flowRule.selector(), is(expectOf2Selector)); |
| 502 | assertThat(flowRule.treatment(), is(expectOf2Treatment)); |
| 503 | |
| 504 | // Of3 |
| 505 | deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules()); |
| 506 | assertThat(deviceFlowRules, hasSize(1)); |
| 507 | flowRule = deviceFlowRules.get(0); |
| 508 | assertThat(flowRule.selector(), is(expectOf3Selector)); |
| 509 | assertThat(flowRule.treatment(), is(expectOf3Treatment)); |
| 510 | |
| 511 | // Of4 |
| 512 | deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules()); |
| 513 | assertThat(deviceFlowRules, hasSize(1)); |
| 514 | flowRule = deviceFlowRules.get(0); |
| 515 | assertThat(flowRule.selector(), is(expectOf4Selector)); |
| 516 | assertThat(flowRule.treatment(), is(expectOf4Treatment)); |
| 517 | |
| 518 | } |
| 519 | sut.deactivate(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 522 | /** |
| 523 | * Multi point to single point intent without filtered connect point. |
| 524 | * |
| 525 | * -1 of1 2-1 of2 2-1 of4 2- |
| 526 | * 3 |
| 527 | * -1 of3 2---/ |
| 528 | */ |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 529 | @Test |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 530 | public void nonTrivialTranslationForMp() { |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 531 | sut.activate(); |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 532 | Set<Link> testlinks = ImmutableSet.of( |
| 533 | DefaultLink.builder().providerId(PID).src(of1p2).dst(of2p1).type(DIRECT).build(), |
| 534 | DefaultLink.builder().providerId(PID).src(of3p2).dst(of2p3).type(DIRECT).build(), |
| 535 | DefaultLink.builder().providerId(PID).src(of2p2).dst(of4p1).type(DIRECT).build() |
| 536 | ); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 537 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 538 | Set<ConnectPoint> ingress = ImmutableSet.of( |
| 539 | of1p1, |
| 540 | of3p1 |
| 541 | ); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 542 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 543 | Set<ConnectPoint> egress = ImmutableSet.of( |
| 544 | of4p2 |
| 545 | ); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 546 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 547 | TrafficSelector expectOf1Selector = DefaultTrafficSelector.builder(ipPrefixSelector) |
| 548 | .matchInPort(PortNumber.portNumber(1)) |
| 549 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 550 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 551 | TrafficTreatment expectOf1Treatment = DefaultTrafficTreatment.builder(ethDstTreatment) |
| 552 | .setOutput(PortNumber.portNumber(2)) |
| 553 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 554 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 555 | TrafficSelector expectOf2Selector1 = DefaultTrafficSelector.builder(ipPrefixSelector) |
| 556 | .matchInPort(PortNumber.portNumber(1)) |
| 557 | .matchEthDst(MacAddress.valueOf("C0:FF:EE:C0:FF:EE")) |
| 558 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 559 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 560 | TrafficSelector expectOf2Selector2 = DefaultTrafficSelector.builder(ipPrefixSelector) |
| 561 | .matchEthDst(MacAddress.valueOf("C0:FF:EE:C0:FF:EE")) |
| 562 | .matchInPort(PortNumber.portNumber(3)) |
| 563 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 564 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 565 | TrafficTreatment expectOf2Treatment = DefaultTrafficTreatment.builder() |
| 566 | .setOutput(PortNumber.portNumber(2)) |
| 567 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 568 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 569 | TrafficSelector expectOf3Selector = DefaultTrafficSelector.builder(ipPrefixSelector) |
| 570 | .matchInPort(PortNumber.portNumber(1)) |
| 571 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 572 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 573 | TrafficTreatment expectOf3Treatment = DefaultTrafficTreatment.builder(ethDstTreatment) |
| 574 | .setOutput(PortNumber.portNumber(2)) |
| 575 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 576 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 577 | TrafficSelector expectOf4Selector = DefaultTrafficSelector.builder(ipPrefixSelector) |
| 578 | .matchEthDst(MacAddress.valueOf("C0:FF:EE:C0:FF:EE")) |
| 579 | .matchInPort(PortNumber.portNumber(1)) |
| 580 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 581 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 582 | TrafficTreatment expectOf4Treatment = DefaultTrafficTreatment.builder() |
| 583 | .setOutput(PortNumber.portNumber(2)) |
| 584 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 585 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 586 | intent = LinkCollectionIntent.builder() |
| 587 | .appId(APP_ID) |
| 588 | .selector(ipPrefixSelector) |
| 589 | .ingressPoints(ingress) |
| 590 | .egressPoints(egress) |
| 591 | .treatment(ethDstTreatment) |
| 592 | .links(testlinks) |
| 593 | .build(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 594 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 595 | List<Intent> result = sut.compile(intent, Collections.emptyList()); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 596 | |
Yi Tseng | 2a81c9d | 2016-09-14 10:14:24 -0700 | [diff] [blame] | 597 | assertThat(result, is(notNullValue())); |
| 598 | assertThat(result, hasSize(1)); |
| 599 | |
| 600 | Intent resultIntent = result.get(0); |
| 601 | assertThat(resultIntent, instanceOf(FlowRuleIntent.class)); |
| 602 | |
| 603 | if (resultIntent instanceof FlowRuleIntent) { |
| 604 | FlowRuleIntent frIntent = (FlowRuleIntent) resultIntent; |
| 605 | assertThat(frIntent.flowRules(), hasSize(5)); |
| 606 | |
| 607 | List<FlowRule> deviceFlowRules; |
| 608 | FlowRule flowRule; |
| 609 | |
| 610 | // Of1 |
| 611 | deviceFlowRules = getFlowRulesByDevice(of1Id, frIntent.flowRules()); |
| 612 | assertThat(deviceFlowRules, hasSize(1)); |
| 613 | flowRule = deviceFlowRules.get(0); |
| 614 | assertThat(flowRule.selector(), is(expectOf1Selector)); |
| 615 | assertThat(flowRule.treatment(), is(expectOf1Treatment)); |
| 616 | |
| 617 | // Of2 (has 2 flows) |
| 618 | deviceFlowRules = getFlowRulesByDevice(of2Id, frIntent.flowRules()); |
| 619 | assertThat(deviceFlowRules, hasSize(2)); |
| 620 | flowRule = deviceFlowRules.get(0); |
| 621 | assertThat(flowRule.selector(), is(expectOf2Selector1)); |
| 622 | assertThat(flowRule.treatment(), is(expectOf2Treatment)); |
| 623 | flowRule = deviceFlowRules.get(1); |
| 624 | assertThat(flowRule.selector(), is(expectOf2Selector2)); |
| 625 | assertThat(flowRule.treatment(), is(expectOf2Treatment)); |
| 626 | |
| 627 | // Of3 |
| 628 | deviceFlowRules = getFlowRulesByDevice(of3Id, frIntent.flowRules()); |
| 629 | assertThat(deviceFlowRules, hasSize(1)); |
| 630 | flowRule = deviceFlowRules.get(0); |
| 631 | assertThat(flowRule.selector(), is(expectOf3Selector)); |
| 632 | assertThat(flowRule.treatment(), is(expectOf3Treatment)); |
| 633 | |
| 634 | // Of4 |
| 635 | deviceFlowRules = getFlowRulesByDevice(of4Id, frIntent.flowRules()); |
| 636 | assertThat(deviceFlowRules, hasSize(1)); |
| 637 | flowRule = deviceFlowRules.get(0); |
| 638 | assertThat(flowRule.selector(), is(expectOf4Selector)); |
| 639 | assertThat(flowRule.treatment(), is(expectOf4Treatment)); |
| 640 | } |
| 641 | |
| 642 | sut.deactivate(); |
Pier Ventre | 27d4257 | 2016-08-29 17:37:08 -0700 | [diff] [blame] | 643 | } |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 644 | |
| 645 | /** |
| 646 | * We test the proper compilation of mp2sp with |
| 647 | * trivial selector, trivial treatment and 1 hop. |
| 648 | */ |
| 649 | @Test |
| 650 | public void singleHopTestForMp() { |
| 651 | |
| 652 | intent = LinkCollectionIntent.builder() |
| 653 | .appId(APP_ID) |
| 654 | .selector(selector) |
| 655 | .treatment(treatment) |
| 656 | .links(ImmutableSet.of()) |
| 657 | .filteredIngressPoints(ImmutableSet.of( |
| 658 | new FilteredConnectPoint(d1p10), |
| 659 | new FilteredConnectPoint(d1p11) |
| 660 | )) |
| 661 | .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0))) |
| 662 | .build(); |
| 663 | |
| 664 | sut.activate(); |
| 665 | |
| 666 | List<Intent> compiled = sut.compile(intent, Collections.emptyList()); |
| 667 | assertThat(compiled, hasSize(1)); |
| 668 | |
| 669 | Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); |
| 670 | assertThat(rules, hasSize(2)); |
| 671 | |
| 672 | Collection<FlowRule> rulesS1 = rules.stream() |
| 673 | .filter(rule -> rule.deviceId().equals(d1p0.deviceId())) |
| 674 | .collect(Collectors.toSet()); |
| 675 | assertThat(rulesS1, hasSize(2)); |
| 676 | FlowRule ruleS1 = rulesS1.stream() |
| 677 | .filter(rule -> { |
| 678 | PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT); |
| 679 | return inPort.port().equals(d1p10.port()); |
| 680 | }) |
| 681 | .findFirst() |
| 682 | .get(); |
| 683 | assertThat(ruleS1.selector(), Is.is( |
| 684 | DefaultTrafficSelector |
| 685 | .builder() |
| 686 | .matchInPort(d1p10.port()) |
| 687 | .build() |
| 688 | )); |
| 689 | assertThat(ruleS1.treatment(), Is.is( |
| 690 | DefaultTrafficTreatment |
| 691 | .builder() |
| 692 | .setOutput(d1p0.port()) |
| 693 | .build() |
| 694 | )); |
| 695 | |
| 696 | ruleS1 = rulesS1.stream() |
| 697 | .filter(rule -> { |
| 698 | PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT); |
| 699 | return inPort.port().equals(d1p11.port()); |
| 700 | }) |
| 701 | .findFirst() |
| 702 | .get(); |
| 703 | assertThat(ruleS1.selector(), Is.is( |
| 704 | DefaultTrafficSelector |
| 705 | .builder() |
| 706 | .matchInPort(d1p11.port()) |
| 707 | .build() |
| 708 | )); |
| 709 | assertThat(ruleS1.treatment(), Is.is( |
| 710 | DefaultTrafficTreatment |
| 711 | .builder() |
| 712 | .setOutput(d1p0.port()) |
| 713 | .build() |
| 714 | )); |
| 715 | |
| 716 | sut.deactivate(); |
| 717 | |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * We test the proper compilation of sp2mp with |
| 722 | * trivial selector, trivial treatment and 1 hop. |
| 723 | */ |
| 724 | @Test |
| 725 | public void singleHopTestForSp() { |
| 726 | |
| 727 | intent = LinkCollectionIntent.builder() |
| 728 | .appId(APP_ID) |
| 729 | .selector(selector) |
| 730 | .treatment(treatment) |
| 731 | .applyTreatmentOnEgress(true) |
| 732 | .links(ImmutableSet.of()) |
| 733 | .filteredEgressPoints(ImmutableSet.of( |
| 734 | new FilteredConnectPoint(d1p10), |
| 735 | new FilteredConnectPoint(d1p11) |
| 736 | )) |
| 737 | .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0))) |
| 738 | .build(); |
| 739 | |
| 740 | sut.activate(); |
| 741 | |
| 742 | List<Intent> compiled = sut.compile(intent, Collections.emptyList()); |
| 743 | assertThat(compiled, hasSize(1)); |
| 744 | |
| 745 | Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); |
| 746 | assertThat(rules, hasSize(1)); |
| 747 | |
| 748 | Collection<FlowRule> rulesS1 = rules.stream() |
| 749 | .filter(rule -> rule.deviceId().equals(d1p0.deviceId())) |
| 750 | .collect(Collectors.toSet()); |
| 751 | assertThat(rulesS1, hasSize(1)); |
| 752 | FlowRule ruleS1 = rulesS1.stream() |
| 753 | .filter(rule -> { |
| 754 | PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT); |
| 755 | return inPort.port().equals(d1p0.port()); |
| 756 | }) |
| 757 | .findFirst() |
| 758 | .get(); |
| 759 | assertThat(ruleS1.selector(), Is.is( |
| 760 | DefaultTrafficSelector |
| 761 | .builder() |
| 762 | .matchInPort(d1p0.port()) |
| 763 | .build() |
| 764 | )); |
| 765 | assertThat(ruleS1.treatment(), Is.is( |
| 766 | DefaultTrafficTreatment |
| 767 | .builder() |
| 768 | .setOutput(d1p10.port()) |
| 769 | .setOutput(d1p11.port()) |
| 770 | .build() |
| 771 | )); |
| 772 | |
| 773 | sut.deactivate(); |
| 774 | |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * We test the proper compilation of mp2sp with |
| 779 | * trivial selector, trivial treatment, filtered |
| 780 | * points and 1 hop. |
| 781 | */ |
| 782 | @Test |
| 783 | public void singleHopTestFilteredForMp() { |
| 784 | |
| 785 | intent = LinkCollectionIntent.builder() |
| 786 | .appId(APP_ID) |
| 787 | .selector(selector) |
| 788 | .treatment(treatment) |
| 789 | .links(ImmutableSet.of()) |
| 790 | .filteredIngressPoints(ImmutableSet.of( |
| 791 | new FilteredConnectPoint(d1p10, vlan100Selector), |
| 792 | new FilteredConnectPoint(d1p11, mpls69Selector) |
| 793 | )) |
| 794 | .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector))) |
| 795 | .build(); |
| 796 | |
| 797 | sut.activate(); |
| 798 | |
| 799 | List<Intent> compiled = sut.compile(intent, Collections.emptyList()); |
| 800 | assertThat(compiled, hasSize(1)); |
| 801 | |
| 802 | Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); |
| 803 | assertThat(rules, hasSize(2)); |
| 804 | |
| 805 | Collection<FlowRule> rulesS1 = rules.stream() |
| 806 | .filter(rule -> rule.deviceId().equals(d1p0.deviceId())) |
| 807 | .collect(Collectors.toSet()); |
| 808 | assertThat(rulesS1, hasSize(2)); |
| 809 | FlowRule ruleS1 = rulesS1.stream() |
| 810 | .filter(rule -> { |
| 811 | PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT); |
| 812 | return inPort.port().equals(d1p10.port()); |
| 813 | }) |
| 814 | .findFirst() |
| 815 | .get(); |
| 816 | assertThat(ruleS1.selector(), Is.is( |
| 817 | DefaultTrafficSelector |
| 818 | .builder(vlan100Selector) |
| 819 | .matchInPort(d1p10.port()) |
| 820 | .build() |
| 821 | )); |
| 822 | assertThat(ruleS1.treatment(), Is.is( |
| 823 | DefaultTrafficTreatment |
| 824 | .builder() |
| 825 | .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()) |
| 826 | .setOutput(d1p0.port()) |
| 827 | .build() |
| 828 | )); |
| 829 | |
| 830 | ruleS1 = rulesS1.stream() |
| 831 | .filter(rule -> { |
| 832 | PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT); |
| 833 | return inPort.port().equals(d1p11.port()); |
| 834 | }) |
| 835 | .findFirst() |
| 836 | .get(); |
| 837 | assertThat(ruleS1.selector(), Is.is( |
| 838 | DefaultTrafficSelector |
| 839 | .builder(mpls69Selector) |
| 840 | .matchInPort(d1p11.port()) |
| 841 | .build() |
| 842 | )); |
| 843 | assertThat(ruleS1.treatment(), Is.is( |
| 844 | DefaultTrafficTreatment |
| 845 | .builder() |
| 846 | .popMpls(IPV4.ethType()) |
| 847 | .pushVlan() |
| 848 | .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()) |
| 849 | .setOutput(d1p0.port()) |
| 850 | .build() |
| 851 | )); |
| 852 | |
| 853 | sut.deactivate(); |
| 854 | |
| 855 | } |
| 856 | |
| 857 | /** |
| 858 | * We test the proper compilation of sp2mp with |
| 859 | * trivial selector, trivial treatment and 1 hop. |
| 860 | */ |
| 861 | @Test |
| 862 | public void singleHopTestFilteredForSp() { |
| 863 | |
| 864 | intent = LinkCollectionIntent.builder() |
| 865 | .appId(APP_ID) |
| 866 | .selector(selector) |
| 867 | .treatment(treatment) |
| 868 | .applyTreatmentOnEgress(true) |
| 869 | .links(ImmutableSet.of()) |
| 870 | .filteredEgressPoints(ImmutableSet.of( |
| 871 | new FilteredConnectPoint(d1p10, vlan100Selector), |
| 872 | new FilteredConnectPoint(d1p11, mpls80Selector) |
| 873 | )) |
| 874 | .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector))) |
| 875 | .build(); |
| 876 | |
| 877 | sut.activate(); |
| 878 | |
| 879 | List<Intent> compiled = sut.compile(intent, Collections.emptyList()); |
| 880 | assertThat(compiled, hasSize(1)); |
| 881 | |
| 882 | Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); |
| 883 | assertThat(rules, hasSize(1)); |
| 884 | |
| 885 | Collection<FlowRule> rulesS1 = rules.stream() |
| 886 | .filter(rule -> rule.deviceId().equals(d1p0.deviceId())) |
| 887 | .collect(Collectors.toSet()); |
| 888 | assertThat(rulesS1, hasSize(1)); |
| 889 | FlowRule ruleS1 = rulesS1.stream() |
| 890 | .filter(rule -> { |
| 891 | PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT); |
| 892 | return inPort.port().equals(d1p0.port()); |
| 893 | }) |
| 894 | .findFirst() |
| 895 | .get(); |
| 896 | assertThat(ruleS1.selector(), Is.is( |
| 897 | DefaultTrafficSelector |
| 898 | .builder(vlan200Selector) |
| 899 | .matchInPort(d1p0.port()) |
| 900 | .build() |
| 901 | )); |
| 902 | assertThat(ruleS1.treatment(), Is.is( |
| 903 | DefaultTrafficTreatment |
| 904 | .builder() |
| 905 | .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()) |
| 906 | .setOutput(d1p10.port()) |
| 907 | .popVlan() |
| 908 | .pushMpls() |
| 909 | .setMpls(((MplsCriterion) mpls80Selector.getCriterion(MPLS_LABEL)).label()) |
| 910 | .setOutput(d1p11.port()) |
| 911 | .build() |
| 912 | )); |
| 913 | |
| 914 | sut.deactivate(); |
| 915 | |
| 916 | } |
| 917 | |
| 918 | /** |
| 919 | * We test the proper compilation of mp2sp with |
| 920 | * selector, treatment, filtered |
| 921 | * points and 1 hop. |
| 922 | */ |
| 923 | @Test |
| 924 | public void singleHopNonTrivialForMp() { |
| 925 | |
| 926 | intent = LinkCollectionIntent.builder() |
| 927 | .appId(APP_ID) |
| 928 | .selector(ipPrefixSelector) |
| 929 | .treatment(ethDstTreatment) |
| 930 | .links(ImmutableSet.of()) |
| 931 | .filteredIngressPoints(ImmutableSet.of( |
| 932 | new FilteredConnectPoint(d1p10, vlan100Selector), |
| 933 | new FilteredConnectPoint(d1p11, mpls100Selector) |
| 934 | )) |
| 935 | .filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector))) |
| 936 | .build(); |
| 937 | |
| 938 | sut.activate(); |
| 939 | |
| 940 | List<Intent> compiled = sut.compile(intent, Collections.emptyList()); |
| 941 | assertThat(compiled, hasSize(1)); |
| 942 | |
| 943 | Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); |
| 944 | assertThat(rules, hasSize(2)); |
| 945 | |
| 946 | Collection<FlowRule> rulesS1 = rules.stream() |
| 947 | .filter(rule -> rule.deviceId().equals(d1p0.deviceId())) |
| 948 | .collect(Collectors.toSet()); |
| 949 | assertThat(rulesS1, hasSize(2)); |
| 950 | FlowRule ruleS1 = rulesS1.stream() |
| 951 | .filter(rule -> { |
| 952 | PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT); |
| 953 | return inPort.port().equals(d1p10.port()); |
| 954 | }) |
| 955 | .findFirst() |
| 956 | .get(); |
| 957 | assertThat(ruleS1.selector(), Is.is( |
| 958 | DefaultTrafficSelector |
| 959 | .builder(ipPrefixSelector) |
| 960 | .matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()) |
| 961 | .matchInPort(d1p10.port()) |
| 962 | .build() |
| 963 | )); |
| 964 | assertThat(ruleS1.treatment(), Is.is( |
| 965 | DefaultTrafficTreatment |
| 966 | .builder() |
| 967 | .setEthDst(((ModEtherInstruction) ethDstTreatment |
| 968 | .allInstructions() |
| 969 | .stream() |
| 970 | .filter(instruction -> instruction instanceof ModEtherInstruction) |
| 971 | .findFirst().get()).mac()) |
| 972 | .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()) |
| 973 | .setOutput(d1p0.port()) |
| 974 | .build() |
| 975 | )); |
| 976 | |
| 977 | ruleS1 = rulesS1.stream() |
| 978 | .filter(rule -> { |
| 979 | PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT); |
| 980 | return inPort.port().equals(d1p11.port()); |
| 981 | }) |
| 982 | .findFirst() |
| 983 | .get(); |
| 984 | assertThat(ruleS1.selector(), Is.is( |
| 985 | DefaultTrafficSelector |
| 986 | .builder(ipPrefixSelector) |
| 987 | .matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()) |
| 988 | .matchInPort(d1p11.port()) |
| 989 | .build() |
| 990 | )); |
| 991 | assertThat(ruleS1.treatment(), Is.is( |
| 992 | DefaultTrafficTreatment |
| 993 | .builder() |
| 994 | .setEthDst(((ModEtherInstruction) ethDstTreatment |
| 995 | .allInstructions() |
| 996 | .stream() |
| 997 | .filter(instruction -> instruction instanceof ModEtherInstruction) |
| 998 | .findFirst().get()).mac()) |
| 999 | .popMpls(IPV4.ethType()) |
| 1000 | .pushVlan() |
| 1001 | .setVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()) |
| 1002 | .setOutput(d1p0.port()) |
| 1003 | .build() |
| 1004 | )); |
| 1005 | |
| 1006 | sut.deactivate(); |
| 1007 | |
| 1008 | } |
| 1009 | |
| 1010 | /** |
| 1011 | * We test the proper compilation of sp2mp with |
| 1012 | * selector, treatment and 1 hop. |
| 1013 | */ |
| 1014 | @Test |
| 1015 | public void singleHopNonTrivialForSp() { |
| 1016 | |
| 1017 | intent = LinkCollectionIntent.builder() |
| 1018 | .appId(APP_ID) |
| 1019 | .selector(ipPrefixSelector) |
| 1020 | .treatment(ethDstTreatment) |
| 1021 | .applyTreatmentOnEgress(true) |
| 1022 | .links(ImmutableSet.of()) |
| 1023 | .filteredEgressPoints(ImmutableSet.of( |
| 1024 | new FilteredConnectPoint(d1p10, vlan100Selector), |
| 1025 | new FilteredConnectPoint(d1p11, mpls200Selector) |
| 1026 | )) |
| 1027 | .filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0, vlan200Selector))) |
| 1028 | .build(); |
| 1029 | |
| 1030 | sut.activate(); |
| 1031 | |
| 1032 | List<Intent> compiled = sut.compile(intent, Collections.emptyList()); |
| 1033 | assertThat(compiled, hasSize(1)); |
| 1034 | |
| 1035 | Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules(); |
| 1036 | assertThat(rules, hasSize(1)); |
| 1037 | |
| 1038 | Collection<FlowRule> rulesS1 = rules.stream() |
| 1039 | .filter(rule -> rule.deviceId().equals(d1p0.deviceId())) |
| 1040 | .collect(Collectors.toSet()); |
| 1041 | assertThat(rulesS1, hasSize(1)); |
| 1042 | FlowRule ruleS1 = rulesS1.stream() |
| 1043 | .filter(rule -> { |
| 1044 | PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT); |
| 1045 | return inPort.port().equals(d1p0.port()); |
| 1046 | }) |
| 1047 | .findFirst() |
| 1048 | .get(); |
| 1049 | assertThat(ruleS1.selector(), Is.is( |
| 1050 | DefaultTrafficSelector |
| 1051 | .builder(ipPrefixSelector) |
| 1052 | .matchVlanId(((VlanIdCriterion) vlan200Selector.getCriterion(VLAN_VID)).vlanId()) |
| 1053 | .matchInPort(d1p0.port()) |
| 1054 | .build() |
| 1055 | )); |
| 1056 | assertThat(ruleS1.treatment(), Is.is( |
| 1057 | DefaultTrafficTreatment |
| 1058 | .builder() |
| 1059 | .setEthDst(((ModEtherInstruction) ethDstTreatment |
| 1060 | .allInstructions() |
| 1061 | .stream() |
| 1062 | .filter(instruction -> instruction instanceof ModEtherInstruction) |
| 1063 | .findFirst().get()).mac()) |
| 1064 | .setVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()) |
| 1065 | .setOutput(d1p10.port()) |
| 1066 | .setEthDst(((ModEtherInstruction) ethDstTreatment |
| 1067 | .allInstructions() |
| 1068 | .stream() |
| 1069 | .filter(instruction -> instruction instanceof ModEtherInstruction) |
| 1070 | .findFirst().get()).mac()) |
| 1071 | .popVlan() |
| 1072 | .pushMpls() |
| 1073 | .setMpls(((MplsCriterion) mpls200Selector.getCriterion(MPLS_LABEL)).label()) |
| 1074 | .setOutput(d1p11.port()) |
| 1075 | .build() |
| 1076 | )); |
| 1077 | |
| 1078 | sut.deactivate(); |
| 1079 | |
| 1080 | } |
| 1081 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 1082 | } |