X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fopenflow%2Fmd%2Fcore%2Fsal%2Fconvertor%2FPacketOutConvertor.java;h=bc002d1409e58e85ce9f4d7d7fdecef3f8dc0a59;hb=1bf6ccb5580d41856c87d4171644a2eabe457d89;hp=494844896bf9c73a7f5021a682e6d21de55a738c;hpb=d63aaa9ee66e40cc4a6f4d65103a10c1e6b6fcb9;p=openflowplugin.git 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 494844896b..bc002d1409 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 @@ -7,18 +7,21 @@ */ 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.List; import org.opendaylight.controller.sal.common.util.Arguments; import org.opendaylight.openflowplugin.api.OFConstants; -import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +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.augments.rev131002.MaxLengthAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder; +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.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInputBuilder; @@ -28,38 +31,36 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - public final class PacketOutConvertor { - private static final Logger LOG = LoggerFactory.getLogger(MeterConvertor.class); + private static final Logger LOG = LoggerFactory.getLogger(PacketOutConvertor.class); private PacketOutConvertor() { } // Get all the data for the PacketOut from the Yang/SAL-Layer + /** - * @param version - * @param Yang - * Data source + * @param version openflow version + * @param inputPacket input packet + * @param datapathid datapath id + * @param xid tx id * @return PacketOutInput required by OF Library */ - public static PacketOutInput toPacketOutInput(TransmitPacketInput inputPacket, short version, Long xid, - BigInteger datapathid) { + public static PacketOutInput toPacketOutInput(final TransmitPacketInput inputPacket, final short version, final Long xid, + final BigInteger datapathid) { + LOG.trace("toPacketOutInput for datapathId:{}, xid:{}", datapathid, xid); // Build Port ID from TransmitPacketInput.Ingress PortNumber inPortNr = null; Long bufferId = OFConstants.OFP_NO_BUFFER; - List actions = new ArrayList<>(); - List inArgs = null; + Iterable inArgs = null; PacketOutInputBuilder builder = new PacketOutInputBuilder(); if (inputPacket.getIngress() != null) { - inArgs = inputPacket.getIngress().getValue().getPath(); + inArgs = inputPacket.getIngress().getValue().getPathArguments(); } - if (inArgs != null && inArgs.size() >= 3) { - inPortNr = getPortNumber(inArgs.get(2), version); + if (inArgs != null && Iterables.size(inArgs) >= 3) { + inPortNr = getPortNumber(Iterables.get(inArgs, 2), version); } else { // The packetOut originated from the controller inPortNr = new PortNumber(0xfffffffdL); @@ -72,32 +73,42 @@ public final class PacketOutConvertor { PortNumber outPort = null; NodeConnectorRef outRef = inputPacket.getEgress(); - List outArgs = outRef.getValue().getPath(); - if (outArgs.size() >= 3) { - outPort = getPortNumber(outArgs.get(2), version); + Iterable outArgs = outRef.getValue().getPathArguments(); + if (Iterables.size(outArgs) >= 3) { + outPort = getPortNumber(Iterables.get(outArgs, 2), version); } else { // TODO : P4 search for some normal exception new Exception("PORT NR not exist in Egress"); } - // TODO VD P! wait for way to move Actions (e.g. augmentation) + List actions = null; + List inputActions = + inputPacket.getAction(); + if (inputActions != null) { + actions = ActionConvertor.getActions(inputActions, version, datapathid, null); - // FIXME VD implementation for testing PacketIn (REMOVE IT) - if (inputPacket.getAction() == null) { + } else { + actions = new ArrayList<>(); + // TODO VD P! wait for way to move Actions (e.g. augmentation) ActionBuilder aBuild = new ActionBuilder(); - aBuild.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class); - PortActionBuilder paBuild = new PortActionBuilder(); - paBuild.setPort(outPort); - aBuild.addAugmentation(PortAction.class, paBuild.build()); - MaxLengthActionBuilder mlBuild = new MaxLengthActionBuilder(); - mlBuild.setMaxLength(0xffff); - aBuild.addAugmentation(MaxLengthAction.class, mlBuild.build()); + + OutputActionCaseBuilder outputActionCaseBuilder = + new OutputActionCaseBuilder(); + + OutputActionBuilder outputActionBuilder = + new OutputActionBuilder(); + + outputActionBuilder.setPort(outPort); + outputActionBuilder.setMaxLength(OFConstants.OFPCML_NO_BUFFER); + + outputActionCaseBuilder.setOutputAction(outputActionBuilder.build()); + + aBuild.setActionChoice(outputActionCaseBuilder.build()); + actions.add(aBuild.build()); - builder.setAction(actions); - } else { - builder.setAction(ActionConvertor.getActions(inputPacket.getAction(), version, datapathid, null)); } + builder.setAction(actions); builder.setData(inputPacket.getPayload()); builder.setVersion(version); builder.setXid(xid); @@ -108,13 +119,13 @@ public final class PacketOutConvertor { return builder.build(); } - private static PortNumber getPortNumber(PathArgument pathArgument, Short ofVersion) { + private static PortNumber getPortNumber(final PathArgument pathArgument, final Short ofVersion) { // FIXME VD P! find InstanceIdentifier helper - InstanceIdentifier.IdentifiableItem item = Arguments.checkInstanceOf(pathArgument, + InstanceIdentifier.IdentifiableItem item = Arguments.checkInstanceOf(pathArgument, InstanceIdentifier.IdentifiableItem.class); NodeConnectorKey key = Arguments.checkInstanceOf(item.getKey(), NodeConnectorKey.class); - String[] split = key.getId().getValue().split(":"); - Long port = OpenflowPortsUtil.getPortFromLogicalName(OpenflowVersion.get(ofVersion), split[split.length - 1]); + Long port = InventoryDataServiceUtil.portNumberfromNodeConnectorId( + OpenflowVersion.get(ofVersion), key.getId()); return new PortNumber(port); } }