Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [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; |
| 18 | |
| 19 | import com.google.common.base.MoreObjects; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableList; |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 21 | import org.onosproject.core.ApplicationId; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 22 | import org.onosproject.net.DeviceId; |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 23 | import org.onosproject.net.NetworkResource; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 24 | import org.onosproject.net.ResourceGroup; |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 25 | import org.onosproject.net.flowobjective.Objective; |
| 26 | |
| 27 | import java.util.Collection; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 28 | import java.util.List; |
| 29 | |
| 30 | import static com.google.common.base.Preconditions.checkArgument; |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Intent expressed as (and backed by) a collection of flow objectives through |
| 34 | * which the intent is to be accomplished. |
| 35 | */ |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 36 | public final class FlowObjectiveIntent extends Intent { |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 37 | |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 38 | private final List<Objective> objectives; |
| 39 | private final List<DeviceId> devices; |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Constructor for serialization. |
| 43 | */ |
| 44 | protected FlowObjectiveIntent() { |
| 45 | super(); |
| 46 | this.objectives = null; |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 47 | this.devices = null; |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Creates a flow objective intent with the specified objectives and |
| 52 | * resources. |
| 53 | * |
| 54 | * @param appId application id |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 55 | * @param devices list of target devices; in same order as the objectives |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 56 | * @param objectives backing flow objectives |
| 57 | * @param resources backing network resources |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 58 | * @deprecated 1.9.1 |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 59 | */ |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 60 | @Deprecated |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 61 | public FlowObjectiveIntent(ApplicationId appId, |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 62 | List<DeviceId> devices, |
| 63 | List<Objective> objectives, |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 64 | Collection<NetworkResource> resources) { |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 65 | this(appId, null, devices, objectives, resources, null); |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Creates a flow objective intent with the specified objectives and |
| 70 | * resources. |
| 71 | * |
| 72 | * @param appId application id |
| 73 | * @param key intent key |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 74 | * @param devices list of target devices; in same order as the objectives |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 75 | * @param objectives backing flow objectives |
| 76 | * @param resources backing network resources |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 77 | * @deprecated 1.9.1 |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 78 | */ |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 79 | @Deprecated |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 80 | public FlowObjectiveIntent(ApplicationId appId, |
| 81 | Key key, |
| 82 | List<DeviceId> devices, |
| 83 | List<Objective> objectives, |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 84 | Collection<NetworkResource> resources) { |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 85 | this(appId, key, devices, objectives, resources, null); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Creates a flow objective intent with the specified objectives and |
| 90 | * resources. |
| 91 | * |
| 92 | * @param appId application id |
| 93 | * @param key intent key |
| 94 | * @param devices list of target devices; in same order as the objectives |
| 95 | * @param objectives backing flow objectives |
| 96 | * @param resources backing network resources |
| 97 | * @param resourceGroup resource goup for this intent |
| 98 | */ |
| 99 | public FlowObjectiveIntent(ApplicationId appId, |
| 100 | Key key, |
| 101 | List<DeviceId> devices, |
| 102 | List<Objective> objectives, |
| 103 | Collection<NetworkResource> resources, |
| 104 | ResourceGroup resourceGroup) { |
| 105 | super(appId, key, resources, DEFAULT_INTENT_PRIORITY, resourceGroup); |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 106 | checkArgument(devices.size() == objectives.size(), |
| 107 | "Number of devices and objectives does not match"); |
| 108 | this.objectives = ImmutableList.copyOf(objectives); |
| 109 | this.devices = ImmutableList.copyOf(devices); |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Returns the collection of backing flow objectives. |
| 114 | * |
| 115 | * @return flow objectives |
| 116 | */ |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 117 | public List<Objective> objectives() { |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 118 | return objectives; |
| 119 | } |
| 120 | |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 121 | /** |
| 122 | * Returns the list of devices for the flow objectives. |
| 123 | * |
| 124 | * @return devices |
| 125 | */ |
| 126 | public List<DeviceId> devices() { |
| 127 | return devices; |
| 128 | } |
| 129 | |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 130 | |
| 131 | @Override |
| 132 | public boolean isInstallable() { |
| 133 | return true; |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public String toString() { |
| 138 | return MoreObjects.toStringHelper(this) |
| 139 | .add("id", id()) |
| 140 | .add("key", key()) |
| 141 | .add("appId", appId()) |
| 142 | .add("resources", resources()) |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 143 | .add("device", devices()) |
| 144 | .add("objectives", objectives()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 145 | .add("resourceGroup", resourceGroup()) |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 146 | .toString(); |
| 147 | } |
| 148 | } |