blob: 2c858ca40d76dd2f37dbd04573099c9563b05042 [file] [log] [blame]
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
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
Luca Prete670ac5d2017-02-03 15:55:43 -080055 * @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 Milkey661c38c2016-02-26 17:12:17 -080068 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 Vachuskaf6ec97b2016-02-22 10:59:23 -080072 }
73
74 /**
75 * Returns the collection of backing flow objectives.
76 *
77 * @return flow objectives
78 */
Ray Milkey661c38c2016-02-26 17:12:17 -080079 public List<Objective> objectives() {
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -080080 return objectives;
81 }
82
Ray Milkey661c38c2016-02-26 17:12:17 -080083 /**
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 Vachuskaf6ec97b2016-02-22 10:59:23 -080092
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 Milkey661c38c2016-02-26 17:12:17 -0800105 .add("device", devices())
106 .add("objectives", objectives())
Luca Prete670ac5d2017-02-03 15:55:43 -0800107 .add("resourceGroup", resourceGroup())
Thomas Vachuskaf6ec97b2016-02-22 10:59:23 -0800108 .toString();
109 }
110}