blob: e1529e3af96d902bb7f9aeb61c7700b51443e403 [file] [log] [blame]
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -08003 *
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;
18
19import com.google.common.base.MoreObjects;
Ray Milkey661c38c2016-02-26 17:12:17 -080020import com.google.common.collect.ImmutableList;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080021import org.onosproject.core.ApplicationId;
Ray Milkey661c38c2016-02-26 17:12:17 -080022import org.onosproject.net.DeviceId;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080023import org.onosproject.net.NetworkResource;
Luca Prete670ac5d2017-02-03 15:55:43 -080024import org.onosproject.net.ResourceGroup;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080025import org.onosproject.net.flowobjective.Objective;
26
27import java.util.Collection;
Ray Milkey661c38c2016-02-26 17:12:17 -080028import java.util.List;
29
30import static com.google.common.base.Preconditions.checkArgument;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080031
32/**
33 * Intent expressed as (and backed by) a collection of flow objectives through
34 * which the intent is to be accomplished.
35 */
Ray Milkey661c38c2016-02-26 17:12:17 -080036public final class FlowObjectiveIntent extends Intent {
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080037
Ray Milkey661c38c2016-02-26 17:12:17 -080038 private final List<Objective> objectives;
39 private final List<DeviceId> devices;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080040
41 /**
42 * Constructor for serialization.
43 */
44 protected FlowObjectiveIntent() {
45 super();
46 this.objectives = null;
Ray Milkey661c38c2016-02-26 17:12:17 -080047 this.devices = null;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080048 }
49
50 /**
51 * Creates a flow objective intent with the specified objectives and
52 * resources.
53 *
54 * @param appId application id
Ray Milkey661c38c2016-02-26 17:12:17 -080055 * @param devices list of target devices; in same order as the objectives
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080056 * @param objectives backing flow objectives
57 * @param resources backing network resources
Luca Prete670ac5d2017-02-03 15:55:43 -080058 * @deprecated 1.9.1
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080059 */
Luca Prete670ac5d2017-02-03 15:55:43 -080060 @Deprecated
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080061 public FlowObjectiveIntent(ApplicationId appId,
Ray Milkey661c38c2016-02-26 17:12:17 -080062 List<DeviceId> devices,
63 List<Objective> objectives,
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080064 Collection<NetworkResource> resources) {
Luca Prete670ac5d2017-02-03 15:55:43 -080065 this(appId, null, devices, objectives, resources, null);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080066 }
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 Milkey661c38c2016-02-26 17:12:17 -080074 * @param devices list of target devices; in same order as the objectives
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080075 * @param objectives backing flow objectives
76 * @param resources backing network resources
Luca Prete670ac5d2017-02-03 15:55:43 -080077 * @deprecated 1.9.1
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080078 */
Luca Prete670ac5d2017-02-03 15:55:43 -080079 @Deprecated
Ray Milkey661c38c2016-02-26 17:12:17 -080080 public FlowObjectiveIntent(ApplicationId appId,
81 Key key,
82 List<DeviceId> devices,
83 List<Objective> objectives,
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080084 Collection<NetworkResource> resources) {
Luca Prete670ac5d2017-02-03 15:55:43 -080085 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 Milkey661c38c2016-02-26 17:12:17 -0800106 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 Vachuskaf6ec97b2016-02-22 10:59:23 -0800110 }
111
112 /**
113 * Returns the collection of backing flow objectives.
114 *
115 * @return flow objectives
116 */
Ray Milkey661c38c2016-02-26 17:12:17 -0800117 public List<Objective> objectives() {
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -0800118 return objectives;
119 }
120
Ray Milkey661c38c2016-02-26 17:12:17 -0800121 /**
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 Vachuskaf6ec97b2016-02-22 10:59:23 -0800130
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 Milkey661c38c2016-02-26 17:12:17 -0800143 .add("device", devices())
144 .add("objectives", objectives())
Luca Prete670ac5d2017-02-03 15:55:43 -0800145 .add("resourceGroup", resourceGroup())
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -0800146 .toString();
147 }
148}