for connection tracking.
Change-Id: Id92c251d0b8379e23aa99a013ec7c10e6818bc3e
Signed-off-by: Aswin Suryanarayanan <asuryana@redhat.com>
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.add.group.input.buckets.bucket.action.action.NxActionResubmitRpcAddGroupCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionConntrackNodesNodeTableFlowApplyActionsCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.conntrack.grouping.NxConntrack;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.conntrack.grouping.NxConntrackBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.resubmit.grouping.NxResubmitBuilder;
public enum ActionType {
ActionBuilder ab = new ActionBuilder();
return null;
}
+ },
+ nx_conntrack {
+ @Override
+ public Action buildAction(ActionInfo actionInfo) {
+ String[] actionValues = actionInfo.getActionValues();
+ Integer flags = new Integer(actionValues[0]);
+ Long zoneSrc = new Long(actionValues[1]);
+ Integer conntrackZone = new Integer(actionValues[2]);
+ Short recircTable = new Short(actionValues[3]);
+ NxConntrackBuilder ctb = new NxConntrackBuilder()
+ .setFlags(flags)
+ .setZoneSrc(zoneSrc)
+ .setConntrackZone(conntrackZone)
+ .setRecircTable(recircTable);
+ ActionBuilder ab = new ActionBuilder();
+ ab.setAction(new NxActionConntrackNodesNodeTableFlowApplyActionsCaseBuilder()
+ .setNxConntrack(ctb.build()).build());
+ ab.setKey(new ActionKey(actionInfo.getActionKey()));
+ return ab.build();
+
+ }
+
};
private static final int RADIX_HEX = 16;
private int m_nIdleTimeOut;
private int m_nHardTimeOut;
private BigInteger m_biCookie;
- private List<MatchInfo> m_listMatchInfo;
+ private List<? extends MatchInfoBase> m_listMatchInfo;
private List<InstructionInfo> m_listInstructionInfo;
private boolean m_bStrictFlag;
return m_listInstructionInfo;
}
- public List<MatchInfo> getMatchInfoList() {
+ public List<? extends MatchInfoBase> getMatchInfoList() {
return m_listMatchInfo;
}
m_flowBuilder = null;
}
- public void setMatchInfoList(List<MatchInfo> listMatchInfo) {
+ public void setMatchInfoList(List<? extends MatchInfoBase> listMatchInfo) {
m_listMatchInfo = listMatchInfo;
m_flowBuilder = null;
}
private static final Logger logger = LoggerFactory.getLogger(MDSALUtil.class);
public static FlowEntity buildFlowEntity(BigInteger dpnId, short tableId, String flowId, int priority, String flowName,
- int idleTimeOut, int hardTimeOut, BigInteger cookie, List<MatchInfo> listMatchInfo,
+ int idleTimeOut, int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase> listMatchInfoBase,
List<InstructionInfo> listInstructionInfo) {
FlowEntity flowEntity = new FlowEntity(dpnId);
flowEntity.setIdleTimeOut(idleTimeOut);
flowEntity.setHardTimeOut(hardTimeOut);
flowEntity.setCookie(cookie);
- flowEntity.setMatchInfoList(listMatchInfo);
+ flowEntity.setMatchInfoList(listMatchInfoBase);
flowEntity.setInstructionInfoList(listInstructionInfo);
return flowEntity;
// TODO: CHECK IF THIS IS USED
public static Flow buildFlow(short tableId, String flowId, int priority, String flowName, int idleTimeOut,
- int hardTimeOut, BigInteger cookie, List<MatchInfo> listMatchInfo, List<InstructionInfo> listInstructionInfo) {
+ int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase> listMatchInfoBase, List<InstructionInfo> listInstructionInfo) {
return MDSALUtil.buildFlow(tableId, flowId, priority, flowName, idleTimeOut, hardTimeOut, cookie,
- listMatchInfo, listInstructionInfo, true);
+ listMatchInfoBase, listInstructionInfo, true);
}
public static Flow buildFlow(short tableId, String flowId, int priority, String flowName, int idleTimeOut,
- int hardTimeOut, BigInteger cookie, List<MatchInfo> listMatchInfo,
+ int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase> listMatchInfoBase,
List<InstructionInfo> listInstructionInfo, boolean isStrict) {
FlowKey key = new FlowKey(new FlowId(flowId));
- return new FlowBuilder().setMatch(buildMatches(listMatchInfo)).setKey(key)
+ return new FlowBuilder().setMatch(buildMatches(listMatchInfoBase)).setKey(key)
.setPriority(Integer.valueOf(priority)).setInstructions(buildInstructions(listInstructionInfo))
.setBarrier(false).setInstallHw(true).setHardTimeout(hardTimeOut).setIdleTimeout(idleTimeOut)
.setFlowName(flowName).setTableId(Short.valueOf(tableId)).setStrict(isStrict)
}
public static Flow buildFlowNew(short tableId, String flowId, int priority, String flowName, int idleTimeOut,
- int hardTimeOut, BigInteger cookie, List<MatchInfo> listMatchInfo, List<Instruction> listInstructionInfo) {
+ int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase> listMatchInfoBase, List<Instruction> listInstructionInfo) {
return MDSALUtil.buildFlowNew(tableId, flowId, priority, flowName, idleTimeOut, hardTimeOut, cookie,
- listMatchInfo, listInstructionInfo, true);
+ listMatchInfoBase, listInstructionInfo, true);
}
private static Flow buildFlowNew(short tableId, String flowId, int priority, String flowName, int idleTimeOut,
- int hardTimeOut, BigInteger cookie, List<MatchInfo> listMatchInfo,
+ int hardTimeOut, BigInteger cookie, List<? extends MatchInfoBase> listMatchInfoBase,
List<Instruction> listInstructionInfo, boolean isStrict) {
FlowKey key = new FlowKey(new FlowId(flowId));
- return new FlowBuilder().setMatch(buildMatches(listMatchInfo)).setKey(key)
+ return new FlowBuilder().setMatch(buildMatches(listMatchInfoBase)).setKey(key)
.setPriority(Integer.valueOf(priority)).setInstructions(new InstructionsBuilder().setInstruction(listInstructionInfo).build())
.setBarrier(false).setInstallHw(true).setHardTimeout(hardTimeOut).setIdleTimeout(idleTimeOut)
.setFlowName(flowName).setTableId(Short.valueOf(tableId)).setStrict(isStrict)
return EMPTY_Instructions;
}
- public static Match buildMatches(List<MatchInfo> listMatchInfo) {
- if (listMatchInfo != null) {
+ public static Match buildMatches(List<? extends MatchInfoBase> listMatchInfoBase) {
+ if (listMatchInfoBase != null) {
MatchBuilder matchBuilder = new MatchBuilder();
Map<Class<?>, Object> mapMatchBuilder = new HashMap<Class<?>, Object>();
- for (MatchInfo matchInfo : listMatchInfo) {
- matchInfo.createInnerMatchBuilder(mapMatchBuilder);
+ for (MatchInfoBase MatchInfoBase : listMatchInfoBase) {
+ MatchInfoBase.createInnerMatchBuilder(mapMatchBuilder);
}
- for (MatchInfo matchInfo : listMatchInfo) {
- matchInfo.setMatch(matchBuilder, mapMatchBuilder);
+ for (MatchInfoBase MatchInfoBase : listMatchInfoBase) {
+ MatchInfoBase.setMatch(matchBuilder, mapMatchBuilder);
}
return matchBuilder.build();
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
-public class MatchInfo implements Serializable {
+public class MatchInfo implements Serializable, MatchInfoBase {
private static final long serialVersionUID = 1L;
private final MatchFieldType m_matchField;
m_asMatchValues = alStringMatchValues;
}
+ @Override
public void createInnerMatchBuilder(Map<Class<?>, Object> mapMatchBuilder) {
m_matchField.createInnerMatchBuilder(this, mapMatchBuilder);
}
+ @Override
public void setMatch(MatchBuilder matchBuilder, Map<Class<?>, Object> mapMatchBuilder) {
m_matchField.setMatch(matchBuilder, this, mapMatchBuilder);
}
--- /dev/null
+/*
+ * Copyright (c) 2016 RedHat Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.genius.mdsalutil;
+
+import java.util.Map;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+
+/**
+ * This interface helps in creating the openflow matches.
+ */
+
+public interface MatchInfoBase {
+
+ /**
+ * Creater the inner match object
+ *
+ * @param mapMatchBuilder the map which holds the matches.
+ */
+ public void createInnerMatchBuilder(Map<Class<?>, Object> mapMatchBuilder);
+
+ /**
+ * Set the match to the match builder.
+ * @param matchBuilder the matchbuilder to set the match
+ * @param mapMatchBuilder the map containing the matches
+ */
+ public void setMatch(MatchBuilder matchBuilder, Map<Class<?>, Object> mapMatchBuilder);
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 RedHat Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.genius.mdsalutil;
+
+import java.util.Map;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralAugMatchNodesNodeTableFlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.ExtensionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.list.grouping.ExtensionListBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxAugMatchNodesNodeTableFlowBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.NxmNxCtStateKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.state.grouping.NxmNxCtStateBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.match.rev140714.nxm.nx.ct.zone.grouping.NxmNxCtZoneBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.MatchField;
+
+import com.google.common.collect.ImmutableList;
+
+public enum NxMatchFieldType {
+
+ ct_state {
+ @Override
+ protected Class<? extends MatchField> getMatchType() {
+ return NxmNxReg.class;
+ }
+
+ @Override
+ public void createInnerMatchBuilder(NxMatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder) {
+ NxmNxCtStateBuilder ctStateBuilder = (NxmNxCtStateBuilder) mapMatchBuilder.get(NxmNxCtStateBuilder.class);
+
+ if (ctStateBuilder == null) {
+ ctStateBuilder = new NxmNxCtStateBuilder();
+ mapMatchBuilder.put(NxmNxCtStateBuilder.class, ctStateBuilder);
+ }
+
+ ctStateBuilder.setCtState(matchInfo.getMatchValues()[0]);
+ ctStateBuilder.setMask(matchInfo.getMatchValues()[1]);
+ }
+
+ @Override
+ public void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
+ Map<Class<?>, Object> mapMatchBuilder) {
+ NxmNxCtStateBuilder ctStateBuilder = (NxmNxCtStateBuilder) mapMatchBuilder
+ .remove(NxmNxCtStateBuilder.class);
+
+ if (ctStateBuilder != null) {
+ NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
+ .setNxmNxCtState(ctStateBuilder.build())
+ .build();
+ GeneralAugMatchNodesNodeTableFlow genAugMatch = new GeneralAugMatchNodesNodeTableFlowBuilder()
+ .setExtensionList(ImmutableList.of(new ExtensionListBuilder()
+ .setExtensionKey(NxmNxCtStateKey.class)
+ .setExtension(new ExtensionBuilder()
+ .addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch)
+ .build()).build())).build();
+ matchBuilderInOut.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
+ }
+ }
+ },
+ ct_zone {
+ @Override
+ protected Class<? extends MatchField> getMatchType() {
+ return NxmNxReg.class;
+ }
+
+ @Override
+ public void createInnerMatchBuilder(NxMatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder) {
+ NxmNxCtZoneBuilder ctZoneBuilder = (NxmNxCtZoneBuilder) mapMatchBuilder.get(NxmNxCtZoneBuilder.class);
+
+ if (ctZoneBuilder == null) {
+ ctZoneBuilder = new NxmNxCtZoneBuilder();
+ mapMatchBuilder.put(NxmNxCtStateBuilder.class, ctZoneBuilder);
+ }
+
+ ctZoneBuilder.setCtZone((int)matchInfo.getMatchValues()[0]);
+ }
+
+ @Override
+ public void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
+ Map<Class<?>, Object> mapMatchBuilder) {
+ NxmNxCtZoneBuilder ctZoneBuilder = (NxmNxCtZoneBuilder) mapMatchBuilder.remove(NxmNxCtZoneBuilder.class);
+
+ if (ctZoneBuilder != null) {
+ NxAugMatchNodesNodeTableFlow nxAugMatch = new NxAugMatchNodesNodeTableFlowBuilder()
+ .setNxmNxCtZone(ctZoneBuilder.build())
+ .build();
+ GeneralAugMatchNodesNodeTableFlow genAugMatch = new GeneralAugMatchNodesNodeTableFlowBuilder()
+ .setExtensionList(ImmutableList.of(new ExtensionListBuilder()
+ .setExtensionKey(NxmNxCtStateKey.class)
+ .setExtension(new ExtensionBuilder()
+ .addAugmentation(NxAugMatchNodesNodeTableFlow.class, nxAugMatch)
+ .build()).build())).build();
+ matchBuilderInOut.addAugmentation(GeneralAugMatchNodesNodeTableFlow.class, genAugMatch);
+ }
+ }
+
+ };
+
+ public abstract void createInnerMatchBuilder(NxMatchInfo matchInfo, Map<Class<?>, Object> mapMatchBuilder);
+
+ public abstract void setMatch(MatchBuilder matchBuilderInOut, MatchInfoBase matchInfo,
+ Map<Class<?>, Object> mapMatchBuilder);
+
+ protected abstract Class<? extends MatchField> getMatchType();
+
+ protected boolean hasMatchFieldMask() {
+ // Override this to return true
+ return false;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 RedHat Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.genius.mdsalutil;
+
+import java.io.Serializable;
+import java.math.BigInteger;
+import java.util.Map;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
+
+/**
+ * This class defines the nicira extension matches.
+ */
+
+public class NxMatchInfo implements Serializable, MatchInfoBase {
+
+
+ private static final long serialVersionUID = 1L;
+
+ private final NxMatchFieldType m_matchField;
+ private long[] m_alMatchValues;
+ private BigInteger[] m_aBigIntValues;
+ private String[] m_asMatchValues;
+
+ public NxMatchInfo(NxMatchFieldType matchField, long[] alMatchValues) {
+ m_matchField = matchField;
+ m_alMatchValues = alMatchValues;
+ }
+
+ public NxMatchInfo(NxMatchFieldType matchField, BigInteger[] alBigMatchValues) {
+ m_matchField = matchField;
+ m_aBigIntValues = alBigMatchValues;
+ }
+
+ public NxMatchInfo(NxMatchFieldType matchField, String[] alStringMatchValues) {
+ m_matchField = matchField;
+ m_asMatchValues = alStringMatchValues;
+ }
+
+ @Override
+ public void createInnerMatchBuilder(Map<Class<?>, Object> mapMatchBuilder) {
+ m_matchField.createInnerMatchBuilder(this, mapMatchBuilder);
+ }
+
+ @Override
+ public void setMatch(MatchBuilder matchBuilder, Map<Class<?>, Object> mapMatchBuilder) {
+ m_matchField.setMatch(matchBuilder, this, mapMatchBuilder);
+ }
+
+ public NxMatchFieldType getMatchField() {
+ return m_matchField;
+ }
+
+ public long[] getMatchValues() {
+ return m_alMatchValues;
+ }
+
+ public BigInteger[] getBigMatchValues() {
+ return m_aBigIntValues;
+ }
+
+ public String[] getStringMatchValues() {
+ return m_asMatchValues;
+ }
+}