blob: 82ea0b7936cb27e8a61c6ad80b54e54bcb74ec74 [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 /**
49 * Creates an flow rule intent with the specified key, flow rules to be set, and
50 * required network resources.
51 *
52 * @param appId application id
53 * @param key key
54 * @param flowRules flow rules
55 * @param resources network resources
56 */
57 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
58 Collection<NetworkResource> resources) {
59 super(appId, key, resources, DEFAULT_INTENT_PRIORITY);
60 this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules));
61 }
62
63 /**
Brian O'Connora7515372015-03-25 14:45:34 -070064 * Constructor for serializer.
65 */
66 protected FlowRuleIntent() {
67 super();
68 this.flowRules = null;
69 }
70
71 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080072 * Returns a collection of flow rules to be set.
73 *
74 * @return a collection of flow rules
75 */
76 public Collection<FlowRule> flowRules() {
77 return flowRules;
78 }
79
80 @Override
81 public boolean isInstallable() {
82 return true;
83 }
84
85 @Override
86 public String toString() {
87 return MoreObjects.toStringHelper(this)
88 .add("id", id())
89 .add("key", key())
90 .add("appId", appId())
91 .add("resources", resources())
92 .add("flowRule", flowRules)
93 .toString();
94 }
95}