blob: 9f4b9b90ceb6472f89f76c5ac193f02782f16102 [file] [log] [blame]
Sho SHIMIZUee2aa652015-02-25 18:56:43 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Sho SHIMIZUee2aa652015-02-25 18:56:43 -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 */
16package org.onosproject.net.intent;
17
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080019import com.google.common.base.MoreObjects;
20import com.google.common.collect.ImmutableList;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.net.NetworkResource;
Luca Prete670ac5d2017-02-03 15:55:43 -080023import org.onosproject.net.ResourceGroup;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080024import org.onosproject.net.flow.FlowRule;
25
26import java.util.Collection;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080027import java.util.List;
28
29import static com.google.common.base.Preconditions.checkNotNull;
30
31/**
32 * An intent that enables to tell flow level operation.
33 * This instance holds a collection of flow rules that may be executed in parallel.
34 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040035@Beta
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080036public class FlowRuleIntent extends Intent {
37
38 private final Collection<FlowRule> flowRules;
helenyrwu2a674902016-07-20 09:48:04 -070039 private PathIntent.ProtectionType type;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080040
41 /**
Sho SHIMIZU2de94492015-04-23 17:33:59 +090042 * Creates a flow rule intent with the specified flow rules and resources.
43 *
44 * @param appId application id
45 * @param flowRules flow rules to be set
46 * @param resources network resource to be set
Luca Prete670ac5d2017-02-03 15:55:43 -080047 * @deprecated 1.9.1
Sho SHIMIZU2de94492015-04-23 17:33:59 +090048 */
Luca Prete670ac5d2017-02-03 15:55:43 -080049 @Deprecated
Sho SHIMIZU2de94492015-04-23 17:33:59 +090050 public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules, Collection<NetworkResource> resources) {
51 this(appId, null, flowRules, resources);
52 }
53
54 /**
helenyrwu2a674902016-07-20 09:48:04 -070055 * Creates a flow rule intent with the specified flow rules, resources, and type.
56 *
57 * @param appId application id
58 * @param flowRules flow rules to be set
59 * @param resources network resource to be set
Ray Milkeyef794342016-11-09 16:20:29 -080060 * @param type protection type
Luca Prete670ac5d2017-02-03 15:55:43 -080061 * @deprecated 1.9.1
helenyrwu2a674902016-07-20 09:48:04 -070062 */
Luca Prete670ac5d2017-02-03 15:55:43 -080063 @Deprecated
helenyrwu2a674902016-07-20 09:48:04 -070064 public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules, Collection<NetworkResource> resources,
65 PathIntent.ProtectionType type) {
Luca Prete670ac5d2017-02-03 15:55:43 -080066 this(appId, null, flowRules, resources, type, null);
helenyrwu2a674902016-07-20 09:48:04 -070067 }
68
69 /**
70 * Creates a flow rule intent with the specified key, flow rules to be set, and
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080071 * required network resources.
72 *
73 * @param appId application id
74 * @param key key
75 * @param flowRules flow rules
76 * @param resources network resources
Luca Prete670ac5d2017-02-03 15:55:43 -080077 * @deprecated 1.9.1
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080078 */
Luca Prete670ac5d2017-02-03 15:55:43 -080079 @Deprecated
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080080 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
81 Collection<NetworkResource> resources) {
Luca Prete670ac5d2017-02-03 15:55:43 -080082 this(appId, key, flowRules, resources,
83 PathIntent.ProtectionType.PRIMARY, null);
helenyrwu2a674902016-07-20 09:48:04 -070084 }
85
86 /**
87 * Creates a flow rule intent with the specified key, flow rules to be set, and
88 * required network resources.
89 *
90 * @param appId application id
91 * @param key key
92 * @param flowRules flow rules
93 * @param resources network resources
Ray Milkeyef794342016-11-09 16:20:29 -080094 * @param primary primary protection type
Luca Prete670ac5d2017-02-03 15:55:43 -080095 * @deprecated 1.9.1
96 */
97 @Deprecated
98 public FlowRuleIntent(ApplicationId appId,
99 Key key,
100 Collection<FlowRule> flowRules,
101 Collection<NetworkResource> resources,
102 PathIntent.ProtectionType primary) {
103 this(appId, key, flowRules, resources, primary, null);
104 }
105
106 /**
107 * Creates a flow rule intent with the specified key, flow rules to be set, and
108 * required network resources.
109 *
110 * @param appId application id
111 * @param key key
112 * @param flowRules flow rules
113 * @param resources network resources
114 * @param primary primary protection type
115 * @param resourceGroup resource group for this intent
helenyrwu2a674902016-07-20 09:48:04 -0700116 */
117 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
Luca Prete670ac5d2017-02-03 15:55:43 -0800118 Collection<NetworkResource> resources, PathIntent.ProtectionType primary,
119 ResourceGroup resourceGroup) {
120 super(appId, key, resources, DEFAULT_INTENT_PRIORITY, resourceGroup);
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800121 this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules));
helenyrwu2a674902016-07-20 09:48:04 -0700122 this.type = primary;
123 }
124
125 /**
126 * Creates a flow rule intent with all the same characteristics as the given
127 * one except for the flow rule type.
Ray Milkeyef794342016-11-09 16:20:29 -0800128 *
129 * @param intent original flow rule intent
130 * @param type new protection type
helenyrwu2a674902016-07-20 09:48:04 -0700131 */
132 public FlowRuleIntent(FlowRuleIntent intent, PathIntent.ProtectionType type) {
133 this(intent.appId(), intent.key(), intent.flowRules(),
Luca Prete670ac5d2017-02-03 15:55:43 -0800134 intent.resources(), type, intent.resourceGroup());
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800135 }
136
137 /**
Brian O'Connora7515372015-03-25 14:45:34 -0700138 * Constructor for serializer.
139 */
140 protected FlowRuleIntent() {
141 super();
142 this.flowRules = null;
helenyrwu2a674902016-07-20 09:48:04 -0700143 this.type = PathIntent.ProtectionType.PRIMARY;
Brian O'Connora7515372015-03-25 14:45:34 -0700144 }
145
146 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800147 * Returns a collection of flow rules to be set.
148 *
149 * @return a collection of flow rules
150 */
151 public Collection<FlowRule> flowRules() {
152 return flowRules;
153 }
154
155 @Override
156 public boolean isInstallable() {
157 return true;
158 }
159
helenyrwu2a674902016-07-20 09:48:04 -0700160 public PathIntent.ProtectionType type() {
161 return type;
162 }
163
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800164 @Override
165 public String toString() {
166 return MoreObjects.toStringHelper(this)
167 .add("id", id())
168 .add("key", key())
169 .add("appId", appId())
170 .add("resources", resources())
171 .add("flowRule", flowRules)
Luca Prete670ac5d2017-02-03 15:55:43 -0800172 .add("resourceGroup", resourceGroup())
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800173 .toString();
174 }
175}