blob: 56ced3da3a9eff43013c2a18ae9e69d3e2ed06c4 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -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 Vachuska781d18b2014-10-27 10:31:25 -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 Vachuska781d18b2014-10-27 10:31:25 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.provider.of.flow.impl;
alshabib1cc04f72014-09-16 16:09:58 -070017
Jonathan Hart2ffcd102015-01-16 16:47:50 -080018
Brian O'Connor72cb19a2015-01-16 16:14:41 -080019import com.google.common.cache.Cache;
20import com.google.common.cache.CacheBuilder;
21import com.google.common.cache.RemovalCause;
22import com.google.common.cache.RemovalNotification;
23import com.google.common.collect.Maps;
24import com.google.common.collect.Sets;
alshabib1cc04f72014-09-16 16:09:58 -070025import org.apache.felix.scr.annotations.Activate;
26import org.apache.felix.scr.annotations.Component;
27import org.apache.felix.scr.annotations.Deactivate;
28import org.apache.felix.scr.annotations.Reference;
29import org.apache.felix.scr.annotations.ReferenceCardinality;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.core.ApplicationId;
31import org.onosproject.net.DeviceId;
Brian O'Connorabafb502014-12-02 22:26:20 -080032import org.onosproject.net.flow.CompletedBatchOperation;
Brian O'Connorabafb502014-12-02 22:26:20 -080033import org.onosproject.net.flow.FlowEntry;
34import org.onosproject.net.flow.FlowRule;
35import org.onosproject.net.flow.FlowRuleBatchEntry;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080036import org.onosproject.net.flow.FlowRuleBatchOperation;
Brian O'Connorabafb502014-12-02 22:26:20 -080037import org.onosproject.net.flow.FlowRuleProvider;
38import org.onosproject.net.flow.FlowRuleProviderRegistry;
39import org.onosproject.net.flow.FlowRuleProviderService;
40import org.onosproject.net.provider.AbstractProvider;
41import org.onosproject.net.provider.ProviderId;
Brian O'Connorabafb502014-12-02 22:26:20 -080042import org.onosproject.openflow.controller.Dpid;
43import org.onosproject.openflow.controller.OpenFlowController;
44import org.onosproject.openflow.controller.OpenFlowEventListener;
45import org.onosproject.openflow.controller.OpenFlowSwitch;
46import org.onosproject.openflow.controller.OpenFlowSwitchListener;
47import org.onosproject.openflow.controller.RoleState;
alshabib19fdc122014-10-03 11:38:19 -070048import org.projectfloodlight.openflow.protocol.OFActionType;
alshabib902d41b2014-10-07 16:52:05 -070049import org.projectfloodlight.openflow.protocol.OFBarrierRequest;
50import org.projectfloodlight.openflow.protocol.OFErrorMsg;
Brian O'Connor72cb19a2015-01-16 16:14:41 -080051import org.projectfloodlight.openflow.protocol.OFErrorType;
alshabib193525b2014-10-08 18:58:03 -070052import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib8f1cf4a2014-09-17 14:44:48 -070053import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
alshabib5c370ff2014-09-18 10:12:14 -070054import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry;
55import org.projectfloodlight.openflow.protocol.OFFlowStatsReply;
alshabib19fdc122014-10-03 11:38:19 -070056import org.projectfloodlight.openflow.protocol.OFInstructionType;
alshabib8f1cf4a2014-09-17 14:44:48 -070057import org.projectfloodlight.openflow.protocol.OFMessage;
58import org.projectfloodlight.openflow.protocol.OFPortStatus;
alshabib5c370ff2014-09-18 10:12:14 -070059import org.projectfloodlight.openflow.protocol.OFStatsReply;
sangho89bf6fb2015-02-09 09:33:13 -080060import org.projectfloodlight.openflow.protocol.OFStatsType;
alshabib19fdc122014-10-03 11:38:19 -070061import org.projectfloodlight.openflow.protocol.OFVersion;
62import org.projectfloodlight.openflow.protocol.action.OFAction;
63import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
alshabib193525b2014-10-08 18:58:03 -070064import org.projectfloodlight.openflow.protocol.errormsg.OFFlowModFailedErrorMsg;
alshabib19fdc122014-10-03 11:38:19 -070065import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
66import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
67import org.projectfloodlight.openflow.types.OFPort;
alshabib1cc04f72014-09-16 16:09:58 -070068import org.slf4j.Logger;
69
Brian O'Connor72cb19a2015-01-16 16:14:41 -080070import java.util.Collections;
71import java.util.List;
72import java.util.Map;
73import java.util.Optional;
74import java.util.Set;
75import java.util.concurrent.TimeUnit;
76import java.util.stream.Collectors;
77
78import static org.slf4j.LoggerFactory.getLogger;
79
alshabibeec3a062014-09-17 18:01:26 -070080
alshabib1cc04f72014-09-16 16:09:58 -070081/**
82 * Provider which uses an OpenFlow controller to detect network
83 * end-station hosts.
84 */
85@Component(immediate = true)
86public class OpenFlowRuleProvider extends AbstractProvider implements FlowRuleProvider {
87
Jonathan Hart2ffcd102015-01-16 16:47:50 -080088 private static final int LOWEST_PRIORITY = 0;
89
alshabib1cc04f72014-09-16 16:09:58 -070090 private final Logger log = getLogger(getClass());
91
92 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
93 protected FlowRuleProviderRegistry providerRegistry;
94
95 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
96 protected OpenFlowController controller;
97
alshabib1cc04f72014-09-16 16:09:58 -070098
99 private FlowRuleProviderService providerService;
100
alshabibeec3a062014-09-17 18:01:26 -0700101 private final InternalFlowProvider listener = new InternalFlowProvider();
102
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800103 private Cache<Long, InternalCacheEntry> pendingBatches;
alshabib193525b2014-10-08 18:58:03 -0700104
alshabib3d643ec2014-10-22 18:33:00 -0700105 private final Map<Dpid, FlowStatsCollector> collectors = Maps.newHashMap();
106
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800107
alshabib1cc04f72014-09-16 16:09:58 -0700108 /**
109 * Creates an OpenFlow host provider.
110 */
111 public OpenFlowRuleProvider() {
Brian O'Connorabafb502014-12-02 22:26:20 -0800112 super(new ProviderId("of", "org.onosproject.provider.openflow"));
alshabib1cc04f72014-09-16 16:09:58 -0700113 }
114
115 @Activate
116 public void activate() {
117 providerService = providerRegistry.register(this);
alshabibeec3a062014-09-17 18:01:26 -0700118 controller.addListener(listener);
119 controller.addEventListener(listener);
alshabib3d643ec2014-10-22 18:33:00 -0700120
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800121 pendingBatches = CacheBuilder.newBuilder()
122 .expireAfterWrite(10, TimeUnit.SECONDS)
123 .removalListener((RemovalNotification<Long, InternalCacheEntry> notification) -> {
124 if (notification.getCause() == RemovalCause.EXPIRED) {
125 providerService.batchOperationCompleted(notification.getKey(),
126 notification.getValue().failedCompletion());
127 }
128 }).build();
129
130
alshabib3d643ec2014-10-22 18:33:00 -0700131 for (OpenFlowSwitch sw : controller.getSwitches()) {
132 FlowStatsCollector fsc = new FlowStatsCollector(sw, POLL_INTERVAL);
133 fsc.start();
134 collectors.put(new Dpid(sw.getId()), fsc);
135 }
136
137
alshabib1cc04f72014-09-16 16:09:58 -0700138 log.info("Started");
139 }
140
141 @Deactivate
142 public void deactivate() {
143 providerRegistry.unregister(this);
144 providerService = null;
145
146 log.info("Stopped");
147 }
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800148
alshabib1cc04f72014-09-16 16:09:58 -0700149 @Override
150 public void applyFlowRule(FlowRule... flowRules) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800151 for (FlowRule flowRule : flowRules) {
152 applyRule(flowRule);
alshabib35edb1a2014-09-16 17:44:44 -0700153 }
alshabib1cc04f72014-09-16 16:09:58 -0700154 }
155
alshabib35edb1a2014-09-16 17:44:44 -0700156 private void applyRule(FlowRule flowRule) {
157 OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri()));
sangho87af8112015-01-29 12:53:08 -0800158 if (flowRule.type() == FlowRule.Type.DEFAULT) {
159 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
160 Optional.empty()).buildFlowAdd());
161 } else {
alshabib9af70072015-02-09 14:34:16 -0800162 OpenFlowSwitch.TableType type = getTableType(flowRule.type());
sangho87af8112015-01-29 12:53:08 -0800163 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
alshabib9af70072015-02-09 14:34:16 -0800164 Optional.empty()).buildFlowAdd(),
165 type);
sangho87af8112015-01-29 12:53:08 -0800166 }
alshabib35edb1a2014-09-16 17:44:44 -0700167 }
168
alshabib35edb1a2014-09-16 17:44:44 -0700169
alshabib1cc04f72014-09-16 16:09:58 -0700170 @Override
171 public void removeFlowRule(FlowRule... flowRules) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800172 for (FlowRule flowRule : flowRules) {
173 removeRule(flowRule);
alshabib219ebaa2014-09-22 15:41:24 -0700174 }
alshabib1cc04f72014-09-16 16:09:58 -0700175
176 }
177
alshabib219ebaa2014-09-22 15:41:24 -0700178 private void removeRule(FlowRule flowRule) {
179 OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri()));
sangho87af8112015-01-29 12:53:08 -0800180 if (flowRule.type() == FlowRule.Type.DEFAULT) {
181 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
182 Optional.empty()).buildFlowDel());
183 } else {
184 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
185 Optional.empty()).buildFlowDel(), getTableType(flowRule.type()));
186 }
alshabib219ebaa2014-09-22 15:41:24 -0700187 }
188
alshabiba68eb962014-09-24 20:34:13 -0700189 @Override
190 public void removeRulesById(ApplicationId id, FlowRule... flowRules) {
191 // TODO: optimize using the ApplicationId
192 removeFlowRule(flowRules);
193 }
194
alshabib193525b2014-10-08 18:58:03 -0700195 @Override
sangho87af8112015-01-29 12:53:08 -0800196
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800197 public void executeBatch(FlowRuleBatchOperation batch) {
198
199 pendingBatches.put(batch.id(), new InternalCacheEntry(batch));
200
201
202 OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(batch.deviceId().uri()));
203 OFFlowMod mod;
204
alshabib193525b2014-10-08 18:58:03 -0700205 for (FlowRuleBatchEntry fbe : batch.getOperations()) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800206
Brian O'Connor427a1762014-11-19 18:40:32 -0800207 FlowModBuilder builder =
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800208 FlowModBuilder.builder(fbe.target(), sw.factory(),
209 Optional.of(batch.id()));
Sho SHIMIZUaba9d002015-01-29 14:51:04 -0800210 switch (fbe.operator()) {
alshabib193525b2014-10-08 18:58:03 -0700211 case ADD:
212 mod = builder.buildFlowAdd();
213 break;
214 case REMOVE:
215 mod = builder.buildFlowDel();
216 break;
217 case MODIFY:
218 mod = builder.buildFlowMod();
219 break;
220 default:
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800221 log.error("Unsupported batch operation {}; skipping flowmod {}",
222 fbe.operator(), fbe);
223 continue;
224 }
225 sw.sendMsg(mod);
alshabib193525b2014-10-08 18:58:03 -0700226 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800227 OFBarrierRequest.Builder builder = sw.factory()
228 .buildBarrierRequest()
229 .setXid(batch.id());
230 sw.sendMsg(builder.build());
alshabib193525b2014-10-08 18:58:03 -0700231 }
232
sangho87af8112015-01-29 12:53:08 -0800233 private OpenFlowSwitch.TableType getTableType(FlowRule.Type type) {
234 switch (type) {
alshabib9af70072015-02-09 14:34:16 -0800235
236 case DEFAULT:
237 return OpenFlowSwitch.TableType.NONE;
sangho87af8112015-01-29 12:53:08 -0800238 case IP:
239 return OpenFlowSwitch.TableType.IP;
240 case MPLS:
241 return OpenFlowSwitch.TableType.MPLS;
242 case ACL:
243 return OpenFlowSwitch.TableType.ACL;
alshabib9af70072015-02-09 14:34:16 -0800244 case VLAN_MPLS:
245 return OpenFlowSwitch.TableType.VLAN_MPLS;
246 case VLAN:
247 return OpenFlowSwitch.TableType.VLAN;
248 case ETHER:
249 return OpenFlowSwitch.TableType.ETHER;
250 case COS:
251 return OpenFlowSwitch.TableType.COS;
sangho87af8112015-01-29 12:53:08 -0800252 default:
253 return OpenFlowSwitch.TableType.NONE;
254 }
255 }
alshabib193525b2014-10-08 18:58:03 -0700256
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800257
258
259
alshabib8f1cf4a2014-09-17 14:44:48 -0700260 private class InternalFlowProvider
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800261 implements OpenFlowSwitchListener, OpenFlowEventListener {
alshabib8f1cf4a2014-09-17 14:44:48 -0700262
alshabib8f1cf4a2014-09-17 14:44:48 -0700263 @Override
264 public void switchAdded(Dpid dpid) {
alshabibba5ac482014-10-02 17:15:20 -0700265 FlowStatsCollector fsc = new FlowStatsCollector(controller.getSwitch(dpid), POLL_INTERVAL);
alshabibeec3a062014-09-17 18:01:26 -0700266 fsc.start();
267 collectors.put(dpid, fsc);
alshabib8f1cf4a2014-09-17 14:44:48 -0700268 }
269
270 @Override
271 public void switchRemoved(Dpid dpid) {
alshabibdfc7afb2014-10-21 20:13:27 -0700272 FlowStatsCollector collector = collectors.remove(dpid);
273 if (collector != null) {
274 collector.stop();
275 }
alshabib8f1cf4a2014-09-17 14:44:48 -0700276 }
277
278 @Override
Ayaka Koshibe38594c22014-10-22 13:36:12 -0700279 public void switchChanged(Dpid dpid) {
280 }
281
282 @Override
alshabib8f1cf4a2014-09-17 14:44:48 -0700283 public void portChanged(Dpid dpid, OFPortStatus status) {
284 //TODO: Decide whether to evict flows internal store.
285 }
286
287 @Override
288 public void handleMessage(Dpid dpid, OFMessage msg) {
289 switch (msg.getType()) {
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800290 case FLOW_REMOVED:
291 OFFlowRemoved removed = (OFFlowRemoved) msg;
alshabib6b5cfec2014-09-18 17:42:18 -0700292
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800293 FlowEntry fr = new FlowEntryBuilder(dpid, removed).build();
294 providerService.flowRemoved(fr);
295 break;
296 case STATS_REPLY:
sangho20f91162015-02-12 11:24:23 -0800297 if (((OFStatsReply) msg).getStatsType() == OFStatsType.FLOW) {
sangho89bf6fb2015-02-09 09:33:13 -0800298 pushFlowMetrics(dpid, (OFFlowStatsReply) msg);
299 }
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800300 break;
301 case BARRIER_REPLY:
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800302 try {
303 InternalCacheEntry entry = pendingBatches.getIfPresent(msg.getXid());
304 if (entry != null) {
305 providerService.batchOperationCompleted(msg.getXid(), entry.completed());
306 } else {
307 log.warn("Received unknown Barrier Reply: {}", msg.getXid());
308 }
309 } finally {
310 pendingBatches.invalidate(msg.getXid());
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800311 }
312 break;
313 case ERROR:
Yuta HIGUCHI82e53262014-11-27 10:28:51 -0800314 log.warn("received Error message {} from {}", msg, dpid);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800315
316 OFErrorMsg error = (OFErrorMsg) msg;
317 if (error.getErrType() == OFErrorType.FLOW_MOD_FAILED) {
318 OFFlowModFailedErrorMsg fmFailed = (OFFlowModFailedErrorMsg) error;
319 if (fmFailed.getData().getParsedMessage().isPresent()) {
320 OFMessage m = fmFailed.getData().getParsedMessage().get();
321 OFFlowMod fm = (OFFlowMod) m;
322 InternalCacheEntry entry = pendingBatches.getIfPresent(msg.getXid());
323 if (entry != null) {
324 entry.appendFailure(new FlowEntryBuilder(dpid, fm).build());
325 } else {
326 log.error("No matching batch for this error: {}", error);
327 }
328 } else {
329 //FIXME: Potentially add flowtracking to avoid this message.
330 log.error("Flow installation failed but switch didn't" +
331 " tell us which one.");
332 }
Yuta HIGUCHI82e53262014-11-27 10:28:51 -0800333 } else {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800334 log.warn("Received error {}", error);
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800335 }
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800336
337
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800338 default:
339 log.debug("Unhandled message type: {}", msg.getType());
alshabib8f1cf4a2014-09-17 14:44:48 -0700340 }
341
342 }
343
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700344 @Override
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700345 public void receivedRoleReply(Dpid dpid, RoleState requested,
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800346 RoleState response) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700347 // Do nothing here for now.
348 }
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700349
sangho89bf6fb2015-02-09 09:33:13 -0800350 private void pushFlowMetrics(Dpid dpid, OFFlowStatsReply replies) {
alshabib64def642014-12-02 23:27:37 -0800351
alshabib54ce5892014-09-23 17:50:51 -0700352 DeviceId did = DeviceId.deviceId(Dpid.uri(dpid));
alshabib54ce5892014-09-23 17:50:51 -0700353
alshabib64def642014-12-02 23:27:37 -0800354 List<FlowEntry> flowEntries = replies.getEntries().stream()
355 .filter(entry -> !tableMissRule(dpid, entry))
356 .map(entry -> new FlowEntryBuilder(dpid, entry).build())
357 .collect(Collectors.toList());
alshabib54ce5892014-09-23 17:50:51 -0700358
alshabib64def642014-12-02 23:27:37 -0800359 providerService.pushFlowMetrics(did, flowEntries);
360
alshabib5c370ff2014-09-18 10:12:14 -0700361 }
362
alshabib19fdc122014-10-03 11:38:19 -0700363 private boolean tableMissRule(Dpid dpid, OFFlowStatsEntry reply) {
Jonathan Hart2ffcd102015-01-16 16:47:50 -0800364 if (reply.getMatch().getMatchFields().iterator().hasNext()) {
alshabib19fdc122014-10-03 11:38:19 -0700365 return false;
366 }
Jonathan Hart2ffcd102015-01-16 16:47:50 -0800367 if (reply.getVersion().equals(OFVersion.OF_10)) {
368 return reply.getPriority() == LOWEST_PRIORITY
369 && reply.getActions().isEmpty();
370 }
alshabib19fdc122014-10-03 11:38:19 -0700371 for (OFInstruction ins : reply.getInstructions()) {
372 if (ins.getType() == OFInstructionType.APPLY_ACTIONS) {
373 OFInstructionApplyActions apply = (OFInstructionApplyActions) ins;
374 List<OFAction> acts = apply.getActions();
375 for (OFAction act : acts) {
376 if (act.getType() == OFActionType.OUTPUT) {
377 OFActionOutput out = (OFActionOutput) act;
378 if (out.getPort() == OFPort.CONTROLLER) {
379 return true;
380 }
381 }
382 }
383 }
384 }
385 return false;
386 }
Ayaka Koshibe38594c22014-10-22 13:36:12 -0700387
alshabib8f1cf4a2014-09-17 14:44:48 -0700388 }
alshabib1cc04f72014-09-16 16:09:58 -0700389
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800390 /**
391 * The internal cache entry holding the original request as well
392 * as accumulating the any failures along the way.
393 *
394 * If this entry is evicted from the cache then the entire operation
395 * is considered failed. Otherwise, only the failures reported by the device
396 * will be propagated up.
397 */
398 private class InternalCacheEntry {
alshabib902d41b2014-10-07 16:52:05 -0700399
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800400 private final FlowRuleBatchOperation operation;
401 private final Set<FlowRule> failures = Sets.newConcurrentHashSet();
alshabib193525b2014-10-08 18:58:03 -0700402
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800403 public InternalCacheEntry(FlowRuleBatchOperation operation) {
404 this.operation = operation;
alshabib902d41b2014-10-07 16:52:05 -0700405 }
406
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800407 /**
408 * Appends a failed rule to the set of failed items.
409 * @param rule the failed rule
410 */
411 public void appendFailure(FlowRule rule) {
412 failures.add(rule);
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800413 }
414
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800415 /**
416 * Fails the entire batch and returns the failed operation.
417 * @return the failed operation
418 */
419 public CompletedBatchOperation failedCompletion() {
420 Set<FlowRule> fails = operation.getOperations().stream()
421 .map(op -> op.target()).collect(Collectors.toSet());
422 return new CompletedBatchOperation(false, Collections.unmodifiableSet(fails), operation.deviceId());
alshabib902d41b2014-10-07 16:52:05 -0700423 }
424
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800425 /**
426 * Returns the completed operation and whether the batch suceeded.
427 * @return the completed operation
428 */
429 public CompletedBatchOperation completed() {
430 return new CompletedBatchOperation(failures.isEmpty(),
431 Collections.unmodifiableSet(failures), operation.deviceId());
alshabib902d41b2014-10-07 16:52:05 -0700432 }
433
alshabib902d41b2014-10-07 16:52:05 -0700434 }
alshabiba68eb962014-09-24 20:34:13 -0700435
alshabib1cc04f72014-09-16 16:09:58 -0700436}