blob: 32dc47f61b2491bdcc677f13edb822ac23e48dc8 [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;
23import org.onosproject.core.IdGenerator;
24import org.onosproject.net.ConnectPoint;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.Link;
Yi Tsenga64f0c82017-02-03 11:17:15 -080027import org.onosproject.net.ResourceGroup;
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020028import org.onosproject.net.domain.DomainId;
29import org.onosproject.net.domain.DomainService;
Pier Ventre766995d2016-10-05 22:15:56 -070030import org.onosproject.net.flow.FlowRule;
31import org.onosproject.net.flow.TrafficSelector;
32import org.onosproject.net.flow.TrafficTreatment;
33import org.onosproject.net.intent.Constraint;
34import org.onosproject.net.intent.IntentExtensionService;
35import org.onosproject.net.intent.LinkCollectionIntent;
36import org.onosproject.net.intent.MockIdGenerator;
37
38import java.util.Collection;
39import java.util.List;
40import java.util.Set;
41import java.util.stream.Collectors;
42
43import static org.onosproject.net.NetTestTools.*;
44import static org.onosproject.net.NetTestTools.macDstTreatment;
45
46/**
47 * Abstract class to hold the common variables and pieces
48 * of code.
49 */
50class AbstractLinkCollectionTest {
51
52 static final String LABEL_SELECTION = "FIRST_FIT";
53 static final String LABEL = "1";
54
55 final ApplicationId appId = new TestApplicationId("test");
56
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020057 final DomainId domain = DomainId.domainId("d1");
58
59 final DeviceId d2Id = DeviceId.deviceId("of:s2");
Pier Ventre766995d2016-10-05 22:15:56 -070060 final ConnectPoint d2p0 = connectPoint("s2", 0);
61 final ConnectPoint d2p1 = connectPoint("s2", 1);
Pier Ventre81c47bf2016-11-04 07:26:22 -070062 final ConnectPoint d2p10 = connectPoint("s2", 10);
Pier Ventre766995d2016-10-05 22:15:56 -070063
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020064 final DeviceId d3Id = DeviceId.deviceId("of:s3");
Pier Ventre766995d2016-10-05 22:15:56 -070065 final ConnectPoint d3p0 = connectPoint("s3", 0);
66 final ConnectPoint d3p1 = connectPoint("s3", 1);
67 final ConnectPoint d3p10 = connectPoint("s3", 10);
68
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020069 final DeviceId d4Id = DeviceId.deviceId("of:s4");
70 final ConnectPoint d4p0 = connectPoint("s4", 0);
71 final ConnectPoint d4p1 = connectPoint("s4", 1);
72 final ConnectPoint d4p10 = connectPoint("s4", 10);
73
Pier Ventre766995d2016-10-05 22:15:56 -070074 final DeviceId of1Id = DeviceId.deviceId("of:of1");
75 final DeviceId of2Id = DeviceId.deviceId("of:of2");
76 final DeviceId of3Id = DeviceId.deviceId("of:of3");
77 final DeviceId of4Id = DeviceId.deviceId("of:of4");
78
79 final ConnectPoint of1p1 = connectPoint("of1", 1);
80 final ConnectPoint of1p2 = connectPoint("of1", 2);
Yi Tsenga64f0c82017-02-03 11:17:15 -080081 final ConnectPoint of1p3 = connectPoint("of1", 3);
Pier Ventre766995d2016-10-05 22:15:56 -070082 final ConnectPoint of2p1 = connectPoint("of2", 1);
83 final ConnectPoint of2p2 = connectPoint("of2", 2);
84 final ConnectPoint of2p3 = connectPoint("of2", 3);
85 final ConnectPoint of3p1 = connectPoint("of3", 1);
86 final ConnectPoint of3p2 = connectPoint("of3", 2);
87 final ConnectPoint of4p1 = connectPoint("of4", 1);
88 final ConnectPoint of4p2 = connectPoint("of4", 2);
89
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +020090 final DeviceId d1Id = DeviceId.deviceId("of:s1");
Pier Ventre766995d2016-10-05 22:15:56 -070091 final ConnectPoint d1p0 = connectPoint("s1", 0);
92 final ConnectPoint d1p1 = connectPoint("s1", 1);
93 final ConnectPoint d1p10 = connectPoint("s1", 10);
94 final ConnectPoint d1p11 = connectPoint("s1", 11);
Pier Ventre81c47bf2016-11-04 07:26:22 -070095 final ConnectPoint d1p12 = connectPoint("s1", 12);
Pier Ventre766995d2016-10-05 22:15:56 -070096
97 final Set<Link> links = ImmutableSet.of(
98 link(d1p1, d2p0),
99 link(d2p1, d3p1),
100 link(d1p1, d3p1)
101 );
102
103 final Set<Link> linksForMp2Sp = ImmutableSet.of(
104 link(d1p0, d2p0),
105 link(d2p1, d3p0)
106 );
107
Pier Ventre766995d2016-10-05 22:15:56 -0700108 final Set<Link> linksForSp2Mp = ImmutableSet.of(
109 link(d3p0, d2p1),
110 link(d2p0, d1p0)
111 );
112
Pier Ventreffe88d62016-10-13 14:34:40 -0700113 final Set<Link> p2pLinks = ImmutableSet.of(
114 link(d1p0, d2p0),
115 link(d2p1, d3p1)
116 );
117
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +0200118 final Set<Link> domainP2Plinks = ImmutableSet.of(
119 link(d1p0, d2p0),
120 link(d2p1, d4p1),
121 link(d4p0, d3p0)
122 );
123
Pier Ventre5c4a0762016-11-21 10:28:13 -0800124 final Set<Link> linksForSp2MpCoLoc = ImmutableSet.of(
125 link(d1p0, d2p0),
126 link(d2p1, d3p0)
127 );
128
129 final Set<Link> linksForMp2SpCoLoc = ImmutableSet.of(
130 link(d2p0, d1p0)
131 );
132
Pier Ventre766995d2016-10-05 22:15:56 -0700133 final TrafficTreatment treatment = emptyTreatment();
Pier Ventre81c47bf2016-11-04 07:26:22 -0700134 final TrafficTreatment ethDstTreatment = macDstTreatment("C0:FF:EE:C0:FF:EE");
135 final TrafficTreatment decTllTreatment = decTtlTreatment();
Pier Ventre766995d2016-10-05 22:15:56 -0700136
137 final TrafficSelector selector = emptySelector();
138 final TrafficSelector vlan69Selector = vlanSelector("69");
139 final TrafficSelector vlan100Selector = vlanSelector("100");
140 final TrafficSelector vlan200Selector = vlanSelector("200");
141 final TrafficSelector vlan300Selector = vlanSelector("300");
142 final TrafficSelector mpls69Selector = mplsSelector("69");
143 final TrafficSelector mpls80Selector = mplsSelector("80");
144 final TrafficSelector mpls100Selector = mplsSelector("100");
145 final TrafficSelector mpls200Selector = mplsSelector("200");
146 final TrafficSelector ipPrefixSelector = ipPrefixDstSelector("192.168.100.0/24");
Yi Tsenga64f0c82017-02-03 11:17:15 -0800147 final TrafficSelector ethDstSelector = ethDstSelector("C0:FF:EE:C0:FF:EE");
148 final ResourceGroup resourceGroup1 = ResourceGroup.of(1L);
149 final ResourceGroup resourceGroup2 = ResourceGroup.of(1L);
Pier Ventre766995d2016-10-05 22:15:56 -0700150
151 final List<Constraint> constraintsForVlan = vlanConstraint();
152 final List<Constraint> constraintsForMPLS = mplsConstraint();
153
154 CoreService coreService;
Thomas Szyrkowiec770093f2017-05-05 13:06:53 +0200155 DomainService domainService;
Pier Ventre766995d2016-10-05 22:15:56 -0700156 IntentExtensionService intentExtensionService;
157 IntentConfigurableRegistrator registrator;
158 IdGenerator idGenerator = new MockIdGenerator();
159
160 LinkCollectionIntent intent;
161
162 LinkCollectionIntentCompiler sut;
163
164 List<FlowRule> getFlowRulesByDevice(DeviceId deviceId, Collection<FlowRule> flowRules) {
165 return flowRules.stream()
166 .filter(fr -> fr.deviceId().equals(deviceId))
167 .collect(Collectors.toList());
168 }
169
170}