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