blob: 921c279d01a5ad62451bf81f4e58dbf32938badf [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;
helenyrwu2a674902016-07-20 09:48:04 -070038 private PathIntent.ProtectionType type;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080039
40 /**
Sho SHIMIZU2de94492015-04-23 17:33:59 +090041 * Creates a flow rule intent with the specified flow rules and resources.
42 *
43 * @param appId application id
44 * @param flowRules flow rules to be set
45 * @param resources network resource to be set
46 */
47 public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules, Collection<NetworkResource> resources) {
48 this(appId, null, flowRules, resources);
49 }
50
51 /**
helenyrwu2a674902016-07-20 09:48:04 -070052 * Creates a flow rule intent with the specified flow rules, resources, and type.
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 PathIntent.ProtectionType type) {
60 this(appId, null, flowRules, resources, type);
61 }
62
63 /**
64 * Creates a flow rule intent with the specified key, flow rules to be set, and
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080065 * required network resources.
66 *
67 * @param appId application id
68 * @param key key
69 * @param flowRules flow rules
70 * @param resources network resources
71 */
72 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
73 Collection<NetworkResource> resources) {
helenyrwu2a674902016-07-20 09:48:04 -070074 this(appId, key, flowRules, resources, PathIntent.ProtectionType.PRIMARY);
75 }
76
77 /**
78 * Creates a flow rule intent with the specified key, flow rules to be set, and
79 * required network resources.
80 *
81 * @param appId application id
82 * @param key key
83 * @param flowRules flow rules
84 * @param resources network resources
85 */
86 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
87 Collection<NetworkResource> resources, PathIntent.ProtectionType primary) {
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080088 super(appId, key, resources, DEFAULT_INTENT_PRIORITY);
89 this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules));
helenyrwu2a674902016-07-20 09:48:04 -070090 this.type = primary;
91 }
92
93 /**
94 * Creates a flow rule intent with all the same characteristics as the given
95 * one except for the flow rule type.
96 */
97 public FlowRuleIntent(FlowRuleIntent intent, PathIntent.ProtectionType type) {
98 this(intent.appId(), intent.key(), intent.flowRules(),
99 intent.resources(), type);
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800100 }
101
102 /**
Brian O'Connora7515372015-03-25 14:45:34 -0700103 * Constructor for serializer.
104 */
105 protected FlowRuleIntent() {
106 super();
107 this.flowRules = null;
helenyrwu2a674902016-07-20 09:48:04 -0700108 this.type = PathIntent.ProtectionType.PRIMARY;
Brian O'Connora7515372015-03-25 14:45:34 -0700109 }
110
111 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800112 * Returns a collection of flow rules to be set.
113 *
114 * @return a collection of flow rules
115 */
116 public Collection<FlowRule> flowRules() {
117 return flowRules;
118 }
119
120 @Override
121 public boolean isInstallable() {
122 return true;
123 }
124
helenyrwu2a674902016-07-20 09:48:04 -0700125 public PathIntent.ProtectionType type() {
126 return type;
127 }
128
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800129 @Override
130 public String toString() {
131 return MoreObjects.toStringHelper(this)
132 .add("id", id())
133 .add("key", key())
134 .add("appId", appId())
135 .add("resources", resources())
136 .add("flowRule", flowRules)
137 .toString();
138 }
139}