Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.net.intent; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.NetworkResource; |
| 22 | import org.onosproject.net.flow.FlowRule; |
| 23 | |
| 24 | import java.util.Collection; |
| 25 | import java.util.Collections; |
| 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 | */ |
| 34 | public 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 | */ |
Sho SHIMIZU | 0c3c076 | 2015-04-25 08:37:34 +0900 | [diff] [blame] | 44 | @Deprecated |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 45 | public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules) { |
| 46 | this(appId, null, flowRules, Collections.emptyList()); |
| 47 | } |
| 48 | |
| 49 | /** |
Sho SHIMIZU | 2de9449 | 2015-04-23 17:33:59 +0900 | [diff] [blame] | 50 | * Creates a flow rule intent with the specified flow rules and resources. |
| 51 | * |
| 52 | * @param appId application id |
| 53 | * @param flowRules flow rules to be set |
| 54 | * @param resources network resource to be set |
| 55 | */ |
| 56 | public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules, Collection<NetworkResource> resources) { |
| 57 | this(appId, null, flowRules, resources); |
| 58 | } |
| 59 | |
| 60 | /** |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 61 | * Creates an flow rule intent with the specified key, flow rules to be set, and |
| 62 | * required network resources. |
| 63 | * |
| 64 | * @param appId application id |
| 65 | * @param key key |
| 66 | * @param flowRules flow rules |
| 67 | * @param resources network resources |
| 68 | */ |
| 69 | public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules, |
| 70 | Collection<NetworkResource> resources) { |
| 71 | super(appId, key, resources, DEFAULT_INTENT_PRIORITY); |
| 72 | this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules)); |
| 73 | } |
| 74 | |
| 75 | /** |
Brian O'Connor | a751537 | 2015-03-25 14:45:34 -0700 | [diff] [blame] | 76 | * Constructor for serializer. |
| 77 | */ |
| 78 | protected FlowRuleIntent() { |
| 79 | super(); |
| 80 | this.flowRules = null; |
| 81 | } |
| 82 | |
| 83 | /** |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 84 | * Returns a collection of flow rules to be set. |
| 85 | * |
| 86 | * @return a collection of flow rules |
| 87 | */ |
| 88 | public Collection<FlowRule> flowRules() { |
| 89 | return flowRules; |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public boolean isInstallable() { |
| 94 | return true; |
| 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public String toString() { |
| 99 | return MoreObjects.toStringHelper(this) |
| 100 | .add("id", id()) |
| 101 | .add("key", key()) |
| 102 | .add("appId", appId()) |
| 103 | .add("resources", resources()) |
| 104 | .add("flowRule", flowRules) |
| 105 | .toString(); |
| 106 | } |
| 107 | } |