Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
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 |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 55 | * @param key intent key |
| 56 | * @param devices list of target devices; in same order as the objectives |
| 57 | * @param objectives backing flow objectives |
| 58 | * @param resources backing network resources |
| 59 | * @param resourceGroup resource goup for this intent |
| 60 | */ |
| 61 | public FlowObjectiveIntent(ApplicationId appId, |
| 62 | Key key, |
| 63 | List<DeviceId> devices, |
| 64 | List<Objective> objectives, |
| 65 | Collection<NetworkResource> resources, |
| 66 | ResourceGroup resourceGroup) { |
| 67 | super(appId, key, resources, DEFAULT_INTENT_PRIORITY, resourceGroup); |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 68 | checkArgument(devices.size() == objectives.size(), |
| 69 | "Number of devices and objectives does not match"); |
| 70 | this.objectives = ImmutableList.copyOf(objectives); |
| 71 | this.devices = ImmutableList.copyOf(devices); |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Returns the collection of backing flow objectives. |
| 76 | * |
| 77 | * @return flow objectives |
| 78 | */ |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 79 | public List<Objective> objectives() { |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 80 | return objectives; |
| 81 | } |
| 82 | |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 83 | /** |
| 84 | * Returns the list of devices for the flow objectives. |
| 85 | * |
| 86 | * @return devices |
| 87 | */ |
| 88 | public List<DeviceId> devices() { |
| 89 | return devices; |
| 90 | } |
| 91 | |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 92 | |
| 93 | @Override |
| 94 | public boolean isInstallable() { |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public String toString() { |
| 100 | return MoreObjects.toStringHelper(this) |
| 101 | .add("id", id()) |
| 102 | .add("key", key()) |
| 103 | .add("appId", appId()) |
| 104 | .add("resources", resources()) |
Ray Milkey | 661c38c | 2016-02-26 17:12:17 -0800 | [diff] [blame] | 105 | .add("device", devices()) |
| 106 | .add("objectives", objectives()) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 107 | .add("resourceGroup", resourceGroup()) |
Thomas Vachuska | f6ec97b | 2016-02-22 10:59:23 -0800 | [diff] [blame] | 108 | .toString(); |
| 109 | } |
| 110 | } |