Search in sources :

Example 6 with OpenflowVersion

use of org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion in project openflowplugin by opendaylight.

the class PortTranslatorUtil method translatePort.

public static NodeConnectorUpdated translatePort(final Short version, final BigInteger datapathId, final Long portNumber, final PortGrouping port) {
    OpenflowVersion ofVersion = OpenflowVersion.get(version);
    final NodeConnectorUpdatedBuilder builder = InventoryDataServiceUtil.nodeConnectorUpdatedBuilderFromDatapathIdPortNo(datapathId, port.getPortNo(), ofVersion);
    FlowCapableNodeConnectorUpdatedBuilder fcncub = new FlowCapableNodeConnectorUpdatedBuilder();
    if (ofVersion == OpenflowVersion.OF13) {
        fcncub.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(port.getAdvertisedFeatures()));
        fcncub.setConfiguration(PortTranslatorUtil.translatePortConfig(port.getConfig()));
        fcncub.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(port.getCurrentFeatures()));
        fcncub.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(port.getPeerFeatures()));
        fcncub.setState(PortTranslatorUtil.translatePortState(port.getState()));
        fcncub.setSupported(PortTranslatorUtil.translatePortFeatures(port.getSupportedFeatures()));
    } else if (ofVersion == OpenflowVersion.OF10) {
        fcncub.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(port.getAdvertisedFeaturesV10()));
        fcncub.setConfiguration(PortTranslatorUtil.translatePortConfig(port.getConfigV10()));
        fcncub.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(port.getCurrentFeaturesV10()));
        fcncub.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(port.getPeerFeaturesV10()));
        fcncub.setState(PortTranslatorUtil.translatePortState(port.getStateV10()));
        fcncub.setSupported(PortTranslatorUtil.translatePortFeatures(port.getSupportedFeaturesV10()));
    }
    if (port instanceof PortStatusMessage) {
        if (((PortStatusMessage) port).getReason() != null) {
            fcncub.setReason(PortReason.forValue(((PortStatusMessage) port).getReason().getIntValue()));
        } else {
            LOG.debug("PortStatus Message has reason as null");
        }
    }
    fcncub.setCurrentSpeed(port.getCurrSpeed());
    fcncub.setHardwareAddress(port.getHwAddr());
    fcncub.setMaximumSpeed(port.getMaxSpeed());
    fcncub.setName(port.getName());
    fcncub.setPortNumber(OpenflowPortsUtil.getProtocolAgnosticPort(ofVersion, portNumber));
    builder.addAugmentation(FlowCapableNodeConnectorUpdated.class, fcncub.build());
    return builder.build();
}
Also used : OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) PortStatusMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage) FlowCapableNodeConnectorUpdatedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdatedBuilder) NodeConnectorUpdatedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdatedBuilder) FlowCapableNodeConnectorUpdatedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdatedBuilder)

Example 7 with OpenflowVersion

use of org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion in project openflowplugin by opendaylight.

the class ActionResponseConvertor method convert.

@Override
public List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> convert(List<Action> source, ActionResponseConvertorData data) {
    final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> 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<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> convertedAction = PROCESSOR.process(action.getActionChoice(), data, getConvertorExecutor());
            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;
}
Also used : Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) ArrayList(java.util.ArrayList)

Example 8 with OpenflowVersion

use of org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion in project openflowplugin by opendaylight.

the class SalToOfOutputActionCase method process.

@Nonnull
@Override
public Optional<Action> process(@Nonnull final OutputActionCase source, final ActionConvertorData data, ConvertorExecutor convertorExecutor) {
    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());
}
Also used : OutputActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) OutputAction(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) Nonnull(javax.annotation.Nonnull)

Example 9 with OpenflowVersion

use of org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion in project openflowplugin by opendaylight.

the class MatchV10ResponseConvertor method convert.

