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