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