blob: a439103e5ae624f1f16f39d9cce1e4895a0c6bc5 [file] [log] [blame]
Yi Tsengc927a062017-05-02 15:02:37 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yi Tsengc927a062017-05-02 15:02:37 -07003 *
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.installer;
18
Antonio Marsico4f68ec92017-03-09 11:16:32 +010019import com.google.common.collect.ImmutableList;
Yi Tsengc927a062017-05-02 15:02:37 -070020import org.onosproject.TestApplicationId;
21import org.onosproject.core.ApplicationId;
Yi Tsengc927a062017-05-02 15:02:37 -070022import org.onosproject.net.ConnectPoint;
23import org.onosproject.net.FilteredConnectPoint;
Antonio Marsico4f68ec92017-03-09 11:16:32 +010024import org.onosproject.net.Link;
Yi Tsengc927a062017-05-02 15:02:37 -070025import org.onosproject.net.ResourceGroup;
26import org.onosproject.net.flow.DefaultTrafficSelector;
27import org.onosproject.net.flow.DefaultTrafficTreatment;
28import org.onosproject.net.flow.TrafficSelector;
29import org.onosproject.net.flow.TrafficTreatment;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070030import org.onosproject.net.intent.AbstractIntentTest;
Antonio Marsico4f68ec92017-03-09 11:16:32 +010031import org.onosproject.net.intent.Constraint;
Yi Tsengc927a062017-05-02 15:02:37 -070032import org.onosproject.net.intent.IntentExtensionService;
33import org.onosproject.net.intent.IntentInstallCoordinator;
34import org.onosproject.net.intent.IntentOperationContext;
35import org.onosproject.net.intent.Key;
Yi Tseng24d9be72017-05-12 11:28:13 -070036import org.onosproject.net.intent.ObjectiveTrackerService;
Antonio Marsico4f68ec92017-03-09 11:16:32 +010037import org.onosproject.net.intent.PointToPointIntent;
38
39import java.util.List;
Yi Tsengc927a062017-05-02 15:02:37 -070040
41import static org.easymock.EasyMock.createMock;
Antonio Marsico4f68ec92017-03-09 11:16:32 +010042import static org.onosproject.net.NetTestTools.link;
43import static org.onosproject.net.intent.constraint.NonDisruptiveConstraint.nonDisruptive;
Yi Tsengc927a062017-05-02 15:02:37 -070044
45/**
46 * Abstract class to hold the common variables and pieces of code for Intent
47 * installer test.
48 */
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070049public class AbstractIntentInstallerTest extends AbstractIntentTest {
Yi Tsengc927a062017-05-02 15:02:37 -070050 protected static final ApplicationId APP_ID = TestApplicationId.create("IntentInstallerTest");
Antonio Marsico4f68ec92017-03-09 11:16:32 +010051
Yi Tsengc927a062017-05-02 15:02:37 -070052 protected static final ConnectPoint CP1 = ConnectPoint.deviceConnectPoint("s1/1");
53 protected static final ConnectPoint CP2 = ConnectPoint.deviceConnectPoint("s1/2");
54 protected static final ConnectPoint CP3 = ConnectPoint.deviceConnectPoint("s1/3");
Antonio Marsico4f68ec92017-03-09 11:16:32 +010055
56 protected static final ConnectPoint CP2_1 = ConnectPoint.deviceConnectPoint("s2/1");
57 protected static final ConnectPoint CP2_2 = ConnectPoint.deviceConnectPoint("s2/2");
58
59 protected static final ConnectPoint CP3_1 = ConnectPoint.deviceConnectPoint("s3/1");
60 protected static final ConnectPoint CP3_2 = ConnectPoint.deviceConnectPoint("s3/2");
61
62 protected static final ConnectPoint CP4_1 = ConnectPoint.deviceConnectPoint("s4/1");
63 protected static final ConnectPoint CP4_2 = ConnectPoint.deviceConnectPoint("s4/2");
64 protected static final ConnectPoint CP4_3 = ConnectPoint.deviceConnectPoint("s4/3");
65
66 protected static final Link S1_S2 = link(CP2, CP2_1);
67 protected static final Link S2_S4 = link(CP2_2, CP4_2);
68 protected static final Link S1_S3 = link(CP3, CP3_1);
69 protected static final Link S3_S4 = link(CP3_2, CP4_3);
70
Yi Tsengc927a062017-05-02 15:02:37 -070071 protected static final Key KEY1 = Key.of("test intent 1", APP_ID);
72 protected static final ResourceGroup RG1 = ResourceGroup.of("test resource group 1");
73 protected static final int DEFAULT_PRIORITY = 30000;
Yi Tsengc927a062017-05-02 15:02:37 -070074
75 protected IntentExtensionService intentExtensionService;
76 protected ObjectiveTrackerService trackerService;
77 protected TestIntentInstallCoordinator intentInstallCoordinator;
78
79 public void setup() {
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070080 super.setUp();
Yi Tsengc927a062017-05-02 15:02:37 -070081 intentExtensionService = createMock(IntentExtensionService.class);
82 trackerService = createMock(ObjectiveTrackerService.class);
83 intentInstallCoordinator = new TestIntentInstallCoordinator();
84 }
85
Yi Tsengc927a062017-05-02 15:02:37 -070086 /**
87 * Creates point to point Intent for test.
88 *
89 * @return the point to point Intent
90 */
91 public PointToPointIntent createP2PIntent() {
92 PointToPointIntent intent;
93 TrafficSelector selector = DefaultTrafficSelector.emptySelector();
94 TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
95
96 FilteredConnectPoint ingress = new FilteredConnectPoint(CP1);
97 FilteredConnectPoint egress = new FilteredConnectPoint(CP2);
98
99 intent = PointToPointIntent.builder()
100 .selector(selector)
101 .treatment(treatment)
102 .filteredIngressPoint(ingress)
103 .filteredEgressPoint(egress)
104 .appId(APP_ID)
105 .build();
106
107 return intent;
108 }
109
110 /**
Antonio Marsico4f68ec92017-03-09 11:16:32 +0100111 * Creates point to point Intent for testing non-disruptive reallocation.
112 *
113 * @return the point to point Intent
114 */
115 public PointToPointIntent createP2PIntentNonDisruptive() {
116 PointToPointIntent intent;
117 TrafficSelector selector = DefaultTrafficSelector.emptySelector();
118 TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
119
120 FilteredConnectPoint ingress = new FilteredConnectPoint(CP1);
121 FilteredConnectPoint egress = new FilteredConnectPoint(CP4_1);
122
123 List<Constraint> constraints = ImmutableList.of(nonDisruptive());
124
125 intent = PointToPointIntent.builder()
126 .selector(selector)
127 .treatment(treatment)
128 .filteredIngressPoint(ingress)
129 .filteredEgressPoint(egress)
130 .constraints(constraints)
131 .appId(APP_ID)
132 .build();
133
134 return intent;
135 }
136
137 /**
Yi Tsengc927a062017-05-02 15:02:37 -0700138 * The Intent install coordinator for test.
139 * Records success and fail context.
140 */
141 class TestIntentInstallCoordinator implements IntentInstallCoordinator {
142
143 IntentOperationContext successContext;
144 IntentOperationContext failedContext;
145
146 @Override
147 public void intentInstallSuccess(IntentOperationContext context) {
148 successContext = context;
149 }
150
151 @Override
152 public void intentInstallFailed(IntentOperationContext context) {
153 failedContext = context;
154 }
155 }
156
157}