Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [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 | */ |
| 16 | |
| 17 | package org.onosproject.ui.impl; |
| 18 | |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Simon Hunt | abd16f6 | 2015-05-01 13:14:40 -0700 | [diff] [blame] | 20 | import com.google.common.base.Strings; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 21 | import com.google.common.collect.ImmutableSet; |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.core.DefaultApplicationId; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.net.flow.FlowEntry; |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 26 | import org.onosproject.net.flow.FlowRule; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 27 | import org.onosproject.net.flow.FlowRuleService; |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 28 | import org.onosproject.net.flow.TrafficTreatment; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 29 | import org.onosproject.net.flow.criteria.Criterion; |
| 30 | import org.onosproject.net.flow.instructions.Instruction; |
Simon Hunt | d2747a0 | 2015-04-30 22:41:16 -0700 | [diff] [blame] | 31 | import org.onosproject.ui.RequestHandler; |
Simon Hunt | a0ddb02 | 2015-05-01 09:53:01 -0700 | [diff] [blame] | 32 | import org.onosproject.ui.UiMessageHandler; |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 33 | import org.onosproject.ui.table.CellFormatter; |
Simon Hunt | 3d1b065 | 2015-05-05 17:27:24 -0700 | [diff] [blame] | 34 | import org.onosproject.ui.table.TableModel; |
Simon Hunt | abd16f6 | 2015-05-01 13:14:40 -0700 | [diff] [blame] | 35 | import org.onosproject.ui.table.TableRequestHandler; |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 36 | import org.onosproject.ui.table.cell.EnumFormatter; |
Simon Hunt | 3e4ccaf | 2016-01-12 19:59:54 -0800 | [diff] [blame] | 37 | import org.onosproject.ui.table.cell.HexFormatter; |
| 38 | import org.onosproject.ui.table.cell.HexLongFormatter; |
Simon Hunt | be60dde | 2016-01-13 12:26:56 -0800 | [diff] [blame] | 39 | import org.onosproject.ui.table.cell.NumberFormatter; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 40 | |
Simon Hunt | d2747a0 | 2015-04-30 22:41:16 -0700 | [diff] [blame] | 41 | import java.util.Collection; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 42 | import java.util.List; |
| 43 | import java.util.Set; |
| 44 | |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 45 | |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 46 | /** |
| 47 | * Message handler for flow view related messages. |
| 48 | */ |
Simon Hunt | a0ddb02 | 2015-05-01 09:53:01 -0700 | [diff] [blame] | 49 | public class FlowViewMessageHandler extends UiMessageHandler { |
Simon Hunt | d2747a0 | 2015-04-30 22:41:16 -0700 | [diff] [blame] | 50 | |
| 51 | private static final String FLOW_DATA_REQ = "flowDataRequest"; |
Simon Hunt | abd16f6 | 2015-05-01 13:14:40 -0700 | [diff] [blame] | 52 | private static final String FLOW_DATA_RESP = "flowDataResponse"; |
| 53 | private static final String FLOWS = "flows"; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 54 | |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 55 | private static final String FLOW_DETAILS_REQ = "flowDetailsRequest"; |
| 56 | private static final String FLOW_DETAILS_RESP = "flowDetailsResponse"; |
| 57 | private static final String DETAILS = "details"; |
| 58 | private static final String FLOW_PRIORITY = "priority"; |
| 59 | |
Simon Hunt | abd16f6 | 2015-05-01 13:14:40 -0700 | [diff] [blame] | 60 | private static final String ID = "id"; |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 61 | private static final String FLOW_ID = "flowId"; |
Simon Hunt | abd16f6 | 2015-05-01 13:14:40 -0700 | [diff] [blame] | 62 | private static final String APP_ID = "appId"; |
| 63 | private static final String GROUP_ID = "groupId"; |
| 64 | private static final String TABLE_ID = "tableId"; |
| 65 | private static final String PRIORITY = "priority"; |
| 66 | private static final String SELECTOR = "selector"; |
| 67 | private static final String TREATMENT = "treatment"; |
| 68 | private static final String TIMEOUT = "timeout"; |
| 69 | private static final String PERMANENT = "permanent"; |
| 70 | private static final String STATE = "state"; |
Bri Prebilic Cole | 641b97b | 2015-05-05 14:47:40 -0700 | [diff] [blame] | 71 | private static final String PACKETS = "packets"; |
| 72 | private static final String BYTES = "bytes"; |
Simon Hunt | abd16f6 | 2015-05-01 13:14:40 -0700 | [diff] [blame] | 73 | |
| 74 | private static final String COMMA = ", "; |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 75 | private static final String OX = "0x"; |
| 76 | private static final String EMPTY = ""; |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 77 | |
Simon Hunt | 3d1b065 | 2015-05-05 17:27:24 -0700 | [diff] [blame] | 78 | private static final String[] COL_IDS = { |
| 79 | ID, APP_ID, GROUP_ID, TABLE_ID, PRIORITY, SELECTOR, |
| 80 | TREATMENT, TIMEOUT, PERMANENT, STATE, PACKETS, BYTES |
| 81 | }; |
| 82 | |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 83 | @Override |
Simon Hunt | da58088 | 2015-05-12 20:58:18 -0700 | [diff] [blame] | 84 | protected Collection<RequestHandler> createRequestHandlers() { |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 85 | return ImmutableSet.of( |
| 86 | new FlowDataRequest(), |
| 87 | new DetailRequestHandler() |
| 88 | ); |
Simon Hunt | d2747a0 | 2015-04-30 22:41:16 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 91 | private StringBuilder removeTrailingComma(StringBuilder sb) { |
| 92 | int pos = sb.lastIndexOf(COMMA); |
| 93 | sb.delete(pos, sb.length()); |
| 94 | return sb; |
| 95 | } |
| 96 | |
Simon Hunt | abd16f6 | 2015-05-01 13:14:40 -0700 | [diff] [blame] | 97 | // handler for flow table requests |
| 98 | private final class FlowDataRequest extends TableRequestHandler { |
Simon Hunt | d2747a0 | 2015-04-30 22:41:16 -0700 | [diff] [blame] | 99 | |
Jian Li | 69f6663 | 2016-01-15 12:27:42 -0800 | [diff] [blame] | 100 | private static final String NO_ROWS_MESSAGE = "No flows found"; |
| 101 | |
Simon Hunt | d2747a0 | 2015-04-30 22:41:16 -0700 | [diff] [blame] | 102 | private FlowDataRequest() { |
Simon Hunt | abd16f6 | 2015-05-01 13:14:40 -0700 | [diff] [blame] | 103 | super(FLOW_DATA_REQ, FLOW_DATA_RESP, FLOWS); |
Simon Hunt | d2747a0 | 2015-04-30 22:41:16 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Override |
Simon Hunt | 3d1b065 | 2015-05-05 17:27:24 -0700 | [diff] [blame] | 107 | protected String[] getColumnIds() { |
| 108 | return COL_IDS; |
Simon Hunt | 44aa2f8 | 2015-04-30 15:01:35 -0700 | [diff] [blame] | 109 | } |
Simon Hunt | 44aa2f8 | 2015-04-30 15:01:35 -0700 | [diff] [blame] | 110 | |
Simon Hunt | 3d1b065 | 2015-05-05 17:27:24 -0700 | [diff] [blame] | 111 | @Override |
Jian Li | 8baf447 | 2016-01-15 15:08:09 -0800 | [diff] [blame] | 112 | protected String noRowsMessage(ObjectNode payload) { |
Jian Li | 69f6663 | 2016-01-15 12:27:42 -0800 | [diff] [blame] | 113 | return NO_ROWS_MESSAGE; |
| 114 | } |
| 115 | |
| 116 | @Override |
Simon Hunt | 3d1b065 | 2015-05-05 17:27:24 -0700 | [diff] [blame] | 117 | protected TableModel createTableModel() { |
| 118 | TableModel tm = super.createTableModel(); |
Simon Hunt | 3e4ccaf | 2016-01-12 19:59:54 -0800 | [diff] [blame] | 119 | tm.setFormatter(ID, HexLongFormatter.INSTANCE); |
| 120 | tm.setFormatter(GROUP_ID, HexFormatter.INSTANCE); |
Simon Hunt | be60dde | 2016-01-13 12:26:56 -0800 | [diff] [blame] | 121 | tm.setFormatter(STATE, EnumFormatter.INSTANCE); |
| 122 | tm.setFormatter(PACKETS, NumberFormatter.INTEGER); |
| 123 | tm.setFormatter(BYTES, NumberFormatter.INTEGER); |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 124 | tm.setFormatter(SELECTOR, new SelectorFormatter()); |
| 125 | tm.setFormatter(TREATMENT, new TreatmentFormatter()); |
Simon Hunt | 3d1b065 | 2015-05-05 17:27:24 -0700 | [diff] [blame] | 126 | return tm; |
| 127 | } |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 128 | |
Simon Hunt | 3d1b065 | 2015-05-05 17:27:24 -0700 | [diff] [blame] | 129 | @Override |
| 130 | protected void populateTable(TableModel tm, ObjectNode payload) { |
| 131 | String uri = string(payload, "devId"); |
| 132 | if (!Strings.isNullOrEmpty(uri)) { |
| 133 | DeviceId deviceId = DeviceId.deviceId(uri); |
| 134 | FlowRuleService frs = get(FlowRuleService.class); |
| 135 | for (FlowEntry flow : frs.getFlowEntries(deviceId)) { |
| 136 | populateRow(tm.addRow(), flow); |
| 137 | } |
| 138 | } |
| 139 | } |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 140 | |
Simon Hunt | 3d1b065 | 2015-05-05 17:27:24 -0700 | [diff] [blame] | 141 | private void populateRow(TableModel.Row row, FlowEntry flow) { |
| 142 | row.cell(ID, flow.id().value()) |
Simon Hunt | 8a0429a | 2017-01-06 16:52:47 -0800 | [diff] [blame] | 143 | .cell(APP_ID, flow.appId()) |
| 144 | .cell(GROUP_ID, flow.groupId().id()) |
| 145 | .cell(TABLE_ID, flow.tableId()) |
| 146 | .cell(PRIORITY, flow.priority()) |
| 147 | .cell(TIMEOUT, flow.timeout()) |
| 148 | .cell(PERMANENT, flow.isPermanent()) |
| 149 | .cell(STATE, flow.state()) |
| 150 | .cell(PACKETS, flow.packets()) |
| 151 | .cell(BYTES, flow.bytes()) |
| 152 | .cell(SELECTOR, flow) |
| 153 | .cell(TREATMENT, flow); |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 156 | private final class SelectorFormatter implements CellFormatter { |
| 157 | @Override |
| 158 | public String format(Object value) { |
| 159 | FlowEntry flow = (FlowEntry) value; |
| 160 | Set<Criterion> criteria = flow.selector().criteria(); |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 161 | |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 162 | if (criteria.isEmpty()) { |
| 163 | return "(No traffic selector criteria for this flow)"; |
| 164 | } |
| 165 | StringBuilder sb = new StringBuilder("Criteria: "); |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 166 | for (Criterion c : criteria) { |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 167 | sb.append(c).append(COMMA); |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 168 | } |
| 169 | removeTrailingComma(sb); |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 170 | |
| 171 | return sb.toString(); |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 175 | private final class TreatmentFormatter implements CellFormatter { |
| 176 | @Override |
| 177 | public String format(Object value) { |
| 178 | FlowEntry flow = (FlowEntry) value; |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 179 | TrafficTreatment treatment = flow.treatment(); |
| 180 | List<Instruction> imm = treatment.immediate(); |
| 181 | List<Instruction> def = treatment.deferred(); |
| 182 | if (imm.isEmpty() && |
| 183 | def.isEmpty() && |
| 184 | treatment.metered() == null && |
| 185 | treatment.tableTransition() == null) { |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 186 | return "(No traffic treatment instructions for this flow)"; |
| 187 | } |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 188 | |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 189 | StringBuilder sb = new StringBuilder("Treatment Instructions: "); |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 190 | formatInstructs(sb, imm, "immediate:"); |
| 191 | formatInstructs(sb, def, "deferred:"); |
| 192 | |
| 193 | if (treatment.metered() != null) { |
| 194 | sb.append("metered:") |
| 195 | .append(treatment.metered()) |
| 196 | .append(COMMA); |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 197 | } |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 198 | |
| 199 | if (treatment.tableTransition() != null) { |
| 200 | sb.append("transition:") |
| 201 | .append(treatment.tableTransition()) |
| 202 | .append(COMMA); |
Konstantinos Kanonakis | 845c328 | 2016-04-01 17:34:20 -0500 | [diff] [blame] | 203 | } |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 204 | |
| 205 | if (treatment.writeMetadata() != null) { |
| 206 | sb.append("metadata:") |
| 207 | .append(treatment.writeMetadata()) |
| 208 | .append(COMMA); |
Konstantinos Kanonakis | 845c328 | 2016-04-01 17:34:20 -0500 | [diff] [blame] | 209 | } |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 210 | |
| 211 | sb.append("cleared:").append(treatment.clearedDeferred()); |
Bri Prebilic Cole | 9467a23 | 2015-05-06 16:59:05 -0700 | [diff] [blame] | 212 | |
| 213 | return sb.toString(); |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 217 | private void formatInstructs(StringBuilder sb, |
| 218 | List<Instruction> instructs, |
| 219 | String type) { |
| 220 | if (!instructs.isEmpty()) { |
| 221 | sb.append(type); |
| 222 | for (Instruction i : instructs) { |
| 223 | sb.append(i).append(COMMA); |
| 224 | } |
| 225 | } |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 226 | } |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 227 | } |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 228 | |
| 229 | private final class DetailRequestHandler extends RequestHandler { |
| 230 | private DetailRequestHandler() { |
| 231 | super(FLOW_DETAILS_REQ); |
| 232 | } |
| 233 | |
Bharath Thiruveedula | 99849dc | 2016-11-17 22:04:38 +0530 | [diff] [blame] | 234 | private FlowEntry findFlowById(String appIdText, String flowId) { |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 235 | String strippedFlowId = flowId.replaceAll(OX, EMPTY); |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 236 | FlowRuleService fs = get(FlowRuleService.class); |
| 237 | int appIdInt = Integer.parseInt(appIdText); |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 238 | ApplicationId appId = new DefaultApplicationId(appIdInt, DETAILS); |
Bharath Thiruveedula | 99849dc | 2016-11-17 22:04:38 +0530 | [diff] [blame] | 239 | Iterable<FlowEntry> entries = fs.getFlowEntriesById(appId); |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 240 | |
Bharath Thiruveedula | 99849dc | 2016-11-17 22:04:38 +0530 | [diff] [blame] | 241 | for (FlowEntry entry : entries) { |
| 242 | if (entry.id().toString().equals(strippedFlowId)) { |
| 243 | return entry; |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | return null; |
| 248 | } |
| 249 | |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 250 | private String decorateFlowId(FlowRule flow) { |
| 251 | return OX + flow.id(); |
| 252 | } |
| 253 | |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 254 | private String decorateGroupId(FlowRule flow) { |
| 255 | return OX + flow.groupId().id(); |
| 256 | } |
| 257 | |
| 258 | private String getCriteriaString(FlowRule flow) { |
| 259 | Set<Criterion> criteria = flow.selector().criteria(); |
| 260 | StringBuilder sb = new StringBuilder(); |
| 261 | for (Criterion c : criteria) { |
| 262 | sb.append(c).append(COMMA); |
| 263 | } |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 264 | removeTrailingComma(sb); |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 265 | return sb.toString(); |
| 266 | } |
| 267 | |
| 268 | private String getTreatmentString(FlowRule flow) { |
| 269 | List<Instruction> instructions = flow.treatment().allInstructions(); |
| 270 | StringBuilder sb = new StringBuilder(); |
| 271 | for (Instruction inst : instructions) { |
| 272 | sb.append(inst).append(COMMA); |
| 273 | } |
| 274 | if (flow.treatment().metered() != null) { |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 275 | sb.append(flow.treatment().metered()).append(COMMA); |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 276 | } |
| 277 | if (flow.treatment().tableTransition() != null) { |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 278 | sb.append(flow.treatment().tableTransition()).append(COMMA); |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 279 | } |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 280 | |
Deepa Vaddireddy | f3932c0 | 2017-02-09 17:32:28 +0530 | [diff] [blame] | 281 | removeTrailingComma(sb); |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 282 | return sb.toString(); |
| 283 | } |
| 284 | |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 285 | @Override |
Simon Hunt | 8a0429a | 2017-01-06 16:52:47 -0800 | [diff] [blame] | 286 | public void process(ObjectNode payload) { |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 287 | |
| 288 | String flowId = string(payload, FLOW_ID); |
| 289 | String appId = string(payload, APP_ID); |
| 290 | FlowRule flow = findFlowById(appId, flowId); |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 291 | if (flow != null) { |
| 292 | ObjectNode data = objectNode(); |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 293 | |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 294 | |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 295 | data.put(FLOW_ID, decorateFlowId(flow)); |
| 296 | data.put(FLOW_PRIORITY, flow.priority()); |
Viswanath KSP | ed55ecf | 2016-12-22 18:15:45 +0530 | [diff] [blame] | 297 | data.put(GROUP_ID, decorateGroupId(flow)); |
| 298 | data.put(APP_ID, flow.appId()); |
| 299 | data.put(TABLE_ID, flow.tableId()); |
| 300 | data.put(TIMEOUT, flow.hardTimeout()); |
| 301 | data.put(PERMANENT, Boolean.toString(flow.isPermanent())); |
| 302 | data.put(SELECTOR, getCriteriaString(flow)); |
| 303 | data.put(TREATMENT, getTreatmentString(flow)); |
| 304 | |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 305 | |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 306 | //TODO put more detail info to data |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 307 | |
Viswanath KSP | 70e0d14 | 2016-10-28 21:58:32 +0530 | [diff] [blame] | 308 | ObjectNode rootNode = objectNode(); |
| 309 | rootNode.set(DETAILS, data); |
| 310 | sendMessage(FLOW_DETAILS_RESP, rootNode); |
| 311 | } |
Viswanath KSP | d1212c7 | 2016-10-21 01:03:35 +0530 | [diff] [blame] | 312 | } |
| 313 | } |
Bri Prebilic Cole | cdc188d | 2015-04-24 16:40:11 -0700 | [diff] [blame] | 314 | } |