From 41e008a8af2f5ee6134a59391235c145a2b27fc1 Mon Sep 17 00:00:00 2001 From: Michal Polkorab Date: Thu, 14 Nov 2013 12:53:13 +0100 Subject: [PATCH] Factory tests back to stable Signed-off-by: Michal Polkorab --- .../MultipartReplyMessageFactory.java | 227 ++++++-------- .../OF10StatsReplyMessageFactory.java | 106 +++---- .../factories/PacketInMessageFactory.java | 6 - .../MultipartRequestMessageFactory.java | 99 +++++- .../OF10StatsRequestMessageFactory.java | 36 ++- .../impl/util/ActionsDeserializer.java | 292 ++++++++++-------- .../protocol/impl/util/ActionsSerializer.java | 20 +- .../protocol/impl/util/MatchDeserializer.java | 25 +- .../protocol/impl/util/MatchSerializer.java | 4 +- .../FeaturesReplyMessageFactoryTest.java | 7 +- .../MultipartReplyMessageFactoryTest.java | 72 ++--- .../PortStatusMessageFactoryTest.java | 5 +- ...GetConfigReplyMessageFactoryMultiTest.java | 38 ++- ...QueueGetConfigReplyMessageFactoryTest.java | 15 +- .../MultipartRequestMessageFactoryTest.java | 5 +- .../PortModInputMessageFactoryTest.java | 1 - .../TableModInputMessageFactoryTest.java | 1 - 17 files changed, 519 insertions(+), 440 deletions(-) diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java index 61d8c41e..2aabc78b 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java @@ -105,6 +105,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features.TableFeaturesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeatureProperties; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeaturePropertiesBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author timotej.kubas @@ -112,9 +114,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class MultipartReplyMessageFactory implements OFDeserializer { - private static MultipartReplyMessageFactory instance; + private static final Logger LOGGER = LoggerFactory + .getLogger(MultipartReplyMessageFactory.class); private static final byte PADDING_IN_MULTIPART_REPLY_HEADER = 4; + private static MultipartReplyMessageFactory instance; + private MultipartReplyMessageFactory() { // singleton } @@ -209,8 +214,8 @@ public class MultipartReplyMessageFactory implements OFDeserializer flowStatsList = new ArrayList<>(); - FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder(); while (input.readableBytes() > 0) { + FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder(); input.skipBytes(Short.SIZE / Byte.SIZE); flowStatsBuilder.setTableId(input.readUnsignedByte()); input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_01); @@ -234,8 +239,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer(flowStatsList)); - flowStatsList.clear(); + flowBuilder.setFlowStats(flowStatsList); return flowBuilder.build(); } @@ -265,9 +269,9 @@ public class MultipartReplyMessageFactory implements OFDeserializer tableStatsList = new ArrayList<>(); while (input.readableBytes() > 0) { + TableStatsBuilder tableStatsBuilder = new TableStatsBuilder(); tableStatsBuilder.setTableId(input.readUnsignedByte()); input.skipBytes(PADDING_IN_TABLE_HEADER); tableStatsBuilder.setActiveCount(input.readUnsignedInt()); @@ -279,8 +283,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer(tableStatsList)); - tableStatsList.clear(); + builder.setTableStats(tableStatsList); return builder.build(); } @@ -374,96 +377,76 @@ public class MultipartReplyMessageFactory implements OFDeserializer portStatsList = new ArrayList<>(); while (input.readableBytes() > 0) { + PortStatsBuilder portStatsBuilder = new PortStatsBuilder(); portStatsBuilder.setPortNo(input.readUnsignedInt()); input.skipBytes(PADDING_IN_PORT_STATS_HEADER); - byte[] rxPackets = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxPackets); portStatsBuilder.setRxPackets(new BigInteger(rxPackets)); - byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txPackets); portStatsBuilder.setTxPackets(new BigInteger(txPackets)); - byte[] rxBytes = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxBytes); portStatsBuilder.setRxBytes(new BigInteger(rxBytes)); - byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txBytes); portStatsBuilder.setTxBytes(new BigInteger(txBytes)); - byte[] rxDropped = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxDropped); portStatsBuilder.setRxDropped(new BigInteger(rxDropped)); - byte[] txDropped = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txDropped); portStatsBuilder.setTxDropped(new BigInteger(txDropped)); - byte[] rxErrors = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxErrors); portStatsBuilder.setRxErrors(new BigInteger(rxErrors)); - byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txErrors); portStatsBuilder.setTxErrors(new BigInteger(txErrors)); - byte[] rxFrameErr = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxFrameErr); portStatsBuilder.setRxFrameErr(new BigInteger(rxFrameErr)); - byte[] rxOverErr = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxOverErr); portStatsBuilder.setRxOverErr(new BigInteger(rxOverErr)); - byte[] rxCrcErr = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxCrcErr); portStatsBuilder.setRxCrcErr(new BigInteger(rxCrcErr)); - byte[] collisions = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(collisions); portStatsBuilder.setCollisions(new BigInteger(collisions)); - portStatsBuilder.setDurationSec(input.readUnsignedInt()); portStatsBuilder.setDurationNsec(input.readUnsignedInt()); portStatsList.add(portStatsBuilder.build()); } - builder.setPortStats(new ArrayList<>(portStatsList)); - portStatsList.clear(); + builder.setPortStats(portStatsList); return builder.build(); } private static MultipartReplyQueue setQueue(ByteBuf input) { MultipartReplyQueueBuilder builder = new MultipartReplyQueueBuilder(); - QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder(); List queueStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { + QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder(); queueStatsBuilder.setPortNo(input.readUnsignedInt()); queueStatsBuilder.setQueueId(input.readUnsignedInt()); - byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txBytes); queueStatsBuilder.setTxBytes(new BigInteger(txBytes)); - byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txPackets); queueStatsBuilder.setTxPackets(new BigInteger(txPackets)); - byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txErrors); queueStatsBuilder.setTxErrors(new BigInteger(txErrors)); - queueStatsBuilder.setDurationSec(input.readUnsignedInt()); queueStatsBuilder.setDurationNsec(input.readUnsignedInt()); queueStatsList.add(queueStatsBuilder.build()); } - builder.setQueueStats(new ArrayList<>(queueStatsList)); - queueStatsList.clear(); + builder.setQueueStats(queueStatsList); return builder.build(); } @@ -472,18 +455,11 @@ public class MultipartReplyMessageFactory implements OFDeserializer groupStatsList = new ArrayList<>(); - - BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder(); - List bucketStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { + GroupStatsBuilder groupStatsBuilder = new GroupStatsBuilder(); int bodyLength = input.readUnsignedShort(); - actualLength = 0; - input.skipBytes(PADDING_IN_GROUP_HEADER_01); groupStatsBuilder.setGroupId(input.readUnsignedInt()); groupStatsBuilder.setRefCount(input.readUnsignedInt()); @@ -496,9 +472,10 @@ public class MultipartReplyMessageFactory implements OFDeserializer bucketStatsList = new ArrayList<>(); while (actualLength < bodyLength) { + BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder(); byte[] packetCountBucket = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(packetCountBucket); bucketStatsBuilder.setPacketCount(new BigInteger(packetCountBucket)); @@ -506,15 +483,12 @@ public class MultipartReplyMessageFactory implements OFDeserializer(bucketStatsList)); - bucketStatsList.clear(); + groupStatsBuilder.setBucketStats(bucketStatsList); groupStatsList.add(groupStatsBuilder.build()); } - builder.setGroupStats(new ArrayList<>(groupStatsList)); - groupStatsList.clear(); + builder.setGroupStats(groupStatsList); return builder.build(); } @@ -523,14 +497,14 @@ public class MultipartReplyMessageFactory implements OFDeserializer meterStatsList = new ArrayList<>(); - MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder(); - List meterBandStatsList = new ArrayList<>(); - MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder(); while (input.readableBytes() > 0) { + MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder(); meterStatsBuilder.setMeterId(input.readUnsignedInt()); - actualLength = 0; int meterStatsBodyLength = input.readUnsignedShort(); input.skipBytes(PADDING_IN_METER_STATS_HEADER); meterStatsBuilder.setFlowCount(input.readUnsignedInt()); @@ -562,88 +532,80 @@ public class MultipartReplyMessageFactory implements OFDeserializer meterBandStatsList = new ArrayList<>(); while (actualLength < meterStatsBodyLength) { + MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder(); byte[] packetBandCount = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(packetBandCount); meterBandStatsBuilder.setPacketBandCount(new BigInteger(packetBandCount)); byte[] byteBandCount = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(byteBandCount); meterBandStatsBuilder.setByteBandCount(new BigInteger(byteBandCount)); - meterBandStatsList.add(meterBandStatsBuilder.build()); - actualLength = actualLength + METER_BAND_STATS_LENGTH; + actualLength += METER_BAND_STATS_LENGTH; } - - meterStatsBuilder.setMeterBandStats(new ArrayList<>(meterBandStatsList)); - meterBandStatsList.clear(); + meterStatsBuilder.setMeterBandStats(meterBandStatsList); meterStatsList.add(meterStatsBuilder.build()); } - builder.setMeterStats(new ArrayList<>(meterStatsList)); - meterStatsList.clear(); + builder.setMeterStats(meterStatsList); return builder.build(); } private static MultipartReplyMeterConfig setMeterConfig(ByteBuf input) { - final byte METER_BAND_LENGTH = 16; final byte METER_CONFIG_LENGTH = 8; - final byte bandLength = 2; - int actualLength; + final byte PADDING_IN_METER_BAND_DROP_HEADER = 4; + final byte PADDING_IN_METER_BAND_DSCP_HEADER = 3; MultipartReplyMeterConfigBuilder builder = new MultipartReplyMeterConfigBuilder(); List meterConfigList = new ArrayList<>(); - MeterConfigBuilder meterConfigBuilder = new MeterConfigBuilder(); - List bandsList = new ArrayList<>(); - BandsBuilder bandsBuilder = new BandsBuilder(); - while (input.readableBytes() > 0) { + MeterConfigBuilder meterConfigBuilder = new MeterConfigBuilder(); int meterConfigBodyLength = input.readUnsignedShort(); - actualLength = 0; meterConfigBuilder.setFlags(MeterModCommand.forValue(input.readUnsignedShort())); meterConfigBuilder.setMeterId(input.readUnsignedInt()); - actualLength = METER_CONFIG_LENGTH; - + int actualLength = METER_CONFIG_LENGTH; + List bandsList = new ArrayList<>(); while (actualLength < meterConfigBodyLength) { - MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder(); - final byte PADDING_IN_METER_BAND_DROP_HEADER = 4; - MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder(); - final byte PADDING_IN_METER_BAND_DSCP_HEADER = 3; - MeterBandExperimenterBuilder bandExperimenterBuilder = new MeterBandExperimenterBuilder(); + BandsBuilder bandsBuilder = new BandsBuilder(); int bandType = input.readUnsignedShort(); switch (bandType) { - case 1: bandDropBuilder.setType(MeterBandType.forValue(bandType)); - input.skipBytes(bandLength); - bandDropBuilder.setRate(input.readUnsignedInt()); - bandDropBuilder.setBurstSize(input.readUnsignedInt()); - input.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER); - bandsBuilder.setMeterBand(bandDropBuilder.build()); - break; - case 2: bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType)); - input.skipBytes(bandLength); - bandDscpRemarkBuilder.setRate(input.readUnsignedInt()); - bandDscpRemarkBuilder.setBurstSize(input.readUnsignedInt()); - bandDscpRemarkBuilder.setPrecLevel(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER); - bandsBuilder.setMeterBand(bandDscpRemarkBuilder.build()); - break; - case 0xFFFF: bandExperimenterBuilder.setType(MeterBandType.forValue(bandType)); - input.skipBytes(bandLength); - bandExperimenterBuilder.setRate(input.readUnsignedInt()); - bandExperimenterBuilder.setBurstSize(input.readUnsignedInt()); - bandExperimenterBuilder.setExperimenter(input.readUnsignedInt()); - bandsBuilder.setMeterBand(bandExperimenterBuilder.build()); - break; - default: break; + case 1: + MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder(); + bandDropBuilder.setType(MeterBandType.forValue(bandType)); + actualLength += input.readUnsignedShort(); + bandDropBuilder.setRate(input.readUnsignedInt()); + bandDropBuilder.setBurstSize(input.readUnsignedInt()); + input.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER); + bandsBuilder.setMeterBand(bandDropBuilder.build()); + break; + case 2: + MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder(); + bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType)); + actualLength += input.readUnsignedShort(); + bandDscpRemarkBuilder.setRate(input.readUnsignedInt()); + bandDscpRemarkBuilder.setBurstSize(input.readUnsignedInt()); + bandDscpRemarkBuilder.setPrecLevel(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER); + bandsBuilder.setMeterBand(bandDscpRemarkBuilder.build()); + break; + case 0xFFFF: + MeterBandExperimenterBuilder bandExperimenterBuilder = new MeterBandExperimenterBuilder(); + bandExperimenterBuilder.setType(MeterBandType.forValue(bandType)); + actualLength += input.readUnsignedShort(); + bandExperimenterBuilder.setRate(input.readUnsignedInt()); + bandExperimenterBuilder.setBurstSize(input.readUnsignedInt()); + bandExperimenterBuilder.setExperimenter(input.readUnsignedInt()); + bandsBuilder.setMeterBand(bandExperimenterBuilder.build()); + break; + default: + break; } bandsList.add(bandsBuilder.build()); - actualLength = actualLength + METER_BAND_LENGTH; } - meterConfigBuilder.setBands(new ArrayList<>(bandsList)); - bandsList.clear(); + meterConfigBuilder.setBands(bandsList); meterConfigList.add(meterConfigBuilder.build()); } - builder.setMeterConfig(new ArrayList<>(meterConfigList)); - meterConfigList.clear(); + builder.setMeterConfig(meterConfigList); return builder.build(); } @@ -651,7 +613,7 @@ public class MultipartReplyMessageFactory implements OFDeserializer portsList = new ArrayList<>(); - PortsBuilder portsBuilder = new PortsBuilder(); - while (input.readableBytes() > 0) { + PortsBuilder portsBuilder = new PortsBuilder(); portsBuilder.setPortNo(input.readUnsignedInt()); input.skipBytes(PADDING_IN_PORT_DESC_HEADER_01); StringBuffer macToString = new StringBuffer(); @@ -677,12 +638,10 @@ public class MultipartReplyMessageFactory implements OFDeserializer(portsList)); - portsList.clear(); + builder.setPorts(portsList); return builder.build(); } @@ -797,41 +754,43 @@ public class MultipartReplyMessageFactory implements OFDeserializer groupDescsList = new ArrayList<>(); - BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); - List bucketsList = new ArrayList<>(); - List actionsList = new ArrayList<>(); + LOGGER.info("readablebytes pred: " + input.readableBytes()); while (input.readableBytes() > 0) { - bodyLength = input.readUnsignedShort(); + LOGGER.info("readablebytes po: " + input.readableBytes()); + GroupDescBuilder groupDescBuilder = new GroupDescBuilder(); + int bodyLength = input.readUnsignedShort(); + LOGGER.info("bodylength: " + bodyLength); groupDescBuilder.setType(GroupType.forValue(input.readUnsignedByte())); input.skipBytes(PADDING_IN_GROUP_DESC_HEADER); groupDescBuilder.setGroupId(input.readUnsignedInt()); - actualLength = GROUP_DESC_HEADER_LENGTH; + int actualLength = GROUP_DESC_HEADER_LENGTH; + List bucketsList = new ArrayList<>(); while (actualLength < bodyLength) { - bucketsLength = input.readUnsignedShort(); + System.out.println("cyklim v buckets"); + BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); + int bucketsLength = input.readUnsignedShort(); bucketsBuilder.setWeight(input.readUnsignedShort()); bucketsBuilder.setWatchPort(new PortNumber(input.readUnsignedInt())); bucketsBuilder.setWatchGroup(input.readUnsignedInt()); input.skipBytes(PADDING_IN_BUCKETS_HEADER); - bucketsCurrentLength = bucketsLength; - actionsList = ActionsDeserializer.createActionsList(input, bucketsLength); - bucketsBuilder.setActionsList(new ArrayList<>(actionsList)); - actionsList.clear(); + System.out.println("bucketslength: " + bucketsLength); + System.out.println("actuallength: " + actualLength); + System.out.println("bodylength: " + bodyLength); + LOGGER.info("length - length: " + (bucketsLength - BUCKETS_HEADER_LENGTH)); + List actionsList = ActionsDeserializer + .createActionsList(input, bucketsLength - BUCKETS_HEADER_LENGTH); + LOGGER.info("actions size: " + actionsList.size()); + bucketsBuilder.setActionsList(actionsList); bucketsList.add(bucketsBuilder.build()); - actualLength = actualLength + bucketsCurrentLength; + actualLength += bucketsLength; } - groupDescBuilder.setBucketsList(new ArrayList<>(bucketsList)); - bucketsList.clear(); + groupDescBuilder.setBucketsList(bucketsList); groupDescsList.add(groupDescBuilder.build()); } - builder.setGroupDesc(new ArrayList<>(groupDescsList)); - groupDescsList.clear(); + builder.setGroupDesc(groupDescsList); return builder.build(); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java index b18efb44..8b8e2fa6 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/OF10StatsReplyMessageFactory.java @@ -120,30 +120,31 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer flowStatsList = new ArrayList<>(); - FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder(); - input.skipBytes(Short.SIZE / Byte.SIZE); - flowStatsBuilder.setTableId(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_FLOW_STATS_HEADER); - flowStatsBuilder.setMatchV10(OF10MatchDeserializer.createMatchV10(input)); - flowStatsBuilder.setDurationSec(input.readUnsignedInt()); - flowStatsBuilder.setDurationNsec(input.readUnsignedInt()); - flowStatsBuilder.setPriority(input.readUnsignedShort()); - flowStatsBuilder.setIdleTimeout(input.readUnsignedShort()); - flowStatsBuilder.setHardTimeout(input.readUnsignedShort()); - input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02); - byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(cookie); - flowStatsBuilder.setCookie(new BigInteger(cookie)); - byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(packetCount); - flowStatsBuilder.setPacketCount(new BigInteger(packetCount)); - byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(byteCount); - flowStatsBuilder.setByteCount(new BigInteger(byteCount)); - flowStatsBuilder.setActionsList(OF10ActionsDeserializer.createActionsList(input)); - flowStatsList.add(flowStatsBuilder.build()); - flowBuilder.setFlowStats(new ArrayList<>(flowStatsList)); - flowStatsList.clear(); + while (input.readableBytes() > 0) { + FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder(); + input.skipBytes(Short.SIZE / Byte.SIZE); + flowStatsBuilder.setTableId(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_FLOW_STATS_HEADER); + flowStatsBuilder.setMatchV10(OF10MatchDeserializer.createMatchV10(input)); + flowStatsBuilder.setDurationSec(input.readUnsignedInt()); + flowStatsBuilder.setDurationNsec(input.readUnsignedInt()); + flowStatsBuilder.setPriority(input.readUnsignedShort()); + flowStatsBuilder.setIdleTimeout(input.readUnsignedShort()); + flowStatsBuilder.setHardTimeout(input.readUnsignedShort()); + input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02); + byte[] cookie = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(cookie); + flowStatsBuilder.setCookie(new BigInteger(cookie)); + byte[] packetCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(packetCount); + flowStatsBuilder.setPacketCount(new BigInteger(packetCount)); + byte[] byteCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(byteCount); + flowStatsBuilder.setByteCount(new BigInteger(byteCount)); + flowStatsBuilder.setActionsList(OF10ActionsDeserializer.createActionsList(input)); + flowStatsList.add(flowStatsBuilder.build()); + } + flowBuilder.setFlowStats(flowStatsList); return flowBuilder.build(); } @@ -165,114 +166,95 @@ public class OF10StatsReplyMessageFactory implements OFDeserializer tableStatsList = new ArrayList<>(); - tableStatsBuilder.setTableId(input.readUnsignedByte()); - input.skipBytes(PADDING_IN_TABLE_HEADER); - tableStatsBuilder.setName(input.readBytes(MAX_TABLE_NAME_LENGTH).toString()); - tableStatsBuilder.setActiveCount(input.readUnsignedInt()); - byte[] lookupCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(lookupCount); - tableStatsBuilder.setLookupCount(new BigInteger(lookupCount)); - byte[] matchedCount = new byte[Long.SIZE/Byte.SIZE]; - input.readBytes(matchedCount); - tableStatsBuilder.setMatchedCount(new BigInteger(matchedCount)); - tableStatsList.add(tableStatsBuilder.build()); - builder.setTableStats(new ArrayList<>(tableStatsList)); - tableStatsList.clear(); + while (input.readableBytes() > 0) { + TableStatsBuilder tableStatsBuilder = new TableStatsBuilder(); + tableStatsBuilder.setTableId(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_TABLE_HEADER); + tableStatsBuilder.setName(input.readBytes(MAX_TABLE_NAME_LENGTH).toString()); + tableStatsBuilder.setActiveCount(input.readUnsignedInt()); + byte[] lookupCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(lookupCount); + tableStatsBuilder.setLookupCount(new BigInteger(lookupCount)); + byte[] matchedCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(matchedCount); + tableStatsBuilder.setMatchedCount(new BigInteger(matchedCount)); + tableStatsList.add(tableStatsBuilder.build()); + } + builder.setTableStats(tableStatsList); return builder.build(); } private static MultipartReplyPortStats setPortStats(ByteBuf input) { final byte PADDING_IN_PORT_STATS_HEADER = 6; MultipartReplyPortStatsBuilder builder = new MultipartReplyPortStatsBuilder(); - PortStatsBuilder portStatsBuilder = new PortStatsBuilder(); List portStatsList = new ArrayList<>(); while (input.readableBytes() > 0) { + PortStatsBuilder portStatsBuilder = new PortStatsBuilder(); portStatsBuilder.setPortNo((long) input.readUnsignedShort()); input.skipBytes(PADDING_IN_PORT_STATS_HEADER); - byte[] rxPackets = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxPackets); portStatsBuilder.setRxPackets(new BigInteger(rxPackets)); - byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txPackets); portStatsBuilder.setTxPackets(new BigInteger(txPackets)); - byte[] rxBytes = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxBytes); portStatsBuilder.setRxBytes(new BigInteger(rxBytes)); - byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txBytes); portStatsBuilder.setTxBytes(new BigInteger(txBytes)); - byte[] rxDropped = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxDropped); portStatsBuilder.setRxDropped(new BigInteger(rxDropped)); - byte[] txDropped = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txDropped); portStatsBuilder.setTxDropped(new BigInteger(txDropped)); - byte[] rxErrors = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxErrors); portStatsBuilder.setRxErrors(new BigInteger(rxErrors)); - byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txErrors); portStatsBuilder.setTxErrors(new BigInteger(txErrors)); - byte[] rxFrameErr = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxFrameErr); portStatsBuilder.setRxFrameErr(new BigInteger(rxFrameErr)); - byte[] rxOverErr = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxOverErr); portStatsBuilder.setRxOverErr(new BigInteger(rxOverErr)); - byte[] rxCrcErr = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(rxCrcErr); portStatsBuilder.setRxCrcErr(new BigInteger(rxCrcErr)); - byte[] collisions = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(collisions); portStatsBuilder.setCollisions(new BigInteger(collisions)); - } - builder.setPortStats(new ArrayList<>(portStatsList)); - portStatsList.clear(); + builder.setPortStats(portStatsList); return builder.build(); } private static MultipartReplyQueue setQueue(ByteBuf input) { final byte PADDING_IN_QUEUE_HEADER = 2; MultipartReplyQueueBuilder builder = new MultipartReplyQueueBuilder(); - QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder(); List queueStatsList = new ArrayList<>(); - while (input.readableBytes() > 0) { + QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder(); queueStatsBuilder.setPortNo((long) input.readUnsignedShort()); input.skipBytes(PADDING_IN_QUEUE_HEADER); queueStatsBuilder.setQueueId(input.readUnsignedInt()); - byte[] txBytes = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txBytes); queueStatsBuilder.setTxBytes(new BigInteger(txBytes)); - byte[] txPackets = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txPackets); queueStatsBuilder.setTxPackets(new BigInteger(txPackets)); - byte[] txErrors = new byte[Long.SIZE/Byte.SIZE]; input.readBytes(txErrors); queueStatsBuilder.setTxErrors(new BigInteger(txErrors)); - queueStatsList.add(queueStatsBuilder.build()); } - builder.setQueueStats(new ArrayList<>(queueStatsList)); - queueStatsList.clear(); + builder.setQueueStats(queueStatsList); return builder.build(); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java index 0042b155..ba84fe86 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java @@ -10,8 +10,6 @@ import org.opendaylight.openflowjava.protocol.impl.util.MatchDeserializer; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * @author michal.polkorab @@ -22,9 +20,6 @@ public class PacketInMessageFactory implements OFDeserializer { private static PacketInMessageFactory instance; private static final byte PADDING_IN_PACKET_IN_HEADER = 2; - private static final Logger LOGGER = LoggerFactory - .getLogger(PacketInMessageFactory.class); - private PacketInMessageFactory() { // Singleton } @@ -53,7 +48,6 @@ public class PacketInMessageFactory implements OFDeserializer { builder.setCookie(new BigInteger(cookie)); builder.setMatch(MatchDeserializer.createMatch(rawMessage)); rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER); - LOGGER.info("readablebytes: " + rawMessage.readableBytes()); builder.setData(rawMessage.readBytes(rawMessage.readableBytes()).array()); return builder.build(); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactory.java index db4b8537..dd7d5df4 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactory.java @@ -21,6 +21,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions; 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.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.oxm.fields.MatchEntries; @@ -94,13 +95,100 @@ public class MultipartRequestMessageFactory implements OFSerializer tableFeatures = body.getTableFeatures(); + for (TableFeatures feature : tableFeatures) { + length += TABLE_FEATURES_LENGTH; + List featureProperties = feature.getTableFeatureProperties(); + if (featureProperties != null) { + for (TableFeatureProperties featProp : featureProperties) { + length += TABLE_FEAT_HEADER_LENGTH; + if (featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class) != null) { + InstructionRelatedTableFeatureProperty property = + featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class); + length += property.getInstructions().size() * STRUCTURE_HEADER_LENGTH; + } else if (featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class) != null) { + NextTableRelatedTableFeatureProperty property = + featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class); + length += property.getNextTableIds().size(); + } else if (featProp.getAugmentation(ActionRelatedTableFeatureProperty.class) != null) { + ActionRelatedTableFeatureProperty property = + featProp.getAugmentation(ActionRelatedTableFeatureProperty.class); + length += property.getActionsList().size() * STRUCTURE_HEADER_LENGTH; + } else if (featProp.getAugmentation(OxmRelatedTableFeatureProperty.class) != null) { + OxmRelatedTableFeatureProperty property = + featProp.getAugmentation(OxmRelatedTableFeatureProperty.class); + length += property.getMatchEntries().size() * STRUCTURE_HEADER_LENGTH; + } else if (featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class) != null) { + ExperimenterRelatedTableFeatureProperty property = + featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class); + length += 2 * (Integer.SIZE / Byte.SIZE); + if (property.getData() != null) { + length += property.getData().length; + } + } + } + } + } + } + return length; + } private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) { int multipartRequestFlagsBitmask = 0; @@ -177,7 +265,10 @@ public class MultipartRequestMessageFactory implements OFSerializer multipartRequestFlagsMap = new HashMap<>(); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java index 154a1814..5a55c1b1 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsDeserializer.java @@ -54,110 +54,108 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 * @author michal.polkorab */ public abstract class ActionsDeserializer { - private static ActionBuilder actionBuilder = new ActionBuilder(); - private static ActionsListBuilder actionsListBuilder = new ActionsListBuilder(); - private static List actionsList = new ArrayList<>(); + + private static final byte ACTION_HEADER_LENGTH = 4; /** * @param input input ByteBuf - * @param bucketsLength length of buckets + * @param actionsLength length of buckets * @return ActionsList */ - public static List createActionsList(ByteBuf input, int bucketsLength) { - final byte BUCKET_HEADER_LENGTH = 16; - final byte ACTION_HEADER_LENGTH = 4; - int bucketsCurrentLength = BUCKET_HEADER_LENGTH; - int actionsLength = 0; - - while (bucketsCurrentLength < bucketsLength) { - switch(input.readUnsignedShort()) { - case 0: actionsLength = input.readUnsignedShort(); //outputActionLength - actionsList.add(ActionsDeserializer.createOutputAction(input)); - break; - case 11: - actionsLength = input.readUnsignedShort();//empty header length - actionsList.add(ActionsDeserializer.createCopyTtlOutAction(input)); - break; - - case 12: - actionsLength = input.readUnsignedShort();//empty header length - actionsList.add(ActionsDeserializer.createCopyTtlInAction(input)); - break; - - case 15: - actionsLength = input.readUnsignedShort();//empty header length - actionsList.add(ActionsDeserializer.createSetMplsTtlAction(input)); - break; - - case 16: - actionsLength = input.readUnsignedShort();//empty header length - actionsList.add(ActionsDeserializer.createDecMplsTtlOutAction(input)); - break; - - case 17: - actionsLength = input.readUnsignedShort(); - actionsList.add(ActionsDeserializer.createPushVlanAction(input)); - break; - - case 18: - actionsLength = input.readUnsignedShort();//empty header length - actionsList.add(ActionsDeserializer.createPopVlanAction(input)); - break; - - case 19: - actionsLength = input.readUnsignedShort();//8 - actionsList.add(ActionsDeserializer.createPushMplsAction(input)); - break; - - case 20: - actionsLength = input.readUnsignedShort();//8 - actionsList.add(ActionsDeserializer.createPopMplsAction(input)); - break; - - case 21: - actionsLength = input.readUnsignedShort(); - actionsList.add(ActionsDeserializer.createSetQueueAction(input)); - break; - - case 22: - actionsLength = input.readUnsignedShort();//8 - actionsList.add(ActionsDeserializer.createGroupAction(input)); - break; - - case 23: - actionsLength = input.readUnsignedShort();//8 - actionsList.add(ActionsDeserializer.createSetNwTtlAction(input)); - break; - - case 24: - actionsLength = input.readUnsignedShort();//empty header length - actionsList.add(ActionsDeserializer.createDecNwTtlAction(input)); - break; - - case 25: - actionsLength = input.readUnsignedShort();//8 - actionsList.add(ActionsDeserializer.createSetFieldAction(input, - actionsLength - ACTION_HEADER_LENGTH)); - break; - case 26: - actionsLength = input.readUnsignedShort();//8 - actionsList.add(ActionsDeserializer.createPushPbbAction(input)); - break; - - case 27: - actionsLength = input.readUnsignedShort();//empty header length - actionsList.add(ActionsDeserializer.createPopPbbAction(input)); - break; - - case 0xFFFF: - actionsLength = input.readUnsignedShort(); - actionsList.add(ActionsDeserializer.createExperimenterAction(input)); - break; - default: - break; - } - bucketsCurrentLength += actionsLength; - } + public static List createActionsList(ByteBuf input, int actionsLength) { + ActionsListBuilder actionsListBuilder = new ActionsListBuilder(); + List actionsList = new ArrayList<>(); + int length = 0; + while (length < actionsLength) { + int currentActionLength = 0; + switch(input.readUnsignedShort()) { + case 0: currentActionLength = input.readUnsignedShort(); //outputActionLength + actionsList.add(ActionsDeserializer.createOutputAction(input, actionsListBuilder)); + break; + case 11: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(ActionsDeserializer.createCopyTtlOutAction(input, actionsListBuilder)); + break; + + case 12: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(ActionsDeserializer.createCopyTtlInAction(input, actionsListBuilder)); + break; + + case 15: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(ActionsDeserializer.createSetMplsTtlAction(input, actionsListBuilder)); + break; + + case 16: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(ActionsDeserializer.createDecMplsTtlOutAction(input, actionsListBuilder)); + break; + + case 17: + currentActionLength = input.readUnsignedShort(); + actionsList.add(ActionsDeserializer.createPushVlanAction(input, actionsListBuilder)); + break; + + case 18: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(ActionsDeserializer.createPopVlanAction(input, actionsListBuilder)); + break; + + case 19: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(ActionsDeserializer.createPushMplsAction(input, actionsListBuilder)); + break; + + case 20: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(ActionsDeserializer.createPopMplsAction(input, actionsListBuilder)); + break; + + case 21: + currentActionLength = input.readUnsignedShort(); + actionsList.add(ActionsDeserializer.createSetQueueAction(input, actionsListBuilder)); + break; + + case 22: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(ActionsDeserializer.createGroupAction(input, actionsListBuilder)); + break; + + case 23: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(ActionsDeserializer.createSetNwTtlAction(input, actionsListBuilder)); + break; + + case 24: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(ActionsDeserializer.createDecNwTtlAction(input, actionsListBuilder)); + break; + + case 25: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(ActionsDeserializer.createSetFieldAction(input, actionsListBuilder, + currentActionLength)); + break; + case 26: + currentActionLength = input.readUnsignedShort();//8 + actionsList.add(ActionsDeserializer.createPushPbbAction(input, actionsListBuilder)); + break; + + case 27: + currentActionLength = input.readUnsignedShort();//empty header length + actionsList.add(ActionsDeserializer.createPopPbbAction(input, actionsListBuilder)); + break; + + case 0xFFFF: + currentActionLength = input.readUnsignedShort(); + actionsList.add(ActionsDeserializer.createExperimenterAction(input, actionsListBuilder)); + break; + default: + break; + } + length += currentActionLength; + } return actionsList; } @@ -165,12 +163,14 @@ public abstract class ActionsDeserializer { /** * @param action input action that contains empty header * @param in input ByteBuf + * @param actionsListBuilder * @return Action */ private static ActionsList createEmptyHeader(Class action, ByteBuf in) { + urn.opendaylight.openflow.common.types.rev130731.Action> action, + ByteBuf in, ActionsListBuilder actionsListBuilder) { final byte PADDING_IN_ACTIONS_HEADER = 4; - + ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(action); in.skipBytes(PADDING_IN_ACTIONS_HEADER); actionsListBuilder.setAction(actionBuilder.build()); @@ -179,59 +179,66 @@ public abstract class ActionsDeserializer { /** * @param in input ByteBuf + * @param actionsListBuilder * @return Action */ - public static ActionsList createCopyTtlInAction(ByteBuf in) { - return createEmptyHeader(CopyTtlIn.class, in); + public static ActionsList createCopyTtlInAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(CopyTtlIn.class, in, actionsListBuilder); } /** * @param in input ByteBuf + * @param actionsListBuilder * @return Action */ - public static ActionsList createCopyTtlOutAction(ByteBuf in) { - return createEmptyHeader(CopyTtlOut.class, in); + public static ActionsList createCopyTtlOutAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(CopyTtlOut.class, in, actionsListBuilder); } /** * @param in input ByteBuf + * @param actionsListBuilder * @return Action */ - public static ActionsList createDecMplsTtlOutAction(ByteBuf in) { - return createEmptyHeader(DecMplsTtl.class, in); + public static ActionsList createDecMplsTtlOutAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(DecMplsTtl.class, in, actionsListBuilder); } /** * @param in input ByteBuf + * @param actionsListBuilder * @return Action */ - public static ActionsList createPopVlanAction(ByteBuf in) { - return createEmptyHeader(PopVlan.class, in); + public static ActionsList createPopVlanAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(PopVlan.class, in, actionsListBuilder); } /** * @param in input ByteBuf + * @param actionsListBuilder * @return Action */ - public static ActionsList createDecNwTtlAction(ByteBuf in) { - return createEmptyHeader(DecNwTtl.class, in); + public static ActionsList createDecNwTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(DecNwTtl.class, in, actionsListBuilder); } /** * @param in input ByteBuf + * @param actionsListBuilder * @return Action */ - public static ActionsList createPopPbbAction(ByteBuf in) { - return createEmptyHeader(PopPbb.class, in); + public static ActionsList createPopPbbAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createEmptyHeader(PopPbb.class, in, actionsListBuilder); } /** * @param in input ByteBuf + * @param actionsListBuilder * @return ActionList */ - public static ActionsList createOutputAction(ByteBuf in) { + public static ActionsList createOutputAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { final byte PADDING_IN_OUTPUT_ACTIONS_HEADER = 6; - + ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(Output.class); PortActionBuilder port = new PortActionBuilder(); port.setPort(new PortNumber(in.readUnsignedInt())); @@ -247,11 +254,12 @@ public abstract class ActionsDeserializer { /** * @param in input ByteBuf + * @param actionsListBuilder * @return ActionList */ - public static ActionsList createSetMplsTtlAction(ByteBuf in) { + public static ActionsList createSetMplsTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { final byte PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER = 3; - + ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(SetMplsTtl.class); MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder(); mplsTtl.setMplsTtl(in.readUnsignedByte()); @@ -265,11 +273,14 @@ public abstract class ActionsDeserializer { /** * @param action input action that contains push * @param in input ByteBuf + * @param actionsListBuilder * @return ActionList */ - private static ActionsList createPushAction(Class action, ByteBuf in) { + private static ActionsList createPushAction(Class action, + ByteBuf in, ActionsListBuilder actionsListBuilder) { final byte PADDING_IN_PUSH_VLAN_ACTIONS_HEADER = 2; - + ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(action); EthertypeActionBuilder etherType = new EthertypeActionBuilder(); etherType.setEthertype(new EtherType(in.readUnsignedShort())); @@ -282,41 +293,47 @@ public abstract class ActionsDeserializer { /** * @param in input ByteBuf + * @param actionsListBuilder * @return Action */ - public static ActionsList createPushVlanAction(ByteBuf in) { - return createPushAction(PushVlan.class, in); + public static ActionsList createPushVlanAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createPushAction(PushVlan.class, in, actionsListBuilder); } /** * @param in input ByteBuf + * @param actionsListBuilder * @return Action */ - public static ActionsList createPushMplsAction(ByteBuf in) { - return createPushAction(PushMpls.class, in); + public static ActionsList createPushMplsAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createPushAction(PushMpls.class, in, actionsListBuilder); } /** * @param in input ByteBuf + * @param actionsListBuilder * @return Action */ - public static ActionsList createPopMplsAction(ByteBuf in) { - return createPushAction(PopMpls.class, in); + public static ActionsList createPopMplsAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createPushAction(PopMpls.class, in, actionsListBuilder); } /** * @param in input ByteBuf + * @param actionsListBuilder * @return Action */ - public static ActionsList createPushPbbAction(ByteBuf in) { - return createPushAction(PushPbb.class, in); + public static ActionsList createPushPbbAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + return createPushAction(PushPbb.class, in, actionsListBuilder); } /** * @param in input ByteBuf + * @param actionsListBuilder * @return ActionList */ - public static ActionsList createSetQueueAction(ByteBuf in) { + public static ActionsList createSetQueueAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(SetQueue.class); QueueIdActionBuilder queueId = new QueueIdActionBuilder(); queueId.setQueueId(in.readUnsignedInt()); @@ -328,9 +345,11 @@ public abstract class ActionsDeserializer { /** * @param in input ByteBuf + * @param actionsListBuilder * @return ActionList */ - public static ActionsList createGroupAction(ByteBuf in) { + public static ActionsList createGroupAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(Group.class); GroupIdActionBuilder group = new GroupIdActionBuilder(); group.setGroupId(in.readUnsignedInt()); @@ -342,9 +361,11 @@ public abstract class ActionsDeserializer { /** * @param in input ByteBuf + * @param actionsListBuilder * @return ActionList */ - public static ActionsList createExperimenterAction(ByteBuf in) { + public static ActionsList createExperimenterAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { + ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(Experimenter.class); ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder(); experimenter.setExperimenter(in.readUnsignedInt()); @@ -356,11 +377,12 @@ public abstract class ActionsDeserializer { /** * @param in input ByteBuf + * @param actionsListBuilder * @return ActionList */ - public static ActionsList createSetNwTtlAction(ByteBuf in) { + public static ActionsList createSetNwTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) { final byte PADDING_IN_NW_TTL_ACTIONS_HEADER = 3; - + ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(SetNwTtl.class); NwTtlActionBuilder nwTtl = new NwTtlActionBuilder(); nwTtl.setNwTtl(in.readUnsignedByte()); @@ -373,13 +395,15 @@ public abstract class ActionsDeserializer { /** * @param in input ByteBuf + * @param actionsListBuilder * @param actionLength length of action * @return ActionList */ - public static ActionsList createSetFieldAction(ByteBuf in, int actionLength) { + public static ActionsList createSetFieldAction(ByteBuf in, ActionsListBuilder actionsListBuilder, int actionLength) { + ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setType(SetField.class); OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder(); - matchEntries.setMatchEntries(MatchDeserializer.createMatchEntries(in, actionLength)); + matchEntries.setMatchEntries(MatchDeserializer.createMatchEntry(in, actionLength - ACTION_HEADER_LENGTH)); actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build()); actionsListBuilder.setAction(actionBuilder.build()); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java index 3f92f990..5746ea0e 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ActionsSerializer.java @@ -34,8 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries; /** * Class for easy serialization of actions @@ -45,8 +44,6 @@ import org.slf4j.LoggerFactory; */ public abstract class ActionsSerializer { - private static final Logger LOGGER = LoggerFactory.getLogger(ActionsSerializer.class); - /** * Encodes actions to ByteBuf * @param actionsList list of actions to be encoded @@ -199,11 +196,9 @@ public abstract class ActionsSerializer { private static void encodeSetFieldAction(Action action, ByteBuf outBuffer) { final int SET_FIELD_CODE = 25; - final byte SET_FIELD_FIELDS_LENGTH = 4; // only type and length - // TODO - figure out definition from testing + check length + final byte SET_FIELD_HEADER_LENGTH = 4; // only type and length OxmFieldsAction oxmField = action.getAugmentation(OxmFieldsAction.class); - int length = MatchSerializer.computeMatchEntriesLength(oxmField.getMatchEntries()) + SET_FIELD_FIELDS_LENGTH; - LOGGER.warn("Received set-field action - possible wrong or no implementation"); + int length = MatchSerializer.computeMatchEntriesLength(oxmField.getMatchEntries()) + SET_FIELD_HEADER_LENGTH; outBuffer.writeShort(SET_FIELD_CODE); int paddingRemainder = length % EncodeConstants.PADDING; if (paddingRemainder != 0) { @@ -257,12 +252,21 @@ public abstract class ActionsSerializer { public static int computeLengthOfActions(List actionsList) { final byte OUTPUT_LENGTH = 16; final byte LENGTH_OF_OTHER_ACTIONS = 8; + final byte ACTION_HEADER_LENGTH = 4; int lengthOfActions = 0; if (actionsList != null) { for (ActionsList list : actionsList) { Action action = list.getAction(); if (action.getType().equals(Output.class)) { lengthOfActions += OUTPUT_LENGTH; + } else if (action.getType().equals(SetField.class)){ + List entries = action.getAugmentation(OxmFieldsAction.class).getMatchEntries(); + int actionLength = ACTION_HEADER_LENGTH + MatchSerializer.computeMatchEntriesLength(entries); + lengthOfActions += actionLength; + int paddingRemainder = actionLength % EncodeConstants.PADDING; + if ((paddingRemainder) != 0) { + lengthOfActions += EncodeConstants.PADDING - paddingRemainder; + } } else { lengthOfActions += LENGTH_OF_OTHER_ACTIONS; } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java index 4567a7b3..dba41160 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchDeserializer.java @@ -130,8 +130,7 @@ public abstract class MatchDeserializer { private static final byte SIZE_OF_SHORT_IN_BYTES = Short.SIZE / Byte.SIZE; private static final byte SIZE_OF_BYTE_IN_BYTES = Byte.SIZE / Byte.SIZE; private static final byte SIZE_OF_IPV6_ADDRESS_IN_BYTES = (8 * Short.SIZE) / Byte.SIZE; - private static List matchEntriesList = new ArrayList<>(); - private static MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); + /** * Creates match @@ -143,7 +142,6 @@ public abstract class MatchDeserializer { MatchBuilder builder = new MatchBuilder(); int type = in.readUnsignedShort(); int length = in.readUnsignedShort(); - LOGGER.debug("length: " + length); switch (type) { case 0: builder.setType(StandardMatchType.class); @@ -164,14 +162,29 @@ public abstract class MatchDeserializer { return null; } + /** + * @param in input ByteBuf + * @param matchLength to infer size of array + * @return MatchEntriesList + */ + public static List createMatchEntry(ByteBuf in, int matchLength) { + return createMatchEntriesInternal(in, matchLength, true); + } + /** * @param in input ByteBuf * @param matchLength to infer size of array * @return MatchEntriesList */ public static List createMatchEntries(ByteBuf in, int matchLength) { + return createMatchEntriesInternal(in, matchLength, false); + } + + private static List createMatchEntriesInternal(ByteBuf in, int matchLength, boolean oneEntry) { + List matchEntriesList = new ArrayList<>(); int currLength = 0; while(currLength < matchLength) { + MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); switch (in.readUnsignedShort()) { case 0x0000: matchEntriesBuilder.setOxmClass(Nxm0Class.class); @@ -476,6 +489,12 @@ public abstract class MatchDeserializer { break; } matchEntriesList.add(matchEntriesBuilder.build()); + if (oneEntry) { + break; + } + } + if ((matchLength - currLength) > 0) { + in.skipBytes(matchLength - currLength); } return matchEntriesList; } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java index bb2bb5b0..e36e7d42 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/MatchSerializer.java @@ -133,7 +133,7 @@ public class MatchSerializer { */ public static void encodeMatchEntries(List matchEntries, ByteBuf out) { if (matchEntries == null) { - LOGGER.warn("Match entry is null"); + LOGGER.warn("Match entries are null"); return; } for (MatchEntries entry : matchEntries) { @@ -518,9 +518,11 @@ public class MatchSerializer { * @return length of MatchEntries */ public static int computeMatchEntriesLength(List matchEntries) { + final byte MATCH_ENTRY_HEADER_LENGTH = 4; int length = 0; if (matchEntries != null) { for (MatchEntries entry : matchEntries) { + length += MATCH_ENTRY_HEADER_LENGTH; Class field = entry.getOxmMatchField(); if (field.equals(InPort.class)) { length += Integer.SIZE / Byte.SIZE; diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java index 3aa99e1e..bf2bc82f 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java @@ -6,6 +6,7 @@ import io.netty.buffer.ByteBuf; import org.junit.Assert; import org.junit.Test; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; /** @@ -20,7 +21,7 @@ public class FeaturesReplyMessageFactoryTest { @Test public void test() { ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00" - + " 01 02 03 00 01 02 03"); + + " 00 01 41 00 01 02 03"); GetFeaturesOutput builtByFactory = BufferHelper.decodeV13( FeaturesReplyMessageFactory.getInstance(), bb); @@ -29,9 +30,7 @@ public class FeaturesReplyMessageFactoryTest { Assert.assertEquals("Wrong buffers", 0x00010203L, builtByFactory.getBuffers().longValue()); Assert.assertEquals("Wrong number of tables", 0x01, builtByFactory.getTables().shortValue()); Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue()); - - //TODO - fix test - //Assert.assertEquals("Wrong capabilities", 0x00010203L, builtByFactory.getCapabilities().longValue()); + Assert.assertEquals("Wrong capabilities", new Capabilities(true, false, false, true, false, true, false), builtByFactory.getCapabilities()); Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue()); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java index a20374d4..c10c4ac5 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java @@ -11,7 +11,6 @@ import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction; @@ -24,7 +23,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev1 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.DecNwTtl; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter; 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.PopMpls; @@ -42,7 +40,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState; -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.OpenflowBasicClass; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; @@ -62,6 +59,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStats; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueue; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author timotej.kubas @@ -69,6 +68,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class MultipartReplyMessageFactoryTest { + private static final Logger LOGGER = LoggerFactory + .getLogger(MultipartReplyMessageFactoryTest.class); + /** * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO *//* @@ -851,11 +853,10 @@ public class MultipartReplyMessageFactoryTest { message.getPorts().get(0).getHwAddr()); Assert.assertEquals("Wrong portName", "SampleText", message.getPorts().get(0).getName()); - //TODO - fix test - //Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), - // message.getPorts().get(0).getConfig()); - //Assert.assertEquals("Wrong portState", new PortState(true, false, true), - // message.getPorts().get(0).getState()); + Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), + message.getPorts().get(0).getConfig()); + Assert.assertEquals("Wrong portState", new PortState(false, true, true), + message.getPorts().get(0).getState()); Assert.assertEquals("Wrong currentFeatures", new PortFeatures(true, false, false, false, false, false, false, true, false, false, false, false, @@ -911,7 +912,6 @@ public class MultipartReplyMessageFactoryTest { "00 08 "+//copyTTLIntLen "00 00 00 00"//copyTTLInPad ); - MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); BufferHelper.checkHeaderV13(builtByFactory); @@ -1156,15 +1156,14 @@ public class MultipartReplyMessageFactoryTest { * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO * Test covers bodies of actions NW TTL, Experimenter */ - //@Test - // TODO - fix test + @Test public void testMultipartReplyGroupDescBody04(){ ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+ - "00 3C "+//len + "00 30 "+//len "01 "+//type "00 "+//pad "00 00 00 08 "+//groupId - "00 34 "+//bucketLen + "00 28 "+//bucketLen "00 06 "+//bucketWeight "00 00 00 05 "+//bucketWatchPort "00 00 00 04 "+//bucketWatchGroup @@ -1173,21 +1172,14 @@ public class MultipartReplyMessageFactoryTest { "00 08 "+//nwTTlLen "0E "+//nwTTlnwTTL "00 00 00 "+//nwTTlPad - "FF FF "+//experimenterType - "00 08 "+//experimenterLen - "00 01 02 03 "+//experimenterExperimenter "00 19 "+//setFieldType - "00 14 "+//setFieldLen + "00 10 "+//setFieldLen "80 00 "+//setFieldOXMClass "00 "+//setFieldOXMField "04 "+//setFieldOXMLength - "00 00 00 FF "+//setFieldPort - - "80 00 "+//setFieldOXMClass - "03 "+//setFieldOXMField - "04 "+//setFieldOXMLength - "00 00 0F FF"//setFieldPort - ); + "00 00 00 FF "+ //setFieldPort + "00 00 00 00" + ); MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); @@ -1217,43 +1209,21 @@ public class MultipartReplyMessageFactoryTest { message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0). getAction().getAugmentation(NwTtlAction.class).getNwTtl().intValue()); - Assert.assertEquals("Wrong experimenterType", Experimenter.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). - getAction().getType()); - - Assert.assertEquals("Wrong experimenterExperimenter", 66051, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). - getAction().getAugmentation(ExperimenterAction.class).getExperimenter().intValue()); - Assert.assertEquals("Wrong setFieldType", SetField.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). getAction().getType()); Assert.assertEquals("Wrong setFieldOXMClass", OpenflowBasicClass.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).getOxmClass()); Assert.assertEquals("Wrong setFieldOXMField", InPort.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).getOxmMatchField()); - Assert.assertEquals("Wrong setFieldOXMField", 255, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). + Assert.assertEquals("Wrong setFieldOXMValue", 255, + message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1). getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0). getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); - - - Assert.assertEquals("Wrong setFieldOXMClass", OpenflowBasicClass.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). - getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(1).getOxmClass()); - - Assert.assertEquals("Wrong setFieldOXMField", InPhyPort.class, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). - getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(1).getOxmMatchField()); - - Assert.assertEquals("Wrong setFieldOXMField", 4095, - message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2). - getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(1). - getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue()); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java index 517abaef..ddb9a794 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java @@ -46,9 +46,8 @@ public class PortStatusMessageFactoryTest { Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue()); Assert.assertEquals("Wrong portNumber", 66051L, builtByFactory.getPortNo().longValue()); Assert.assertEquals("Wrong macAddress", new MacAddress("08002700B0EB"), builtByFactory.getHwAddr()); - //TODO - fix test - //Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), builtByFactory.getConfig()); - //Assert.assertEquals("Wrong portState", new PortState(true, false, true), builtByFactory.getState()); + Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), builtByFactory.getConfig()); + Assert.assertEquals("Wrong portState", new PortState(false, true, true), builtByFactory.getState()); Assert.assertEquals("Wrong currentFeatures", new PortFeatures(true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false), builtByFactory.getCurrentFeatures()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java index b0ea6cb6..eb2cdc7c 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryMultiTest.java @@ -9,6 +9,8 @@ import java.util.List; import org.junit.Assert; import org.junit.Test; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; @@ -28,26 +30,28 @@ public class QueueGetConfigReplyMessageFactoryMultiTest { * Testing of {@link QueueGetConfigReplyMessageFactory} for correct * translation into POJO */ - //@Test - // TODO - fix test + @Test public void test() { ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 " + // port "00 00 00 00 " + // padding "00 00 00 01 " + // queueId "00 00 00 01 " + // port - "00 00 00 00 00 00 00 00 " + // pad - "00 01 " + // property + "00 20 " + // length + "00 00 00 00 00 00 " + // pad + "00 02 " + // property + "00 10 " + // length + "00 00 00 00 " + // pad + "00 05 " + // rate "00 00 00 00 00 00 " + // pad "00 00 00 02 " + // queueId "00 00 00 02 " + // port - "00 00 00 00 00 00 00 00 " + // pad - "00 01 " + // property + "00 20 " + // length "00 00 00 00 00 00 " + // pad - "00 00 00 03 " + // queueId - "00 00 00 03 " + // port - "00 00 00 00 00 00 00 00 " + // pad - "00 01 " + // property - "00 00 00 00 00 00" // pad + "00 02 " + // property + "00 10 " + // length + "00 00 00 00 " + // pad + "00 05 " + // rate + "00 00 00 00 00 00 " // pad ); GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13( @@ -55,14 +59,13 @@ public class QueueGetConfigReplyMessageFactoryMultiTest { BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue()); - Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), - createQueuesList()); + Assert.assertEquals("Wrong queues", createQueuesList(), builtByFactory.getQueues()); } private static List createQueuesList() { List queuesList = new ArrayList<>(); - QueuesBuilder qb = new QueuesBuilder(); - for (int i = 1; i <= 3; i++) { + for (int i = 1; i < 3; i++) { + QueuesBuilder qb = new QueuesBuilder(); qb.setQueueId(new QueueId((long) i)); qb.setPort(new PortNumber((long) i)); qb.setQueueProperty(createPropertiesList()); @@ -74,7 +77,10 @@ public class QueueGetConfigReplyMessageFactoryMultiTest { private static List createPropertiesList() { List propertiesList = new ArrayList<>(); QueuePropertyBuilder pb = new QueuePropertyBuilder(); - pb.setProperty(QueueProperties.forValue(1)); + pb.setProperty(QueueProperties.forValue(2)); + RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder(); + rateBuilder.setRate(5); + pb.addAugmentation(RateQueueProperty.class, rateBuilder.build()); propertiesList.add(pb.build()); return propertiesList; } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java index db1c9c95..cf50b277 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactoryTest.java @@ -9,6 +9,8 @@ import java.util.List; import org.junit.Assert; import org.junit.Test; import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties; @@ -27,13 +29,12 @@ public class QueueGetConfigReplyMessageFactoryTest { /** * Testing {@link QueueGetConfigReplyMessageFactory} for correct translation into POJO */ - //@Test - // TODO - fix test + @Test public void test(){ - ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 00 00 00 00 00 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00"); + ByteBuf bb = BufferHelper.buildBuffer("00 00 00 03 00 00 00 00 00 00 00 01 00 00 00 03 00 20 00 00 00 00 00 00 00 02 00 10 00 00 00 00 00 05 00 00 00 00 00 00"); GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(QueueGetConfigReplyMessageFactory.getInstance(), bb); BufferHelper.checkHeaderV13(builtByFactory); - Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue()); + Assert.assertEquals("Wrong port", 3L, builtByFactory.getPort().getValue().longValue()); Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), createQueuesList()); } @@ -41,7 +42,7 @@ public class QueueGetConfigReplyMessageFactoryTest { List queuesList = new ArrayList<>(); QueuesBuilder qb = new QueuesBuilder(); qb.setQueueId(new QueueId(1L)); - qb.setPort(new PortNumber(1L)); + qb.setPort(new PortNumber(3L)); qb.setQueueProperty(createPropertiesList()); queuesList.add(qb.build()); @@ -52,8 +53,10 @@ public class QueueGetConfigReplyMessageFactoryTest { List propertiesList = new ArrayList<>(); QueuePropertyBuilder pb = new QueuePropertyBuilder(); pb.setProperty(QueueProperties.forValue(2)); + RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder(); + rateBuilder.setRate(5); + pb.addAugmentation(RateQueueProperty.class, rateBuilder.build()); propertiesList.add(pb.build()); - return propertiesList; } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactoryTest.java index d0baa17d..68b7ca09 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/MultipartRequestMessageFactoryTest.java @@ -393,8 +393,7 @@ public class MultipartRequestMessageFactoryTest { * @throws Exception * Testing of {@link MultipartRequestMessageFactory} for correct translation from POJO */ - //@Test - //TODO - fix test + @Test public void testMultipartRequestExperimenterMessageFactory() throws Exception { MultipartRequestMessageBuilder builder = new MultipartRequestMessageBuilder(); BufferHelper.setupHeader(builder); @@ -438,7 +437,7 @@ public class MultipartRequestMessageFactoryTest { public void testMultipartRequestTableFeaturesMessageFactory() throws Exception { MultipartRequestMessageBuilder builder = new MultipartRequestMessageBuilder(); BufferHelper.setupHeader(builder); - builder.setType(MultipartType.forValue(0xffff)); + builder.setType(MultipartType.forValue(12)); builder.setFlags(new MultipartRequestFlags(true)); builder.setMultipartRequestBody(createRequestTableFeatures()); MultipartRequestMessage message = builder.build(); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java index afc03ba4..e3d83798 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PortModInputMessageFactoryTest.java @@ -36,7 +36,6 @@ public class PortModInputMessageFactoryTest { BufferHelper.setupHeader(builder); builder.setPortNo(new PortNumber(9L)); builder.setHwAddress(new MacAddress("08002700B0EB")); - //TODO - fix test builder.setConfig(new PortConfig(true, false, true, false)); builder.setMask(new PortConfig(false, true, false, true)); builder.setAdvertise(new PortFeatures(true, false, false, false, diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java index 0cb42307..501453bd 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/TableModInputMessageFactoryTest.java @@ -30,7 +30,6 @@ public class TableModInputMessageFactoryTest { TableModInputBuilder builder = new TableModInputBuilder(); BufferHelper.setupHeader(builder); builder.setTableId(new TableId(9L)); - //TODO - fix test builder.setConfig(new PortConfig(true, false, true, false)); TableModInput message = builder.build(); -- 2.36.6