Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 3 | * |
| 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 Hart | 9bb32ab | 2015-05-05 18:17:31 -0700 | [diff] [blame] | 16 | package org.onosproject.rest.resources; |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 17 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Ray Milkey | 460f9b0 | 2016-03-29 11:56:19 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ArrayListMultimap; |
| 22 | import com.google.common.collect.ListMultimap; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 23 | import org.onlab.util.ItemNotFoundException; |
| 24 | import org.onosproject.net.Device; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.device.DeviceService; |
| 27 | import org.onosproject.net.flow.FlowEntry; |
| 28 | import org.onosproject.net.flow.FlowRule; |
| 29 | import org.onosproject.net.flow.FlowRuleService; |
| 30 | import org.onosproject.rest.AbstractWebResource; |
| 31 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 32 | import javax.ws.rs.Consumes; |
| 33 | import javax.ws.rs.DELETE; |
| 34 | import javax.ws.rs.GET; |
| 35 | import javax.ws.rs.POST; |
| 36 | import javax.ws.rs.Path; |
| 37 | import javax.ws.rs.PathParam; |
| 38 | import javax.ws.rs.Produces; |
| 39 | import javax.ws.rs.core.Context; |
| 40 | import javax.ws.rs.core.MediaType; |
| 41 | import javax.ws.rs.core.Response; |
| 42 | import javax.ws.rs.core.UriBuilder; |
| 43 | import javax.ws.rs.core.UriInfo; |
| 44 | import java.io.IOException; |
| 45 | import java.io.InputStream; |
Ray Milkey | 460f9b0 | 2016-03-29 11:56:19 -0700 | [diff] [blame] | 46 | import java.util.ArrayList; |
Thomas Vachuska | a1ae5e1 | 2016-03-28 10:36:30 -0700 | [diff] [blame] | 47 | import java.util.List; |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 48 | import java.util.stream.StreamSupport; |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 49 | |
Ray Milkey | 460f9b0 | 2016-03-29 11:56:19 -0700 | [diff] [blame] | 50 | import static org.onlab.util.Tools.nullIsNotFound; |
| 51 | |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 52 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 53 | * Query and program flow rules. |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 54 | */ |
| 55 | |
| 56 | @Path("flows") |
| 57 | public class FlowsWebResource extends AbstractWebResource { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 58 | |
| 59 | @Context |
| 60 | UriInfo uriInfo; |
| 61 | |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 62 | public static final String DEVICE_NOT_FOUND = "Device is not found"; |
Ray Milkey | 460f9b0 | 2016-03-29 11:56:19 -0700 | [diff] [blame] | 63 | public static final String FLOW_NOT_FOUND = "Flow is not found"; |
Thomas Vachuska | a1ae5e1 | 2016-03-28 10:36:30 -0700 | [diff] [blame] | 64 | public static final String FLOWS = "flows"; |
Ray Milkey | 460f9b0 | 2016-03-29 11:56:19 -0700 | [diff] [blame] | 65 | public static final String DEVICE_ID = "deviceId"; |
| 66 | public static final String FLOW_ID = "flowId"; |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 67 | |
| 68 | final FlowRuleService service = get(FlowRuleService.class); |
| 69 | final ObjectNode root = mapper().createObjectNode(); |
Thomas Vachuska | a1ae5e1 | 2016-03-28 10:36:30 -0700 | [diff] [blame] | 70 | final ArrayNode flowsNode = root.putArray(FLOWS); |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 71 | |
| 72 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 73 | * Get all flow entries. Returns array of all flow rules in the system. |
Andrea Campanella | 10c4adc | 2015-12-03 15:27:54 -0800 | [diff] [blame] | 74 | * @onos.rsModel Flows |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 75 | * @return array of all the intents in the system |
| 76 | */ |
| 77 | @GET |
| 78 | @Produces(MediaType.APPLICATION_JSON) |
| 79 | public Response getFlows() { |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 80 | final Iterable<Device> devices = get(DeviceService.class).getDevices(); |
| 81 | for (final Device device : devices) { |
Phaneendra Manda | aec654c | 2015-09-23 19:02:23 +0530 | [diff] [blame] | 82 | final Iterable<FlowEntry> flowEntries = service.getFlowEntries(device.id()); |
| 83 | if (flowEntries != null) { |
| 84 | for (final FlowEntry entry : flowEntries) { |
Thomas Vachuska | 8683e01 | 2015-03-18 18:03:33 -0700 | [diff] [blame] | 85 | flowsNode.add(codec(FlowEntry.class).encode(entry, this)); |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
Ray Milkey | 3f02569 | 2015-01-26 11:15:41 -0800 | [diff] [blame] | 90 | return ok(root).build(); |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
Thomas Vachuska | a1ae5e1 | 2016-03-28 10:36:30 -0700 | [diff] [blame] | 94 | * Create new flow rules. Creates and installs a new flow rules.<br> |
| 95 | * Instructions description: |
| 96 | * https://wiki.onosproject.org/display/ONOS/Flow+Rule+Instructions |
| 97 | * <br> |
| 98 | * Criteria description: |
| 99 | * https://wiki.onosproject.org/display/ONOS/Flow+Rule+Criteria |
| 100 | * |
| 101 | * @onos.rsModel FlowsBatchPost |
| 102 | * @param stream flow rules JSON |
| 103 | * @return status of the request - CREATED if the JSON is correct, |
| 104 | * BAD_REQUEST if the JSON is invalid |
| 105 | */ |
| 106 | @POST |
| 107 | @Consumes(MediaType.APPLICATION_JSON) |
| 108 | @Produces(MediaType.APPLICATION_JSON) |
| 109 | public Response createFlows(InputStream stream) { |
| 110 | try { |
| 111 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
| 112 | ArrayNode flowsArray = (ArrayNode) jsonTree.get(FLOWS); |
| 113 | List<FlowRule> rules = codec(FlowRule.class).decode(flowsArray, this); |
| 114 | service.applyFlowRules(rules.toArray(new FlowRule[rules.size()])); |
Ray Milkey | 460f9b0 | 2016-03-29 11:56:19 -0700 | [diff] [blame] | 115 | rules.forEach(flowRule -> { |
| 116 | ObjectNode flowNode = mapper().createObjectNode(); |
| 117 | flowNode.put(DEVICE_ID, flowRule.deviceId().toString()) |
| 118 | .put(FLOW_ID, flowRule.id().value()); |
| 119 | flowsNode.add(flowNode); |
| 120 | }); |
Thomas Vachuska | a1ae5e1 | 2016-03-28 10:36:30 -0700 | [diff] [blame] | 121 | } catch (IOException ex) { |
| 122 | throw new IllegalArgumentException(ex); |
| 123 | } |
Ray Milkey | 460f9b0 | 2016-03-29 11:56:19 -0700 | [diff] [blame] | 124 | return Response.ok(root).build(); |
Thomas Vachuska | a1ae5e1 | 2016-03-28 10:36:30 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 128 | * Get flow entries of a device. Returns array of all flow rules for the |
| 129 | * specified device. |
Andrea Campanella | 10c4adc | 2015-12-03 15:27:54 -0800 | [diff] [blame] | 130 | * @onos.rsModel Flows |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 131 | * @param deviceId device identifier |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 132 | * @return flow data as an array |
| 133 | */ |
| 134 | @GET |
| 135 | @Produces(MediaType.APPLICATION_JSON) |
| 136 | @Path("{deviceId}") |
| 137 | public Response getFlowByDeviceId(@PathParam("deviceId") String deviceId) { |
Phaneendra Manda | aec654c | 2015-09-23 19:02:23 +0530 | [diff] [blame] | 138 | final Iterable<FlowEntry> flowEntries = |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 139 | service.getFlowEntries(DeviceId.deviceId(deviceId)); |
| 140 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 141 | if (flowEntries == null || !flowEntries.iterator().hasNext()) { |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 142 | throw new ItemNotFoundException(DEVICE_NOT_FOUND); |
| 143 | } |
Phaneendra Manda | aec654c | 2015-09-23 19:02:23 +0530 | [diff] [blame] | 144 | for (final FlowEntry entry : flowEntries) { |
Thomas Vachuska | 8683e01 | 2015-03-18 18:03:33 -0700 | [diff] [blame] | 145 | flowsNode.add(codec(FlowEntry.class).encode(entry, this)); |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 146 | } |
Ray Milkey | 3f02569 | 2015-01-26 11:15:41 -0800 | [diff] [blame] | 147 | return ok(root).build(); |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 151 | * Get flow rule. Returns the flow entry specified by the device id and |
| 152 | * flow rule id. |
Andrea Campanella | 10c4adc | 2015-12-03 15:27:54 -0800 | [diff] [blame] | 153 | * @onos.rsModel Flows |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 154 | * @param deviceId device identifier |
| 155 | * @param flowId flow rule identifier |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 156 | * @return flow data as an array |
| 157 | */ |
| 158 | @GET |
| 159 | @Produces(MediaType.APPLICATION_JSON) |
| 160 | @Path("{deviceId}/{flowId}") |
| 161 | public Response getFlowByDeviceIdAndFlowId(@PathParam("deviceId") String deviceId, |
| 162 | @PathParam("flowId") long flowId) { |
Phaneendra Manda | aec654c | 2015-09-23 19:02:23 +0530 | [diff] [blame] | 163 | final Iterable<FlowEntry> flowEntries = |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 164 | service.getFlowEntries(DeviceId.deviceId(deviceId)); |
| 165 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 166 | if (flowEntries == null || !flowEntries.iterator().hasNext()) { |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 167 | throw new ItemNotFoundException(DEVICE_NOT_FOUND); |
| 168 | } |
Phaneendra Manda | aec654c | 2015-09-23 19:02:23 +0530 | [diff] [blame] | 169 | for (final FlowEntry entry : flowEntries) { |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 170 | if (entry.id().value() == flowId) { |
Thomas Vachuska | 8683e01 | 2015-03-18 18:03:33 -0700 | [diff] [blame] | 171 | flowsNode.add(codec(FlowEntry.class).encode(entry, this)); |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 172 | } |
| 173 | } |
Ray Milkey | 3f02569 | 2015-01-26 11:15:41 -0800 | [diff] [blame] | 174 | return ok(root).build(); |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 175 | } |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 176 | |
| 177 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 178 | * Create new flow rule. Creates and installs a new flow rule for the |
Andrea Campanella | 881f29f | 2016-03-03 19:18:42 -0800 | [diff] [blame] | 179 | * specified device. <br> |
| 180 | * Instructions description: |
| 181 | * https://wiki.onosproject.org/display/ONOS/Flow+Rule+Instructions |
| 182 | * <br> |
| 183 | * Criteria description: |
| 184 | * https://wiki.onosproject.org/display/ONOS/Flow+Rule+Criteria |
| 185 | * |
Andrea Campanella | 10c4adc | 2015-12-03 15:27:54 -0800 | [diff] [blame] | 186 | * @onos.rsModel FlowsPost |
Madan Jampani | 0dbac7a | 2015-06-25 10:37:45 -0700 | [diff] [blame] | 187 | * @param deviceId device identifier |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 188 | * @param stream flow rule JSON |
Ray Milkey | eb5c717 | 2015-06-23 14:59:27 -0700 | [diff] [blame] | 189 | * @return status of the request - CREATED if the JSON is correct, |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 190 | * BAD_REQUEST if the JSON is invalid |
| 191 | */ |
| 192 | @POST |
Ray Milkey | eb5c717 | 2015-06-23 14:59:27 -0700 | [diff] [blame] | 193 | @Path("{deviceId}") |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 194 | @Consumes(MediaType.APPLICATION_JSON) |
| 195 | @Produces(MediaType.APPLICATION_JSON) |
Ray Milkey | eb5c717 | 2015-06-23 14:59:27 -0700 | [diff] [blame] | 196 | public Response createFlow(@PathParam("deviceId") String deviceId, |
| 197 | InputStream stream) { |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 198 | try { |
Ray Milkey | 5d915f4 | 2015-08-13 10:27:53 -0700 | [diff] [blame] | 199 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
| 200 | JsonNode specifiedDeviceId = jsonTree.get("deviceId"); |
Ray Milkey | eb5c717 | 2015-06-23 14:59:27 -0700 | [diff] [blame] | 201 | if (specifiedDeviceId != null && |
| 202 | !specifiedDeviceId.asText().equals(deviceId)) { |
| 203 | throw new IllegalArgumentException( |
| 204 | "Invalid deviceId in flow creation request"); |
| 205 | } |
Ray Milkey | 5d915f4 | 2015-08-13 10:27:53 -0700 | [diff] [blame] | 206 | jsonTree.put("deviceId", deviceId); |
| 207 | FlowRule rule = codec(FlowRule.class).decode(jsonTree, this); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 208 | service.applyFlowRules(rule); |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 209 | UriBuilder locationBuilder = uriInfo.getBaseUriBuilder() |
| 210 | .path("flows") |
| 211 | .path(deviceId) |
Ray Milkey | 90289b0 | 2016-03-31 15:23:28 -0700 | [diff] [blame] | 212 | .path(Long.toString(rule.id().value())); |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 213 | |
| 214 | return Response |
| 215 | .created(locationBuilder.build()) |
| 216 | .build(); |
| 217 | } catch (IOException ex) { |
Ray Milkey | 5d915f4 | 2015-08-13 10:27:53 -0700 | [diff] [blame] | 218 | throw new IllegalArgumentException(ex); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 219 | } |
Ray Milkey | eb5c717 | 2015-06-23 14:59:27 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /** |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 223 | * Remove flow rule. Removes the specified flow rule. |
Ray Milkey | eb5c717 | 2015-06-23 14:59:27 -0700 | [diff] [blame] | 224 | * |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 225 | * @param deviceId device identifier |
| 226 | * @param flowId flow rule identifier |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 227 | * @return 204 NO CONTENT |
Ray Milkey | eb5c717 | 2015-06-23 14:59:27 -0700 | [diff] [blame] | 228 | */ |
| 229 | @DELETE |
| 230 | @Produces(MediaType.APPLICATION_JSON) |
| 231 | @Path("{deviceId}/{flowId}") |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 232 | public Response deleteFlowByDeviceIdAndFlowId(@PathParam("deviceId") String deviceId, |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 233 | @PathParam("flowId") long flowId) { |
Phaneendra Manda | aec654c | 2015-09-23 19:02:23 +0530 | [diff] [blame] | 234 | final Iterable<FlowEntry> flowEntries = |
Ray Milkey | eb5c717 | 2015-06-23 14:59:27 -0700 | [diff] [blame] | 235 | service.getFlowEntries(DeviceId.deviceId(deviceId)); |
| 236 | |
Phaneendra Manda | aec654c | 2015-09-23 19:02:23 +0530 | [diff] [blame] | 237 | if (!flowEntries.iterator().hasNext()) { |
Ray Milkey | eb5c717 | 2015-06-23 14:59:27 -0700 | [diff] [blame] | 238 | throw new ItemNotFoundException(DEVICE_NOT_FOUND); |
| 239 | } |
| 240 | |
Phaneendra Manda | aec654c | 2015-09-23 19:02:23 +0530 | [diff] [blame] | 241 | StreamSupport.stream(flowEntries.spliterator(), false) |
Ray Milkey | eb5c717 | 2015-06-23 14:59:27 -0700 | [diff] [blame] | 242 | .filter(entry -> entry.id().value() == flowId) |
| 243 | .forEach(service::removeFlowRules); |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 244 | return Response.noContent().build(); |
Ray Milkey | d43fe45 | 2015-05-29 09:35:12 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Ray Milkey | 460f9b0 | 2016-03-29 11:56:19 -0700 | [diff] [blame] | 247 | /** |
| 248 | * Removes a batch of flow rules. |
Ray Milkey | bee3509 | 2016-04-12 10:01:26 -0700 | [diff] [blame] | 249 | * |
| 250 | * @param stream stream for posted JSON |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 251 | * @return NO CONTENT |
Ray Milkey | 460f9b0 | 2016-03-29 11:56:19 -0700 | [diff] [blame] | 252 | */ |
| 253 | @DELETE |
| 254 | @Produces(MediaType.APPLICATION_JSON) |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 255 | public Response deleteFlows(InputStream stream) { |
Ray Milkey | 460f9b0 | 2016-03-29 11:56:19 -0700 | [diff] [blame] | 256 | ListMultimap<DeviceId, Long> deviceMap = ArrayListMultimap.create(); |
| 257 | List<FlowEntry> rulesToRemove = new ArrayList<>(); |
| 258 | |
| 259 | try { |
| 260 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
| 261 | |
| 262 | JsonNode jsonFlows = jsonTree.get("flows"); |
| 263 | |
| 264 | jsonFlows.forEach(node -> { |
| 265 | DeviceId deviceId = |
| 266 | DeviceId.deviceId( |
| 267 | nullIsNotFound(node.get(DEVICE_ID), |
| 268 | DEVICE_NOT_FOUND).asText()); |
| 269 | long flowId = nullIsNotFound(node.get(FLOW_ID), |
| 270 | FLOW_NOT_FOUND).asLong(); |
| 271 | deviceMap.put(deviceId, flowId); |
| 272 | |
| 273 | }); |
| 274 | } catch (IOException ex) { |
| 275 | throw new IllegalArgumentException(ex); |
| 276 | } |
| 277 | |
| 278 | deviceMap.keySet().forEach(deviceId -> { |
| 279 | List<Long> flowIds = deviceMap.get(deviceId); |
| 280 | Iterable<FlowEntry> entries = service.getFlowEntries(deviceId); |
| 281 | flowIds.forEach(flowId -> { |
| 282 | StreamSupport.stream(entries.spliterator(), false) |
| 283 | .filter(entry -> flowId == entry.id().value()) |
| 284 | .forEach(rulesToRemove::add); |
| 285 | }); |
| 286 | }); |
| 287 | |
| 288 | service.removeFlowRules(rulesToRemove.toArray(new FlowEntry[0])); |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 289 | return Response.noContent().build(); |
Ray Milkey | 460f9b0 | 2016-03-29 11:56:19 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Ray Milkey | 4f5de00 | 2014-12-17 19:26:11 -0800 | [diff] [blame] | 292 | } |