@Override
public MatchBuilder convert(MatchV10 source, VersionDatapathIdConvertorData datapathIdConvertorData) {
    MatchBuilder matchBuilder = new MatchBuilder();
    EthernetMatchBuilder ethMatchBuilder = new EthernetMatchBuilder();
    VlanMatchBuilder vlanMatchBuilder = new VlanMatchBuilder();
    Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
    IpMatchBuilder ipMatchBuilder = new IpMatchBuilder();
    OpenflowVersion ofVersion = OpenflowVersion.get(datapathIdConvertorData.getVersion());
    BigInteger datapathid = datapathIdConvertorData.getDatapathId();
    if (!source.getWildcards().isINPORT() && source.getInPort() != null) {
        matchBuilder.setInPort(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathid, (long) source.getInPort(), ofVersion));
    }
    if (!source.getWildcards().isDLSRC() && source.getDlSrc() != null) {
        EthernetSourceBuilder ethSrcBuilder = new EthernetSourceBuilder();
        ethSrcBuilder.setAddress(source.getDlSrc());
        ethMatchBuilder.setEthernetSource(ethSrcBuilder.build());
        matchBuilder.setEthernetMatch(ethMatchBuilder.build());
    }
    if (!source.getWildcards().isDLDST() && source.getDlDst() != null) {
        EthernetDestinationBuilder ethDstBuilder = new EthernetDestinationBuilder();
        ethDstBuilder.setAddress(source.getDlDst());
        ethMatchBuilder.setEthernetDestination(ethDstBuilder.build());
        matchBuilder.setEthernetMatch(ethMatchBuilder.build());
    }
    if (!source.getWildcards().isDLTYPE() && source.getDlType() != null) {
        EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
        ethTypeBuilder.setType(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType((long) source.getDlType()));
        ethMatchBuilder.setEthernetType(ethTypeBuilder.build());
        matchBuilder.setEthernetMatch(ethMatchBuilder.build());
    }
    if (!source.getWildcards().isDLVLAN() && source.getDlVlan() != null) {
        VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
        int vlanId = source.getDlVlan() == 0xffff ? 0 : source.getDlVlan();
        vlanIdBuilder.setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
        vlanIdBuilder.setVlanIdPresent(vlanId != 0);
        vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
        matchBuilder.setVlanMatch(vlanMatchBuilder.build());
    }
    if (!source.getWildcards().isDLVLANPCP() && source.getDlVlanPcp() != null) {
        vlanMatchBuilder.setVlanPcp(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanPcp(source.getDlVlanPcp()));
        matchBuilder.setVlanMatch(vlanMatchBuilder.build());
    }
    if (!source.getWildcards().isDLTYPE() && source.getNwSrc() != null) {
        final Ipv4Prefix prefix;
        if (source.getNwSrcMask() != null) {
            prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc(), source.getNwSrcMask());
        } else {
            // Openflow Spec : 1.3.2
            // An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
            // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
            // statistics response.
            prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwSrc());
        }
        if (!NO_IP.equals(prefix.getValue())) {
            ipv4MatchBuilder.setIpv4Source(prefix);
            matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
        }
    }
    if (!source.getWildcards().isDLTYPE() && source.getNwDst() != null) {
        final Ipv4Prefix prefix;
        if (source.getNwDstMask() != null) {
            prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst(), source.getNwDstMask());
        } else {
            // Openflow Spec : 1.3.2
            // An all-one-bits oxm_mask is equivalent to specifying 0 for oxm_hasmask and omitting oxm_mask.
            // So when user specify 32 as a mast, switch omit that mast and we get null as a mask in flow
            // statistics response.
            prefix = IetfInetUtil.INSTANCE.ipv4PrefixFor(source.getNwDst());
        }
        if (!NO_IP.equals(prefix.getValue())) {
            ipv4MatchBuilder.setIpv4Destination(prefix);
            matchBuilder.setLayer3Match(ipv4MatchBuilder.build());
        }
    }
    if (!source.getWildcards().isNWPROTO() && source.getNwProto() != null) {
        Short nwProto = source.getNwProto();
        ipMatchBuilder.setIpProtocol(nwProto);
        matchBuilder.setIpMatch(ipMatchBuilder.build());
        int proto = nwProto.intValue();
        if (proto == PROTO_TCP) {
            TcpMatchBuilder tcpMatchBuilder = new TcpMatchBuilder();
            boolean hasTcp = false;
            if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
                tcpMatchBuilder.setTcpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpSrc()));
                hasTcp = true;
            }
            if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
                tcpMatchBuilder.setTcpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
                hasTcp = true;
            }
            if (hasTcp) {
                matchBuilder.setLayer4Match(tcpMatchBuilder.build());
            }
        } else if (proto == PROTO_UDP) {
            UdpMatchBuilder udpMatchBuilder = new UdpMatchBuilder();
            boolean hasUdp = false;
            if (!source.getWildcards().isTPSRC() && source.getTpSrc() != null) {
                udpMatchBuilder.setUdpSourcePort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpSrc()));
                hasUdp = true;
            }
            if (!source.getWildcards().isTPDST() && source.getTpDst() != null) {
                udpMatchBuilder.setUdpDestinationPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber(source.getTpDst()));
                hasUdp = true;
            }
            if (hasUdp) {
                matchBuilder.setLayer4Match(udpMatchBuilder.build());
            }
        } else if (proto == PROTO_ICMPV4) {
            Icmpv4MatchBuilder icmpv4MatchBuilder = new Icmpv4MatchBuilder();
            boolean hasIcmpv4 = false;
            if (!source.getWildcards().isTPSRC()) {
                Integer type = source.getTpSrc();
                if (type != null) {
                    icmpv4MatchBuilder.setIcmpv4Type(type.shortValue());
                    hasIcmpv4 = true;
                }
            }
            if (!source.getWildcards().isTPDST()) {
                Integer code = source.getTpDst();
                if (code != null) {
                    icmpv4MatchBuilder.setIcmpv4Code(code.shortValue());
                    hasIcmpv4 = true;
                }
            }
            if (hasIcmpv4) {
                matchBuilder.setIcmpv4Match(icmpv4MatchBuilder.build());
            }
        }
    }
    if (!source.getWildcards().isNWTOS() && source.getNwTos() != null) {
        Short dscp = ActionUtil.tosToDscp(source.getNwTos());
        ipMatchBuilder.setIpDscp(new Dscp(dscp));
        matchBuilder.setIpMatch(ipMatchBuilder.build());
    }
    return matchBuilder;
}
Also used : Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) Collections(java.util.Collections) EthernetTypeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) UdpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder) TcpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder) Icmpv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder) VlanIdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) IpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder) EthernetDestinationBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder) BigInteger(java.math.BigInteger) EthernetSourceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder) BigInteger(java.math.BigInteger) Dscp(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Dscp) IpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder) TcpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder) Icmpv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4MatchBuilder) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) UdpMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder) EthernetMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder) Ipv4MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)

