blob: 0bffaaa5c19087c034ca1398928dcafc73e583d8 [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
Ray Milkeyef794342016-11-09 16:20:29 -080057 * @param type protection type
helenyrwu2a674902016-07-20 09:48:04 -070058 */
59 public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules, Collection<NetworkResource> resources,
60 PathIntent.ProtectionType type) {
61 this(appId, null, flowRules, resources, type);
62 }
63
64 /**
65 * Creates a flow rule intent with the specified key, flow rules to be set, and
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080066 * required network resources.
67 *
68 * @param appId application id
69 * @param key key
70 * @param flowRules flow rules
71 * @param resources network resources
72 */
73 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
74 Collection<NetworkResource> resources) {
helenyrwu2a674902016-07-20 09:48:04 -070075 this(appId, key, flowRules, resources, PathIntent.ProtectionType.PRIMARY);
76 }
77
78 /**
79 * Creates a flow rule intent with the specified key, flow rules to be set, and
80 * required network resources.
81 *
82 * @param appId application id
83 * @param key key
84 * @param flowRules flow rules
85 * @param resources network resources
Ray Milkeyef794342016-11-09 16:20:29 -080086 * @param primary primary protection type
helenyrwu2a674902016-07-20 09:48:04 -070087 */
88 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
89 Collection<NetworkResource> resources, PathIntent.ProtectionType primary) {
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080090 super(appId, key, resources, DEFAULT_INTENT_PRIORITY);
91 this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules));
helenyrwu2a674902016-07-20 09:48:04 -070092 this.type = primary;
93 }
94
95 /**
96 * Creates a flow rule intent with all the same characteristics as the given
97 * one except for the flow rule type.
Ray Milkeyef794342016-11-09 16:20:29 -080098 *
99 * @param intent original flow rule intent
100 * @param type new protection type
helenyrwu2a674902016-07-20 09:48:04 -0700101 */
102 public FlowRuleIntent(FlowRuleIntent intent, PathIntent.ProtectionType type) {
103 this(intent.appId(), intent.key(), intent.flowRules(),
104 intent.resources(), type);
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800105 }
106
107 /**
Brian O'Connora7515372015-03-25 14:45:34 -0700108 * Constructor for serializer.
109 */
110 protected FlowRuleIntent() {
111 super();
112 this.flowRules = null;
helenyrwu2a674902016-07-20 09:48:04 -0700113 this.type = PathIntent.ProtectionType.PRIMARY;
Brian O'Connora7515372015-03-25 14:45:34 -0700114 }
115
116 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800117 * Returns a collection of flow rules to be set.
118 *
119 * @return a collection of flow rules
120 */
121 public Collection<FlowRule> flowRules() {
122 return flowRules;
123 }
124
125 @Override
126 public boolean isInstallable() {
127 return true;
128 }
129
helenyrwu2a674902016-07-20 09:48:04 -0700130 public PathIntent.ProtectionType type() {
131 return type;
132 }
133
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800134 @Override
135 public String toString() {
136 return MoreObjects.toStringHelper(this)
137 .add("id", id())
138 .add("key", key())
139 .add("appId", appId())
140 .add("resources", resources())
141 .add("flowRule", flowRules)
142 .toString();
143 }
144}