import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @author usha@ericsson Action List:This class takes data from SAL layer and
* @param actions SAL actions
* @param version Openflow protocol version used
* @param datapathid
+ * @param flow TODO
* @return OF Library actions
*/
public static List<Action> getActions(
List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions,
- short version, BigInteger datapathid) {
+ short version, BigInteger datapathid, Flow flow) {
List<Action> actionsList = new ArrayList<>();
Action ofAction;
ofAction = SalToOFSetNwSrc(action, actionBuilder, version);
else if (action instanceof SetNwDstActionCase)
ofAction = SalToOFSetNwDst(action, actionBuilder, version);
- else if (action instanceof SetTpSrcActionCase)
- ofAction = SalToOFSetTpSrc(action, actionBuilder, version);
- else if (action instanceof SetTpDstActionCase)
- ofAction = SalToOFSetTpDst(action, actionBuilder, version);
+ else if (action instanceof SetTpSrcActionCase) {
+ ofAction = SalToOFSetTpSrc(action, actionBuilder, version, IPProtocols.fromProtocolNum(flow.getMatch().
+ getIpMatch().getIpProtocol()));
+ }
+ else if (action instanceof SetTpDstActionCase) {
+ ofAction = SalToOFSetTpDst(action, actionBuilder, version, IPProtocols.fromProtocolNum(flow.getMatch().
+ getIpMatch().getIpProtocol()));
+ }
else if (action instanceof SetNwTosActionCase)
ofAction = SalToOFSetNwTos(action, actionBuilder, version);
else if (action instanceof GeneralExtensionGrouping) {
private static Action SalToOFSetTpSrc(
org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
- ActionBuilder actionBuilder, short version) {
+ ActionBuilder actionBuilder, short version, IPProtocols protocol) {
if (version == OFConstants.OFP_VERSION_1_0) {
SetTpSrcActionCase settpsrccase = (SetTpSrcActionCase) action;
MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
matchEntriesBuilder.setHasMask(false);
- matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
- portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(settpsrcaction.getPort().getValue().intValue()));
- matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
+ int port = settpsrcaction.getPort().getValue().intValue();
+ int type = 0x0f & port;
+
+ switch(protocol) {
+ case ICMP:
+ matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
+ Icmpv4TypeMatchEntryBuilder icmpv4TypeMatchEntryBuilder = new Icmpv4TypeMatchEntryBuilder();
+ icmpv4TypeMatchEntryBuilder.setIcmpv4Type((short) type);
+ matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeMatchEntryBuilder.build());
+ break;
+ case ICMPV6:
+ matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
+ Icmpv6TypeMatchEntryBuilder icmpv6TypeMatchEntryBuilder = new Icmpv6TypeMatchEntryBuilder();
+ icmpv6TypeMatchEntryBuilder.setIcmpv6Type((short) type);
+ matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeMatchEntryBuilder.build());
+ break;
+ case TCP:
+ matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
+ portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
+ matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
+ break;
+ case UDP:
+ matchEntriesBuilder.setOxmMatchField(UdpSrc.class);
+ portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
+ matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
+ break;
+ default: logger.warn("Unknown protocol with combination of SetSourcePort: {}", protocol);
+ break;
+ }
actionBuilder
.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
private static Action SalToOFSetTpDst(
org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
- ActionBuilder actionBuilder, short version) {
+ ActionBuilder actionBuilder, short version, IPProtocols protocol) {
if (version == OFConstants.OFP_VERSION_1_0) {
SetTpDstActionCase settpdstcase = (SetTpDstActionCase) action;
MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
matchEntriesBuilder.setHasMask(false);
- matchEntriesBuilder.setOxmMatchField(TcpDst.class);
PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
- portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(settpdstaction.getPort().getValue().intValue()));
- matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
+ int port = settpdstaction.getPort().getValue().intValue();
+ int code = 0x0f & port;
+
+ switch(protocol) {
+ case ICMP:
+ matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
+ Icmpv4CodeMatchEntryBuilder icmpv4CodeMatchEntryBuilder = new Icmpv4CodeMatchEntryBuilder();
+ icmpv4CodeMatchEntryBuilder.setIcmpv4Code((short) code);
+ matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeMatchEntryBuilder.build());
+ break;
+ case ICMPV6:
+ matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
+ Icmpv6CodeMatchEntryBuilder icmpv6CodeMatchEntryBuilder = new Icmpv6CodeMatchEntryBuilder();
+ icmpv6CodeMatchEntryBuilder.setIcmpv6Code((short) code);
+ matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeMatchEntryBuilder.build());
+ break;
+ case TCP:
+ matchEntriesBuilder.setOxmMatchField(TcpDst.class);
+ portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
+ matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
+ break;
+ case UDP:
+ matchEntriesBuilder.setOxmMatchField(UdpDst.class);
+ portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
+ matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
+ break;
+ default: logger.warn("Unknown protocol with combination of SetDestinationPort: {}", protocol);
+ break;
+ }
actionBuilder
.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
QueueIdAction queueId = action.getAugmentation(QueueIdAction.class);
setQueueAction.setQueueId(queueId.getQueueId());
-
return new SetQueueActionCaseBuilder().setSetQueueAction(setQueueAction.build()).build();
}
return new PushPbbActionCaseBuilder().setPushPbbAction(pushPbbAction.build()).build();
}
+ //TODO make a model in YANG for protocols
+ /*private enum IPProtocols {
+ ICMP(1),
+ TCP(6),
+ UDP(17),
+ ICMPV6(58);
+
+ private int protocol;
+
+ private static Map<Integer, IPProtocols> valueMap;
+ static {
+ valueMap = new HashMap<>();
+ for(IPProtocols protocols : IPProtocols.values()) {
+ valueMap.put(protocols.protocol, protocols);
+ }
+ }
+
+ private IPProtocols(int value) {
+ this.protocol = value;
+ }
+
+ private byte getValue() {
+ return (byte) this.protocol;
+ }
+
+ private Short getShortValue() {
+ return new Short((short) protocol);
+ }
+
+ private IPProtocols fromProtocolNum(Short protocolNum) {
+ return valueMap.get(protocolNum);
+ }
+ } */
+
}
MatchReactor.getInstance().convert(flow.getMatch(), version, flowMod,datapathid);
if (flow.getInstructions() != null) {
- flowMod.setInstruction(toInstructions(flow.getInstructions(), version,datapathid));
- flowMod.setAction(getActions(flow.getInstructions(), version,datapathid));
+ flowMod.setInstruction(toInstructions(flow, version,datapathid));
+ flowMod.setAction(getActions(version,datapathid, flow));
}
flowMod.setVersion(version);
}
private static List<Instruction> toInstructions(
- org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions,
+ Flow flow,
short version,BigInteger datapathid) {
List<Instruction> instructionsList = new ArrayList<>();
+ org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions = flow.getInstructions();
for (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction instruction : instructions
.getInstruction()) {
InstructionBuilder instructionBuilder = new InstructionBuilder();
.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions.class);
ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
actionsInstructionBuilder.setAction(ActionConvertor.getActions(writeActions.getAction(),
- version,datapathid));
+ version,datapathid, flow));
instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
instructionsList.add(instructionBuilder.build());
}
.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions.class);
ActionsInstructionBuilder actionsInstructionBuilder = new ActionsInstructionBuilder();
actionsInstructionBuilder.setAction(ActionConvertor.getActions(applyActions.getAction(),
- version,datapathid));
+ version,datapathid, flow));
instructionBuilder.addAugmentation(ActionsInstruction.class, actionsInstructionBuilder.build());
instructionsList.add(instructionBuilder.build());
}
return instructionsList;
}
- private static List<Action> getActions(
+ /*private static List<Action> getActions(
org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions,
- short version,BigInteger datapathid) {
-
+ short version,BigInteger datapathid) {*/
+ private static List<Action> getActions(short version,BigInteger datapathid, Flow flow) {
+
+ org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions instructions = flow.getInstructions();
List<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction> sortedInstructions =
Ordering.from(OrderComparator.<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction>toInstance())
.sortedCopy(instructions.getInstruction());
if (curInstruction instanceof ApplyActionsCase) {
ApplyActionsCase applyActionscase = (ApplyActionsCase) curInstruction;
ApplyActions applyActions = applyActionscase.getApplyActions();
- return ActionConvertor.getActions(applyActions.getAction(), version,datapathid);
+ return ActionConvertor.getActions(applyActions.getAction(), version,datapathid, flow);
}
}
return null;