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