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;
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());
final int rangeBits = rangePresent.toJava();
if ((rangeBits & NxActionNatRangePresent.NXNATRANGEIPV4MIN.getIntValue()) != 0) {
- InetAddress address = InetAddresses.fromInteger((int)message.readUnsignedInt());
- nxActionNatBuilder.setIpAddressMin(IpAddressBuilder.getDefaultInstance(address.getHostAddress()));
+ nxActionNatBuilder.setIpAddressMin(readIpv4Address(message));
}
if ((rangeBits & NxActionNatRangePresent.NXNATRANGEIPV4MAX.getIntValue()) != 0) {
- InetAddress address = InetAddresses.fromInteger((int)message.readUnsignedInt());
- nxActionNatBuilder.setIpAddressMax(IpAddressBuilder.getDefaultInstance(address.getHostAddress()));
+ nxActionNatBuilder.setIpAddressMax(readIpv4Address(message));
}
if ((rangeBits & NxActionNatRangePresent.NXNATRANGEPROTOMIN.getIntValue()) != 0) {
nxActionNatBuilder.setPortMin(readUint16(message));
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(Short.BYTES);