Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.net.intent.impl.installer; |
| 18 | |
| 19 | import org.onosproject.TestApplicationId; |
| 20 | import org.onosproject.core.ApplicationId; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 21 | import org.onosproject.net.ConnectPoint; |
| 22 | import org.onosproject.net.FilteredConnectPoint; |
| 23 | import org.onosproject.net.ResourceGroup; |
| 24 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 25 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 26 | import org.onosproject.net.flow.TrafficSelector; |
| 27 | import org.onosproject.net.flow.TrafficTreatment; |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame^] | 28 | import org.onosproject.net.intent.AbstractIntentTest; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 29 | import org.onosproject.net.intent.IntentExtensionService; |
| 30 | import org.onosproject.net.intent.IntentInstallCoordinator; |
| 31 | import org.onosproject.net.intent.IntentOperationContext; |
| 32 | import org.onosproject.net.intent.Key; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 33 | import org.onosproject.net.intent.PointToPointIntent; |
| 34 | import org.onosproject.net.intent.impl.ObjectiveTrackerService; |
| 35 | |
| 36 | import 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 Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame^] | 42 | public class AbstractIntentInstallerTest extends AbstractIntentTest { |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 43 | 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 Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 50 | |
| 51 | protected IntentExtensionService intentExtensionService; |
| 52 | protected ObjectiveTrackerService trackerService; |
| 53 | protected TestIntentInstallCoordinator intentInstallCoordinator; |
| 54 | |
| 55 | public void setup() { |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame^] | 56 | super.setUp(); |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 57 | intentExtensionService = createMock(IntentExtensionService.class); |
| 58 | trackerService = createMock(ObjectiveTrackerService.class); |
| 59 | intentInstallCoordinator = new TestIntentInstallCoordinator(); |
| 60 | } |
| 61 | |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 62 | /** |
| 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 | } |