Example 10 with OpenflowVersion

use of org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion in project openflowplugin by opendaylight.

the class PortStatsMultipartWriter method storeStatistics.

@Override
public void storeStatistics(final NodeConnectorStatisticsAndPortNumberMap statistics, final boolean withParents) {
    statistics.getNodeConnectorStatisticsAndPortNumberMap().forEach(stat -> {
        final OpenflowVersion openflowVersion = OpenflowVersion.get(features.getVersion());
        final Long port = InventoryDataServiceUtil.portNumberfromNodeConnectorId(openflowVersion, stat.getNodeConnectorId());
        final NodeConnectorId id = InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(features.getDatapathId(), port, OpenflowVersion.get(features.getVersion()));
        writeToTransaction(getInstanceIdentifier().child(NodeConnector.class, new NodeConnectorKey(id)).augmentation(FlowCapableNodeConnectorStatisticsData.class).child(FlowCapableNodeConnectorStatistics.class), new FlowCapableNodeConnectorStatisticsBuilder(stat).build(), OFConstants.OFP_VERSION_1_0 == features.getVersion() || withParents);
    });
}
Also used : FlowCapableNodeConnectorStatisticsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatisticsBuilder) OpenflowVersion(org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion) NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) FlowCapableNodeConnectorStatistics(org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatistics) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)

Aggregations

OpenflowVersion (org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion)13 BigInteger (java.math.BigInteger)3 Nullable (javax.annotation.Nullable)3 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)3 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)3 Collections (java.util.Collections)2 Nonnull (javax.annotation.Nonnull)2 TranslatorLibrary (org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary)2 ConvertorExecutor (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor)2 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)2 NodeConnector (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector)2 NodeConnectorKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)2 PortStatusMessage (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1