Do not copy collections needlessly in toFlowModInputs(). Also bail from
isSetVlanIdActionCasePresent() as soon as we find a match. In
handleSetVlanIdForOF13() we know we are returning at most two elements,
so allocate the array accordingly.
Change-Id: I121893068827fe9f3d7bfc156d5fd334d2550c80
Signed-off-by: Robert Varga <rovarga@cisco.com>
import java.math.BigInteger;
import java.util.ArrayList;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Collections;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag.FlowFlagReactor;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.flowflag.FlowFlagReactor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInputBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.Ordering;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.Ordering;
* If yes its handled separately
*/
public static List<FlowModInputBuilder> toFlowModInputs(Flow srcFlow, short version, BigInteger datapathId) {
* If yes its handled separately
*/
public static List<FlowModInputBuilder> toFlowModInputs(Flow srcFlow, short version, BigInteger datapathId) {
- List<FlowModInputBuilder> list = new ArrayList<>();
-
if (version >= OFConstants.OFP_VERSION_1_3 && isSetVlanIdActionCasePresent(srcFlow)) {
if (version >= OFConstants.OFP_VERSION_1_3 && isSetVlanIdActionCasePresent(srcFlow)) {
- list.addAll(handleSetVlanIdForOF13(srcFlow, version, datapathId));
+ return handleSetVlanIdForOF13(srcFlow, version, datapathId);
- list.add(toFlowModInput(srcFlow, version, datapathId));
+ return Collections.singletonList(toFlowModInput(srcFlow, version, datapathId));
}
public static FlowModInputBuilder toFlowModInput(Flow flow, short version, BigInteger datapathid) {
}
public static FlowModInputBuilder toFlowModInput(Flow flow, short version, BigInteger datapathid) {
// check if set vlanid action is present in the flow
private static boolean isSetVlanIdActionCasePresent(Flow flow) {
// check if set vlanid action is present in the flow
private static boolean isSetVlanIdActionCasePresent(Flow flow) {
- boolean isPresent = false;
// we are trying to find if there is a set-vlan-id action (OF1.0) action present in the flow.
// If yes,then we would need to two flows
if (flow.getInstructions() != null) {
// we are trying to find if there is a set-vlan-id action (OF1.0) action present in the flow.
// If yes,then we would need to two flows
if (flow.getInstructions() != null) {
for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action :
applyActions.getAction()) {
if (action.getAction() instanceof SetVlanIdActionCase) {
for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action :
applyActions.getAction()) {
if (action.getAction() instanceof SetVlanIdActionCase) {
- isPresent = true;
- break;
* 2) Match on (OFPVID_PRESENT) with mask (OFPVID_PRESENT ) + action [ set_field]
*/
private static List<FlowModInputBuilder> handleSetVlanIdForOF13(Flow srcFlow, short version, BigInteger datapathId) {
* 2) Match on (OFPVID_PRESENT) with mask (OFPVID_PRESENT ) + action [ set_field]
*/
private static List<FlowModInputBuilder> handleSetVlanIdForOF13(Flow srcFlow, short version, BigInteger datapathId) {
- List<FlowModInputBuilder> list = new ArrayList<>();
+ List<FlowModInputBuilder> list = new ArrayList<>(2);
VlanMatch srcVlanMatch = srcFlow.getMatch().getVlanMatch();
boolean hasVlanMatch = (srcFlow.getMatch() != null && srcVlanMatch != null);
VlanMatch srcVlanMatch = srcFlow.getMatch().getVlanMatch();
boolean hasVlanMatch = (srcFlow.getMatch() != null && srcVlanMatch != null);