Be a bit smarter about dealing with units, fixing related warnings.
JIRA: OPNFLWPLUG-1099
Change-Id: I9ab33dc6634f37bb38735d948741424c9c2fa07f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.Uint8;
public final class SalPortServiceImpl
extends AbstractSimpleService<UpdatePortInput, UpdatePortOutput> implements SalPortService {
.convert(getPortFromInput(input), data);
final PortModInputBuilder mdInput = new PortModInputBuilder(ofPortModInput
- .orElse(PortConvertor.defaultResult(getVersion())))
+ .orElse(PortConvertor.defaultResult(Uint8.valueOf(getVersion()))))
.setXid(xid.getValue());
return mdInput.build();
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.Ports;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc._case.multipart.reply.port.desc.PortsBuilder;
+import org.opendaylight.yangtools.yang.common.Uint8;
/**
* Converts port mod, port status and port description MD-SAL messages to OF library data.
* @param version Openflow version
* @return default empty port mod input
*/
- public static PortModInput defaultResult(final short version) {
- return new PortModInputBuilder()
- .setVersion(version)
- .build();
+ public static PortModInput defaultResult(final Uint8 version) {
+ return new PortModInputBuilder().setVersion(version).build();
}
private static PortConfig maskPortConfigFields(
* 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 org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
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.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.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.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint8;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
super(SetTpDstActionCase.class, true, OFConstants.OFP_VERSION_1_3);
}
- @NonNull
@Override
- public Optional<Action> process(@NonNull final SetTpDstActionCase source, final ActionConvertorData data,
+ public Optional<Action> process(final SetTpDstActionCase source, final ActionConvertorData data,
final ConvertorExecutor convertorExecutor) {
- IPProtocols protocol = null;
-
- if (data.getIpProtocol() != null) {
- protocol = IPProtocols.fromProtocolNum(data.getIpProtocol());
- }
-
- SetTpDstAction settpdstaction = source.getSetTpDstAction();
-
- MatchEntryBuilder matchBuilder = new MatchEntryBuilder()
+ final MatchEntryBuilder matchBuilder = new MatchEntryBuilder()
.setOxmClass(OpenflowBasicClass.class)
.setHasMask(Boolean.FALSE);
- int port = settpdstaction.getPort().getValue().toJava();
- int code = 0xff & port;
+
+ final Uint8 ipProtocol = data.getIpProtocol();
+ final IPProtocols protocol;
+ if (ipProtocol != null) {
+ protocol = IPProtocols.fromProtocolNum(ipProtocol);
+ } else {
+ protocol = null;
+ }
if (protocol != null) {
+ final Uint16 port = source.getSetTpDstAction().getPort().getValue();
+
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());
+ matchBuilder.setMatchEntryValue(new Icmpv4CodeCaseBuilder()
+ .setIcmpv4Code(new Icmpv4CodeBuilder()
+ .setIcmpv4Code(Uint8.valueOf(0xFF & port.toJava()))
+ .build())
+ .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());
+ matchBuilder.setMatchEntryValue(new Icmpv6CodeCaseBuilder()
+ .setIcmpv6Code(new Icmpv6CodeBuilder()
+ .setIcmpv6Code(Uint8.valueOf(0xFF & port.toJava()))
+ .build())
+ .build());
break;
case TCP:
matchBuilder.setOxmMatchField(TcpDst.class);
LOG.warn("Missing protocol with combination of SetSourcePort");
}
- List<MatchEntry> entries = new ArrayList<>();
- entries.add(matchBuilder.build());
-
- SetFieldActionBuilder setFieldBuilder = new SetFieldActionBuilder();
- setFieldBuilder.setMatchEntry(entries);
-
- SetFieldCaseBuilder setFieldCaseBuilder = new SetFieldCaseBuilder();
- setFieldCaseBuilder.setSetFieldAction(setFieldBuilder.build());
-
return Optional.of(new ActionBuilder()
- .setActionChoice(setFieldCaseBuilder.build())
- .build());
+ .setActionChoice(new SetFieldCaseBuilder()
+ .setSetFieldAction(new SetFieldActionBuilder().setMatchEntry(List.of(matchBuilder.build())).build())
+ .build())
+ .build());
}
}
* 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 org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
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;
super(SetTpDstActionCase.class, true, OFConstants.OFP_VERSION_1_0);
}
- @NonNull
@Override
- public Optional<Action> process(@NonNull final SetTpDstActionCase source, final ActionConvertorData data,
- ConvertorExecutor convertorExecutor) {
- SetTpDstAction settpdstaction = source.getSetTpDstAction();
- SetTpDstCaseBuilder setTpDstCaseBuilder = new SetTpDstCaseBuilder();
- SetTpDstActionBuilder setTpDstActionBuilder = new SetTpDstActionBuilder();
- setTpDstActionBuilder.setPort(new PortNumber(settpdstaction.getPort().getValue().longValue()));
- setTpDstCaseBuilder.setSetTpDstAction(setTpDstActionBuilder.build());
-
+ public Optional<Action> process(final SetTpDstActionCase source, final ActionConvertorData data,
+ final ConvertorExecutor convertorExecutor) {
return Optional.of(new ActionBuilder()
- .setActionChoice(setTpDstCaseBuilder.build())
- .build());
+ .setActionChoice(new SetTpDstCaseBuilder()
+ .setSetTpDstAction(new SetTpDstActionBuilder()
+ .setPort(new PortNumber(source.getSetTpDstAction().getPort().getValue().toUint32()))
+ .build())
+ .build())
+ .build());
}
}
import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil;
import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
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.Ipv4Prefix;
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.set.field._case.SetField;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
+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;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatch;
import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv4Match;
*/
private static final Ipv4Address ZERO_IPV4 = new Ipv4Address("0.0.0.0");
+ private static final Uint8 DEFAULT_PREFIX = Uint8.valueOf(32);
+
/*
* The value 0xffff (OFP_VLAN_NONE) is used to indicate
* that no VLAN ID is set for OF Flow.
* @param matchBuilder match builder
* @param ipv4 ip v4 match
*/
- private static void convertL3Ipv4DstMatch(final MatchV10Builder matchBuilder,
- final Ipv4Match ipv4) {
- if (ipv4.getIpv4Destination() != null) {
- Iterator<String> addressParts = IpConversionUtil.PREFIX_SPLITTER.split(
- ipv4.getIpv4Destination().getValue()).iterator();
- Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
- Integer prefix = buildPrefix(addressParts);
- matchBuilder.setNwDst(ipv4Address);
- matchBuilder.setNwDstMask(prefix.shortValue());
+ private static void convertL3Ipv4DstMatch(final MatchV10Builder matchBuilder, final Ipv4Match ipv4) {
+ final Ipv4Prefix destination = ipv4.getIpv4Destination();
+ if (destination != null) {
+ // TODO: consider using IetfInetUtil
+ Iterator<String> addressParts = IpConversionUtil.PREFIX_SPLITTER.split(destination.getValue()).iterator();
+ matchBuilder.setNwDst(new Ipv4Address(addressParts.next()));
+ matchBuilder.setNwDstMask(buildPrefix(addressParts));
}
}
* @param matchBuilder match builder
* @param ipv4 ip v4 match
*/
- private static void convertL3Ipv4SrcMatch(final MatchV10Builder matchBuilder,
- final Ipv4Match ipv4) {
- if (ipv4.getIpv4Source() != null) {
- Iterator<String> addressParts = IpConversionUtil.PREFIX_SPLITTER.split(
- ipv4.getIpv4Source().getValue()).iterator();
- Ipv4Address ipv4Address = new Ipv4Address(addressParts.next());
- int prefix = buildPrefix(addressParts);
-
- matchBuilder.setNwSrc(ipv4Address);
- matchBuilder.setNwSrcMask((short) prefix);
+ private static void convertL3Ipv4SrcMatch(final MatchV10Builder matchBuilder, final Ipv4Match ipv4) {
+ final Ipv4Prefix source = ipv4.getIpv4Source();
+ if (source != null) {
+ // TODO: consider IetfInetUtil
+ Iterator<String> addressParts = IpConversionUtil.PREFIX_SPLITTER.split(source.getValue()).iterator();
+ matchBuilder.setNwSrc(new Ipv4Address(addressParts.next()));
+ matchBuilder.setNwSrcMask(buildPrefix(addressParts));
}
}
- private static int buildPrefix(final Iterator<String> addressParts) {
- int prefix = 32;
- if (addressParts.hasNext()) {
- prefix = Integer.parseInt(addressParts.next());
- }
- return prefix;
+ private static Uint8 buildPrefix(final Iterator<String> addressParts) {
+ return addressParts.hasNext() ? Uint8.valueOf(addressParts.next()) : DEFAULT_PREFIX;
}
- private static boolean convertDlVlanPcp(final MatchV10Builder matchBuilder,
- final VlanMatch vlanMatch) {
- if (vlanMatch.getVlanPcp() != null) {
- matchBuilder.setDlVlanPcp(vlanMatch.getVlanPcp().getValue());
+ private static boolean convertDlVlanPcp(final MatchV10Builder matchBuilder, final VlanMatch vlanMatch) {
+ final VlanPcp vlanPcp = vlanMatch.getVlanPcp();
+ if (vlanPcp != null) {
+ matchBuilder.setDlVlanPcp(vlanPcp.getValue());
return false;
}
return true;
matchBuilder.setEthernetMatch(ethMatchBuilder.build());
}
if (!source.getWildcards().getDLVLAN() && source.getDlVlan() != null) {
- VlanIdBuilder vlanIdBuilder = new VlanIdBuilder();
- int vlanId = source.getDlVlan().toJava() == 0xffff ? 0 : source.getDlVlan().toJava();
- vlanIdBuilder.setVlanId(
- new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId));
- vlanIdBuilder.setVlanIdPresent(vlanId != 0);
- vlanMatchBuilder.setVlanId(vlanIdBuilder.build());
+ Uint16 vlanId = source.getDlVlan();
+ if (vlanId.toJava() == 0xffff) {
+ vlanId = Uint16.ZERO;
+ }
+
+ vlanMatchBuilder.setVlanId(new VlanIdBuilder()
+ .setVlanId(new org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId(vlanId))
+ .setVlanIdPresent(!Uint16.ZERO.equals(vlanId))
+ .build());
matchBuilder.setVlanMatch(vlanMatchBuilder.build());
}
if (!source.getWildcards().getDLVLANPCP() && source.getDlVlanPcp() != null) {
VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
- Optional<PortModInput> portOutOptional = convertorManager.convert(portBld.build(), data);
- final PortModInput portOut = portOutOptional.orElse(PortConvertor.defaultResult(OFConstants.OFP_VERSION_1_3));
+ final Optional<PortModInput> portOutOptional = convertorManager.convert(portBld.build(), data);
+ final PortModInput portOut = portOutOptional
+ .orElse(PortConvertor.defaultResult(EncodeConstants.OF_VERSION_1_3));
PortConfigV10 portConfV10 = new PortConfigV10(false, false, false, false, true, true, false);