From: Tomas Slusny Date: Tue, 28 Jun 2016 12:55:02 +0000 (+0200) Subject: Bug 5540 - ActionConvertor, ActionResponseConvertor X-Git-Tag: release/boron~62 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=ee3019e71b1a91ff0aedcbc3aec4ba281872ec78;p=openflowplugin.git Bug 5540 - ActionConvertor, ActionResponseConvertor - Reworked ActionConvertor to use new ConvertorManager desing - Added new ActionResponseConvertor (moved a bit of logic from ActionConvertor) - Updated tests and usages accordingly Change-Id: I76a9b345942272dc555e4d75766968931ee4ecdb Signed-off-by: Tomas Slusny --- diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertor.java deleted file mode 100644 index 84341cd3fc..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertor.java +++ /dev/null @@ -1,1230 +0,0 @@ -/** - * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. 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.openflowplugin.openflow.md.core.sal.convertor; - -import com.google.common.collect.Ordering; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; -import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey; -import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava; -import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava; -import org.opendaylight.openflowplugin.extension.api.TypeVersionKey; -import org.opendaylight.openflowplugin.extension.api.path.ActionPath; -import org.opendaylight.openflowplugin.openflow.md.core.extension.ActionExtensionHelper; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionSetNwDstReactor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionSetNwSrcReactor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IPProtocols; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor; -import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; -import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil; -import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; -import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.out._case.CopyTtlOutBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction; -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.PortNumberUni; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecMplsTtlCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetDlDstCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetDlSrcCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTosCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetTpDstCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetTpSrcCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetVlanPcpCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetVlanVidCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.StripVlanCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.group._case.GroupActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.pop.mpls._case.PopMplsAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.pop.mpls._case.PopMplsActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.pbb._case.PushPbbAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.pbb._case.PushPbbActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.dl.dst._case.SetDlDstActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.dl.src._case.SetDlSrcActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.mpls.ttl._case.SetMplsTtlActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.tos._case.SetNwTosActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.ttl._case.SetNwTtlAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.ttl._case.SetNwTtlActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.queue._case.SetQueueActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.tp.dst._case.SetTpDstActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.tp.src._case.SetTpSrcActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.vlan.pcp._case.SetVlanPcpActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.vlan.vid._case.SetVlanVidActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv4Code; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv4Type; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv6Code; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv6Type; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.UdpDst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.UdpSrc; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanVid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthDstCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthSrcCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4CodeCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4TypeCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv6CodeCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv6TypeCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.InPortCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpDstCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpSrcCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpDstCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpSrcCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanVidCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.dst._case.EthDstBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.src._case.EthSrcBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.code._case.Icmpv4CodeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.type._case.Icmpv4TypeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv6.code._case.Icmpv6CodeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv6.type._case.Icmpv6TypeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.dst._case.TcpDstBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.src._case.TcpSrcBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.dst._case.UdpDstBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.src._case.UdpSrcBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.vid._case.VlanVidBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionGrouping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author usha@ericsson Action List:This class takes data from SAL layer and - * converts into OF Data - * @author avishnoi@in.ibm.com Added convertor for OF bucket actions to SAL - * actions - */ -public final class ActionConvertor { - private static final Logger LOG = LoggerFactory.getLogger(ActionConvertor.class); - private static final String UNKNOWN_ACTION_TYPE_VERSION = "Unknown Action Type for the Version"; - private static final Ordering ACTION_ORDERING = - Ordering.from(OrderComparator.build()); - - private ActionConvertor() { - // NOOP - } - - /** - * Translates SAL actions into OF Library actions - * - * @param actions SAL actions - * @param version Openflow protocol version used - * @param datapathid datapath id - * @param flow TODO - * @return OF Library actions - */ - public static List getActions( - final List actions, - final short version, final BigInteger datapathid, final Flow flow) { - List actionsList = new ArrayList<>(); - Action ofAction; - - final List sortedActions = - ACTION_ORDERING.sortedCopy(actions); - - for (int actionItem = 0; actionItem < sortedActions.size(); actionItem++) { - ofAction = null; - ActionBuilder actionBuilder = new ActionBuilder(); - - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action = sortedActions.get( - actionItem).getAction(); - - - if (action instanceof OutputActionCase) { - ofAction = salToOFAction((OutputActionCase) action, actionBuilder, version); - } else if (action instanceof DropActionCase){ - //noop - } else if (action instanceof GroupActionCase) { - ofAction = salToOFGroupAction(action, actionBuilder); - } else if (action instanceof CopyTtlOutCase) { - ofAction = salToOFCopyTTLIOut(actionBuilder); - } else if (action instanceof CopyTtlInCase) { - ofAction = salToOFCopyTTLIIn(actionBuilder); - } else if (action instanceof SetMplsTtlActionCase) { - ofAction = salToOFSetMplsTtl(action, actionBuilder); - } else if (action instanceof DecMplsTtlCase) { - ofAction = salToOFDecMplsTtl(actionBuilder); - } else if (action instanceof PushVlanActionCase) { - ofAction = salToOFPushVlanAction(action, actionBuilder, version); - } else if (action instanceof PopVlanActionCase) { - ofAction = (version == OFConstants.OFP_VERSION_1_0) ? - salToOFStripVlan(actionBuilder, version) - : salToOFPopVlan(actionBuilder); - } else if (action instanceof PushMplsActionCase) { - ofAction = salToOFPushMplsAction(action, actionBuilder); - } else if (action instanceof PopMplsActionCase) { - ofAction = salToOFPopMpls(action, actionBuilder); - } else if (action instanceof SetQueueActionCase) { - ofAction = salToOFSetQueue(action, actionBuilder); - } else if (action instanceof SetNwTtlActionCase) { - ofAction = salToOFSetNwTtl(action, actionBuilder); - } else if (action instanceof DecNwTtlCase) { - ofAction = salToOFDecNwTtl(actionBuilder); - } else if (action instanceof SetFieldCase) { - ofAction = salToOFSetField(action, actionBuilder, version, datapathid); - } else if (action instanceof PushPbbActionCase) { - ofAction = salToOFPushPbbAction(action, actionBuilder); - } else if (action instanceof PopPbbActionCase) { - ofAction = salToOFPopPBB(actionBuilder); - - // 1.0 Actions - } else if (action instanceof SetVlanIdActionCase) { - ofAction = salToOFSetVlanId(action, actionBuilder, version); - } else if (action instanceof SetVlanPcpActionCase) { - ofAction = salToOFSetVlanpcp(action, actionBuilder, version); - } else if (action instanceof StripVlanActionCase) { - ofAction = salToOFStripVlan(actionBuilder, version); - } else if (action instanceof SetDlSrcActionCase) { - ofAction = salToOFSetDlSrc(action, actionBuilder, version); - } else if (action instanceof SetDlDstActionCase) { - ofAction = salToOFSetDlDst(action, actionBuilder, version); - } else if (action instanceof SetNwSrcActionCase) { - 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, 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) { - /** - * TODO: EXTENSION PROPOSAL (action, MD-SAL to OFJava) - * - we might need sessionContext as converter input - * - */ - - GeneralExtensionGrouping extensionCaseGrouping = (GeneralExtensionGrouping) action; - Extension extAction = extensionCaseGrouping.getExtension(); - ConverterExtensionKey key = new ConverterExtensionKey<>(extensionCaseGrouping.getExtensionKey(), version); - ConvertorToOFJava convertor = - OFSessionUtil.getExtensionConvertorProvider().getConverter(key); - if (convertor != null) { - ofAction = convertor.convert(extAction); - } - } else { - // try vendor codecs - TypeVersionKey key = - new TypeVersionKey<>( - (Class) action.getImplementedInterface(), - version); - ConvertorActionToOFJava convertor = - OFSessionUtil.getExtensionConvertorProvider().getConverter(key); - LOG.trace("OFP Extension action, key:{}, converter:{}", key, convertor); - if (convertor != null) { - ofAction = convertor.convert(action); - } - } - - if (ofAction != null) { - actionsList.add(ofAction); - } - } - return actionsList; - } - - private static Action salToOFSetField( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder, final short version, final BigInteger datapathid) { - - SetFieldCase setFieldCase = (SetFieldCase) action; - org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match = - setFieldCase.getSetField(); - - if (version == OFConstants.OFP_VERSION_1_0) { - // pushvlan +setField can be called to configure 1.0 switches via MDSAL app - if (match.getVlanMatch() != null) { - SetVlanVidActionBuilder vlanidActionBuilder = new SetVlanVidActionBuilder(); - SetVlanVidCaseBuilder setVlanVidCaseBuilder = new SetVlanVidCaseBuilder(); - vlanidActionBuilder.setVlanVid(match.getVlanMatch().getVlanId().getVlanId().getValue()); - setVlanVidCaseBuilder.setSetVlanVidAction(vlanidActionBuilder.build()); - - actionBuilder.setActionChoice(setVlanVidCaseBuilder.build()); - return actionBuilder.build(); - } else { - return emtpyAction(actionBuilder); - } - - } else { - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); - MatchReactor.getInstance().convert(match, version, setFieldBuilder); - setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); - actionBuilder.setActionChoice(setFieldCaseBuilder.build()); - - return actionBuilder.build(); - } - } - - private static Action salToOFDecNwTtl(final ActionBuilder actionBuilder) { - actionBuilder.setActionChoice(new DecNwTtlCaseBuilder().build()); - return emtpyAction(actionBuilder); - } - - private static Action salToOFPushMplsAction( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder) { - PushMplsActionCase pushMplsActionCase = (PushMplsActionCase) action; - PushMplsCaseBuilder pushMplsCaseBuilder = new PushMplsCaseBuilder(); - PushMplsActionBuilder pushMplsBuilder = new PushMplsActionBuilder(); - pushMplsBuilder.setEthertype(new EtherType(pushMplsActionCase.getPushMplsAction().getEthernetType())); - pushMplsCaseBuilder.setPushMplsAction(pushMplsBuilder.build()); - actionBuilder.setActionChoice(pushMplsCaseBuilder.build()); - return actionBuilder.build(); - } - - private static Action salToOFPushPbbAction( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder) { - PushPbbActionCase pushPbbActionCase = (PushPbbActionCase) action; - PushPbbCaseBuilder pushPbbCaseBuilder = new PushPbbCaseBuilder(); - PushPbbActionBuilder pushPbbBuilder = new PushPbbActionBuilder(); - pushPbbBuilder.setEthertype(new EtherType(pushPbbActionCase.getPushPbbAction().getEthernetType())); - pushPbbCaseBuilder.setPushPbbAction(pushPbbBuilder.build()); - actionBuilder.setActionChoice(pushPbbCaseBuilder.build()); - return actionBuilder.build(); - } - - private static Action salToOFPushVlanAction( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder, final short version) { - if (version == OFConstants.OFP_VERSION_1_0) { - // if client configure openflow 1.0 switch as a openflow 1.3 switch using openflow 1.3 instructions - // then we can ignore PUSH_VLAN as set-vlan-id will push a vlan header if not present - return null; - } - PushVlanActionCase pushVlanActionCase = (PushVlanActionCase) action; - PushVlanAction pushVlanAction = pushVlanActionCase.getPushVlanAction(); - - PushVlanCaseBuilder pushVlanCaseBuilder = new PushVlanCaseBuilder(); - PushVlanActionBuilder pushVlanBuilder = new PushVlanActionBuilder(); - if (null != pushVlanAction.getEthernetType()) { - pushVlanBuilder.setEthertype(new EtherType(pushVlanAction.getEthernetType())); - } - pushVlanCaseBuilder.setPushVlanAction(pushVlanBuilder.build()); - actionBuilder.setActionChoice(pushVlanCaseBuilder.build()); - return actionBuilder.build(); - } - - private static Action salToOFSetNwTtl( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder) { - SetNwTtlActionCase nwTtlActionCase = (SetNwTtlActionCase) action; - - SetNwTtlCaseBuilder nwTtlCaseBuilder = new SetNwTtlCaseBuilder(); - SetNwTtlActionBuilder nwTtlBuilder = new SetNwTtlActionBuilder(); - nwTtlBuilder.setNwTtl(nwTtlActionCase.getSetNwTtlAction().getNwTtl()); - nwTtlCaseBuilder.setSetNwTtlAction(nwTtlBuilder.build()); - actionBuilder.setActionChoice(nwTtlCaseBuilder.build()); - return actionBuilder.build(); - } - - private static Action salToOFSetQueue( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder) { - SetQueueActionCase setQueueActionCase = (SetQueueActionCase) action; - SetQueueAction setQueueAction = setQueueActionCase.getSetQueueAction(); - - SetQueueCaseBuilder setQueueCaseBuilder = new SetQueueCaseBuilder(); - SetQueueActionBuilder setQueueBuilder = new SetQueueActionBuilder(); - setQueueBuilder.setQueueId(setQueueAction.getQueueId()); - setQueueCaseBuilder.setSetQueueAction(setQueueBuilder.build()); - actionBuilder.setActionChoice(setQueueCaseBuilder.build()); - return actionBuilder.build(); - } - - private static Action salToOFPopMpls( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder) { - PopMplsActionCase popMplsActionCase = (PopMplsActionCase) action; - - PopMplsCaseBuilder popMplsCaseBuilder = new PopMplsCaseBuilder(); - PopMplsActionBuilder popMplsBuilder = new PopMplsActionBuilder(); - popMplsBuilder.setEthertype(new EtherType(new EtherType(popMplsActionCase.getPopMplsAction().getEthernetType()))); - popMplsCaseBuilder.setPopMplsAction(popMplsBuilder.build()); - actionBuilder.setActionChoice(popMplsCaseBuilder.build()); - return actionBuilder.build(); - } - - private static Action salToOFPopVlan(final ActionBuilder actionBuilder) { - actionBuilder.setActionChoice(new PopVlanCaseBuilder().build()); - return emtpyAction(actionBuilder); - } - - private static Action salToOFPopPBB(final ActionBuilder actionBuilder) { - actionBuilder.setActionChoice(new PopPbbCaseBuilder().build()); - return emtpyAction(actionBuilder); - } - - // set-vlan-id (1.0 feature) can be called on 1.3 switches as well using ADSAL apis - private static Action salToOFSetVlanId( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder, final short version) { - - SetVlanIdActionCase setvlanidcase = (SetVlanIdActionCase) action; - SetVlanIdAction setvlanidaction = setvlanidcase.getSetVlanIdAction(); - - SetVlanVidActionBuilder vlanidActionBuilder = new SetVlanVidActionBuilder(); - SetVlanVidCaseBuilder setVlanVidCaseBuilder = new SetVlanVidCaseBuilder(); - - if (version == OFConstants.OFP_VERSION_1_0) { - vlanidActionBuilder.setVlanVid(setvlanidaction.getVlanId().getValue()); - setVlanVidCaseBuilder.setSetVlanVidAction(vlanidActionBuilder.build()); - actionBuilder.setActionChoice(setVlanVidCaseBuilder.build()); - return actionBuilder.build(); - - } else { - if (version >= OFConstants.OFP_VERSION_1_3) { - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); - List entries = new ArrayList<>(); - MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); - matchBuilder.setOxmClass(OpenflowBasicClass.class); - matchBuilder.setOxmMatchField(VlanVid.class); - matchBuilder.setHasMask(false); - VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder(); - VlanVidBuilder vlanVidBuilder = new VlanVidBuilder(); - vlanVidBuilder.setCfiBit(true); - vlanVidBuilder.setVlanVid(setvlanidaction.getVlanId().getValue()); - vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build()); - matchBuilder.setMatchEntryValue(vlanVidCaseBuilder.build()); - entries.add(matchBuilder.build()); - setFieldBuilder.setMatchEntry(entries); - setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); - actionBuilder.setActionChoice(setFieldCaseBuilder.build()); - return actionBuilder.build(); - } else { - LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version); - return null; - } - } - } - - private static Action salToOFSetVlanpcp( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder, final short version) { - - SetVlanPcpActionCase setvlanpcpcase = (SetVlanPcpActionCase) action; - SetVlanPcpAction setvlanpcpaction = setvlanpcpcase.getSetVlanPcpAction(); - - if (version == OFConstants.OFP_VERSION_1_0) { - SetVlanPcpActionBuilder setVlanPcpActionBuilder = new SetVlanPcpActionBuilder(); - SetVlanPcpCaseBuilder setVlanPcpCaseBuilder = new SetVlanPcpCaseBuilder(); - setVlanPcpActionBuilder.setVlanPcp(setvlanpcpaction.getVlanPcp().getValue()); - setVlanPcpCaseBuilder.setSetVlanPcpAction(setVlanPcpActionBuilder.build()); - actionBuilder.setActionChoice(setVlanPcpCaseBuilder.build()); - return actionBuilder.build(); - } else if (version >= OFConstants.OFP_VERSION_1_3) { - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); - - List matchEntriesList = new ArrayList<>(); - - matchEntriesList.add(MatchConvertorUtil.toOfVlanPcp(setvlanpcpaction.getVlanPcp())); - setFieldBuilder.setMatchEntry(matchEntriesList); - setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); - actionBuilder.setActionChoice(setFieldCaseBuilder.build()); - - return actionBuilder.build(); - } else { - LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version); - return null; - } - } - - private static Action salToOFStripVlan(final ActionBuilder actionBuilder, final short version) { - if (version == OFConstants.OFP_VERSION_1_0) { - actionBuilder.setActionChoice(new StripVlanCaseBuilder().build()); - return emtpyAction(actionBuilder); - } else if (version >= OFConstants.OFP_VERSION_1_3) { - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); - List entries = new ArrayList<>(); - MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); - matchBuilder.setOxmClass(OpenflowBasicClass.class); - matchBuilder.setOxmMatchField(VlanVid.class); - matchBuilder.setHasMask(false); - VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder(); - VlanVidBuilder vlanVidBuilder = new VlanVidBuilder(); - vlanVidBuilder.setCfiBit(true); - vlanVidBuilder.setVlanVid(0x0000); - vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build()); - matchBuilder.setMatchEntryValue(vlanVidCaseBuilder.build()); - matchBuilder.setHasMask(false); - entries.add(matchBuilder.build()); - setFieldBuilder.setMatchEntry(entries); - setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); - actionBuilder.setActionChoice(setFieldCaseBuilder.build()); - return actionBuilder.build(); - } else { - LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version); - return null; - } - } - - private static Action salToOFSetDlSrc( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder, final short version) { - - SetDlSrcActionCase setdlsrccase = (SetDlSrcActionCase) action; - SetDlSrcAction setdlsrcaction = setdlsrccase.getSetDlSrcAction(); - - if (version == OFConstants.OFP_VERSION_1_0) { - SetDlSrcCaseBuilder setDlSrcCaseBuilder = new SetDlSrcCaseBuilder(); - SetDlSrcActionBuilder setDlSrcActionBuilder = new SetDlSrcActionBuilder(); - setDlSrcActionBuilder.setDlSrcAddress(setdlsrcaction.getAddress()); - setDlSrcCaseBuilder.setSetDlSrcAction(setDlSrcActionBuilder.build()); - actionBuilder.setActionChoice(setDlSrcCaseBuilder.build()); - return actionBuilder.build(); - } else if (version >= OFConstants.OFP_VERSION_1_3) { - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); - - List entries = new ArrayList<>(); - MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); - matchBuilder.setOxmClass(OpenflowBasicClass.class); - matchBuilder.setOxmMatchField(EthSrc.class); - EthSrcCaseBuilder ethSrcCaseBuilder = new EthSrcCaseBuilder(); - EthSrcBuilder ethSrcBuilder = new EthSrcBuilder(); - ethSrcBuilder.setMacAddress(setdlsrcaction.getAddress()); - matchBuilder.setHasMask(false); - ethSrcCaseBuilder.setEthSrc(ethSrcBuilder.build()); - matchBuilder.setMatchEntryValue(ethSrcCaseBuilder.build()); - entries.add(matchBuilder.build()); - setFieldBuilder.setMatchEntry(entries); - setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); - actionBuilder.setActionChoice(setFieldCaseBuilder.build()); - - return actionBuilder.build(); - } else { - LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version); - return null; - } - } - - private static Action salToOFSetDlDst( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder, final short version) { - - SetDlDstActionCase setdldstcase = (SetDlDstActionCase) action; - SetDlDstAction setdldstaction = setdldstcase.getSetDlDstAction(); - - if (version == OFConstants.OFP_VERSION_1_0) { - SetDlDstCaseBuilder setDlDstCaseBuilder = new SetDlDstCaseBuilder(); - SetDlDstActionBuilder setDlDstActionBuilder = new SetDlDstActionBuilder(); - setDlDstActionBuilder.setDlDstAddress(setdldstaction.getAddress()); - setDlDstCaseBuilder.setSetDlDstAction(setDlDstActionBuilder.build()); - actionBuilder.setActionChoice(setDlDstCaseBuilder.build()); - return actionBuilder.build(); - } else if (version >= OFConstants.OFP_VERSION_1_3) { - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); - - List entries = new ArrayList<>(); - - MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); - matchBuilder.setOxmClass(OpenflowBasicClass.class); - matchBuilder.setOxmMatchField(EthDst.class); - EthDstCaseBuilder ethDstCaseBuilder = new EthDstCaseBuilder(); - EthDstBuilder ethDstBuilder = new EthDstBuilder(); - ethDstBuilder.setMacAddress(setdldstaction.getAddress()); - matchBuilder.setHasMask(false); - ethDstCaseBuilder.setEthDst(ethDstBuilder.build()); - matchBuilder.setMatchEntryValue(ethDstCaseBuilder.build()); - entries.add(matchBuilder.build()); - setFieldBuilder.setMatchEntry(entries); - setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); - actionBuilder.setActionChoice(setFieldCaseBuilder.build()); - return actionBuilder.build(); - } else { - LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version); - return null; - } - } - - protected static Action salToOFSetNwSrc( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder, final short version) { - - try { - ActionSetNwSrcReactor.getInstance().convert((SetNwSrcActionCase) action, version, actionBuilder); - } catch (Exception e) { - LOG.error(e.getMessage(), e); - return null; - } - - return actionBuilder.build(); - } - - protected static Action salToOFSetNwDst( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder, final short version) { - - try { - ActionSetNwDstReactor.getInstance().convert((SetNwDstActionCase) action, version, actionBuilder); - } catch (Exception e) { - LOG.error(e.getMessage(), e); - return null; - } - - return actionBuilder.build(); - } - - private static Action salToOFSetNwTos( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder, final short version) { - - SetNwTosActionCase setnwtoscase = (SetNwTosActionCase) action; - SetNwTosAction setnwtosaction = setnwtoscase.getSetNwTosAction(); - - if (version == OFConstants.OFP_VERSION_1_0) { - SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder(); - SetNwTosCaseBuilder setNwTosCaseBuilder = new SetNwTosCaseBuilder(); - setNwTosActionBuilder.setNwTos(setnwtosaction.getTos().shortValue()); - setNwTosCaseBuilder.setSetNwTosAction(setNwTosActionBuilder.build()); - actionBuilder.setActionChoice(setNwTosCaseBuilder.build()); - return actionBuilder.build(); - } else if (version >= OFConstants.OFP_VERSION_1_3) { - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); - - List entries = new ArrayList<>(); - entries.add(MatchConvertorUtil.toOfIpDscp(new Dscp( - ActionUtil.tosToDscp(setnwtosaction.getTos().shortValue()) - ))); - setFieldBuilder.setMatchEntry(entries); - setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); - actionBuilder.setActionChoice(setFieldCaseBuilder.build()); - return actionBuilder.build(); - } else { - LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version); - return null; - } - - } - - private static Action salToOFSetTpSrc( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder, final short version, final IPProtocols protocol) { - - SetTpSrcActionCase settpsrccase = (SetTpSrcActionCase) action; - SetTpSrcAction settpsrcaction = settpsrccase.getSetTpSrcAction(); - if (version == OFConstants.OFP_VERSION_1_0) { - SetTpSrcCaseBuilder setTpSrcCaseBuilder = new SetTpSrcCaseBuilder(); - SetTpSrcActionBuilder setTpSrcActionBuilder = new SetTpSrcActionBuilder(); - setTpSrcActionBuilder.setPort(new PortNumber(settpsrcaction.getPort() - .getValue() - .longValue())); - setTpSrcCaseBuilder.setSetTpSrcAction(setTpSrcActionBuilder.build()); - actionBuilder.setActionChoice(setTpSrcCaseBuilder.build()); - return actionBuilder.build(); - } else if (version == OFConstants.OFP_VERSION_1_3) { - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); - - MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); - matchBuilder.setOxmClass(OpenflowBasicClass.class); - matchBuilder.setHasMask(false); - - InPortCaseBuilder inPortCaseBuilder = new InPortCaseBuilder(); - int port = settpsrcaction.getPort().getValue().intValue(); - int type = 0xff & port; - - switch (protocol) { - case ICMP: - matchBuilder.setOxmMatchField(Icmpv4Type.class); - Icmpv4TypeCaseBuilder icmpv4TypeCaseBuilder = new Icmpv4TypeCaseBuilder(); - Icmpv4TypeBuilder icmpv4TypeBuilder = new Icmpv4TypeBuilder(); - icmpv4TypeBuilder.setIcmpv4Type((short) type); - icmpv4TypeCaseBuilder.setIcmpv4Type(icmpv4TypeBuilder.build()); - matchBuilder.setMatchEntryValue(icmpv4TypeCaseBuilder.build()); - break; - case ICMPV6: - matchBuilder.setOxmMatchField(Icmpv6Type.class); - Icmpv6TypeCaseBuilder icmpv6TypeCaseBuilder = new Icmpv6TypeCaseBuilder(); - Icmpv6TypeBuilder icmpv6TypeBuilder = new Icmpv6TypeBuilder(); - icmpv6TypeBuilder.setIcmpv6Type((short) type); - icmpv6TypeCaseBuilder.setIcmpv6Type(icmpv6TypeBuilder.build()); - matchBuilder.setMatchEntryValue(icmpv6TypeCaseBuilder.build()); - break; - case TCP: - matchBuilder.setOxmMatchField(TcpSrc.class); - TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder(); - TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder(); - tcpSrcBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(port)); - tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build()); - matchBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build()); - break; - case UDP: - matchBuilder.setOxmMatchField(UdpSrc.class); - UdpSrcCaseBuilder udpSrcCaseBuilder = new UdpSrcCaseBuilder(); - UdpSrcBuilder udpSrcBuilder = new UdpSrcBuilder(); - udpSrcBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(port)); - udpSrcCaseBuilder.setUdpSrc(udpSrcBuilder.build()); - matchBuilder.setMatchEntryValue(udpSrcCaseBuilder.build()); - break; - default: - LOG.warn("Unknown protocol with combination of SetSourcePort: {}", protocol); - break; - } - List entries = new ArrayList(); - entries.add(matchBuilder.build()); - setFieldBuilder.setMatchEntry(entries); - setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); - actionBuilder.setActionChoice(setFieldCaseBuilder.build()); - return actionBuilder.build(); - } - LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version); - return null; - } - - private static Action salToOFSetTpDst( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder, final short version, final IPProtocols protocol) { - - SetTpDstActionCase settpdstcase = (SetTpDstActionCase) action; - SetTpDstAction settpdstaction = settpdstcase.getSetTpDstAction(); - if (version == OFConstants.OFP_VERSION_1_0) { - SetTpDstCaseBuilder setTpDstCaseBuilder = new SetTpDstCaseBuilder(); - SetTpDstActionBuilder setTpDstActionBuilder = new SetTpDstActionBuilder(); - setTpDstActionBuilder.setPort(new PortNumber(settpdstaction.getPort().getValue().longValue())); - setTpDstCaseBuilder.setSetTpDstAction(setTpDstActionBuilder.build()); - actionBuilder.setActionChoice(setTpDstCaseBuilder.build()); - return actionBuilder.build(); - } else if (version == OFConstants.OFP_VERSION_1_3) { - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); - - MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); - matchBuilder.setOxmClass(OpenflowBasicClass.class); - matchBuilder.setHasMask(false); - int port = settpdstaction.getPort().getValue().intValue(); - int code = 0xff & port; - - switch (protocol) { - case ICMP: - matchBuilder.setOxmMatchField(Icmpv4Code.class); - Icmpv4CodeCaseBuilder icmpv4CodeCaseBuilder = new Icmpv4CodeCaseBuilder(); - Icmpv4CodeBuilder icmpv4CodeBuilder = new Icmpv4CodeBuilder(); - icmpv4CodeBuilder.setIcmpv4Code((short) code); - icmpv4CodeCaseBuilder.setIcmpv4Code(icmpv4CodeBuilder.build()); - matchBuilder.setMatchEntryValue(icmpv4CodeCaseBuilder.build()); - break; - case ICMPV6: - matchBuilder.setOxmMatchField(Icmpv6Code.class); - Icmpv6CodeCaseBuilder icmpv6CodeCaseBuilder = new Icmpv6CodeCaseBuilder(); - Icmpv6CodeBuilder icmpv6CodeBuilder = new Icmpv6CodeBuilder(); - icmpv6CodeBuilder.setIcmpv6Code((short) code); - icmpv6CodeCaseBuilder.setIcmpv6Code(icmpv6CodeBuilder.build()); - matchBuilder.setMatchEntryValue(icmpv6CodeCaseBuilder.build()); - break; - case TCP: - matchBuilder.setOxmMatchField(TcpDst.class); - TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder(); - TcpDstBuilder tcpDstBuilder = new TcpDstBuilder(); - tcpDstBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(port)); - tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build()); - matchBuilder.setMatchEntryValue(tcpDstCaseBuilder.build()); - break; - case UDP: - matchBuilder.setOxmMatchField(UdpDst.class); - UdpDstCaseBuilder udpDstCaseBuilder = new UdpDstCaseBuilder(); - UdpDstBuilder udpDstBuilder = new UdpDstBuilder(); - udpDstBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(port)); - udpDstCaseBuilder.setUdpDst(udpDstBuilder.build()); - matchBuilder.setMatchEntryValue(udpDstCaseBuilder.build()); - break; - default: - LOG.warn("Unknown protocol with combination of SetSourcePort: {}", protocol); - break; - } - List entries = new ArrayList(); - entries.add(matchBuilder.build()); - setFieldBuilder.setMatchEntry(entries); - setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); - actionBuilder.setActionChoice(setFieldCaseBuilder.build()); - return actionBuilder.build(); - } - LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version); - return null; - } - - private static Action salToOFGroupAction( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder) { - GroupActionCase groupActionCase = (GroupActionCase) action; - GroupAction groupAction = groupActionCase.getGroupAction(); - GroupCaseBuilder groupCaseBuilder = new GroupCaseBuilder(); - GroupActionBuilder groupActionBuilder = new GroupActionBuilder(); - - if (null != groupAction.getGroupId()) { - groupActionBuilder.setGroupId(groupAction.getGroupId()); - } else { - groupActionBuilder.setGroupId(Long.parseLong(groupAction.getGroup())); - } - - groupCaseBuilder.setGroupAction(groupActionBuilder.build()); - actionBuilder.setActionChoice(groupCaseBuilder.build()); - return actionBuilder.build(); - } - - private static Action salToOFDecMplsTtl(final ActionBuilder actionBuilder) { - actionBuilder.setActionChoice(new DecMplsTtlCaseBuilder().build()); - return emtpyAction(actionBuilder); - } - - private static Action salToOFSetMplsTtl( - final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action, - final ActionBuilder actionBuilder) { - SetMplsTtlActionCase mplsTtlActionCase = (SetMplsTtlActionCase) action; - SetMplsTtlAction mplsTtlAction = mplsTtlActionCase.getSetMplsTtlAction(); - SetMplsTtlCaseBuilder setMplsTtlCaseBuilder = new SetMplsTtlCaseBuilder(); - SetMplsTtlActionBuilder setMplsTtlBuilder = new SetMplsTtlActionBuilder(); - setMplsTtlBuilder.setMplsTtl(mplsTtlAction.getMplsTtl()/* SAL */); - setMplsTtlCaseBuilder.setSetMplsTtlAction(setMplsTtlBuilder.build()); - actionBuilder.setActionChoice(setMplsTtlCaseBuilder.build()); - return actionBuilder.build(); - } - - private static Action salToOFCopyTTLIIn(final ActionBuilder actionBuilder) { - actionBuilder.setActionChoice(new CopyTtlInCaseBuilder().build()); - return emtpyAction(actionBuilder); - } - - private static Action salToOFCopyTTLIOut(final ActionBuilder actionBuilder) { - actionBuilder.setActionChoice(new CopyTtlOutCaseBuilder().build()); - return emtpyAction(actionBuilder); - - } - - private static Action emtpyAction(final ActionBuilder actionBuilder) { - return actionBuilder.build(); - } - - private static Action salToOFAction( - final OutputActionCase outputActionCase, - final ActionBuilder actionBuilder, final short version) { - - OutputAction outputAction = outputActionCase.getOutputAction(); - OutputActionCaseBuilder caseBuilder = new OutputActionCaseBuilder(); - OutputActionBuilder outputBuilder = new OutputActionBuilder(); - - if (outputAction.getMaxLength() != null) { - outputBuilder.setMaxLength(outputAction.getMaxLength()); - } else { - outputBuilder.setMaxLength(0); - } - Uri uri = outputAction.getOutputNodeConnector(); - OpenflowVersion ofVersion = OpenflowVersion.get(version); - Long portNumber = InventoryDataServiceUtil.portNumberfromNodeConnectorId(ofVersion, uri.getValue()); - if (OpenflowPortsUtil.checkPortValidity(ofVersion, portNumber)) { - outputBuilder.setPort(new PortNumber(portNumber)); - } else { - LOG.error("Invalid Port specified {} for Output Action for OF version: {}", portNumber, ofVersion); - } - caseBuilder.setOutputAction(outputBuilder.build()); - actionBuilder.setActionChoice(caseBuilder.build()); - return actionBuilder.build(); - - } - - /** - * Method to convert OF actions associated with bucket to SAL Actions. - * - * @param actionList action list - * @param ofVersion current ofp version - * @param actionPath TODO - * @return List of converted SAL Actions. - */ - public static List toMDSalActions( - final List actionList, final OpenflowVersion ofVersion, final ActionPath actionPath) { - - List bucketActions = new ArrayList<>(); - if(actionList != null){ - for (Action action : actionList) { - if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase) { - bucketActions.add(ofToSALOutputAction(ofVersion, action)); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCase) { - bucketActions.add(ofToSALGroupAction(action)); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCase) { - CopyTtlOutBuilder copyTtlOutaction = new CopyTtlOutBuilder(); - bucketActions.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder().setCopyTtlOut(copyTtlOutaction.build()).build()); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCase) { - CopyTtlInBuilder copyTtlInaction = new CopyTtlInBuilder(); - bucketActions.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder().setCopyTtlIn(copyTtlInaction.build()).build()); - - } else if (action.getActionChoice() instanceof SetMplsTtlCase) { - bucketActions.add(ofToSALSetMplsTtl(action)); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecMplsTtlCase) { - DecMplsTtlBuilder decMplsTtl = new DecMplsTtlBuilder(); - bucketActions.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder().setDecMplsTtl(decMplsTtl.build()).build()); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCase) { - bucketActions.add(ofToSALPushVlanAction(action)); - } else if ((action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCase) - || (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.StripVlanCase)) { - // OF1.0 nodes will emit StripVlan and OF1.3+ will emit StripVlan/PopVlan, convert both to PopVlan for SAL - PopVlanActionBuilder popVlan = new PopVlanActionBuilder(); - bucketActions.add(new PopVlanActionCaseBuilder().setPopVlanAction(popVlan.build()).build()); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCase) { - bucketActions.add(ofToSALPushMplsAction(action)); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCase) { - bucketActions.add(ofToSALPopMplsAction(action)); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCase) { - bucketActions.add(ofToSALSetQueue(action)); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCase) { - bucketActions.add(ofToSALSetNwTtl(action)); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCase) { - DecNwTtlBuilder decNwTtl = new DecNwTtlBuilder(); - bucketActions.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder() - .setDecNwTtl(decNwTtl.build()).build()); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) { - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase setFieldCase = (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase) action.getActionChoice(); - final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(ofVersion.getVersion()); - final SetFieldAction setFieldAction = setFieldCase.getSetFieldAction(); - final SetFieldBuilder setField = new SetFieldBuilder(); - final Optional matchOptional = ConvertorManager.getInstance().convert(setFieldAction, datapathIdConvertorData); - - if (matchOptional.isPresent()) { - setField.fieldsFrom(matchOptional.get().build()); - } - - bucketActions.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder().setSetField(setField.build()).build()); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCase) { - bucketActions.add(ofToSALPushPbbAction(action)); - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCase) { - PopPbbActionBuilder popPbb = new PopPbbActionBuilder(); - bucketActions.add(new PopPbbActionCaseBuilder().setPopPbbAction(popPbb.build()).build()); - - } else if (action.getActionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCase) { - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder setNwDstActionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder(); - bucketActions.add(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build()); - - } else { - /** - * TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL) - * - we might also need a way on how to identify exact type of augmentation to be - * used as match can be bound to multiple models - */ - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action processedAction = - ActionExtensionHelper.processAlienAction(action, ofVersion, actionPath); - if (processedAction != null) { - bucketActions.add(processedAction); - } - } - } - } - return bucketActions; - } - - /** - * Method converts OF Output action object to SAL Output action object. - * - * @param ofVersion openflow version - * @param action org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common. - * action.rev130731.actions.actions.list.Action - * @return OutputAction - */ - public static OutputActionCase ofToSALOutputAction(final OpenflowVersion ofVersion, final Action action) { - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder outputAction = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder(); - - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase actionCase = - (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase) action.getActionChoice(); - - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputAction outputActionFromOF = actionCase.getOutputAction(); - if (outputActionFromOF.getPort() != null) { - PortNumberUni protocolAgnosticPort = OpenflowPortsUtil.getProtocolAgnosticPort( - ofVersion, outputActionFromOF.getPort().getValue()); - String portNumberAsString = OpenflowPortsUtil.portNumberToString(protocolAgnosticPort); - outputAction.setOutputNodeConnector(new Uri(portNumberAsString)); - } else { - LOG.error("Provided action is not OF Output action, no associated port found!"); - } - - Integer maxLength = outputActionFromOF.getMaxLength(); - if (maxLength != null) { - outputAction.setMaxLength(maxLength); - } else { - LOG.error("Provided action is not OF Output action, no associated length found!"); - } - - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder outputActionCaseBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder(); - outputActionCaseBuilder.setOutputAction(outputAction.build()); - return outputActionCaseBuilder.build(); - } - - /** - * Method converts OF GroupAction object to SAL GroupAction object - * - * @param action action - * @return GroupAction group action - */ - public static GroupActionCase ofToSALGroupAction(final Action action) { - GroupCase actionCase = (GroupCase) action.getActionChoice(); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.group._case.GroupAction groupActionFromOF = - actionCase.getGroupAction(); - - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder groupAction = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder(); - groupAction.setGroupId(groupActionFromOF.getGroupId()); - - return new GroupActionCaseBuilder().setGroupAction(groupAction.build()).build(); - } - - /** - * Method converts OF SetMplsTTL action object to SAL SetMplsTTL action - * object. - * - * @param action action - * @return set-mpls ttl action - */ - public static SetMplsTtlActionCase ofToSALSetMplsTtl(final Action action) { - SetMplsTtlCase actionCase = (SetMplsTtlCase) action.getActionChoice(); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action - .choice.set.mpls.ttl._case.SetMplsTtlAction setMplsTtlActionFromOF = actionCase.getSetMplsTtlAction(); - - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder mplsTtlAction = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder(); - mplsTtlAction.setMplsTtl(setMplsTtlActionFromOF.getMplsTtl()); - return new SetMplsTtlActionCaseBuilder().setSetMplsTtlAction(mplsTtlAction.build()).build(); - } - - /** - * Method converts OF Pushvlan action to SAL PushVlan action. - * - * @param action input actioj - * @return PushVlanAction - */ - public static PushVlanActionCase ofToSALPushVlanAction(final Action action) { - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCase actionCase = - (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCase) action.getActionChoice(); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanAction pushVlanActionFromOF = - actionCase.getPushVlanAction(); - - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder pushVlanAction = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder(); - - pushVlanAction.setEthernetType(pushVlanActionFromOF.getEthertype().getValue()); - return new PushVlanActionCaseBuilder().setPushVlanAction(pushVlanAction.build()).build(); - } - - /** - * Method converts OF PushMpls action to SAL PushMpls action. - * - * @param action action - * @return PushMplsAction - */ - public static PushMplsActionCase ofToSALPushMplsAction(final Action action) { - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCase actionCase = - (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCase) action.getActionChoice(); - PushMplsAction pushMplsActionFromOF = actionCase.getPushMplsAction(); - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder pushMplsAction = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder(); - pushMplsAction.setEthernetType(pushMplsActionFromOF.getEthertype().getValue()); - return new PushMplsActionCaseBuilder().setPushMplsAction(pushMplsAction.build()).build(); - } - - /** - * Method converts OF PopMpls action to SAL PopMpls action. - * - * @param action action - * @return PopMplsActionCase - */ - public static PopMplsActionCase ofToSALPopMplsAction(final Action action) { - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCase actionCase = - (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCase) action.getActionChoice(); - PopMplsAction popMplsActionFromOF = actionCase.getPopMplsAction(); - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder popMplsAction = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder(); - popMplsAction.setEthernetType(popMplsActionFromOF.getEthertype().getValue()); - return new PopMplsActionCaseBuilder().setPopMplsAction(popMplsAction.build()).build(); - } - - /** - * Method converts OF SetQueue action to SAL SetQueue action. - * - * @param action action - * @return SetQueueAction - */ - public static SetQueueActionCase ofToSALSetQueue(final Action action) { - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCase actionCase = - (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCase) action.getActionChoice(); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.queue._case.SetQueueAction queueActionFromOF = - actionCase.getSetQueueAction(); - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder setQueueAction = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder(); - setQueueAction.setQueueId(queueActionFromOF.getQueueId()); - return new SetQueueActionCaseBuilder().setSetQueueAction(setQueueAction.build()).build(); - } - - /** - * Method converts OF SetNwTtl action to SAL SetNwTtl action. - * - * @param action action - * @return SetNwTtlAction - */ - public static SetNwTtlActionCase ofToSALSetNwTtl(final Action action) { - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCase actionCase = - (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCase) action.getActionChoice(); - SetNwTtlAction setNwTtlActionFromOf = actionCase.getSetNwTtlAction(); - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder setNwTtl = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder(); - setNwTtl.setNwTtl(setNwTtlActionFromOf.getNwTtl()); - return new SetNwTtlActionCaseBuilder().setSetNwTtlAction(setNwTtl.build()).build(); - } - - /** - * Method converts OF Pushvlan action to SAL PushVlan action. - * - * @param action action - * @return PushVlanAction - */ - public static PushPbbActionCase ofToSALPushPbbAction(final Action action) { - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCase actionCase = - (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCase) action.getActionChoice(); - PushPbbAction pushPbbActionFromOf = actionCase.getPushPbbAction(); - org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder pushPbbAction = - new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder(); - pushPbbAction.setEthernetType(pushPbbActionFromOf.getEthertype().getValue()); - 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 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 (short) protocol; - } - - private IPProtocols fromProtocolNum(Short protocolNum) { - return valueMap.get(protocolNum); - } - } */ - -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionUtil.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionUtil.java deleted file mode 100644 index 60fcc5da51..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionUtil.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor; - -/** - * Created by Martin Bobak <mbobak@cisco.com> on 13.3.2015. - */ -public final class ActionUtil { - - private ActionUtil() { - throw new IllegalStateException("This class should not be instantiated"); - } - -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java index 2cb539515c..067566d1dc 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ConvertorManager.java @@ -16,6 +16,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionConvertor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionResponseConvertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorData; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; @@ -43,6 +45,8 @@ public class ConvertorManager { // TODO: Add MatchConvertor INSTANCE.registerConvertor(new MatchResponseConvertor()); INSTANCE.registerConvertor(new MatchV10ResponseConvertor()); + INSTANCE.registerConvertor(new ActionConvertor()); + INSTANCE.registerConvertor(new ActionResponseConvertor()); } // Actual convertor keys diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java index 401227b800..0e8f56651e 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/FlowConvertor.java @@ -8,11 +8,16 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; +import com.google.common.base.MoreObjects; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.Ordering; import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; 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.openflow.md.core.sal.convertor.match.MatchReactor; @@ -72,10 +77,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.matc 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.MoreObjects; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.collect.Ordering; /** * Utility class for converting a MD-SAL Flow into the OF flow mod @@ -307,6 +308,13 @@ public class FlowConvertor { InstructionBuilder instructionBuilder = new InstructionBuilder(); org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction curInstruction = instruction .getInstruction(); + ActionConvertorData data = new ActionConvertorData(version); + data.setDatapathId(datapathid); + + if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) { + data.setIpProtocol(flow.getMatch().getIpMatch().getIpProtocol()); + } + if (curInstruction instanceof GoToTableCase) { GoToTableCase goToTablecase = (GoToTableCase) curInstruction; GoToTable goToTable = goToTablecase.getGoToTable(); @@ -334,7 +342,11 @@ public class FlowConvertor { WriteActions writeActions = writeActionscase.getWriteActions(); WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder(); WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder(); - writeActionsBuilder.setAction(ActionConvertor.getActions(writeActions.getAction(),version, datapathid, flow)); + + final java.util.Optional> actions = ConvertorManager.getInstance().convert( + writeActions.getAction(), data); + + writeActionsBuilder.setAction(actions.orElse(Collections.emptyList())); writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build()); instructionBuilder.setInstructionChoice(writeActionsCaseBuilder.build()); instructionsList.add(instructionBuilder.build()); @@ -345,7 +357,10 @@ public class FlowConvertor { new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCaseBuilder(); org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.apply.actions._case.ApplyActionsBuilder applyActionsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.apply.actions._case.ApplyActionsBuilder(); - applyActionsBuilder.setAction(ActionConvertor.getActions(applyActions.getAction(), version, datapathid, flow)); + final java.util.Optional> actionList = ConvertorManager.getInstance().convert( + applyActions.getAction(), data); + + applyActionsBuilder.setAction(actionList.orElse(Collections.emptyList())); applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build()); instructionBuilder.setInstructionChoice(applyActionsCaseBuilder.build()); instructionsList.add(instructionBuilder.build()); @@ -381,7 +396,15 @@ public class FlowConvertor { if (curInstruction instanceof ApplyActionsCase) { ApplyActionsCase applyActionscase = (ApplyActionsCase) curInstruction; ApplyActions applyActions = applyActionscase.getApplyActions(); - return ActionConvertor.getActions(applyActions.getAction(), version, datapathid, flow); + final ActionConvertorData data = new ActionConvertorData(version); + data.setDatapathId(datapathid); + + if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) { + data.setIpProtocol(flow.getMatch().getIpMatch().getIpProtocol()); + } + + java.util.Optional> result = ConvertorManager.getInstance().convert(applyActions.getAction(), data); + return result.orElse(Collections.emptyList()); } } return null; diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertor.java index 2a73c8bbaa..8d2ee474ac 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupConvertor.java @@ -12,8 +12,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; - +import java.util.Optional; import org.opendaylight.openflowjava.protocol.api.util.BinContent; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroup; @@ -108,6 +109,8 @@ public final class GroupConvertor { private static List salToOFBucketList(Buckets buckets, short version, int groupType,BigInteger datapathid) { final List bucketLists = new ArrayList<>(); + final ActionConvertorData data = new ActionConvertorData(version); + data.setDatapathId(datapathid); for (org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket groupBucket : buckets .getBucket()) { BucketsListBuilder bucketBuilder = new BucketsListBuilder(); @@ -116,8 +119,10 @@ public final class GroupConvertor { salToOFBucketListWatchGroup(groupBucket, bucketBuilder, groupType); salToOFBucketListWatchPort(groupBucket, bucketBuilder, groupType); - List bucketActionList = ActionConvertor.getActions(groupBucket.getAction(), version, datapathid, null); - bucketBuilder.setAction(bucketActionList); + Optional> bucketActionList = ConvertorManager.getInstance().convert( + groupBucket.getAction(), data); + + bucketBuilder.setAction(bucketActionList.orElse(Collections.emptyList())); BucketsList bucket = bucketBuilder.build(); bucketLists.add(bucket); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertor.java index 99c8cdf619..c3e385fc8f 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertor.java @@ -9,12 +9,14 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; import java.util.ArrayList; +import java.util.Collections; import java.util.List; - -import org.opendaylight.openflowplugin.extension.api.path.ActionPath; +import java.util.Optional; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter32; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Counter64; +import org.opendaylight.openflowplugin.extension.api.path.ActionPath; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey; @@ -138,6 +140,8 @@ public class GroupStatsResponseConvertor { public org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.Buckets toSALBucketsDesc( List bucketDescStats, OpenflowVersion ofVersion ){ + final ActionResponseConvertorData data = new ActionResponseConvertorData(ofVersion.getVersion()); + data.setActionPath(ActionPath.GROUPDESCSTATSUPDATED_GROUPDESCSTATS_BUCKETS_BUCKET_ACTION); org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder salBucketsDesc = new org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.BucketsBuilder(); @@ -145,21 +149,26 @@ public class GroupStatsResponseConvertor { int bucketKey = 0; for(BucketsList bucketDetails : bucketDescStats){ BucketBuilder bucketDesc = new BucketBuilder(); - List convertedSalActions = - ActionConvertor.toMDSalActions (bucketDetails.getAction(), ofVersion, - ActionPath.GROUPDESCSTATSUPDATED_GROUPDESCSTATS_BUCKETS_BUCKET_ACTION); - - List actions = new ArrayList<>(); - int actionKey = 0; - for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action : convertedSalActions){ - ActionBuilder wrappedAction = new ActionBuilder(); - wrappedAction.setAction(action); - wrappedAction.setKey(new ActionKey(actionKey)); - wrappedAction.setOrder(actionKey); - actions.add(wrappedAction.build()); - actionKey++; + final Optional> convertedSalActions = + ConvertorManager.getInstance().convert(bucketDetails.getAction(), data); + + if (convertedSalActions.isPresent()) { + List actions = new ArrayList<>(); + int actionKey = 0; + for (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action : convertedSalActions.get()) { + ActionBuilder wrappedAction = new ActionBuilder(); + wrappedAction.setAction(action); + wrappedAction.setKey(new ActionKey(actionKey)); + wrappedAction.setOrder(actionKey); + actions.add(wrappedAction.build()); + actionKey++; + } + + bucketDesc.setAction(actions); + } else { + bucketDesc.setAction(Collections.emptyList()); } - bucketDesc.setAction(actions); + bucketDesc.setWeight(bucketDetails.getWeight()); bucketDesc.setWatchPort(bucketDetails.getWatchPort().getValue()); bucketDesc.setWatchGroup(bucketDetails.getWatchGroup()); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java index 4ca2d58bda..35480d7dcf 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/OFToMDSalFlowConvertor.java @@ -10,10 +10,13 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Optional; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; import org.opendaylight.openflowplugin.extension.api.path.ActionPath; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey; @@ -68,9 +71,13 @@ public final class OFToMDSalFlowConvertor { ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder(); ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder(); + final ActionResponseConvertorData actionResponseConvertorData = new ActionResponseConvertorData(ofVersion.getVersion()); + actionResponseConvertorData.setActionPath(ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION); - applyActionsBuilder.setAction(wrapActionList(ActionConvertor.toMDSalActions(actionsInstruction.getApplyActions().getAction(), ofVersion, ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION))); + final Optional> actions = ConvertorManager.getInstance().convert( + actionsInstruction.getApplyActions().getAction(), actionResponseConvertorData); + applyActionsBuilder.setAction(wrapActionList(actions.orElse(Collections.emptyList()))); applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build()); salInstruction = applyActionsCaseBuilder.build(); } else if (switchInst.getInstructionChoice() instanceof org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCase) { @@ -106,7 +113,14 @@ public final class OFToMDSalFlowConvertor { WriteActionsCaseBuilder writeActionsCaseBuilder = new WriteActionsCaseBuilder(); WriteActionsBuilder writeActionsBuilder = new WriteActionsBuilder(); - writeActionsBuilder.setAction(wrapActionList(ActionConvertor.toMDSalActions(writeActionsCase.getWriteActions().getAction(), ofVersion, ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION))); + + final ActionResponseConvertorData actionResponseConvertorData = new ActionResponseConvertorData(ofVersion.getVersion()); + actionResponseConvertorData.setActionPath(ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION); + + final Optional> actions = ConvertorManager.getInstance().convert( + writeActionsCase.getWriteActions().getAction(), actionResponseConvertorData); + + writeActionsBuilder.setAction(wrapActionList(actions.orElse(Collections.emptyList()))); writeActionsCaseBuilder.setWriteActions(writeActionsBuilder.build()); salInstruction = writeActionsCaseBuilder.build(); @@ -174,8 +188,13 @@ public final class OFToMDSalFlowConvertor { ApplyActionsCaseBuilder applyActionsCaseBuilder = new ApplyActionsCaseBuilder(); ApplyActionsBuilder applyActionsBuilder = new ApplyActionsBuilder(); - applyActionsBuilder.setAction(wrapActionList(ActionConvertor.toMDSalActions(actionsList, ofVersion, ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION))); + final ActionResponseConvertorData actionResponseConvertorData = new ActionResponseConvertorData(ofVersion.getVersion()); + actionResponseConvertorData.setActionPath(ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION); + + final Optional> actions = ConvertorManager.getInstance().convert( + actionsList, actionResponseConvertorData); + applyActionsBuilder.setAction(wrapActionList(actions.orElse(Collections.emptyList()))); applyActionsCaseBuilder.setApplyActions(applyActionsBuilder.build()); InstructionBuilder instBuilder = new InstructionBuilder(); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertor.java index bc002d1409..50f834a46d 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertor.java @@ -10,12 +10,14 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; import com.google.common.collect.Iterables; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Optional; import org.opendaylight.controller.sal.common.util.Arguments; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; -import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder; @@ -85,7 +87,13 @@ public final class PacketOutConvertor { List inputActions = inputPacket.getAction(); if (inputActions != null) { - actions = ActionConvertor.getActions(inputActions, version, datapathid, null); + final ActionConvertorData actionConvertorData = new ActionConvertorData(version); + actionConvertorData.setDatapathId(datapathid); + + final Optional> convertedActions = ConvertorManager.getInstance().convert( + inputActions, actionConvertorData); + + actions = convertedActions.orElse(Collections.emptyList()); } else { actions = new ArrayList<>(); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertor.java new file mode 100644 index 0000000000..3d7c5f0204 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertor.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. 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.openflowplugin.openflow.md.core.sal.convertor.action; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfCopyTtlInCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfCopyTtlOutCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfDecMplsTtlCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfDecNwTtlCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfDropActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfGeneralExtensionGroupingCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfGroupActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfOutputActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPopMplsActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPopPbbActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPopVlanActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPopVlanActionV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPushMplsActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPushPbbActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPushVlanActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetDlDstActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetDlDstActionV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetDlSrcActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetDlSrcActionV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetFieldCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetFieldV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetMplsTtlActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwDstActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwDstActionV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwSrcActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwSrcActionV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwTosActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwTosActionV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwTtlActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetQueueActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetTpDstActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetTpDstActionV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetTpSrcActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetTpSrcActionV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetVlanIdActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetVlanIdActionV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetVlanPcpActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetVlanPcpActionV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfStripVlanActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfStripVlanActionV10Case; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfVendorCodecCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; + +/** + * Converts SAL actions into OF Library actions + * + * Example usage: + *
+ * {@code
+ * ActionConvertorData data = new ActionConvertorData(version);
+ * data.setDatapathId(datapathId);
+ * data.setIpProtocol(ipProtocol);
+ * Optional> ofActions = ConvertorManager.getInstance().convert(salActions, data);
+ * }
+ * 
+ */ +public final class ActionConvertor implements ParametrizedConvertor< + List, + List, + ActionConvertorData> { + + private static final ConvertorProcessor PROCESSOR = new ConvertorProcessor< + org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, + Action, + ActionConvertorData>() + // Set default rule, what will be used if no rule match is found + .setDefaultCase(new SalToOfVendorCodecCase()) + // Add rules for each action type + .addCase(new SalToOfCopyTtlInCase()) + .addCase(new SalToOfCopyTtlOutCase()) + .addCase(new SalToOfDecMplsTtlCase()) + .addCase(new SalToOfDecNwTtlCase()) + .addCase(new SalToOfDropActionCase()) + .addCase(new SalToOfGroupActionCase()) + .addCase(new SalToOfOutputActionCase()) + .addCase(new SalToOfPopMplsActionCase()) + .addCase(new SalToOfPopPbbActionCase()) + .addCase(new SalToOfPopVlanActionCase()) + .addCase(new SalToOfPopVlanActionV10Case()) + .addCase(new SalToOfPushMplsActionCase()) + .addCase(new SalToOfPushPbbActionCase()) + .addCase(new SalToOfPushVlanActionCase()) + .addCase(new SalToOfSetFieldCase()) + .addCase(new SalToOfSetFieldV10Case()) + .addCase(new SalToOfSetMplsTtlActionCase()) + .addCase(new SalToOfSetNwTtlActionCase()) + .addCase(new SalToOfSetQueueActionCase()) + // Openflow 1.0 actions, with support for Openflow 1.3 + .addCase(new SalToOfSetVlanIdActionCase()) + .addCase(new SalToOfSetVlanIdActionV10Case()) + .addCase(new SalToOfSetVlanPcpActionCase()) + .addCase(new SalToOfSetVlanPcpActionV10Case()) + .addCase(new SalToOfStripVlanActionCase()) + .addCase(new SalToOfStripVlanActionV10Case()) + .addCase(new SalToOfSetDlSrcActionCase()) + .addCase(new SalToOfSetDlSrcActionV10Case()) + .addCase(new SalToOfSetDlDstActionCase()) + .addCase(new SalToOfSetDlDstActionV10Case()) + .addCase(new SalToOfSetNwSrcActionCase()) + .addCase(new SalToOfSetNwSrcActionV10Case()) + .addCase(new SalToOfSetNwDstActionCase()) + .addCase(new SalToOfSetNwDstActionV10Case()) + .addCase(new SalToOfSetTpSrcActionCase()) + .addCase(new SalToOfSetTpSrcActionV10Case()) + .addCase(new SalToOfSetTpDstActionCase()) + .addCase(new SalToOfSetTpDstActionV10Case()) + .addCase(new SalToOfSetNwTosActionCase()) + .addCase(new SalToOfSetNwTosActionV10Case()) + // Try to convert action grouping using converters from openflowplugin-extension + .addCase(new SalToOfGeneralExtensionGroupingCase()); + + @Override + public Class getType() { + return org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action.class; + } + + @Override + public List convert(List source, ActionConvertorData data) { + // Prepare list of converted actions + final List result = new ArrayList<>(); + + // Iterate over SAL actions, run them through tokenizer and then add them to list of converted actions + if (source != null) { + for (final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action : source) { + final Optional convertedAction = PROCESSOR.process(action.getAction(), data); + + if (convertedAction.isPresent()) { + result.add(convertedAction.get()); + } + } + } + + return result; + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionResponseConvertor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionResponseConvertor.java new file mode 100644 index 0000000000..1ddf48088b --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionResponseConvertor.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. 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.openflowplugin.openflow.md.core.sal.convertor.action; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +import org.opendaylight.openflowplugin.openflow.md.core.extension.ActionExtensionHelper; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalCopyTtlInCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalCopyTtlOutCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalDecMplsTtlCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalDecNwTtlCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalGroupCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalOutputActionCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPopMplsCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPopPbbCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPopVlanCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPushMplsCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPushPbbCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPushVlanCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetFieldCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetMplsTtlCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetNwDstCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetNwTtlCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetQueueCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalStripVlanCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.ActionChoice; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; + +/** + * Converts OF actions associated with bucket to SAL Actions. + * + * Example usage: + *
+ * {@code
+ * ActionResponseConvertorData data = new ActionResponseConvertorData(version);
+ * data.setActionPath(actionPath);
+ * Optional> salActions = ConvertorManager.getInstance().convert(ofActions, data);
+ * }
+ * 
+ */ +public final class ActionResponseConvertor implements ParametrizedConvertor< + List, + List, + ActionResponseConvertorData> { + + private static final ConvertorProcessor PROCESSOR = new ConvertorProcessor< + ActionChoice, + org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, + ActionResponseConvertorData>() + // Add rules for each action type + .addCase(new OfToSalCopyTtlInCase()) + .addCase(new OfToSalCopyTtlOutCase()) + .addCase(new OfToSalDecMplsTtlCase()) + .addCase(new OfToSalDecNwTtlCase()) + .addCase(new OfToSalGroupCase()) + .addCase(new OfToSalOutputActionCase()) + .addCase(new OfToSalPopMplsCase()) + .addCase(new OfToSalPopPbbCase()) + .addCase(new OfToSalPopVlanCase()) + .addCase(new OfToSalPushMplsCase()) + .addCase(new OfToSalPushPbbCase()) + .addCase(new OfToSalPushVlanCase()) + .addCase(new OfToSalSetFieldCase()) + .addCase(new OfToSalSetMplsTtlCase()) + .addCase(new OfToSalSetNwDstCase()) + .addCase(new OfToSalSetNwTtlCase()) + .addCase(new OfToSalSetQueueCase()) + .addCase(new OfToSalStripVlanCase()); + + @Override + public Class getType() { + return Action.class; + } + + @Override + public List convert(List source, ActionResponseConvertorData data) { + final List result = new ArrayList<>(); + final OpenflowVersion ofVersion = OpenflowVersion.get(data.getVersion()); + + // Iterate over Openflow actions, run them through tokenizer and then add them to list of converted actions + if (source != null) { + for (final Action action : source) { + final Optional convertedAction = PROCESSOR.process(action.getActionChoice(), data); + + if (convertedAction.isPresent()) { + result.add(convertedAction.get()); + } else { + /** + * TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL) + * - we might also need a way on how to identify exact type of augmentation to be + * used as match can be bound to multiple models + */ + org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action processedAction = + ActionExtensionHelper.processAlienAction(action, ofVersion, data.getActionPath()); + + if (processedAction != null) { + result.add(processedAction); + } + } + } + } + + return result; + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorImpl.java deleted file mode 100644 index 15909e8fa0..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorImpl.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2013 Ericsson. 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.openflowplugin.openflow.md.core.sal.convertor.action; - -import com.google.common.base.Splitter; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6; - -/** - * Utility class for converting a MD-SAL action subelement into the OF subelement - */ -public class ActionSetNwDstConvertorImpl implements Convertor { - private static final Splitter PREFIX_SPLITTER = Splitter.on('/'); - - @Override - public Class getType() { - return SetNwDstActionCase.class; - } - - @Override - public Object convert(final SetNwDstActionCase source) { - Address address = source.getSetNwDstAction().getAddress(); - if (address instanceof Ipv4) { - Iterable addressParts = PREFIX_SPLITTER.split(((Ipv4) address).getIpv4Address().getValue()); - return new Ipv4Address(addressParts.iterator().next()); - } else if (address instanceof Ipv6) { - Iterable addressParts = PREFIX_SPLITTER.split(((Ipv6) address).getIpv6Address().getValue()); - return new Ipv6Address(addressParts.iterator().next()); - } else { - throw new IllegalArgumentException("Address is not supported: "+address.getClass().getName()); - } - } -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorV10Impl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorV10Impl.java deleted file mode 100644 index 0a3293495d..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstConvertorV10Impl.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2013 Ericsson. 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.openflowplugin.openflow.md.core.sal.convertor.action; - -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; - -/** - * Utility class for converting a MD-SAL action subelement into the OF subelement - */ -public class ActionSetNwDstConvertorV10Impl implements Convertor { - - @Override - public Class getType() { - return SetNwDstActionCase.class; - } - - @Override - public Object convert(SetNwDstActionCase source) { - Address address = source.getSetNwDstAction().getAddress(); - if (address instanceof Ipv4) { - //FIXME use of substring should be removed and OF models should distinguish where - //FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask) - - String ipAddress = ((Ipv4) address).getIpv4Address().getValue(); - ipAddress = ipAddress.substring(0, ipAddress.indexOf("/")); - return new Ipv4Address(ipAddress); - } else { - throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName()); - } - } -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactor.java deleted file mode 100644 index 887ed4fadf..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactor.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (c) 2013 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action; - -import java.util.Map; - -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertReactor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionKey; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionResultTargetKey; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ResultInjector; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; - -/** - * - */ -public class ActionSetNwDstReactor extends ConvertReactor { - - private static ActionSetNwDstReactor INSTANCE = new ActionSetNwDstReactor(); - - private ActionSetNwDstReactor() { - //NOOP - } - - /** - * @return singleton - */ - public static ActionSetNwDstReactor getInstance() { - return INSTANCE; - } - - @Override - protected void initMappings(final Map> conversions, - final Map> injections) { - ActionSetNwDstReactorMappingFactory.addSetNwDstConvertors(conversions); - ActionSetNwDstReactorMappingFactory.addSetNwDstInjectors(injections); - } - - @Override - protected InjectionKey buildInjectionKey(final short version, - final Object convertedItem, final Object target) { - InjectionResultTargetKey key = null; - if (convertedItem != null) { - key = new InjectionResultTargetKey(version, target.getClass(), convertedItem.getClass()); - } - return key; - } - -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorMappingFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorMappingFactory.java deleted file mode 100644 index afbdb4a56b..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorMappingFactory.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Copyright (c) 2013 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionKey; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionResultTargetKey; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ResultInjector; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.dst._case.SetNwDstActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Dst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Dst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4DstCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6DstCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.dst._case.Ipv4DstBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.dst._case.Ipv6DstBuilder; - -/** - * add prepared convertors and injectors into given mappings - * - * @see ActionSetNwSrcReactor - */ -public class ActionSetNwDstReactorMappingFactory { - - /** - * @param conversionMapping conversion mapping - */ - public static void addSetNwDstConvertors(final Map> conversionMapping) { - conversionMapping.put(OFConstants.OFP_VERSION_1_0, new ActionSetNwDstConvertorV10Impl()); - conversionMapping.put(OFConstants.OFP_VERSION_1_3, new ActionSetNwDstConvertorImpl()); - } - - /** - * @param injectionMapping injection mapping - */ - public static void addSetNwDstInjectors(final Map> injectionMapping) { - // OF-1.0| Ipv4Address -> ActionBuilder; SetNwDst - injectionMapping.put(new InjectionResultTargetKey(OFConstants.OFP_VERSION_1_0, - ActionBuilder.class, Ipv4Address.class), - new ResultInjector() { - @Override - public void inject(final Ipv4Address result, final ActionBuilder target) { - SetNwDstCaseBuilder setNwDstCaseBuilder = new SetNwDstCaseBuilder(); - SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder(); - setNwDstActionBuilder.setIpAddress(result); - setNwDstCaseBuilder.setSetNwDstAction(setNwDstActionBuilder.build()); - target.setActionChoice(setNwDstCaseBuilder.build()); - } - }); - - // OF-1.3| Ipv4Address -> ActionBuilder; SetNwDst - injectionMapping.put(new InjectionResultTargetKey(OFConstants.OFP_VERSION_1_3, - ActionBuilder.class, Ipv4Address.class), - new ResultInjector() { - @Override - public void inject(final Ipv4Address result, final ActionBuilder target) { - List matchEntriesList = new ArrayList<>(); - MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder(); - matchEntryBuilder.setOxmClass(OpenflowBasicClass.class); - matchEntryBuilder.setOxmMatchField(Ipv4Dst.class); - - Ipv4DstCaseBuilder ipv4DstCaseBuilder = new Ipv4DstCaseBuilder(); - Ipv4DstBuilder ipv4DstBuilder = new Ipv4DstBuilder(); - ipv4DstBuilder.setIpv4Address(result); - Integer prefix = IpConversionUtil.extractPrefix(result); - if (prefix != null) { - ipv4DstBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix)); - } - ipv4DstCaseBuilder.setIpv4Dst(ipv4DstBuilder.build()); - - matchEntryBuilder.setHasMask(false); - matchEntryBuilder.setMatchEntryValue(ipv4DstCaseBuilder.build()); - matchEntriesList.add(matchEntryBuilder.build()); - - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldActionBuilder = new SetFieldActionBuilder(); - setFieldActionBuilder.setMatchEntry(matchEntriesList); - setFieldCaseBuilder.setSetFieldAction(setFieldActionBuilder.build()); - target.setActionChoice(setFieldCaseBuilder.build()); - } - }); - - // OF-1.3| Ipv6Address -> ActionBuilder; SetNwDst - injectionMapping.put(new InjectionResultTargetKey(OFConstants.OFP_VERSION_1_3, - ActionBuilder.class, Ipv6Address.class), - new ResultInjector() { - @Override - public void inject(final Ipv6Address result, final ActionBuilder target) { - List matchEntriesList = new ArrayList<>(); - MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder(); - matchEntryBuilder.setOxmClass(OpenflowBasicClass.class); - matchEntryBuilder.setOxmMatchField(Ipv6Dst.class); - - Ipv6DstCaseBuilder ipv6DstCaseBuilder = new Ipv6DstCaseBuilder(); - Ipv6DstBuilder ipv6DstBuilder = new Ipv6DstBuilder(); - ipv6DstBuilder.setIpv6Address(result); - Integer prefix = IpConversionUtil.extractPrefix(result); - if (prefix != null) { - ipv6DstBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix)); - } - ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build()); - - matchEntryBuilder.setHasMask(false); - matchEntryBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build()); - matchEntriesList.add(matchEntryBuilder.build()); - - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldActionBuilder = new SetFieldActionBuilder(); - setFieldActionBuilder.setMatchEntry(matchEntriesList); - setFieldCaseBuilder.setSetFieldAction(setFieldActionBuilder.build()); - target.setActionChoice(setFieldCaseBuilder.build()); - } - }); - } -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorImpl.java deleted file mode 100644 index 0b58ae0c5d..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) 2013 Ericsson. 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.openflowplugin.openflow.md.core.sal.convertor.action; - -import com.google.common.base.Splitter; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6; - -/** - * Utility class for converting a MD-SAL action subelement into the OF subelement - */ -public class ActionSetNwSrcConvertorImpl implements Convertor { - - private static final Splitter PREFIX_SPLITTER = Splitter.on('/'); - - @Override - public Class getType() { - return SetNwSrcActionCase.class; - } - - @Override - public Object convert(final SetNwSrcActionCase source) { - Address address = source.getSetNwSrcAction().getAddress(); - if (address instanceof Ipv4) { - Iterable addressParts = PREFIX_SPLITTER.split(((Ipv4) address).getIpv4Address().getValue()); - return new Ipv4Address(addressParts.iterator().next()); - } else if (address instanceof Ipv6) { - Iterable addressParts = PREFIX_SPLITTER.split(((Ipv6) address).getIpv6Address().getValue()); - return new Ipv6Address(addressParts.iterator().next()); - } else { - throw new IllegalArgumentException("Address is not supported: "+address.getClass().getName()); - } - } -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorV10Impl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorV10Impl.java deleted file mode 100644 index fc988aa2bc..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcConvertorV10Impl.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2013 Ericsson. 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.openflowplugin.openflow.md.core.sal.convertor.action; - -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; - -/** - * Utility class for converting a MD-SAL action subelement into the OF subelement - */ -public class ActionSetNwSrcConvertorV10Impl implements Convertor { - - @Override - public Class getType() { - return SetNwSrcActionCase.class; - } - - @Override - public Object convert(SetNwSrcActionCase source) { - Address address = source.getSetNwSrcAction().getAddress(); - if (address instanceof Ipv4) { - //FIXME use of substring should be removed and OF models should distinguish where - //FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask) - - String ipAddress = ((Ipv4) address).getIpv4Address().getValue(); - ipAddress = ipAddress.substring(0, ipAddress.indexOf("/")); - return new Ipv4Address(ipAddress); - } else { - throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName()); - } - } -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactor.java deleted file mode 100644 index a704458afb..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactor.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (c) 2013 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action; - -import java.util.Map; - -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertReactor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionKey; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionResultTargetKey; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ResultInjector; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; - -/** - * - */ -public class ActionSetNwSrcReactor extends ConvertReactor { - - private static ActionSetNwSrcReactor INSTANCE = new ActionSetNwSrcReactor(); - - private ActionSetNwSrcReactor() { - //NOOP - } - - /** - * @return singleton - */ - public static ActionSetNwSrcReactor getInstance() { - return INSTANCE; - } - - @Override - protected void initMappings(final Map> conversions, - final Map> injections) { - ActionSetNwSrcReactorMappingFactory.addSetNwSrcConvertors(conversions); - ActionSetNwSrcReactorMappingFactory.addSetNwSrcInjectors(injections); - } - - @Override - protected InjectionKey buildInjectionKey(final short version, - final Object convertedItem, final Object target) { - InjectionResultTargetKey key = null; - if (convertedItem != null) { - key = new InjectionResultTargetKey(version, target.getClass(), convertedItem.getClass()); - } - return key; - } - -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorMappingFactory.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorMappingFactory.java deleted file mode 100644 index a7d43108f1..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorMappingFactory.java +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Copyright (c) 2013 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionKey; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.InjectionResultTargetKey; -import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ResultInjector; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwSrcCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4SrcCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.src._case.Ipv4SrcBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.src._case.Ipv6SrcBuilder; - -/** - * add prepared convertors and injectors into given mappings - * - * @see ActionSetNwSrcReactor - */ -public class ActionSetNwSrcReactorMappingFactory { - - /** - * @param conversionMapping conversion mapping - */ - public static void addSetNwSrcConvertors(final Map> conversionMapping) { - conversionMapping.put(OFConstants.OFP_VERSION_1_0, new ActionSetNwSrcConvertorV10Impl()); - conversionMapping.put(OFConstants.OFP_VERSION_1_3, new ActionSetNwSrcConvertorImpl()); - } - - /** - * @param injectionMapping injection mapping - */ - public static void addSetNwSrcInjectors(final Map> injectionMapping) { - // OF-1.0| Ipv4Address -> ActionBuilder; SetNwSrc - injectionMapping.put(new InjectionResultTargetKey(OFConstants.OFP_VERSION_1_0, - ActionBuilder.class, Ipv4Address.class), - new ResultInjector() { - @Override - public void inject(final Ipv4Address result, final ActionBuilder target) { - SetNwSrcCaseBuilder nwSrcCaseBuilder = new SetNwSrcCaseBuilder(); - SetNwSrcActionBuilder nwSrcBuilder = new SetNwSrcActionBuilder(); - nwSrcBuilder.setIpAddress(new Ipv4Address(result)); - nwSrcCaseBuilder.setSetNwSrcAction(nwSrcBuilder.build()); - target.setActionChoice(nwSrcCaseBuilder.build()); - } - }); - - // OF-1.3| Ipv4Address -> ActionBuilder; SetNwSrc - injectionMapping.put(new InjectionResultTargetKey(OFConstants.OFP_VERSION_1_3, - ActionBuilder.class, Ipv4Address.class), - new ResultInjector() { - @Override - public void inject(final Ipv4Address result, final ActionBuilder target) { - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); - List entries = new ArrayList<>(); - MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder(); - matchEntryBuilder.setOxmClass(OpenflowBasicClass.class); - matchEntryBuilder.setOxmMatchField(Ipv4Src.class); - - Ipv4SrcCaseBuilder ipv4SrcCaseBuilder = new Ipv4SrcCaseBuilder(); - Ipv4SrcBuilder ipv4SrcBuilder = new Ipv4SrcBuilder(); - ipv4SrcBuilder.setIpv4Address(result); - Integer prefix = IpConversionUtil.extractPrefix(result); - if (prefix != null) { - ipv4SrcBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix)); - } - ipv4SrcCaseBuilder.setIpv4Src(ipv4SrcBuilder.build()); - - matchEntryBuilder.setHasMask(false); - matchEntryBuilder.setMatchEntryValue(ipv4SrcCaseBuilder.build()); - entries.add(matchEntryBuilder.build()); - setFieldBuilder.setMatchEntry(entries); - setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); - target.setActionChoice(setFieldCaseBuilder.build()); - } - }); - - // OF-1.3| Ipv6Address -> ActionBuilder; SetNwSrc - injectionMapping.put(new InjectionResultTargetKey(OFConstants.OFP_VERSION_1_3, - ActionBuilder.class, Ipv6Address.class), - new ResultInjector() { - @Override - public void inject(final Ipv6Address result, final ActionBuilder target) { - List matchEntriesList = new ArrayList<>(); - MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder(); - matchEntryBuilder.setOxmClass(OpenflowBasicClass.class); - matchEntryBuilder.setOxmMatchField(Ipv6Src.class); - - Ipv6SrcCaseBuilder ipv6SrcCaseBuilder = new Ipv6SrcCaseBuilder(); - Ipv6SrcBuilder ipv6SrcBuilder = new Ipv6SrcBuilder(); - ipv6SrcBuilder.setIpv6Address(result); - Integer prefix = IpConversionUtil.extractPrefix(result); - if (prefix != null) { - ipv6SrcBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix)); - } - ipv6SrcCaseBuilder.setIpv6Src(ipv6SrcBuilder.build()); - - matchEntryBuilder.setHasMask(false); - matchEntryBuilder.setMatchEntryValue(ipv6SrcCaseBuilder.build()); - matchEntriesList.add(matchEntryBuilder.build()); - - SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); - SetFieldActionBuilder setFieldActionBuilder = new SetFieldActionBuilder(); - setFieldActionBuilder.setMatchEntry(matchEntriesList); - setFieldCaseBuilder.setSetFieldAction(setFieldActionBuilder.build()); - target.setActionChoice(setFieldCaseBuilder.build()); - - } - }); - } - - private static byte[] extractIpv4Mask(boolean hasMask, final Iterator addressParts) { - final int prefix; - if (addressParts.hasNext()) { - int potentionalPrefix = Integer.parseInt(addressParts.next()); - prefix = potentionalPrefix < 32 ? potentionalPrefix : 0; - } else { - prefix = 0; - } - - if (prefix != 0) { - int mask = 0xffffffff << (32 - prefix); - byte[] maskBytes = new byte[]{(byte) (mask >>> 24), (byte) (mask >>> 16), (byte) (mask >>> 8), - (byte) mask}; - hasMask = true; - return maskBytes; - } - return null; - } -} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalCopyTtlInCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalCopyTtlInCase.java new file mode 100644 index 0000000000..9838ffc734 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalCopyTtlInCase.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCase; + +public class OfToSalCopyTtlInCase extends ConvertorCase { + public OfToSalCopyTtlInCase() { + super(CopyTtlInCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final CopyTtlInCase source, final ActionResponseConvertorData data) { + CopyTtlInBuilder copyTtlInaction = new CopyTtlInBuilder(); + return Optional.of(new CopyTtlInCaseBuilder().setCopyTtlIn(copyTtlInaction.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalCopyTtlOutCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalCopyTtlOutCase.java new file mode 100644 index 0000000000..369c325e3c --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalCopyTtlOutCase.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.out._case.CopyTtlOutBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCase; + +public class OfToSalCopyTtlOutCase extends ConvertorCase { + public OfToSalCopyTtlOutCase() { + super(CopyTtlOutCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final CopyTtlOutCase source, final ActionResponseConvertorData data) { + CopyTtlOutBuilder copyTtlOutaction = new CopyTtlOutBuilder(); + return Optional.of(new CopyTtlOutCaseBuilder().setCopyTtlOut(copyTtlOutaction.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalDecMplsTtlCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalDecMplsTtlCase.java new file mode 100644 index 0000000000..11eca3074d --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalDecMplsTtlCase.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecMplsTtlCase; + +public class OfToSalDecMplsTtlCase extends ConvertorCase { + public OfToSalDecMplsTtlCase() { + super(DecMplsTtlCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final DecMplsTtlCase source, final ActionResponseConvertorData data) { + DecMplsTtlBuilder decMplsTtl = new DecMplsTtlBuilder(); + return Optional.of(new DecMplsTtlCaseBuilder().setDecMplsTtl(decMplsTtl.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalDecNwTtlCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalDecNwTtlCase.java new file mode 100644 index 0000000000..4305aacba1 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalDecNwTtlCase.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCase; + +public class OfToSalDecNwTtlCase extends ConvertorCase { + public OfToSalDecNwTtlCase() { + super(DecNwTtlCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final DecNwTtlCase source, final ActionResponseConvertorData data) { + DecNwTtlBuilder decNwTtl = new DecNwTtlBuilder(); + return Optional.of(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalGroupCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalGroupCase.java new file mode 100644 index 0000000000..c51cff0cb9 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalGroupCase.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.group._case.GroupAction; + +public class OfToSalGroupCase extends ConvertorCase { + public OfToSalGroupCase() { + super(GroupCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final GroupCase source, final ActionResponseConvertorData data) { + GroupAction groupActionFromOF = source.getGroupAction(); + GroupActionBuilder groupAction = new GroupActionBuilder(); + groupAction.setGroupId(groupActionFromOF.getGroupId()); + + return Optional.of(new GroupActionCaseBuilder().setGroupAction(groupAction.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalOutputActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalOutputActionCase.java new file mode 100644 index 0000000000..1b831ed407 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalOutputActionCase.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortNumberUni; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputAction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class OfToSalOutputActionCase extends ConvertorCase { + private static final Logger LOG = LoggerFactory.getLogger(OfToSalOutputActionCase.class); + + public OfToSalOutputActionCase() { + super(OutputActionCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final OutputActionCase source, final ActionResponseConvertorData data) { + final OpenflowVersion ofVersion = OpenflowVersion.get(data.getVersion()); + + OutputActionBuilder outputAction = new OutputActionBuilder(); + OutputAction outputActionFromOF = source.getOutputAction(); + + if (outputActionFromOF.getPort() != null) { + PortNumberUni protocolAgnosticPort = OpenflowPortsUtil.getProtocolAgnosticPort(ofVersion, outputActionFromOF.getPort().getValue()); + String portNumberAsString = OpenflowPortsUtil.portNumberToString(protocolAgnosticPort); + outputAction.setOutputNodeConnector(new Uri(portNumberAsString)); + } else { + LOG.error("Provided action is not OF Output action, no associated port found!"); + } + + Integer maxLength = outputActionFromOF.getMaxLength(); + + if (maxLength != null) { + outputAction.setMaxLength(maxLength); + } else { + LOG.error("Provided action is not OF Output action, no associated length found!"); + } + + OutputActionCaseBuilder outputActionCaseBuilder = new OutputActionCaseBuilder(); + outputActionCaseBuilder.setOutputAction(outputAction.build()); + + return Optional.of(outputActionCaseBuilder.build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPopMplsCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPopMplsCase.java new file mode 100644 index 0000000000..519d06be0c --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPopMplsCase.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.pop.mpls._case.PopMplsAction; + +public class OfToSalPopMplsCase extends ConvertorCase { + public OfToSalPopMplsCase() { + super(PopMplsCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final PopMplsCase source, final ActionResponseConvertorData data) { + PopMplsAction popMplsActionFromOF = source.getPopMplsAction(); + PopMplsActionBuilder popMplsAction = new PopMplsActionBuilder(); + popMplsAction.setEthernetType(popMplsActionFromOF.getEthertype().getValue()); + return Optional.of(new PopMplsActionCaseBuilder().setPopMplsAction(popMplsAction.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPopPbbCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPopPbbCase.java new file mode 100644 index 0000000000..debc22116f --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPopPbbCase.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCase; + +public class OfToSalPopPbbCase extends ConvertorCase { + public OfToSalPopPbbCase() { + super(PopPbbCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final PopPbbCase source, final ActionResponseConvertorData data) { + PopPbbActionBuilder popPbb = new PopPbbActionBuilder(); + return Optional.of(new PopPbbActionCaseBuilder().setPopPbbAction(popPbb.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPopVlanCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPopVlanCase.java new file mode 100644 index 0000000000..b450bfba32 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPopVlanCase.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCase; + +public class OfToSalPopVlanCase extends ConvertorCase { + public OfToSalPopVlanCase() { + super(PopVlanCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final PopVlanCase source, final ActionResponseConvertorData data) { + PopVlanActionBuilder popVlan = new PopVlanActionBuilder(); + return Optional.of(new PopVlanActionCaseBuilder().setPopVlanAction(popVlan.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPushMplsCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPushMplsCase.java new file mode 100644 index 0000000000..4f9c7db1cd --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPushMplsCase.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsAction; + +public class OfToSalPushMplsCase extends ConvertorCase { + public OfToSalPushMplsCase() { + super(PushMplsCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final PushMplsCase source, final ActionResponseConvertorData data) { + PushMplsAction pushMplsActionFromOF = source.getPushMplsAction(); + PushMplsActionBuilder pushMplsAction = new PushMplsActionBuilder(); + pushMplsAction.setEthernetType(pushMplsActionFromOF.getEthertype().getValue()); + return Optional.of(new PushMplsActionCaseBuilder().setPushMplsAction(pushMplsAction.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPushPbbCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPushPbbCase.java new file mode 100644 index 0000000000..f2cd9b987d --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPushPbbCase.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.pbb._case.PushPbbAction; + +public class OfToSalPushPbbCase extends ConvertorCase { + public OfToSalPushPbbCase() { + super(PushPbbCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final PushPbbCase source, final ActionResponseConvertorData data) { + PushPbbAction pushPbbActionFromOf = source.getPushPbbAction(); + PushPbbActionBuilder pushPbbAction = new PushPbbActionBuilder(); + pushPbbAction.setEthernetType(pushPbbActionFromOf.getEthertype().getValue()); + return Optional.of(new PushPbbActionCaseBuilder().setPushPbbAction(pushPbbAction.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPushVlanCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPushVlanCase.java new file mode 100644 index 0000000000..61c8deb7f8 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalPushVlanCase.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanAction; + +public class OfToSalPushVlanCase extends ConvertorCase { + public OfToSalPushVlanCase() { + super(PushVlanCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final PushVlanCase source, final ActionResponseConvertorData data) { + PushVlanAction pushVlanActionFromOF = source.getPushVlanAction(); + PushVlanActionBuilder pushVlanAction = new PushVlanActionBuilder(); + pushVlanAction.setEthernetType(pushVlanActionFromOF.getEthertype().getValue()); + return Optional.of(new PushVlanActionCaseBuilder().setPushVlanAction(pushVlanAction.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetFieldCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetFieldCase.java new file mode 100644 index 0000000000..3b97a5ca5a --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetFieldCase.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldAction; + +public class OfToSalSetFieldCase extends ConvertorCase { + public OfToSalSetFieldCase() { + super(SetFieldCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final SetFieldCase source, final ActionResponseConvertorData data) { + final VersionDatapathIdConvertorData datapathIdConvertorData = new VersionDatapathIdConvertorData(data.getVersion()); + final SetFieldAction setFieldAction = source.getSetFieldAction(); + final SetFieldBuilder setField = new SetFieldBuilder(); + final Optional matchOptional = ConvertorManager.getInstance().convert(setFieldAction, datapathIdConvertorData); + setField.fieldsFrom(matchOptional.orElse(new MatchBuilder()).build()); + + return Optional.of(new SetFieldCaseBuilder().setSetField(setField.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetMplsTtlCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetMplsTtlCase.java new file mode 100644 index 0000000000..8dfc94d437 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetMplsTtlCase.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.mpls.ttl._case.SetMplsTtlAction; + +public class OfToSalSetMplsTtlCase extends ConvertorCase { + public OfToSalSetMplsTtlCase() { + super(SetMplsTtlCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final SetMplsTtlCase source, final ActionResponseConvertorData data) { + SetMplsTtlAction setMplsTtlActionFromOF = source.getSetMplsTtlAction(); + + SetMplsTtlActionBuilder mplsTtlAction = new SetMplsTtlActionBuilder(); + mplsTtlAction.setMplsTtl(setMplsTtlActionFromOF.getMplsTtl()); + return Optional.of(new SetMplsTtlActionCaseBuilder().setSetMplsTtlAction(mplsTtlAction.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetNwDstCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetNwDstCase.java new file mode 100644 index 0000000000..b87f578dbc --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetNwDstCase.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCase; + +public class OfToSalSetNwDstCase extends ConvertorCase { + public OfToSalSetNwDstCase() { + super(SetNwDstCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final SetNwDstCase source, final ActionResponseConvertorData data) { + SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder(); + return Optional.of(new SetNwDstActionCaseBuilder().setSetNwDstAction(setNwDstActionBuilder.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetNwTtlCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetNwTtlCase.java new file mode 100644 index 0000000000..5e207453d3 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetNwTtlCase.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.ttl._case.SetNwTtlAction; + +public class OfToSalSetNwTtlCase extends ConvertorCase { + public OfToSalSetNwTtlCase() { + super(SetNwTtlCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final SetNwTtlCase source, final ActionResponseConvertorData data) { + SetNwTtlAction setNwTtlActionFromOf = source.getSetNwTtlAction(); + SetNwTtlActionBuilder setNwTtl = new SetNwTtlActionBuilder(); + setNwTtl.setNwTtl(setNwTtlActionFromOf.getNwTtl()); + return Optional.of(new SetNwTtlActionCaseBuilder().setSetNwTtlAction(setNwTtl.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetQueueCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetQueueCase.java new file mode 100644 index 0000000000..bdaf478447 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalSetQueueCase.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.queue._case.SetQueueAction; + +public class OfToSalSetQueueCase extends ConvertorCase { + public OfToSalSetQueueCase() { + super(SetQueueCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final SetQueueCase source, final ActionResponseConvertorData data) { + SetQueueAction queueActionFromOF = source.getSetQueueAction(); + SetQueueActionBuilder setQueueAction = new SetQueueActionBuilder(); + setQueueAction.setQueueId(queueActionFromOF.getQueueId()); + return Optional.of(new SetQueueActionCaseBuilder().setSetQueueAction(setQueueAction.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalStripVlanCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalStripVlanCase.java new file mode 100644 index 0000000000..bcc0e7c725 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/OfToSalStripVlanCase.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.StripVlanCase; + +public class OfToSalStripVlanCase extends ConvertorCase { + public OfToSalStripVlanCase() { + super(StripVlanCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Override + public Optional process(@Nonnull final StripVlanCase source, final ActionResponseConvertorData data) { + PopVlanActionBuilder popVlan = new PopVlanActionBuilder(); + return Optional.of(new PopVlanActionCaseBuilder().setPopVlanAction(popVlan.build()).build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfCopyTtlInCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfCopyTtlInCase.java new file mode 100644 index 0000000000..12d5359f91 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfCopyTtlInCase.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfCopyTtlInCase extends ConvertorCase { + public SalToOfCopyTtlInCase() { + super(CopyTtlInCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final CopyTtlInCase source, final ActionConvertorData data) { + return Optional.of(new ActionBuilder() + .setActionChoice(new CopyTtlInCaseBuilder().build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfCopyTtlOutCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfCopyTtlOutCase.java new file mode 100644 index 0000000000..cb5b41cfd1 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfCopyTtlOutCase.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfCopyTtlOutCase extends ConvertorCase { + public SalToOfCopyTtlOutCase() { + super(CopyTtlOutCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final CopyTtlOutCase source, final ActionConvertorData data) { + return Optional.of(new ActionBuilder() + .setActionChoice(new CopyTtlOutCaseBuilder().build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfDecMplsTtlCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfDecMplsTtlCase.java new file mode 100644 index 0000000000..a5bd2d0531 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfDecMplsTtlCase.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecMplsTtlCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfDecMplsTtlCase extends ConvertorCase { + public SalToOfDecMplsTtlCase() { + super(DecMplsTtlCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final DecMplsTtlCase source, final ActionConvertorData data) { + return Optional.of(new ActionBuilder() + .setActionChoice(new DecMplsTtlCaseBuilder().build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfDecNwTtlCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfDecNwTtlCase.java new file mode 100644 index 0000000000..4c8790d30a --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfDecNwTtlCase.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfDecNwTtlCase extends ConvertorCase { + public SalToOfDecNwTtlCase() { + super(DecNwTtlCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final DecNwTtlCase source, final ActionConvertorData data) { + return Optional.of(new ActionBuilder() + .setActionChoice(new DecNwTtlCaseBuilder().build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfDropActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfDropActionCase.java new file mode 100644 index 0000000000..a7787c9a3c --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfDropActionCase.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; + +public class SalToOfDropActionCase extends ConvertorCase { + public SalToOfDropActionCase() { + super(DropActionCase.class, false, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final DropActionCase source, final ActionConvertorData data) { + return Optional.empty(); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfGeneralExtensionGroupingCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfGeneralExtensionGroupingCase.java new file mode 100644 index 0000000000..04ae198cb5 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfGeneralExtensionGroupingCase.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey; +import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionGrouping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SalToOfGeneralExtensionGroupingCase extends ConvertorCase { + private static final Logger LOG = LoggerFactory.getLogger(SalToOfGeneralExtensionGroupingCase.class); + + public SalToOfGeneralExtensionGroupingCase() { + super(GeneralExtensionGrouping.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final GeneralExtensionGrouping source, final ActionConvertorData data) { + final short version = data.getVersion(); + /** + * TODO: EXTENSION PROPOSAL (action, MD-SAL to OFJava) + * - we might need sessionContext as converter input + * + */ + + Extension extAction = source.getExtension(); + ConverterExtensionKey key = new ConverterExtensionKey<>(source.getExtensionKey(), version); + ConvertorToOFJava convertor = OFSessionUtil.getExtensionConvertorProvider().getConverter(key); + return convertor != null ? Optional.of(convertor.convert(extAction)) : Optional.empty(); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfGroupActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfGroupActionCase.java new file mode 100644 index 0000000000..cf2a483dbb --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfGroupActionCase.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.group._case.GroupActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfGroupActionCase extends ConvertorCase { + public SalToOfGroupActionCase() { + super(GroupActionCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final GroupActionCase source, final ActionConvertorData data) { + GroupAction groupAction = source.getGroupAction(); + GroupActionBuilder groupActionBuilder = new GroupActionBuilder(); + + if (null != groupAction.getGroupId()) { + groupActionBuilder.setGroupId(groupAction.getGroupId()); + } else { + groupActionBuilder.setGroupId(Long.parseLong(groupAction.getGroup())); + } + + return Optional.of(new ActionBuilder() + .setActionChoice(new GroupCaseBuilder() + .setGroupAction(groupActionBuilder.build()) + .build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfOutputActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfOutputActionCase.java new file mode 100644 index 0000000000..644a228bcf --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfOutputActionCase.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; +import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SalToOfOutputActionCase extends ConvertorCase { + private static final Logger LOG = LoggerFactory.getLogger(SalToOfOutputActionCase.class); + + public SalToOfOutputActionCase() { + super(OutputActionCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final OutputActionCase source, final ActionConvertorData data) { + final OutputAction outputAction = source.getOutputAction(); + final OutputActionBuilder outputBuilder = new OutputActionBuilder(); + + if (outputAction.getMaxLength() != null) { + outputBuilder.setMaxLength(outputAction.getMaxLength()); + } else { + outputBuilder.setMaxLength(0); + } + + final OpenflowVersion version = OpenflowVersion.get(data.getVersion()); + final String nodeConnectorId = outputAction.getOutputNodeConnector().getValue(); + final Long portNumber = InventoryDataServiceUtil.portNumberfromNodeConnectorId(version, nodeConnectorId); + + if (OpenflowPortsUtil.checkPortValidity(version, portNumber)) { + outputBuilder.setPort(new PortNumber(portNumber)); + } else { + LOG.error("Invalid Port specified {} for Output Action for OF version: {}", portNumber, version); + } + + return Optional.of(new ActionBuilder() + .setActionChoice(new OutputActionCaseBuilder() + .setOutputAction(outputBuilder.build()) + .build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopMplsActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopMplsActionCase.java new file mode 100644 index 0000000000..82ba5baf93 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopMplsActionCase.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.pop.mpls._case.PopMplsActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; + +public class SalToOfPopMplsActionCase extends ConvertorCase { + public SalToOfPopMplsActionCase() { + super(PopMplsActionCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final PopMplsActionCase source, final ActionConvertorData data) { + PopMplsCaseBuilder popMplsCaseBuilder = new PopMplsCaseBuilder(); + PopMplsActionBuilder popMplsBuilder = new PopMplsActionBuilder(); + popMplsBuilder.setEthertype(new EtherType(new EtherType(source.getPopMplsAction().getEthernetType()))); + popMplsCaseBuilder.setPopMplsAction(popMplsBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(popMplsCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopPbbActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopPbbActionCase.java new file mode 100644 index 0000000000..8b6a523fe3 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopPbbActionCase.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfPopPbbActionCase extends ConvertorCase { + public SalToOfPopPbbActionCase() { + super(PopPbbActionCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final PopPbbActionCase source, final ActionConvertorData data) { + return Optional.of(new ActionBuilder() + .setActionChoice(new PopPbbCaseBuilder().build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopVlanActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopVlanActionCase.java new file mode 100644 index 0000000000..2025a99493 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopVlanActionCase.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfPopVlanActionCase extends ConvertorCase { + public SalToOfPopVlanActionCase() { + super(PopVlanActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final PopVlanActionCase source, final ActionConvertorData data) { + return Optional.of(new ActionBuilder() + .setActionChoice(new PopVlanCaseBuilder().build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopVlanActionV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopVlanActionV10Case.java new file mode 100644 index 0000000000..6319d5ae98 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPopVlanActionV10Case.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.StripVlanCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfPopVlanActionV10Case extends ConvertorCase { + public SalToOfPopVlanActionV10Case() { + super(PopVlanActionCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final PopVlanActionCase source, final ActionConvertorData data) { + return Optional.of(new ActionBuilder() + .setActionChoice(new StripVlanCaseBuilder().build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPushMplsActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPushMplsActionCase.java new file mode 100644 index 0000000000..c6e2a52951 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPushMplsActionCase.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; + +public class SalToOfPushMplsActionCase extends ConvertorCase { + public SalToOfPushMplsActionCase() { + super(PushMplsActionCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final PushMplsActionCase source, final ActionConvertorData data) { + PushMplsCaseBuilder pushMplsCaseBuilder = new PushMplsCaseBuilder(); + PushMplsActionBuilder pushMplsBuilder = new PushMplsActionBuilder(); + pushMplsBuilder.setEthertype(new EtherType(source.getPushMplsAction().getEthernetType())); + pushMplsCaseBuilder.setPushMplsAction(pushMplsBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(pushMplsCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPushPbbActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPushPbbActionCase.java new file mode 100644 index 0000000000..b9886c5a30 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPushPbbActionCase.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.pbb._case.PushPbbActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; + +public class SalToOfPushPbbActionCase extends ConvertorCase { + public SalToOfPushPbbActionCase() { + super(PushPbbActionCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final PushPbbActionCase source, final ActionConvertorData data) { + PushPbbCaseBuilder pushPbbCaseBuilder = new PushPbbCaseBuilder(); + PushPbbActionBuilder pushPbbBuilder = new PushPbbActionBuilder(); + pushPbbBuilder.setEthertype(new EtherType(source.getPushPbbAction().getEthernetType())); + pushPbbCaseBuilder.setPushPbbAction(pushPbbBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(pushPbbCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPushVlanActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPushVlanActionCase.java new file mode 100644 index 0000000000..a40e94d436 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfPushVlanActionCase.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.vlan._case.PushVlanActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; + +public class SalToOfPushVlanActionCase extends ConvertorCase { + public SalToOfPushVlanActionCase() { + super(PushVlanActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final PushVlanActionCase source, final ActionConvertorData data) { + PushVlanAction pushVlanAction = source.getPushVlanAction(); + + PushVlanCaseBuilder pushVlanCaseBuilder = new PushVlanCaseBuilder(); + PushVlanActionBuilder pushVlanBuilder = new PushVlanActionBuilder(); + + if (pushVlanAction.getEthernetType() != null) { + pushVlanBuilder.setEthertype(new EtherType(pushVlanAction.getEthernetType())); + } + + pushVlanCaseBuilder.setPushVlanAction(pushVlanBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(pushVlanCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlDstActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlDstActionCase.java new file mode 100644 index 0000000000..36ddbf0389 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlDstActionCase.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthDstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.dst._case.EthDstBuilder; + +public class SalToOfSetDlDstActionCase extends ConvertorCase { + public SalToOfSetDlDstActionCase() { + super(SetDlDstActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetDlDstActionCase source, final ActionConvertorData data) { + SetDlDstAction setdldstaction = source.getSetDlDstAction(); + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); + + List entries = new ArrayList<>(); + + MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); + matchBuilder.setOxmClass(OpenflowBasicClass.class); + matchBuilder.setOxmMatchField(EthDst.class); + EthDstCaseBuilder ethDstCaseBuilder = new EthDstCaseBuilder(); + EthDstBuilder ethDstBuilder = new EthDstBuilder(); + ethDstBuilder.setMacAddress(setdldstaction.getAddress()); + matchBuilder.setHasMask(false); + ethDstCaseBuilder.setEthDst(ethDstBuilder.build()); + matchBuilder.setMatchEntryValue(ethDstCaseBuilder.build()); + entries.add(matchBuilder.build()); + setFieldBuilder.setMatchEntry(entries); + setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setFieldCaseBuilder.build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlDstActionV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlDstActionV10Case.java new file mode 100644 index 0000000000..4b75af9722 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlDstActionV10Case.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetDlDstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.dl.dst._case.SetDlDstActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetDlDstActionV10Case extends ConvertorCase { + public SalToOfSetDlDstActionV10Case() { + super(SetDlDstActionCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetDlDstActionCase source, final ActionConvertorData data) { + SetDlDstAction setdldstaction = source.getSetDlDstAction(); + SetDlDstCaseBuilder setDlDstCaseBuilder = new SetDlDstCaseBuilder(); + SetDlDstActionBuilder setDlDstActionBuilder = new SetDlDstActionBuilder(); + setDlDstActionBuilder.setDlDstAddress(setdldstaction.getAddress()); + setDlDstCaseBuilder.setSetDlDstAction(setDlDstActionBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setDlDstCaseBuilder.build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlSrcActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlSrcActionCase.java new file mode 100644 index 0000000000..527e0893b2 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlSrcActionCase.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.EthSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.EthSrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.eth.src._case.EthSrcBuilder; + +public class SalToOfSetDlSrcActionCase extends ConvertorCase { + public SalToOfSetDlSrcActionCase() { + super(SetDlSrcActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetDlSrcActionCase source, final ActionConvertorData data) { + SetDlSrcAction setdlsrcaction = source.getSetDlSrcAction(); + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); + + List entries = new ArrayList<>(); + MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); + matchBuilder.setOxmClass(OpenflowBasicClass.class); + matchBuilder.setOxmMatchField(EthSrc.class); + EthSrcCaseBuilder ethSrcCaseBuilder = new EthSrcCaseBuilder(); + EthSrcBuilder ethSrcBuilder = new EthSrcBuilder(); + ethSrcBuilder.setMacAddress(setdlsrcaction.getAddress()); + matchBuilder.setHasMask(false); + ethSrcCaseBuilder.setEthSrc(ethSrcBuilder.build()); + matchBuilder.setMatchEntryValue(ethSrcCaseBuilder.build()); + entries.add(matchBuilder.build()); + setFieldBuilder.setMatchEntry(entries); + setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setFieldCaseBuilder.build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlSrcActionV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlSrcActionV10Case.java new file mode 100644 index 0000000000..b18b42bbfe --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetDlSrcActionV10Case.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetDlSrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.dl.src._case.SetDlSrcActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetDlSrcActionV10Case extends ConvertorCase { + public SalToOfSetDlSrcActionV10Case() { + super(SetDlSrcActionCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetDlSrcActionCase source, final ActionConvertorData data) { + SetDlSrcAction setdlsrcaction = source.getSetDlSrcAction(); + SetDlSrcCaseBuilder setDlSrcCaseBuilder = new SetDlSrcCaseBuilder(); + SetDlSrcActionBuilder setDlSrcActionBuilder = new SetDlSrcActionBuilder(); + setDlSrcActionBuilder.setDlSrcAddress(setdlsrcaction.getAddress()); + setDlSrcCaseBuilder.setSetDlSrcAction(setDlSrcActionBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setDlSrcCaseBuilder.build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetFieldCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetFieldCase.java new file mode 100644 index 0000000000..858d45895e --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetFieldCase.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetFieldCase extends ConvertorCase { + public SalToOfSetFieldCase() { + super(SetFieldCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetFieldCase source, final ActionConvertorData data) { + final short version = data.getVersion(); + final SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); + + MatchReactor.getInstance().convert(source.getSetField(), version, setFieldBuilder); + + return Optional.of(new ActionBuilder() + .setActionChoice(new SetFieldCaseBuilder() + .setSetFieldAction(setFieldBuilder.build()) + .build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetFieldV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetFieldV10Case.java new file mode 100644 index 0000000000..510405830c --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetFieldV10Case.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetVlanVidCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.vlan.vid._case.SetVlanVidActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetFieldV10Case extends ConvertorCase { + public SalToOfSetFieldV10Case() { + super(SetFieldCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetFieldCase source, final ActionConvertorData data) { + SetVlanVidCaseBuilder setVlanVidCaseBuilder = new SetVlanVidCaseBuilder(); + + if (source.getSetField().getVlanMatch() != null) { + setVlanVidCaseBuilder.setSetVlanVidAction(new SetVlanVidActionBuilder() + .setVlanVid(source.getSetField().getVlanMatch().getVlanId().getVlanId().getValue()) + .build()); + } + + return Optional.of(new ActionBuilder() + .setActionChoice(setVlanVidCaseBuilder.build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetMplsTtlActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetMplsTtlActionCase.java new file mode 100644 index 0000000000..516388924e --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetMplsTtlActionCase.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.mpls.ttl._case.SetMplsTtlActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetMplsTtlActionCase extends ConvertorCase { + public SalToOfSetMplsTtlActionCase() { + super(SetMplsTtlActionCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetMplsTtlActionCase source, final ActionConvertorData data) { + SetMplsTtlActionBuilder setMplsTtlBuilder = new SetMplsTtlActionBuilder() + .setMplsTtl(source.getSetMplsTtlAction().getMplsTtl()); + + return Optional.of(new ActionBuilder() + .setActionChoice(new SetMplsTtlCaseBuilder() + .setSetMplsTtlAction(setMplsTtlBuilder.build()) + .build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwDstActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwDstActionCase.java new file mode 100644 index 0000000000..2dcba51103 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwDstActionCase.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import com.google.common.base.Splitter; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Dst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Dst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4DstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6DstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.dst._case.Ipv4DstBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.dst._case.Ipv6DstBuilder; + +public class SalToOfSetNwDstActionCase extends ConvertorCase { + private static final Splitter PREFIX_SPLITTER = Splitter.on('/'); + + public SalToOfSetNwDstActionCase() { + super(SetNwDstActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetNwDstActionCase source, final ActionConvertorData data) { + final ActionBuilder builder = new ActionBuilder(); + final Address address = source.getSetNwDstAction().getAddress(); + + if (address instanceof Ipv4) { + Iterable addressParts = PREFIX_SPLITTER.split(((Ipv4) address).getIpv4Address().getValue()); + Ipv4Address result = new Ipv4Address(addressParts.iterator().next()); + List matchEntriesList = new ArrayList<>(); + MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder(); + matchEntryBuilder.setOxmClass(OpenflowBasicClass.class); + matchEntryBuilder.setOxmMatchField(Ipv4Dst.class); + + Ipv4DstCaseBuilder ipv4DstCaseBuilder = new Ipv4DstCaseBuilder(); + Ipv4DstBuilder ipv4DstBuilder = new Ipv4DstBuilder(); + ipv4DstBuilder.setIpv4Address(result); + Integer prefix = IpConversionUtil.extractPrefix(result); + ipv4DstBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix)); + ipv4DstCaseBuilder.setIpv4Dst(ipv4DstBuilder.build()); + + matchEntryBuilder.setHasMask(false); + matchEntryBuilder.setMatchEntryValue(ipv4DstCaseBuilder.build()); + matchEntriesList.add(matchEntryBuilder.build()); + + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldActionBuilder = new SetFieldActionBuilder(); + setFieldActionBuilder.setMatchEntry(matchEntriesList); + setFieldCaseBuilder.setSetFieldAction(setFieldActionBuilder.build()); + builder.setActionChoice(setFieldCaseBuilder.build()); + } else if (address instanceof Ipv6) { + Iterable addressParts = PREFIX_SPLITTER.split(((Ipv6) address).getIpv6Address().getValue()); + Ipv6Address result = new Ipv6Address(addressParts.iterator().next()); + List matchEntriesList = new ArrayList<>(); + MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder(); + matchEntryBuilder.setOxmClass(OpenflowBasicClass.class); + matchEntryBuilder.setOxmMatchField(Ipv6Dst.class); + + Ipv6DstCaseBuilder ipv6DstCaseBuilder = new Ipv6DstCaseBuilder(); + Ipv6DstBuilder ipv6DstBuilder = new Ipv6DstBuilder(); + ipv6DstBuilder.setIpv6Address(result); + Integer prefix = IpConversionUtil.extractPrefix(result); + ipv6DstBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix)); + ipv6DstCaseBuilder.setIpv6Dst(ipv6DstBuilder.build()); + + matchEntryBuilder.setHasMask(false); + matchEntryBuilder.setMatchEntryValue(ipv6DstCaseBuilder.build()); + matchEntriesList.add(matchEntryBuilder.build()); + + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldActionBuilder = new SetFieldActionBuilder(); + setFieldActionBuilder.setMatchEntry(matchEntriesList); + setFieldCaseBuilder.setSetFieldAction(setFieldActionBuilder.build()); + builder.setActionChoice(setFieldCaseBuilder.build()); + } else { + throw new IllegalArgumentException("Address is not supported: " + address.getClass().getName()); + } + + return Optional.of(builder.build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwDstActionV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwDstActionV10Case.java new file mode 100644 index 0000000000..a33f8b6f8b --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwDstActionV10Case.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.dst._case.SetNwDstActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetNwDstActionV10Case extends ConvertorCase { + public SalToOfSetNwDstActionV10Case() { + super(SetNwDstActionCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetNwDstActionCase source, final ActionConvertorData data) { + final ActionBuilder builder = new ActionBuilder(); + final Address address = source.getSetNwDstAction().getAddress(); + + if (address instanceof Ipv4) { + //FIXME use of substring should be removed and OF models should distinguish where + //FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask) + + String ipAddress = ((Ipv4) address).getIpv4Address().getValue(); + ipAddress = ipAddress.substring(0, ipAddress.indexOf("/")); + Ipv4Address result = new Ipv4Address(ipAddress); + SetNwDstCaseBuilder setNwDstCaseBuilder = new SetNwDstCaseBuilder(); + SetNwDstActionBuilder setNwDstActionBuilder = new SetNwDstActionBuilder(); + setNwDstActionBuilder.setIpAddress(result); + setNwDstCaseBuilder.setSetNwDstAction(setNwDstActionBuilder.build()); + builder.setActionChoice(setNwDstCaseBuilder.build()); + } else { + throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName()); + } + + return Optional.of(builder.build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwSrcActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwSrcActionCase.java new file mode 100644 index 0000000000..d326e592b5 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwSrcActionCase.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import com.google.common.base.Splitter; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IpConversionUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Src; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4SrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv4.src._case.Ipv4SrcBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.src._case.Ipv6SrcBuilder; + +public class SalToOfSetNwSrcActionCase extends ConvertorCase { + private static final Splitter PREFIX_SPLITTER = Splitter.on('/'); + + public SalToOfSetNwSrcActionCase() { + super(SetNwSrcActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetNwSrcActionCase source, final ActionConvertorData data) { + final ActionBuilder builder = new ActionBuilder(); + final Address address = source.getSetNwSrcAction().getAddress(); + + if (address instanceof Ipv4) { + Iterable addressParts = PREFIX_SPLITTER.split(((Ipv4) address).getIpv4Address().getValue()); + Ipv4Address result = new Ipv4Address(addressParts.iterator().next()); + + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); + List entries = new ArrayList<>(); + MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder(); + matchEntryBuilder.setOxmClass(OpenflowBasicClass.class); + matchEntryBuilder.setOxmMatchField(Ipv4Src.class); + + Ipv4SrcCaseBuilder ipv4SrcCaseBuilder = new Ipv4SrcCaseBuilder(); + Ipv4SrcBuilder ipv4SrcBuilder = new Ipv4SrcBuilder(); + ipv4SrcBuilder.setIpv4Address(result); + Integer prefix = IpConversionUtil.extractPrefix(result); + ipv4SrcBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix)); + ipv4SrcCaseBuilder.setIpv4Src(ipv4SrcBuilder.build()); + + matchEntryBuilder.setHasMask(false); + matchEntryBuilder.setMatchEntryValue(ipv4SrcCaseBuilder.build()); + entries.add(matchEntryBuilder.build()); + setFieldBuilder.setMatchEntry(entries); + setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); + builder.setActionChoice(setFieldCaseBuilder.build()); + } else if (address instanceof Ipv6) { + Iterable addressParts = PREFIX_SPLITTER.split(((Ipv6) address).getIpv6Address().getValue()); + Ipv6Address result = new Ipv6Address(addressParts.iterator().next()); + + List matchEntriesList = new ArrayList<>(); + MatchEntryBuilder matchEntryBuilder = new MatchEntryBuilder(); + matchEntryBuilder.setOxmClass(OpenflowBasicClass.class); + matchEntryBuilder.setOxmMatchField(Ipv6Src.class); + + Ipv6SrcCaseBuilder ipv6SrcCaseBuilder = new Ipv6SrcCaseBuilder(); + Ipv6SrcBuilder ipv6SrcBuilder = new Ipv6SrcBuilder(); + ipv6SrcBuilder.setIpv6Address(result); + Integer prefix = IpConversionUtil.extractPrefix(result); + ipv6SrcBuilder.setMask(IpConversionUtil.convertIpv6PrefixToByteArray(prefix)); + ipv6SrcCaseBuilder.setIpv6Src(ipv6SrcBuilder.build()); + + matchEntryBuilder.setHasMask(false); + matchEntryBuilder.setMatchEntryValue(ipv6SrcCaseBuilder.build()); + matchEntriesList.add(matchEntryBuilder.build()); + + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldActionBuilder = new SetFieldActionBuilder(); + setFieldActionBuilder.setMatchEntry(matchEntriesList); + setFieldCaseBuilder.setSetFieldAction(setFieldActionBuilder.build()); + builder.setActionChoice(setFieldCaseBuilder.build()); + } else { + throw new IllegalArgumentException("Address is not supported: " + address.getClass().getName()); + } + + return Optional.of(builder.build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwSrcActionV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwSrcActionV10Case.java new file mode 100644 index 0000000000..a4523dfad4 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwSrcActionV10Case.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwSrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.src._case.SetNwSrcActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetNwSrcActionV10Case extends ConvertorCase { + public SalToOfSetNwSrcActionV10Case() { + super(SetNwSrcActionCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetNwSrcActionCase source, final ActionConvertorData data) { + final ActionBuilder builder = new ActionBuilder(); + final Address address = source.getSetNwSrcAction().getAddress(); + + if (address instanceof Ipv4) { + //FIXME use of substring should be removed and OF models should distinguish where + //FIXME to use Ipv4Prefix (with mask) and where to use Ipv4Address (without mask) + + String ipAddress = ((Ipv4) address).getIpv4Address().getValue(); + ipAddress = ipAddress.substring(0, ipAddress.indexOf("/")); + Ipv4Address result = new Ipv4Address(ipAddress); + SetNwSrcCaseBuilder nwSrcCaseBuilder = new SetNwSrcCaseBuilder(); + SetNwSrcActionBuilder nwSrcBuilder = new SetNwSrcActionBuilder(); + nwSrcBuilder.setIpAddress(new Ipv4Address(result)); + nwSrcCaseBuilder.setSetNwSrcAction(nwSrcBuilder.build()); + builder.setActionChoice(nwSrcCaseBuilder.build()); + } else { + throw new IllegalArgumentException("Address is not supported by OF-1.0: " + address.getClass().getName()); + } + + return Optional.of(builder.build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwTosActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwTosActionCase.java new file mode 100644 index 0000000000..02f2e0a33b --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwTosActionCase.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil; +import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; + +public class SalToOfSetNwTosActionCase extends ConvertorCase { + public SalToOfSetNwTosActionCase() { + super(SetNwTosActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetNwTosActionCase source, final ActionConvertorData data) { + SetNwTosAction setnwtosaction = source.getSetNwTosAction(); + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); + + List entries = new ArrayList<>(); + entries.add(MatchConvertorUtil.toOfIpDscp(new Dscp( + ActionUtil.tosToDscp(setnwtosaction.getTos().shortValue()) + ))); + setFieldBuilder.setMatchEntry(entries); + setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setFieldCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwTosActionV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwTosActionV10Case.java new file mode 100644 index 0000000000..21b7a3e9a8 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwTosActionV10Case.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTosCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.tos._case.SetNwTosActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetNwTosActionV10Case extends ConvertorCase { + public SalToOfSetNwTosActionV10Case() { + super(SetNwTosActionCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetNwTosActionCase source, final ActionConvertorData data) { + SetNwTosAction setnwtosaction = source.getSetNwTosAction(); + SetNwTosActionBuilder setNwTosActionBuilder = new SetNwTosActionBuilder(); + SetNwTosCaseBuilder setNwTosCaseBuilder = new SetNwTosCaseBuilder(); + setNwTosActionBuilder.setNwTos(setnwtosaction.getTos().shortValue()); + setNwTosCaseBuilder.setSetNwTosAction(setNwTosActionBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setNwTosCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwTtlActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwTtlActionCase.java new file mode 100644 index 0000000000..3a51f5e367 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetNwTtlActionCase.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.nw.ttl._case.SetNwTtlActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetNwTtlActionCase extends ConvertorCase { + public SalToOfSetNwTtlActionCase() { + super(SetNwTtlActionCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetNwTtlActionCase source, final ActionConvertorData data) { + SetNwTtlCaseBuilder nwTtlCaseBuilder = new SetNwTtlCaseBuilder(); + SetNwTtlActionBuilder nwTtlBuilder = new SetNwTtlActionBuilder(); + nwTtlBuilder.setNwTtl(source.getSetNwTtlAction().getNwTtl()); + nwTtlCaseBuilder.setSetNwTtlAction(nwTtlBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(nwTtlCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetQueueActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetQueueActionCase.java new file mode 100644 index 0000000000..a9db724f91 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetQueueActionCase.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.queue._case.SetQueueActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetQueueActionCase extends ConvertorCase { + public SalToOfSetQueueActionCase() { + super(SetQueueActionCase.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetQueueActionCase source, final ActionConvertorData data) { + SetQueueAction setQueueAction = source.getSetQueueAction(); + SetQueueCaseBuilder setQueueCaseBuilder = new SetQueueCaseBuilder(); + SetQueueActionBuilder setQueueBuilder = new SetQueueActionBuilder(); + setQueueBuilder.setQueueId(setQueueAction.getQueueId()); + setQueueCaseBuilder.setSetQueueAction(setQueueBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setQueueCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpDstActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpDstActionCase.java new file mode 100644 index 0000000000..1995ebe75c --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpDstActionCase.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IPProtocols; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv4Code; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv6Code; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.UdpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4CodeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv6CodeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpDstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpDstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.code._case.Icmpv4CodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv6.code._case.Icmpv6CodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.dst._case.TcpDstBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.dst._case.UdpDstBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SalToOfSetTpDstActionCase extends ConvertorCase { + private static final Logger LOG = LoggerFactory.getLogger(SalToOfSetTpDstActionCase.class); + + public SalToOfSetTpDstActionCase() { + super(SetTpDstActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetTpDstActionCase source, final ActionConvertorData data) { + IPProtocols protocol = null; + + if (data.getIpProtocol() != null) { + protocol = IPProtocols.fromProtocolNum(data.getIpProtocol()); + } + + SetTpDstAction settpdstaction = source.getSetTpDstAction(); + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); + + MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); + matchBuilder.setOxmClass(OpenflowBasicClass.class); + matchBuilder.setHasMask(false); + int port = settpdstaction.getPort().getValue(); + int code = 0xff & port; + + if (protocol != null) { + switch (protocol) { + case ICMP: + matchBuilder.setOxmMatchField(Icmpv4Code.class); + Icmpv4CodeCaseBuilder icmpv4CodeCaseBuilder = new Icmpv4CodeCaseBuilder(); + Icmpv4CodeBuilder icmpv4CodeBuilder = new Icmpv4CodeBuilder(); + icmpv4CodeBuilder.setIcmpv4Code((short) code); + icmpv4CodeCaseBuilder.setIcmpv4Code(icmpv4CodeBuilder.build()); + matchBuilder.setMatchEntryValue(icmpv4CodeCaseBuilder.build()); + break; + case ICMPV6: + matchBuilder.setOxmMatchField(Icmpv6Code.class); + Icmpv6CodeCaseBuilder icmpv6CodeCaseBuilder = new Icmpv6CodeCaseBuilder(); + Icmpv6CodeBuilder icmpv6CodeBuilder = new Icmpv6CodeBuilder(); + icmpv6CodeBuilder.setIcmpv6Code((short) code); + icmpv6CodeCaseBuilder.setIcmpv6Code(icmpv6CodeBuilder.build()); + matchBuilder.setMatchEntryValue(icmpv6CodeCaseBuilder.build()); + break; + case TCP: + matchBuilder.setOxmMatchField(TcpDst.class); + TcpDstCaseBuilder tcpDstCaseBuilder = new TcpDstCaseBuilder(); + TcpDstBuilder tcpDstBuilder = new TcpDstBuilder(); + tcpDstBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(port)); + tcpDstCaseBuilder.setTcpDst(tcpDstBuilder.build()); + matchBuilder.setMatchEntryValue(tcpDstCaseBuilder.build()); + break; + case UDP: + matchBuilder.setOxmMatchField(UdpDst.class); + UdpDstCaseBuilder udpDstCaseBuilder = new UdpDstCaseBuilder(); + UdpDstBuilder udpDstBuilder = new UdpDstBuilder(); + udpDstBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(port)); + udpDstCaseBuilder.setUdpDst(udpDstBuilder.build()); + matchBuilder.setMatchEntryValue(udpDstCaseBuilder.build()); + break; + default: + LOG.warn("Unknown protocol with combination of SetSourcePort: {}", protocol); + break; + } + } else { + LOG.warn("Missing protocol with combination of SetSourcePort"); + } + + List entries = new ArrayList<>(); + entries.add(matchBuilder.build()); + setFieldBuilder.setMatchEntry(entries); + setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setFieldCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpDstActionV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpDstActionV10Case.java new file mode 100644 index 0000000000..e762a0433c --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpDstActionV10Case.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetTpDstCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.tp.dst._case.SetTpDstActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; + +public class SalToOfSetTpDstActionV10Case extends ConvertorCase { + public SalToOfSetTpDstActionV10Case() { + super(SetTpDstActionCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetTpDstActionCase source, final ActionConvertorData data) { + SetTpDstAction settpdstaction = source.getSetTpDstAction(); + SetTpDstCaseBuilder setTpDstCaseBuilder = new SetTpDstCaseBuilder(); + SetTpDstActionBuilder setTpDstActionBuilder = new SetTpDstActionBuilder(); + setTpDstActionBuilder.setPort(new PortNumber(settpdstaction.getPort().getValue().longValue())); + setTpDstCaseBuilder.setSetTpDstAction(setTpDstActionBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setTpDstCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpSrcActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpSrcActionCase.java new file mode 100644 index 0000000000..641df7d3db --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpSrcActionCase.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.IPProtocols; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv4Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Icmpv6Type; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.TcpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.UdpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv4TypeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Icmpv6TypeCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.TcpSrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.UdpSrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv4.type._case.Icmpv4TypeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.icmpv6.type._case.Icmpv6TypeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.tcp.src._case.TcpSrcBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.udp.src._case.UdpSrcBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SalToOfSetTpSrcActionCase extends ConvertorCase { + private static final Logger LOG = LoggerFactory.getLogger(SalToOfSetTpSrcActionCase.class); + + public SalToOfSetTpSrcActionCase() { + super(SetTpSrcActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetTpSrcActionCase source, final ActionConvertorData data) { + IPProtocols protocol = null; + + if (data.getIpProtocol() != null) { + protocol = IPProtocols.fromProtocolNum(data.getIpProtocol()); + } + + SetTpSrcAction settpsrcaction = source.getSetTpSrcAction(); + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); + + MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); + matchBuilder.setOxmClass(OpenflowBasicClass.class); + matchBuilder.setHasMask(false); + + int port = settpsrcaction.getPort().getValue(); + int type = 0xff & port; + + if (protocol != null) { + switch (protocol) { + case ICMP: + matchBuilder.setOxmMatchField(Icmpv4Type.class); + Icmpv4TypeCaseBuilder icmpv4TypeCaseBuilder = new Icmpv4TypeCaseBuilder(); + Icmpv4TypeBuilder icmpv4TypeBuilder = new Icmpv4TypeBuilder(); + icmpv4TypeBuilder.setIcmpv4Type((short) type); + icmpv4TypeCaseBuilder.setIcmpv4Type(icmpv4TypeBuilder.build()); + matchBuilder.setMatchEntryValue(icmpv4TypeCaseBuilder.build()); + break; + case ICMPV6: + matchBuilder.setOxmMatchField(Icmpv6Type.class); + Icmpv6TypeCaseBuilder icmpv6TypeCaseBuilder = new Icmpv6TypeCaseBuilder(); + Icmpv6TypeBuilder icmpv6TypeBuilder = new Icmpv6TypeBuilder(); + icmpv6TypeBuilder.setIcmpv6Type((short) type); + icmpv6TypeCaseBuilder.setIcmpv6Type(icmpv6TypeBuilder.build()); + matchBuilder.setMatchEntryValue(icmpv6TypeCaseBuilder.build()); + break; + case TCP: + matchBuilder.setOxmMatchField(TcpSrc.class); + TcpSrcCaseBuilder tcpSrcCaseBuilder = new TcpSrcCaseBuilder(); + TcpSrcBuilder tcpSrcBuilder = new TcpSrcBuilder(); + tcpSrcBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(port)); + tcpSrcCaseBuilder.setTcpSrc(tcpSrcBuilder.build()); + matchBuilder.setMatchEntryValue(tcpSrcCaseBuilder.build()); + break; + case UDP: + matchBuilder.setOxmMatchField(UdpSrc.class); + UdpSrcCaseBuilder udpSrcCaseBuilder = new UdpSrcCaseBuilder(); + UdpSrcBuilder udpSrcBuilder = new UdpSrcBuilder(); + udpSrcBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(port)); + udpSrcCaseBuilder.setUdpSrc(udpSrcBuilder.build()); + matchBuilder.setMatchEntryValue(udpSrcCaseBuilder.build()); + break; + default: + LOG.warn("Unknown protocol with combination of SetSourcePort: {}", protocol); + break; + } + } else { + LOG.warn("Null protocol with combination of SetSourcePort"); + } + + List entries = new ArrayList<>(); + entries.add(matchBuilder.build()); + setFieldBuilder.setMatchEntry(entries); + setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setFieldCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpSrcActionV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpSrcActionV10Case.java new file mode 100644 index 0000000000..2b455c8449 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetTpSrcActionV10Case.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetTpSrcCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.tp.src._case.SetTpSrcActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SalToOfSetTpSrcActionV10Case extends ConvertorCase { + private static final Logger LOG = LoggerFactory.getLogger(SalToOfSetTpSrcActionV10Case.class); + + public SalToOfSetTpSrcActionV10Case() { + super(SetTpSrcActionCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetTpSrcActionCase source, final ActionConvertorData data) { + SetTpSrcAction settpsrcaction = source.getSetTpSrcAction(); + SetTpSrcCaseBuilder setTpSrcCaseBuilder = new SetTpSrcCaseBuilder(); + SetTpSrcActionBuilder setTpSrcActionBuilder = new SetTpSrcActionBuilder(); + setTpSrcActionBuilder.setPort(new PortNumber(settpsrcaction.getPort() + .getValue() + .longValue())); + setTpSrcCaseBuilder.setSetTpSrcAction(setTpSrcActionBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setTpSrcCaseBuilder.build()) + .build()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanIdActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanIdActionCase.java new file mode 100644 index 0000000000..3722293f56 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanIdActionCase.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase; +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.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanVid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanVidCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.vid._case.VlanVidBuilder; + +public class SalToOfSetVlanIdActionCase extends ConvertorCase { + public SalToOfSetVlanIdActionCase() { + super(SetVlanIdActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetVlanIdActionCase source, final ActionConvertorData data) { + SetVlanIdAction setvlanidaction = source.getSetVlanIdAction(); + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); + List entries = new ArrayList<>(); + MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); + matchBuilder.setOxmClass(OpenflowBasicClass.class); + matchBuilder.setOxmMatchField(VlanVid.class); + matchBuilder.setHasMask(false); + VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder(); + VlanVidBuilder vlanVidBuilder = new VlanVidBuilder(); + vlanVidBuilder.setCfiBit(true); + vlanVidBuilder.setVlanVid(setvlanidaction.getVlanId().getValue()); + vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build()); + matchBuilder.setMatchEntryValue(vlanVidCaseBuilder.build()); + entries.add(matchBuilder.build()); + setFieldBuilder.setMatchEntry(entries); + setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setFieldCaseBuilder.build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanIdActionV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanIdActionV10Case.java new file mode 100644 index 0000000000..0f2543b4af --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanIdActionV10Case.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase; +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.openflow.common.action.rev150203.action.grouping.action.choice.SetVlanVidCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.vlan.vid._case.SetVlanVidActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetVlanIdActionV10Case extends ConvertorCase { + public SalToOfSetVlanIdActionV10Case() { + super(SetVlanIdActionCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetVlanIdActionCase source, final ActionConvertorData data) { + SetVlanIdAction setvlanidaction = source.getSetVlanIdAction(); + SetVlanVidActionBuilder vlanidActionBuilder = new SetVlanVidActionBuilder(); + SetVlanVidCaseBuilder setVlanVidCaseBuilder = new SetVlanVidCaseBuilder(); + vlanidActionBuilder.setVlanVid(setvlanidaction.getVlanId().getValue()); + setVlanVidCaseBuilder.setSetVlanVidAction(vlanidActionBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setVlanVidCaseBuilder.build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanPcpActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanPcpActionCase.java new file mode 100644 index 0000000000..798f6ebbc7 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanPcpActionCase.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase; +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.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; + +public class SalToOfSetVlanPcpActionCase extends ConvertorCase { + public SalToOfSetVlanPcpActionCase() { + super(SetVlanPcpActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetVlanPcpActionCase source, final ActionConvertorData data) { + SetVlanPcpAction setvlanpcpaction = source.getSetVlanPcpAction(); + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); + + List matchEntriesList = new ArrayList<>(); + matchEntriesList.add(MatchConvertorUtil.toOfVlanPcp(setvlanpcpaction.getVlanPcp())); + setFieldBuilder.setMatchEntry(matchEntriesList); + setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setFieldCaseBuilder.build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanPcpActionV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanPcpActionV10Case.java new file mode 100644 index 0000000000..6c2babb89d --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfSetVlanPcpActionV10Case.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase; +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.openflow.common.action.rev150203.action.grouping.action.choice.SetVlanPcpCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.vlan.pcp._case.SetVlanPcpActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfSetVlanPcpActionV10Case extends ConvertorCase { + public SalToOfSetVlanPcpActionV10Case() { + super(SetVlanPcpActionCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final SetVlanPcpActionCase source, final ActionConvertorData data) { + SetVlanPcpAction setvlanpcpaction = source.getSetVlanPcpAction(); + SetVlanPcpActionBuilder setVlanPcpActionBuilder = new SetVlanPcpActionBuilder(); + SetVlanPcpCaseBuilder setVlanPcpCaseBuilder = new SetVlanPcpCaseBuilder(); + setVlanPcpActionBuilder.setVlanPcp(setvlanpcpaction.getVlanPcp().getValue()); + setVlanPcpCaseBuilder.setSetVlanPcpAction(setVlanPcpActionBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setVlanPcpCaseBuilder.build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfStripVlanActionCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfStripVlanActionCase.java new file mode 100644 index 0000000000..30ccb2e35c --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfStripVlanActionCase.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.set.field._case.SetFieldActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.VlanVid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.VlanVidCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.vlan.vid._case.VlanVidBuilder; + +public class SalToOfStripVlanActionCase extends ConvertorCase { + public SalToOfStripVlanActionCase() { + super(StripVlanActionCase.class, true, OFConstants.OFP_VERSION_1_3); + } + + @Nonnull + @Override + public Optional process(@Nonnull final StripVlanActionCase source, final ActionConvertorData data) { + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder(); + List entries = new ArrayList<>(); + MatchEntryBuilder matchBuilder = new MatchEntryBuilder(); + matchBuilder.setOxmClass(OpenflowBasicClass.class); + matchBuilder.setOxmMatchField(VlanVid.class); + matchBuilder.setHasMask(false); + VlanVidCaseBuilder vlanVidCaseBuilder = new VlanVidCaseBuilder(); + VlanVidBuilder vlanVidBuilder = new VlanVidBuilder(); + vlanVidBuilder.setCfiBit(true); + vlanVidBuilder.setVlanVid(0x0000); + vlanVidCaseBuilder.setVlanVid(vlanVidBuilder.build()); + matchBuilder.setMatchEntryValue(vlanVidCaseBuilder.build()); + matchBuilder.setHasMask(false); + entries.add(matchBuilder.build()); + setFieldBuilder.setMatchEntry(entries); + setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build()); + + return Optional.of(new ActionBuilder() + .setActionChoice(setFieldCaseBuilder.build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfStripVlanActionV10Case.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfStripVlanActionV10Case.java new file mode 100644 index 0000000000..026efbfe68 --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfStripVlanActionV10Case.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.StripVlanCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; + +public class SalToOfStripVlanActionV10Case extends ConvertorCase { + public SalToOfStripVlanActionV10Case() { + super(StripVlanActionCase.class, true, OFConstants.OFP_VERSION_1_0); + } + + @Nonnull + @Override + public Optional process(@Nonnull final StripVlanActionCase source, final ActionConvertorData data) { + return Optional.of(new ActionBuilder() + .setActionChoice(new StripVlanCaseBuilder().build()) + .build()); + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfVendorCodecCase.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfVendorCodecCase.java new file mode 100644 index 0000000000..81d68e3ceb --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/cases/SalToOfVendorCodecCase.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.cases; + +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava; +import org.opendaylight.openflowplugin.extension.api.TypeVersionKey; +import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorCase; +import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SalToOfVendorCodecCase extends ConvertorCase { + private static final Logger LOG = LoggerFactory.getLogger(SalToOfVendorCodecCase.class); + + public SalToOfVendorCodecCase() { + super(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action.class, true, OFConstants.OFP_VERSION_1_0, OFConstants.OFP_VERSION_1_3); + } + + @SuppressWarnings("unchecked") + @Nonnull + @Override + public Optional process(@Nonnull final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action source, final ActionConvertorData data) { + final short version = data.getVersion(); + final TypeVersionKey key = + new TypeVersionKey<>( + (Class) source.getImplementedInterface(), + version); + + ExtensionConverterProvider extensionConverterProvider = OFSessionUtil.getExtensionConvertorProvider(); + + if (extensionConverterProvider == null) { + return Optional.empty(); + } + + final ConvertorActionToOFJava convertor = + extensionConverterProvider.getConverter(key); + + LOG.trace("OFP Extension action, key:{}, converter:{}", key, convertor); + return convertor != null ? Optional.of(convertor.convert(source)) : Optional.empty(); + } +} \ No newline at end of file diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/data/ActionConvertorData.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/data/ActionConvertorData.java new file mode 100644 index 0000000000..493bd2c61c --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/data/ActionConvertorData.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.data; + +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionDatapathIdConvertorData; + +/** + * Convertor data used in {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionConvertor} + * containing Openflow version, datapath ID and IP protocol from flow + */ +public class ActionConvertorData extends VersionDatapathIdConvertorData { + private Short ipProtocol; + + /** + * Instantiates a new Action convertor data. + * + * @param version the version + */ + public ActionConvertorData(short version) { + super(version); + } + + /** + * Gets ip protocol. + * + * @return the ip protocol + */ + public Short getIpProtocol() { + return ipProtocol; + } + + /** + * Sets ip protocol. + * + * @param ipProtocol the ip protocol + */ + public void setIpProtocol(Short ipProtocol) { + this.ipProtocol = ipProtocol; + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/data/ActionResponseConvertorData.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/data/ActionResponseConvertorData.java new file mode 100644 index 0000000000..0b0d5b885f --- /dev/null +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/data/ActionResponseConvertorData.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action.data; + +import org.opendaylight.openflowplugin.extension.api.path.ActionPath; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorData; + +/** + * Convertor data used in {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionResponseConvertor} + * containing Openflow version and {@link org.opendaylight.openflowplugin.extension.api.path.ActionPath} + */ +public class ActionResponseConvertorData extends ConvertorData { + private ActionPath actionPath; + + /** + * Instantiates a new Action response convertor data. + * + * @param version the version + */ + public ActionResponseConvertorData(short version) { + super(version); + } + + /** + * Gets action path. + * + * @return the action path + */ + public ActionPath getActionPath() { + return actionPath; + } + + /** + * Sets action path. + * + * @param actionPath the action path + */ + public void setActionPath(ActionPath actionPath) { + this.actionPath = actionPath; + } +} diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/InjectionResultTargetKey.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/InjectionResultTargetKey.java deleted file mode 100644 index 7d1e8adfbe..0000000000 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/common/InjectionResultTargetKey.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (c) 2014 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.common; - -import com.google.common.base.MoreObjects.ToStringHelper; -import com.google.common.base.Preconditions; - -/** - * - */ -public class InjectionResultTargetKey extends InjectionKey { - - private final Class resultClazz; - - /** - * @param version openflow version - * @param targetClazz target class - * @param resultClazz result class - */ - public InjectionResultTargetKey(final int version, final Class targetClazz, final Class resultClazz) { - super(version, targetClazz); - this.resultClazz = Preconditions.checkNotNull(resultClazz); - } - - @Override - public int hashCode() { - return super.hashCode() ^ resultClazz.hashCode(); - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - final InjectionResultTargetKey other = (InjectionResultTargetKey) obj; - return resultClazz.equals(other.resultClazz); - } - - @Override - protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { - return super.addToStringAttributes(toStringHelper).add("resultClazz", resultClazz); - } -} diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertorTest.java index e9cccd8f7f..c5ef62043e 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/PacketOutConvertorTest.java @@ -10,13 +10,16 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Optional; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil; import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; @@ -173,9 +176,14 @@ public class PacketOutConvertorTest { Assert.assertEquals((Object) version, Short.valueOf(message.getVersion())); Assert.assertEquals(xid, message.getXid()); - Assert.assertEquals( - ActionConvertor.getActions(actionList, version, datapathId, null), - message.getAction()); + ActionConvertorData actionConvertorData = new ActionConvertorData(version); + actionConvertorData.setDatapathId(datapathId); + + Optional> actionsOptional = ConvertorManager.getInstance().convert( + actionList, actionConvertorData); + + List actions = actionsOptional.orElse(Collections.emptyList()); + Assert.assertEquals(actions, message.getAction()); Assert.assertArrayEquals(transmitPacketInput.getPayload(), message.getData()); } diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorTest.java similarity index 50% rename from openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertorTest.java rename to openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorTest.java index a6da6dfb35..73ef034c00 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertorTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorTest.java @@ -5,22 +5,25 @@ * 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.openflowplugin.openflow.md.core.sal.convertor; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Optional; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DropActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder; @@ -31,10 +34,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder; @@ -51,17 +50,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.OutputPortValues; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; @@ -72,28 +64,15 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.GroupCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopMplsCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopVlanCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushPbbCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwSrcCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Dst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv4Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Dst; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.Ipv6Src; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4DstCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv4SrcCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6DstCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCase; /** * test for {@link ActionConvertor} @@ -124,9 +103,15 @@ public class ActionConvertorTest { pbbActionData(); setFieldData(); setExperimenterData(); - List OFActionsList = ActionConvertor.getActions(actions, (short) 0X4, BigInteger.ONE, null); + dropActionData(); - outputActions(OFActionsList); + ActionConvertorData data = new ActionConvertorData((short) 0X4); + data.setDatapathId(BigInteger.ONE); + + Optional> OFActionsList = + ConvertorManager.getInstance().convert(actions, data); + + outputActions(OFActionsList.orElse(Collections.emptyList())); } @@ -136,11 +121,17 @@ public class ActionConvertorTest { } - private void setFieldData() { + private void dropActionData() { + ActionBuilder AB = new ActionBuilder(); + AB.setOrder(actionItem).setAction(new DropActionCaseBuilder().build()); - SetFieldBuilder setFA = new SetFieldBuilder(); + actions.add(actionItem++, AB.build()); + + } + + private void setFieldData() { - SetFieldBuilder matchBuilder = setFA; + SetFieldBuilder matchBuilder = new SetFieldBuilder(); matchBuilder.setInPort(new NodeConnectorId("openflow:1:2125")); @@ -206,10 +197,7 @@ public class ActionConvertorTest { private static void outputActions(final List oFActionsList) { - for (int item = 0; item < oFActionsList.size(); item++) { - - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action = oFActionsList - .get(item); + for (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action : oFActionsList) { if (action.getActionChoice() instanceof OutputActionCase) { OutputActionCase outputActionCase = (OutputActionCase) action.getActionChoice(); @@ -356,7 +344,7 @@ public class ActionConvertorTest { ActionBuilder AB = new ActionBuilder(); AB.setOrder(actionItem).setAction(new DecMplsTtlCaseBuilder().setDecMplsTtl(decMplsTtlB.build()).build()); - actions.add(actionItem++, AB1.build()); + actions.add(actionItem++, AB.build()); } private void vlanActionData() { @@ -397,24 +385,6 @@ public class ActionConvertorTest { actions.add(actionItem++, AB1.build()); } - /** - * testing {@link ActionConvertor#ofToSALPushMplsAction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)} - * with OF-1.3, IPv6 - */ - @Test - public void testOFtoSALPushMplsAction() { - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder - = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder(); - PushMplsCaseBuilder pushMplsCaseBuilder = new PushMplsCaseBuilder(); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsActionBuilder pushMplsBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsActionBuilder(); - pushMplsBuilder.setEthertype(new EtherType(new Integer(34888))); - pushMplsCaseBuilder.setPushMplsAction(pushMplsBuilder.build()); - actionBuilder.setActionChoice(pushMplsCaseBuilder.build()); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action = actionBuilder.build(); - Assert.assertEquals(34888, ActionConvertor.ofToSALPushMplsAction(action).getPushMplsAction().getEthernetType().intValue()); - } - private void setQueueActionData() { SetQueueActionBuilder setQB = new SetQueueActionBuilder(); @@ -427,199 +397,4 @@ public class ActionConvertorTest { } - /** - * testing {@link ActionConvertor#salToOFSetNwDst(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)} - * with OF-1.0, IPv4 - */ - @Test - public void testSalToOFSetNwDst10v4() { - short version = 1; - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder(); - Address address; - address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build(); - SetNwDstActionCase action = provisionNwDstActionBuilder(address); - ActionConvertor.salToOFSetNwDst(action, actionBuilder, version); - Assert.assertEquals(SetNwDstCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName()); - SetNwDstCase setNwDstCase = (SetNwDstCase) actionBuilder.getActionChoice(); - Assert.assertEquals("10.0.0.1", setNwDstCase.getSetNwDstAction().getIpAddress().getValue()); - } - - /** - * testing {@link ActionConvertor#salToOFSetNwDst(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)} - * with OF-1.0, IPv6 - */ - @Test - public void testSalToOFSetNwDst10v6() { - short version = 1; - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder(); - Address address; - /* Use canonical form - no leading zeroes!!! */ - address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build(); - SetNwDstActionCase action = provisionNwDstActionBuilder(address); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action ofAction = ActionConvertor.salToOFSetNwDst(action, actionBuilder, version); - Assert.assertNull(ofAction); - } - - - /** - * testing {@link ActionConvertor#salToOFSetNwDst(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)} - * with OF-1.3, IPv4 - */ - @Test - public void testSalToOFSetNwDst13v4() { - short version = 4; - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder(); - Address address; - address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build(); - SetNwDstActionCase action = provisionNwDstActionBuilder(address); - ActionConvertor.salToOFSetNwDst(action, actionBuilder, version); - Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName()); - SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice(); - MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0); - Assert.assertEquals(Ipv4Dst.class.getName(), matchEntry.getOxmMatchField().getName()); - Ipv4DstCase ipv4DstCase = ((Ipv4DstCase) matchEntry.getMatchEntryValue()); - Assert.assertEquals("10.0.0.1", ipv4DstCase.getIpv4Dst().getIpv4Address().getValue()); - } - - - /** - * testing {@link ActionConvertor#salToOFSetNwDst(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)} - * with OF-1.3, IPv6 - */ - @Test - public void testSalToOFSetNwDst13v6() { - short version = 4; - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder(); - Address address; - /* Use canonical form - no leading zeroes and a prefix, even if the prefix is /128 !!! */ - address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build(); - SetNwDstActionCase action = provisionNwDstActionBuilder(address); - ActionConvertor.salToOFSetNwDst(action, actionBuilder, version); - Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName()); - SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice(); - MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0); - Assert.assertEquals(Ipv6Dst.class.getName(), matchEntry.getOxmMatchField().getName()); - Ipv6DstCase ipv6DstCase = ((Ipv6DstCase) matchEntry.getMatchEntryValue()); - /* We check the IP only, the netmask should have gone into the wildcard field */ - Assert.assertEquals("2001:db8:85a3:42:1000:8a2e:370:7334", ipv6DstCase.getIpv6Dst().getIpv6Address().getValue()); - } - - - /** - * testing {@link ActionConvertor#salToOFSetNwSrc(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)} - * with OF-1.0, IPv4 - */ - @Test - public void testSalToOFSetNwSrc10v4() { - short version = 1; - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder(); - Address address; - address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build(); - SetNwSrcActionCase action = provisionNwSrcActionBuilder(address); - ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version); - Assert.assertEquals(SetNwSrcCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName()); - SetNwSrcCase setNwSrcCase = (SetNwSrcCase) actionBuilder.getActionChoice(); - Assert.assertEquals("10.0.0.1", setNwSrcCase.getSetNwSrcAction().getIpAddress().getValue()); - } - - /** - * testing {@link ActionConvertor#salToOFSetNwSrc(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)} - * with OF-1.0, IPv6 - */ - @Test - public void testSalToOFSetNwSrc10v6() { - short version = 1; - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder(); - Address address; - /* Use canonical form - no leading zeroes and a prefix, even if the prefix is /128 !!! */ - address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build(); - SetNwSrcActionCase action = provisionNwSrcActionBuilder(address); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action ofAction = ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version); - Assert.assertNull(ofAction); - } - - /** - * testing {@link ActionConvertor#salToOFSetNwSrc(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)} - * with OF-1.3, IPv4 - */ - @Test - public void testSalToOFSetNwSrc13v4() { - short version = 4; - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder(); - Address address; - address = new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.0.1/32")).build(); - SetNwSrcActionCase action = provisionNwSrcActionBuilder(address); - ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version); - Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName()); - SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice(); - MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0); - Assert.assertEquals(Ipv4Src.class, matchEntry.getOxmMatchField()); - Ipv4SrcCase ipv4SrcCase = ((Ipv4SrcCase) matchEntry.getMatchEntryValue()); - Assert.assertEquals("10.0.0.1", ipv4SrcCase.getIpv4Src().getIpv4Address().getValue()); - } - - /** - * testing {@link ActionConvertor#salToOFSetNwSrc(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder, short)} - * with OF-1.3, IPv6 - */ - @Test - public void testSalToOFSetNwSrc13v6() { - short version = 4; - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder(); - Address address; - /* Use canonical form - no leading zeroes and a prefix, even if the prefix is /128 !!! */ - address = new Ipv6Builder().setIpv6Address(new Ipv6Prefix("2001:db8:85a3:42:1000:8a2e:370:7334/128")).build(); - SetNwSrcActionCase action = provisionNwSrcActionBuilder(address); - ActionConvertor.salToOFSetNwSrc(action, actionBuilder, version); - Assert.assertEquals(SetFieldCase.class.getName(), actionBuilder.getActionChoice().getImplementedInterface().getName()); - SetFieldCase setFieldCase = (SetFieldCase) actionBuilder.getActionChoice(); - MatchEntry matchEntry = setFieldCase.getSetFieldAction().getMatchEntry().get(0); - Ipv6SrcCase ipv6SrcCase = ((Ipv6SrcCase) matchEntry.getMatchEntryValue()); - Assert.assertEquals(Ipv6Src.class.getName(), matchEntry.getOxmMatchField().getName()); - /* We check the IP only, the netmask should have gone into the wildcard field */ - Assert.assertEquals("2001:db8:85a3:42:1000:8a2e:370:7334", ipv6SrcCase.getIpv6Src().getIpv6Address().getValue()); - } - - /** - * testing {@link ActionConvertor#ofToSALPopMplsAction(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action)} - * with OF-1.3, IPv6 - */ - @Test - public void testOFtoSALPopMplsAction() { - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder actionBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder(); - PopMplsCaseBuilder popMplsCaseBuilder = new PopMplsCaseBuilder(); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.pop.mpls._case.PopMplsActionBuilder popMplsBuilder = - new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.pop.mpls._case.PopMplsActionBuilder(); - popMplsBuilder.setEthertype(new EtherType(new EtherType(34888))); - popMplsCaseBuilder.setPopMplsAction(popMplsBuilder.build()); - actionBuilder.setActionChoice(popMplsCaseBuilder.build()); - org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action = actionBuilder.build(); - Assert.assertEquals(34888, ActionConvertor.ofToSALPopMplsAction(action).getPopMplsAction().getEthernetType().intValue()); - } - - private static SetNwDstActionCase provisionNwDstActionBuilder(final Address address) { - SetNwDstAction nwDstAction = new SetNwDstActionBuilder().setAddress(address).build(); - SetNwDstActionCase action = new SetNwDstActionCaseBuilder() - .setSetNwDstAction(nwDstAction) - .build(); - return action; - } - - private static SetNwSrcActionCase provisionNwSrcActionBuilder(final Address address) { - SetNwSrcAction nwSrcAction = new SetNwSrcActionBuilder().setAddress(address).build(); - SetNwSrcActionCase action = new SetNwSrcActionCaseBuilder() - .setSetNwSrcAction(nwSrcAction) - .build(); - return action; - } - } diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertorV10Test.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV10Test.java similarity index 78% rename from openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertorV10Test.java rename to openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV10Test.java index ca2d589d09..6ebb124839 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertorV10Test.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV10Test.java @@ -6,25 +6,30 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; - +import java.util.Optional; import org.junit.Assert; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; -import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.extension.api.path.ActionPath; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpVersion; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCaseBuilder; @@ -35,6 +40,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosActionBuilder; @@ -46,11 +52,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp; import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetDlDstCase; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetDlSrcCase; @@ -70,7 +79,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 public class ActionConvertorV10Test { /** - * Test {@link ActionConvertor#getActions(List, short, BigInteger)} + * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionConvertor#convert(java.util.List, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData)}} */ @Test public void testGetActions() { @@ -83,6 +92,7 @@ public class ActionConvertorV10Test { actionBuilder.setAction(vlanPcpCaseBuilder.build()); actionBuilder.setOrder(0); salActions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); StripVlanActionCaseBuilder stripCaseBuilder = new StripVlanActionCaseBuilder(); StripVlanActionBuilder stripBuilder = new StripVlanActionBuilder(); @@ -90,6 +100,7 @@ public class ActionConvertorV10Test { actionBuilder.setAction(stripCaseBuilder.build()); actionBuilder.setOrder(1); salActions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); SetDlDstActionCaseBuilder dlDstCaseBuilder = new SetDlDstActionCaseBuilder(); SetDlDstActionBuilder dlDstBuilder = new SetDlDstActionBuilder(); @@ -98,6 +109,7 @@ public class ActionConvertorV10Test { actionBuilder.setAction(dlDstCaseBuilder.build()); actionBuilder.setOrder(2); salActions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); SetDlSrcActionCaseBuilder dlSrcCaseBuilder = new SetDlSrcActionCaseBuilder(); SetDlSrcActionBuilder dlSrcBuilder = new SetDlSrcActionBuilder(); @@ -129,6 +141,7 @@ public class ActionConvertorV10Test { actionBuilder.setAction(nwDstCaseBuilder.build()); actionBuilder.setOrder(5); salActions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); SetTpSrcActionCaseBuilder tpSrcCaseBuilder = new SetTpSrcActionCaseBuilder(); SetTpSrcActionBuilder tpSrcBuilder = new SetTpSrcActionBuilder(); @@ -137,6 +150,7 @@ public class ActionConvertorV10Test { actionBuilder.setAction(tpSrcCaseBuilder.build()); actionBuilder.setOrder(6); salActions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); SetTpDstActionCaseBuilder tpDstCaseBuilder = new SetTpDstActionCaseBuilder(); SetTpDstActionBuilder tpDstBuilder = new SetTpDstActionBuilder(); @@ -145,6 +159,7 @@ public class ActionConvertorV10Test { actionBuilder.setAction(tpDstCaseBuilder.build()); actionBuilder.setOrder(7); salActions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); SetNwTosActionCaseBuilder tosCaseBuilder = new SetNwTosActionCaseBuilder(); SetNwTosActionBuilder tosBuilder = new SetNwTosActionBuilder(); @@ -153,6 +168,7 @@ public class ActionConvertorV10Test { actionBuilder.setAction(tosCaseBuilder.build()); actionBuilder.setOrder(8); salActions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); SetVlanIdActionCaseBuilder vlanIdCaseBuilder = new SetVlanIdActionCaseBuilder(); SetVlanIdActionBuilder vlanIdBuilder = new SetVlanIdActionBuilder(); @@ -161,13 +177,41 @@ public class ActionConvertorV10Test { actionBuilder.setAction(vlanIdCaseBuilder.build()); actionBuilder.setOrder(9); salActions.add(actionBuilder.build()); + + actionBuilder = new ActionBuilder(); + PopVlanActionCaseBuilder popVlanActionCaseBuilder = new PopVlanActionCaseBuilder(); + actionBuilder.setAction(popVlanActionCaseBuilder.build()); + actionBuilder.setOrder(10); + salActions.add(actionBuilder.build()); + + actionBuilder = new ActionBuilder(); + SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder(); + SetFieldBuilder setFieldBuilder = new SetFieldBuilder(); + VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder(); + vlanMatchBuilder.setVlanId(new VlanIdBuilder().setVlanId(new VlanId(22)).build()); + setFieldBuilder.setVlanMatch(vlanMatchBuilder.build()); + setFieldCaseBuilder.setSetField(setFieldBuilder.build()); + actionBuilder.setAction(setFieldCaseBuilder.build()); + actionBuilder.setOrder(11); + salActions.add(actionBuilder.build()); IpMatchBuilder ipMatchBld = new IpMatchBuilder().setIpProto(IpVersion.Ipv4); MatchBuilder matchBld = new MatchBuilder().setIpMatch(ipMatchBld.build()); FlowBuilder flowBld = new FlowBuilder().setMatch(matchBld.build()); - List actions = ActionConvertor.getActions(salActions, EncodeConstants.OF10_VERSION_ID, new BigInteger("42"), flowBld.build()); + Flow flow = flowBld.build(); + + ActionConvertorData data = new ActionConvertorData(OFConstants.OFP_VERSION_1_0); + data.setDatapathId(new BigInteger("42")); + if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) { + data.setIpProtocol(flow.getMatch().getIpMatch().getIpProtocol()); + } + + Optional> actionsOptional = + ConvertorManager.getInstance().convert(salActions, data); + + List actions = actionsOptional.orElse(Collections.emptyList()); - Assert.assertEquals("Wrong number of actions", 10, actions.size()); + Assert.assertEquals("Wrong number of actions", 12, actions.size()); org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action action = actions.get(0); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" @@ -226,10 +270,20 @@ public class ActionConvertorV10Test { + ".action.rev150203.action.grouping.action.choice.SetVlanVidCase", action.getActionChoice().getImplementedInterface().getName()); SetVlanVidCase setVlanVidCase = (SetVlanVidCase) action.getActionChoice(); Assert.assertEquals("Wrong vlan id", 22, setVlanVidCase.getSetVlanVidAction().getVlanVid().intValue()); + + action = actions.get(10); + Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + + ".action.rev150203.action.grouping.action.choice.StripVlanCase", action.getActionChoice().getImplementedInterface().getName()); + + action = actions.get(11); + Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common" + + ".action.rev150203.action.grouping.action.choice.SetVlanVidCase", action.getActionChoice().getImplementedInterface().getName()); + setVlanVidCase = (SetVlanVidCase) action.getActionChoice(); + Assert.assertEquals("Wrong vlan id", 22, setVlanVidCase.getSetVlanVidAction().getVlanVid().intValue()); } /** - * Test {@link ActionConvertor#toMDSalActions(List, OpenflowVersion, ActionPath)} + * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionResponseConvertor#convert(java.util.List, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData)}} */ @Test public void testToMDSalActions() { @@ -245,19 +299,18 @@ public class ActionConvertorV10Test { outputBuilder.setMaxLength(555); caseBuilder.setOutputAction(outputBuilder.build()); actionbuilder.setActionChoice(caseBuilder.build()); - -// actionbuilder.setType(Output.class); -// PortActionBuilder portBuilder = new PortActionBuilder(); -// portBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber(14L)); -// actionbuilder.addAugmentation(PortAction.class, portBuilder.build()); -// MaxLengthActionBuilder lengthBuilder = new MaxLengthActionBuilder(); -// lengthBuilder.setMaxLength(555); -// actionbuilder.addAugmentation(MaxLengthAction.class, lengthBuilder.build()); actions.add(actionbuilder.build()); + ActionResponseConvertorData data = new ActionResponseConvertorData(OFConstants.OFP_VERSION_1_0); + data.setActionPath(ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION); + + Optional> mdSalActionsOptional = + ConvertorManager.getInstance().convert( + actions, data); + List mdSalActions = ActionConvertor.toMDSalActions(actions, OpenflowVersion.OF10, - ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION); + .Action> mdSalActions = mdSalActionsOptional.orElse(Collections.emptyList()); Assert.assertEquals("Wrong number of output actions", 1, mdSalActions.size()); org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action = mdSalActions.get(0); diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertorV13Test.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV13Test.java similarity index 90% rename from openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertorV13Test.java rename to openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV13Test.java index 34300bd37a..503881d23c 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/ActionConvertorV13Test.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionConvertorV13Test.java @@ -6,17 +6,20 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor; +package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; - +import java.util.Optional; import org.junit.Assert; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; -import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.extension.api.path.ActionPath; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData; +import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData; import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; @@ -53,6 +56,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.acti import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.strip.vlan.action._case.StripVlanActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; @@ -72,8 +76,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushVlanCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetFieldCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetMplsTtlCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwDstCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetNwTtlCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.SetQueueCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.StripVlanCaseBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.group._case.GroupActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.pop.mpls._case.PopMplsActionBuilder; @@ -112,20 +118,22 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.matc */ public class ActionConvertorV13Test { /** - * Test {@link ActionConvertor#toMDSalActions(List, OpenflowVersion, ActionPath)} + * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionResponseConvertor#convert(java.util.List, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData)}} */ @Test public void testToMDSalActions() { List actions = new ArrayList<>(); - List mdSalActions = ActionConvertor.toMDSalActions(actions, OpenflowVersion.OF13, - ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION); + ActionResponseConvertorData data = new ActionResponseConvertorData(OFConstants.OFP_VERSION_1_3); + data.setActionPath(ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION); - Assert.assertEquals("Wrong number of output actions", 0, mdSalActions.size()); + Optional> mdSalActions = ConvertorManager.getInstance().convert(actions, data); + + Assert.assertEquals("Wrong number of output actions", 0, mdSalActions.orElse(Collections.emptyList()).size()); } /** - * Test {@link ActionConvertor#toMDSalActions(List, OpenflowVersion, ActionPath)} + * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionConvertor#convert(java.util.List, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData)}} */ @Test public void testToMDSalActions2() { @@ -248,11 +256,24 @@ public class ActionConvertorV13Test { actionBuilder.setActionChoice(new PopPbbCaseBuilder().build()); actions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setActionChoice(new SetNwDstCaseBuilder().build()); + actions.add(actionBuilder.build()); + + actionBuilder = new ActionBuilder(); + actionBuilder.setActionChoice(new StripVlanCaseBuilder().build()); + actions.add(actionBuilder.build()); + + ActionResponseConvertorData data = new ActionResponseConvertorData(OFConstants.OFP_VERSION_1_3); + data.setActionPath(ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION); + + Optional> mdSalActionsOptional = ConvertorManager.getInstance().convert(actions, data); + List mdSalActions = ActionConvertor.toMDSalActions(actions, OpenflowVersion.OF13, - ActionPath.FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION); + .Action> mdSalActions = mdSalActionsOptional.orElse(Collections.emptyList()); - Assert.assertEquals("Wrong number of output actions", 16, mdSalActions.size()); + Assert.assertEquals("Wrong number of output actions", 18, mdSalActions.size()); org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action = mdSalActions.get(0); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types" + ".rev131112.action.action.OutputActionCase", action.getImplementedInterface().getName()); @@ -322,10 +343,16 @@ public class ActionConvertorV13Test { action = mdSalActions.get(15); Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types" + ".rev131112.action.action.PopPbbActionCase", action.getImplementedInterface().getName()); + action = mdSalActions.get(16); + Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types" + + ".rev131112.action.action.SetNwDstActionCase", action.getImplementedInterface().getName()); + action = mdSalActions.get(17); + Assert.assertEquals("Wrong action type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types" + + ".rev131112.action.action.PopVlanActionCase", action.getImplementedInterface().getName()); } /** - * Test {@link ActionConvertor#getActions(java.util.List, short, java.math.BigInteger, org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow)} + * Test {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionConvertor#convert(java.util.List, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData)} } */ @Test public void testGetActions() { @@ -468,8 +495,17 @@ public class ActionConvertorV13Test { IpMatchBuilder ipMatchBld = new IpMatchBuilder().setIpProtocol((short) 6); MatchBuilder matchBld = new MatchBuilder().setIpMatch(ipMatchBld.build()); FlowBuilder flowBld = new FlowBuilder().setMatch(matchBld.build()); + Flow flow = flowBld.build(); + + ActionConvertorData data = new ActionConvertorData(OFConstants.OFP_VERSION_1_3); + data.setDatapathId(new BigInteger("42")); + + if (flow.getMatch() != null && flow.getMatch().getIpMatch() != null) { + data.setIpProtocol(flow.getMatch().getIpMatch().getIpProtocol()); + } - List actions = ActionConvertor.getActions(salActions, EncodeConstants.OF13_VERSION_ID, new BigInteger("42"), flowBld.build()); + Optional> actionsOptional = ConvertorManager.getInstance().convert(salActions, data); + List actions = actionsOptional.orElse(Collections.emptyList()); Assert.assertEquals("Wrong number of actions", 12, actions.size()); Action action = actions.get(0); diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorTest.java deleted file mode 100644 index d3f51e9cc4..0000000000 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactorTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Copyright (c) 2013 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.dst.action._case.SetNwDstActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; - -/** - * match conversion and injection test - */ -public class ActionSetNwDstReactorTest { - - private Address[] addresses; - - /** - * prepare input match - */ - @Before - public void setUp() { - addresses = new Address[]{ - new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1/32")).build(), - new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1/16")).build(), - new Ipv6Builder().setIpv6Address(new Ipv6Prefix("1234:5678:9abc:def1:2345:6789:abcd:ef12/128")).build(), - new Ipv6Builder().setIpv6Address(new Ipv6Prefix("1234:5678:9abc:def1:2345:6789:abcd:ef12/42")).build(), - }; - } - - /** - * convert for OF-1.3, inject into {@link ActionBuilder} - */ - @Test - public void testMatchConvertorV13_flow() { - final ActionBuilder target = new ActionBuilder(); - for (final Address address : addresses) { - final SetNwDstActionCase action = prepareSetNwDstActionCase(address); - ActionSetNwDstReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_3, target); - final Object mEntry = target.getActionChoice(); -/* - Assert.assertNotNull(mEntry); - if (address instanceof Ipv4) { - Ipv4DstCase ipv4DstCase = ((Ipv4DstCase) mEntry.getMatchEntryValue()); - Assert.assertNotNull(ipv4DstCase.getIpv4Dst()); - } else if (address instanceof Ipv6) { - Ipv6DstCase ipv6DstCase = ((Ipv6DstCase) mEntry.getMatchEntryValue()); - Assert.assertNotNull(ipv6DstCase.getIpv6Dst()); - } else { - Assert.fail("not tested yet: " + address.getClass().getName()); - } -*/ - } - } - - /** - * @param address - * @return - */ - private static SetNwDstActionCase prepareSetNwDstActionCase(final Address address) { - return new SetNwDstActionCaseBuilder().setSetNwDstAction( - new SetNwDstActionBuilder().setAddress(address).build()).build(); - } - - /** - * convert for OF-1.0, inject into {@link ActionBuilder} - */ - @Test - public void testMatchConvertorV10_flow() { - final ActionBuilder target = new ActionBuilder(); - for (final Address address : addresses) { - final SetNwDstActionCase action = prepareSetNwDstActionCase(address); - - if (address instanceof Ipv4) { - ActionSetNwDstReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_0, target); -// Assert.assertNotNull(target.getAugmentation(IpAddressAction.class).getIpAddress()); - } else { - try { - ActionSetNwDstReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_0, target); - Assert.fail("address of this type must not pass the reactor: " + address.getClass().getName()); - } catch (final Exception e) { - //expected - Assert.assertEquals(IllegalArgumentException.class, e.getClass()); - } - } - } - } -} diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorTest.java deleted file mode 100644 index fc15fb46c9..0000000000 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactorTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Copyright (c) 2013 Cisco Systems, 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.openflowplugin.openflow.md.core.sal.convertor.action; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCaseBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.src.action._case.SetNwSrcActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.Address; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv4Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.address.address.Ipv6Builder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder; - -/** - * match conversion and injection test - */ -public class ActionSetNwSrcReactorTest { - - private Address[] addresses; - - /** - * prepare input match - */ - @Before - public void setUp() { - addresses = new Address[]{ - new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1/32")).build(), - new Ipv4Builder().setIpv4Address(new Ipv4Prefix("10.0.10.1/16")).build(), - new Ipv6Builder().setIpv6Address(new Ipv6Prefix("1234:5678:9abc:def1:2345:6789:abcd:ef12/128")).build(), - new Ipv6Builder().setIpv6Address(new Ipv6Prefix("1234:5678:9abc:def1:2345:6789:abcd:ef12/42")).build(), - }; - } - - /** - * convert for OF-1.3, inject into {@link ActionBuilder} - */ - - @Test - public void testMatchConvertorV13_flow() { - final ActionBuilder target = new ActionBuilder(); - for (final Address address : addresses) { - final SetNwSrcActionCase action = prepareSetNwSrcActionCase(address); - ActionSetNwSrcReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_3, target); -/* - MatchEntry mEntry = target.getActionChoice() getAugmentation(OxmFieldsAction.class).getMatchEntry().get(0); - Assert.assertNotNull(mEntry); - if (address instanceof Ipv4) { - Ipv4SrcCase ipv4SrcCase = ((Ipv4SrcCase) mEntry.getMatchEntryValue()); - Assert.assertNotNull(ipv4SrcCase.getIpv4Src()); - } else if (address instanceof Ipv6) { - Ipv6SrcCase ipv6SrcCase = ((Ipv6SrcCase) mEntry.getMatchEntryValue()); - Assert.assertNotNull(ipv6SrcCase.getIpv6Src().getIpv6Address()); - } else { - Assert.fail("not tested yet: " + address.getClass().getName()); - } -*/ - } - } - - /** - * @param address - * @return - */ - private static SetNwSrcActionCase prepareSetNwSrcActionCase(final Address address) { - return new SetNwSrcActionCaseBuilder().setSetNwSrcAction( - new SetNwSrcActionBuilder().setAddress(address).build()).build(); - } - - /** - * convert for OF-1.0, inject into {@link ActionBuilder} - */ - @Test - public void testMatchConvertorV10_flow() { - final ActionBuilder target = new ActionBuilder(); - for (final Address address : addresses) { - final SetNwSrcActionCase action = prepareSetNwSrcActionCase(address); - - if (address instanceof Ipv4) { - ActionSetNwSrcReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_0, target); - } else { - try { - ActionSetNwSrcReactor.getInstance().convert(action, - OFConstants.OFP_VERSION_1_0, target); - Assert.fail("address of this type must not pass the reactor: " + address.getClass().getName()); - } catch (final Exception e) { - //expected - Assert.assertEquals(IllegalArgumentException.class, e.getClass()); - } - } - } - } -}