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 | |
| 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 | /** |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 41 | * Creates a flow rule intent with the specified key, flow rules to be set, and |
| 42 | * required network resources. |
| 43 | * |
| 44 | * @param appId application id |
| 45 | * @param key key |
| 46 | * @param flowRules flow rules |
| 47 | * @param resources network resources |
| 48 | * @param primary primary protection type |
| 49 | * @param resourceGroup resource group for this intent |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 50 | */ |
| 51 | public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules, |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 52 | Collection<NetworkResource> resources, PathIntent.ProtectionType primary, |
| 53 | ResourceGroup resourceGroup) { |
| 54 | super(appId, key, resources, DEFAULT_INTENT_PRIORITY, resourceGroup); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 55 | this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules)); |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 56 | this.type = primary; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Creates a flow rule intent with all the same characteristics as the given |
| 61 | * one except for the flow rule type. |
Ray Milkey | ef79434 | 2016-11-09 16:20:29 -0800 | [diff] [blame] | 62 | * |
| 63 | * @param intent original flow rule intent |
| 64 | * @param type new protection type |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 65 | */ |
| 66 | public FlowRuleIntent(FlowRuleIntent intent, PathIntent.ProtectionType type) { |
| 67 | this(intent.appId(), intent.key(), intent.flowRules(), |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 68 | intent.resources(), type, intent.resourceGroup()); |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /** |
Brian O'Connor | a751537 | 2015-03-25 14:45:34 -0700 | [diff] [blame] | 72 | * Constructor for serializer. |
| 73 | */ |
| 74 | protected FlowRuleIntent() { |
| 75 | super(); |
| 76 | this.flowRules = null; |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 77 | this.type = PathIntent.ProtectionType.PRIMARY; |
Brian O'Connor | a751537 | 2015-03-25 14:45:34 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /** |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 81 | * Returns a collection of flow rules to be set. |
| 82 | * |
| 83 | * @return a collection of flow rules |
| 84 | */ |
| 85 | public Collection<FlowRule> flowRules() { |
| 86 | return flowRules; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public boolean isInstallable() { |
| 91 | return true; |
| 92 | } |
| 93 | |
helenyrwu | 2a67490 | 2016-07-20 09:48:04 -0700 | [diff] [blame] | 94 | public PathIntent.ProtectionType type() { |
| 95 | return type; |
| 96 | } |
| 97 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 98 | @Override |
| 99 | public String toString() { |
| 100 | return MoreObjects.toStringHelper(this) |
| 101 | .add("id", id()) |
| 102 | .add("key", key()) |
| 103 | .add("appId", appId()) |
| 104 | .add("resources", resources()) |
| 105 | .add("flowRule", flowRules) |
Luca Prete | 670ac5d | 2017-02-03 15:55:43 -0800 | [diff] [blame] | 106 | .add("resourceGroup", resourceGroup()) |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 107 | .toString(); |
| 108 | } |
| 109 | } |