From a4ca2b0e7cdbd1917edc94acf86e92a9f9969c99 Mon Sep 17 00:00:00 2001 From: Michal Polkorab Date: Fri, 19 Sep 2014 17:23:25 +0200 Subject: [PATCH] Bug 1254 - Added unit tests - + fixed MultipartReplyTranslator#getGroupActionsSupportBitmap() Change-Id: Ie05f26b366da6e2edaf5ca6392b80ce81c018734 Signed-off-by: Michal Polkorab --- .../translator/MultipartReplyTranslator.java | 33 +- .../GroupStatsResponseConvertorTest.java | 172 ++++++ .../GroupStatsResponseConvertorTest2.java | 181 ++++++ .../TableFeaturesReplyConvertorTest.java | 573 ++++++++++++++++++ .../MultipartReplyTranslatorTest.java | 232 +++++++ .../MultipartReplyTranslatorTest2.java | 214 +++++++ .../MultipartReplyTranslatorTest3.java | 373 ++++++++++++ 7 files changed, 1761 insertions(+), 17 deletions(-) create mode 100644 openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertorTest.java create mode 100644 openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertorTest2.java create mode 100644 openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesReplyConvertorTest.java create mode 100644 openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest.java create mode 100644 openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest2.java create mode 100644 openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest3.java diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslator.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslator.java index 12ae74a489..69674a31b4 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslator.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslator.java @@ -470,23 +470,22 @@ public class MultipartReplyTranslator implements IMDMessageTranslator supportActionByGroups = new ArrayList(); for(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType supportedActions : actionsSupported){ long supportActionBitmap = 0; - supportActionBitmap |= supportedActions.isOFPATOUTPUT()?(1 << 0): ~(1 << 0); - supportActionBitmap |= supportedActions.isOFPATCOPYTTLOUT()?(1 << 11): ~(1 << 11); - supportActionBitmap |= supportedActions.isOFPATCOPYTTLIN()?(1 << 12): ~(1 << 12); - supportActionBitmap |= supportedActions.isOFPATSETMPLSTTL()?(1 << 15): ~(1 << 15); - supportActionBitmap |= supportedActions.isOFPATDECMPLSTTL()?(1 << 16): ~(1 << 16); - supportActionBitmap |= supportedActions.isOFPATPUSHVLAN()?(1 << 16): ~(1 << 16); - supportActionBitmap |= supportedActions.isOFPATPOPVLAN()?(1 << 17): ~(1 << 17); - supportActionBitmap |= supportedActions.isOFPATPUSHMPLS()?(1 << 18): ~(1 << 18); - supportActionBitmap |= supportedActions.isOFPATPOPMPLS()?(1 << 19): ~(1 << 19); - supportActionBitmap |= supportedActions.isOFPATSETQUEUE()?(1 << 20): ~(1 << 20); - supportActionBitmap |= supportedActions.isOFPATGROUP()?(1 << 21): ~(1 << 21); - supportActionBitmap |= supportedActions.isOFPATSETNWTTL()?(1 << 22): ~(1 << 22); - supportActionBitmap |= supportedActions.isOFPATDECNWTTL()?(1 << 23): ~(1 << 23); - supportActionBitmap |= supportedActions.isOFPATSETFIELD()?(1 << 24): ~(1 << 24); - supportActionBitmap |= supportedActions.isOFPATPUSHPBB()?(1 << 25): ~(1 << 25); - supportActionBitmap |= supportedActions.isOFPATPOPPBB()?(1 << 26): ~(1 << 26); - supportActionBitmap |= supportedActions.isOFPATEXPERIMENTER()?(1 << 27): ~(1 << 27); + supportActionBitmap |= supportedActions.isOFPATOUTPUT()?(1 << 0): 0; + supportActionBitmap |= supportedActions.isOFPATCOPYTTLOUT()?(1 << 11): 0; + supportActionBitmap |= supportedActions.isOFPATCOPYTTLIN()?(1 << 12): 0; + supportActionBitmap |= supportedActions.isOFPATSETMPLSTTL()?(1 << 15): 0; + supportActionBitmap |= supportedActions.isOFPATDECMPLSTTL()?(1 << 16): 0; + supportActionBitmap |= supportedActions.isOFPATPUSHVLAN()?(1 << 17): 0; + supportActionBitmap |= supportedActions.isOFPATPOPVLAN()?(1 << 18): 0; + supportActionBitmap |= supportedActions.isOFPATPUSHMPLS()?(1 << 19): 0; + supportActionBitmap |= supportedActions.isOFPATPOPMPLS()?(1 << 20): 0; + supportActionBitmap |= supportedActions.isOFPATSETQUEUE()?(1 << 21): 0; + supportActionBitmap |= supportedActions.isOFPATGROUP()?(1 << 22): 0; + supportActionBitmap |= supportedActions.isOFPATSETNWTTL()?(1 << 23): 0; + supportActionBitmap |= supportedActions.isOFPATDECNWTTL()?(1 << 24): 0; + supportActionBitmap |= supportedActions.isOFPATSETFIELD()?(1 << 25): 0; + supportActionBitmap |= supportedActions.isOFPATPUSHPBB()?(1 << 26): 0; + supportActionBitmap |= supportedActions.isOFPATPOPPBB()?(1 << 27): 0; supportActionByGroups.add(Long.valueOf(supportActionBitmap)); } return supportActionByGroups; diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertorTest.java new file mode 100644 index 0000000000..df7a135460 --- /dev/null +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertorTest.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2014 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.openflowplugin.openflow.md.core.sal.convertor; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStatsBuilder; + +/** + * @author michal.polkorab + * + */ +public class GroupStatsResponseConvertorTest { + + GroupStatsResponseConvertor convertor = new GroupStatsResponseConvertor(); + + /** + * Test empty GroupStats conversion + */ + @Test + public void testEmptyGroupStats() { + List groupStats = new ArrayList<>(); + + List salGroupStats = convertor.toSALGroupStatsList(groupStats); + + Assert.assertEquals("Wrong group stats size", 0, salGroupStats.size()); + } + + /** + * Test single GroupStat conversion + */ + @Test + public void testSingleGroupStat() { + List groupStats = new ArrayList<>(); + GroupStatsBuilder statsBuilder = new GroupStatsBuilder(); + statsBuilder.setByteCount(new BigInteger("12345")); + statsBuilder.setDurationNsec(1000000L); + statsBuilder.setDurationSec(5000L); + statsBuilder.setGroupId(new GroupId(42L)); + statsBuilder.setPacketCount(new BigInteger("54321")); + statsBuilder.setRefCount(24L); + statsBuilder.setBucketStats(new ArrayList()); + groupStats.add(statsBuilder.build()); + + List salGroupStats = convertor.toSALGroupStatsList(groupStats); + + Assert.assertEquals("Wrong group stats size", 1, salGroupStats.size()); + org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply + .GroupStats stat = salGroupStats.get(0); + Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong ref-count", 24, stat.getRefCount().getValue().intValue()); + Assert.assertEquals("Wrong packet count", 54321, stat.getPacketCount().getValue().intValue()); + Assert.assertEquals("Wrong byte count", 12345, stat.getByteCount().getValue().intValue()); + Assert.assertEquals("Wrong duration sec", 5000, stat.getDuration().getSecond().getValue().intValue()); + Assert.assertEquals("Wrong duration n sec", 1000000, stat.getDuration().getNanosecond().getValue().intValue()); + Assert.assertEquals("Wrong bucket stats", 0, stat.getBuckets().getBucketCounter().size()); + } + + /** + * Test two GroupStats conversion + */ + @Test + public void testTwoGroupStats() { + List groupStats = new ArrayList<>(); + GroupStatsBuilder statsBuilder = new GroupStatsBuilder(); + statsBuilder.setByteCount(new BigInteger("12345")); + statsBuilder.setDurationNsec(1000000L); + statsBuilder.setDurationSec(5000L); + statsBuilder.setGroupId(new GroupId(42L)); + statsBuilder.setPacketCount(new BigInteger("54321")); + statsBuilder.setRefCount(24L); + statsBuilder.setBucketStats(new ArrayList()); + groupStats.add(statsBuilder.build()); + statsBuilder = new GroupStatsBuilder(); + statsBuilder.setByteCount(new BigInteger("1")); + statsBuilder.setDurationNsec(2L); + statsBuilder.setDurationSec(3L); + statsBuilder.setGroupId(new GroupId(4L)); + statsBuilder.setPacketCount(new BigInteger("5")); + statsBuilder.setRefCount(6L); + statsBuilder.setBucketStats(new ArrayList()); + groupStats.add(statsBuilder.build()); + + List salGroupStats = convertor.toSALGroupStatsList(groupStats); + + Assert.assertEquals("Wrong group stats size", 2, salGroupStats.size()); + org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply + .GroupStats stat = salGroupStats.get(0); + Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong ref-count", 24, stat.getRefCount().getValue().intValue()); + Assert.assertEquals("Wrong packet count", 54321, stat.getPacketCount().getValue().intValue()); + Assert.assertEquals("Wrong byte count", 12345, stat.getByteCount().getValue().intValue()); + Assert.assertEquals("Wrong duration sec", 5000, stat.getDuration().getSecond().getValue().intValue()); + Assert.assertEquals("Wrong duration n sec", 1000000, stat.getDuration().getNanosecond().getValue().intValue()); + Assert.assertEquals("Wrong bucket stats", 0, stat.getBuckets().getBucketCounter().size()); + stat = salGroupStats.get(1); + Assert.assertEquals("Wrong group-id", 4, stat.getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong key", 4, stat.getKey().getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong ref-count", 6, stat.getRefCount().getValue().intValue()); + Assert.assertEquals("Wrong packet count", 5, stat.getPacketCount().getValue().intValue()); + Assert.assertEquals("Wrong byte count", 1, stat.getByteCount().getValue().intValue()); + Assert.assertEquals("Wrong duration sec", 3, stat.getDuration().getSecond().getValue().intValue()); + Assert.assertEquals("Wrong duration n sec", 2, stat.getDuration().getNanosecond().getValue().intValue()); + Assert.assertEquals("Wrong bucket stats", 0, stat.getBuckets().getBucketCounter().size()); + } + + /** + * Test GroupStats with buckets conversion + */ + @Test + public void testGroupStatsWithBuckets() { + List groupStats = new ArrayList<>(); + GroupStatsBuilder statsBuilder = new GroupStatsBuilder(); + statsBuilder.setByteCount(new BigInteger("12345")); + statsBuilder.setDurationNsec(1000000L); + statsBuilder.setDurationSec(5000L); + statsBuilder.setGroupId(new GroupId(42L)); + statsBuilder.setPacketCount(new BigInteger("54321")); + statsBuilder.setRefCount(24L); + List bucketStats = new ArrayList<>(); + BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder(); + bucketStatsBuilder.setByteCount(new BigInteger("987")); + bucketStatsBuilder.setPacketCount(new BigInteger("654")); + bucketStats.add(bucketStatsBuilder.build()); + bucketStatsBuilder = new BucketStatsBuilder(); + bucketStatsBuilder.setByteCount(new BigInteger("123")); + bucketStatsBuilder.setPacketCount(new BigInteger("456")); + bucketStats.add(bucketStatsBuilder.build()); + statsBuilder.setBucketStats(bucketStats); + groupStats.add(statsBuilder.build()); + + List salGroupStats = convertor.toSALGroupStatsList(groupStats); + + Assert.assertEquals("Wrong group stats size", 1, salGroupStats.size()); + org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply + .GroupStats stat = salGroupStats.get(0); + Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong ref-count", 24, stat.getRefCount().getValue().intValue()); + Assert.assertEquals("Wrong packet count", 54321, stat.getPacketCount().getValue().intValue()); + Assert.assertEquals("Wrong byte count", 12345, stat.getByteCount().getValue().intValue()); + Assert.assertEquals("Wrong duration sec", 5000, stat.getDuration().getSecond().getValue().intValue()); + Assert.assertEquals("Wrong duration n sec", 1000000, stat.getDuration().getNanosecond().getValue().intValue()); + Assert.assertEquals("Wrong bucket stats", 2, stat.getBuckets().getBucketCounter().size()); + List list = stat.getBuckets().getBucketCounter(); + Assert.assertEquals("Wrong bucket-id", 0, list.get(0).getBucketId().getValue().intValue()); + Assert.assertEquals("Wrong bucket packet count", 654, list.get(0).getPacketCount().getValue().intValue()); + Assert.assertEquals("Wrong bucket byte count", 987, list.get(0).getByteCount().getValue().intValue()); + Assert.assertEquals("Wrong bucket-id", 1, list.get(1).getBucketId().getValue().intValue()); + Assert.assertEquals("Wrong bucket packet count", 456, list.get(1).getPacketCount().getValue().intValue()); + Assert.assertEquals("Wrong bucket byte count", 123, list.get(1).getByteCount().getValue().intValue()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertorTest2.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertorTest2.java new file mode 100644 index 0000000000..fec246da45 --- /dev/null +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/GroupStatsResponseConvertorTest2.java @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2014 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.openflowplugin.openflow.md.core.sal.convertor; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDescBuilder; + +/** + * @author michal.polkorab + * + */ +public class GroupStatsResponseConvertorTest2 { + + GroupStatsResponseConvertor convertor = new GroupStatsResponseConvertor(); + + /** + * Test empty GroupDescStats conversion + */ + @Test + public void test() { + List groupDescStats = new ArrayList<>(); + + List statsList = convertor.toSALGroupDescStatsList(groupDescStats, OpenflowVersion.OF13); + + Assert.assertEquals("Wrong groupDesc stats size", 0, statsList.size()); + } + + /** + * Test single GroupDescStat conversion without buckets + */ + @Test + public void testSingleGroupDescStat() { + List groupDescStats = new ArrayList<>(); + GroupDescBuilder builder = new GroupDescBuilder(); + builder.setType(GroupType.OFPGTALL); + builder.setGroupId(new GroupId(42L)); + builder.setBucketsList(new ArrayList()); + groupDescStats.add(builder.build()); + + List statsList = convertor.toSALGroupDescStatsList(groupDescStats, OpenflowVersion.OF13); + + Assert.assertEquals("Wrong groupDesc stats size", 1, statsList.size()); + GroupDescStats stat = statsList.get(0); + Assert.assertEquals("Wrong type", GroupTypes.GroupAll, stat.getGroupType()); + Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong buckets size", 0, stat.getBuckets().getBucket().size()); + } + + /** + * Test single GroupDescStats conversion + */ + @Test + public void testGroupDescStats() { + List groupDescStats = new ArrayList<>(); + GroupDescBuilder builder = new GroupDescBuilder(); + builder.setType(GroupType.OFPGTFF); + builder.setGroupId(new GroupId(42L)); + List bucketsList = new ArrayList<>(); + BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); + bucketsBuilder.setWeight(16); + bucketsBuilder.setWatchPort(new PortNumber(84L)); + bucketsBuilder.setWatchGroup(168L); + List actions = new ArrayList<>(); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(CopyTtlIn.class); + actions.add(actionBuilder.build()); + bucketsBuilder.setAction(actions); + bucketsList.add(bucketsBuilder.build()); + builder.setBucketsList(bucketsList); + groupDescStats.add(builder.build()); + builder = new GroupDescBuilder(); + builder.setType(GroupType.OFPGTINDIRECT); + builder.setGroupId(new GroupId(50L)); + bucketsList = new ArrayList<>(); + bucketsBuilder = new BucketsListBuilder(); + bucketsBuilder.setWeight(100); + bucketsBuilder.setWatchPort(new PortNumber(200L)); + bucketsBuilder.setWatchGroup(400L); + actions = new ArrayList<>(); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(CopyTtlOut.class); + actions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(DecNwTtl.class); + actions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(PopPbb.class); + actions.add(actionBuilder.build()); + bucketsBuilder.setAction(actions); + bucketsList.add(bucketsBuilder.build()); + bucketsBuilder = new BucketsListBuilder(); + bucketsBuilder.setWeight(5); + bucketsBuilder.setWatchPort(new PortNumber(10L)); + bucketsBuilder.setWatchGroup(15L); + actions = new ArrayList<>(); + bucketsBuilder.setAction(actions); + bucketsList.add(bucketsBuilder.build()); + builder.setBucketsList(bucketsList); + groupDescStats.add(builder.build()); + + List statsList = convertor.toSALGroupDescStatsList(groupDescStats, OpenflowVersion.OF13); + + Assert.assertEquals("Wrong groupDesc stats size", 2, statsList.size()); + GroupDescStats stat = statsList.get(0); + Assert.assertEquals("Wrong type", GroupTypes.GroupFf, stat.getGroupType()); + Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong buckets size", 1, stat.getBuckets().getBucket().size()); + Bucket bucket = stat.getBuckets().getBucket().get(0); + Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue()); + Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue()); + Assert.assertEquals("Wrong type", 16, bucket.getWeight().intValue()); + Assert.assertEquals("Wrong type", 168, bucket.getWatchGroup().intValue()); + Assert.assertEquals("Wrong type", 84, bucket.getWatchPort().intValue()); + Assert.assertEquals("Wrong type", 1, bucket.getAction().size()); + org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list + .Action action = bucket.getAction().get(0); + Assert.assertEquals("Wrong type", 0, action.getOrder().intValue()); + Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + + ".action.action.CopyTtlInCase", action.getAction().getImplementedInterface().getName()); + + stat = statsList.get(1); + Assert.assertEquals("Wrong type", GroupTypes.GroupIndirect, stat.getGroupType()); + Assert.assertEquals("Wrong group-id", 50, stat.getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong key", 50, stat.getKey().getGroupId().getValue().intValue()); + Assert.assertEquals("Wrong buckets size", 2, stat.getBuckets().getBucket().size()); + bucket = stat.getBuckets().getBucket().get(0); + Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue()); + Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue()); + Assert.assertEquals("Wrong type", 100, bucket.getWeight().intValue()); + Assert.assertEquals("Wrong type", 400, bucket.getWatchGroup().intValue()); + Assert.assertEquals("Wrong type", 200, bucket.getWatchPort().intValue()); + Assert.assertEquals("Wrong type", 3, bucket.getAction().size()); + action = bucket.getAction().get(0); + Assert.assertEquals("Wrong type", 0, action.getOrder().intValue()); + Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + + ".action.action.CopyTtlOutCase", action.getAction().getImplementedInterface().getName()); + action = bucket.getAction().get(1); + Assert.assertEquals("Wrong type", 1, action.getOrder().intValue()); + Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + + ".action.action.DecNwTtlCase", action.getAction().getImplementedInterface().getName()); + action = bucket.getAction().get(2); + Assert.assertEquals("Wrong type", 2, action.getOrder().intValue()); + Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112" + + ".action.action.PopPbbActionCase", action.getAction().getImplementedInterface().getName()); + bucket = stat.getBuckets().getBucket().get(1); + Assert.assertEquals("Wrong type", 1, bucket.getKey().getBucketId().getValue().intValue()); + Assert.assertEquals("Wrong type", 1, bucket.getBucketId().getValue().intValue()); + Assert.assertEquals("Wrong type", 5, bucket.getWeight().intValue()); + Assert.assertEquals("Wrong type", 15, bucket.getWatchGroup().intValue()); + Assert.assertEquals("Wrong type", 10, bucket.getWatchPort().intValue()); + Assert.assertEquals("Wrong type", 0, bucket.getAction().size()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesReplyConvertorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesReplyConvertorTest.java new file mode 100644 index 0000000000..64d0daf3c9 --- /dev/null +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/TableFeaturesReplyConvertorTest.java @@ -0,0 +1,573 @@ +/* + * Copyright (c) 2014 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.openflowplugin.openflow.md.core.sal.convertor; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ActionRelatedTableFeaturePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.InstructionRelatedTableFeaturePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NextTableRelatedTableFeaturePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeatureProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmRelatedTableFeaturePropertyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIds; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.table.features.properties.container.table.feature.properties.NextTableIdsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.InstructionBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpEcn; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.IpProto; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Ipv6Exthdr; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanPcp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.MultipartReplyTableFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features._case.multipart.reply.table.features.TableFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeatureProperties; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.grouping.TableFeaturePropertiesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.set.field.match.SetFieldMatch; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfield; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldMiss; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Instructions; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsMiss; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableMiss; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Wildcards; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfield; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldMiss; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures; + +/** + * @author michal.polkorab + * + */ +public class TableFeaturesReplyConvertorTest { + + /** + * Incorrect / empty input test + */ + @Test + public void test() { + List list = TableFeaturesReplyConvertor.toTableFeaturesReply(null); + Assert.assertEquals("Returned list is not empty", 0, list.size()); + } + + /** + * Incorrect / empty input test + */ + @Test + public void test2() { + MultipartReplyTableFeaturesBuilder builder = new MultipartReplyTableFeaturesBuilder(); + List list = TableFeaturesReplyConvertor.toTableFeaturesReply(builder.build()); + Assert.assertEquals("Returned list is not empty", 0, list.size()); + } + + /** + * Test correct input - without table properties + */ + @Test + public void testWithMPTableFeature() { + MultipartReplyTableFeaturesBuilder builder = new MultipartReplyTableFeaturesBuilder(); + List features = new ArrayList<>(); + TableFeaturesBuilder featuresBuilder = new TableFeaturesBuilder(); + featuresBuilder.setTableId((short) 5); + featuresBuilder.setName("Aloha"); + byte[] metaMatch = new byte[]{0, 1, 2, 3, 4, 5, 6, 7}; + featuresBuilder.setMetadataMatch(metaMatch); + byte[] metaWrite = new byte[]{8, 9, 10, 11, 12, 13, 14, 15}; + featuresBuilder.setMetadataWrite(metaWrite); + featuresBuilder.setConfig(new TableConfig(false)); + featuresBuilder.setMaxEntries(42L); + features.add(featuresBuilder.build()); + builder.setTableFeatures(features); + List list = TableFeaturesReplyConvertor.toTableFeaturesReply(builder.build()); + Assert.assertEquals("Returned empty list", 1, list.size()); + TableFeatures feature = list.get(0); + Assert.assertEquals("Wrong table-id", 5, feature.getTableId().intValue()); + Assert.assertEquals("Wrong name", "Aloha", feature.getName()); + Assert.assertEquals("Wrong metadata match", new BigInteger(1, metaMatch), feature.getMetadataMatch()); + Assert.assertEquals("Wrong metadata write", new BigInteger(1, metaWrite), feature.getMetadataWrite()); + Assert.assertEquals("Wrong config", false, feature.getConfig().isDEPRECATEDMASK()); + Assert.assertEquals("Wrong max-entries", 42, feature.getMaxEntries().intValue()); + Assert.assertEquals("Wrong properties", 0, feature.getTableProperties().getTableFeatureProperties().size()); + } + + /** + * Test correct input + */ + @Test + public void testWithMPTableFeatureWithProperties() { + MultipartReplyTableFeaturesBuilder builder = new MultipartReplyTableFeaturesBuilder(); + List features = new ArrayList<>(); + TableFeaturesBuilder featuresBuilder = new TableFeaturesBuilder(); + featuresBuilder.setTableId((short) 5); + featuresBuilder.setName("Aloha"); + byte[] metaMatch = new byte[]{0, 1, 2, 3, 4, 5, 6, 7}; + featuresBuilder.setMetadataMatch(metaMatch); + byte[] metaWrite = new byte[]{8, 9, 10, 11, 12, 13, 14, 15}; + featuresBuilder.setMetadataWrite(metaWrite); + featuresBuilder.setConfig(new TableConfig(false)); + featuresBuilder.setMaxEntries(42L); + List properties = new ArrayList<>(); + TableFeaturePropertiesBuilder propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTNEXTTABLES); + NextTableRelatedTableFeaturePropertyBuilder nextPropBuilder = + new NextTableRelatedTableFeaturePropertyBuilder(); + List nextIds = new ArrayList<>(); + nextIds.add(new NextTableIdsBuilder().setTableId((short) 1).build()); + nextIds.add(new NextTableIdsBuilder().setTableId((short) 2).build()); + nextPropBuilder.setNextTableIds(nextIds); + propBuilder.addAugmentation(NextTableRelatedTableFeatureProperty.class, nextPropBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTNEXTTABLESMISS); + nextPropBuilder = new NextTableRelatedTableFeaturePropertyBuilder(); + nextIds = new ArrayList<>(); + nextIds.add(new NextTableIdsBuilder().setTableId((short) 3).build()); + nextPropBuilder.setNextTableIds(nextIds); + propBuilder.addAugmentation(NextTableRelatedTableFeatureProperty.class, nextPropBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTINSTRUCTIONS); + InstructionRelatedTableFeaturePropertyBuilder insPropBuilder = + new InstructionRelatedTableFeaturePropertyBuilder(); + List insIds = new ArrayList<>(); + InstructionBuilder insBuilder = new InstructionBuilder(); + insBuilder.setType(WriteActions.class); + insIds.add(insBuilder.build()); + insBuilder = new InstructionBuilder(); + insBuilder.setType(GotoTable.class); + insIds.add(insBuilder.build()); + insPropBuilder.setInstruction(insIds); + propBuilder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insPropBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTINSTRUCTIONSMISS); + insPropBuilder = new InstructionRelatedTableFeaturePropertyBuilder(); + insIds = new ArrayList<>(); + insBuilder = new InstructionBuilder(); + insBuilder.setType(WriteMetadata.class); + insIds.add(insBuilder.build()); + insBuilder = new InstructionBuilder(); + insBuilder.setType(ApplyActions.class); + insIds.add(insBuilder.build()); + insBuilder = new InstructionBuilder(); + insBuilder.setType(Meter.class); + insIds.add(insBuilder.build()); + insBuilder = new InstructionBuilder(); + insBuilder.setType(ClearActions.class); + insIds.add(insBuilder.build()); + insBuilder = new InstructionBuilder(); + insBuilder.setType(GotoTable.class); + insIds.add(insBuilder.build()); + insPropBuilder.setInstruction(insIds); + propBuilder.addAugmentation(InstructionRelatedTableFeatureProperty.class, insPropBuilder.build()); + properties.add(propBuilder.build()); + featuresBuilder.setTableFeatureProperties(properties); + features.add(featuresBuilder.build()); + featuresBuilder = new TableFeaturesBuilder(); + featuresBuilder.setTableId((short) 6); + featuresBuilder.setName("Mahalo"); + byte[] metaMatch2 = new byte[]{8, 9, 10, 11, 12, 13, 14, 15}; + featuresBuilder.setMetadataMatch(metaMatch2); + byte[] metaWrite2 = new byte[]{0, 1, 2, 3, 4, 5, 6, 7}; + featuresBuilder.setMetadataWrite(metaWrite2); + featuresBuilder.setConfig(new TableConfig(false)); + featuresBuilder.setMaxEntries(24L); + properties = new ArrayList<>(); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTMATCH); + OxmRelatedTableFeaturePropertyBuilder oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); + List entries = new ArrayList<>(); + MatchEntriesBuilder entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(InPhyPort.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(InPort.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + oxmBuilder.setMatchEntries(entries); + propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYSETFIELD); + oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); + entries = new ArrayList<>(); + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(IpProto.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(IpEcn.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + oxmBuilder.setMatchEntries(entries); + propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITESETFIELD); + oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); + entries = new ArrayList<>(); + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(Ipv6Exthdr.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(VlanVid.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + oxmBuilder.setMatchEntries(entries); + propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITESETFIELDMISS); + oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); + entries = new ArrayList<>(); + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(VlanPcp.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(TcpSrc.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + oxmBuilder.setMatchEntries(entries); + propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYSETFIELDMISS); + oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); + entries = new ArrayList<>(); + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(UdpSrc.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(UdpDst.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + oxmBuilder.setMatchEntries(entries); + propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTWILDCARDS); + oxmBuilder = new OxmRelatedTableFeaturePropertyBuilder(); + entries = new ArrayList<>(); + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(EthSrc.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + entriesBuilder = new MatchEntriesBuilder(); + entriesBuilder.setOxmClass(OpenflowBasicClass.class); + entriesBuilder.setOxmMatchField(EthDst.class); + entriesBuilder.setHasMask(false); + entries.add(entriesBuilder.build()); + oxmBuilder.setMatchEntries(entries); + propBuilder.addAugmentation(OxmRelatedTableFeatureProperty.class, oxmBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYACTIONS); + ActionRelatedTableFeaturePropertyBuilder actBuilder = new ActionRelatedTableFeaturePropertyBuilder(); + List actions = new ArrayList<>(); + ActionBuilder actionBuilder = new ActionBuilder(); + actionBuilder.setType(Output.class); + actions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(PopPbb.class); + actions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetNwTtl.class); + actions.add(actionBuilder.build()); + actBuilder.setAction(actions); + propBuilder.addAugmentation(ActionRelatedTableFeatureProperty.class, actBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTAPPLYACTIONSMISS); + actBuilder = new ActionRelatedTableFeaturePropertyBuilder(); + actions = new ArrayList<>(); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(Group.class); + actions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(CopyTtlIn.class); + actions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(CopyTtlOut.class); + actions.add(actionBuilder.build()); + actBuilder.setAction(actions); + propBuilder.addAugmentation(ActionRelatedTableFeatureProperty.class, actBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITEACTIONS); + actBuilder = new ActionRelatedTableFeaturePropertyBuilder(); + actions = new ArrayList<>(); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetMplsTtl.class); + actions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(DecMplsTtl.class); + actions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(PushVlan.class); + actions.add(actionBuilder.build()); + actBuilder.setAction(actions); + propBuilder.addAugmentation(ActionRelatedTableFeatureProperty.class, actBuilder.build()); + properties.add(propBuilder.build()); + propBuilder = new TableFeaturePropertiesBuilder(); + propBuilder.setType(TableFeaturesPropType.OFPTFPTWRITEACTIONSMISS); + actBuilder = new ActionRelatedTableFeaturePropertyBuilder(); + actions = new ArrayList<>(); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(PopVlan.class); + actions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(PushPbb.class); + actions.add(actionBuilder.build()); + actionBuilder = new ActionBuilder(); + actionBuilder.setType(SetField.class); + actions.add(actionBuilder.build()); + actBuilder.setAction(actions); + propBuilder.addAugmentation(ActionRelatedTableFeatureProperty.class, actBuilder.build()); + properties.add(propBuilder.build()); + featuresBuilder.setTableFeatureProperties(properties); + features.add(featuresBuilder.build()); + builder.setTableFeatures(features); + + List list = TableFeaturesReplyConvertor.toTableFeaturesReply(builder.build()); + + Assert.assertEquals("Returned empty list", 2, list.size()); + TableFeatures feature = list.get(0); + Assert.assertEquals("Wrong table-id", 5, feature.getTableId().intValue()); + Assert.assertEquals("Wrong name", "Aloha", feature.getName()); + Assert.assertEquals("Wrong metadata match", new BigInteger(1, metaMatch), feature.getMetadataMatch()); + Assert.assertEquals("Wrong metadata write", new BigInteger(1, metaWrite), feature.getMetadataWrite()); + Assert.assertEquals("Wrong config", false, feature.getConfig().isDEPRECATEDMASK()); + Assert.assertEquals("Wrong max-entries", 42, feature.getMaxEntries().intValue()); + Assert.assertEquals("Wrong properties", 4, feature.getTableProperties().getTableFeatureProperties().size()); + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.table.features.table.properties + .TableFeatureProperties property = feature.getTableProperties().getTableFeatureProperties().get(0); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTable", + property.getTableFeaturePropType().getImplementedInterface().getName()); + NextTable propType = (NextTable) property.getTableFeaturePropType(); + List ids = propType.getTables().getTableIds(); + Assert.assertEquals("Wrong next table-id size", 2, ids.size()); + Assert.assertEquals("Wrong next-registry-id", 1, ids.get(0).intValue()); + Assert.assertEquals("Wrong next-registry-id", 2, ids.get(1).intValue()); + property = feature.getTableProperties().getTableFeatureProperties().get(1); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.NextTableMiss", + property.getTableFeaturePropType().getImplementedInterface().getName()); + NextTableMiss propType2 = (NextTableMiss) property.getTableFeaturePropType(); + ids = propType2.getTablesMiss().getTableIds(); + Assert.assertEquals("Wrong next table-id size", 1, ids.size()); + Assert.assertEquals("Wrong next-registry-id", 3, ids.get(0).intValue()); + property = feature.getTableProperties().getTableFeatureProperties().get(2); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Instructions", + property.getTableFeaturePropType().getImplementedInterface().getName()); + Instructions propType3 = (Instructions) property.getTableFeaturePropType(); + List instructionIds = propType3.getInstructions().getInstruction(); + Assert.assertEquals("Wrong instruction-ids size", 2, instructionIds.size()); + Assert.assertEquals("Wrong instruction-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteActionsCase", + instructionIds.get(0).getInstruction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong instruction-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase", + instructionIds.get(1).getInstruction().getImplementedInterface().getName()); + property = feature.getTableProperties().getTableFeatureProperties().get(3); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.InstructionsMiss", + property.getTableFeaturePropType().getImplementedInterface().getName()); + InstructionsMiss propType4 = (InstructionsMiss) property.getTableFeaturePropType(); + instructionIds = propType4.getInstructionsMiss().getInstruction(); + Assert.assertEquals("Wrong instruction-ids size", 5, instructionIds.size()); + Assert.assertEquals("Wrong instruction-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.WriteMetadataCase", + instructionIds.get(0).getInstruction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong instruction-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase", + instructionIds.get(1).getInstruction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong instruction-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.MeterCase", + instructionIds.get(2).getInstruction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong instruction-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ClearActionsCase", + instructionIds.get(3).getInstruction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong instruction-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCase", + instructionIds.get(4).getInstruction().getImplementedInterface().getName()); + feature = list.get(1); + Assert.assertEquals("Wrong table-id", 6, feature.getTableId().intValue()); + Assert.assertEquals("Wrong name", "Mahalo", feature.getName()); + Assert.assertEquals("Wrong metadata match", new BigInteger(1, metaMatch2), feature.getMetadataMatch()); + Assert.assertEquals("Wrong metadata write", new BigInteger(1, metaWrite2), feature.getMetadataWrite()); + Assert.assertEquals("Wrong config", false, feature.getConfig().isDEPRECATEDMASK()); + Assert.assertEquals("Wrong max-entries", 24, feature.getMaxEntries().intValue()); + Assert.assertEquals("Wrong properties", 10, feature.getTableProperties().getTableFeatureProperties().size()); + property = feature.getTableProperties().getTableFeatureProperties().get(0); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Match", + property.getTableFeaturePropType().getImplementedInterface().getName()); + Match propType5 = (Match) property.getTableFeaturePropType(); + List fieldMatch = propType5.getMatchSetfield().getSetFieldMatch(); + Assert.assertEquals("Wrong match-entry-ids size", 2, fieldMatch.size()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPhyPort", + fieldMatch.get(0).getMatchType().getName()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.InPort", + fieldMatch.get(1).getMatchType().getName()); + property = feature.getTableProperties().getTableFeatureProperties().get(1); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfield", + property.getTableFeaturePropType().getImplementedInterface().getName()); + ApplySetfield propType6 = (ApplySetfield) property.getTableFeaturePropType(); + fieldMatch = propType6.getApplySetfield().getSetFieldMatch(); + Assert.assertEquals("Wrong match-entry-ids size", 2, fieldMatch.size()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpProto", + fieldMatch.get(0).getMatchType().getName()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.IpEcn", + fieldMatch.get(1).getMatchType().getName()); + property = feature.getTableProperties().getTableFeatureProperties().get(2); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfield", + property.getTableFeaturePropType().getImplementedInterface().getName()); + WriteSetfield propType7 = (WriteSetfield) property.getTableFeaturePropType(); + fieldMatch = propType7.getWriteSetfield().getSetFieldMatch(); + Assert.assertEquals("Wrong match-entry-ids size", 2, fieldMatch.size()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.Ipv6Exthdr", + fieldMatch.get(0).getMatchType().getName()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanVid", + fieldMatch.get(1).getMatchType().getName()); + property = feature.getTableProperties().getTableFeatureProperties().get(3); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteSetfieldMiss", + property.getTableFeaturePropType().getImplementedInterface().getName()); + WriteSetfieldMiss propType8 = (WriteSetfieldMiss) property.getTableFeaturePropType(); + fieldMatch = propType8.getWriteSetfieldMiss().getSetFieldMatch(); + Assert.assertEquals("Wrong match-entry-ids size", 2, fieldMatch.size()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.VlanPcp", + fieldMatch.get(0).getMatchType().getName()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TcpSrc", + fieldMatch.get(1).getMatchType().getName()); + property = feature.getTableProperties().getTableFeatureProperties().get(4); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplySetfieldMiss", + property.getTableFeaturePropType().getImplementedInterface().getName()); + ApplySetfieldMiss propType9 = (ApplySetfieldMiss) property.getTableFeaturePropType(); + fieldMatch = propType9.getApplySetfieldMiss().getSetFieldMatch(); + Assert.assertEquals("Wrong match-entry-ids size", 2, fieldMatch.size()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpSrc", + fieldMatch.get(0).getMatchType().getName()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.UdpDst", + fieldMatch.get(1).getMatchType().getName()); + property = feature.getTableProperties().getTableFeatureProperties().get(5); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.Wildcards", + property.getTableFeaturePropType().getImplementedInterface().getName()); + Wildcards propType10 = (Wildcards) property.getTableFeaturePropType(); + fieldMatch = propType10.getWildcardSetfield().getSetFieldMatch(); + Assert.assertEquals("Wrong match-entry-ids size", 2, fieldMatch.size()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthSrc", + fieldMatch.get(0).getMatchType().getName()); + Assert.assertEquals("Wrong match-entry-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.EthDst", + fieldMatch.get(1).getMatchType().getName()); + property = feature.getTableProperties().getTableFeatureProperties().get(6); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActions", + property.getTableFeaturePropType().getImplementedInterface().getName()); + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type + .ApplyActions propType11 = (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActions) property.getTableFeaturePropType(); + List actionsList = propType11.getApplyActions().getAction(); + Assert.assertEquals("Wrong actions-ids size", 3, actionsList.size()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase", + actionsList.get(0).getAction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase", + actionsList.get(1).getAction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCase", + actionsList.get(2).getAction().getImplementedInterface().getName()); + property = feature.getTableProperties().getTableFeatureProperties().get(7); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.ApplyActionsMiss", + property.getTableFeaturePropType().getImplementedInterface().getName()); + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type + .ApplyActionsMiss propType12 = (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type + .ApplyActionsMiss) property.getTableFeaturePropType(); + actionsList = propType12.getApplyActionsMiss().getAction(); + Assert.assertEquals("Wrong actions-ids size", 3, actionsList.size()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase", + actionsList.get(0).getAction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase", + actionsList.get(1).getAction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCase", + actionsList.get(2).getAction().getImplementedInterface().getName()); + property = feature.getTableProperties().getTableFeatureProperties().get(8); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActions", + property.getTableFeaturePropType().getImplementedInterface().getName()); + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type + .WriteActions propType13 = (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type + .WriteActions) property.getTableFeaturePropType(); + actionsList = propType13.getWriteActions().getAction(); + Assert.assertEquals("Wrong actions-ids size", 3, actionsList.size()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase", + actionsList.get(0).getAction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCase", + actionsList.get(1).getAction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase", + actionsList.get(2).getAction().getImplementedInterface().getName()); + property = feature.getTableProperties().getTableFeatureProperties().get(9); + Assert.assertEquals("Wrong property type", "org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type.WriteActionsMiss", + property.getTableFeaturePropType().getImplementedInterface().getName()); + org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type + .WriteActionsMiss propType14 = (org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.feature.prop.type.table.feature.prop.type + .WriteActionsMiss) property.getTableFeaturePropType(); + actionsList = propType14.getWriteActionsMiss().getAction(); + Assert.assertEquals("Wrong actions-ids size", 3, actionsList.size()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase", + actionsList.get(0).getAction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCase", + actionsList.get(1).getAction().getImplementedInterface().getName()); + Assert.assertEquals("Wrong actions-id", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase", + actionsList.get(2).getAction().getImplementedInterface().getName()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest.java new file mode 100644 index 0000000000..7fd306b4a8 --- /dev/null +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest.java @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2014 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.openflowplugin.openflow.md.core.translator; + +import static org.mockito.Mockito.when; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher; +import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor; +import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OxmMatchType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.match.grouping.MatchBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * @author michal.polkorab + * + */ +public class MultipartReplyTranslatorTest { + + @Mock SwitchConnectionDistinguisher cookie; + @Mock SessionContext sc; + @Mock ConnectionConductor conductor; + @Mock GetFeaturesOutput features; + + MultipartReplyTranslator translator = new MultipartReplyTranslator(); + + /** + * Initializes mocks + */ + @Before + public void startUp() { + MockitoAnnotations.initMocks(this); + when(sc.getPrimaryConductor()).thenReturn(conductor); + when(conductor.getVersion()).thenReturn((short) EncodeConstants.OF13_VERSION_ID); + when(sc.getFeatures()).thenReturn(features); + when(features.getDatapathId()).thenReturn(new BigInteger("42")); + } + + /** + * Test with null and incorrect message + */ + @Test + public void test() { + List list = translator.translate(cookie, sc, null); + + Assert.assertEquals("Wrong list size", 0, list.size()); + HelloMessageBuilder helloBuilder = new HelloMessageBuilder(); + list = translator.translate(cookie, sc, helloBuilder.build()); + Assert.assertEquals("Wrong list size", 0, list.size()); + } + + /** + * Test with experimenter MultipartReply message + */ + @Test + public void testExperimenterCase() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPEXPERIMENTER); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 0, list.size()); + } + + /** + * Test MultipartReply message with empty flow stats + */ + @Test + public void testEmptyFlowCase() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPFLOW); + + MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder(); + MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder(); + List flowStats = new ArrayList<>(); + flowBuilder.setFlowStats(flowStats); + caseBuilder.setMultipartReplyFlow(flowBuilder.build()); + mpBuilder.setMultipartReplyBody(caseBuilder.build()); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 1, list.size()); + FlowsStatisticsUpdate flowUpdate = (FlowsStatisticsUpdate) list.get(0); + Assert.assertEquals("Wrong node-id", "openflow:42", flowUpdate.getId().getValue()); + Assert.assertEquals("Wrong more-replies", false, flowUpdate.isMoreReplies()); + Assert.assertEquals("Wrong transaction-id", 123, flowUpdate.getTransactionId().getValue().intValue()); + List mapList = flowUpdate.getFlowAndStatisticsMapList(); + Assert.assertEquals("Wrong flow stats size", 0, mapList.size()); + } + + /** + * Test with experimenter MultipartReply message + */ + @Test + public void testFlowCase() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPFLOW); + + MultipartReplyFlowCaseBuilder caseBuilder = new MultipartReplyFlowCaseBuilder(); + MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder(); + List flowStats = new ArrayList<>(); + FlowStatsBuilder statsBuilder = new FlowStatsBuilder(); + statsBuilder.setTableId((short) 1); + statsBuilder.setDurationSec(2L); + statsBuilder.setDurationNsec(3L); + statsBuilder.setPriority(4); + statsBuilder.setIdleTimeout(5); + statsBuilder.setHardTimeout(6); + FlowModFlags flags = new FlowModFlags(true, false, true, false, true); + statsBuilder.setFlags(flags); + statsBuilder.setCookie(new BigInteger("7")); + statsBuilder.setPacketCount(new BigInteger("8")); + statsBuilder.setByteCount(new BigInteger("9")); + MatchBuilder matchBuilder = new MatchBuilder(); + matchBuilder.setType(OxmMatchType.class); + matchBuilder.setMatchEntries(new ArrayList()); + statsBuilder.setMatch(matchBuilder.build()); + statsBuilder.setInstruction(new ArrayList()); + flowStats.add(statsBuilder.build()); + statsBuilder = new FlowStatsBuilder(); + statsBuilder.setTableId((short) 10); + statsBuilder.setDurationSec(20L); + statsBuilder.setDurationNsec(30L); + statsBuilder.setPriority(40); + statsBuilder.setIdleTimeout(50); + statsBuilder.setHardTimeout(60); + flags = new FlowModFlags(false, true, false, true, false); + statsBuilder.setFlags(flags); + statsBuilder.setCookie(new BigInteger("70")); + statsBuilder.setPacketCount(new BigInteger("80")); + statsBuilder.setByteCount(new BigInteger("90")); + matchBuilder = new MatchBuilder(); + matchBuilder.setType(OxmMatchType.class); + matchBuilder.setMatchEntries(new ArrayList()); + statsBuilder.setMatch(matchBuilder.build()); + statsBuilder.setInstruction(new ArrayList()); + flowStats.add(statsBuilder.build()); + flowBuilder.setFlowStats(flowStats); + caseBuilder.setMultipartReplyFlow(flowBuilder.build()); + mpBuilder.setMultipartReplyBody(caseBuilder.build()); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 1, list.size()); + FlowsStatisticsUpdate flowUpdate = (FlowsStatisticsUpdate) list.get(0); + Assert.assertEquals("Wrong node-id", "openflow:42", flowUpdate.getId().getValue()); + Assert.assertEquals("Wrong more-replies", false, flowUpdate.isMoreReplies()); + Assert.assertEquals("Wrong transaction-id", 123, flowUpdate.getTransactionId().getValue().intValue()); + List mapList = flowUpdate.getFlowAndStatisticsMapList(); + Assert.assertEquals("Wrong flow stats size", 2, mapList.size()); + FlowAndStatisticsMapList stat = mapList.get(0); + Assert.assertEquals("Wrong table-id", 1, stat.getTableId().intValue()); + Assert.assertEquals("Wrong duration sec", 2, stat.getDuration().getSecond().getValue().intValue()); + Assert.assertEquals("Wrong duration n sec", 3, stat.getDuration().getNanosecond().getValue().intValue()); + Assert.assertEquals("Wrong priority", 4, stat.getPriority().intValue()); + Assert.assertEquals("Wrong idle-timeout", 5, stat.getIdleTimeout().intValue()); + Assert.assertEquals("Wrong hard-timeout", 6, stat.getHardTimeout().intValue()); + org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags expectedFlags = + new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026 + .FlowModFlags(!flags.isOFPFFCHECKOVERLAP(), !flags.isOFPFFNOBYTCOUNTS(), !flags.isOFPFFNOPKTCOUNTS(), + !flags.isOFPFFRESETCOUNTS(), !flags.isOFPFFSENDFLOWREM()); + Assert.assertEquals("Wrong flags", expectedFlags, stat.getFlags()); + Assert.assertEquals("Wrong cookie", 7, stat.getCookie().getValue().intValue()); + Assert.assertEquals("Wrong packet count", 8, stat.getPacketCount().getValue().intValue()); + Assert.assertEquals("Wrong byte count", 9, stat.getByteCount().getValue().intValue()); + org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder emptyMatchBuilder = + new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder(); + Match emptyMatch = emptyMatchBuilder.build(); + Assert.assertEquals("Wrong match", emptyMatch, stat.getMatch()); + Assert.assertEquals("Wrong instructions", 0, stat.getInstructions().getInstruction().size()); + stat = mapList.get(1); + Assert.assertEquals("Wrong table-id", 10, stat.getTableId().intValue()); + Assert.assertEquals("Wrong duration sec", 20, stat.getDuration().getSecond().getValue().intValue()); + Assert.assertEquals("Wrong duration n sec", 30, stat.getDuration().getNanosecond().getValue().intValue()); + Assert.assertEquals("Wrong priority", 40, stat.getPriority().intValue()); + Assert.assertEquals("Wrong idle-timeout", 50, stat.getIdleTimeout().intValue()); + Assert.assertEquals("Wrong hard-timeout", 60, stat.getHardTimeout().intValue()); + expectedFlags = new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026 + .FlowModFlags(flags.isOFPFFCHECKOVERLAP(), flags.isOFPFFNOBYTCOUNTS(), flags.isOFPFFNOPKTCOUNTS(), + flags.isOFPFFRESETCOUNTS(), flags.isOFPFFSENDFLOWREM()); + Assert.assertEquals("Wrong flags", expectedFlags, stat.getFlags()); + Assert.assertEquals("Wrong cookie", 70, stat.getCookie().getValue().intValue()); + Assert.assertEquals("Wrong packet count", 80, stat.getPacketCount().getValue().intValue()); + Assert.assertEquals("Wrong byte count", 90, stat.getByteCount().getValue().intValue()); + Assert.assertEquals("Wrong match", emptyMatch, stat.getMatch()); + Assert.assertEquals("Wrong instructions", 0, stat.getInstructions().getInstruction().size()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest2.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest2.java new file mode 100644 index 0000000000..627d119c64 --- /dev/null +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest2.java @@ -0,0 +1,214 @@ +/* + * Copyright (c) 2014 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.openflowplugin.openflow.md.core.translator; + +import static org.mockito.Mockito.when; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher; +import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor; +import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.AggregateFlowStatisticsUpdate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupFeaturesUpdated; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterFeaturesUpdated; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ActionType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupCapabilities; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupTypes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandTypeBitmap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupFeaturesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.aggregate._case.MultipartReplyAggregateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.features._case.MultipartReplyGroupFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.features._case.MultipartReplyMeterFeaturesBuilder; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * @author michal.polkorab + * + */ +public class MultipartReplyTranslatorTest2 { + + @Mock SwitchConnectionDistinguisher cookie; + @Mock SessionContext sc; + @Mock ConnectionConductor conductor; + @Mock GetFeaturesOutput features; + + MultipartReplyTranslator translator = new MultipartReplyTranslator(); + + /** + * Initializes mocks + */ + @Before + public void startUp() { + MockitoAnnotations.initMocks(this); + when(sc.getPrimaryConductor()).thenReturn(conductor); + when(conductor.getVersion()).thenReturn((short) EncodeConstants.OF13_VERSION_ID); + when(sc.getFeatures()).thenReturn(features); + when(features.getDatapathId()).thenReturn(new BigInteger("42")); + } + + /** + * Test MultipartReply message with aggregate stat + */ + @Test + public void testAggregateCase() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPAGGREGATE); + + MultipartReplyAggregateCaseBuilder caseBuilder = new MultipartReplyAggregateCaseBuilder(); + MultipartReplyAggregateBuilder aggBuilder = new MultipartReplyAggregateBuilder(); + aggBuilder.setByteCount(new BigInteger("52")); + aggBuilder.setFlowCount(6587L); + aggBuilder.setPacketCount(new BigInteger("25")); + caseBuilder.setMultipartReplyAggregate(aggBuilder.build()); + mpBuilder.setMultipartReplyBody(caseBuilder.build()); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 1, list.size()); + AggregateFlowStatisticsUpdate aggUpdate = (AggregateFlowStatisticsUpdate) list.get(0); + Assert.assertEquals("Wrong node-id", "openflow:42", aggUpdate.getId().getValue()); + Assert.assertEquals("Wrong more-replies", false, aggUpdate.isMoreReplies()); + Assert.assertEquals("Wrong transaction-id", 123, aggUpdate.getTransactionId().getValue().intValue()); + Assert.assertEquals("Wrong byte count", 52, aggUpdate.getByteCount().getValue().intValue()); + Assert.assertEquals("Wrong packet count", 25, aggUpdate.getPacketCount().getValue().intValue()); + Assert.assertEquals("Wrong flow count", 6587, aggUpdate.getFlowCount().getValue().intValue()); + } + + /** + * Test MultipartReply message with group features stat + */ + @Test + public void testGroupFeaturesCase() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPGROUPFEATURES); + + MultipartReplyGroupFeaturesCaseBuilder caseBuilder = new MultipartReplyGroupFeaturesCaseBuilder(); + MultipartReplyGroupFeaturesBuilder featBuilder = new MultipartReplyGroupFeaturesBuilder(); + featBuilder.setTypes(new GroupTypes(true, false, true, false)); + featBuilder.setCapabilities(new GroupCapabilities(false, true, false, true)); + List maxGroups = new ArrayList<>(); + maxGroups.add(1L); + maxGroups.add(2L); + maxGroups.add(3L); + maxGroups.add(4L); + featBuilder.setMaxGroups(maxGroups); + List actionTypes = new ArrayList<>(); + ActionType actionType1 = new ActionType(true, false, true, false, false, false, true, + false, true, false, true, false, true, false, true, false, true); + actionTypes.add(actionType1); + ActionType actionType2 = new ActionType(false, true, false, true, false, true, false, + true, false, true, false, true, false, true, false, true, false); + actionTypes.add(actionType2); + ActionType actionType3 = new ActionType(false, false, false, false, false, false, false, + true, true, true, true, true, true, true, true, true, true); + actionTypes.add(actionType3); + ActionType actionType4 = new ActionType(true, true, true, true, true, true, true, + false, false, false, false, false, false, false, false, false, false); + actionTypes.add(actionType4); + featBuilder.setActionsBitmap(actionTypes); + caseBuilder.setMultipartReplyGroupFeatures(featBuilder.build()); + mpBuilder.setMultipartReplyBody(caseBuilder.build()); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 1, list.size()); + GroupFeaturesUpdated groupUpdate = (GroupFeaturesUpdated) list.get(0); + Assert.assertEquals("Wrong node-id", "openflow:42", groupUpdate.getId().getValue()); + Assert.assertEquals("Wrong more-replies", false, groupUpdate.isMoreReplies()); + Assert.assertEquals("Wrong transaction-id", 123, groupUpdate.getTransactionId().getValue().intValue()); + Assert.assertEquals("Wrong group types size", 2, groupUpdate.getGroupTypesSupported().size()); + Assert.assertEquals("Wrong group type", "org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupAll", + groupUpdate.getGroupTypesSupported().get(0).getName()); + Assert.assertEquals("Wrong group type", "org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupIndirect", + groupUpdate.getGroupTypesSupported().get(1).getName()); + Assert.assertEquals("Wrong group capabilities size", 2, groupUpdate.getGroupCapabilitiesSupported().size()); + Assert.assertEquals("Wrong group capability", "org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.ChainingChecks", + groupUpdate.getGroupCapabilitiesSupported().get(0).getName()); + Assert.assertEquals("Wrong group capability", "org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.SelectWeight", + groupUpdate.getGroupCapabilitiesSupported().get(1).getName()); + Assert.assertEquals("Wrong max groups", maxGroups, groupUpdate.getMaxGroups()); + Assert.assertEquals("Wrong actions bitmap", 137072641, groupUpdate.getActions().get(0).longValue()); + Assert.assertEquals("Wrong actions bitmap", 131336192, groupUpdate.getActions().get(1).longValue()); + Assert.assertEquals("Wrong actions bitmap", 247365632, groupUpdate.getActions().get(2).longValue()); + Assert.assertEquals("Wrong actions bitmap", 21043201, groupUpdate.getActions().get(3).longValue()); + } + + /** + * Test MultipartReply message with meter features stat + */ + @Test + public void testMeterFeaturesCase() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPMETERFEATURES); + + MultipartReplyMeterFeaturesCaseBuilder caseBuilder = new MultipartReplyMeterFeaturesCaseBuilder(); + MultipartReplyMeterFeaturesBuilder featBuilder = new MultipartReplyMeterFeaturesBuilder(); + featBuilder.setMaxMeter(1L); + featBuilder.setBandTypes(new MeterBandTypeBitmap(true, true)); + featBuilder.setCapabilities(new MeterFlags(true, true, true, true)); + featBuilder.setMaxBands((short) 2); + featBuilder.setMaxColor((short) 3); + caseBuilder.setMultipartReplyMeterFeatures(featBuilder.build()); + mpBuilder.setMultipartReplyBody(caseBuilder.build()); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 1, list.size()); + MeterFeaturesUpdated megterUpdate = (MeterFeaturesUpdated) list.get(0); + Assert.assertEquals("Wrong node-id", "openflow:42", megterUpdate.getId().getValue()); + Assert.assertEquals("Wrong more-replies", false, megterUpdate.isMoreReplies()); + Assert.assertEquals("Wrong transaction-id", 123, megterUpdate.getTransactionId().getValue().intValue()); + Assert.assertEquals("Wrong max meter", 1, megterUpdate.getMaxMeter().getValue().intValue()); + Assert.assertEquals("Wrong max bands", 2, megterUpdate.getMaxBands().intValue()); + Assert.assertEquals("Wrong max color", 3, megterUpdate.getMaxColor().intValue()); + Assert.assertEquals("Wrong capabilities size", 4, megterUpdate.getMeterCapabilitiesSupported().size()); + Assert.assertEquals("Wrong capability", "org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918" + + ".MeterBurst", megterUpdate.getMeterCapabilitiesSupported().get(0).getName()); + Assert.assertEquals("Wrong capability", "org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918" + + ".MeterKbps", megterUpdate.getMeterCapabilitiesSupported().get(1).getName()); + Assert.assertEquals("Wrong capability", "org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918" + + ".MeterPktps", megterUpdate.getMeterCapabilitiesSupported().get(2).getName()); + Assert.assertEquals("Wrong capability", "org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918" + + ".MeterStats", megterUpdate.getMeterCapabilitiesSupported().get(3).getName()); + Assert.assertEquals("Wrong band types size", 2, megterUpdate.getMeterBandSupported().size()); + Assert.assertEquals("Wrong band type", "org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandDrop", + megterUpdate.getMeterBandSupported().get(0).getName()); + Assert.assertEquals("Wrong band type", "org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandDscpRemark", + megterUpdate.getMeterBandSupported().get(1).getName()); + } +} \ No newline at end of file diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest3.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest3.java new file mode 100644 index 0000000000..d3e88d17ac --- /dev/null +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/translator/MultipartReplyTranslatorTest3.java @@ -0,0 +1,373 @@ +/* + * Copyright (c) 2014 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.openflowplugin.openflow.md.core.translator; + +import static org.mockito.Mockito.when; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.openflowjava.protocol.api.util.BinContent; +import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants; +import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher; +import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor; +import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; +import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumberValues; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStatsCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueueCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTableCaseBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueueBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.multipart.reply.queue.QueueStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.MultipartReplyTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.queue.id.and.statistics.map.QueueIdAndStatisticsMap; +import org.opendaylight.yangtools.yang.binding.DataObject; + +/** + * @author michal.polkorab + * + */ +public class MultipartReplyTranslatorTest3 { + + @Mock SwitchConnectionDistinguisher cookie; + @Mock SessionContext sc; + @Mock ConnectionConductor conductor; + @Mock GetFeaturesOutput features; + + MultipartReplyTranslator translator = new MultipartReplyTranslator(); + + /** + * Initializes mocks + */ + @Before + public void startUp() { + MockitoAnnotations.initMocks(this); + when(sc.getPrimaryConductor()).thenReturn(conductor); + when(conductor.getVersion()).thenReturn((short) EncodeConstants.OF13_VERSION_ID); + when(sc.getFeatures()).thenReturn(features); + when(features.getDatapathId()).thenReturn(new BigInteger("42")); + OpenflowPortsUtil.init(); + } + + /** + * Test empty port stats + */ + @Test + public void testEmptyPortStats() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPPORTSTATS); + + MultipartReplyPortStatsCaseBuilder caseBuilder = new MultipartReplyPortStatsCaseBuilder(); + MultipartReplyPortStatsBuilder statsBuilder = new MultipartReplyPortStatsBuilder(); + List portStats = new ArrayList<>(); + statsBuilder.setPortStats(portStats); + caseBuilder.setMultipartReplyPortStats(statsBuilder.build()); + mpBuilder.setMultipartReplyBody(caseBuilder.build()); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 1, list.size()); + NodeConnectorStatisticsUpdate statUpdate = (NodeConnectorStatisticsUpdate) list.get(0); + Assert.assertEquals("Wrong node-id", "openflow:42", statUpdate.getId().getValue()); + Assert.assertEquals("Wrong more-replies", false, statUpdate.isMoreReplies()); + Assert.assertEquals("Wrong transaction-id", 123, statUpdate.getTransactionId().getValue().intValue()); + Assert.assertEquals("Wrong port stats size", 0, statUpdate.getNodeConnectorStatisticsAndPortNumberMap().size()); + } + + /** + * Test port stats + */ + @Test + public void testPortStats() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPPORTSTATS); + + MultipartReplyPortStatsCaseBuilder caseBuilder = new MultipartReplyPortStatsCaseBuilder(); + MultipartReplyPortStatsBuilder statsBuilder = new MultipartReplyPortStatsBuilder(); + List portStats = new ArrayList<>(); + PortStatsBuilder builder = new PortStatsBuilder(); + builder.setPortNo(1L); + builder.setRxPackets(new BigInteger("2")); + builder.setTxPackets(new BigInteger("3")); + builder.setRxBytes(new BigInteger("4")); + builder.setTxBytes(new BigInteger("5")); + builder.setRxDropped(new BigInteger("6")); + builder.setTxDropped(new BigInteger("7")); + builder.setRxErrors(new BigInteger("8")); + builder.setTxErrors(new BigInteger("9")); + builder.setRxFrameErr(new BigInteger("10")); + builder.setRxOverErr(new BigInteger("11")); + builder.setRxCrcErr(new BigInteger("12")); + builder.setCollisions(new BigInteger("13")); + builder.setDurationSec(14L); + builder.setDurationNsec(15L); + portStats.add(builder.build()); + builder = new PortStatsBuilder(); + builder.setPortNo(BinContent.intToUnsignedLong(PortNumberValues.CONTROLLER.getIntValue())); + builder.setRxPackets(new BigInteger("20")); + builder.setTxPackets(new BigInteger("30")); + builder.setRxBytes(new BigInteger("40")); + builder.setTxBytes(new BigInteger("50")); + builder.setRxDropped(new BigInteger("60")); + builder.setTxDropped(new BigInteger("70")); + builder.setRxErrors(new BigInteger("80")); + builder.setTxErrors(new BigInteger("90")); + builder.setRxFrameErr(new BigInteger("100")); + builder.setRxOverErr(new BigInteger("110")); + builder.setRxCrcErr(new BigInteger("120")); + builder.setCollisions(new BigInteger("130")); + portStats.add(builder.build()); + statsBuilder.setPortStats(portStats); + caseBuilder.setMultipartReplyPortStats(statsBuilder.build()); + mpBuilder.setMultipartReplyBody(caseBuilder.build()); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 1, list.size()); + NodeConnectorStatisticsUpdate statUpdate = (NodeConnectorStatisticsUpdate) list.get(0); + Assert.assertEquals("Wrong node-id", "openflow:42", statUpdate.getId().getValue()); + Assert.assertEquals("Wrong more-replies", false, statUpdate.isMoreReplies()); + Assert.assertEquals("Wrong transaction-id", 123, statUpdate.getTransactionId().getValue().intValue()); + Assert.assertEquals("Wrong port stats size", 2, statUpdate.getNodeConnectorStatisticsAndPortNumberMap().size()); + NodeConnectorStatisticsAndPortNumberMap stat = statUpdate.getNodeConnectorStatisticsAndPortNumberMap().get(0); + Assert.assertEquals("Wrong port number", "openflow:42:1", stat.getNodeConnectorId().getValue()); + Assert.assertEquals("Wrong rx packets", 2, stat.getPackets().getReceived().intValue()); + Assert.assertEquals("Wrong tx packets", 3, stat.getPackets().getTransmitted().intValue()); + Assert.assertEquals("Wrong rx bytes", 4, stat.getBytes().getReceived().intValue()); + Assert.assertEquals("Wrong tx bytes", 5, stat.getBytes().getTransmitted().intValue()); + Assert.assertEquals("Wrong rx dropped", 6, stat.getReceiveDrops().intValue()); + Assert.assertEquals("Wrong tx dropped", 7, stat.getTransmitDrops().intValue()); + Assert.assertEquals("Wrong rx errors", 8, stat.getReceiveErrors().intValue()); + Assert.assertEquals("Wrong tx errors", 9, stat.getTransmitErrors().intValue()); + Assert.assertEquals("Wrong rx frame error", 10, stat.getReceiveFrameError().intValue()); + Assert.assertEquals("Wrong rx over error", 11, stat.getReceiveOverRunError().intValue()); + Assert.assertEquals("Wrong rx crc error", 12, stat.getReceiveCrcError().intValue()); + Assert.assertEquals("Wrong collision count", 13, stat.getCollisionCount().intValue()); + Assert.assertEquals("Wrong duration sec", 14, stat.getDuration().getSecond().getValue().intValue()); + Assert.assertEquals("Wrong duration n sec", 15, stat.getDuration().getNanosecond().getValue().intValue()); + stat = statUpdate.getNodeConnectorStatisticsAndPortNumberMap().get(1); + Assert.assertEquals("Wrong port number", "openflow:42:CONTROLLER", stat.getNodeConnectorId().getValue()); + Assert.assertEquals("Wrong rx packets", 20, stat.getPackets().getReceived().intValue()); + Assert.assertEquals("Wrong tx packets", 30, stat.getPackets().getTransmitted().intValue()); + Assert.assertEquals("Wrong rx bytes", 40, stat.getBytes().getReceived().intValue()); + Assert.assertEquals("Wrong tx bytes", 50, stat.getBytes().getTransmitted().intValue()); + Assert.assertEquals("Wrong rx dropped", 60, stat.getReceiveDrops().intValue()); + Assert.assertEquals("Wrong tx dropped", 70, stat.getTransmitDrops().intValue()); + Assert.assertEquals("Wrong rx errors", 80, stat.getReceiveErrors().intValue()); + Assert.assertEquals("Wrong tx errors", 90, stat.getTransmitErrors().intValue()); + Assert.assertEquals("Wrong rx frame error", 100, stat.getReceiveFrameError().intValue()); + Assert.assertEquals("Wrong rx over error", 110, stat.getReceiveOverRunError().intValue()); + Assert.assertEquals("Wrong rx crc error", 120, stat.getReceiveCrcError().intValue()); + Assert.assertEquals("Wrong collision count", 130, stat.getCollisionCount().intValue()); + Assert.assertEquals("Wrong duration sec", null, stat.getDuration().getSecond()); + Assert.assertEquals("Wrong duration n sec", null, stat.getDuration().getNanosecond()); + } + + /** + * Test empty table stats + */ + @Test + public void testEmptyTableStats() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPTABLE); + + MultipartReplyTableCaseBuilder caseBuilder = new MultipartReplyTableCaseBuilder(); + MultipartReplyTableBuilder statsBuilder = new MultipartReplyTableBuilder(); + List tableStats = new ArrayList<>(); + statsBuilder.setTableStats(tableStats); + caseBuilder.setMultipartReplyTable(statsBuilder.build()); + mpBuilder.setMultipartReplyBody(caseBuilder.build()); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 1, list.size()); + FlowTableStatisticsUpdate statUpdate = (FlowTableStatisticsUpdate) list.get(0); + Assert.assertEquals("Wrong node-id", "openflow:42", statUpdate.getId().getValue()); + Assert.assertEquals("Wrong more-replies", false, statUpdate.isMoreReplies()); + Assert.assertEquals("Wrong transaction-id", 123, statUpdate.getTransactionId().getValue().intValue()); + Assert.assertEquals("Wrong table stats size", 0, statUpdate.getFlowTableAndStatisticsMap().size()); + } + + /** + * Test table stats + */ + @Test + public void testTableStats() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPTABLE); + + MultipartReplyTableCaseBuilder caseBuilder = new MultipartReplyTableCaseBuilder(); + MultipartReplyTableBuilder statsBuilder = new MultipartReplyTableBuilder(); + List tableStats = new ArrayList<>(); + TableStatsBuilder builder = new TableStatsBuilder(); + builder.setTableId((short) 1); + builder.setActiveCount(2L); + builder.setLookupCount(new BigInteger("3")); + builder.setMatchedCount(new BigInteger("4")); + tableStats.add(builder.build()); + builder = new TableStatsBuilder(); + builder.setTableId((short) 10); + builder.setActiveCount(20L); + builder.setLookupCount(new BigInteger("30")); + builder.setMatchedCount(new BigInteger("40")); + tableStats.add(builder.build()); + statsBuilder.setTableStats(tableStats); + caseBuilder.setMultipartReplyTable(statsBuilder.build()); + mpBuilder.setMultipartReplyBody(caseBuilder.build()); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 1, list.size()); + FlowTableStatisticsUpdate statUpdate = (FlowTableStatisticsUpdate) list.get(0); + Assert.assertEquals("Wrong node-id", "openflow:42", statUpdate.getId().getValue()); + Assert.assertEquals("Wrong more-replies", false, statUpdate.isMoreReplies()); + Assert.assertEquals("Wrong transaction-id", 123, statUpdate.getTransactionId().getValue().intValue()); + Assert.assertEquals("Wrong table stats size", 2, statUpdate.getFlowTableAndStatisticsMap().size()); + FlowTableAndStatisticsMap stat = statUpdate.getFlowTableAndStatisticsMap().get(0); + Assert.assertEquals("Wrong table-id", 1, stat.getTableId().getValue().intValue()); + Assert.assertEquals("Wrong active count", 2, stat.getActiveFlows().getValue().intValue()); + Assert.assertEquals("Wrong lookup count", 3, stat.getPacketsLookedUp().getValue().intValue()); + Assert.assertEquals("Wrong matched count", 4, stat.getPacketsMatched().getValue().intValue()); + stat = statUpdate.getFlowTableAndStatisticsMap().get(1); + Assert.assertEquals("Wrong table-id", 10, stat.getTableId().getValue().intValue()); + Assert.assertEquals("Wrong active count", 20, stat.getActiveFlows().getValue().intValue()); + Assert.assertEquals("Wrong lookup count", 30, stat.getPacketsLookedUp().getValue().intValue()); + Assert.assertEquals("Wrong matched count", 40, stat.getPacketsMatched().getValue().intValue()); + } + + /** + * Test empty queue stats + */ + @Test + public void testEmptyQueueStats() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPQUEUE); + + MultipartReplyQueueCaseBuilder caseBuilder = new MultipartReplyQueueCaseBuilder(); + MultipartReplyQueueBuilder statsBuilder = new MultipartReplyQueueBuilder(); + List queueStats = new ArrayList<>(); + statsBuilder.setQueueStats(queueStats); + caseBuilder.setMultipartReplyQueue(statsBuilder.build()); + mpBuilder.setMultipartReplyBody(caseBuilder.build()); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 1, list.size()); + QueueStatisticsUpdate statUpdate = (QueueStatisticsUpdate) list.get(0); + Assert.assertEquals("Wrong node-id", "openflow:42", statUpdate.getId().getValue()); + Assert.assertEquals("Wrong more-replies", false, statUpdate.isMoreReplies()); + Assert.assertEquals("Wrong transaction-id", 123, statUpdate.getTransactionId().getValue().intValue()); + Assert.assertEquals("Wrong queue stats size", 0, statUpdate.getQueueIdAndStatisticsMap().size()); + } + + /** + * Test queue stats + */ + @Test + public void testQueueStats() { + MultipartReplyMessageBuilder mpBuilder = new MultipartReplyMessageBuilder(); + mpBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID); + mpBuilder.setXid(123L); + mpBuilder.setFlags(new MultipartRequestFlags(false)); + mpBuilder.setType(MultipartType.OFPMPQUEUE); + + MultipartReplyQueueCaseBuilder caseBuilder = new MultipartReplyQueueCaseBuilder(); + MultipartReplyQueueBuilder statsBuilder = new MultipartReplyQueueBuilder(); + List queueStats = new ArrayList<>(); + QueueStatsBuilder builder = new QueueStatsBuilder(); + builder.setPortNo(BinContent.intToUnsignedLong(PortNumberValues.FLOOD.getIntValue())); + builder.setQueueId(2L); + builder.setTxPackets(new BigInteger("3")); + builder.setTxBytes(new BigInteger("4")); + builder.setTxErrors(new BigInteger("5")); + builder.setDurationSec(6L); + builder.setDurationNsec(7L); + queueStats.add(builder.build()); + builder = new QueueStatsBuilder(); + builder.setPortNo(BinContent.intToUnsignedLong(PortNumberValues.INPORT.getIntValue())); + builder.setQueueId(20L); + builder.setTxPackets(new BigInteger("30")); + builder.setTxBytes(new BigInteger("40")); + builder.setTxErrors(new BigInteger("50")); + builder.setDurationSec(60L); + builder.setDurationNsec(70L); + queueStats.add(builder.build()); + statsBuilder.setQueueStats(queueStats); + caseBuilder.setMultipartReplyQueue(statsBuilder.build()); + mpBuilder.setMultipartReplyBody(caseBuilder.build()); + MultipartReplyMessage message = mpBuilder.build(); + + List list = translator.translate(cookie, sc, message); + + Assert.assertEquals("Wrong list size", 1, list.size()); + QueueStatisticsUpdate statUpdate = (QueueStatisticsUpdate) list.get(0); + Assert.assertEquals("Wrong node-id", "openflow:42", statUpdate.getId().getValue()); + Assert.assertEquals("Wrong more-replies", false, statUpdate.isMoreReplies()); + Assert.assertEquals("Wrong transaction-id", 123, statUpdate.getTransactionId().getValue().intValue()); + Assert.assertEquals("Wrong queue stats size", 2, statUpdate.getQueueIdAndStatisticsMap().size()); + QueueIdAndStatisticsMap stat = statUpdate.getQueueIdAndStatisticsMap().get(0); + Assert.assertEquals("Wrong port number", "openflow:42:FLOOD", stat.getNodeConnectorId().getValue()); + Assert.assertEquals("Wrong queue-id", 2, stat.getQueueId().getValue().intValue()); + Assert.assertEquals("Wrong tx packets", 3, stat.getTransmittedPackets().getValue().intValue()); + Assert.assertEquals("Wrong tx bytes", 4, stat.getTransmittedBytes().getValue().intValue()); + Assert.assertEquals("Wrong tx errors", 5, stat.getTransmissionErrors().getValue().intValue()); + Assert.assertEquals("Wrong duration sec", 6, stat.getDuration().getSecond().getValue().intValue()); + Assert.assertEquals("Wrong duration n sec", 7, stat.getDuration().getNanosecond().getValue().intValue()); + stat = statUpdate.getQueueIdAndStatisticsMap().get(1); + Assert.assertEquals("Wrong port number", "openflow:42:INPORT", stat.getNodeConnectorId().getValue()); + Assert.assertEquals("Wrong queue-id", 20, stat.getQueueId().getValue().intValue()); + Assert.assertEquals("Wrong tx packets", 30, stat.getTransmittedPackets().getValue().intValue()); + Assert.assertEquals("Wrong tx bytes", 40, stat.getTransmittedBytes().getValue().intValue()); + Assert.assertEquals("Wrong tx errors", 50, stat.getTransmissionErrors().getValue().intValue()); + Assert.assertEquals("Wrong duration sec", 60, stat.getDuration().getSecond().getValue().intValue()); + Assert.assertEquals("Wrong duration n sec", 70, stat.getDuration().getNanosecond().getValue().intValue()); + } +} \ No newline at end of file -- 2.36.6