blob: b22a7ae7470b667500e964be9f3095730f487677 [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;
24import org.onosproject.net.flowobjective.Objective;
25
26import java.util.Collection;
Ray Milkey661c38c2016-02-26 17:12:17 -080027import java.util.List;
28
29import static com.google.common.base.Preconditions.checkArgument;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080030
31/**
32 * Intent expressed as (and backed by) a collection of flow objectives through
33 * which the intent is to be accomplished.
34 */
Ray Milkey661c38c2016-02-26 17:12:17 -080035public final class FlowObjectiveIntent extends Intent {
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080036
Ray Milkey661c38c2016-02-26 17:12:17 -080037 private final List<Objective> objectives;
38 private final List<DeviceId> devices;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080039
40 /**
41 * Constructor for serialization.
42 */
43 protected FlowObjectiveIntent() {
44 super();
45 this.objectives = null;
Ray Milkey661c38c2016-02-26 17:12:17 -080046 this.devices = null;
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080047 }
48
49 /**
50 * Creates a flow objective intent with the specified objectives and
51 * resources.
52 *
53 * @param appId application id
Ray Milkey661c38c2016-02-26 17:12:17 -080054 * @param devices list of target devices; in same order as the objectives
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080055 * @param objectives backing flow objectives
56 * @param resources backing network resources
57 */
58 public FlowObjectiveIntent(ApplicationId appId,
Ray Milkey661c38c2016-02-26 17:12:17 -080059 List<DeviceId> devices,
60 List<Objective> objectives,
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080061 Collection<NetworkResource> resources) {
Ray Milkey661c38c2016-02-26 17:12:17 -080062 this(appId, null, devices, objectives, resources);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080063 }
64
65 /**
66 * Creates a flow objective intent with the specified objectives and
67 * resources.
68 *
69 * @param appId application id
70 * @param key intent key
Ray Milkey661c38c2016-02-26 17:12:17 -080071 * @param devices list of target devices; in same order as the objectives
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080072 * @param objectives backing flow objectives
73 * @param resources backing network resources
74 */
Ray Milkey661c38c2016-02-26 17:12:17 -080075 public FlowObjectiveIntent(ApplicationId appId,
76 Key key,
77 List<DeviceId> devices,
78 List<Objective> objectives,
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080079 Collection<NetworkResource> resources) {
80 super(appId, key, resources, DEFAULT_INTENT_PRIORITY);
Ray Milkey661c38c2016-02-26 17:12:17 -080081 checkArgument(devices.size() == objectives.size(),
82 "Number of devices and objectives does not match");
83 this.objectives = ImmutableList.copyOf(objectives);
84 this.devices = ImmutableList.copyOf(devices);
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080085 }
86
87 /**
88 * Returns the collection of backing flow objectives.
89 *
90 * @return flow objectives
91 */
Ray Milkey661c38c2016-02-26 17:12:17 -080092 public List<Objective> objectives() {
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080093 return objectives;
94 }
95
Ray Milkey661c38c2016-02-26 17:12:17 -080096 /**
97 * Returns the list of devices for the flow objectives.
98 *
99 * @return devices
100 */
101 public List<DeviceId> devices() {
102 return devices;
103 }
104
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -0800105
106 @Override
107 public boolean isInstallable() {
108 return true;
109 }
110
111 @Override
112 public String toString() {
113 return MoreObjects.toStringHelper(this)
114 .add("id", id())
115 .add("key", key())
116 .add("appId", appId())
117 .add("resources", resources())
Ray Milkey661c38c2016-02-26 17:12:17 -0800118 .add("device", devices())
119 .add("objectives", objectives())
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -0800120 .toString();
121 }
122}