blob: b2c6cb8fb8a93125abde2b3886115bafce418b40 [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
18import com.google.common.base.MoreObjects;
19import com.google.common.collect.ImmutableList;
20import org.onosproject.core.ApplicationId;
21import org.onosproject.net.NetworkResource;
22import org.onosproject.net.flow.FlowRule;
23
24import java.util.Collection;
25import java.util.Collections;
26import java.util.List;
27
28import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
31 * An intent that enables to tell flow level operation.
32 * This instance holds a collection of flow rules that may be executed in parallel.
33 */
34public class FlowRuleIntent extends Intent {
35
36 private final Collection<FlowRule> flowRules;
37
38 /**
39 * Creates an flow rule intent with the specified flow rules to be set.
40 *
41 * @param appId application id
42 * @param flowRules flow rules to be set.
43 */
Sho SHIMIZU0c3c0762015-04-25 08:37:34 +090044 @Deprecated
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080045 public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules) {
46 this(appId, null, flowRules, Collections.emptyList());
47 }
48
49 /**
Sho SHIMIZU2de94492015-04-23 17:33:59 +090050 * Creates a flow rule intent with the specified flow rules and resources.
51 *
52 * @param appId application id
53 * @param flowRules flow rules to be set
54 * @param resources network resource to be set
55 */
56 public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules, Collection<NetworkResource> resources) {
57 this(appId, null, flowRules, resources);
58 }
59
60 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080061 * Creates an flow rule intent with the specified key, flow rules to be set, and
62 * required network resources.
63 *
64 * @param appId application id
65 * @param key key
66 * @param flowRules flow rules
67 * @param resources network resources
68 */
69 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
70 Collection<NetworkResource> resources) {
71 super(appId, key, resources, DEFAULT_INTENT_PRIORITY);
72 this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules));
73 }
74
75 /**
Brian O'Connora7515372015-03-25 14:45:34 -070076 * Constructor for serializer.
77 */
78 protected FlowRuleIntent() {
79 super();
80 this.flowRules = null;
81 }
82
83 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080084 * Returns a collection of flow rules to be set.
85 *
86 * @return a collection of flow rules
87 */
88 public Collection<FlowRule> flowRules() {
89 return flowRules;
90 }
91
92 @Override
93 public boolean isInstallable() {
94 return true;
95 }
96
97 @Override
98 public String toString() {
99 return MoreObjects.toStringHelper(this)
100 .add("id", id())
101 .add("key", key())
102 .add("appId", appId())
103 .add("resources", resources())
104 .add("flowRule", flowRules)
105 .toString();
106 }
107}