import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint8;
-import com.google.common.net.InetAddresses;
import io.netty.buffer.ByteBuf;
-import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey;
import org.opendaylight.openflowjava.nx.api.NiciraActionSerializerKey;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
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.openflowjava.nx.action.rev140421.NxActionNatRangePresent;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrack;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionConntrackBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.aug.nx.action.ActionConntrack;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.aug.nx.action.ActionConntrackBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.NxActionConntrackBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActions;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.conntrack.grouping.nx.action.conntrack.CtActionsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.ct.mark._case.NxActionCtMarkBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNat;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofpact.actions.ofpact.actions.nx.action.nat._case.NxActionNatBuilder;
+import org.opendaylight.yangtools.yang.common.Uint16;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public static final byte NXAST_CONNTRACK_SUBTYPE = 35;
public static final byte NXAST_NAT_SUBTYPE = 36;
public static final NiciraActionSerializerKey SERIALIZER_KEY =
- new NiciraActionSerializerKey(EncodeConstants.OF13_VERSION_ID, ActionConntrack.class);
+ new NiciraActionSerializerKey(EncodeConstants.OF_VERSION_1_3, ActionConntrack.class);
public static final NiciraActionDeserializerKey DESERIALIZER_KEY =
- new NiciraActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, NXAST_CONNTRACK_SUBTYPE);
+ new NiciraActionDeserializerKey(EncodeConstants.OF_VERSION_1_3, NXAST_CONNTRACK_SUBTYPE);
@Override
public void serialize(final Action input, final ByteBuf outBuffer) {
short rangePresent = natAction.getRangePresent().shortValue();
outBuffer.writeShort(rangePresent);
if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEIPV4MIN.getIntValue())) {
- if (null != natAction.getIpAddressMin()) {
- outBuffer.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(natAction
- .getIpAddressMin().getIpv4Address()));
- }
+ writeIpv4Address(outBuffer, natAction.getIpAddressMin());
}
if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEIPV4MAX.getIntValue())) {
- if (null != natAction.getIpAddressMax()) {
- outBuffer.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(natAction
- .getIpAddressMax().getIpv4Address()));
- }
+ writeIpv4Address(outBuffer, natAction.getIpAddressMax());
}
if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEPROTOMIN.getIntValue())) {
outBuffer.writeShort(natAction.getPortMin().toJava());
@Override
public Action deserialize(final ByteBuf message) {
final short length = deserializeCtHeader(message);
- NxActionConntrackBuilder nxActionConntrackBuilder = new NxActionConntrackBuilder();
- nxActionConntrackBuilder.setFlags(readUint16(message));
- nxActionConntrackBuilder.setZoneSrc(readUint32(message));
- nxActionConntrackBuilder.setConntrackZone(readUint16(message));
- nxActionConntrackBuilder.setRecircTable(readUint8(message));
+ final var nxActionConntrackBuilder = new NxActionConntrackBuilder()
+ .setFlags(readUint16(message))
+ .setZoneSrc(readUint32(message))
+ .setConntrackZone(readUint16(message))
+ .setRecircTable(readUint8(message));
message.skipBytes(5);
- if (length > CT_LENGTH) {
- deserializeCtAction(message,nxActionConntrackBuilder, length - CT_LENGTH);
+ if (length > CT_LENGTH) {
+ deserializeCtAction(message, nxActionConntrackBuilder, length - CT_LENGTH);
}
- ActionBuilder actionBuilder = new ActionBuilder();
- actionBuilder.setExperimenterId(getExperimenterId());
- ActionConntrackBuilder actionConntrackBuilder = new ActionConntrackBuilder();
- actionConntrackBuilder.setNxActionConntrack(nxActionConntrackBuilder.build());
- actionBuilder.setActionChoice(actionConntrackBuilder.build());
- return actionBuilder.build();
+ return new ActionBuilder()
+ .setExperimenterId(getExperimenterId())
+ .setActionChoice(new ActionConntrackBuilder()
+ .setNxActionConntrack(nxActionConntrackBuilder.build())
+ .build())
+ .build();
}
private static void deserializeCtAction(final ByteBuf message,
int processedCtActionsLength = ctActionsLength;
while (processedCtActionsLength > 0) {
- int startReaderIndex = message.readerIndex();
+ final int startReaderIndex = message.readerIndex();
if (EncodeConstants.EXPERIMENTER_VALUE == message.readUnsignedShort()) {
// NAT action
message.setIndex(startReaderIndex, message.writerIndex());
final int startIndex = message.readerIndex();
- int length = deserializeCtHeader(message);
+ final int length = deserializeCtHeader(message);
processedCtActionsLength = processedCtActionsLength - length;
- NxActionNatBuilder nxActionNatBuilder = new NxActionNatBuilder();
message.skipBytes(2);
- nxActionNatBuilder.setFlags(readUint16(message));
+ final var nxActionNatBuilder = new NxActionNatBuilder()
+ .setFlags(readUint16(message));
- int rangePresent = message.readUnsignedShort();
+ final Uint16 rangePresent = readUint16(message);
nxActionNatBuilder.setRangePresent(rangePresent);
- if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEIPV4MIN.getIntValue())) {
- InetAddress address = InetAddresses.fromInteger((int)message.readUnsignedInt());
- nxActionNatBuilder.setIpAddressMin(IpAddressBuilder.getDefaultInstance(address.getHostAddress()));
+
+ final int rangeBits = rangePresent.toJava();
+ if ((rangeBits & NxActionNatRangePresent.NXNATRANGEIPV4MIN.getIntValue()) != 0) {
+ nxActionNatBuilder.setIpAddressMin(readIpv4Address(message));
}
- if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEIPV4MAX.getIntValue())) {
- InetAddress address = InetAddresses.fromInteger((int)message.readUnsignedInt());
- nxActionNatBuilder.setIpAddressMax(IpAddressBuilder.getDefaultInstance(address.getHostAddress()));
+ if ((rangeBits & NxActionNatRangePresent.NXNATRANGEIPV4MAX.getIntValue()) != 0) {
+ nxActionNatBuilder.setIpAddressMax(readIpv4Address(message));
}
- if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEPROTOMIN.getIntValue())) {
+ if ((rangeBits & NxActionNatRangePresent.NXNATRANGEPROTOMIN.getIntValue()) != 0) {
nxActionNatBuilder.setPortMin(readUint16(message));
}
- if (0 != (rangePresent & NxActionNatRangePresent.NXNATRANGEPROTOMAX.getIntValue())) {
+ if ((rangeBits & NxActionNatRangePresent.NXNATRANGEPROTOMAX.getIntValue()) != 0) {
nxActionNatBuilder.setPortMax(readUint16(message));
}
- NxActionNatCaseBuilder caseBuilder = new NxActionNatCaseBuilder();
- caseBuilder.setNxActionNat(nxActionNatBuilder.build());
- CtActionsBuilder ctActionsBuilder = new CtActionsBuilder();
- ctActionsBuilder.setOfpactActions(caseBuilder.build());
- ctActionsList.add(ctActionsBuilder.build());
- int pad = length - (message.readerIndex() - startIndex);
- message.skipBytes(pad);
+ ctActionsList.add(new CtActionsBuilder()
+ .setOfpactActions(new NxActionNatCaseBuilder()
+ .setNxActionNat(nxActionNatBuilder.build()).build())
+ .build());
+
+ // Padding
+ message.skipBytes(length - (message.readerIndex() - startIndex));
} else {
// only other possible action here is currently ct_mark
// reset indices
deserializeCtHeaderWithoutSubtype(message);
- NxActionCtMarkBuilder nxActionCtMarkBuilder = new NxActionCtMarkBuilder();
- nxActionCtMarkBuilder.setCtMark(readUint32(message));
+ ctActionsList.add(new CtActionsBuilder()
+ .setOfpactActions(new NxActionCtMarkCaseBuilder()
+ .setNxActionCtMark(new NxActionCtMarkBuilder()
+ .setCtMark(readUint32(message))
+ .build())
+ .build())
+ .build());
- NxActionCtMarkCaseBuilder caseBuilder = new NxActionCtMarkCaseBuilder();
- caseBuilder.setNxActionCtMark(nxActionCtMarkBuilder.build());
- CtActionsBuilder ctActionsBuilder = new CtActionsBuilder();
- ctActionsBuilder.setOfpactActions(caseBuilder.build());
- ctActionsList.add(ctActionsBuilder.build());
- // padding
- message.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES);
+ // Padding
+ message.skipBytes(Integer.BYTES);
}
}
nxActionConntrackBuilder.setCtActions(ctActionsList);
}
+ private static IpAddress readIpv4Address(final ByteBuf message) {
+ return new IpAddress(IetfInetUtil.INSTANCE.ipv4AddressFor(message.readInt()));
+ }
+
+ private static void writeIpv4Address(final ByteBuf outBuffer, final IpAddress ipAddress) {
+ if (ipAddress != null) {
+ outBuffer.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(ipAddress.getIpv4Address()));
+ }
+ }
+
private static short deserializeCtHeaderWithoutSubtype(final ByteBuf message) {
// size of experimenter type / size of set field code (in case of ct_mark)
- message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+ message.skipBytes(Short.BYTES);
// size of length
short length = message.readShort();
// vendor id / 00 01 d6 04 (in case of ct_mark)
- message.skipBytes(EncodeConstants.SIZE_OF_INT_IN_BYTES);
+ message.skipBytes(Integer.BYTES);
return length;
}
private static short deserializeCtHeader(final ByteBuf message) {
short length = deserializeCtHeaderWithoutSubtype(message);
// subtype
- message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
+ message.skipBytes(Short.BYTES);
return length;
}
}