blob: 0ade2ed14152f495f39d2236366f9397df4a7a4d [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow;
tom8bb16062014-09-12 14:47:46 -070017
Sangsik Yoonb1b823f2016-05-16 18:55:39 +090018import com.google.common.collect.Iterables;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.core.ApplicationId;
Thomas Vachuska42e8cce2015-07-29 19:25:18 -070020import org.onosproject.event.ListenerService;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.DeviceId;
tom8bb16062014-09-12 14:47:46 -070022
23/**
24 * Service for injecting flow rules into the environment and for obtaining
tom4d0c6632014-09-15 23:27:01 -070025 * information about flow rules already in the environment. This implements
26 * semantics of a distributed authoritative flow table where the master copy
27 * of the flow rules lies with the controller and the devices hold only the
28 * 'cached' copy.
tom8bb16062014-09-12 14:47:46 -070029 */
Thomas Vachuska42e8cce2015-07-29 19:25:18 -070030public interface FlowRuleService
31 extends ListenerService<FlowRuleEvent, FlowRuleListener> {
tom8bb16062014-09-12 14:47:46 -070032
33 /**
Brian O'Connor72cb19a2015-01-16 16:14:41 -080034 * The topic used for obtaining globally unique ids.
35 */
Sho SHIMIZUe2952e42015-09-11 17:11:21 -070036 String FLOW_OP_TOPIC = "flow-ops-ids";
Brian O'Connor72cb19a2015-01-16 16:14:41 -080037
38 /**
tom9b4030d2014-10-06 10:39:03 -070039 * Returns the number of flow rules in the system.
40 *
41 * @return flow rule count
42 */
43 int getFlowRuleCount();
44
45 /**
Thomas Vachuskaa8e74772018-02-26 11:33:35 -080046 * Returns the number of flow rules for the given device.
47 *
48 * @param deviceId device identifier
49 * @return number of flow rules for the given device
50 */
51 default int getFlowRuleCount(DeviceId deviceId) {
52 return 0;
53 }
54
55 /**
tom8bb16062014-09-12 14:47:46 -070056 * Returns the collection of flow entries applied on the specified device.
tom4d0c6632014-09-15 23:27:01 -070057 * This will include flow rules which may not yet have been applied to
58 * the device.
tom8bb16062014-09-12 14:47:46 -070059 *
60 * @param deviceId device identifier
61 * @return collection of flow rules
62 */
alshabib1c319ff2014-10-04 20:29:09 -070063 Iterable<FlowEntry> getFlowEntries(DeviceId deviceId);
tom8bb16062014-09-12 14:47:46 -070064
65 /**
Sangsik Yoonb1b823f2016-05-16 18:55:39 +090066 * Returns a list of rules filtered by device id and flow live type.
67 *
68 * @param deviceId the device id to lookup
69 * @param liveType the flow live type to lookup
70 * @return collection of flow entries
71 */
72 default Iterable<FlowEntry> getFlowEntriesByLiveType(DeviceId deviceId,
73 FlowEntry.FlowLiveType liveType) {
74 return Iterables.filter(getFlowEntries(deviceId), fe -> fe.liveType() == liveType);
75 }
76
Georgios Katsikas5eba8aa2017-07-23 18:27:48 +020077 /**
78 * Returns a list of rules filtered by device id and flow state.
79 *
80 * @param deviceId the device id to lookup
81 * @param flowState the flow state to lookup
82 * @return collection of flow entries
83 */
84 default Iterable<FlowEntry> getFlowEntriesByState(DeviceId deviceId,
85 FlowEntry.FlowEntryState flowState) {
86 return Iterables.filter(getFlowEntries(deviceId), fe -> fe.state() == flowState);
87 }
88
Sangsik Yoonb1b823f2016-05-16 18:55:39 +090089 // TODO: add createFlowRule factory method and execute operations method
90
91 /**
tom4d0c6632014-09-15 23:27:01 -070092 * Applies the specified flow rules onto their respective devices. These
93 * flow rules will be retained by the system and re-applied anytime the
94 * device reconnects to the controller.
tom8bb16062014-09-12 14:47:46 -070095 *
96 * @param flowRules one or more flow rules
tom8bb16062014-09-12 14:47:46 -070097 */
alshabib219ebaa2014-09-22 15:41:24 -070098 void applyFlowRules(FlowRule... flowRules);
tom8bb16062014-09-12 14:47:46 -070099
100 /**
Kavitha Alagesanc69c66a2016-06-15 14:26:04 +0530101 * Purges all the flow rules on the specified device.
102 * @param deviceId device identifier
103 */
104 void purgeFlowRules(DeviceId deviceId);
105
106 /**
tom4d0c6632014-09-15 23:27:01 -0700107 * Removes the specified flow rules from their respective devices. If the
108 * device is not presently connected to the controller, these flow will
109 * be removed once the device reconnects.
alshabib369d2942014-09-12 17:59:35 -0700110 *
111 * @param flowRules one or more flow rules
alshabib369d2942014-09-12 17:59:35 -0700112 */
113 void removeFlowRules(FlowRule... flowRules);
114
alshabiba68eb962014-09-24 20:34:13 -0700115 /**
Jonathan Hart3fc7e832016-05-23 15:41:11 -0700116 * Removes all rules submitted by a particular application.
alshabiba68eb962014-09-24 20:34:13 -0700117 *
Jonathan Hart3fc7e832016-05-23 15:41:11 -0700118 * @param appId ID of application whose flows will be removed
alshabiba68eb962014-09-24 20:34:13 -0700119 */
120 void removeFlowRulesById(ApplicationId appId);
121
122 /**
Jonathan Hart3fc7e832016-05-23 15:41:11 -0700123 * Returns a list of rules with this application ID.
alshabiba68eb962014-09-24 20:34:13 -0700124 *
Jonathan Hart3fc7e832016-05-23 15:41:11 -0700125 * @param id the application ID to look up
alshabiba68eb962014-09-24 20:34:13 -0700126 * @return collection of flow rules
127 */
Bharath Thiruveedula99849dc2016-11-17 22:04:38 +0530128 @Deprecated
alshabiba68eb962014-09-24 20:34:13 -0700129 Iterable<FlowRule> getFlowRulesById(ApplicationId id);
tom4d0c6632014-09-15 23:27:01 -0700130
alshabib902d41b2014-10-07 16:52:05 -0700131 /**
Bharath Thiruveedula99849dc2016-11-17 22:04:38 +0530132 * Returns a list of rules with this application ID.
133 *
134 * @param id the application ID to look up
135 * @return collection of flow rules
136 */
137 Iterable<FlowEntry> getFlowEntriesById(ApplicationId id);
138
139 /**
Jonathan Hart5acc88a2016-05-23 10:50:20 -0700140 * Returns a list of rules filtered by application and group id.
141 * <p>
142 * Note that the group concept here is simply a logical grouping of flows.
143 * This is not the same as a group in the
144 * {@link org.onosproject.net.group.GroupService}, and this method will not
145 * return flows that are mapped to a particular {@link org.onosproject.net.group.Group}.
146 * </p>
alshabibaa7e7de2014-11-12 19:20:44 -0800147 *
Jonathan Hart5acc88a2016-05-23 10:50:20 -0700148 * @param appId the application ID to look up
149 * @param groupId the group ID to look up
alshabibaa7e7de2014-11-12 19:20:44 -0800150 * @return collection of flow rules
151 */
152 Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId);
153
154 /**
alshabib902d41b2014-10-07 16:52:05 -0700155 * Applies a batch operation of FlowRules.
156 *
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800157 * @param ops batch operation to apply
158 */
159 void apply(FlowRuleOperations ops);
160
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700161 /**
162 * Returns the collection of flow table statistics of the specified device.
163 *
164 * @param deviceId device identifier
165 * @return collection of flow table statistics
166 */
167 Iterable<TableStatisticsEntry> getFlowTableStatistics(DeviceId deviceId);
Patryk Konopka7e40c012017-06-06 13:38:06 +0200168
169 /**
170 * Returns number of flow rules in ADDED state for specified device.
171 *
172 * @param deviceId device identifier
173 * @return number of flow rules in ADDED state
174 */
175 default long getActiveFlowRuleCount(DeviceId deviceId) {
176 return 0;
177 }
tom8bb16062014-09-12 14:47:46 -0700178}