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; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 38 | private PathIntent.ProtectionType type; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 39 | |
| 40 | /** |
Sho SHIMIZU | 2de9449 | 2015-04-23 17:33:59 +0900 | [diff] [blame] | 41 | * 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 | /** |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 52 | * 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 SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 65 | * 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) { |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 74 | 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 SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 88 | super(appId, key, resources, DEFAULT_INTENT_PRIORITY); |
| 89 | this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules)); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 90 | 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 SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /** |
Brian O'Connor | a751537 | 2015-03-25 14:45:34 -0700 | [diff] [blame] | 103 | * Constructor for serializer. |
| 104 | */ |
| 105 | protected FlowRuleIntent() { |
| 106 | super(); |
| 107 | this.flowRules = null; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 108 | this.type = PathIntent.ProtectionType.PRIMARY; |
Brian O'Connor | a751537 | 2015-03-25 14:45:34 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /** |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 112 | * 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 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 125 | public PathIntent.ProtectionType type() { |
| 126 | return type; |
| 127 | } |
| 128 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 129 | @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 | } |