Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [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 | |
| 17 | package org.onosproject.net.intent.impl.compiler; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import org.onosproject.TestApplicationId; |
| 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.core.CoreService; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 23 | import org.onosproject.net.ConnectPoint; |
| 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.net.Link; |
Yi Tseng | a64f0c8 | 2017-02-03 11:17:15 -0800 | [diff] [blame] | 26 | import org.onosproject.net.ResourceGroup; |
Thomas Szyrkowiec | 770093f | 2017-05-05 13:06:53 +0200 | [diff] [blame] | 27 | import org.onosproject.net.domain.DomainId; |
| 28 | import org.onosproject.net.domain.DomainService; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 29 | import org.onosproject.net.flow.FlowRule; |
| 30 | import org.onosproject.net.flow.TrafficSelector; |
| 31 | import org.onosproject.net.flow.TrafficTreatment; |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 32 | import org.onosproject.net.intent.AbstractIntentTest; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 33 | import org.onosproject.net.intent.Constraint; |
| 34 | import org.onosproject.net.intent.IntentExtensionService; |
| 35 | import org.onosproject.net.intent.LinkCollectionIntent; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 36 | |
| 37 | import java.util.Collection; |
| 38 | import java.util.List; |
| 39 | import java.util.Set; |
| 40 | import java.util.stream.Collectors; |
| 41 | |
| 42 | import static org.onosproject.net.NetTestTools.*; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Abstract class to hold the common variables and pieces |
| 46 | * of code. |
| 47 | */ |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 48 | abstract class AbstractLinkCollectionTest extends AbstractIntentTest { |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 49 | |
| 50 | static final String LABEL_SELECTION = "FIRST_FIT"; |
| 51 | static final String LABEL = "1"; |
| 52 | |
| 53 | final ApplicationId appId = new TestApplicationId("test"); |
| 54 | |
Thomas Szyrkowiec | 770093f | 2017-05-05 13:06:53 +0200 | [diff] [blame] | 55 | final DomainId domain = DomainId.domainId("d1"); |
| 56 | |
| 57 | final DeviceId d2Id = DeviceId.deviceId("of:s2"); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 58 | final ConnectPoint d2p0 = connectPoint("s2", 0); |
| 59 | final ConnectPoint d2p1 = connectPoint("s2", 1); |
Pier Ventre | 81c47bf | 2016-11-04 07:26:22 -0700 | [diff] [blame] | 60 | final ConnectPoint d2p10 = connectPoint("s2", 10); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 61 | |
Thomas Szyrkowiec | 770093f | 2017-05-05 13:06:53 +0200 | [diff] [blame] | 62 | final DeviceId d3Id = DeviceId.deviceId("of:s3"); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 63 | final ConnectPoint d3p0 = connectPoint("s3", 0); |
| 64 | final ConnectPoint d3p1 = connectPoint("s3", 1); |
| 65 | final ConnectPoint d3p10 = connectPoint("s3", 10); |
| 66 | |
Thomas Szyrkowiec | 770093f | 2017-05-05 13:06:53 +0200 | [diff] [blame] | 67 | final DeviceId d4Id = DeviceId.deviceId("of:s4"); |
| 68 | final ConnectPoint d4p0 = connectPoint("s4", 0); |
| 69 | final ConnectPoint d4p1 = connectPoint("s4", 1); |
| 70 | final ConnectPoint d4p10 = connectPoint("s4", 10); |
| 71 | |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 72 | final DeviceId of1Id = DeviceId.deviceId("of:of1"); |
| 73 | final DeviceId of2Id = DeviceId.deviceId("of:of2"); |
| 74 | final DeviceId of3Id = DeviceId.deviceId("of:of3"); |
| 75 | final DeviceId of4Id = DeviceId.deviceId("of:of4"); |
| 76 | |
| 77 | final ConnectPoint of1p1 = connectPoint("of1", 1); |
| 78 | final ConnectPoint of1p2 = connectPoint("of1", 2); |
Yi Tseng | a64f0c8 | 2017-02-03 11:17:15 -0800 | [diff] [blame] | 79 | final ConnectPoint of1p3 = connectPoint("of1", 3); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 80 | final ConnectPoint of2p1 = connectPoint("of2", 1); |
| 81 | final ConnectPoint of2p2 = connectPoint("of2", 2); |
| 82 | final ConnectPoint of2p3 = connectPoint("of2", 3); |
| 83 | final ConnectPoint of3p1 = connectPoint("of3", 1); |
| 84 | final ConnectPoint of3p2 = connectPoint("of3", 2); |
| 85 | final ConnectPoint of4p1 = connectPoint("of4", 1); |
| 86 | final ConnectPoint of4p2 = connectPoint("of4", 2); |
| 87 | |
Thomas Szyrkowiec | 770093f | 2017-05-05 13:06:53 +0200 | [diff] [blame] | 88 | final DeviceId d1Id = DeviceId.deviceId("of:s1"); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 89 | final ConnectPoint d1p0 = connectPoint("s1", 0); |
| 90 | final ConnectPoint d1p1 = connectPoint("s1", 1); |
| 91 | final ConnectPoint d1p10 = connectPoint("s1", 10); |
| 92 | final ConnectPoint d1p11 = connectPoint("s1", 11); |
Pier Ventre | 81c47bf | 2016-11-04 07:26:22 -0700 | [diff] [blame] | 93 | final ConnectPoint d1p12 = connectPoint("s1", 12); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 94 | |
| 95 | final Set<Link> links = ImmutableSet.of( |
| 96 | link(d1p1, d2p0), |
| 97 | link(d2p1, d3p1), |
| 98 | link(d1p1, d3p1) |
| 99 | ); |
| 100 | |
| 101 | final Set<Link> linksForMp2Sp = ImmutableSet.of( |
| 102 | link(d1p0, d2p0), |
| 103 | link(d2p1, d3p0) |
| 104 | ); |
| 105 | |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 106 | final Set<Link> linksForSp2Mp = ImmutableSet.of( |
| 107 | link(d3p0, d2p1), |
| 108 | link(d2p0, d1p0) |
| 109 | ); |
| 110 | |
Pier Ventre | ffe88d6 | 2016-10-13 14:34:40 -0700 | [diff] [blame] | 111 | final Set<Link> p2pLinks = ImmutableSet.of( |
| 112 | link(d1p0, d2p0), |
| 113 | link(d2p1, d3p1) |
| 114 | ); |
| 115 | |
Thomas Szyrkowiec | 770093f | 2017-05-05 13:06:53 +0200 | [diff] [blame] | 116 | final Set<Link> domainP2Plinks = ImmutableSet.of( |
| 117 | link(d1p0, d2p0), |
| 118 | link(d2p1, d4p1), |
| 119 | link(d4p0, d3p0) |
| 120 | ); |
| 121 | |
Pier Ventre | 5c4a076 | 2016-11-21 10:28:13 -0800 | [diff] [blame] | 122 | final Set<Link> linksForSp2MpCoLoc = ImmutableSet.of( |
| 123 | link(d1p0, d2p0), |
| 124 | link(d2p1, d3p0) |
| 125 | ); |
| 126 | |
| 127 | final Set<Link> linksForMp2SpCoLoc = ImmutableSet.of( |
| 128 | link(d2p0, d1p0) |
| 129 | ); |
| 130 | |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 131 | final TrafficTreatment treatment = emptyTreatment(); |
Pier Ventre | 81c47bf | 2016-11-04 07:26:22 -0700 | [diff] [blame] | 132 | final TrafficTreatment ethDstTreatment = macDstTreatment("C0:FF:EE:C0:FF:EE"); |
| 133 | final TrafficTreatment decTllTreatment = decTtlTreatment(); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 134 | |
| 135 | final TrafficSelector selector = emptySelector(); |
| 136 | final TrafficSelector vlan69Selector = vlanSelector("69"); |
Yi Tseng | b32f774 | 2017-05-09 15:34:19 -0700 | [diff] [blame] | 137 | final TrafficSelector vlan1Selector = vlanSelector("1"); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 138 | final TrafficSelector vlan100Selector = vlanSelector("100"); |
| 139 | final TrafficSelector vlan200Selector = vlanSelector("200"); |
| 140 | final TrafficSelector vlan300Selector = vlanSelector("300"); |
| 141 | final TrafficSelector mpls69Selector = mplsSelector("69"); |
| 142 | final TrafficSelector mpls80Selector = mplsSelector("80"); |
| 143 | final TrafficSelector mpls100Selector = mplsSelector("100"); |
| 144 | final TrafficSelector mpls200Selector = mplsSelector("200"); |
| 145 | final TrafficSelector ipPrefixSelector = ipPrefixDstSelector("192.168.100.0/24"); |
Yi Tseng | a64f0c8 | 2017-02-03 11:17:15 -0800 | [diff] [blame] | 146 | final TrafficSelector ethDstSelector = ethDstSelector("C0:FF:EE:C0:FF:EE"); |
| 147 | final ResourceGroup resourceGroup1 = ResourceGroup.of(1L); |
| 148 | final ResourceGroup resourceGroup2 = ResourceGroup.of(1L); |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 149 | |
| 150 | final List<Constraint> constraintsForVlan = vlanConstraint(); |
| 151 | final List<Constraint> constraintsForMPLS = mplsConstraint(); |
| 152 | |
| 153 | CoreService coreService; |
Thomas Szyrkowiec | 770093f | 2017-05-05 13:06:53 +0200 | [diff] [blame] | 154 | DomainService domainService; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 155 | IntentExtensionService intentExtensionService; |
| 156 | IntentConfigurableRegistrator registrator; |
Pier Ventre | 766995d | 2016-10-05 22:15:56 -0700 | [diff] [blame] | 157 | |
| 158 | LinkCollectionIntent intent; |
| 159 | |
| 160 | LinkCollectionIntentCompiler sut; |
| 161 | |
| 162 | List<FlowRule> getFlowRulesByDevice(DeviceId deviceId, Collection<FlowRule> flowRules) { |
| 163 | return flowRules.stream() |
| 164 | .filter(fr -> fr.deviceId().equals(deviceId)) |
| 165 | .collect(Collectors.toList()); |
| 166 | } |
| 167 | |
| 168 | } |