Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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; |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 23 | import org.onosproject.net.ResourceGroup; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 24 | import org.onosproject.net.flow.FlowRule; |
| 25 | |
| 26 | import java.util.Collection; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 27 | import java.util.List; |
| 28 | |
| 29 | import static com.google.common.base.Preconditions.checkNotNull; |
| 30 | |
| 31 | /** |
| 32 | * An intent that enables to tell flow level operation. |
| 33 | * This instance holds a collection of flow rules that may be executed in parallel. |
| 34 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 35 | @Beta |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 36 | public class FlowRuleIntent extends Intent { |
| 37 | |
| 38 | private final Collection<FlowRule> flowRules; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 39 | private PathIntent.ProtectionType type; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
Sho SHIMIZU | 2de9449 | 2015-04-23 17:33:59 +0900 | [diff] [blame] | 42 | * Creates a flow rule intent with the specified flow rules and resources. |
| 43 | * |
| 44 | * @param appId application id |
| 45 | * @param flowRules flow rules to be set |
| 46 | * @param resources network resource to be set |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 47 | * @deprecated 1.9.1 |
Sho SHIMIZU | 2de9449 | 2015-04-23 17:33:59 +0900 | [diff] [blame] | 48 | */ |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 49 | @Deprecated |
Sho SHIMIZU | 2de9449 | 2015-04-23 17:33:59 +0900 | [diff] [blame] | 50 | public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules, Collection<NetworkResource> resources) { |
| 51 | this(appId, null, flowRules, resources); |
| 52 | } |
| 53 | |
| 54 | /** |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 55 | * Creates a flow rule intent with the specified flow rules, resources, and type. |
| 56 | * |
| 57 | * @param appId application id |
| 58 | * @param flowRules flow rules to be set |
| 59 | * @param resources network resource to be set |
Ray Milkey | ef79434 | 2016-11-09 16:20:29 -0800 | [diff] [blame] | 60 | * @param type protection type |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 61 | * @deprecated 1.9.1 |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 62 | */ |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 63 | @Deprecated |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 64 | public FlowRuleIntent(ApplicationId appId, List<FlowRule> flowRules, Collection<NetworkResource> resources, |
| 65 | PathIntent.ProtectionType type) { |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 66 | this(appId, null, flowRules, resources, type, null); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /** |
| 70 | * 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] | 71 | * required network resources. |
| 72 | * |
| 73 | * @param appId application id |
| 74 | * @param key key |
| 75 | * @param flowRules flow rules |
| 76 | * @param resources network resources |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 77 | * @deprecated 1.9.1 |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 78 | */ |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 79 | @Deprecated |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 80 | public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules, |
| 81 | Collection<NetworkResource> resources) { |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 82 | this(appId, key, flowRules, resources, |
| 83 | PathIntent.ProtectionType.PRIMARY, null); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Creates a flow rule intent with the specified key, flow rules to be set, and |
| 88 | * required network resources. |
| 89 | * |
| 90 | * @param appId application id |
| 91 | * @param key key |
| 92 | * @param flowRules flow rules |
| 93 | * @param resources network resources |
Ray Milkey | ef79434 | 2016-11-09 16:20:29 -0800 | [diff] [blame] | 94 | * @param primary primary protection type |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 95 | * @deprecated 1.9.1 |
| 96 | */ |
| 97 | @Deprecated |
| 98 | public FlowRuleIntent(ApplicationId appId, |
| 99 | Key key, |
| 100 | Collection<FlowRule> flowRules, |
| 101 | Collection<NetworkResource> resources, |
| 102 | PathIntent.ProtectionType primary) { |
| 103 | this(appId, key, flowRules, resources, primary, null); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Creates a flow rule intent with the specified key, flow rules to be set, and |
| 108 | * required network resources. |
| 109 | * |
| 110 | * @param appId application id |
| 111 | * @param key key |
| 112 | * @param flowRules flow rules |
| 113 | * @param resources network resources |
| 114 | * @param primary primary protection type |
| 115 | * @param resourceGroup resource group for this intent |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 116 | */ |
| 117 | public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 118 | Collection<NetworkResource> resources, PathIntent.ProtectionType primary, |
| 119 | ResourceGroup resourceGroup) { |
| 120 | super(appId, key, resources, DEFAULT_INTENT_PRIORITY, resourceGroup); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 121 | this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules)); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 122 | this.type = primary; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Creates a flow rule intent with all the same characteristics as the given |
| 127 | * one except for the flow rule type. |
Ray Milkey | ef79434 | 2016-11-09 16:20:29 -0800 | [diff] [blame] | 128 | * |
| 129 | * @param intent original flow rule intent |
| 130 | * @param type new protection type |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 131 | */ |
| 132 | public FlowRuleIntent(FlowRuleIntent intent, PathIntent.ProtectionType type) { |
| 133 | this(intent.appId(), intent.key(), intent.flowRules(), |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 134 | intent.resources(), type, intent.resourceGroup()); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /** |
Brian O'Connor | a751537 | 2015-03-25 14:45:34 -0700 | [diff] [blame] | 138 | * Constructor for serializer. |
| 139 | */ |
| 140 | protected FlowRuleIntent() { |
| 141 | super(); |
| 142 | this.flowRules = null; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 143 | this.type = PathIntent.ProtectionType.PRIMARY; |
Brian O'Connor | a751537 | 2015-03-25 14:45:34 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /** |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 147 | * Returns a collection of flow rules to be set. |
| 148 | * |
| 149 | * @return a collection of flow rules |
| 150 | */ |
| 151 | public Collection<FlowRule> flowRules() { |
| 152 | return flowRules; |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public boolean isInstallable() { |
| 157 | return true; |
| 158 | } |
| 159 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 160 | public PathIntent.ProtectionType type() { |
| 161 | return type; |
| 162 | } |
| 163 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 164 | @Override |
| 165 | public String toString() { |
| 166 | return MoreObjects.toStringHelper(this) |
| 167 | .add("id", id()) |
| 168 | .add("key", key()) |
| 169 | .add("appId", appId()) |
| 170 | .add("resources", resources()) |
| 171 | .add("flowRule", flowRules) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 172 | .add("resourceGroup", resourceGroup()) |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 173 | .toString(); |
| 174 | } |
| 175 | } |