blob: df90c41782bd33cacb5a79fe95596a7a32439ec7 [file] [log] [blame]
Sho SHIMIZUee2aa652015-02-25 18:56:43 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Sho SHIMIZUee2aa652015-02-25 18:56:43 -08003 *
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;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080026import 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 */
Brian O'Connor9476fa12015-06-25 15:17:17 -040034@Beta
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080035public class FlowRuleIntent extends Intent {
36
37 private final Collection<FlowRule> flowRules;
38
39 /**
Sho SHIMIZU2de94492015-04-23 17:33:59 +090040 * Creates a flow rule intent with the specified flow rules and resources.
41 *
42 * @param appId application id
43 * @param flowRules flow rules to be set
44 * @param resources network resource to be set
45 */
46 public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules, Collection<NetworkResource> resources) {
47 this(appId, null, flowRules, resources);
48 }
49
50 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080051 * Creates an flow rule intent with the specified key, flow rules to be set, and
52 * required network resources.
53 *
54 * @param appId application id
55 * @param key key
56 * @param flowRules flow rules
57 * @param resources network resources
58 */
59 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
60 Collection<NetworkResource> resources) {
61 super(appId, key, resources, DEFAULT_INTENT_PRIORITY);
62 this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules));
63 }
64
65 /**
Brian O'Connora7515372015-03-25 14:45:34 -070066 * Constructor for serializer.
67 */
68 protected FlowRuleIntent() {
69 super();
70 this.flowRules = null;
71 }
72
73 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080074 * Returns a collection of flow rules to be set.
75 *
76 * @return a collection of flow rules
77 */
78 public Collection<FlowRule> flowRules() {
79 return flowRules;
80 }
81
82 @Override
83 public boolean isInstallable() {
84 return true;
85 }
86
87 @Override
88 public String toString() {
89 return MoreObjects.toStringHelper(this)
90 .add("id", id())
91 .add("key", key())
92 .add("appId", appId())
93 .add("resources", resources())
94 .add("flowRule", flowRules)
95 .toString();
96 }
97}