Jonathan Hart

Use DeviceId in FlowEntryBuilder to avoid creating deviceId many times per

flow entry build.

Change-Id: I89e90426e1b94b8828b6f83a6dbfc33f4e7cf259
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
16 package org.onosproject.provider.of.flow.impl; 16 package org.onosproject.provider.of.flow.impl;
17 17
18 import com.google.common.collect.Lists; 18 import com.google.common.collect.Lists;
19 -
20 import org.onlab.packet.EthType; 19 import org.onlab.packet.EthType;
21 import org.onlab.packet.Ip4Address; 20 import org.onlab.packet.Ip4Address;
22 import org.onlab.packet.Ip4Prefix; 21 import org.onlab.packet.Ip4Prefix;
...@@ -48,7 +47,6 @@ import org.onosproject.net.flow.TrafficTreatment; ...@@ -48,7 +47,6 @@ import org.onosproject.net.flow.TrafficTreatment;
48 import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes; 47 import org.onosproject.net.flow.criteria.ExtensionSelectorType.ExtensionSelectorTypes;
49 import org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes; 48 import org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes;
50 import org.onosproject.net.flow.instructions.Instructions; 49 import org.onosproject.net.flow.instructions.Instructions;
51 -import org.onosproject.openflow.controller.Dpid;
52 import org.onosproject.openflow.controller.ExtensionSelectorInterpreter; 50 import org.onosproject.openflow.controller.ExtensionSelectorInterpreter;
53 import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter; 51 import org.onosproject.openflow.controller.ExtensionTreatmentInterpreter;
54 import org.projectfloodlight.openflow.protocol.OFFlowMod; 52 import org.projectfloodlight.openflow.protocol.OFFlowMod;
...@@ -86,20 +84,20 @@ import org.projectfloodlight.openflow.types.IPv4Address; ...@@ -86,20 +84,20 @@ import org.projectfloodlight.openflow.types.IPv4Address;
86 import org.projectfloodlight.openflow.types.IPv6Address; 84 import org.projectfloodlight.openflow.types.IPv6Address;
87 import org.projectfloodlight.openflow.types.Masked; 85 import org.projectfloodlight.openflow.types.Masked;
88 import org.projectfloodlight.openflow.types.OFVlanVidMatch; 86 import org.projectfloodlight.openflow.types.OFVlanVidMatch;
87 +import org.projectfloodlight.openflow.types.OduSignalID;
89 import org.projectfloodlight.openflow.types.TransportPort; 88 import org.projectfloodlight.openflow.types.TransportPort;
90 import org.projectfloodlight.openflow.types.U32; 89 import org.projectfloodlight.openflow.types.U32;
91 import org.projectfloodlight.openflow.types.U64; 90 import org.projectfloodlight.openflow.types.U64;
92 import org.projectfloodlight.openflow.types.U8; 91 import org.projectfloodlight.openflow.types.U8;
93 import org.projectfloodlight.openflow.types.VlanPcp; 92 import org.projectfloodlight.openflow.types.VlanPcp;
94 -import org.projectfloodlight.openflow.types.OduSignalID;
95 import org.slf4j.Logger; 93 import org.slf4j.Logger;
96 94
97 import java.util.List; 95 import java.util.List;
98 96
99 import static org.onosproject.net.flow.criteria.Criteria.matchLambda; 97 import static org.onosproject.net.flow.criteria.Criteria.matchLambda;
100 import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType; 98 import static org.onosproject.net.flow.criteria.Criteria.matchOchSignalType;
101 -import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalType;
102 import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalId; 99 import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalId;
100 +import static org.onosproject.net.flow.criteria.Criteria.matchOduSignalType;
103 import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda; 101 import static org.onosproject.net.flow.instructions.Instructions.modL0Lambda;
104 import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId; 102 import static org.onosproject.net.flow.instructions.Instructions.modL1OduSignalId;
105 import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing; 103 import static org.onosproject.provider.of.flow.impl.OpenFlowValueMapper.lookupChannelSpacing;
...@@ -121,7 +119,7 @@ public class FlowEntryBuilder { ...@@ -121,7 +119,7 @@ public class FlowEntryBuilder {
121 // the instruction type is apply instruction (immediate set in ONOS speak) 119 // the instruction type is apply instruction (immediate set in ONOS speak)
122 private final List<OFInstruction> instructions; 120 private final List<OFInstruction> instructions;
123 121
124 - private final Dpid dpid; 122 + private final DeviceId deviceId;
125 123
126 public enum FlowType { STAT, REMOVED, MOD } 124 public enum FlowType { STAT, REMOVED, MOD }
127 125
...@@ -129,21 +127,21 @@ public class FlowEntryBuilder { ...@@ -129,21 +127,21 @@ public class FlowEntryBuilder {
129 127
130 private final DriverService driverService; 128 private final DriverService driverService;
131 129
132 - public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry, DriverService driverService) { 130 + public FlowEntryBuilder(DeviceId deviceId, OFFlowStatsEntry entry, DriverService driverService) {
133 this.stat = entry; 131 this.stat = entry;
134 this.match = entry.getMatch(); 132 this.match = entry.getMatch();
135 this.instructions = getInstructions(entry); 133 this.instructions = getInstructions(entry);
136 - this.dpid = dpid; 134 + this.deviceId = deviceId;
137 this.removed = null; 135 this.removed = null;
138 this.flowMod = null; 136 this.flowMod = null;
139 this.type = FlowType.STAT; 137 this.type = FlowType.STAT;
140 this.driverService = driverService; 138 this.driverService = driverService;
141 } 139 }
142 140
143 - public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed, DriverService driverService) { 141 + public FlowEntryBuilder(DeviceId deviceId, OFFlowRemoved removed, DriverService driverService) {
144 this.match = removed.getMatch(); 142 this.match = removed.getMatch();
145 this.removed = removed; 143 this.removed = removed;
146 - this.dpid = dpid; 144 + this.deviceId = deviceId;
147 this.instructions = null; 145 this.instructions = null;
148 this.stat = null; 146 this.stat = null;
149 this.flowMod = null; 147 this.flowMod = null;
...@@ -151,9 +149,9 @@ public class FlowEntryBuilder { ...@@ -151,9 +149,9 @@ public class FlowEntryBuilder {
151 this.driverService = driverService; 149 this.driverService = driverService;
152 } 150 }
153 151
154 - public FlowEntryBuilder(Dpid dpid, OFFlowMod fm, DriverService driverService) { 152 + public FlowEntryBuilder(DeviceId deviceId, OFFlowMod fm, DriverService driverService) {
155 this.match = fm.getMatch(); 153 this.match = fm.getMatch();
156 - this.dpid = dpid; 154 + this.deviceId = deviceId;
157 this.instructions = getInstructions(fm); 155 this.instructions = getInstructions(fm);
158 this.type = FlowType.MOD; 156 this.type = FlowType.MOD;
159 this.flowMod = fm; 157 this.flowMod = fm;
...@@ -168,7 +166,7 @@ public class FlowEntryBuilder { ...@@ -168,7 +166,7 @@ public class FlowEntryBuilder {
168 switch (this.type) { 166 switch (this.type) {
169 case STAT: 167 case STAT:
170 builder = DefaultFlowRule.builder() 168 builder = DefaultFlowRule.builder()
171 - .forDevice(DeviceId.deviceId(Dpid.uri(dpid))) 169 + .forDevice(deviceId)
172 .withSelector(buildSelector()) 170 .withSelector(buildSelector())
173 .withTreatment(buildTreatment()) 171 .withTreatment(buildTreatment())
174 .withPriority(stat.getPriority()) 172 .withPriority(stat.getPriority())
...@@ -184,7 +182,7 @@ public class FlowEntryBuilder { ...@@ -184,7 +182,7 @@ public class FlowEntryBuilder {
184 stat.getByteCount().getValue()); 182 stat.getByteCount().getValue());
185 case REMOVED: 183 case REMOVED:
186 builder = DefaultFlowRule.builder() 184 builder = DefaultFlowRule.builder()
187 - .forDevice(DeviceId.deviceId(Dpid.uri(dpid))) 185 + .forDevice(deviceId)
188 .withSelector(buildSelector()) 186 .withSelector(buildSelector())
189 .withPriority(removed.getPriority()) 187 .withPriority(removed.getPriority())
190 .makeTemporary(removed.getIdleTimeout()) 188 .makeTemporary(removed.getIdleTimeout())
...@@ -200,7 +198,7 @@ public class FlowEntryBuilder { ...@@ -200,7 +198,7 @@ public class FlowEntryBuilder {
200 case MOD: 198 case MOD:
201 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED; 199 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
202 builder = DefaultFlowRule.builder() 200 builder = DefaultFlowRule.builder()
203 - .forDevice(DeviceId.deviceId(Dpid.uri(dpid))) 201 + .forDevice(deviceId)
204 .withSelector(buildSelector()) 202 .withSelector(buildSelector())
205 .withTreatment(buildTreatment()) 203 .withTreatment(buildTreatment())
206 .withPriority(flowMod.getPriority()) 204 .withPriority(flowMod.getPriority())
...@@ -293,7 +291,7 @@ public class FlowEntryBuilder { ...@@ -293,7 +291,7 @@ public class FlowEntryBuilder {
293 291
294 private TrafficTreatment.Builder buildActions(List<OFAction> actions, 292 private TrafficTreatment.Builder buildActions(List<OFAction> actions,
295 TrafficTreatment.Builder builder) { 293 TrafficTreatment.Builder builder) {
296 - DriverHandler driverHandler = getDriver(dpid); 294 + DriverHandler driverHandler = getDriver(deviceId);
297 ExtensionTreatmentInterpreter treatmentInterpreter; 295 ExtensionTreatmentInterpreter treatmentInterpreter;
298 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) { 296 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
299 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class); 297 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
...@@ -349,7 +347,7 @@ public class FlowEntryBuilder { ...@@ -349,7 +347,7 @@ public class FlowEntryBuilder {
349 } else if (exp.getExperimenter() == 0x2320) { 347 } else if (exp.getExperimenter() == 0x2320) {
350 if (treatmentInterpreter != null) { 348 if (treatmentInterpreter != null) {
351 builder.extension(treatmentInterpreter.mapAction(exp), 349 builder.extension(treatmentInterpreter.mapAction(exp),
352 - DeviceId.deviceId(Dpid.uri(dpid))); 350 + deviceId);
353 } 351 }
354 } else { 352 } else {
355 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter()); 353 log.warn("Unsupported OFActionExperimenter {}", exp.getExperimenter());
...@@ -417,7 +415,7 @@ public class FlowEntryBuilder { ...@@ -417,7 +415,7 @@ public class FlowEntryBuilder {
417 415
418 416
419 private void handleSetField(TrafficTreatment.Builder builder, OFActionSetField action) { 417 private void handleSetField(TrafficTreatment.Builder builder, OFActionSetField action) {
420 - DriverHandler driverHandler = getDriver(dpid); 418 + DriverHandler driverHandler = getDriver(deviceId);
421 ExtensionTreatmentInterpreter treatmentInterpreter; 419 ExtensionTreatmentInterpreter treatmentInterpreter;
422 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) { 420 if (driverHandler.hasBehaviour(ExtensionTreatmentInterpreter.class)) {
423 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class); 421 treatmentInterpreter = driverHandler.behaviour(ExtensionTreatmentInterpreter.class);
...@@ -436,7 +434,7 @@ public class FlowEntryBuilder { ...@@ -436,7 +434,7 @@ public class FlowEntryBuilder {
436 if (treatmentInterpreter != null && 434 if (treatmentInterpreter != null &&
437 treatmentInterpreter.supported(ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) { 435 treatmentInterpreter.supported(ExtensionTreatmentTypes.OFDPA_SET_VLAN_ID.type())) {
438 builder.extension(treatmentInterpreter.mapAction(action), 436 builder.extension(treatmentInterpreter.mapAction(action),
439 - DeviceId.deviceId(Dpid.uri(dpid))); 437 + deviceId);
440 } else { 438 } else {
441 @SuppressWarnings("unchecked") 439 @SuppressWarnings("unchecked")
442 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm; 440 OFOxm<OFVlanVidMatch> vlanvid = (OFOxm<OFVlanVidMatch>) oxm;
...@@ -503,7 +501,7 @@ public class FlowEntryBuilder { ...@@ -503,7 +501,7 @@ public class FlowEntryBuilder {
503 case TUNNEL_IPV4_DST: 501 case TUNNEL_IPV4_DST:
504 if (treatmentInterpreter != null && 502 if (treatmentInterpreter != null &&
505 treatmentInterpreter.supported(ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) { 503 treatmentInterpreter.supported(ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type())) {
506 - builder.extension(treatmentInterpreter.mapAction(action), DeviceId.deviceId(Dpid.uri(dpid))); 504 + builder.extension(treatmentInterpreter.mapAction(action), deviceId);
507 } 505 }
508 break; 506 break;
509 case EXP_ODU_SIG_ID: 507 case EXP_ODU_SIG_ID:
...@@ -592,7 +590,7 @@ public class FlowEntryBuilder { ...@@ -592,7 +590,7 @@ public class FlowEntryBuilder {
592 Ip6Prefix ip6Prefix; 590 Ip6Prefix ip6Prefix;
593 Ip4Address ip; 591 Ip4Address ip;
594 592
595 - DriverHandler driverHandler = getDriver(dpid); 593 + DriverHandler driverHandler = getDriver(deviceId);
596 ExtensionSelectorInterpreter selectorInterpreter; 594 ExtensionSelectorInterpreter selectorInterpreter;
597 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) { 595 if (driverHandler.hasBehaviour(ExtensionSelectorInterpreter.class)) {
598 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class); 596 selectorInterpreter = driverHandler.behaviour(ExtensionSelectorInterpreter.class);
...@@ -648,7 +646,7 @@ public class FlowEntryBuilder { ...@@ -648,7 +646,7 @@ public class FlowEntryBuilder {
648 if (match.getVersion().equals(OFVersion.OF_13)) { 646 if (match.getVersion().equals(OFVersion.OF_13)) {
649 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID); 647 OFOxm oxm = ((OFMatchV3) match).getOxmList().get(MatchField.VLAN_VID);
650 builder.extension(selectorInterpreter.mapOxm(oxm), 648 builder.extension(selectorInterpreter.mapOxm(oxm),
651 - DeviceId.deviceId(Dpid.uri(dpid))); 649 + deviceId);
652 } else { 650 } else {
653 break; 651 break;
654 } 652 }
...@@ -881,8 +879,7 @@ public class FlowEntryBuilder { ...@@ -881,8 +879,7 @@ public class FlowEntryBuilder {
881 return builder.build(); 879 return builder.build();
882 } 880 }
883 881
884 - private DriverHandler getDriver(Dpid dpid) { 882 + private DriverHandler getDriver(DeviceId deviceId) {
885 - DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
886 Driver driver = driverService.getDriver(deviceId); 883 Driver driver = driverService.getDriver(deviceId);
887 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); 884 DriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId));
888 return handler; 885 return handler;
......
...@@ -425,12 +425,12 @@ public class OpenFlowRuleProvider extends AbstractProvider ...@@ -425,12 +425,12 @@ public class OpenFlowRuleProvider extends AbstractProvider
425 425
426 @Override 426 @Override
427 public void handleMessage(Dpid dpid, OFMessage msg) { 427 public void handleMessage(Dpid dpid, OFMessage msg) {
428 - OpenFlowSwitch sw = controller.getSwitch(dpid); 428 + DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
429 switch (msg.getType()) { 429 switch (msg.getType()) {
430 case FLOW_REMOVED: 430 case FLOW_REMOVED:
431 OFFlowRemoved removed = (OFFlowRemoved) msg; 431 OFFlowRemoved removed = (OFFlowRemoved) msg;
432 432
433 - FlowEntry fr = new FlowEntryBuilder(dpid, removed, driverService).build(); 433 + FlowEntry fr = new FlowEntryBuilder(deviceId, removed, driverService).build();
434 providerService.flowRemoved(fr); 434 providerService.flowRemoved(fr);
435 435
436 if (adaptiveFlowSampling) { 436 if (adaptiveFlowSampling) {
...@@ -481,7 +481,7 @@ public class OpenFlowRuleProvider extends AbstractProvider ...@@ -481,7 +481,7 @@ public class OpenFlowRuleProvider extends AbstractProvider
481 InternalCacheEntry entry = 481 InternalCacheEntry entry =
482 pendingBatches.getIfPresent(msg.getXid()); 482 pendingBatches.getIfPresent(msg.getXid());
483 if (entry != null) { 483 if (entry != null) {
484 - entry.appendFailure(new FlowEntryBuilder(dpid, fm, driverService).build()); 484 + entry.appendFailure(new FlowEntryBuilder(deviceId, fm, driverService).build());
485 } else { 485 } else {
486 log.error("No matching batch for this error: {}", error); 486 log.error("No matching batch for this error: {}", error);
487 } 487 }
...@@ -508,7 +508,7 @@ public class OpenFlowRuleProvider extends AbstractProvider ...@@ -508,7 +508,7 @@ public class OpenFlowRuleProvider extends AbstractProvider
508 DeviceId did = DeviceId.deviceId(Dpid.uri(dpid)); 508 DeviceId did = DeviceId.deviceId(Dpid.uri(dpid));
509 509
510 List<FlowEntry> flowEntries = replies.getEntries().stream() 510 List<FlowEntry> flowEntries = replies.getEntries().stream()
511 - .map(entry -> new FlowEntryBuilder(dpid, entry, driverService).build()) 511 + .map(entry -> new FlowEntryBuilder(did, entry, driverService).build())
512 .collect(Collectors.toList()); 512 .collect(Collectors.toList());
513 513
514 if (adaptiveFlowSampling) { 514 if (adaptiveFlowSampling) {
......