blob: 87303787ce4dfd9bcf72d1a6d55a0144433e011e [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
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
Thomas Vachuska75aaa672015-04-29 12:24:43 -070018import com.google.common.cache.Cache;
19import com.google.common.cache.CacheBuilder;
20import com.google.common.cache.RemovalCause;
21import com.google.common.cache.RemovalNotification;
Madan Jampani84382b92016-06-22 08:26:49 -070022import com.google.common.collect.ImmutableSet;
23import com.google.common.collect.Lists;
Thomas Vachuska75aaa672015-04-29 12:24:43 -070024import com.google.common.collect.Maps;
25import com.google.common.collect.Sets;
Yuta HIGUCHI6ee6b8c2017-05-09 14:44:30 -070026import io.netty.buffer.ByteBuf;
27import io.netty.buffer.Unpooled;
Thomas Vachuska75aaa672015-04-29 12:24:43 -070028import org.onosproject.cfg.ComponentConfigService;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.DeviceId;
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -030030import org.onosproject.net.driver.DefaultDriverData;
31import org.onosproject.net.driver.DefaultDriverHandler;
32import org.onosproject.net.driver.Driver;
33import org.onosproject.net.driver.DriverHandler;
Jonathan Hart3c259162015-10-21 21:31:19 -070034import org.onosproject.net.driver.DriverService;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.flow.CompletedBatchOperation;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070036import org.onosproject.net.flow.DefaultTableStatisticsEntry;
Brian O'Connorabafb502014-12-02 22:26:20 -080037import org.onosproject.net.flow.FlowEntry;
38import org.onosproject.net.flow.FlowRule;
Brian O'Connorabafb502014-12-02 22:26:20 -080039import org.onosproject.net.flow.FlowRuleProvider;
40import org.onosproject.net.flow.FlowRuleProviderRegistry;
41import org.onosproject.net.flow.FlowRuleProviderService;
hjtsao1a4333c2018-10-22 11:02:00 -070042import org.onosproject.net.flow.IndexTableId;
Ray Milkey17801b42019-02-22 14:18:00 -080043import org.onosproject.net.flow.TableStatisticsEntry;
44import org.onosproject.net.flow.oldbatch.FlowRuleBatchEntry;
45import org.onosproject.net.flow.oldbatch.FlowRuleBatchOperation;
Brian O'Connorabafb502014-12-02 22:26:20 -080046import org.onosproject.net.provider.AbstractProvider;
47import org.onosproject.net.provider.ProviderId;
Thomas Vachuska75aaa672015-04-29 12:24:43 -070048import org.onosproject.net.statistic.DefaultLoad;
Brian O'Connorabafb502014-12-02 22:26:20 -080049import org.onosproject.openflow.controller.Dpid;
50import org.onosproject.openflow.controller.OpenFlowController;
51import org.onosproject.openflow.controller.OpenFlowEventListener;
52import org.onosproject.openflow.controller.OpenFlowSwitch;
53import org.onosproject.openflow.controller.OpenFlowSwitchListener;
54import org.onosproject.openflow.controller.RoleState;
Thomas Vachuska95caba32016-04-04 10:42:05 -070055import org.onosproject.provider.of.flow.util.FlowEntryBuilder;
Thomas Vachuska75aaa672015-04-29 12:24:43 -070056import org.osgi.service.component.ComponentContext;
Ray Milkey17801b42019-02-22 14:18:00 -080057import org.osgi.service.component.annotations.Activate;
58import org.osgi.service.component.annotations.Component;
59import org.osgi.service.component.annotations.Deactivate;
60import org.osgi.service.component.annotations.Modified;
61import org.osgi.service.component.annotations.Reference;
62import org.osgi.service.component.annotations.ReferenceCardinality;
Thomas Vachuska3358af22015-05-19 18:40:34 -070063import org.projectfloodlight.openflow.protocol.OFBadRequestCode;
alshabib902d41b2014-10-07 16:52:05 -070064import org.projectfloodlight.openflow.protocol.OFBarrierRequest;
Laszlo Pappedadbe22017-12-14 20:05:49 +000065import org.projectfloodlight.openflow.protocol.OFCapabilities;
alshabib902d41b2014-10-07 16:52:05 -070066import org.projectfloodlight.openflow.protocol.OFErrorMsg;
Cem Türker3baff672017-10-12 15:09:01 +030067import org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsReply;
alshabib193525b2014-10-08 18:58:03 -070068import org.projectfloodlight.openflow.protocol.OFFlowMod;
alshabib8f1cf4a2014-09-17 14:44:48 -070069import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
alshabib5c370ff2014-09-18 10:12:14 -070070import org.projectfloodlight.openflow.protocol.OFFlowStatsReply;
alshabib8f1cf4a2014-09-17 14:44:48 -070071import org.projectfloodlight.openflow.protocol.OFMessage;
72import org.projectfloodlight.openflow.protocol.OFPortStatus;
alshabib5c370ff2014-09-18 10:12:14 -070073import org.projectfloodlight.openflow.protocol.OFStatsReply;
sangho89bf6fb2015-02-09 09:33:13 -080074import org.projectfloodlight.openflow.protocol.OFStatsType;
Jonathan Hart3c259162015-10-21 21:31:19 -070075import org.projectfloodlight.openflow.protocol.OFTableStatsEntry;
76import org.projectfloodlight.openflow.protocol.OFTableStatsReply;
Prince Pereira141ed812016-09-02 19:03:18 +053077import org.projectfloodlight.openflow.protocol.OFType;
78import org.projectfloodlight.openflow.protocol.OFVersion;
Prince Pereira788797e2016-08-10 11:24:14 +053079import org.projectfloodlight.openflow.protocol.errormsg.OFBadActionErrorMsg;
80import org.projectfloodlight.openflow.protocol.errormsg.OFBadInstructionErrorMsg;
81import org.projectfloodlight.openflow.protocol.errormsg.OFBadMatchErrorMsg;
Thomas Vachuska3358af22015-05-19 18:40:34 -070082import org.projectfloodlight.openflow.protocol.errormsg.OFBadRequestErrorMsg;
alshabib193525b2014-10-08 18:58:03 -070083import org.projectfloodlight.openflow.protocol.errormsg.OFFlowModFailedErrorMsg;
Prince Pereira141ed812016-09-02 19:03:18 +053084import org.projectfloodlight.openflow.types.U16;
85import org.projectfloodlight.openflow.types.U64;
alshabib1cc04f72014-09-16 16:09:58 -070086import org.slf4j.Logger;
87
Thomas Vachuska75aaa672015-04-29 12:24:43 -070088import java.util.Collections;
89import java.util.Dictionary;
90import java.util.List;
91import java.util.Map;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070092import java.util.Objects;
Thomas Vachuska75aaa672015-04-29 12:24:43 -070093import java.util.Optional;
94import java.util.Set;
95import java.util.Timer;
96import java.util.concurrent.TimeUnit;
97import java.util.stream.Collectors;
98
ssyoon9030fbcd92015-08-17 10:42:07 +090099import static com.google.common.base.Preconditions.checkNotNull;
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700100import static com.google.common.base.Strings.isNullOrEmpty;
101import static org.onlab.util.Tools.get;
Ray Milkey17801b42019-02-22 14:18:00 -0800102import static org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.ADAPTIVE_FLOW_SAMPLING;
103import static org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.ADAPTIVE_FLOW_SAMPLING_DEFAULT;
104import static org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.POLL_FREQUENCY;
105import static org.onosproject.provider.of.flow.impl.OsgiPropertyConstants.POLL_FREQUENCY_DEFAULT;
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700106import static org.slf4j.LoggerFactory.getLogger;
alshabibeec3a062014-09-17 18:01:26 -0700107
alshabib1cc04f72014-09-16 16:09:58 -0700108/**
jcc3d4e14a2015-04-21 11:32:05 +0800109 * Provider which uses an OpenFlow controller to detect network end-station
110 * hosts.
alshabib1cc04f72014-09-16 16:09:58 -0700111 */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700112@Component(immediate = true,
113 property = {
114 POLL_FREQUENCY + ":Integer=" + POLL_FREQUENCY_DEFAULT,
115 ADAPTIVE_FLOW_SAMPLING + ":Boolean=" + ADAPTIVE_FLOW_SAMPLING_DEFAULT,
116 })
jcc3d4e14a2015-04-21 11:32:05 +0800117public class OpenFlowRuleProvider extends AbstractProvider
118 implements FlowRuleProvider {
alshabib1cc04f72014-09-16 16:09:58 -0700119
120 private final Logger log = getLogger(getClass());
121
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700122 @Reference(cardinality = ReferenceCardinality.MANDATORY)
alshabib1cc04f72014-09-16 16:09:58 -0700123 protected FlowRuleProviderRegistry providerRegistry;
124
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700125 @Reference(cardinality = ReferenceCardinality.MANDATORY)
alshabib1cc04f72014-09-16 16:09:58 -0700126 protected OpenFlowController controller;
127
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700128 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700129 protected ComponentConfigService cfgService;
130
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700131 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jonathan Hart3c259162015-10-21 21:31:19 -0700132 protected DriverService driverService;
133
Prince Pereira141ed812016-09-02 19:03:18 +0530134 private static final int MIN_EXPECTED_BYTE_LEN = 56;
135 private static final int SKIP_BYTES = 4;
Prince Pereira141ed812016-09-02 19:03:18 +0530136
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700137 /** Frequency (in seconds) for polling flow statistics. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700138 private int flowPollFrequency = POLL_FREQUENCY_DEFAULT;
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700139
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700140 /** Adaptive Flow Sampling is on or off. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700141 private boolean adaptiveFlowSampling = ADAPTIVE_FLOW_SAMPLING_DEFAULT;
ssyoon9030fbcd92015-08-17 10:42:07 +0900142
alshabib1cc04f72014-09-16 16:09:58 -0700143 private FlowRuleProviderService providerService;
144
alshabibeec3a062014-09-17 18:01:26 -0700145 private final InternalFlowProvider listener = new InternalFlowProvider();
146
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800147 private Cache<Long, InternalCacheEntry> pendingBatches;
alshabib193525b2014-10-08 18:58:03 -0700148
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900149 private final Timer timer = new Timer("onos-openflow-collector");
150
Cem Türker3baff672017-10-12 15:09:01 +0300151
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900152 // Old simple collector set
Madan Jampani6b266102016-06-23 00:56:36 -0700153 private final Map<Dpid, FlowStatsCollector> simpleCollectors = Maps.newConcurrentMap();
ssyoon9030fbcd92015-08-17 10:42:07 +0900154
155 // NewAdaptiveFlowStatsCollector Set
Madan Jampani6b266102016-06-23 00:56:36 -0700156 private final Map<Dpid, NewAdaptiveFlowStatsCollector> afsCollectors = Maps.newConcurrentMap();
157 private final Map<Dpid, TableStatisticsCollector> tableStatsCollectors = Maps.newConcurrentMap();
alshabib3d643ec2014-10-22 18:33:00 -0700158
alshabib1cc04f72014-09-16 16:09:58 -0700159 /**
160 * Creates an OpenFlow host provider.
161 */
162 public OpenFlowRuleProvider() {
Brian O'Connorabafb502014-12-02 22:26:20 -0800163 super(new ProviderId("of", "org.onosproject.provider.openflow"));
alshabib1cc04f72014-09-16 16:09:58 -0700164 }
165
166 @Activate
Thomas Vachuskaa394b952016-06-14 15:02:09 -0700167 protected void activate(ComponentContext context) {
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700168 cfgService.registerProperties(getClass());
alshabib1cc04f72014-09-16 16:09:58 -0700169 providerService = providerRegistry.register(this);
alshabibeec3a062014-09-17 18:01:26 -0700170 controller.addListener(listener);
171 controller.addEventListener(listener);
alshabib3d643ec2014-10-22 18:33:00 -0700172
Antonio Marsico1c5ae1f2015-12-15 15:31:56 +0100173 modified(context);
174
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700175 pendingBatches = createBatchCache();
ssyoon9030fbcd92015-08-17 10:42:07 +0900176
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700177 createCollectors();
alshabib3d643ec2014-10-22 18:33:00 -0700178
ssyoon9030fbcd92015-08-17 10:42:07 +0900179 log.info("Started with flowPollFrequency = {}, adaptiveFlowSampling = {}",
180 flowPollFrequency, adaptiveFlowSampling);
alshabib1cc04f72014-09-16 16:09:58 -0700181 }
182
183 @Deactivate
Thomas Vachuskaa394b952016-06-14 15:02:09 -0700184 protected void deactivate(ComponentContext context) {
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700185 cfgService.unregisterProperties(getClass(), false);
186 stopCollectors();
alshabib1cc04f72014-09-16 16:09:58 -0700187 providerRegistry.unregister(this);
188 providerService = null;
189
190 log.info("Stopped");
191 }
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800192
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700193 @Modified
Thomas Vachuskaa394b952016-06-14 15:02:09 -0700194 protected void modified(ComponentContext context) {
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700195 Dictionary<?, ?> properties = context.getProperties();
196 int newFlowPollFrequency;
197 try {
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700198 String s = get(properties, POLL_FREQUENCY);
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700199 newFlowPollFrequency = isNullOrEmpty(s) ? flowPollFrequency : Integer.parseInt(s.trim());
200
201 } catch (NumberFormatException | ClassCastException e) {
202 newFlowPollFrequency = flowPollFrequency;
203 }
204
205 if (newFlowPollFrequency != flowPollFrequency) {
206 flowPollFrequency = newFlowPollFrequency;
207 adjustRate();
208 }
209
210 log.info("Settings: flowPollFrequency={}", flowPollFrequency);
ssyoon9030fbcd92015-08-17 10:42:07 +0900211
212 boolean newAdaptiveFlowSampling;
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700213 String s = get(properties, ADAPTIVE_FLOW_SAMPLING);
ssyoon9030fbcd92015-08-17 10:42:07 +0900214 newAdaptiveFlowSampling = isNullOrEmpty(s) ? adaptiveFlowSampling : Boolean.parseBoolean(s.trim());
215
216 if (newAdaptiveFlowSampling != adaptiveFlowSampling) {
217 // stop previous collector
218 stopCollectors();
219 adaptiveFlowSampling = newAdaptiveFlowSampling;
220 // create new collectors
221 createCollectors();
222 }
223
224 log.info("Settings: adaptiveFlowSampling={}", adaptiveFlowSampling);
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700225 }
226
227 private Cache<Long, InternalCacheEntry> createBatchCache() {
228 return CacheBuilder.newBuilder()
229 .expireAfterWrite(10, TimeUnit.SECONDS)
230 .removalListener((RemovalNotification<Long, InternalCacheEntry> notification) -> {
231 if (notification.getCause() == RemovalCause.EXPIRED) {
232 providerService.batchOperationCompleted(notification.getKey(),
233 notification.getValue().failedCompletion());
234 }
235 }).build();
236 }
237
238 private void createCollectors() {
239 controller.getSwitches().forEach(this::createCollector);
240 }
241
242 private void createCollector(OpenFlowSwitch sw) {
Kavitha Alagesan6704df32016-08-18 15:15:31 +0530243 if (sw == null) {
244 return;
245 }
Laszlo Papp58174812018-01-16 13:29:47 +0000246 if (sw.features().getCapabilities().contains(OFCapabilities.FLOW_STATS)) {
247 if (adaptiveFlowSampling) {
248 // NewAdaptiveFlowStatsCollector Constructor
249 NewAdaptiveFlowStatsCollector fsc =
250 new NewAdaptiveFlowStatsCollector(driverService, sw, flowPollFrequency);
251 stopCollectorIfNeeded(afsCollectors.put(new Dpid(sw.getId()), fsc));
252 fsc.start();
253 } else {
254 FlowStatsCollector fsc = new FlowStatsCollector(timer, sw, flowPollFrequency);
255 stopCollectorIfNeeded(simpleCollectors.put(new Dpid(sw.getId()), fsc));
256 fsc.start();
257 }
ssyoon9030fbcd92015-08-17 10:42:07 +0900258 }
Laszlo Pappedadbe22017-12-14 20:05:49 +0000259 if (sw.features().getCapabilities().contains(OFCapabilities.TABLE_STATS)) {
260 TableStatisticsCollector tsc = new TableStatisticsCollector(timer, sw, flowPollFrequency);
261 stopCollectorIfNeeded(tableStatsCollectors.put(new Dpid(sw.getId()), tsc));
262 tsc.start();
263 }
Thomas Vachuskaa394b952016-06-14 15:02:09 -0700264 }
265
266 private void stopCollectorIfNeeded(SwitchDataCollector collector) {
267 if (collector != null) {
268 collector.stop();
269 }
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700270 }
271
272 private void stopCollectors() {
ssyoon9030fbcd92015-08-17 10:42:07 +0900273 if (adaptiveFlowSampling) {
274 // NewAdaptiveFlowStatsCollector Destructor
275 afsCollectors.values().forEach(NewAdaptiveFlowStatsCollector::stop);
276 afsCollectors.clear();
277 } else {
278 simpleCollectors.values().forEach(FlowStatsCollector::stop);
279 simpleCollectors.clear();
280 }
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700281 tableStatsCollectors.values().forEach(TableStatisticsCollector::stop);
282 tableStatsCollectors.clear();
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700283 }
284
285 private void adjustRate() {
286 DefaultLoad.setPollInterval(flowPollFrequency);
ssyoon9030fbcd92015-08-17 10:42:07 +0900287 if (adaptiveFlowSampling) {
288 // NewAdaptiveFlowStatsCollector calAndPollInterval
289 afsCollectors.values().forEach(fsc -> fsc.adjustCalAndPollInterval(flowPollFrequency));
290 } else {
291 simpleCollectors.values().forEach(fsc -> fsc.adjustPollInterval(flowPollFrequency));
292 }
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700293 tableStatsCollectors.values().forEach(tsc -> tsc.adjustPollInterval(flowPollFrequency));
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700294 }
295
alshabib1cc04f72014-09-16 16:09:58 -0700296 @Override
297 public void applyFlowRule(FlowRule... flowRules) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800298 for (FlowRule flowRule : flowRules) {
299 applyRule(flowRule);
alshabib35edb1a2014-09-16 17:44:44 -0700300 }
alshabib1cc04f72014-09-16 16:09:58 -0700301 }
302
alshabib35edb1a2014-09-16 17:44:44 -0700303 private void applyRule(FlowRule flowRule) {
ssyoon9030fbcd92015-08-17 10:42:07 +0900304 Dpid dpid = Dpid.dpid(flowRule.deviceId().uri());
305 OpenFlowSwitch sw = controller.getSwitch(dpid);
306
Ray Milkey0ae473d2016-04-04 10:56:47 -0700307 if (sw == null) {
308 return;
309 }
310
alshabibbdcbb102015-04-22 14:16:38 -0700311 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
Jonathan Hart3c259162015-10-21 21:31:19 -0700312 Optional.empty(), Optional.of(driverService)).buildFlowAdd());
alshabib35edb1a2014-09-16 17:44:44 -0700313 }
314
alshabib1cc04f72014-09-16 16:09:58 -0700315 @Override
316 public void removeFlowRule(FlowRule... flowRules) {
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800317 for (FlowRule flowRule : flowRules) {
318 removeRule(flowRule);
alshabib219ebaa2014-09-22 15:41:24 -0700319 }
alshabib1cc04f72014-09-16 16:09:58 -0700320 }
321
alshabib219ebaa2014-09-22 15:41:24 -0700322 private void removeRule(FlowRule flowRule) {
ssyoon9030fbcd92015-08-17 10:42:07 +0900323 Dpid dpid = Dpid.dpid(flowRule.deviceId().uri());
324 OpenFlowSwitch sw = controller.getSwitch(dpid);
325
Ray Milkey0ae473d2016-04-04 10:56:47 -0700326 if (sw == null) {
327 return;
328 }
329
alshabibbdcbb102015-04-22 14:16:38 -0700330 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
Jonathan Hart3c259162015-10-21 21:31:19 -0700331 Optional.empty(), Optional.of(driverService)).buildFlowDel());
alshabib219ebaa2014-09-22 15:41:24 -0700332 }
333
alshabiba68eb962014-09-24 20:34:13 -0700334 @Override
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800335 public void executeBatch(FlowRuleBatchOperation batch) {
ssyoon9030fbcd92015-08-17 10:42:07 +0900336 checkNotNull(batch);
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800337
ssyoon9030fbcd92015-08-17 10:42:07 +0900338 Dpid dpid = Dpid.dpid(batch.deviceId().uri());
339 OpenFlowSwitch sw = controller.getSwitch(dpid);
Madan Jampani84382b92016-06-22 08:26:49 -0700340
341 // If switch no longer exists, simply return.
342 if (sw == null) {
343 Set<FlowRule> failures = ImmutableSet.copyOf(Lists.transform(batch.getOperations(), e -> e.target()));
344 providerService.batchOperationCompleted(batch.id(),
345 new CompletedBatchOperation(false, failures, batch.deviceId()));
346 return;
347 }
348 pendingBatches.put(batch.id(), new InternalCacheEntry(batch));
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800349 OFFlowMod mod;
alshabib193525b2014-10-08 18:58:03 -0700350 for (FlowRuleBatchEntry fbe : batch.getOperations()) {
Thomas Vachuskad07c0922015-10-06 14:48:06 -0700351 FlowModBuilder builder =
Jonathan Hart3c259162015-10-21 21:31:19 -0700352 FlowModBuilder.builder(fbe.target(), sw.factory(),
353 Optional.of(batch.id()), Optional.of(driverService));
Sho SHIMIZUaba9d002015-01-29 14:51:04 -0800354 switch (fbe.operator()) {
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700355 case ADD:
356 mod = builder.buildFlowAdd();
357 break;
358 case REMOVE:
359 mod = builder.buildFlowDel();
360 break;
361 case MODIFY:
362 mod = builder.buildFlowMod();
363 break;
364 default:
365 log.error("Unsupported batch operation {}; skipping flowmod {}",
ssyoon9030fbcd92015-08-17 10:42:07 +0900366 fbe.operator(), fbe);
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700367 continue;
jcc3d4e14a2015-04-21 11:32:05 +0800368 }
Saurav Das3ea46622015-04-22 14:01:34 -0700369 sw.sendMsg(mod);
alshabib193525b2014-10-08 18:58:03 -0700370 }
jcc3d4e14a2015-04-21 11:32:05 +0800371 OFBarrierRequest.Builder builder = sw.factory().buildBarrierRequest()
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800372 .setXid(batch.id());
373 sw.sendMsg(builder.build());
alshabib193525b2014-10-08 18:58:03 -0700374 }
375
alshabib8f1cf4a2014-09-17 14:44:48 -0700376 private class InternalFlowProvider
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800377 implements OpenFlowSwitchListener, OpenFlowEventListener {
alshabib8f1cf4a2014-09-17 14:44:48 -0700378
alshabib8f1cf4a2014-09-17 14:44:48 -0700379 @Override
380 public void switchAdded(Dpid dpid) {
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700381 createCollector(controller.getSwitch(dpid));
alshabib8f1cf4a2014-09-17 14:44:48 -0700382 }
383
384 @Override
385 public void switchRemoved(Dpid dpid) {
ssyoon9030fbcd92015-08-17 10:42:07 +0900386 if (adaptiveFlowSampling) {
Thomas Vachuskaa394b952016-06-14 15:02:09 -0700387 stopCollectorIfNeeded(afsCollectors.remove(dpid));
ssyoon9030fbcd92015-08-17 10:42:07 +0900388 } else {
Thomas Vachuskaa394b952016-06-14 15:02:09 -0700389 stopCollectorIfNeeded(simpleCollectors.remove(dpid));
alshabibdfc7afb2014-10-21 20:13:27 -0700390 }
Thomas Vachuskaa394b952016-06-14 15:02:09 -0700391 stopCollectorIfNeeded(tableStatsCollectors.remove(dpid));
alshabib8f1cf4a2014-09-17 14:44:48 -0700392 }
393
394 @Override
Ayaka Koshibe38594c22014-10-22 13:36:12 -0700395 public void switchChanged(Dpid dpid) {
396 }
397
398 @Override
alshabib8f1cf4a2014-09-17 14:44:48 -0700399 public void portChanged(Dpid dpid, OFPortStatus status) {
jcc3d4e14a2015-04-21 11:32:05 +0800400 // TODO: Decide whether to evict flows internal store.
alshabib8f1cf4a2014-09-17 14:44:48 -0700401 }
402
403 @Override
404 public void handleMessage(Dpid dpid, OFMessage msg) {
Ray Milkeyada9e2d2016-04-05 16:42:35 -0700405 if (providerService == null) {
406 // We are shutting down, nothing to be done
407 return;
408 }
Jonathan Harte4e74f02016-03-03 12:57:40 -0800409 DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
alshabib8f1cf4a2014-09-17 14:44:48 -0700410 switch (msg.getType()) {
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700411 case FLOW_REMOVED:
412 OFFlowRemoved removed = (OFFlowRemoved) msg;
alshabib6b5cfec2014-09-18 17:42:18 -0700413
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300414 FlowEntry fr = new FlowEntryBuilder(deviceId, removed, getDriver(deviceId)).build();
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700415 providerService.flowRemoved(fr);
416 break;
417 case STATS_REPLY:
418 if (((OFStatsReply) msg).getStatsType() == OFStatsType.FLOW) {
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300419 pushFlowMetrics(dpid, (OFFlowStatsReply) msg, getDriver(deviceId));
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700420 } else if (((OFStatsReply) msg).getStatsType() == OFStatsType.TABLE) {
421 pushTableStatistics(dpid, (OFTableStatsReply) msg);
Cem Türker3baff672017-10-12 15:09:01 +0300422 } else if (((OFStatsReply) msg).getStatsType() == OFStatsType.FLOW_LIGHTWEIGHT) {
423 pushFlowLightWeightMetrics(dpid, (OFFlowLightweightStatsReply) msg);
sangho89bf6fb2015-02-09 09:33:13 -0800424 }
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700425 break;
426 case BARRIER_REPLY:
427 try {
Thomas Vachuska3358af22015-05-19 18:40:34 -0700428 InternalCacheEntry entry = pendingBatches.getIfPresent(msg.getXid());
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800429 if (entry != null) {
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700430 providerService
431 .batchOperationCompleted(msg.getXid(),
432 entry.completed());
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800433 } else {
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700434 log.warn("Received unknown Barrier Reply: {}",
435 msg.getXid());
436 }
437 } finally {
438 pendingBatches.invalidate(msg.getXid());
439 }
440 break;
441 case ERROR:
Thomas Vachuska3358af22015-05-19 18:40:34 -0700442 // TODO: This needs to get suppressed in a better way.
443 if (msg instanceof OFBadRequestErrorMsg &&
444 ((OFBadRequestErrorMsg) msg).getCode() == OFBadRequestCode.BAD_TYPE) {
445 log.debug("Received error message {} from {}", msg, dpid);
446 } else {
447 log.warn("Received error message {} from {}", msg, dpid);
448 }
Prince Pereira788797e2016-08-10 11:24:14 +0530449 handleErrorMsg(deviceId, msg);
Ray Milkey4fd3ceb2015-12-10 14:43:08 -0800450 break;
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700451 default:
452 log.debug("Unhandled message type: {}", msg.getType());
alshabib8f1cf4a2014-09-17 14:44:48 -0700453 }
alshabib8f1cf4a2014-09-17 14:44:48 -0700454 }
455
Prince Pereira788797e2016-08-10 11:24:14 +0530456 private void handleErrorMsg(DeviceId deviceId, OFMessage msg) {
Prince Pereira141ed812016-09-02 19:03:18 +0530457 InternalCacheEntry entry = pendingBatches.getIfPresent(msg.getXid());
Prince Pereira788797e2016-08-10 11:24:14 +0530458 OFErrorMsg error = (OFErrorMsg) msg;
459 OFMessage ofMessage = null;
460 switch (error.getErrType()) {
461 case BAD_ACTION:
462 OFBadActionErrorMsg baErrorMsg = (OFBadActionErrorMsg) error;
463 if (baErrorMsg.getData().getParsedMessage().isPresent()) {
464 ofMessage = baErrorMsg.getData().getParsedMessage().get();
465 }
466 break;
467 case BAD_INSTRUCTION:
468 OFBadInstructionErrorMsg biErrorMsg = (OFBadInstructionErrorMsg) error;
469 if (biErrorMsg.getData().getParsedMessage().isPresent()) {
470 ofMessage = biErrorMsg.getData().getParsedMessage().get();
471 }
472 break;
473 case BAD_MATCH:
474 OFBadMatchErrorMsg bmErrorMsg = (OFBadMatchErrorMsg) error;
475 if (bmErrorMsg.getData().getParsedMessage().isPresent()) {
476 ofMessage = bmErrorMsg.getData().getParsedMessage().get();
477 }
478 break;
479 case FLOW_MOD_FAILED:
480 OFFlowModFailedErrorMsg fmFailed = (OFFlowModFailedErrorMsg) error;
481 if (fmFailed.getData().getParsedMessage().isPresent()) {
482 ofMessage = fmFailed.getData().getParsedMessage().get();
483 }
484 break;
485 default:
486 // Do nothing.
487 return;
488 }
Prince Pereira141ed812016-09-02 19:03:18 +0530489
Prince Pereira788797e2016-08-10 11:24:14 +0530490 if (ofMessage != null) {
Prince Pereira141ed812016-09-02 19:03:18 +0530491
Prince Pereira788797e2016-08-10 11:24:14 +0530492 if (entry != null) {
493 OFFlowMod ofFlowMod = (OFFlowMod) ofMessage;
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300494 entry.appendFailure(new FlowEntryBuilder(deviceId, ofFlowMod, getDriver(deviceId)).build());
Prince Pereira788797e2016-08-10 11:24:14 +0530495 } else {
496 log.error("No matching batch for this error: {}", error);
497 }
Prince Pereira141ed812016-09-02 19:03:18 +0530498
Prince Pereira788797e2016-08-10 11:24:14 +0530499 } else {
Prince Pereira141ed812016-09-02 19:03:18 +0530500
501 U64 cookieId = readCookieIdFromOFErrorMsg(error, msg.getVersion());
502
503 if (cookieId != null) {
504 long flowId = cookieId.getValue();
505
506 if (entry != null) {
507 for (FlowRuleBatchEntry fbEntry : entry.operation.getOperations()) {
508 if (fbEntry.target().id().value() == flowId) {
509 entry.appendFailure(fbEntry.target());
510 break;
511 }
512 }
513 } else {
514 log.error("No matching batch for this error: {}", error);
515 }
516
517 } else {
518 log.error("Flow installation failed but switch " +
519 "didn't tell us which one.");
520 }
Prince Pereira788797e2016-08-10 11:24:14 +0530521 }
522 }
523
Prince Pereira141ed812016-09-02 19:03:18 +0530524 /**
525 * Reading cookieId from OFErrorMsg.
526 *
527 * Loxigen OpenFlow API failed in parsing error messages because of
528 * 64 byte data truncation based on OpenFlow specs. The method written
529 * is a workaround to extract the cookieId from the packet till the
530 * issue is resolved in Loxigen OpenFlow code.
531 * Ref: https://groups.google.com/a/onosproject.org/forum/#!topic
532 * /onos-dev/_KwlHZDllLE
533 *
534 * @param msg OF error message
535 * @param ofVersion Openflow version
536 * @return cookieId
537 */
538 private U64 readCookieIdFromOFErrorMsg(OFErrorMsg msg,
539 OFVersion ofVersion) {
540
541 if (ofVersion.wireVersion < OFVersion.OF_13.wireVersion) {
542 log.debug("Unhandled error msg with OF version {} " +
543 "which is less than {}",
544 ofVersion, OFVersion.OF_13);
545 return null;
546 }
547
Yuta HIGUCHI6ee6b8c2017-05-09 14:44:30 -0700548 ByteBuf bb = Unpooled.wrappedBuffer(msg.getData().getData());
Prince Pereira141ed812016-09-02 19:03:18 +0530549
550 if (bb.readableBytes() < MIN_EXPECTED_BYTE_LEN) {
551 log.debug("Wrong length: Expected to be >= {}, was: {}",
552 MIN_EXPECTED_BYTE_LEN, bb.readableBytes());
553 return null;
554 }
555
556 byte ofVer = bb.readByte();
557
558 if (ofVer != ofVersion.wireVersion) {
559 log.debug("Wrong version: Expected={}, got={}",
560 ofVersion.wireVersion, ofVer);
561 return null;
562 }
563
564 byte type = bb.readByte();
565
566 if (type != OFType.FLOW_MOD.ordinal()) {
567 log.debug("Wrong type: Expected={}, got={}",
568 OFType.FLOW_MOD.ordinal(), type);
569 return null;
570 }
571
572 int length = U16.f(bb.readShort());
573
574 if (length < MIN_EXPECTED_BYTE_LEN) {
575 log.debug("Wrong length: Expected to be >= {}, was: {}",
576 MIN_EXPECTED_BYTE_LEN, length);
577 return null;
578 }
579
580 bb.skipBytes(SKIP_BYTES);
581 return U64.ofRaw(bb.readLong());
582 }
583
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700584 @Override
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700585 public void receivedRoleReply(Dpid dpid, RoleState requested,
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800586 RoleState response) {
Ayaka Koshibe3ef2b0d2014-10-31 13:58:27 -0700587 // Do nothing here for now.
588 }
Ayaka Koshibeab91cc42014-09-25 10:20:52 -0700589
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300590 private DriverHandler getDriver(DeviceId devId) {
591 Driver driver = driverService.getDriver(devId);
592 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, devId));
593 return handler;
594 }
595
596 private void pushFlowMetrics(Dpid dpid, OFFlowStatsReply replies, DriverHandler handler) {
alshabib64def642014-12-02 23:27:37 -0800597
alshabib54ce5892014-09-23 17:50:51 -0700598 DeviceId did = DeviceId.deviceId(Dpid.uri(dpid));
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900599 NewAdaptiveFlowStatsCollector afsc = afsCollectors.get(dpid);
alshabib54ce5892014-09-23 17:50:51 -0700600
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900601 if (adaptiveFlowSampling && afsc != null) {
602 List<FlowEntry> flowEntries = replies.getEntries().stream()
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300603 .map(entry -> new FlowEntryBuilder(did, entry, handler).withSetAfsc(afsc).build())
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900604 .collect(Collectors.toList());
alshabib54ce5892014-09-23 17:50:51 -0700605
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900606 // Check that OFFlowStatsReply Xid is same with the one of OFFlowStatsRequest?
607 if (afsc.getFlowMissingXid() != NewAdaptiveFlowStatsCollector.NO_FLOW_MISSING_XID) {
608 log.debug("OpenFlowRuleProvider:pushFlowMetrics, flowMissingXid={}, "
609 + "OFFlowStatsReply Xid={}, for {}",
610 afsc.getFlowMissingXid(), replies.getXid(), dpid);
611 if (afsc.getFlowMissingXid() == replies.getXid()) {
612 // call entire flow stats update with flowMissing synchronization.
613 // used existing pushFlowMetrics
614 providerService.pushFlowMetrics(did, flowEntries);
ssyoon9030fbcd92015-08-17 10:42:07 +0900615 }
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900616 // reset flowMissingXid to NO_FLOW_MISSING_XID
617 afsc.setFlowMissingXid(NewAdaptiveFlowStatsCollector.NO_FLOW_MISSING_XID);
618 } else {
619 // call individual flow stats update
620 providerService.pushFlowMetricsWithoutFlowMissing(did, flowEntries);
ssyoon9030fbcd92015-08-17 10:42:07 +0900621 }
622 } else {
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900623 List<FlowEntry> flowEntries = replies.getEntries().stream()
Rodrigo Duarte Sousae37d1292017-08-29 17:01:24 -0300624 .map(entry -> new FlowEntryBuilder(did, entry, handler).build())
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900625 .collect(Collectors.toList());
626
ssyoon9030fbcd92015-08-17 10:42:07 +0900627 // call existing entire flow stats update with flowMissing synchronization
628 providerService.pushFlowMetrics(did, flowEntries);
629 }
alshabib5c370ff2014-09-18 10:12:14 -0700630 }
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700631
632 private void pushTableStatistics(Dpid dpid, OFTableStatsReply replies) {
633
634 DeviceId did = DeviceId.deviceId(Dpid.uri(dpid));
635 List<TableStatisticsEntry> tableStatsEntries = replies.getEntries().stream()
636 .map(entry -> buildTableStatistics(did, entry))
637 .filter(Objects::nonNull)
638 .collect(Collectors.toList());
639 providerService.pushTableStatistics(did, tableStatsEntries);
640 }
641
Cem Türker3baff672017-10-12 15:09:01 +0300642 private void pushFlowLightWeightMetrics(Dpid dpid, OFFlowLightweightStatsReply replies) {
643
644 DeviceId did = DeviceId.deviceId(Dpid.uri(dpid));
645 NewAdaptiveFlowStatsCollector afsc = afsCollectors.get(dpid);
646 if (adaptiveFlowSampling && afsc != null) {
647 List<FlowEntry> flowEntries = replies.getEntries().stream()
648 .map(entry -> new FlowEntryBuilder(did, entry, driverService).withSetAfsc(afsc).build())
649 .collect(Collectors.toList());
650
651 // Check that OFFlowStatsReply Xid is same with the one of OFFlowStatsRequest?
652 if (afsc.getFlowMissingXid() != NewAdaptiveFlowStatsCollector.NO_FLOW_MISSING_XID) {
653 log.debug("OpenFlowRuleProvider:pushFlowMetrics, flowMissingXid={}, "
654 + "OFFlowStatsReply Xid={}, for {}",
655 afsc.getFlowMissingXid(), replies.getXid(), dpid);
656 if (afsc.getFlowMissingXid() == replies.getXid()) {
657 // call entire flow stats update with flowMissing synchronization.
658 // used existing pushFlowMetrics
659 providerService.pushFlowMetrics(did, flowEntries);
660 }
661 // reset flowMissingXid to NO_FLOW_MISSING_XID
662 afsc.setFlowMissingXid(NewAdaptiveFlowStatsCollector.NO_FLOW_MISSING_XID);
663 } else {
664 // call individual flow stats update
665 providerService.pushFlowMetricsWithoutFlowMissing(did, flowEntries);
666 }
667 } else {
668 List<FlowEntry> flowEntries = replies.getEntries().stream()
669 .map(entry -> new FlowEntryBuilder(did, entry, driverService).build())
670 .collect(Collectors.toList());
671 // call existing entire flow stats update with flowMissing synchronization
672 providerService.pushFlowMetrics(did, flowEntries);
673 }
674 }
675
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700676 private TableStatisticsEntry buildTableStatistics(DeviceId deviceId,
677 OFTableStatsEntry ofEntry) {
678 TableStatisticsEntry entry = null;
679 if (ofEntry != null) {
hjtsao1a4333c2018-10-22 11:02:00 -0700680 IndexTableId tid = IndexTableId.of(ofEntry.getTableId().getValue());
681
682 try {
683 entry = DefaultTableStatisticsEntry.builder()
684 .withDeviceId(deviceId)
685 .withTableId(tid)
686 .withActiveFlowEntries(ofEntry.getActiveCount())
687 .withPacketsLookedUpCount(ofEntry.getLookupCount().getValue())
688 .withPacketsMatchedCount(ofEntry.getMatchedCount().getValue())
689 .withMaxSize(ofEntry.getMaxEntries()).build();
690 } catch (UnsupportedOperationException e) {
691 // The exception "UnsupportedOperationException" is thrown by "getMaxEntries()".
692 entry = DefaultTableStatisticsEntry.builder()
693 .withDeviceId(deviceId)
694 .withTableId(tid)
695 .withActiveFlowEntries(ofEntry.getActiveCount())
696 .withPacketsLookedUpCount(ofEntry.getLookupCount().getValue())
697 .withPacketsMatchedCount(ofEntry.getMatchedCount().getValue()).build();
698 }
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700699 }
700
701 return entry;
702
703 }
alshabib8f1cf4a2014-09-17 14:44:48 -0700704 }
alshabib1cc04f72014-09-16 16:09:58 -0700705
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800706 /**
jcc3d4e14a2015-04-21 11:32:05 +0800707 * The internal cache entry holding the original request as well as
708 * accumulating the any failures along the way.
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700709 * <p/>
jcc3d4e14a2015-04-21 11:32:05 +0800710 * If this entry is evicted from the cache then the entire operation is
711 * considered failed. Otherwise, only the failures reported by the device
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800712 * will be propagated up.
713 */
714 private class InternalCacheEntry {
alshabib902d41b2014-10-07 16:52:05 -0700715
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800716 private final FlowRuleBatchOperation operation;
717 private final Set<FlowRule> failures = Sets.newConcurrentHashSet();
alshabib193525b2014-10-08 18:58:03 -0700718
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800719 public InternalCacheEntry(FlowRuleBatchOperation operation) {
720 this.operation = operation;
alshabib902d41b2014-10-07 16:52:05 -0700721 }
722
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800723 /**
724 * Appends a failed rule to the set of failed items.
jcc3d4e14a2015-04-21 11:32:05 +0800725 *
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800726 * @param rule the failed rule
727 */
728 public void appendFailure(FlowRule rule) {
729 failures.add(rule);
Thomas Vachuska9b2da212014-11-10 19:30:25 -0800730 }
731
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800732 /**
733 * Fails the entire batch and returns the failed operation.
jcc3d4e14a2015-04-21 11:32:05 +0800734 *
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800735 * @return the failed operation
736 */
737 public CompletedBatchOperation failedCompletion() {
738 Set<FlowRule> fails = operation.getOperations().stream()
739 .map(op -> op.target()).collect(Collectors.toSet());
jcc3d4e14a2015-04-21 11:32:05 +0800740 return new CompletedBatchOperation(false,
741 Collections
742 .unmodifiableSet(fails),
743 operation.deviceId());
alshabib902d41b2014-10-07 16:52:05 -0700744 }
745
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800746 /**
747 * Returns the completed operation and whether the batch suceeded.
jcc3d4e14a2015-04-21 11:32:05 +0800748 *
Brian O'Connor72cb19a2015-01-16 16:14:41 -0800749 * @return the completed operation
750 */
751 public CompletedBatchOperation completed() {
jcc3d4e14a2015-04-21 11:32:05 +0800752 return new CompletedBatchOperation(
Thomas Vachuska75aaa672015-04-29 12:24:43 -0700753 failures.isEmpty(),
754 Collections
755 .unmodifiableSet(failures),
756 operation.deviceId());
alshabib902d41b2014-10-07 16:52:05 -0700757 }
alshabib902d41b2014-10-07 16:52:05 -0700758 }
alshabiba68eb962014-09-24 20:34:13 -0700759
hjtsao1a4333c2018-10-22 11:02:00 -0700760}