blob: 0646a0031e262b607dd44ef8da1b3a71fe9d2f23 [file] [log] [blame]
Sho SHIMIZUee2aa652015-02-25 18:56:43 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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 */
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;
23import org.onosproject.net.flow.FlowRule;
24
25import java.util.Collection;
26import java.util.Collections;
27import 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;
39
40 /**
41 * Creates an flow rule intent with the specified flow rules to be set.
42 *
43 * @param appId application id
44 * @param flowRules flow rules to be set.
Sho SHIMIZU9a2b0812015-06-30 10:02:22 -070045 * @deprecated in Cardinal Release
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080046 */
Sho SHIMIZU0c3c0762015-04-25 08:37:34 +090047 @Deprecated
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080048 public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules) {
49 this(appId, null, flowRules, Collections.emptyList());
50 }
51
52 /**
Sho SHIMIZU2de94492015-04-23 17:33:59 +090053 * Creates a flow rule intent with the specified flow rules and resources.
54 *
55 * @param appId application id
56 * @param flowRules flow rules to be set
57 * @param resources network resource to be set
58 */
59 public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules, Collection<NetworkResource> resources) {
60 this(appId, null, flowRules, resources);
61 }
62
63 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080064 * Creates an flow rule intent with the specified key, flow rules to be set, and
65 * required network resources.
66 *
67 * @param appId application id
68 * @param key key
69 * @param flowRules flow rules
70 * @param resources network resources
71 */
72 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
73 Collection<NetworkResource> resources) {
74 super(appId, key, resources, DEFAULT_INTENT_PRIORITY);
75 this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules));
76 }
77
78 /**
Brian O'Connora7515372015-03-25 14:45:34 -070079 * Constructor for serializer.
80 */
81 protected FlowRuleIntent() {
82 super();
83 this.flowRules = null;
84 }
85
86 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080087 * Returns a collection of flow rules to be set.
88 *
89 * @return a collection of flow rules
90 */
91 public Collection<FlowRule> flowRules() {
92 return flowRules;
93 }
94
95 @Override
96 public boolean isInstallable() {
97 return true;
98 }
99
100 @Override
101 public String toString() {
102 return MoreObjects.toStringHelper(this)
103 .add("id", id())
104 .add("key", key())
105 .add("appId", appId())
106 .add("resources", resources())
107 .add("flowRule", flowRules)
108 .toString();
109 }
110}