blob: 23a38a26cb3f7d3a0da1c2544f829e07b2d6aca2 [file] [log] [blame]
Sho SHIMIZUee2aa652015-02-25 18:56:43 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Sho SHIMIZUee2aa652015-02-25 18:56:43 -08003 *
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 */
16package org.onosproject.net.intent;
17
Brian O'Connor9476fa12015-06-25 15:17:17 -040018import com.google.common.annotations.Beta;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080019import com.google.common.base.MoreObjects;
20import com.google.common.collect.ImmutableList;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.net.NetworkResource;
Luca Prete670ac5d2017-02-03 15:55:43 -080023import org.onosproject.net.ResourceGroup;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080024import org.onosproject.net.flow.FlowRule;
25
26import java.util.Collection;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080027
28import 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'Connor9476fa12015-06-25 15:17:17 -040034@Beta
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080035public class FlowRuleIntent extends Intent {
36
37 private final Collection<FlowRule> flowRules;
helenyrwu2a674902016-07-20 09:48:04 -070038 private PathIntent.ProtectionType type;
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080039
40 /**
Luca Prete670ac5d2017-02-03 15:55:43 -080041 * 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
helenyrwu2a674902016-07-20 09:48:04 -070050 */
51 public FlowRuleIntent(ApplicationId appId, Key key, Collection<FlowRule> flowRules,
Luca Prete670ac5d2017-02-03 15:55:43 -080052 Collection<NetworkResource> resources, PathIntent.ProtectionType primary,
53 ResourceGroup resourceGroup) {
54 super(appId, key, resources, DEFAULT_INTENT_PRIORITY, resourceGroup);
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080055 this.flowRules = ImmutableList.copyOf(checkNotNull(flowRules));
helenyrwu2a674902016-07-20 09:48:04 -070056 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 Milkeyef794342016-11-09 16:20:29 -080062 *
63 * @param intent original flow rule intent
64 * @param type new protection type
helenyrwu2a674902016-07-20 09:48:04 -070065 */
66 public FlowRuleIntent(FlowRuleIntent intent, PathIntent.ProtectionType type) {
67 this(intent.appId(), intent.key(), intent.flowRules(),
Luca Prete670ac5d2017-02-03 15:55:43 -080068 intent.resources(), type, intent.resourceGroup());
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080069 }
70
71 /**
Brian O'Connora7515372015-03-25 14:45:34 -070072 * Constructor for serializer.
73 */
74 protected FlowRuleIntent() {
75 super();
76 this.flowRules = null;
helenyrwu2a674902016-07-20 09:48:04 -070077 this.type = PathIntent.ProtectionType.PRIMARY;
Brian O'Connora7515372015-03-25 14:45:34 -070078 }
79
80 /**
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080081 * 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
helenyrwu2a674902016-07-20 09:48:04 -070094 public PathIntent.ProtectionType type() {
95 return type;
96 }
97
Sho SHIMIZUee2aa652015-02-25 18:56:43 -080098 @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 Prete670ac5d2017-02-03 15:55:43 -0800106 .add("resourceGroup", resourceGroup())
Sho SHIMIZUee2aa652015-02-25 18:56:43 -0800107 .toString();
108 }
109}