Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 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 | |
Antonio Marsico | 4f68ec9 | 2017-03-09 11:16:32 +0100 | [diff] [blame^] | 19 | import com.google.common.collect.ImmutableList; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 20 | import org.onosproject.TestApplicationId; |
| 21 | import org.onosproject.core.ApplicationId; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 22 | import org.onosproject.net.ConnectPoint; |
| 23 | import org.onosproject.net.FilteredConnectPoint; |
Antonio Marsico | 4f68ec9 | 2017-03-09 11:16:32 +0100 | [diff] [blame^] | 24 | import org.onosproject.net.Link; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 25 | import org.onosproject.net.ResourceGroup; |
| 26 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 27 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 28 | import org.onosproject.net.flow.TrafficSelector; |
| 29 | import org.onosproject.net.flow.TrafficTreatment; |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 30 | import org.onosproject.net.intent.AbstractIntentTest; |
Antonio Marsico | 4f68ec9 | 2017-03-09 11:16:32 +0100 | [diff] [blame^] | 31 | import org.onosproject.net.intent.Constraint; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 32 | import org.onosproject.net.intent.IntentExtensionService; |
| 33 | import org.onosproject.net.intent.IntentInstallCoordinator; |
| 34 | import org.onosproject.net.intent.IntentOperationContext; |
| 35 | import org.onosproject.net.intent.Key; |
Yi Tseng | 24d9be7 | 2017-05-12 11:28:13 -0700 | [diff] [blame] | 36 | import org.onosproject.net.intent.ObjectiveTrackerService; |
Antonio Marsico | 4f68ec9 | 2017-03-09 11:16:32 +0100 | [diff] [blame^] | 37 | import org.onosproject.net.intent.PointToPointIntent; |
| 38 | |
| 39 | import java.util.List; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 40 | |
| 41 | import static org.easymock.EasyMock.createMock; |
Antonio Marsico | 4f68ec9 | 2017-03-09 11:16:32 +0100 | [diff] [blame^] | 42 | import static org.onosproject.net.NetTestTools.link; |
| 43 | import static org.onosproject.net.intent.constraint.NonDisruptiveConstraint.nonDisruptive; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Abstract class to hold the common variables and pieces of code for Intent |
| 47 | * installer test. |
| 48 | */ |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 49 | public class AbstractIntentInstallerTest extends AbstractIntentTest { |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 50 | protected static final ApplicationId APP_ID = TestApplicationId.create("IntentInstallerTest"); |
Antonio Marsico | 4f68ec9 | 2017-03-09 11:16:32 +0100 | [diff] [blame^] | 51 | |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 52 | 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 Marsico | 4f68ec9 | 2017-03-09 11:16:32 +0100 | [diff] [blame^] | 55 | |
| 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 Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 71 | 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 Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 74 | |
| 75 | protected IntentExtensionService intentExtensionService; |
| 76 | protected ObjectiveTrackerService trackerService; |
| 77 | protected TestIntentInstallCoordinator intentInstallCoordinator; |
| 78 | |
| 79 | public void setup() { |
Thomas Vachuska | 2048c1f | 2017-05-10 19:32:22 -0700 | [diff] [blame] | 80 | super.setUp(); |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 81 | intentExtensionService = createMock(IntentExtensionService.class); |
| 82 | trackerService = createMock(ObjectiveTrackerService.class); |
| 83 | intentInstallCoordinator = new TestIntentInstallCoordinator(); |
| 84 | } |
| 85 | |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 86 | /** |
| 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 Marsico | 4f68ec9 | 2017-03-09 11:16:32 +0100 | [diff] [blame^] | 111 | * 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 Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 138 | * 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 | } |