blob: f7389e7fdff621fc517762b4e45496ec127ad238 [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;
27import org.onosproject.net.flow.FlowRule;
28import org.onosproject.net.flow.TrafficSelector;
29import org.onosproject.net.flow.TrafficTreatment;
30import org.onosproject.net.intent.Constraint;
31import org.onosproject.net.intent.IntentExtensionService;
32import org.onosproject.net.intent.LinkCollectionIntent;
33import org.onosproject.net.intent.MockIdGenerator;
34
35import java.util.Collection;
36import java.util.List;
37import java.util.Set;
38import java.util.stream.Collectors;
39
40import static org.onosproject.net.NetTestTools.*;
41import static org.onosproject.net.NetTestTools.macDstTreatment;
42
43/**
44 * Abstract class to hold the common variables and pieces
45 * of code.
46 */
47class AbstractLinkCollectionTest {
48
49 static final String LABEL_SELECTION = "FIRST_FIT";
50 static final String LABEL = "1";
51
52 final ApplicationId appId = new TestApplicationId("test");
53
54 final ConnectPoint d2p0 = connectPoint("s2", 0);
55 final ConnectPoint d2p1 = connectPoint("s2", 1);
Pier Ventre81c47bf2016-11-04 07:26:22 -070056 final ConnectPoint d2p10 = connectPoint("s2", 10);
Pier Ventre766995d2016-10-05 22:15:56 -070057
58 final ConnectPoint d3p0 = connectPoint("s3", 0);
59 final ConnectPoint d3p1 = connectPoint("s3", 1);
60 final ConnectPoint d3p10 = connectPoint("s3", 10);
61
62 final DeviceId of1Id = DeviceId.deviceId("of:of1");
63 final DeviceId of2Id = DeviceId.deviceId("of:of2");
64 final DeviceId of3Id = DeviceId.deviceId("of:of3");
65 final DeviceId of4Id = DeviceId.deviceId("of:of4");
66
67 final ConnectPoint of1p1 = connectPoint("of1", 1);
68 final ConnectPoint of1p2 = connectPoint("of1", 2);
69 final ConnectPoint of2p1 = connectPoint("of2", 1);
70 final ConnectPoint of2p2 = connectPoint("of2", 2);
71 final ConnectPoint of2p3 = connectPoint("of2", 3);
72 final ConnectPoint of3p1 = connectPoint("of3", 1);
73 final ConnectPoint of3p2 = connectPoint("of3", 2);
74 final ConnectPoint of4p1 = connectPoint("of4", 1);
75 final ConnectPoint of4p2 = connectPoint("of4", 2);
76
77 final ConnectPoint d1p0 = connectPoint("s1", 0);
78 final ConnectPoint d1p1 = connectPoint("s1", 1);
79 final ConnectPoint d1p10 = connectPoint("s1", 10);
80 final ConnectPoint d1p11 = connectPoint("s1", 11);
Pier Ventre81c47bf2016-11-04 07:26:22 -070081 final ConnectPoint d1p12 = connectPoint("s1", 12);
Pier Ventre766995d2016-10-05 22:15:56 -070082
83 final Set<Link> links = ImmutableSet.of(
84 link(d1p1, d2p0),
85 link(d2p1, d3p1),
86 link(d1p1, d3p1)
87 );
88
89 final Set<Link> linksForMp2Sp = ImmutableSet.of(
90 link(d1p0, d2p0),
91 link(d2p1, d3p0)
92 );
93
94
95
96 final Set<Link> linksForSp2Mp = ImmutableSet.of(
97 link(d3p0, d2p1),
98 link(d2p0, d1p0)
99 );
100
101 final TrafficTreatment treatment = emptyTreatment();
Pier Ventre81c47bf2016-11-04 07:26:22 -0700102 final TrafficTreatment ethDstTreatment = macDstTreatment("C0:FF:EE:C0:FF:EE");
103 final TrafficTreatment decTllTreatment = decTtlTreatment();
Pier Ventre766995d2016-10-05 22:15:56 -0700104
105 final TrafficSelector selector = emptySelector();
106 final TrafficSelector vlan69Selector = vlanSelector("69");
107 final TrafficSelector vlan100Selector = vlanSelector("100");
108 final TrafficSelector vlan200Selector = vlanSelector("200");
109 final TrafficSelector vlan300Selector = vlanSelector("300");
110 final TrafficSelector mpls69Selector = mplsSelector("69");
111 final TrafficSelector mpls80Selector = mplsSelector("80");
112 final TrafficSelector mpls100Selector = mplsSelector("100");
113 final TrafficSelector mpls200Selector = mplsSelector("200");
114 final TrafficSelector ipPrefixSelector = ipPrefixDstSelector("192.168.100.0/24");
Pier Ventre766995d2016-10-05 22:15:56 -0700115
116 final List<Constraint> constraintsForVlan = vlanConstraint();
117 final List<Constraint> constraintsForMPLS = mplsConstraint();
118
119 CoreService coreService;
120 IntentExtensionService intentExtensionService;
121 IntentConfigurableRegistrator registrator;
122 IdGenerator idGenerator = new MockIdGenerator();
123
124 LinkCollectionIntent intent;
125
126 LinkCollectionIntentCompiler sut;
127
128 List<FlowRule> getFlowRulesByDevice(DeviceId deviceId, Collection<FlowRule> flowRules) {
129 return flowRules.stream()
130 .filter(fr -> fr.deviceId().equals(deviceId))
131 .collect(Collectors.toList());
132 }
133
134}