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