Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.net.intent; |
| 17 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
| 20 | import com.google.common.collect.ImmutableList; |
| 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.net.NetworkResource; |
| 23 | import org.onosproject.net.flow.FlowRule; |
| 24 | |
| 25 | import java.util.Collection; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 26 | import java.util.List; |
| 27 | |
| 28 | import 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'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 34 | @Beta |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 35 | public class FlowRuleIntent extends Intent { |
| 36 | |
| 37 | private final Collection<FlowRule> flowRules; |
| 38 | |
| 39 | /** |
Sho SHIMIZU | 2de9449 | 2015-04-23 17:33:59 +0900 | [diff] [blame] | 40 | * 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 SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 51 | * 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'Connor | a751537 | 2015-03-25 14:45:34 -0700 | [diff] [blame] | 66 | * Constructor for serializer. |
| 67 | */ |
| 68 | protected FlowRuleIntent() { |
| 69 | super(); |
| 70 | this.flowRules = null; |
| 71 | } |
| 72 | |
| 73 | /** |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 74 | * 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 | } |