blob: 9f879cfb05eba05806be7d478930b7fc8325de7a [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.
45 */
Sho SHIMIZU0c3c0762015-04-25 08:37:34 +090046 @Deprecated
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080047 public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules) {
48 this(appId, null, flowRules, Collections.emptyList());
49 }
50
51 /**
Sho SHIMIZU2de94492015-04-23 17:33:59 +090052 * Creates a flow rule intent with the specified flow rules and resources.
53 *
54 * @param appId application id
55 * @param flowRules flow rules to be set
56 * @param resources network resource to be set
57 */
58 public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules, Collection<NetworkResource> resources) {
59 this(appId, null, flowRules, resources);
60 }
61
62 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080063 * Creates an flow rule intent with the specified key, flow rules to be set, and
64 * required network resources.
65 *
66 * @param appId application id
67 * @param key key
68 * @param flowRules flow rules
69 * @param resources network resources
70 */
71 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
72 Collection<NetworkResource> resources) {
73 super(appId, key, resources, DEFAULT_INTENT_PRIORITY);
74 this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules));
75 }
76
77 /**
Brian O'Connora7515372015-03-25 14:45:34 -070078 * Constructor for serializer.
79 */
80 protected FlowRuleIntent() {
81 super();
82 this.flowRules = null;
83 }
84
85 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080086 * Returns a collection of flow rules to be set.
87 *
88 * @return a collection of flow rules
89 */
90 public Collection<FlowRule> flowRules() {
91 return flowRules;
92 }
93
94 @Override
95 public boolean isInstallable() {
96 return true;
97 }
98
99 @Override
100 public String toString() {
101 return MoreObjects.toStringHelper(this)
102 .add("id", id())
103 .add("key", key())
104 .add("appId", appId())
105 .add("resources", resources())
106 .add("flowRule", flowRules)
107 .toString();
108 }
109}