blob: f6e5dc810e8c819efba1f780f717eba86cb6c32f [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;
Pier Ventre766995d2016-10-05 22:15:56 -070028import org.onosproject.net.flow.FlowRule;
29import org.onosproject.net.flow.TrafficSelector;
30import org.onosproject.net.flow.TrafficTreatment;
31import org.onosproject.net.intent.Constraint;
32import org.onosproject.net.intent.IntentExtensionService;
33import org.onosproject.net.intent.LinkCollectionIntent;
34import org.onosproject.net.intent.MockIdGenerator;
35
36import java.util.Collection;
37import java.util.List;
38import java.util.Set;
39import java.util.stream.Collectors;
40
41import static org.onosproject.net.NetTestTools.*;
42import static org.onosproject.net.NetTestTools.macDstTreatment;
43
44/**
45 * Abstract class to hold the common variables and pieces
46 * of code.
47 */
48class AbstractLinkCollectionTest {
49
50 static final String LABEL_SELECTION = "FIRST_FIT";
51 static final String LABEL = "1";
52
53 final ApplicationId appId = new TestApplicationId("test");
54
55 final ConnectPoint d2p0 = connectPoint("s2", 0);
56 final ConnectPoint d2p1 = connectPoint("s2", 1);
Pier Ventre81c47bf2016-11-04 07:26:22 -070057 final ConnectPoint d2p10 = connectPoint("s2", 10);
Pier Ventre766995d2016-10-05 22:15:56 -070058
59 final ConnectPoint d3p0 = connectPoint("s3", 0);
60 final ConnectPoint d3p1 = connectPoint("s3", 1);
61 final ConnectPoint d3p10 = connectPoint("s3", 10);
62
63 final DeviceId of1Id = DeviceId.deviceId("of:of1");
64 final DeviceId of2Id = DeviceId.deviceId("of:of2");
65 final DeviceId of3Id = DeviceId.deviceId("of:of3");
66 final DeviceId of4Id = DeviceId.deviceId("of:of4");
67
68 final ConnectPoint of1p1 = connectPoint("of1", 1);
69 final ConnectPoint of1p2 = connectPoint("of1", 2);
Yi Tsenga64f0c82017-02-03 11:17:15 -080070 final ConnectPoint of1p3 = connectPoint("of1", 3);
Pier Ventre766995d2016-10-05 22:15:56 -070071 final ConnectPoint of2p1 = connectPoint("of2", 1);
72 final ConnectPoint of2p2 = connectPoint("of2", 2);
73 final ConnectPoint of2p3 = connectPoint("of2", 3);
74 final ConnectPoint of3p1 = connectPoint("of3", 1);
75 final ConnectPoint of3p2 = connectPoint("of3", 2);
76 final ConnectPoint of4p1 = connectPoint("of4", 1);
77 final ConnectPoint of4p2 = connectPoint("of4", 2);
78
79 final ConnectPoint d1p0 = connectPoint("s1", 0);
80 final ConnectPoint d1p1 = connectPoint("s1", 1);
81 final ConnectPoint d1p10 = connectPoint("s1", 10);
82 final ConnectPoint d1p11 = connectPoint("s1", 11);
Pier Ventre81c47bf2016-11-04 07:26:22 -070083 final ConnectPoint d1p12 = connectPoint("s1", 12);
Pier Ventre766995d2016-10-05 22:15:56 -070084
85 final Set<Link> links = ImmutableSet.of(
86 link(d1p1, d2p0),
87 link(d2p1, d3p1),
88 link(d1p1, d3p1)
89 );
90
91 final Set<Link> linksForMp2Sp = ImmutableSet.of(
92 link(d1p0, d2p0),
93 link(d2p1, d3p0)
94 );
95
Pier Ventre766995d2016-10-05 22:15:56 -070096 final Set<Link> linksForSp2Mp = ImmutableSet.of(
97 link(d3p0, d2p1),
98 link(d2p0, d1p0)
99 );
100
Pier Ventreffe88d62016-10-13 14:34:40 -0700101 final Set<Link> p2pLinks = ImmutableSet.of(
102 link(d1p0, d2p0),
103 link(d2p1, d3p1)
104 );
105
Pier Ventre5c4a0762016-11-21 10:28:13 -0800106 final Set<Link> linksForSp2MpCoLoc = ImmutableSet.of(
107 link(d1p0, d2p0),
108 link(d2p1, d3p0)
109 );
110
111 final Set<Link> linksForMp2SpCoLoc = ImmutableSet.of(
112 link(d2p0, d1p0)
113 );
114
Pier Ventre766995d2016-10-05 22:15:56 -0700115 final TrafficTreatment treatment = emptyTreatment();
Pier Ventre81c47bf2016-11-04 07:26:22 -0700116 final TrafficTreatment ethDstTreatment = macDstTreatment("C0:FF:EE:C0:FF:EE");
117 final TrafficTreatment decTllTreatment = decTtlTreatment();
Pier Ventre766995d2016-10-05 22:15:56 -0700118
119 final TrafficSelector selector = emptySelector();
120 final TrafficSelector vlan69Selector = vlanSelector("69");
121 final TrafficSelector vlan100Selector = vlanSelector("100");
122 final TrafficSelector vlan200Selector = vlanSelector("200");
123 final TrafficSelector vlan300Selector = vlanSelector("300");
124 final TrafficSelector mpls69Selector = mplsSelector("69");
125 final TrafficSelector mpls80Selector = mplsSelector("80");
126 final TrafficSelector mpls100Selector = mplsSelector("100");
127 final TrafficSelector mpls200Selector = mplsSelector("200");
128 final TrafficSelector ipPrefixSelector = ipPrefixDstSelector("192.168.100.0/24");
Yi Tsenga64f0c82017-02-03 11:17:15 -0800129 final TrafficSelector ethDstSelector = ethDstSelector("C0:FF:EE:C0:FF:EE");
130 final ResourceGroup resourceGroup1 = ResourceGroup.of(1L);
131 final ResourceGroup resourceGroup2 = ResourceGroup.of(1L);
Pier Ventre766995d2016-10-05 22:15:56 -0700132
133 final List<Constraint> constraintsForVlan = vlanConstraint();
134 final List<Constraint> constraintsForMPLS = mplsConstraint();
135
136 CoreService coreService;
137 IntentExtensionService intentExtensionService;
138 IntentConfigurableRegistrator registrator;
139 IdGenerator idGenerator = new MockIdGenerator();
140
141 LinkCollectionIntent intent;
142
143 LinkCollectionIntentCompiler sut;
144
145 List<FlowRule> getFlowRulesByDevice(DeviceId deviceId, Collection<FlowRule> flowRules) {
146 return flowRules.stream()
147 .filter(fr -> fr.deviceId().equals(deviceId))
148 .collect(Collectors.toList());
149 }
150
151}