From d97676f22d78da6654f00969f628e33275ad9a61 Mon Sep 17 00:00:00 2001 From: Timotej Kubas Date: Tue, 22 Oct 2013 10:11:30 +0200 Subject: [PATCH] multipart request message updated added meter features, meter config, experimenter, meter description in multipart reply message changes in YANG (buckets changed to bucket list, added field data in experimenter multipart reply message) Change-Id: I67c219c5b069da482092e2206eb038217e192809 Signed-off-by: Timotej Kubas --- .../src/main/yang/openflow-action.yang | 92 ---- .../src/main/yang/openflow-protocol.yang | 7 +- .../MultipartReplyMessageFactory.java | 279 ++++++++++- .../GroupModInputMessageFactory.java | 10 +- .../MultipartReplyMessageFactoryTest.java | 452 ++++++++++++++++++ .../PortStatusMessageFactoryTest.java | 8 +- .../GroupModInputMessageFactoryTest.java | 22 +- 7 files changed, 749 insertions(+), 121 deletions(-) diff --git a/openflow-protocol-api/src/main/yang/openflow-action.yang b/openflow-protocol-api/src/main/yang/openflow-action.yang index 232a1470..43157f2b 100644 --- a/openflow-protocol-api/src/main/yang/openflow-action.yang +++ b/openflow-protocol-api/src/main/yang/openflow-action.yang @@ -77,98 +77,6 @@ module openflow-action { base oft:action; } - /* - grouping output { - description - "Action structure for OFPAT_OUTPUT, which sends packets out 'port'. - When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max - number of bytes to send. A 'max_len' of zero means no bytes of the - packet should be sent. A 'max_len' of OFPCML_NO_BUFFER means that - the packet is not buffered and the complete packet is to be sent to - the controller."; - leaf port { - type oft:any-port-number; - } - leaf max-length { - description "Maximum packet length to be send to controller."; - type union { - type uint16 { - range "0..65294"; // 0..0xff0e - } - type enumeration { - enum max { - desription - "maximum max_len value which can be used - to request a specific byte length"; - value 65509; //0xffe5 - } - enum no-buffer { - description - "indicates that no buffering should be - applied and the whole packet is to be - sent to the controller"; - value 65535; //0xffff - } - } - } - } - } - - grouping group { - leaf group { - type oft:group-id; // define action group-id type; - } - } - - grouping set-queue { - leaf queue { - type oft:queue-id; - } - } - - grouping set-mpls-ttl { - leaf mpls_ttl { - type uint8; - } - } - - grouping set-nw-ttl { - leaf nw_ttl { - type uint8; - } - } - - grouping push-pbb { - leaf ethertype { - type oft:ether-type; - } - } - - grouping push-mpls { - leaf ethertype { - type oft:ether-type; - } - } - - grouping push-vlan { - leaf ethertype { - type oft:ether-type; - } - } - - grouping pop-mpls { - leaf ethertype { - type oft:ether-type; - } - } - - grouping set-field { - container field { - // TODO: figure definition - } - } - */ - container actions-container { uses action-header; } diff --git a/openflow-protocol-api/src/main/yang/openflow-protocol.yang b/openflow-protocol-api/src/main/yang/openflow-protocol.yang index d0e087b3..d9afe212 100644 --- a/openflow-protocol-api/src/main/yang/openflow-protocol.yang +++ b/openflow-protocol-api/src/main/yang/openflow-protocol.yang @@ -417,7 +417,7 @@ module openflow-protocol { type uint32; } - list buckets { + list buckets-list { uses bucket; } } @@ -793,7 +793,7 @@ module openflow-protocol { leaf group-id { type uint32; } - list buckets { + list buckets-list { uses bucket; } } @@ -909,6 +909,9 @@ module openflow-protocol { leaf exp-type { type uint32; } + leaf data { + type binary; + } } } } 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 64bf2ac3..c8bfe6e0 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 @@ -8,19 +8,39 @@ import java.util.ArrayList; import java.util.List; import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; +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.common.types.rev130731.FlowModFlags; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterBandType; +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.MeterModCommand; 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.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.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.meter.band.header.meter.band.MeterBandDropBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemarkBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregate; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregateBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDesc; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDescBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroup; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroupBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfigBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeaturesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDescBuilder; 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.MultipartReplyPortStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueue; @@ -33,6 +53,16 @@ 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.group.GroupStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.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.group.stats.BucketStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.MeterStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.MeterStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config.MeterConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config.MeterConfigBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config.meter.config.Bands; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config.meter.config.BandsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.meter.stats.MeterBandStats; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.meter.stats.MeterBandStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc.Ports; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.desc.PortsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.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.PortStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue.QueueStats; @@ -89,6 +119,16 @@ public class MultipartReplyMessageFactory implements OFDeserializer flowStatsList = new ArrayList<>(); FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder(); + int flowLen = 0; while (input.readableBytes() > 0) { + flowLen = input.readUnsignedShort(); flowStatsBuilder.setTableId(input.readUnsignedByte()); input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_01); flowStatsBuilder.setDurationSec(input.readUnsignedInt()); @@ -152,7 +194,8 @@ public class MultipartReplyMessageFactory implements OFDeserializer(flowStatsList)); + flowStatsList.clear(); return flowBuilder.build(); } @@ -196,7 +239,8 @@ public class MultipartReplyMessageFactory implements OFDeserializer(tableStatsList)); + tableStatsList.clear(); return builder.build(); } @@ -261,7 +305,8 @@ public class MultipartReplyMessageFactory implements OFDeserializer(portStatsList)); + portStatsList.clear(); return builder.build(); } @@ -290,7 +335,8 @@ public class MultipartReplyMessageFactory implements OFDeserializer(queueStatsList)); + queueStatsList.clear(); return builder.build(); } @@ -334,12 +380,231 @@ public class MultipartReplyMessageFactory implements OFDeserializer(bucketStatsList)); + bucketStatsList.clear(); + groupStatsList.add(groupStatsBuilder.build()); + } + builder.setGroupStats(new ArrayList<>(groupStatsList)); + groupStatsList.clear(); + return builder.build(); + } + + private static MultipartReplyMeterFeatures setMeterFeatures(ByteBuf input) { + final byte PADDING_IN_METER_FEATURES_HEADER = 2; + MultipartReplyMeterFeaturesBuilder builder = new MultipartReplyMeterFeaturesBuilder(); + builder.setMaxMeter(input.readUnsignedInt()); + builder.setBandTypes(MeterBandType.forValue(input.readInt())); + builder.setCapabilities(decodeMeterModFlags((int) input.readUnsignedInt())); + builder.setMaxBands(input.readUnsignedByte()); + builder.setMaxColor(input.readUnsignedByte()); + input.skipBytes(PADDING_IN_METER_FEATURES_HEADER); + return builder.build(); + } + + private static MeterFlags decodeMeterModFlags(int input){ + final Boolean _oFPMFKBPS = (input & (1 << 0)) > 0; + final Boolean _oFPMFPKTPS = (input & (1 << 1)) > 0; + final Boolean _oFPMFBURST = (input & (1 << 2)) > 0; + final Boolean _oFPMFSTATS = (input & (1 << 3)) > 0; + return new MeterFlags(_oFPMFBURST, _oFPMFKBPS, _oFPMFPKTPS, _oFPMFSTATS); + } + + private static MultipartReplyMeter setMeter(ByteBuf input) { + final byte PADDING_IN_METER_STATS_HEADER = 6; + final byte METER_BAND_STATS_LENGTH = 16; + final byte METER_BODY_LENGTH = 40; + int actualLength; + MultipartReplyMeterBuilder builder = new MultipartReplyMeterBuilder(); + List meterStatsList = new ArrayList<>(); + MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder(); + List meterBandStatsList = new ArrayList<>(); + MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder(); + while (input.readableBytes() > 0) { + meterStatsBuilder.setMeterId(input.readUnsignedInt()); + actualLength = 0; + int meterStatsBodyLength = input.readUnsignedShort(); + input.skipBytes(PADDING_IN_METER_STATS_HEADER); + meterStatsBuilder.setFlowCount(input.readUnsignedInt()); + byte[] packetInCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(packetInCount); + meterStatsBuilder.setPacketInCount(new BigInteger(packetInCount)); + byte[] byteInCount = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(byteInCount); + meterStatsBuilder.setByteInCount(new BigInteger(byteInCount)); + meterStatsBuilder.setDurationSec(input.readUnsignedInt()); + meterStatsBuilder.setDurationNsec(input.readUnsignedInt()); + actualLength = METER_BODY_LENGTH; + + while (actualLength < meterStatsBodyLength) { + 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; + } + + meterStatsBuilder.setMeterBandStats(new ArrayList<>(meterBandStatsList)); + meterBandStatsList.clear(); + meterStatsList.add(meterStatsBuilder.build()); + } + builder.setMeterStats(new ArrayList<>(meterStatsList)); + meterStatsList.clear(); + return builder.build(); + } + + private static MultipartReplyMeterConfig setMeterConfig(ByteBuf input) { + final byte METER_BAND_LENGTH = 16; + final byte METER_CONFIG_LENGTH = 8; + int actualLength; + MultipartReplyMeterConfigBuilder builder = new MultipartReplyMeterConfigBuilder(); + List meterConfigList = new ArrayList<>(); + MeterConfigBuilder meterConfigBuilder = new MeterConfigBuilder(); + List bandsList = new ArrayList(); + BandsBuilder bandsBuilder = new BandsBuilder(); + + while (input.readableBytes() > 0) { + int meterConfigBodyLength = input.readUnsignedShort(); + actualLength = 0; + meterConfigBuilder.setFlags(MeterModCommand.forValue(input.readUnsignedShort())); + meterConfigBuilder.setMeterId(input.readUnsignedInt()); + actualLength = METER_CONFIG_LENGTH; + + 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(); + int bandLen = 0; + int bandType = input.readUnsignedShort(); + switch (bandType) { + case 1: bandDropBuilder.setType(MeterBandType.forValue(bandType)); + bandLen = 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: bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType)); + bandLen = 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: bandExperimenterBuilder.setType(MeterBandType.forValue(bandType)); + bandLen = 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(); + meterConfigList.add(meterConfigBuilder.build()); } - builder.setGroupStats(groupStatsList); + builder.setMeterConfig(new ArrayList<>(meterConfigList)); + meterConfigList.clear(); + return builder.build(); + } + + private static MultipartReplyExperimenter setExperimenter(ByteBuf input) { + MultipartReplyExperimenterBuilder builder = new MultipartReplyExperimenterBuilder(); + builder.setExperimenter(input.readUnsignedInt()); + builder.setExpType(input.readUnsignedInt()); + byte[] data = new byte[Long.SIZE/Byte.SIZE]; + input.readBytes(data); + builder.setData(data); return builder.build(); } + + private static MultipartReplyPortDesc setPortDesc(ByteBuf input) { + final byte PADDING_IN_PORT_DESC_HEADER_01 = 4; + final byte PADDING_IN_PORT_DESC_HEADER_02 = 2; + final int macAddressLength = 6; + final byte MAX_PORT_NAME_LEN = 16; + MultipartReplyPortDescBuilder builder = new MultipartReplyPortDescBuilder(); + List portsList = new ArrayList<>(); + PortsBuilder portsBuilder = new PortsBuilder(); + + while (input.readableBytes() > 0) { + portsBuilder.setPortNo(input.readUnsignedInt()); + input.skipBytes(PADDING_IN_PORT_DESC_HEADER_01); + StringBuffer macToString = new StringBuffer(); + for(int i=0; i(portsList)); + portsList.clear(); + return builder.build(); + } + + private static PortConfig createPortConfig(long input){ + final Boolean _portDown = ((input) & (1<<0)) != 0; + final Boolean _noRecv = ((input) & (1<<2)) != 0; + final Boolean _noFwd = ((input) & (1<<5)) != 0; + final Boolean _noPacketIn = ((input) & (1<<6)) != 0; + return new PortConfig(_noFwd, _noPacketIn, _noRecv, _portDown); + } + + private static PortState createPortState(long input){ + final Boolean _linkDown = ((input) & (1<<0)) != 0; + final Boolean _blocked = ((input) & (1<<1)) != 0; + final Boolean _live = ((input) & (1<<2)) != 0; + return new PortState(_linkDown, _blocked,_live); + } + + private static PortFeatures createPortFeatures(long input){ + final Boolean _10mbHd = ((input) & (1<<0)) != 0; + final Boolean _10mbFd = ((input) & (1<<1)) != 0; + final Boolean _100mbHd = ((input) & (1<<2)) != 0; + final Boolean _100mbFd = ((input) & (1<<3)) != 0; + final Boolean _1gbHd = ((input) & (1<<4)) != 0; + final Boolean _1gbFd = ((input) & (1<<5)) != 0; + final Boolean _10gbFd = ((input) & (1<<6)) != 0; + final Boolean _40gbFd = ((input) & (1<<7)) != 0; + final Boolean _100gbFd = ((input) & (1<<8)) != 0; + final Boolean _1tbFd = ((input) & (1<<9)) != 0; + final Boolean _other = ((input) & (1<<10)) != 0; + final Boolean _copper = ((input) & (1<<11)) != 0; + final Boolean _fiber = ((input) & (1<<12)) != 0; + final Boolean _autoneg = ((input) & (1<<13)) != 0; + final Boolean _pause = ((input) & (1<<14)) != 0; + final Boolean _pauseAsym = ((input) & (1<<15)) != 0; + return new PortFeatures(_10mbHd, _10mbFd, _100mbHd, _100mbFd, _1gbHd, _1gbFd, _10gbFd, + _40gbFd, _100gbFd, _1tbFd, _other, _copper, _fiber, _autoneg, _pause, _pauseAsym); + } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java index ef30ec04..2c5d8519 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactory.java @@ -9,7 +9,7 @@ import java.util.List; import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.group.mod.Buckets; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.group.mod.BucketsList; /** * @author timotej.kubas @@ -43,7 +43,7 @@ public class GroupModInputMessageFactory implements OFSerializer out.writeByte(message.getType().getIntValue()); ByteBufUtils.padBuffer(PADDING_IN_GROUP_MOD_MESSAGE, out); out.writeInt(message.getGroupId().intValue()); - encodeBuckets(message.getBuckets(), out); + encodeBuckets(message.getBucketsList(), out); } @Override @@ -56,11 +56,11 @@ public class GroupModInputMessageFactory implements OFSerializer return MESSAGE_TYPE; } - private static void encodeBuckets(List buckets, ByteBuf outBuffer) { + private static void encodeBuckets(List buckets, ByteBuf outBuffer) { final byte PADDING_IN_BUCKET = 4; - for (Iterator iterator = buckets.iterator(); iterator.hasNext();) { - Buckets currentBucket = iterator.next(); + for (Iterator iterator = buckets.iterator(); iterator.hasNext();) { + BucketsList currentBucket = iterator.next(); // TODO get method for field length missing outBuffer.writeShort(currentBucket.getWeight().intValue()); outBuffer.writeInt(currentBucket.getWatchPort().getValue().intValue()); 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 fda59e66..af700bbb 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 @@ -9,12 +9,25 @@ import org.junit.Assert; import org.junit.Test; 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.common.types.rev130731.FlowModFlags; +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.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.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDrop; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandDscpRemark; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.meter.band.header.meter.band.MeterBandExperimenter; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyAggregate; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyDesc; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenter; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlow; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyGroup; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterConfig; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyMeterFeatures; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortDesc; 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; @@ -98,6 +111,7 @@ public class MultipartReplyMessageFactoryTest { @Test public void testMultipartReplyFlowBody(){ ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00 "+ + "00 0C "+//length "08 "+//tableId "00 "+//pad_01 "00 00 00 09 "+//durationSec @@ -395,4 +409,442 @@ public class MultipartReplyMessageFactoryTest { new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), message.getGroupStats().get(1).getBucketStats().get(1).getByteCount()); } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyMeterFeaturesBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 0B 00 01 00 00 00 00 "+ + "00 00 00 09 "+//maxMeter + "00 00 00 01 "+//bandTypes + "00 00 00 03 "+//capabilities + "03 "+//maxBands + "04 "+//maxColor + "00 00"//pad + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 11, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyMeterFeatures message = (MultipartReplyMeterFeatures) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong maxMeter", 9, message.getMaxMeter().intValue()); + Assert.assertEquals("Wrong bandTypes", 1, message.getBandTypes().getIntValue()); + Assert.assertEquals("Wrong capabilities", new MeterFlags(false, true, true, false), + message.getCapabilities()); + Assert.assertEquals("Wrong maxBands", 3, message.getMaxBands().intValue()); + Assert.assertEquals("Wrong maxColor", 4, message.getMaxColor().intValue()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyMeterBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 "+ + "00 00 00 09 "+//meterId + "00 58 "+//len + "00 00 00 00 00 00 "+//pad + "00 00 00 07 "+//flowCount + "00 01 01 01 01 01 01 01 "+//packetInCount + "00 01 01 01 01 01 01 01 "+//byteInCount + "00 00 00 05 "+//durationSec + "00 00 00 05 "+//durationNsec + "00 01 01 01 01 01 01 01 "+//packetBandCount_01 + "00 01 01 01 01 01 01 01 "+//byteBandCount_01 + "00 02 02 02 02 02 02 02 "+//packetBandCount_02 + "00 02 02 02 02 02 02 02 "+//byteBandCount_02 + "00 03 03 03 03 03 03 03 "+//packetBandCount_03 + "00 03 03 03 03 03 03 03"//byteBandCount_03 + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyMeter message = (MultipartReplyMeter) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong meterId", 9, + message.getMeterStats().get(0).getMeterId().intValue()); + Assert.assertEquals("Wrong flowCount", 7, + message.getMeterStats().get(0).getFlowCount().intValue()); + Assert.assertEquals("Wrong packetInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getPacketInCount()); + Assert.assertEquals("Wrong byteInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getByteInCount()); + Assert.assertEquals("Wrong durationSec", 5, + message.getMeterStats().get(0).getDurationSec().intValue()); + Assert.assertEquals("Wrong durationNsec", 5, + message.getMeterStats().get(0).getDurationNsec().intValue()); + Assert.assertEquals("Wrong packetBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount()); + } + + @Test + public void testMultipartReplyMeterBodyMulti(){ + ByteBuf bb = BufferHelper.buildBuffer("00 09 00 01 00 00 00 00 "+ + "00 00 00 09 "+//meterId_0 + "00 58 "+//len_0 + "00 00 00 00 00 00 "+//pad_0 + "00 00 00 07 "+//flowCount_0 + "00 01 01 01 01 01 01 01 "+//packetInCount_0 + "00 01 01 01 01 01 01 01 "+//byteInCount_0 + "00 00 00 05 "+//durationSec_0 + "00 00 00 05 "+//durationNsec_0 + "00 01 01 01 01 01 01 01 "+//packetBandCount_01 + "00 01 01 01 01 01 01 01 "+//byteBandCount_01 + "00 02 02 02 02 02 02 02 "+//packetBandCount_02 + "00 02 02 02 02 02 02 02 "+//byteBandCount_02 + "00 03 03 03 03 03 03 03 "+//packetBandCount_03 + "00 03 03 03 03 03 03 03 "+//byteBandCount_03 + "00 00 00 08 "+//meterId_1 + "00 58 "+//len_1 + "00 00 00 00 00 00 "+//pad_1 + "00 00 00 07 "+//flowCount_1 + "00 01 01 01 01 01 01 01 "+//packetInCount_1 + "00 01 01 01 01 01 01 01 "+//byteInCount_1 + "00 00 00 05 "+//durationSec_1 + "00 00 00 05 "+//durationNsec_1 + "00 01 01 01 01 01 01 01 "+//packetBandCount_11 + "00 01 01 01 01 01 01 01 "+//byteBandCount_11 + "00 02 02 02 02 02 02 02 "+//packetBandCount_12 + "00 02 02 02 02 02 02 02 "+//byteBandCount_12 + "00 03 03 03 03 03 03 03 "+//packetBandCount_13 + "00 03 03 03 03 03 03 03"//byteBandCount_13 + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 9, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyMeter message = (MultipartReplyMeter) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong meterId", 9, + message.getMeterStats().get(0).getMeterId().intValue()); + Assert.assertEquals("Wrong flowCount", 7, + message.getMeterStats().get(0).getFlowCount().intValue()); + Assert.assertEquals("Wrong packetInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getPacketInCount()); + Assert.assertEquals("Wrong byteInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getByteInCount()); + Assert.assertEquals("Wrong durationSec", 5, + message.getMeterStats().get(0).getDurationSec().intValue()); + Assert.assertEquals("Wrong durationNsec", 5, + message.getMeterStats().get(0).getDurationNsec().intValue()); + Assert.assertEquals("Wrong packetBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getMeterBandStats().get(0).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(0).getMeterBandStats().get(0).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(0).getMeterBandStats().get(1).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(0).getMeterBandStats().get(1).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(0).getMeterBandStats().get(2).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(0).getMeterBandStats().get(2).getByteBandCount()); + + Assert.assertEquals("Wrong meterId", 8, + message.getMeterStats().get(1).getMeterId().intValue()); + Assert.assertEquals("Wrong flowCount", 7, + message.getMeterStats().get(1).getFlowCount().intValue()); + Assert.assertEquals("Wrong packetInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(1).getPacketInCount()); + Assert.assertEquals("Wrong byteInCount", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(1).getByteInCount()); + Assert.assertEquals("Wrong durationSec", 5, + message.getMeterStats().get(1).getDurationSec().intValue()); + Assert.assertEquals("Wrong durationNsec", 5, + message.getMeterStats().get(1).getDurationNsec().intValue()); + Assert.assertEquals("Wrong packetBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(1).getMeterBandStats().get(0).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_01", + new BigInteger(new byte[]{0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}), + message.getMeterStats().get(1).getMeterBandStats().get(0).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(1).getMeterBandStats().get(1).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_02", + new BigInteger(new byte[]{0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}), + message.getMeterStats().get(1).getMeterBandStats().get(1).getByteBandCount()); + Assert.assertEquals("Wrong packetBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(1).getMeterBandStats().get(2).getPacketBandCount()); + Assert.assertEquals("Wrong byteBandCount_03", + new BigInteger(new byte[]{0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}), + message.getMeterStats().get(1).getMeterBandStats().get(2).getByteBandCount()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyMeterConfigBody(){ + ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 01 00 00 00 00 "+ + "00 38 "+//len + "00 01 "+//flags + "00 00 00 09 "+//meterId + "00 01 "+//meterBandDrop.type + "00 10 "+//meterBandDrop.len + "00 00 00 11 "+//meterBandDrop.rate + "00 00 00 20 "+//meterBandDrop.burstSize + "00 00 00 00 "+//meterBandDrop.pad + "00 02 "+//meterBandDscp.type + "00 10 "+//meterBandDscp.len + "00 00 00 11 "+//meterBandDscp.rate + "00 00 00 20 "+//meterBandDscp.burstSize + "04 "+//meterBandDscp.precLevel + "00 00 00 "+//meterBandDscp.pad + "FF FF "+//meterBandExperimenter.type + "00 10 "+//meterBandExperimenter.len + "00 00 00 11 "+//meterBandExperimenter.rate + "00 00 00 20 "+//meterBandExperimenter.burstSize + "00 00 00 04"//meterBandExperimenter.experimenter + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyMeterConfig message = (MultipartReplyMeterConfig) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong flags", 1, + message.getMeterConfig().get(0).getFlags().getIntValue()); + Assert.assertEquals("Wrong meterId", 9, + message.getMeterConfig().get(0).getMeterId().intValue()); + + MeterBandDrop meterBandDrop = (MeterBandDrop) message.getMeterConfig().get(0).getBands().get(0).getMeterBand(); + Assert.assertEquals("Wrong meterBandDrop.type", 1, meterBandDrop.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandDrop.rate", 17, meterBandDrop.getRate().intValue()); + Assert.assertEquals("Wrong meterBandDrop.burstSize", 32, meterBandDrop.getBurstSize().intValue()); + + MeterBandDscpRemark meterBandDscp = (MeterBandDscpRemark) message.getMeterConfig().get(0).getBands().get(1).getMeterBand(); + Assert.assertEquals("Wrong meterBandDscp.type", 2, meterBandDscp.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandDscp.rate", 17, meterBandDscp.getRate().intValue()); + Assert.assertEquals("Wrong meterBandDscp.burstSize", 32, meterBandDscp.getBurstSize().intValue()); + Assert.assertEquals("Wrong meterBandDscp.precLevel", 4, meterBandDscp.getPrecLevel().intValue()); + + MeterBandExperimenter meterBandExperimenter = (MeterBandExperimenter) message.getMeterConfig().get(0).getBands().get(2).getMeterBand(); + Assert.assertEquals("Wrong meterBandExperimenter.type", 0xFFFF, meterBandExperimenter.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandExperimenter.rate", 17, meterBandExperimenter.getRate().intValue()); + Assert.assertEquals("Wrong meterBandExperimenter.burstSize", 32, meterBandExperimenter.getBurstSize().intValue()); + Assert.assertEquals("Wrong meterBandExperimenter.experimenter", 4, meterBandExperimenter.getExperimenter().intValue()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyMeterConfigBodyMulti(){ + ByteBuf bb = BufferHelper.buildBuffer("00 0A 00 01 00 00 00 00 "+ + "00 38 "+//len + "00 01 "+//flags + "00 00 00 09 "+//meterId + "00 01 "+//meterBandDrop.type + "00 10 "+//meterBandDrop.len + "00 00 00 11 "+//meterBandDrop.rate + "00 00 00 20 "+//meterBandDrop.burstSize + "00 00 00 00 "+//meterBandDrop.pad + "00 02 "+//meterBandDscp.type + "00 10 "+//meterBandDscp.len + "00 00 00 11 "+//meterBandDscp.rate + "00 00 00 20 "+//meterBandDscp.burstSize + "04 "+//meterBandDscp.precLevel + "00 00 00 "+//meterBandDscp.pad + "FF FF "+//meterBandExperimenter.type + "00 10 "+//meterBandExperimenter.len + "00 00 00 11 "+//meterBandExperimenter.rate + "00 00 00 20 "+//meterBandExperimenter.burstSize + "00 00 00 04 "+//meterBandExperimenter.experimenter + + "00 18 "+//len01 + "00 00 "+//flags01 + "00 00 00 07 "+//meterId01 + "00 02 "+//meterBandDscp01.type + "00 10 "+//meterBandDscp01.len + "00 00 00 11 "+//meterBandDscp01.rate + "00 00 00 20 "+//meterBandDscp01.burstSize + "04 "+//meterBandDscp01.precLevel + "00 00 00"//meterBandDscp01.pad + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 10, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyMeterConfig message = (MultipartReplyMeterConfig) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong flags", 1, + message.getMeterConfig().get(0).getFlags().getIntValue()); + Assert.assertEquals("Wrong meterId", 9, + message.getMeterConfig().get(0).getMeterId().intValue()); + + MeterBandDrop meterBandDrop = (MeterBandDrop) message.getMeterConfig().get(0).getBands().get(0).getMeterBand(); + Assert.assertEquals("Wrong meterBandDrop.type", 1, meterBandDrop.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandDrop.rate", 17, meterBandDrop.getRate().intValue()); + Assert.assertEquals("Wrong meterBandDrop.burstSize", 32, meterBandDrop.getBurstSize().intValue()); + + MeterBandDscpRemark meterBandDscp = (MeterBandDscpRemark) message.getMeterConfig().get(0).getBands().get(1).getMeterBand(); + Assert.assertEquals("Wrong meterBandDscp.type", 2, meterBandDscp.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandDscp.rate", 17, meterBandDscp.getRate().intValue()); + Assert.assertEquals("Wrong meterBandDscp.burstSize", 32, meterBandDscp.getBurstSize().intValue()); + Assert.assertEquals("Wrong meterBandDscp.precLevel", 4, meterBandDscp.getPrecLevel().intValue()); + + MeterBandExperimenter meterBandExperimenter = (MeterBandExperimenter) message.getMeterConfig().get(0).getBands().get(2).getMeterBand(); + Assert.assertEquals("Wrong meterBandExperimenter.type", 0xFFFF, meterBandExperimenter.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandExperimenter.rate", 17, meterBandExperimenter.getRate().intValue()); + Assert.assertEquals("Wrong meterBandExperimenter.burstSize", 32, meterBandExperimenter.getBurstSize().intValue()); + Assert.assertEquals("Wrong meterBandExperimenter.experimenter", 4, meterBandExperimenter.getExperimenter().intValue()); + + Assert.assertEquals("Wrong flags01", 1, + message.getMeterConfig().get(0).getFlags().getIntValue()); + Assert.assertEquals("Wrong meterId01", 7, + message.getMeterConfig().get(1).getMeterId().intValue()); + + MeterBandDscpRemark meterBandDscp01 = (MeterBandDscpRemark) message.getMeterConfig().get(1).getBands().get(0).getMeterBand(); + Assert.assertEquals("Wrong meterBandDscp01.type", 2, meterBandDscp01.getType().getIntValue()); + Assert.assertEquals("Wrong meterBandDscp01.rate", 17, meterBandDscp01.getRate().intValue()); + Assert.assertEquals("Wrong meterBandDscp01.burstSize", 32, meterBandDscp01.getBurstSize().intValue()); + Assert.assertEquals("Wrong meterBandDscp01.precLevel", 4, meterBandDscp01.getPrecLevel().intValue()); + + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyExperimenterBody(){ + ByteBuf bb = BufferHelper.buildBuffer("FF FF 00 01 00 00 00 00 "+ + "00 00 00 0F "+//experimenterId + "00 00 00 FF "+//expType + "00 00 01 01 00 00 01 01" + ); + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 0xFFFF, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyExperimenter message = (MultipartReplyExperimenter) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong experimenterId", 15, message.getExperimenter().intValue()); + Assert.assertEquals("Wrong expType", 255, message.getExpType().intValue()); + Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01}, + message.getData()); + } + + /** + * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO + */ + @Test + public void testMultipartReplyPortDescBody(){ + final byte MAX_PORT_NAME_LEN = 16; + ByteBuf bb = BufferHelper.buildBuffer("00 0D 00 01 00 00 00 00 "+ + "00 01 02 03 "+ //portNo + "00 00 00 00 "+ //padding01 + "08 00 27 00 B0 EB " + //mac address + "00 00 "); //padding02 + //port name + String portName = "SampleText"; + byte[] portNameBytes = new byte[MAX_PORT_NAME_LEN]; + portNameBytes = portName.getBytes(); + bb.writeBytes(portNameBytes); + ByteBufUtils.padBuffer((MAX_PORT_NAME_LEN - portNameBytes.length), bb); + + ByteBuf bb2 = BufferHelper.buildBuffer("00 00 00 41 " + //port config + "00 00 00 05 " + //port state + "00 00 00 81 " + //current features + "00 00 00 81 " + //advertised features + "00 00 00 81 " + //supported features + "00 00 00 81 " + //peer features + "00 00 00 81 " + //curr speed + "00 00 00 80" //max speed + ); + bb.writeBytes(bb2.copy(4, bb2.readableBytes()-4));//excluding version and xid + + MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb); + + BufferHelper.checkHeaderV13(builtByFactory); + Assert.assertEquals("Wrong type", 13, builtByFactory.getType().getIntValue()); + Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); + + MultipartReplyPortDesc message = (MultipartReplyPortDesc) builtByFactory.getMultipartReplyBody(); + + Assert.assertEquals("Wrong portNo", 66051L, message.getPorts().get(0).getPortNo().longValue()); + Assert.assertEquals("Wrong macAddress", new MacAddress("08002700B0EB"), + message.getPorts().get(0).getHwAddr()); + Assert.assertEquals("Wrong portName", "SampleText", + message.getPorts().get(0).getName()); + 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 currentFeatures", new PortFeatures(true, false, false, false, + false, false, false, true, + false, false, false, false, + false, false, false, false), + message.getPorts().get(0).getCurrentFeatures()); + Assert.assertEquals("Wrong advertisedFeatures", + new PortFeatures(true, false, false, false, + false, false, false, true, + false, false, false, false, + false, false, false, false), + message.getPorts().get(0).getAdvertisedFeatures()); + Assert.assertEquals("Wrong supportedFeatures", + new PortFeatures(true, false, false, false, + false, false, false, true, + false, false, false, false, + false, false, false, false), + message.getPorts().get(0).getSupportedFeatures()); + Assert.assertEquals("Wrong peerFeatures", + new PortFeatures(true, false, false, false, + false, false, false, true, + false, false, false, false, + false, false, false, false), + message.getPorts().get(0).getPeerFeatures()); + Assert.assertEquals("Wrong currSpeed", 129L, message.getPorts().get(0).getCurrSpeed().longValue()); + Assert.assertEquals("Wrong maxSpeed", 128L, message.getPorts().get(0).getMaxSpeed().longValue()); + } } 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 bf95ea18..771aae23 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 @@ -48,16 +48,16 @@ public class PortStatusMessageFactoryTest { Assert.assertEquals("Wrong macAddress", new MacAddress("08002700B0EB"), builtByFactory.getHwAddr()); 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 portFeatures", new PortFeatures(true, false, false, false, + Assert.assertEquals("Wrong currentFeatures", new PortFeatures(true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false), builtByFactory.getCurrentFeatures()); - Assert.assertEquals("Wrong portFeatures", new PortFeatures(true, false, false, false, + Assert.assertEquals("Wrong advertisedFeatures", new PortFeatures(true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false), builtByFactory.getAdvertisedFeatures()); - Assert.assertEquals("Wrong portFeatures", new PortFeatures(true, false, false, false, + Assert.assertEquals("Wrong supportedFeatures", new PortFeatures(true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false), builtByFactory.getSupportedFeatures()); - Assert.assertEquals("Wrong portFeatures", new PortFeatures(true, false, false, false, + Assert.assertEquals("Wrong peerFeatures", new PortFeatures(true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false), builtByFactory.getSupportedFeatures()); Assert.assertEquals("Wrong currSpeed", 129L, builtByFactory.getCurrSpeed().longValue()); diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java index bb6ab999..d2162da7 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GroupModInputMessageFactoryTest.java @@ -17,8 +17,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.group.mod.Buckets; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.group.mod.BucketsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.group.mod.BucketsList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.group.mod.BucketsListBuilder; /** * @author timotej.kubas @@ -38,7 +38,7 @@ public class GroupModInputMessageFactoryTest { builder.setCommand(GroupModCommand.forValue(2)); builder.setType(GroupType.forValue(3)); builder.setGroupId(256L); - builder.setBuckets(createBucketsList()); + builder.setBucketsList(createBucketsList()); GroupModInput message = builder.build(); ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer(); @@ -53,10 +53,10 @@ public class GroupModInputMessageFactoryTest { Assert.assertEquals("Wrong bucketList", createBucketsList(), createBucketsListFromBufer(out)); } - private static List createBucketsList(){ - List bucketsList = new ArrayList<>(); - BucketsBuilder bucketsBuilder = new BucketsBuilder(); - Buckets bucket; + private static List createBucketsList(){ + List bucketsList = new ArrayList<>(); + BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); + BucketsList bucket; bucketsBuilder.setWeight(10); bucketsBuilder.setWatchPort(new PortNumber(65L)); bucketsBuilder.setWatchGroup(22L); @@ -65,10 +65,10 @@ public class GroupModInputMessageFactoryTest { return bucketsList; } - private static List createBucketsListFromBufer(ByteBuf out){ - List bucketsList = new ArrayList<>(); - BucketsBuilder bucketsBuilder = new BucketsBuilder(); - Buckets bucket; + private static List createBucketsListFromBufer(ByteBuf out){ + List bucketsList = new ArrayList<>(); + BucketsListBuilder bucketsBuilder = new BucketsListBuilder(); + BucketsList bucket; bucketsBuilder.setWeight((int) out.readShort()); bucketsBuilder.setWatchPort(new PortNumber(out.readUnsignedInt())); bucketsBuilder.setWatchGroup(out.readUnsignedInt()); -- 2.36.6