blob: f0f1d29731f9efd300edba40ea3cc75cdbd906f0 [file] [log] [blame]
Pier Ventre766995d2016-10-05 22:15:56 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
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
17package org.onosproject.net.intent.impl.compiler;
18
19import com.google.common.collect.ImmutableSet;
20import org.onosproject.TestApplicationId;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.core.CoreService;
Pier Ventre766995d2016-10-05 22:15:56 -070023import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.DeviceId;
25import org.onosproject.net.Link;
Yi Tsenga64f0c82017-02-03 11:17:15 -080026import org.onosproject.net.ResourceGroup;
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020027import org.onosproject.net.domain.DomainId;
28import org.onosproject.net.domain.DomainService;
Pier Ventre766995d2016-10-05 22:15:56 -070029import org.onosproject.net.flow.FlowRule;
30import org.onosproject.net.flow.TrafficSelector;
31import org.onosproject.net.flow.TrafficTreatment;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070032import org.onosproject.net.intent.AbstractIntentTest;
Pier Ventre766995d2016-10-05 22:15:56 -070033import org.onosproject.net.intent.Constraint;
34import org.onosproject.net.intent.IntentExtensionService;
35import org.onosproject.net.intent.LinkCollectionIntent;
Pier Ventre766995d2016-10-05 22:15:56 -070036
37import java.util.Collection;
38import java.util.List;
39import java.util.Set;
40import java.util.stream.Collectors;
41
42import static org.onosproject.net.NetTestTools.*;
Pier Ventre766995d2016-10-05 22:15:56 -070043
44/**
45 * Abstract class to hold the common variables and pieces
46 * of code.
47 */
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070048abstract class AbstractLinkCollectionTest extends AbstractIntentTest {
Pier Ventre766995d2016-10-05 22:15:56 -070049
50 static final String LABEL_SELECTION = "FIRST_FIT";
51 static final String LABEL = "1";
52
53 final ApplicationId appId = new TestApplicationId("test");
54
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020055 final DomainId domain = DomainId.domainId("d1");
56
57 final DeviceId d2Id = DeviceId.deviceId("of:s2");
Pier Ventre766995d2016-10-05 22:15:56 -070058 final ConnectPoint d2p0 = connectPoint("s2", 0);
59 final ConnectPoint d2p1 = connectPoint("s2", 1);
Pier Ventre81c47bf2016-11-04 07:26:22 -070060 final ConnectPoint d2p10 = connectPoint("s2", 10);
Pier Ventre766995d2016-10-05 22:15:56 -070061
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020062 final DeviceId d3Id = DeviceId.deviceId("of:s3");
Pier Ventre766995d2016-10-05 22:15:56 -070063 final ConnectPoint d3p0 = connectPoint("s3", 0);
64 final ConnectPoint d3p1 = connectPoint("s3", 1);
65 final ConnectPoint d3p10 = connectPoint("s3", 10);
66
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020067 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 Ventre766995d2016-10-05 22:15:56 -070072 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 Tsenga64f0c82017-02-03 11:17:15 -080079 final ConnectPoint of1p3 = connectPoint("of1", 3);
Pier Ventre766995d2016-10-05 22:15:56 -070080 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 Szyrkowiec770093f2017-05-05 13:06:53 +020088 final DeviceId d1Id = DeviceId.deviceId("of:s1");
Pier Ventre766995d2016-10-05 22:15:56 -070089 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 Ventre81c47bf2016-11-04 07:26:22 -070093 final ConnectPoint d1p12 = connectPoint("s1", 12);
Pier Ventre766995d2016-10-05 22:15:56 -070094
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 Ventre766995d2016-10-05 22:15:56 -0700106 final Set<Link> linksForSp2Mp = ImmutableSet.of(
107 link(d3p0, d2p1),
108 link(d2p0, d1p0)
109 );
110
Pier Ventreffe88d62016-10-13 14:34:40 -0700111 final Set<Link> p2pLinks = ImmutableSet.of(
112 link(d1p0, d2p0),
113 link(d2p1, d3p1)
114 );
115
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +0200116 final Set<Link> domainP2Plinks = ImmutableSet.of(
117 link(d1p0, d2p0),
118 link(d2p1, d4p1),
119 link(d4p0, d3p0)
120 );
121
Pier Ventre5c4a0762016-11-21 10:28:13 -0800122 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 Ventre766995d2016-10-05 22:15:56 -0700131 final TrafficTreatment treatment = emptyTreatment();
Pier Ventre81c47bf2016-11-04 07:26:22 -0700132 final TrafficTreatment ethDstTreatment = macDstTreatment("C0:FF:EE:C0:FF:EE");
133 final TrafficTreatment decTllTreatment = decTtlTreatment();
Pier Ventre766995d2016-10-05 22:15:56 -0700134
135 final TrafficSelector selector = emptySelector();
136 final TrafficSelector vlan69Selector = vlanSelector("69");
137 final TrafficSelector vlan100Selector = vlanSelector("100");
138 final TrafficSelector vlan200Selector = vlanSelector("200");
139 final TrafficSelector vlan300Selector = vlanSelector("300");
140 final TrafficSelector mpls69Selector = mplsSelector("69");
141 final TrafficSelector mpls80Selector = mplsSelector("80");
142 final TrafficSelector mpls100Selector = mplsSelector("100");
143 final TrafficSelector mpls200Selector = mplsSelector("200");
144 final TrafficSelector ipPrefixSelector = ipPrefixDstSelector("192.168.100.0/24");
Yi Tsenga64f0c82017-02-03 11:17:15 -0800145 final TrafficSelector ethDstSelector = ethDstSelector("C0:FF:EE:C0:FF:EE");
146 final ResourceGroup resourceGroup1 = ResourceGroup.of(1L);
147 final ResourceGroup resourceGroup2 = ResourceGroup.of(1L);
Pier Ventre766995d2016-10-05 22:15:56 -0700148
149 final List<Constraint> constraintsForVlan = vlanConstraint();
150 final List<Constraint> constraintsForMPLS = mplsConstraint();
151
152 CoreService coreService;
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +0200153 DomainService domainService;
Pier Ventre766995d2016-10-05 22:15:56 -0700154 IntentExtensionService intentExtensionService;
155 IntentConfigurableRegistrator registrator;
Pier Ventre766995d2016-10-05 22:15:56 -0700156
157 LinkCollectionIntent intent;
158
159 LinkCollectionIntentCompiler sut;
160
161 List<FlowRule> getFlowRulesByDevice(DeviceId deviceId, Collection<FlowRule> flowRules) {
162 return flowRules.stream()
163 .filter(fr -> fr.deviceId().equals(deviceId))
164 .collect(Collectors.toList());
165 }
166
167}