blob: d8d3d80a8c7b6966c96d81220202f0e4ca2d5877 [file] [log] [blame]
Ray Milkey4f5de002014-12-17 19:26:11 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Ray Milkey4f5de002014-12-17 19:26:11 -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 */
Jonathan Hart9bb32ab2015-05-05 18:17:31 -070016package org.onosproject.rest.resources;
Ray Milkey4f5de002014-12-17 19:26:11 -080017
Jian Li9d616492016-03-09 10:52:49 -080018import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.node.ArrayNode;
20import com.fasterxml.jackson.databind.node.ObjectNode;
Ray Milkey460f9b02016-03-29 11:56:19 -070021import com.google.common.collect.ArrayListMultimap;
22import com.google.common.collect.ListMultimap;
Ray Milkeyd43fe452015-05-29 09:35:12 -070023import org.onlab.util.ItemNotFoundException;
Jian Li2907ad22016-05-12 23:08:54 -070024import org.onosproject.app.ApplicationService;
25import org.onosproject.core.ApplicationId;
Ray Milkeyd43fe452015-05-29 09:35:12 -070026import org.onosproject.net.Device;
27import org.onosproject.net.DeviceId;
28import org.onosproject.net.device.DeviceService;
29import org.onosproject.net.flow.FlowEntry;
30import org.onosproject.net.flow.FlowRule;
31import org.onosproject.net.flow.FlowRuleService;
32import org.onosproject.rest.AbstractWebResource;
33
Jian Li9d616492016-03-09 10:52:49 -080034import javax.ws.rs.Consumes;
35import javax.ws.rs.DELETE;
36import javax.ws.rs.GET;
37import javax.ws.rs.POST;
38import javax.ws.rs.Path;
39import javax.ws.rs.PathParam;
40import javax.ws.rs.Produces;
Jian Li2907ad22016-05-12 23:08:54 -070041import javax.ws.rs.QueryParam;
Jian Li9d616492016-03-09 10:52:49 -080042import javax.ws.rs.core.Context;
43import javax.ws.rs.core.MediaType;
44import javax.ws.rs.core.Response;
45import javax.ws.rs.core.UriBuilder;
46import javax.ws.rs.core.UriInfo;
47import java.io.IOException;
48import java.io.InputStream;
Ray Milkey460f9b02016-03-29 11:56:19 -070049import java.util.ArrayList;
Thomas Vachuskaa1ae5e12016-03-28 10:36:30 -070050import java.util.List;
Jian Li9d616492016-03-09 10:52:49 -080051import java.util.stream.StreamSupport;
Ray Milkeyd43fe452015-05-29 09:35:12 -070052
Ray Milkey131c0682016-10-18 11:12:50 -070053import static org.onlab.util.Tools.nullIsIllegal;
Ray Milkey460f9b02016-03-29 11:56:19 -070054import static org.onlab.util.Tools.nullIsNotFound;
Ray Milkey86ee5e82018-04-02 15:33:07 -070055import static org.onlab.util.Tools.readTreeFromStream;
Ray Milkey460f9b02016-03-29 11:56:19 -070056
Ray Milkey4f5de002014-12-17 19:26:11 -080057/**
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070058 * Query and program flow rules.
Ray Milkey4f5de002014-12-17 19:26:11 -080059 */
60
61@Path("flows")
62public class FlowsWebResource extends AbstractWebResource {
Jian Li9d616492016-03-09 10:52:49 -080063
64 @Context
Jian Licc730a62016-05-10 16:36:16 -070065 private UriInfo uriInfo;
Jian Li9d616492016-03-09 10:52:49 -080066
Jian Licc730a62016-05-10 16:36:16 -070067 private static final String DEVICE_NOT_FOUND = "Device is not found";
68 private static final String FLOW_NOT_FOUND = "Flow is not found";
Jian Li2907ad22016-05-12 23:08:54 -070069 private static final String APP_ID_NOT_FOUND = "Application Id is not found";
Ray Milkey131c0682016-10-18 11:12:50 -070070 private static final String FLOW_ARRAY_REQUIRED = "Flows array was not specified";
Jian Licc730a62016-05-10 16:36:16 -070071 private static final String FLOWS = "flows";
72 private static final String DEVICE_ID = "deviceId";
73 private static final String FLOW_ID = "flowId";
Ray Milkey4f5de002014-12-17 19:26:11 -080074
Jian Licc730a62016-05-10 16:36:16 -070075 private final FlowRuleService service = get(FlowRuleService.class);
76 private final ObjectNode root = mapper().createObjectNode();
77 private final ArrayNode flowsNode = root.putArray(FLOWS);
Ray Milkey4f5de002014-12-17 19:26:11 -080078
79 /**
Jian Licc730a62016-05-10 16:36:16 -070080 * Gets all flow entries. Returns array of all flow rules in the system.
81 *
82 * @return 200 OK with a collection of flows
Jian Li2907ad22016-05-12 23:08:54 -070083 * @onos.rsModel FlowEntries
Ray Milkey4f5de002014-12-17 19:26:11 -080084 */
85 @GET
86 @Produces(MediaType.APPLICATION_JSON)
87 public Response getFlows() {
Ray Milkey4f5de002014-12-17 19:26:11 -080088 final Iterable<Device> devices = get(DeviceService.class).getDevices();
89 for (final Device device : devices) {
Phaneendra Mandaaec654c2015-09-23 19:02:23 +053090 final Iterable<FlowEntry> flowEntries = service.getFlowEntries(device.id());
91 if (flowEntries != null) {
92 for (final FlowEntry entry : flowEntries) {
Thomas Vachuska8683e012015-03-18 18:03:33 -070093 flowsNode.add(codec(FlowEntry.class).encode(entry, this));
Ray Milkey4f5de002014-12-17 19:26:11 -080094 }
95 }
96 }
97
Ray Milkey3f025692015-01-26 11:15:41 -080098 return ok(root).build();
Ray Milkey4f5de002014-12-17 19:26:11 -080099 }
100
rsahot0360f9564d2018-04-30 16:25:05 -0400101 /**
102 * Gets all pending flow entries. Returns array of all pending flow rules in the system.
103 *
104 * @return 200 OK with a collection of flows
105 * @onos.rsModel FlowEntries
106 */
107 @GET
108 @Produces(MediaType.APPLICATION_JSON)
109 @Path("pending")
110 public Response getPendingFlows() {
111 final Iterable<Device> devices = get(DeviceService.class).getDevices();
112 for (final Device device : devices) {
113 final Iterable<FlowEntry> flowEntries = service.getFlowEntries(device.id());
114 if (flowEntries != null) {
115 for (final FlowEntry entry : flowEntries) {
116 if ((entry.state() == FlowEntry.FlowEntryState.PENDING_ADD) ||
117 (entry.state() == FlowEntry.FlowEntryState.PENDING_REMOVE)) {
118 flowsNode.add(codec(FlowEntry.class).encode(entry, this));
119 }
120 }
121 }
122 }
123
124 return ok(root).build();
125 }
126
Ray Milkey4f5de002014-12-17 19:26:11 -0800127 /**
Jian Licc730a62016-05-10 16:36:16 -0700128 * Creates new flow rules. Creates and installs a new flow rules.<br>
Jonathan Hartf09a13a2017-01-26 09:52:14 -0800129 * Flow rule criteria and instruction description:
130 * https://wiki.onosproject.org/display/ONOS/Flow+Rules
Thomas Vachuskaa1ae5e12016-03-28 10:36:30 -0700131 *
Ray Milkeybb23e0b2016-08-02 17:00:21 -0700132 * @param appId application id
Jian Licc730a62016-05-10 16:36:16 -0700133 * @param stream flow rules JSON
Thomas Vachuskaa1ae5e12016-03-28 10:36:30 -0700134 * @return status of the request - CREATED if the JSON is correct,
135 * BAD_REQUEST if the JSON is invalid
Jian Licc730a62016-05-10 16:36:16 -0700136 * @onos.rsModel FlowsBatchPost
Thomas Vachuskaa1ae5e12016-03-28 10:36:30 -0700137 */
138 @POST
139 @Consumes(MediaType.APPLICATION_JSON)
140 @Produces(MediaType.APPLICATION_JSON)
Jian Li2907ad22016-05-12 23:08:54 -0700141 public Response createFlows(@QueryParam("appId") String appId, InputStream stream) {
Thomas Vachuskaa1ae5e12016-03-28 10:36:30 -0700142 try {
Ray Milkey86ee5e82018-04-02 15:33:07 -0700143 ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
Ray Milkey131c0682016-10-18 11:12:50 -0700144 ArrayNode flowsArray = nullIsIllegal((ArrayNode) jsonTree.get(FLOWS),
145 FLOW_ARRAY_REQUIRED);
Jian Li2907ad22016-05-12 23:08:54 -0700146
Jonathan Hart9b80da82016-11-10 21:46:15 +0000147 if (appId != null) {
148 flowsArray.forEach(flowJson -> ((ObjectNode) flowJson).put("appId", appId));
149 }
Jian Li2907ad22016-05-12 23:08:54 -0700150
Thomas Vachuskaa1ae5e12016-03-28 10:36:30 -0700151 List<FlowRule> rules = codec(FlowRule.class).decode(flowsArray, this);
Ray Milkey131c0682016-10-18 11:12:50 -0700152
Thomas Vachuskaa1ae5e12016-03-28 10:36:30 -0700153 service.applyFlowRules(rules.toArray(new FlowRule[rules.size()]));
Ray Milkey460f9b02016-03-29 11:56:19 -0700154 rules.forEach(flowRule -> {
155 ObjectNode flowNode = mapper().createObjectNode();
156 flowNode.put(DEVICE_ID, flowRule.deviceId().toString())
Jayasree Ghosh28e1b3e2016-06-16 05:38:50 +0530157 .put(FLOW_ID, Long.toString(flowRule.id().value()));
Ray Milkey460f9b02016-03-29 11:56:19 -0700158 flowsNode.add(flowNode);
159 });
Thomas Vachuskaa1ae5e12016-03-28 10:36:30 -0700160 } catch (IOException ex) {
161 throw new IllegalArgumentException(ex);
162 }
Ray Milkey460f9b02016-03-29 11:56:19 -0700163 return Response.ok(root).build();
Thomas Vachuskaa1ae5e12016-03-28 10:36:30 -0700164 }
165
166 /**
Jian Licc730a62016-05-10 16:36:16 -0700167 * Gets flow entries of a device. Returns array of all flow rules for the
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700168 * specified device.
Jian Licc730a62016-05-10 16:36:16 -0700169 *
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700170 * @param deviceId device identifier
Jian Licc730a62016-05-10 16:36:16 -0700171 * @return 200 OK with a collection of flows of given device
Jian Li2907ad22016-05-12 23:08:54 -0700172 * @onos.rsModel FlowEntries
Ray Milkey4f5de002014-12-17 19:26:11 -0800173 */
174 @GET
175 @Produces(MediaType.APPLICATION_JSON)
Jian Li2907ad22016-05-12 23:08:54 -0700176 // TODO: we need to add "/device" suffix to the path to differentiate with appId
Ray Milkey4f5de002014-12-17 19:26:11 -0800177 @Path("{deviceId}")
178 public Response getFlowByDeviceId(@PathParam("deviceId") String deviceId) {
Phaneendra Mandaaec654c2015-09-23 19:02:23 +0530179 final Iterable<FlowEntry> flowEntries =
Ray Milkey4f5de002014-12-17 19:26:11 -0800180 service.getFlowEntries(DeviceId.deviceId(deviceId));
181
Jian Li9d616492016-03-09 10:52:49 -0800182 if (flowEntries == null || !flowEntries.iterator().hasNext()) {
Ray Milkey4f5de002014-12-17 19:26:11 -0800183 throw new ItemNotFoundException(DEVICE_NOT_FOUND);
184 }
Phaneendra Mandaaec654c2015-09-23 19:02:23 +0530185 for (final FlowEntry entry : flowEntries) {
Thomas Vachuska8683e012015-03-18 18:03:33 -0700186 flowsNode.add(codec(FlowEntry.class).encode(entry, this));
Ray Milkey4f5de002014-12-17 19:26:11 -0800187 }
Ray Milkey3f025692015-01-26 11:15:41 -0800188 return ok(root).build();
Ray Milkey4f5de002014-12-17 19:26:11 -0800189 }
190
191 /**
Jian Li2907ad22016-05-12 23:08:54 -0700192 * Gets flow rules. Returns the flow entry specified by the device id and
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700193 * flow rule id.
Jian Licc730a62016-05-10 16:36:16 -0700194 *
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700195 * @param deviceId device identifier
196 * @param flowId flow rule identifier
Jian Li2907ad22016-05-12 23:08:54 -0700197 * @return 200 OK with a collection of flows of given device and flow
198 * @onos.rsModel FlowEntries
Ray Milkey4f5de002014-12-17 19:26:11 -0800199 */
200 @GET
201 @Produces(MediaType.APPLICATION_JSON)
202 @Path("{deviceId}/{flowId}")
203 public Response getFlowByDeviceIdAndFlowId(@PathParam("deviceId") String deviceId,
204 @PathParam("flowId") long flowId) {
Phaneendra Mandaaec654c2015-09-23 19:02:23 +0530205 final Iterable<FlowEntry> flowEntries =
Ray Milkey4f5de002014-12-17 19:26:11 -0800206 service.getFlowEntries(DeviceId.deviceId(deviceId));
207
Jian Li9d616492016-03-09 10:52:49 -0800208 if (flowEntries == null || !flowEntries.iterator().hasNext()) {
Ray Milkey4f5de002014-12-17 19:26:11 -0800209 throw new ItemNotFoundException(DEVICE_NOT_FOUND);
210 }
Phaneendra Mandaaec654c2015-09-23 19:02:23 +0530211 for (final FlowEntry entry : flowEntries) {
Ray Milkey4f5de002014-12-17 19:26:11 -0800212 if (entry.id().value() == flowId) {
Thomas Vachuska8683e012015-03-18 18:03:33 -0700213 flowsNode.add(codec(FlowEntry.class).encode(entry, this));
Ray Milkey4f5de002014-12-17 19:26:11 -0800214 }
215 }
Ray Milkey3f025692015-01-26 11:15:41 -0800216 return ok(root).build();
Ray Milkey4f5de002014-12-17 19:26:11 -0800217 }
Ray Milkeyd43fe452015-05-29 09:35:12 -0700218
219 /**
Jian Li2907ad22016-05-12 23:08:54 -0700220 * Gets flow rules generated by an application.
221 * Returns the flow rule specified by the application id.
222 *
223 * @param appId application identifier
224 * @return 200 OK with a collection of flows of given application id
225 * @onos.rsModel FlowRules
226 */
227 @GET
228 @Produces(MediaType.APPLICATION_JSON)
229 @Path("application/{appId}")
230 public Response getFlowByAppId(@PathParam("appId") String appId) {
231 final ApplicationService appService = get(ApplicationService.class);
232 final ApplicationId idInstant = nullIsNotFound(appService.getId(appId), APP_ID_NOT_FOUND);
Bharath Thiruveedula99849dc2016-11-17 22:04:38 +0530233 final Iterable<FlowEntry> flowEntries = service.getFlowEntriesById(idInstant);
Jian Li2907ad22016-05-12 23:08:54 -0700234
Bharath Thiruveedula99849dc2016-11-17 22:04:38 +0530235 flowEntries.forEach(flow -> flowsNode.add(codec(FlowEntry.class).encode(flow, this)));
Jian Li2907ad22016-05-12 23:08:54 -0700236 return ok(root).build();
237 }
238
Bharath Thiruveedula99849dc2016-11-17 22:04:38 +0530239
Jian Li2907ad22016-05-12 23:08:54 -0700240 /**
241 * Removes flow rules by application ID.
242 * Removes a collection of flow rules generated by the given application.
243 *
244 * @param appId application identifier
245 * @return 204 NO CONTENT
246 */
247 @DELETE
248 @Produces(MediaType.APPLICATION_JSON)
249 @Path("application/{appId}")
250 public Response removeFlowByAppId(@PathParam("appId") String appId) {
251 final ApplicationService appService = get(ApplicationService.class);
252 final ApplicationId idInstant = nullIsNotFound(appService.getId(appId), APP_ID_NOT_FOUND);
253 service.removeFlowRulesById(idInstant);
254 return Response.noContent().build();
255 }
256
257 /**
Jian Licc730a62016-05-10 16:36:16 -0700258 * Creates new flow rule. Creates and installs a new flow rule for the
Andrea Campanella881f29f2016-03-03 19:18:42 -0800259 * specified device. <br>
Jonathan Hartf09a13a2017-01-26 09:52:14 -0800260 * Flow rule criteria and instruction description:
261 * https://wiki.onosproject.org/display/ONOS/Flow+Rules
Andrea Campanella881f29f2016-03-03 19:18:42 -0800262 *
Madan Jampani0dbac7a2015-06-25 10:37:45 -0700263 * @param deviceId device identifier
Jian Li2907ad22016-05-12 23:08:54 -0700264 * @param appId application identifier
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700265 * @param stream flow rule JSON
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700266 * @return status of the request - CREATED if the JSON is correct,
Ray Milkeyd43fe452015-05-29 09:35:12 -0700267 * BAD_REQUEST if the JSON is invalid
Jian Licc730a62016-05-10 16:36:16 -0700268 * @onos.rsModel FlowsPost
Ray Milkeyd43fe452015-05-29 09:35:12 -0700269 */
270 @POST
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700271 @Path("{deviceId}")
Ray Milkeyd43fe452015-05-29 09:35:12 -0700272 @Consumes(MediaType.APPLICATION_JSON)
273 @Produces(MediaType.APPLICATION_JSON)
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700274 public Response createFlow(@PathParam("deviceId") String deviceId,
Jian Li2907ad22016-05-12 23:08:54 -0700275 @QueryParam("appId") String appId,
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700276 InputStream stream) {
Ray Milkeyd43fe452015-05-29 09:35:12 -0700277 try {
Ray Milkey86ee5e82018-04-02 15:33:07 -0700278 ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
Ray Milkey5d915f42015-08-13 10:27:53 -0700279 JsonNode specifiedDeviceId = jsonTree.get("deviceId");
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700280 if (specifiedDeviceId != null &&
281 !specifiedDeviceId.asText().equals(deviceId)) {
282 throw new IllegalArgumentException(
283 "Invalid deviceId in flow creation request");
284 }
Ray Milkey5d915f42015-08-13 10:27:53 -0700285 jsonTree.put("deviceId", deviceId);
Jian Li2907ad22016-05-12 23:08:54 -0700286
Jonathan Hart9b80da82016-11-10 21:46:15 +0000287 if (appId != null) {
288 jsonTree.put("appId", appId);
289 }
Jian Li2907ad22016-05-12 23:08:54 -0700290
Ray Milkey5d915f42015-08-13 10:27:53 -0700291 FlowRule rule = codec(FlowRule.class).decode(jsonTree, this);
Ray Milkeyd43fe452015-05-29 09:35:12 -0700292 service.applyFlowRules(rule);
Jian Li9d616492016-03-09 10:52:49 -0800293 UriBuilder locationBuilder = uriInfo.getBaseUriBuilder()
294 .path("flows")
295 .path(deviceId)
Ray Milkey90289b02016-03-31 15:23:28 -0700296 .path(Long.toString(rule.id().value()));
Jian Li9d616492016-03-09 10:52:49 -0800297
298 return Response
299 .created(locationBuilder.build())
300 .build();
301 } catch (IOException ex) {
Ray Milkey5d915f42015-08-13 10:27:53 -0700302 throw new IllegalArgumentException(ex);
Ray Milkeyd43fe452015-05-29 09:35:12 -0700303 }
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700304 }
305
306 /**
Jian Li2907ad22016-05-12 23:08:54 -0700307 * Removes flow rule. Removes the specified flow rule.
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700308 *
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -0700309 * @param deviceId device identifier
310 * @param flowId flow rule identifier
Jian Lic2a542b2016-05-10 11:48:19 -0700311 * @return 204 NO CONTENT
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700312 */
313 @DELETE
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700314 @Path("{deviceId}/{flowId}")
Jian Lic2a542b2016-05-10 11:48:19 -0700315 public Response deleteFlowByDeviceIdAndFlowId(@PathParam("deviceId") String deviceId,
Jian Licc730a62016-05-10 16:36:16 -0700316 @PathParam("flowId") long flowId) {
Phaneendra Mandaaec654c2015-09-23 19:02:23 +0530317 final Iterable<FlowEntry> flowEntries =
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700318 service.getFlowEntries(DeviceId.deviceId(deviceId));
319
Phaneendra Mandaaec654c2015-09-23 19:02:23 +0530320 if (!flowEntries.iterator().hasNext()) {
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700321 throw new ItemNotFoundException(DEVICE_NOT_FOUND);
322 }
323
Phaneendra Mandaaec654c2015-09-23 19:02:23 +0530324 StreamSupport.stream(flowEntries.spliterator(), false)
Ray Milkeyeb5c7172015-06-23 14:59:27 -0700325 .filter(entry -> entry.id().value() == flowId)
326 .forEach(service::removeFlowRules);
Jian Lic2a542b2016-05-10 11:48:19 -0700327 return Response.noContent().build();
Ray Milkeyd43fe452015-05-29 09:35:12 -0700328 }
329
Ray Milkey460f9b02016-03-29 11:56:19 -0700330 /**
331 * Removes a batch of flow rules.
Ray Milkeybee35092016-04-12 10:01:26 -0700332 *
333 * @param stream stream for posted JSON
Jian Licc730a62016-05-10 16:36:16 -0700334 * @return 204 NO CONTENT
Ray Milkey460f9b02016-03-29 11:56:19 -0700335 */
336 @DELETE
Jian Lic2a542b2016-05-10 11:48:19 -0700337 public Response deleteFlows(InputStream stream) {
Ray Milkey460f9b02016-03-29 11:56:19 -0700338 ListMultimap<DeviceId, Long> deviceMap = ArrayListMultimap.create();
339 List<FlowEntry> rulesToRemove = new ArrayList<>();
340
341 try {
Ray Milkey86ee5e82018-04-02 15:33:07 -0700342 ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
Ray Milkey460f9b02016-03-29 11:56:19 -0700343
344 JsonNode jsonFlows = jsonTree.get("flows");
345
346 jsonFlows.forEach(node -> {
347 DeviceId deviceId =
348 DeviceId.deviceId(
349 nullIsNotFound(node.get(DEVICE_ID),
Jian Licc730a62016-05-10 16:36:16 -0700350 DEVICE_NOT_FOUND).asText());
Ray Milkey460f9b02016-03-29 11:56:19 -0700351 long flowId = nullIsNotFound(node.get(FLOW_ID),
Jian Licc730a62016-05-10 16:36:16 -0700352 FLOW_NOT_FOUND).asLong();
Ray Milkey460f9b02016-03-29 11:56:19 -0700353 deviceMap.put(deviceId, flowId);
354
355 });
356 } catch (IOException ex) {
357 throw new IllegalArgumentException(ex);
358 }
359
360 deviceMap.keySet().forEach(deviceId -> {
361 List<Long> flowIds = deviceMap.get(deviceId);
362 Iterable<FlowEntry> entries = service.getFlowEntries(deviceId);
363 flowIds.forEach(flowId -> {
364 StreamSupport.stream(entries.spliterator(), false)
365 .filter(entry -> flowId == entry.id().value())
366 .forEach(rulesToRemove::add);
367 });
368 });
369
370 service.removeFlowRules(rulesToRemove.toArray(new FlowEntry[0]));
Jian Lic2a542b2016-05-10 11:48:19 -0700371 return Response.noContent().build();
Ray Milkey460f9b02016-03-29 11:56:19 -0700372 }
Ray Milkey4f5de002014-12-17 19:26:11 -0800373}