blob: a7725bd6829b6c73569b2d402bf471d3f45d5fed [file] [log] [blame]
Yi Tsengc927a062017-05-02 15:02:37 -07001/*
2 * Copyright 2017-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.installer;
18
19import org.onosproject.TestApplicationId;
20import org.onosproject.core.ApplicationId;
Yi Tsengc927a062017-05-02 15:02:37 -070021import org.onosproject.net.ConnectPoint;
22import org.onosproject.net.FilteredConnectPoint;
23import org.onosproject.net.ResourceGroup;
24import org.onosproject.net.flow.DefaultTrafficSelector;
25import org.onosproject.net.flow.DefaultTrafficTreatment;
26import org.onosproject.net.flow.TrafficSelector;
27import org.onosproject.net.flow.TrafficTreatment;
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070028import org.onosproject.net.intent.AbstractIntentTest;
Yi Tsengc927a062017-05-02 15:02:37 -070029import org.onosproject.net.intent.IntentExtensionService;
30import org.onosproject.net.intent.IntentInstallCoordinator;
31import org.onosproject.net.intent.IntentOperationContext;
32import org.onosproject.net.intent.Key;
Yi Tsengc927a062017-05-02 15:02:37 -070033import org.onosproject.net.intent.PointToPointIntent;
34import org.onosproject.net.intent.impl.ObjectiveTrackerService;
35
36import static org.easymock.EasyMock.createMock;
37
38/**
39 * Abstract class to hold the common variables and pieces of code for Intent
40 * installer test.
41 */
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070042public class AbstractIntentInstallerTest extends AbstractIntentTest {
Yi Tsengc927a062017-05-02 15:02:37 -070043 protected static final ApplicationId APP_ID = TestApplicationId.create("IntentInstallerTest");
44 protected static final ConnectPoint CP1 = ConnectPoint.deviceConnectPoint("s1/1");
45 protected static final ConnectPoint CP2 = ConnectPoint.deviceConnectPoint("s1/2");
46 protected static final ConnectPoint CP3 = ConnectPoint.deviceConnectPoint("s1/3");
47 protected static final Key KEY1 = Key.of("test intent 1", APP_ID);
48 protected static final ResourceGroup RG1 = ResourceGroup.of("test resource group 1");
49 protected static final int DEFAULT_PRIORITY = 30000;
Yi Tsengc927a062017-05-02 15:02:37 -070050
51 protected IntentExtensionService intentExtensionService;
52 protected ObjectiveTrackerService trackerService;
53 protected TestIntentInstallCoordinator intentInstallCoordinator;
54
55 public void setup() {
Thomas Vachuska2048c1f2017-05-10 19:32:22 -070056 super.setUp();
Yi Tsengc927a062017-05-02 15:02:37 -070057 intentExtensionService = createMock(IntentExtensionService.class);
58 trackerService = createMock(ObjectiveTrackerService.class);
59 intentInstallCoordinator = new TestIntentInstallCoordinator();
60 }
61
Yi Tsengc927a062017-05-02 15:02:37 -070062 /**
63 * Creates point to point Intent for test.
64 *
65 * @return the point to point Intent
66 */
67 public PointToPointIntent createP2PIntent() {
68 PointToPointIntent intent;
69 TrafficSelector selector = DefaultTrafficSelector.emptySelector();
70 TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
71
72 FilteredConnectPoint ingress = new FilteredConnectPoint(CP1);
73 FilteredConnectPoint egress = new FilteredConnectPoint(CP2);
74
75 intent = PointToPointIntent.builder()
76 .selector(selector)
77 .treatment(treatment)
78 .filteredIngressPoint(ingress)
79 .filteredEgressPoint(egress)
80 .appId(APP_ID)
81 .build();
82
83 return intent;
84 }
85
86 /**
87 * The Intent install coordinator for test.
88 * Records success and fail context.
89 */
90 class TestIntentInstallCoordinator implements IntentInstallCoordinator {
91
92 IntentOperationContext successContext;
93 IntentOperationContext failedContext;
94
95 @Override
96 public void intentInstallSuccess(IntentOperationContext context) {
97 successContext = context;
98 }
99
100 @Override
101 public void intentInstallFailed(IntentOperationContext context) {
102 failedContext = context;
103 }
104 }
105
106}