From 5e72621f9cce6287fc6ae98dcb662398d02246a7 Mon Sep 17 00:00:00 2001 From: Michal Polkorab Date: Thu, 19 Dec 2013 09:24:53 +0100 Subject: [PATCH] Fixed ipv6 address deserialization in match Signed-off-by: Michal Polkorab --- .../protocol/impl/util/MatchDeserializer.java | 16 +----- .../protocol/impl/util/MatchSerializer.java | 1 - .../impl/util/MatchDeserializerTest.java | 54 +++++++++++++++++++ 3 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializerTest.java diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java index 640fc9f5..097046f3 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java @@ -119,8 +119,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm. import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntriesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.Match; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.match.grouping.MatchBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.Joiner; @@ -131,8 +129,6 @@ import com.google.common.base.Joiner; */ public abstract class MatchDeserializer { - private static final Logger LOGGER = LoggerFactory.getLogger(MatchDeserializer.class); - /** * Creates match * @param in input ByteBuf @@ -289,7 +285,6 @@ public abstract class MatchDeserializer { break; case 11: matchEntriesBuilder.setOxmMatchField(Ipv4Src.class); - LOGGER.warn("IPV4address(ipv4src): received but possible wrong deserialization"); addIpv4AddressAugmentation(matchEntriesBuilder, in); if (hasMask) { addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); @@ -297,7 +292,6 @@ public abstract class MatchDeserializer { break; case 12: matchEntriesBuilder.setOxmMatchField(Ipv4Dst.class); - LOGGER.warn("IPV4address(ipv4dst): received but possible wrong deserialization"); addIpv4AddressAugmentation(matchEntriesBuilder, in); if (hasMask) { addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); @@ -347,7 +341,6 @@ public abstract class MatchDeserializer { break; case 22: matchEntriesBuilder.setOxmMatchField(ArpSpa.class); - LOGGER.warn("IPV4address(arpspa): received but possible wrong deserialization"); addIpv4AddressAugmentation(matchEntriesBuilder, in); if (hasMask) { addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); @@ -355,7 +348,6 @@ public abstract class MatchDeserializer { break; case 23: matchEntriesBuilder.setOxmMatchField(ArpTpa.class); - LOGGER.warn("IPV4address(arptpa): received but possible wrong deserialization"); addIpv4AddressAugmentation(matchEntriesBuilder, in); if (hasMask) { addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_INT_IN_BYTES); @@ -377,8 +369,6 @@ public abstract class MatchDeserializer { break; case 26: matchEntriesBuilder.setOxmMatchField(Ipv6Src.class); - // TODO - ipv6address - check format with tests - LOGGER.warn("IPV6address(Ipv6Src): received but possible wrong deserialization"); addIpv6AddressAugmentation(matchEntriesBuilder, in); if (hasMask) { addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); @@ -386,8 +376,6 @@ public abstract class MatchDeserializer { break; case 27: matchEntriesBuilder.setOxmMatchField(Ipv6Dst.class); - // TODO - ipv6address - check format with tests - LOGGER.warn("IPV6address(Ipv6Dst): received but possible wrong deserialization"); addIpv6AddressAugmentation(matchEntriesBuilder, in); if (hasMask) { addMaskAugmentation(matchEntriesBuilder, in, EncodeConstants.SIZE_OF_IPV6_ADDRESS_IN_BYTES); @@ -416,8 +404,6 @@ public abstract class MatchDeserializer { break; case 31: matchEntriesBuilder.setOxmMatchField(Ipv6NdTarget.class); - // TODO - ipv6address - check format with tests - LOGGER.warn("IPV6address(Ipv6NdTarget): received but possible wrong deserialization"); addIpv6AddressAugmentation(matchEntriesBuilder, in); break; case 32: @@ -512,7 +498,7 @@ public abstract class MatchDeserializer { Ipv6AddressMatchEntryBuilder ipv6AddressBuilder = new Ipv6AddressMatchEntryBuilder(); List groups = new ArrayList<>(); for (int i = 0; i < EncodeConstants.GROUPS_IN_IPV6_ADDRESS; i++) { - groups.add(String.format("X", in.readUnsignedShort())); + groups.add(String.format("%04X", in.readUnsignedShort())); } Joiner joiner = Joiner.on(":"); ipv6AddressBuilder.setIpv6Address(new Ipv6Address(joiner.join(groups))); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java index b22ec0de..3a26f4c5 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java @@ -305,7 +305,6 @@ public class MatchSerializer { } else if (field.isAssignableFrom(MplsLabel.class)) { fieldValue = 34; writeOxmFieldAndLength(out, fieldValue, false, EncodeConstants.SIZE_OF_INT_IN_BYTES); - LOGGER.warn("MplsLabel match entry: possible wrong length written (wrote 4 - maybe must be 3)"); out.writeInt(entry.getAugmentation(MplsLabelMatchEntry.class).getMplsLabel().intValue()); } else if (field.isAssignableFrom(MplsTc.class)) { fieldValue = 35; diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializerTest.java new file mode 100644 index 00000000..018feb1d --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializerTest.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.openflowjava.protocol.impl.util; + +import io.netty.buffer.ByteBuf; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv4AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Ipv6AddressMatchEntry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; + +/** + * @author michal.polkorab + * + */ +public class MatchDeserializerTest { + + /** + * Testing match deserialization + */ + @Test + public void testIpv4Address() { + ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("80 00 18 04 00 01 02 03"); + + List list = MatchDeserializer.createMatchEntry(buffer, 8); + MatchEntries entry = list.get(0); + Assert.assertEquals("Wrong Ipv4 address format", new Ipv4Address("0.1.2.3"), + entry.getAugmentation(Ipv4AddressMatchEntry.class).getIpv4Address()); + } + + /** + * Testing match deserialization + */ + @Test + public void testIpv6Address() { + ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("80 00 34 10 00 00 00 01 00 02 00 03 00 04 00 05 00 06 0F 07"); + + List list = MatchDeserializer.createMatchEntry(buffer, 20); + MatchEntries entry = list.get(0); + Assert.assertEquals("Wrong Ipv6 address format", new Ipv6Address("0000:0001:0002:0003:0004:0005:0006:0F07"), + entry.getAugmentation(Ipv6AddressMatchEntry.class).getIpv6Address()); + } + +} -- 2.36.6