Jian Li
Committed by Gerrit Code Review

Remove duplicated treatment building from GroupBucketEntryBuilder

Change-Id: I0f956dd11d990209eb3dc00c866dd535843506ea
...@@ -91,6 +91,7 @@ import org.projectfloodlight.openflow.types.U64; ...@@ -91,6 +91,7 @@ import org.projectfloodlight.openflow.types.U64;
91 import org.projectfloodlight.openflow.types.U8; 91 import org.projectfloodlight.openflow.types.U8;
92 import org.projectfloodlight.openflow.types.VlanPcp; 92 import org.projectfloodlight.openflow.types.VlanPcp;
93 import org.slf4j.Logger; 93 import org.slf4j.Logger;
94 +import org.slf4j.LoggerFactory;
94 95
95 import java.util.List; 96 import java.util.List;
96 97
...@@ -104,10 +105,9 @@ import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupCh ...@@ -104,10 +105,9 @@ import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupCh
104 import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType; 105 import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupGridType;
105 import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType; 106 import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOchSignalType;
106 import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOduSignalType; 107 import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupOduSignalType;
107 -import static org.slf4j.LoggerFactory.getLogger;
108 108
109 public class FlowEntryBuilder { 109 public class FlowEntryBuilder {
110 - private final Logger log = getLogger(getClass()); 110 + private static final Logger log = LoggerFactory.getLogger(FlowEntryBuilder.class);
111 111
112 private final OFFlowStatsEntry stat; 112 private final OFFlowStatsEntry stat;
113 private final OFFlowRemoved removed; 113 private final OFFlowRemoved removed;
...@@ -289,14 +289,24 @@ public class FlowEntryBuilder { ...@@ -289,14 +289,24 @@ public class FlowEntryBuilder {
289 return builder.build(); 289 return builder.build();
290 } 290 }
291 291
292 - private TrafficTreatment.Builder buildActions(List<OFAction> actions, 292 + /**
293 - TrafficTreatment.Builder builder) { 293 + * Configures traffic treatment builder with a given collection of actions.
294 - DriverHandler driverHandler = getDriver(deviceId); 294 + *
295 - ExtensionTreatmentInterpreter treatmentInterpreter; 295 + * @param actions a set of OpenFlow actions
296 + * @param builder traffic treatment builder
297 + * @param driverHandler driver handler
298 + * @param deviceId device identifier
299 + * @return configured traffic treatment builder
300 + */
301 + public static TrafficTreatment.Builder configureTreatmentBuilder(List<OFAction> actions,
302 + TrafficTreatment.Builder builder,
303 + DriverHandler driverHandler,
304 + DeviceId deviceId) {
305 + ExtensionTreatmentInterpreter interpreter;
296 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) { 306 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
297 - treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class); 307 + interpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
298 } else { 308 } else {
299 - treatmentInterpreter = null; 309 + interpreter = null;
300 } 310 }
301 311
302 for (OFAction act : actions) { 312 for (OFAction act : actions) {
...@@ -344,15 +354,15 @@ public class FlowEntryBuilder { ...@@ -344,15 +354,15 @@ public class FlowEntryBuilder {
344 lookupGridType(circuitSignalID.getGridType()), 354 lookupGridType(circuitSignalID.getGridType()),
345 lookupChannelSpacing(circuitSignalID.getChannelSpacing()), 355 lookupChannelSpacing(circuitSignalID.getChannelSpacing()),
346 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth()))); 356 circuitSignalID.getChannelNumber(), circuitSignalID.getSpectralWidth())));
347 - } else if (treatmentInterpreter != null) { 357 + } else if (interpreter != null) {
348 - builder.extension(treatmentInterpreter.mapAction(exp), deviceId); 358 + builder.extension(interpreter.mapAction(exp), deviceId);
349 } else { 359 } else {
350 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter()); 360 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
351 } 361 }
352 break; 362 break;
353 case SET_FIELD: 363 case SET_FIELD:
354 OFActionSetField setField = (OFActionSetField) act; 364 OFActionSetField setField = (OFActionSetField) act;
355 - handleSetField(builder, setField); 365 + handleSetField(builder, setField, driverHandler, deviceId);
356 break; 366 break;
357 case POP_MPLS: 367 case POP_MPLS:
358 OFActionPopMpls popMpls = (OFActionPopMpls) act; 368 OFActionPopMpls popMpls = (OFActionPopMpls) act;
...@@ -410,9 +420,18 @@ public class FlowEntryBuilder { ...@@ -410,9 +420,18 @@ public class FlowEntryBuilder {
410 return builder; 420 return builder;
411 } 421 }
412 422
413 - 423 + private TrafficTreatment.Builder buildActions(List<OFAction> actions,
414 - private void handleSetField(TrafficTreatment.Builder builder, OFActionSetField action) { 424 + TrafficTreatment.Builder builder) {
415 DriverHandler driverHandler = getDriver(deviceId); 425 DriverHandler driverHandler = getDriver(deviceId);
426 +
427 + return configureTreatmentBuilder(actions, builder, driverHandler, deviceId);
428 + }
429 +
430 +
431 + private static void handleSetField(TrafficTreatment.Builder builder,
432 + OFActionSetField action,
433 + DriverHandler driverHandler,
434 + DeviceId deviceId) {
416 ExtensionTreatmentInterpreter treatmentInterpreter; 435 ExtensionTreatmentInterpreter treatmentInterpreter;
417 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) { 436 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
418 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class); 437 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
......
...@@ -31,4 +31,12 @@ ...@@ -31,4 +31,12 @@
31 31
32 <description>ONOS OpenFlow protocol group provider</description> 32 <description>ONOS OpenFlow protocol group provider</description>
33 33
34 + <dependencies>
35 + <dependency>
36 + <groupId>org.onosproject</groupId>
37 + <artifactId>onos-of-provider-flow</artifactId>
38 + <version>${project.version}</version>
39 + </dependency>
40 + </dependencies>
41 +
34 </project> 42 </project>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -16,12 +16,6 @@ ...@@ -16,12 +16,6 @@
16 package org.onosproject.provider.of.group.impl; 16 package org.onosproject.provider.of.group.impl;
17 17
18 import com.google.common.collect.Lists; 18 import com.google.common.collect.Lists;
19 -
20 -import org.onlab.packet.EthType;
21 -import org.onlab.packet.Ip4Address;
22 -import org.onlab.packet.MacAddress;
23 -import org.onlab.packet.MplsLabel;
24 -import org.onlab.packet.VlanId;
25 import org.onosproject.core.DefaultGroupId; 19 import org.onosproject.core.DefaultGroupId;
26 import org.onosproject.core.GroupId; 20 import org.onosproject.core.GroupId;
27 import org.onosproject.net.DeviceId; 21 import org.onosproject.net.DeviceId;
...@@ -37,33 +31,10 @@ import org.onosproject.net.group.DefaultGroupBucket; ...@@ -37,33 +31,10 @@ import org.onosproject.net.group.DefaultGroupBucket;
37 import org.onosproject.net.group.GroupBucket; 31 import org.onosproject.net.group.GroupBucket;
38 import org.onosproject.net.group.GroupBuckets; 32 import org.onosproject.net.group.GroupBuckets;
39 import org.onosproject.openflow.controller.Dpid; 33 import org.onosproject.openflow.controller.Dpid;
40 -import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; 34 +import org.onosproject.provider.of.flow.impl.FlowEntryBuilder;
41 import org.projectfloodlight.openflow.protocol.OFBucket; 35 import org.projectfloodlight.openflow.protocol.OFBucket;
42 import org.projectfloodlight.openflow.protocol.OFGroupType; 36 import org.projectfloodlight.openflow.protocol.OFGroupType;
43 import org.projectfloodlight.openflow.protocol.action.OFAction; 37 import org.projectfloodlight.openflow.protocol.action.OFAction;
44 -import org.projectfloodlight.openflow.protocol.action.OFActionCopyTtlIn;
45 -import org.projectfloodlight.openflow.protocol.action.OFActionCopyTtlOut;
46 -import org.projectfloodlight.openflow.protocol.action.OFActionDecMplsTtl;
47 -import org.projectfloodlight.openflow.protocol.action.OFActionDecNwTtl;
48 -import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter;
49 -import org.projectfloodlight.openflow.protocol.action.OFActionGroup;
50 -import org.projectfloodlight.openflow.protocol.action.OFActionOutput;
51 -import org.projectfloodlight.openflow.protocol.action.OFActionPopMpls;
52 -import org.projectfloodlight.openflow.protocol.action.OFActionPushMpls;
53 -import org.projectfloodlight.openflow.protocol.action.OFActionSetDlDst;
54 -import org.projectfloodlight.openflow.protocol.action.OFActionSetDlSrc;
55 -import org.projectfloodlight.openflow.protocol.action.OFActionSetField;
56 -import org.projectfloodlight.openflow.protocol.action.OFActionSetNwDst;
57 -import org.projectfloodlight.openflow.protocol.action.OFActionSetNwSrc;
58 -import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
59 -import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
60 -import org.projectfloodlight.openflow.protocol.oxm.OFOxm;
61 -import org.projectfloodlight.openflow.types.IPv4Address;
62 -import org.projectfloodlight.openflow.types.OFVlanVidMatch;
63 -import org.projectfloodlight.openflow.types.U32;
64 -import org.projectfloodlight.openflow.types.U64;
65 -import org.projectfloodlight.openflow.types.U8;
66 -import org.projectfloodlight.openflow.types.VlanPcp;
67 import org.slf4j.Logger; 38 import org.slf4j.Logger;
68 39
69 import java.util.List; 40 import java.util.List;
...@@ -143,225 +114,18 @@ public class GroupBucketEntryBuilder { ...@@ -143,225 +114,18 @@ public class GroupBucketEntryBuilder {
143 return new GroupBuckets(bucketList); 114 return new GroupBuckets(bucketList);
144 } 115 }
145 116
146 -
147 private TrafficTreatment buildTreatment(List<OFAction> actions) { 117 private TrafficTreatment buildTreatment(List<OFAction> actions) {
118 + DriverHandler driverHandler = getDriver(dpid);
148 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); 119 TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
120 +
149 // If this is a drop rule 121 // If this is a drop rule
150 if (actions.size() == 0) { 122 if (actions.size() == 0) {
151 builder.drop(); 123 builder.drop();
152 return builder.build(); 124 return builder.build();
153 } 125 }
154 - for (OFAction act : actions) {
155 - switch (act.getType()) {
156 - case OUTPUT:
157 - OFActionOutput out = (OFActionOutput) act;
158 - builder.setOutput(
159 - PortNumber.portNumber(out.getPort().getPortNumber()));
160 - break;
161 - case SET_VLAN_VID:
162 - OFActionSetVlanVid vlan = (OFActionSetVlanVid) act;
163 - builder.setVlanId(VlanId.vlanId(vlan.getVlanVid().getVlan()));
164 - break;
165 - case SET_VLAN_PCP:
166 - OFActionSetVlanPcp pcp = (OFActionSetVlanPcp) act;
167 - builder.setVlanPcp(pcp.getVlanPcp().getValue());
168 - break;
169 - case POP_VLAN:
170 - builder.popVlan();
171 - break;
172 - case PUSH_VLAN:
173 - builder.pushVlan();
174 - break;
175 - case SET_DL_DST:
176 - OFActionSetDlDst dldst = (OFActionSetDlDst) act;
177 - builder.setEthDst(
178 - MacAddress.valueOf(dldst.getDlAddr().getLong()));
179 - break;
180 - case SET_DL_SRC:
181 - OFActionSetDlSrc dlsrc = (OFActionSetDlSrc) act;
182 - builder.setEthSrc(
183 - MacAddress.valueOf(dlsrc.getDlAddr().getLong()));
184 -
185 - break;
186 - case SET_NW_DST:
187 - OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
188 - IPv4Address di = nwdst.getNwAddr();
189 - builder.setIpDst(Ip4Address.valueOf(di.getInt()));
190 - break;
191 - case SET_NW_SRC:
192 - OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
193 - IPv4Address si = nwsrc.getNwAddr();
194 - builder.setIpSrc(Ip4Address.valueOf(si.getInt()));
195 - break;
196 - case EXPERIMENTER:
197 - OFActionExperimenter exp = (OFActionExperimenter) act;
198 - log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
199 - break;
200 - case SET_FIELD:
201 - OFActionSetField setField = (OFActionSetField) act;
202 - handleSetField(builder, setField);
203 - break;
204 - case POP_MPLS:
205 - OFActionPopMpls popMpls = (OFActionPopMpls) act;
206 - builder.popMpls(new EthType(popMpls.getEthertype().getValue()));
207 - break;
208 - case PUSH_MPLS:
209 - OFActionPushMpls pushMpls = (OFActionPushMpls) act;
210 - builder.pushMpls();
211 - break;
212 - case COPY_TTL_IN:
213 - OFActionCopyTtlIn copyTtlIn = (OFActionCopyTtlIn) act;
214 - builder.copyTtlIn();
215 - break;
216 - case COPY_TTL_OUT:
217 - OFActionCopyTtlOut copyTtlOut = (OFActionCopyTtlOut) act;
218 - builder.copyTtlOut();
219 - break;
220 - case DEC_MPLS_TTL:
221 - OFActionDecMplsTtl decMplsTtl = (OFActionDecMplsTtl) act;
222 - builder.decMplsTtl();
223 - break;
224 - case DEC_NW_TTL:
225 - OFActionDecNwTtl decNwTtl = (OFActionDecNwTtl) act;
226 - builder.decNwTtl();
227 - break;
228 - case GROUP:
229 - OFActionGroup grp = (OFActionGroup) act;
230 - builder.group(new DefaultGroupId(grp.getGroup().getGroupNumber()));
231 - break;
232 - case SET_TP_DST:
233 - case SET_TP_SRC:
234 - case POP_PBB:
235 - case PUSH_PBB:
236 - case SET_MPLS_LABEL:
237 - case SET_MPLS_TC:
238 - case SET_MPLS_TTL:
239 - case SET_NW_ECN:
240 - case SET_NW_TOS:
241 - case SET_NW_TTL:
242 - case SET_QUEUE:
243 - case STRIP_VLAN:
244 - case ENQUEUE:
245 - default:
246 - log.warn("Action type {} not yet implemented.", act.getType());
247 - }
248 - }
249 126
250 - return builder.build(); 127 + return FlowEntryBuilder.configureTreatmentBuilder(actions, builder,
251 - } 128 + driverHandler, DeviceId.deviceId(Dpid.uri(dpid))).build();
252 -
253 - private void handleSetField(TrafficTreatment.Builder builder, OFActionSetField action) {
254 - OFOxm<?> oxm = action.getField();
255 - switch (oxm.getMatchField().id) {
256 - case VLAN_PCP:
257 - @SuppressWarnings("unchecked")
258 - OFOxm<VlanPcp> vlanpcp = (OFOxm<VlanPcp>) oxm;
259 - builder.setVlanPcp(vlanpcp.getValue().getValue());
260 - break;
261 - case VLAN_VID:
262 - @SuppressWarnings("unchecked")
263 - OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
264 - builder.setVlanId(VlanId.vlanId(vlanvid.getValue().getVlan()));
265 - break;
266 - case ETH_DST:
267 - @SuppressWarnings("unchecked")
268 - OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethdst =
269 - (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
270 - builder.setEthDst(MacAddress.valueOf(ethdst.getValue().getLong()));
271 - break;
272 - case ETH_SRC:
273 - @SuppressWarnings("unchecked")
274 - OFOxm<org.projectfloodlight.openflow.types.MacAddress> ethsrc =
275 - (OFOxm<org.projectfloodlight.openflow.types.MacAddress>) oxm;
276 - builder.setEthSrc(MacAddress.valueOf(ethsrc.getValue().getLong()));
277 - break;
278 - case IPV4_DST:
279 - @SuppressWarnings("unchecked")
280 - OFOxm<IPv4Address> ip4dst = (OFOxm<IPv4Address>) oxm;
281 - builder.setIpDst(Ip4Address.valueOf(ip4dst.getValue().getInt()));
282 - break;
283 - case IPV4_SRC:
284 - @SuppressWarnings("unchecked")
285 - OFOxm<IPv4Address> ip4src = (OFOxm<IPv4Address>) oxm;
286 - builder.setIpSrc(Ip4Address.valueOf(ip4src.getValue().getInt()));
287 - break;
288 - case MPLS_LABEL:
289 - @SuppressWarnings("unchecked")
290 - OFOxm<U32> labelId = (OFOxm<U32>) oxm;
291 - builder.setMpls(MplsLabel.mplsLabel((int) labelId.getValue().getValue()));
292 - break;
293 - case MPLS_BOS:
294 - @SuppressWarnings("unchecked")
295 - OFOxm<U8> mplsBos = (OFOxm<U8>) oxm;
296 - builder.setMplsBos(mplsBos.getValue() == U8.ZERO ? false : true);
297 - break;
298 - case TUNNEL_ID:
299 - @SuppressWarnings("unchecked")
300 - OFOxm<U64> tunnelId = (OFOxm<U64>) oxm;
301 - builder.setTunnelId(tunnelId.getValue().getValue());
302 - break;
303 - case TUNNEL_IPV4_DST:
304 - DriverHandler driver = getDriver(dpid);
305 - ExtensionTreatmentInterpreter interpreter = driver.behaviour(ExtensionTreatmentInterpreter.class);
306 - if (interpreter != null) {
307 - builder.extension(interpreter.mapAction(action), DeviceId.deviceId(Dpid.uri(dpid)));
308 - }
309 - break;
310 - case ARP_OP:
311 - case ARP_SHA:
312 - case ARP_SPA:
313 - case ARP_THA:
314 - case ARP_TPA:
315 - case BSN_EGR_PORT_GROUP_ID:
316 - case BSN_GLOBAL_VRF_ALLOWED:
317 - case BSN_IN_PORTS_128:
318 - case BSN_L3_DST_CLASS_ID:
319 - case BSN_L3_INTERFACE_CLASS_ID:
320 - case BSN_L3_SRC_CLASS_ID:
321 - case BSN_LAG_ID:
322 - case BSN_TCP_FLAGS:
323 - case BSN_UDF0:
324 - case BSN_UDF1:
325 - case BSN_UDF2:
326 - case BSN_UDF3:
327 - case BSN_UDF4:
328 - case BSN_UDF5:
329 - case BSN_UDF6:
330 - case BSN_UDF7:
331 - case BSN_VLAN_XLATE_PORT_GROUP_ID:
332 - case BSN_VRF:
333 - case ETH_TYPE:
334 - case ICMPV4_CODE:
335 - case ICMPV4_TYPE:
336 - case ICMPV6_CODE:
337 - case ICMPV6_TYPE:
338 - case IN_PHY_PORT:
339 - case IN_PORT:
340 - case IPV6_DST:
341 - case IPV6_FLABEL:
342 - case IPV6_ND_SLL:
343 - case IPV6_ND_TARGET:
344 - case IPV6_ND_TLL:
345 - case IPV6_SRC:
346 - case IP_DSCP:
347 - case IP_ECN:
348 - case IP_PROTO:
349 - case METADATA:
350 - case MPLS_TC:
351 - case OCH_SIGID:
352 - case OCH_SIGID_BASIC:
353 - case OCH_SIGTYPE:
354 - case OCH_SIGTYPE_BASIC:
355 - case SCTP_DST:
356 - case SCTP_SRC:
357 - case TCP_DST:
358 - case TCP_SRC:
359 - case UDP_DST:
360 - case UDP_SRC:
361 - default:
362 - log.warn("Set field type {} not yet implemented.", oxm.getMatchField().id);
363 - break;
364 - }
365 } 129 }
366 130
367 private DriverHandler getDriver(Dpid dpid) { 131 private DriverHandler getDriver(Dpid dpid) {
......