import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table.features.TableFeaturesBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeatureProperties;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.table.features.properties.TableFeaturePropertiesBuilder;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
\r
/**\r
* @author timotej.kubas\r
*/\r
public class MultipartReplyMessageFactory implements OFDeserializer<MultipartReplyMessage> {\r
\r
- private static MultipartReplyMessageFactory instance;\r
+ private static final Logger LOGGER = LoggerFactory\r
+ .getLogger(MultipartReplyMessageFactory.class);\r
private static final byte PADDING_IN_MULTIPART_REPLY_HEADER = 4;\r
\r
+ private static MultipartReplyMessageFactory instance;\r
+\r
private MultipartReplyMessageFactory() {\r
// singleton\r
}\r
final byte PADDING_IN_FLOW_STATS_HEADER_02 = 4;\r
MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder();\r
List<FlowStats> flowStatsList = new ArrayList<>();\r
- FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();\r
while (input.readableBytes() > 0) {\r
+ FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();\r
input.skipBytes(Short.SIZE / Byte.SIZE);\r
flowStatsBuilder.setTableId(input.readUnsignedByte());\r
input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_01);\r
flowStatsBuilder.setInstructions(InstructionsDeserializer.createInstructions(input, input.readableBytes()));\r
flowStatsList.add(flowStatsBuilder.build());\r
}\r
- flowBuilder.setFlowStats(new ArrayList<>(flowStatsList));\r
- flowStatsList.clear();\r
+ flowBuilder.setFlowStats(flowStatsList);\r
return flowBuilder.build();\r
}\r
\r
private static MultipartReplyTable setTable(ByteBuf input) {\r
final byte PADDING_IN_TABLE_HEADER = 3;\r
MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder();\r
- TableStatsBuilder tableStatsBuilder = new TableStatsBuilder();\r
List<TableStats> tableStatsList = new ArrayList<>();\r
while (input.readableBytes() > 0) {\r
+ TableStatsBuilder tableStatsBuilder = new TableStatsBuilder();\r
tableStatsBuilder.setTableId(input.readUnsignedByte());\r
input.skipBytes(PADDING_IN_TABLE_HEADER);\r
tableStatsBuilder.setActiveCount(input.readUnsignedInt());\r
tableStatsBuilder.setMatchedCount(new BigInteger(matchedCount));\r
tableStatsList.add(tableStatsBuilder.build());\r
}\r
- builder.setTableStats(new ArrayList<>(tableStatsList));\r
- tableStatsList.clear();\r
+ builder.setTableStats(tableStatsList);\r
return builder.build();\r
}\r
\r
private static MultipartReplyPortStats setPortStats(ByteBuf input) {\r
final byte PADDING_IN_PORT_STATS_HEADER = 4;\r
MultipartReplyPortStatsBuilder builder = new MultipartReplyPortStatsBuilder();\r
- PortStatsBuilder portStatsBuilder = new PortStatsBuilder();\r
List<PortStats> portStatsList = new ArrayList<>();\r
while (input.readableBytes() > 0) {\r
+ PortStatsBuilder portStatsBuilder = new PortStatsBuilder();\r
portStatsBuilder.setPortNo(input.readUnsignedInt());\r
input.skipBytes(PADDING_IN_PORT_STATS_HEADER);\r
- \r
byte[] rxPackets = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxPackets);\r
portStatsBuilder.setRxPackets(new BigInteger(rxPackets));\r
- \r
byte[] txPackets = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txPackets);\r
portStatsBuilder.setTxPackets(new BigInteger(txPackets));\r
- \r
byte[] rxBytes = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxBytes);\r
portStatsBuilder.setRxBytes(new BigInteger(rxBytes));\r
- \r
byte[] txBytes = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txBytes);\r
portStatsBuilder.setTxBytes(new BigInteger(txBytes));\r
- \r
byte[] rxDropped = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxDropped);\r
portStatsBuilder.setRxDropped(new BigInteger(rxDropped));\r
- \r
byte[] txDropped = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txDropped);\r
portStatsBuilder.setTxDropped(new BigInteger(txDropped));\r
- \r
byte[] rxErrors = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxErrors);\r
portStatsBuilder.setRxErrors(new BigInteger(rxErrors));\r
- \r
byte[] txErrors = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txErrors);\r
portStatsBuilder.setTxErrors(new BigInteger(txErrors));\r
- \r
byte[] rxFrameErr = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxFrameErr);\r
portStatsBuilder.setRxFrameErr(new BigInteger(rxFrameErr));\r
- \r
byte[] rxOverErr = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxOverErr);\r
portStatsBuilder.setRxOverErr(new BigInteger(rxOverErr));\r
- \r
byte[] rxCrcErr = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxCrcErr);\r
portStatsBuilder.setRxCrcErr(new BigInteger(rxCrcErr));\r
- \r
byte[] collisions = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(collisions);\r
portStatsBuilder.setCollisions(new BigInteger(collisions));\r
- \r
portStatsBuilder.setDurationSec(input.readUnsignedInt());\r
portStatsBuilder.setDurationNsec(input.readUnsignedInt());\r
portStatsList.add(portStatsBuilder.build());\r
}\r
- builder.setPortStats(new ArrayList<>(portStatsList));\r
- portStatsList.clear();\r
+ builder.setPortStats(portStatsList);\r
return builder.build();\r
}\r
\r
private static MultipartReplyQueue setQueue(ByteBuf input) {\r
MultipartReplyQueueBuilder builder = new MultipartReplyQueueBuilder();\r
- QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder();\r
List<QueueStats> queueStatsList = new ArrayList<>();\r
- \r
while (input.readableBytes() > 0) {\r
+ QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder();\r
queueStatsBuilder.setPortNo(input.readUnsignedInt());\r
queueStatsBuilder.setQueueId(input.readUnsignedInt());\r
-\r
byte[] txBytes = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txBytes);\r
queueStatsBuilder.setTxBytes(new BigInteger(txBytes));\r
-\r
byte[] txPackets = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txPackets);\r
queueStatsBuilder.setTxPackets(new BigInteger(txPackets));\r
-\r
byte[] txErrors = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txErrors);\r
queueStatsBuilder.setTxErrors(new BigInteger(txErrors));\r
-\r
queueStatsBuilder.setDurationSec(input.readUnsignedInt());\r
queueStatsBuilder.setDurationNsec(input.readUnsignedInt());\r
queueStatsList.add(queueStatsBuilder.build());\r
}\r
- builder.setQueueStats(new ArrayList<>(queueStatsList));\r
- queueStatsList.clear();\r
+ builder.setQueueStats(queueStatsList);\r
return builder.build();\r
}\r
\r
final byte PADDING_IN_GROUP_HEADER_02 = 4;\r
final byte BUCKET_COUNTER_LENGTH = 16;\r
final byte GROUP_BODY_LENGTH = 40;\r
- int actualLength;\r
MultipartReplyGroupBuilder builder = new MultipartReplyGroupBuilder();\r
- GroupStatsBuilder groupStatsBuilder = new GroupStatsBuilder();\r
List<GroupStats> groupStatsList = new ArrayList<>();\r
- \r
- BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder();\r
- List<BucketStats> bucketStatsList = new ArrayList<>();\r
- \r
while (input.readableBytes() > 0) {\r
+ GroupStatsBuilder groupStatsBuilder = new GroupStatsBuilder();\r
int bodyLength = input.readUnsignedShort();\r
- actualLength = 0;\r
- \r
input.skipBytes(PADDING_IN_GROUP_HEADER_01);\r
groupStatsBuilder.setGroupId(input.readUnsignedInt());\r
groupStatsBuilder.setRefCount(input.readUnsignedInt());\r
groupStatsBuilder.setByteCount(new BigInteger(byteCount));\r
groupStatsBuilder.setDurationSec(input.readUnsignedInt());\r
groupStatsBuilder.setDurationNsec(input.readUnsignedInt());\r
- actualLength = GROUP_BODY_LENGTH;\r
- \r
+ int actualLength = GROUP_BODY_LENGTH;\r
+ List<BucketStats> bucketStatsList = new ArrayList<>();\r
while (actualLength < bodyLength) {\r
+ BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder();\r
byte[] packetCountBucket = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(packetCountBucket);\r
bucketStatsBuilder.setPacketCount(new BigInteger(packetCountBucket));\r
input.readBytes(byteCountBucket);\r
bucketStatsBuilder.setByteCount(new BigInteger(byteCountBucket));\r
bucketStatsList.add(bucketStatsBuilder.build());\r
-\r
- actualLength = actualLength + BUCKET_COUNTER_LENGTH;\r
+ actualLength += BUCKET_COUNTER_LENGTH;\r
} \r
- groupStatsBuilder.setBucketStats(new ArrayList<>(bucketStatsList));\r
- bucketStatsList.clear();\r
+ groupStatsBuilder.setBucketStats(bucketStatsList);\r
groupStatsList.add(groupStatsBuilder.build());\r
}\r
- builder.setGroupStats(new ArrayList<>(groupStatsList));\r
- groupStatsList.clear();\r
+ builder.setGroupStats(groupStatsList);\r
return builder.build();\r
}\r
\r
MultipartReplyMeterFeaturesBuilder builder = new MultipartReplyMeterFeaturesBuilder();\r
builder.setMaxMeter(input.readUnsignedInt());\r
builder.setBandTypes(MeterBandType.forValue(input.readInt()));\r
- builder.setCapabilities(decodeMeterModFlags((int) input.readUnsignedInt()));\r
+ builder.setCapabilities(decodeMeterModFlags(input.readUnsignedInt()));\r
builder.setMaxBands(input.readUnsignedByte());\r
builder.setMaxColor(input.readUnsignedByte());\r
input.skipBytes(PADDING_IN_METER_FEATURES_HEADER);\r
return builder.build();\r
}\r
\r
- private static MeterFlags decodeMeterModFlags(int input){\r
+ private static MeterFlags decodeMeterModFlags(long input){\r
final Boolean _oFPMFKBPS = (input & (1 << 0)) != 0;\r
final Boolean _oFPMFPKTPS = (input & (1 << 1)) != 0;\r
final Boolean _oFPMFBURST = (input & (1 << 2)) != 0; \r
final byte PADDING_IN_METER_STATS_HEADER = 6;\r
final byte METER_BAND_STATS_LENGTH = 16;\r
final byte METER_BODY_LENGTH = 40;\r
- int actualLength;\r
MultipartReplyMeterBuilder builder = new MultipartReplyMeterBuilder();\r
List<MeterStats> meterStatsList = new ArrayList<>();\r
- MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder();\r
- List<MeterBandStats> meterBandStatsList = new ArrayList<>();\r
- MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder();\r
while (input.readableBytes() > 0) {\r
+ MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder();\r
meterStatsBuilder.setMeterId(input.readUnsignedInt());\r
- actualLength = 0;\r
int meterStatsBodyLength = input.readUnsignedShort();\r
input.skipBytes(PADDING_IN_METER_STATS_HEADER);\r
meterStatsBuilder.setFlowCount(input.readUnsignedInt());\r
meterStatsBuilder.setByteInCount(new BigInteger(byteInCount));\r
meterStatsBuilder.setDurationSec(input.readUnsignedInt());\r
meterStatsBuilder.setDurationNsec(input.readUnsignedInt());\r
- actualLength = METER_BODY_LENGTH;\r
- \r
+ int actualLength = METER_BODY_LENGTH;\r
+ List<MeterBandStats> meterBandStatsList = new ArrayList<>();\r
while (actualLength < meterStatsBodyLength) {\r
+ MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder();\r
byte[] packetBandCount = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(packetBandCount);\r
meterBandStatsBuilder.setPacketBandCount(new BigInteger(packetBandCount));\r
byte[] byteBandCount = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(byteBandCount);\r
meterBandStatsBuilder.setByteBandCount(new BigInteger(byteBandCount));\r
- \r
meterBandStatsList.add(meterBandStatsBuilder.build());\r
- actualLength = actualLength + METER_BAND_STATS_LENGTH;\r
+ actualLength += METER_BAND_STATS_LENGTH;\r
}\r
- \r
- meterStatsBuilder.setMeterBandStats(new ArrayList<>(meterBandStatsList));\r
- meterBandStatsList.clear();\r
+ meterStatsBuilder.setMeterBandStats(meterBandStatsList);\r
meterStatsList.add(meterStatsBuilder.build());\r
}\r
- builder.setMeterStats(new ArrayList<>(meterStatsList));\r
- meterStatsList.clear();\r
+ builder.setMeterStats(meterStatsList);\r
return builder.build();\r
}\r
\r
private static MultipartReplyMeterConfig setMeterConfig(ByteBuf input) {\r
- final byte METER_BAND_LENGTH = 16;\r
final byte METER_CONFIG_LENGTH = 8;\r
- final byte bandLength = 2;\r
- int actualLength;\r
+ final byte PADDING_IN_METER_BAND_DROP_HEADER = 4;\r
+ final byte PADDING_IN_METER_BAND_DSCP_HEADER = 3;\r
MultipartReplyMeterConfigBuilder builder = new MultipartReplyMeterConfigBuilder();\r
List<MeterConfig> meterConfigList = new ArrayList<>();\r
- MeterConfigBuilder meterConfigBuilder = new MeterConfigBuilder();\r
- List<Bands> bandsList = new ArrayList<>();\r
- BandsBuilder bandsBuilder = new BandsBuilder();\r
- \r
while (input.readableBytes() > 0) {\r
+ MeterConfigBuilder meterConfigBuilder = new MeterConfigBuilder();\r
int meterConfigBodyLength = input.readUnsignedShort();\r
- actualLength = 0;\r
meterConfigBuilder.setFlags(MeterModCommand.forValue(input.readUnsignedShort()));\r
meterConfigBuilder.setMeterId(input.readUnsignedInt());\r
- actualLength = METER_CONFIG_LENGTH;\r
- \r
+ int actualLength = METER_CONFIG_LENGTH;\r
+ List<Bands> bandsList = new ArrayList<>();\r
while (actualLength < meterConfigBodyLength) {\r
- MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder();\r
- final byte PADDING_IN_METER_BAND_DROP_HEADER = 4;\r
- MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder();\r
- final byte PADDING_IN_METER_BAND_DSCP_HEADER = 3;\r
- MeterBandExperimenterBuilder bandExperimenterBuilder = new MeterBandExperimenterBuilder(); \r
+ BandsBuilder bandsBuilder = new BandsBuilder();\r
int bandType = input.readUnsignedShort();\r
switch (bandType) {\r
- case 1: bandDropBuilder.setType(MeterBandType.forValue(bandType));\r
- input.skipBytes(bandLength);\r
- bandDropBuilder.setRate(input.readUnsignedInt());\r
- bandDropBuilder.setBurstSize(input.readUnsignedInt());\r
- input.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER);\r
- bandsBuilder.setMeterBand(bandDropBuilder.build());\r
- break;\r
- case 2: bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType));\r
- input.skipBytes(bandLength);\r
- bandDscpRemarkBuilder.setRate(input.readUnsignedInt());\r
- bandDscpRemarkBuilder.setBurstSize(input.readUnsignedInt());\r
- bandDscpRemarkBuilder.setPrecLevel(input.readUnsignedByte());\r
- input.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER);\r
- bandsBuilder.setMeterBand(bandDscpRemarkBuilder.build());\r
- break;\r
- case 0xFFFF: bandExperimenterBuilder.setType(MeterBandType.forValue(bandType));\r
- input.skipBytes(bandLength);\r
- bandExperimenterBuilder.setRate(input.readUnsignedInt());\r
- bandExperimenterBuilder.setBurstSize(input.readUnsignedInt());\r
- bandExperimenterBuilder.setExperimenter(input.readUnsignedInt());\r
- bandsBuilder.setMeterBand(bandExperimenterBuilder.build());\r
- break;\r
- default: break;\r
+ case 1:\r
+ MeterBandDropBuilder bandDropBuilder = new MeterBandDropBuilder();\r
+ bandDropBuilder.setType(MeterBandType.forValue(bandType));\r
+ actualLength += input.readUnsignedShort();\r
+ bandDropBuilder.setRate(input.readUnsignedInt());\r
+ bandDropBuilder.setBurstSize(input.readUnsignedInt());\r
+ input.skipBytes(PADDING_IN_METER_BAND_DROP_HEADER);\r
+ bandsBuilder.setMeterBand(bandDropBuilder.build());\r
+ break;\r
+ case 2:\r
+ MeterBandDscpRemarkBuilder bandDscpRemarkBuilder = new MeterBandDscpRemarkBuilder();\r
+ bandDscpRemarkBuilder.setType(MeterBandType.forValue(bandType));\r
+ actualLength += input.readUnsignedShort();\r
+ bandDscpRemarkBuilder.setRate(input.readUnsignedInt());\r
+ bandDscpRemarkBuilder.setBurstSize(input.readUnsignedInt());\r
+ bandDscpRemarkBuilder.setPrecLevel(input.readUnsignedByte());\r
+ input.skipBytes(PADDING_IN_METER_BAND_DSCP_HEADER);\r
+ bandsBuilder.setMeterBand(bandDscpRemarkBuilder.build());\r
+ break;\r
+ case 0xFFFF:\r
+ MeterBandExperimenterBuilder bandExperimenterBuilder = new MeterBandExperimenterBuilder();\r
+ bandExperimenterBuilder.setType(MeterBandType.forValue(bandType));\r
+ actualLength += input.readUnsignedShort();\r
+ bandExperimenterBuilder.setRate(input.readUnsignedInt());\r
+ bandExperimenterBuilder.setBurstSize(input.readUnsignedInt());\r
+ bandExperimenterBuilder.setExperimenter(input.readUnsignedInt());\r
+ bandsBuilder.setMeterBand(bandExperimenterBuilder.build());\r
+ break;\r
+ default:\r
+ break;\r
}\r
bandsList.add(bandsBuilder.build());\r
- actualLength = actualLength + METER_BAND_LENGTH;\r
}\r
- meterConfigBuilder.setBands(new ArrayList<>(bandsList));\r
- bandsList.clear();\r
+ meterConfigBuilder.setBands(bandsList);\r
meterConfigList.add(meterConfigBuilder.build());\r
}\r
- builder.setMeterConfig(new ArrayList<>(meterConfigList));\r
- meterConfigList.clear();\r
+ builder.setMeterConfig(meterConfigList);\r
return builder.build();\r
}\r
\r
MultipartReplyExperimenterBuilder builder = new MultipartReplyExperimenterBuilder();\r
builder.setExperimenter(input.readUnsignedInt());\r
builder.setExpType(input.readUnsignedInt());\r
- byte[] data = new byte[Long.SIZE/Byte.SIZE];\r
+ byte[] data = new byte[input.readableBytes()];\r
input.readBytes(data);\r
builder.setData(data);\r
return builder.build();\r
final byte MAX_PORT_NAME_LEN = 16;\r
MultipartReplyPortDescBuilder builder = new MultipartReplyPortDescBuilder();\r
List<Ports> portsList = new ArrayList<>();\r
- PortsBuilder portsBuilder = new PortsBuilder();\r
- \r
while (input.readableBytes() > 0) {\r
+ PortsBuilder portsBuilder = new PortsBuilder();\r
portsBuilder.setPortNo(input.readUnsignedInt());\r
input.skipBytes(PADDING_IN_PORT_DESC_HEADER_01);\r
StringBuffer macToString = new StringBuffer();\r
}\r
portsBuilder.setHwAddr(new MacAddress(macToString.toString()));\r
input.skipBytes(PADDING_IN_PORT_DESC_HEADER_02);\r
- \r
byte[] portNameBytes = new byte[MAX_PORT_NAME_LEN];\r
input.readBytes(portNameBytes);\r
String portName = new String(portNameBytes);\r
portsBuilder.setName(portName.trim());\r
- \r
portsBuilder.setConfig(createPortConfig(input.readUnsignedInt()));\r
portsBuilder.setState(createPortState(input.readUnsignedInt()));\r
portsBuilder.setCurrentFeatures(createPortFeatures(input.readUnsignedInt()));\r
portsBuilder.setMaxSpeed(input.readUnsignedInt());\r
portsList.add(portsBuilder.build());\r
}\r
- \r
- builder.setPorts(new ArrayList<>(portsList));\r
- portsList.clear();\r
+ builder.setPorts(portsList);\r
return builder.build();\r
}\r
\r
final byte PADDING_IN_GROUP_DESC_HEADER = 1;\r
final byte PADDING_IN_BUCKETS_HEADER = 4;\r
final byte GROUP_DESC_HEADER_LENGTH = 8;\r
- int actualLength;\r
- int bucketsLength = 0;\r
- int bucketsCurrentLength = 0;\r
- int bodyLength = 0;\r
+ final byte BUCKETS_HEADER_LENGTH = 16;\r
MultipartReplyGroupDescBuilder builder = new MultipartReplyGroupDescBuilder();\r
- GroupDescBuilder groupDescBuilder = new GroupDescBuilder();\r
List<GroupDesc> groupDescsList = new ArrayList<>();\r
- BucketsListBuilder bucketsBuilder = new BucketsListBuilder();\r
- List<BucketsList> bucketsList = new ArrayList<>();\r
- List<ActionsList> actionsList = new ArrayList<>();\r
+ LOGGER.info("readablebytes pred: " + input.readableBytes());\r
while (input.readableBytes() > 0) {\r
- bodyLength = input.readUnsignedShort();\r
+ LOGGER.info("readablebytes po: " + input.readableBytes());\r
+ GroupDescBuilder groupDescBuilder = new GroupDescBuilder();\r
+ int bodyLength = input.readUnsignedShort();\r
+ LOGGER.info("bodylength: " + bodyLength);\r
groupDescBuilder.setType(GroupType.forValue(input.readUnsignedByte()));\r
input.skipBytes(PADDING_IN_GROUP_DESC_HEADER);\r
groupDescBuilder.setGroupId(input.readUnsignedInt());\r
- actualLength = GROUP_DESC_HEADER_LENGTH;\r
+ int actualLength = GROUP_DESC_HEADER_LENGTH;\r
+ List<BucketsList> bucketsList = new ArrayList<>();\r
while (actualLength < bodyLength) {\r
- bucketsLength = input.readUnsignedShort();\r
+ System.out.println("cyklim v buckets");\r
+ BucketsListBuilder bucketsBuilder = new BucketsListBuilder();\r
+ int bucketsLength = input.readUnsignedShort();\r
bucketsBuilder.setWeight(input.readUnsignedShort());\r
bucketsBuilder.setWatchPort(new PortNumber(input.readUnsignedInt()));\r
bucketsBuilder.setWatchGroup(input.readUnsignedInt());\r
input.skipBytes(PADDING_IN_BUCKETS_HEADER);\r
- bucketsCurrentLength = bucketsLength;\r
- actionsList = ActionsDeserializer.createActionsList(input, bucketsLength);\r
- bucketsBuilder.setActionsList(new ArrayList<>(actionsList));\r
- actionsList.clear();\r
+ System.out.println("bucketslength: " + bucketsLength);\r
+ System.out.println("actuallength: " + actualLength);\r
+ System.out.println("bodylength: " + bodyLength);\r
+ LOGGER.info("length - length: " + (bucketsLength - BUCKETS_HEADER_LENGTH));\r
+ List<ActionsList> actionsList = ActionsDeserializer\r
+ .createActionsList(input, bucketsLength - BUCKETS_HEADER_LENGTH);\r
+ LOGGER.info("actions size: " + actionsList.size());\r
+ bucketsBuilder.setActionsList(actionsList);\r
bucketsList.add(bucketsBuilder.build());\r
- actualLength = actualLength + bucketsCurrentLength;\r
+ actualLength += bucketsLength;\r
}\r
- groupDescBuilder.setBucketsList(new ArrayList<>(bucketsList));\r
- bucketsList.clear();\r
+ groupDescBuilder.setBucketsList(bucketsList);\r
groupDescsList.add(groupDescBuilder.build());\r
}\r
- builder.setGroupDesc(new ArrayList<>(groupDescsList));\r
- groupDescsList.clear();\r
+ builder.setGroupDesc(groupDescsList);\r
return builder.build();\r
}\r
\r
final byte PADDING_IN_FLOW_STATS_HEADER_02 = 6;\r
MultipartReplyFlowBuilder flowBuilder = new MultipartReplyFlowBuilder();\r
List<FlowStats> flowStatsList = new ArrayList<>();\r
- FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();\r
- input.skipBytes(Short.SIZE / Byte.SIZE);\r
- flowStatsBuilder.setTableId(input.readUnsignedByte());\r
- input.skipBytes(PADDING_IN_FLOW_STATS_HEADER);\r
- flowStatsBuilder.setMatchV10(OF10MatchDeserializer.createMatchV10(input));\r
- flowStatsBuilder.setDurationSec(input.readUnsignedInt());\r
- flowStatsBuilder.setDurationNsec(input.readUnsignedInt());\r
- flowStatsBuilder.setPriority(input.readUnsignedShort());\r
- flowStatsBuilder.setIdleTimeout(input.readUnsignedShort());\r
- flowStatsBuilder.setHardTimeout(input.readUnsignedShort());\r
- input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);\r
- byte[] cookie = new byte[Long.SIZE/Byte.SIZE];\r
- input.readBytes(cookie);\r
- flowStatsBuilder.setCookie(new BigInteger(cookie));\r
- byte[] packetCount = new byte[Long.SIZE/Byte.SIZE];\r
- input.readBytes(packetCount);\r
- flowStatsBuilder.setPacketCount(new BigInteger(packetCount));\r
- byte[] byteCount = new byte[Long.SIZE/Byte.SIZE];\r
- input.readBytes(byteCount);\r
- flowStatsBuilder.setByteCount(new BigInteger(byteCount));\r
- flowStatsBuilder.setActionsList(OF10ActionsDeserializer.createActionsList(input));\r
- flowStatsList.add(flowStatsBuilder.build());\r
- flowBuilder.setFlowStats(new ArrayList<>(flowStatsList));\r
- flowStatsList.clear();\r
+ while (input.readableBytes() > 0) {\r
+ FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder();\r
+ input.skipBytes(Short.SIZE / Byte.SIZE);\r
+ flowStatsBuilder.setTableId(input.readUnsignedByte());\r
+ input.skipBytes(PADDING_IN_FLOW_STATS_HEADER);\r
+ flowStatsBuilder.setMatchV10(OF10MatchDeserializer.createMatchV10(input));\r
+ flowStatsBuilder.setDurationSec(input.readUnsignedInt());\r
+ flowStatsBuilder.setDurationNsec(input.readUnsignedInt());\r
+ flowStatsBuilder.setPriority(input.readUnsignedShort());\r
+ flowStatsBuilder.setIdleTimeout(input.readUnsignedShort());\r
+ flowStatsBuilder.setHardTimeout(input.readUnsignedShort());\r
+ input.skipBytes(PADDING_IN_FLOW_STATS_HEADER_02);\r
+ byte[] cookie = new byte[Long.SIZE/Byte.SIZE];\r
+ input.readBytes(cookie);\r
+ flowStatsBuilder.setCookie(new BigInteger(cookie));\r
+ byte[] packetCount = new byte[Long.SIZE/Byte.SIZE];\r
+ input.readBytes(packetCount);\r
+ flowStatsBuilder.setPacketCount(new BigInteger(packetCount));\r
+ byte[] byteCount = new byte[Long.SIZE/Byte.SIZE];\r
+ input.readBytes(byteCount);\r
+ flowStatsBuilder.setByteCount(new BigInteger(byteCount));\r
+ flowStatsBuilder.setActionsList(OF10ActionsDeserializer.createActionsList(input));\r
+ flowStatsList.add(flowStatsBuilder.build());\r
+ }\r
+ flowBuilder.setFlowStats(flowStatsList);\r
return flowBuilder.build();\r
}\r
\r
final byte PADDING_IN_TABLE_HEADER = 3;\r
final byte MAX_TABLE_NAME_LENGTH = 32;\r
MultipartReplyTableBuilder builder = new MultipartReplyTableBuilder();\r
- TableStatsBuilder tableStatsBuilder = new TableStatsBuilder();\r
List<TableStats> tableStatsList = new ArrayList<>();\r
- tableStatsBuilder.setTableId(input.readUnsignedByte());\r
- input.skipBytes(PADDING_IN_TABLE_HEADER);\r
- tableStatsBuilder.setName(input.readBytes(MAX_TABLE_NAME_LENGTH).toString());\r
- tableStatsBuilder.setActiveCount(input.readUnsignedInt());\r
- byte[] lookupCount = new byte[Long.SIZE/Byte.SIZE];\r
- input.readBytes(lookupCount);\r
- tableStatsBuilder.setLookupCount(new BigInteger(lookupCount));\r
- byte[] matchedCount = new byte[Long.SIZE/Byte.SIZE];\r
- input.readBytes(matchedCount);\r
- tableStatsBuilder.setMatchedCount(new BigInteger(matchedCount));\r
- tableStatsList.add(tableStatsBuilder.build());\r
- builder.setTableStats(new ArrayList<>(tableStatsList));\r
- tableStatsList.clear();\r
+ while (input.readableBytes() > 0) {\r
+ TableStatsBuilder tableStatsBuilder = new TableStatsBuilder();\r
+ tableStatsBuilder.setTableId(input.readUnsignedByte());\r
+ input.skipBytes(PADDING_IN_TABLE_HEADER);\r
+ tableStatsBuilder.setName(input.readBytes(MAX_TABLE_NAME_LENGTH).toString());\r
+ tableStatsBuilder.setActiveCount(input.readUnsignedInt());\r
+ byte[] lookupCount = new byte[Long.SIZE/Byte.SIZE];\r
+ input.readBytes(lookupCount);\r
+ tableStatsBuilder.setLookupCount(new BigInteger(lookupCount));\r
+ byte[] matchedCount = new byte[Long.SIZE/Byte.SIZE];\r
+ input.readBytes(matchedCount);\r
+ tableStatsBuilder.setMatchedCount(new BigInteger(matchedCount));\r
+ tableStatsList.add(tableStatsBuilder.build());\r
+ }\r
+ builder.setTableStats(tableStatsList);\r
return builder.build();\r
}\r
\r
private static MultipartReplyPortStats setPortStats(ByteBuf input) {\r
final byte PADDING_IN_PORT_STATS_HEADER = 6;\r
MultipartReplyPortStatsBuilder builder = new MultipartReplyPortStatsBuilder();\r
- PortStatsBuilder portStatsBuilder = new PortStatsBuilder();\r
List<PortStats> portStatsList = new ArrayList<>();\r
while (input.readableBytes() > 0) {\r
+ PortStatsBuilder portStatsBuilder = new PortStatsBuilder();\r
portStatsBuilder.setPortNo((long) input.readUnsignedShort());\r
input.skipBytes(PADDING_IN_PORT_STATS_HEADER);\r
- \r
byte[] rxPackets = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxPackets);\r
portStatsBuilder.setRxPackets(new BigInteger(rxPackets));\r
- \r
byte[] txPackets = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txPackets);\r
portStatsBuilder.setTxPackets(new BigInteger(txPackets));\r
- \r
byte[] rxBytes = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxBytes);\r
portStatsBuilder.setRxBytes(new BigInteger(rxBytes));\r
- \r
byte[] txBytes = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txBytes);\r
portStatsBuilder.setTxBytes(new BigInteger(txBytes));\r
- \r
byte[] rxDropped = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxDropped);\r
portStatsBuilder.setRxDropped(new BigInteger(rxDropped));\r
- \r
byte[] txDropped = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txDropped);\r
portStatsBuilder.setTxDropped(new BigInteger(txDropped));\r
- \r
byte[] rxErrors = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxErrors);\r
portStatsBuilder.setRxErrors(new BigInteger(rxErrors));\r
- \r
byte[] txErrors = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txErrors);\r
portStatsBuilder.setTxErrors(new BigInteger(txErrors));\r
- \r
byte[] rxFrameErr = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxFrameErr);\r
portStatsBuilder.setRxFrameErr(new BigInteger(rxFrameErr));\r
- \r
byte[] rxOverErr = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxOverErr);\r
portStatsBuilder.setRxOverErr(new BigInteger(rxOverErr));\r
- \r
byte[] rxCrcErr = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(rxCrcErr);\r
portStatsBuilder.setRxCrcErr(new BigInteger(rxCrcErr));\r
- \r
byte[] collisions = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(collisions);\r
portStatsBuilder.setCollisions(new BigInteger(collisions));\r
- \r
}\r
- builder.setPortStats(new ArrayList<>(portStatsList));\r
- portStatsList.clear();\r
+ builder.setPortStats(portStatsList);\r
return builder.build();\r
}\r
\r
private static MultipartReplyQueue setQueue(ByteBuf input) {\r
final byte PADDING_IN_QUEUE_HEADER = 2;\r
MultipartReplyQueueBuilder builder = new MultipartReplyQueueBuilder();\r
- QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder();\r
List<QueueStats> queueStatsList = new ArrayList<>();\r
- \r
while (input.readableBytes() > 0) {\r
+ QueueStatsBuilder queueStatsBuilder = new QueueStatsBuilder();\r
queueStatsBuilder.setPortNo((long) input.readUnsignedShort());\r
input.skipBytes(PADDING_IN_QUEUE_HEADER);\r
queueStatsBuilder.setQueueId(input.readUnsignedInt());\r
-\r
byte[] txBytes = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txBytes);\r
queueStatsBuilder.setTxBytes(new BigInteger(txBytes));\r
-\r
byte[] txPackets = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txPackets);\r
queueStatsBuilder.setTxPackets(new BigInteger(txPackets));\r
-\r
byte[] txErrors = new byte[Long.SIZE/Byte.SIZE];\r
input.readBytes(txErrors);\r
queueStatsBuilder.setTxErrors(new BigInteger(txErrors));\r
-\r
queueStatsList.add(queueStatsBuilder.build());\r
}\r
- builder.setQueueStats(new ArrayList<>(queueStatsList));\r
- queueStatsList.clear();\r
+ builder.setQueueStats(queueStatsList);\r
return builder.build();\r
}\r
\r
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
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
}
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();
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.Instructions;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableConfig;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableFeaturesPropType;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;\r
\r
@Override\r
public int computeLength(MultipartRequestMessage message) {\r
- // TODO\r
- return MESSAGE_LENGTH;\r
+ return MESSAGE_LENGTH + computeBodyLength(message);\r
}\r
@Override\r
public byte getMessageType() {\r
return MESSAGE_TYPE;\r
- } \r
+ }\r
+ \r
+ /**\r
+ * \r
+ * @param message\r
+ * @return length of MultipartRequestMessage\r
+ */\r
+ public int computeBodyLength(MultipartRequestMessage message) {\r
+ int length = 0;\r
+ MultipartType type = message.getType();\r
+ if (type.equals(MultipartType.OFPMPFLOW)) {\r
+ final byte FLOW_BODY_LENGTH = 32;\r
+ MultipartRequestFlow body = (MultipartRequestFlow) message.getMultipartRequestBody();\r
+ length += FLOW_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch());\r
+ } else if (type.equals(MultipartType.OFPMPAGGREGATE)) {\r
+ final byte AGGREGATE_BODY_LENGTH = 32;\r
+ MultipartRequestAggregate body = (MultipartRequestAggregate) message.getMultipartRequestBody();\r
+ length += AGGREGATE_BODY_LENGTH + MatchSerializer.computeMatchLength(body.getMatch());\r
+ } else if (type.equals(MultipartType.OFPMPPORTSTATS)) {\r
+ final byte PORT_STATS_BODY_LENGTH = 8;\r
+ length += PORT_STATS_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPQUEUE)) {\r
+ final byte QUEUE_BODY_LENGTH = 8;\r
+ length += QUEUE_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPGROUP)) {\r
+ final byte GROUP_BODY_LENGTH = 8;\r
+ length += GROUP_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPMETER)) {\r
+ final byte METER_BODY_LENGTH = 8;\r
+ length += METER_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPMETERCONFIG)) {\r
+ final byte METER_CONFIG_BODY_LENGTH = 8;\r
+ length += METER_CONFIG_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPTABLEFEATURES)) {\r
+ MultipartRequestTableFeatures body = (MultipartRequestTableFeatures) message.getMultipartRequestBody();\r
+ length += computeTableFeaturesLength(body);\r
+ } else if (type.equals(MultipartType.OFPMPEXPERIMENTER)) {\r
+ final byte EXPERIMENTER_BODY_LENGTH = 8;\r
+ MultipartRequestExperimenter body = (MultipartRequestExperimenter) message.getMultipartRequestBody();\r
+ length += EXPERIMENTER_BODY_LENGTH;\r
+ if (body.getData() != null) {\r
+ length += body.getData().length;\r
+ }\r
+ }\r
+ return length;\r
+ }\r
+\r
+ private static int computeTableFeaturesLength(MultipartRequestTableFeatures body) {\r
+ final byte TABLE_FEATURES_LENGTH = 64;\r
+ final byte STRUCTURE_HEADER_LENGTH = 4;\r
+ int length = 0;\r
+ if (body != null) {\r
+ List<TableFeatures> tableFeatures = body.getTableFeatures();\r
+ for (TableFeatures feature : tableFeatures) {\r
+ length += TABLE_FEATURES_LENGTH;\r
+ List<TableFeatureProperties> featureProperties = feature.getTableFeatureProperties();\r
+ if (featureProperties != null) {\r
+ for (TableFeatureProperties featProp : featureProperties) {\r
+ length += TABLE_FEAT_HEADER_LENGTH;\r
+ if (featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class) != null) {\r
+ InstructionRelatedTableFeatureProperty property =\r
+ featProp.getAugmentation(InstructionRelatedTableFeatureProperty.class);\r
+ length += property.getInstructions().size() * STRUCTURE_HEADER_LENGTH;\r
+ } else if (featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class) != null) {\r
+ NextTableRelatedTableFeatureProperty property =\r
+ featProp.getAugmentation(NextTableRelatedTableFeatureProperty.class);\r
+ length += property.getNextTableIds().size();\r
+ } else if (featProp.getAugmentation(ActionRelatedTableFeatureProperty.class) != null) {\r
+ ActionRelatedTableFeatureProperty property =\r
+ featProp.getAugmentation(ActionRelatedTableFeatureProperty.class);\r
+ length += property.getActionsList().size() * STRUCTURE_HEADER_LENGTH;\r
+ } else if (featProp.getAugmentation(OxmRelatedTableFeatureProperty.class) != null) {\r
+ OxmRelatedTableFeatureProperty property =\r
+ featProp.getAugmentation(OxmRelatedTableFeatureProperty.class);\r
+ length += property.getMatchEntries().size() * STRUCTURE_HEADER_LENGTH;\r
+ } else if (featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class) != null) {\r
+ ExperimenterRelatedTableFeatureProperty property =\r
+ featProp.getAugmentation(ExperimenterRelatedTableFeatureProperty.class);\r
+ length += 2 * (Integer.SIZE / Byte.SIZE);\r
+ if (property.getData() != null) {\r
+ length += property.getData().length;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return length;\r
+ }\r
\r
private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) {\r
int multipartRequestFlagsBitmask = 0;\r
MultipartRequestExperimenter experimenter = (MultipartRequestExperimenter) multipartRequestBody;\r
output.writeInt(experimenter.getExperimenter().intValue());\r
output.writeInt(experimenter.getExpType().intValue());\r
- output.writeBytes(experimenter.getData());\r
+ byte[] data = experimenter.getData();\r
+ if (data != null) {\r
+ output.writeBytes(data);\r
+ }\r
}\r
\r
private static void encodeTableFeaturesBody(MultipartRequestBody multipartRequestBody, ByteBuf output) {\r
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
import org.opendaylight.openflowjava.protocol.impl.util.OF10MatchSerializer;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestMessage;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.MultipartRequestBody;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestAggregate;\r
ByteBufUtils.writeOFHeader(instance, message, out);\r
out.writeShort(message.getType().getIntValue());\r
out.writeShort(createMultipartRequestFlagsBitmask(message.getFlags()));\r
- \r
if (message.getMultipartRequestBody() instanceof MultipartRequestFlow) {\r
encodeFlowBody(message.getMultipartRequestBody(), out);\r
} else if (message.getMultipartRequestBody() instanceof MultipartRequestAggregate) {\r
\r
@Override\r
public int computeLength(MultipartRequestMessage message) {\r
- // TODO\r
- return MESSAGE_LENGTH;\r
+ return MESSAGE_LENGTH + computeBodyLength(message);\r
}\r
@Override\r
public byte getMessageType() {\r
return MESSAGE_TYPE;\r
}\r
\r
+ /**\r
+ * \r
+ * @param message\r
+ * @return length of MultipartRequestMessage\r
+ */\r
+ public int computeBodyLength(MultipartRequestMessage message) {\r
+ int length = 0;\r
+ MultipartType type = message.getType();\r
+ if (type.equals(MultipartType.OFPMPFLOW)) {\r
+ final byte FLOW_BODY_LENGTH = 44;\r
+ length += FLOW_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPAGGREGATE)) {\r
+ final byte AGGREGATE_BODY_LENGTH = 44;\r
+ length += AGGREGATE_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPPORTSTATS)) {\r
+ final byte PORT_STATS_BODY_LENGTH = 8;\r
+ length += PORT_STATS_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPQUEUE)) {\r
+ final byte QUEUE_BODY_LENGTH = 8;\r
+ length += QUEUE_BODY_LENGTH;\r
+ } else if (type.equals(MultipartType.OFPMPEXPERIMENTER)) {\r
+ final byte EXPERIMENTER_BODY_LENGTH = 4;\r
+ MultipartRequestExperimenter body = (MultipartRequestExperimenter) message.getMultipartRequestBody();\r
+ length += EXPERIMENTER_BODY_LENGTH;\r
+ if (body.getData() != null) {\r
+ length += body.getData().length;\r
+ }\r
+ }\r
+ return length;\r
+ }\r
+ \r
private static int createMultipartRequestFlagsBitmask(MultipartRequestFlags flags) {\r
int multipartRequestFlagsBitmask = 0;\r
Map<Integer, Boolean> multipartRequestFlagsMap = new HashMap<>();\r
* @author michal.polkorab\r
*/\r
public abstract class ActionsDeserializer {\r
- private static ActionBuilder actionBuilder = new ActionBuilder();\r
- private static ActionsListBuilder actionsListBuilder = new ActionsListBuilder();\r
- private static List<ActionsList> actionsList = new ArrayList<>();\r
+ \r
+ private static final byte ACTION_HEADER_LENGTH = 4;\r
\r
/**\r
* @param input input ByteBuf\r
- * @param bucketsLength length of buckets\r
+ * @param actionsLength length of buckets\r
* @return ActionsList\r
*/\r
- public static List<ActionsList> createActionsList(ByteBuf input, int bucketsLength) {\r
- final byte BUCKET_HEADER_LENGTH = 16;\r
- final byte ACTION_HEADER_LENGTH = 4;\r
- int bucketsCurrentLength = BUCKET_HEADER_LENGTH;\r
- int actionsLength = 0;\r
- \r
- while (bucketsCurrentLength < bucketsLength) {\r
- switch(input.readUnsignedShort()) {\r
- case 0: actionsLength = input.readUnsignedShort(); //outputActionLength\r
- actionsList.add(ActionsDeserializer.createOutputAction(input));\r
- break;\r
- case 11: \r
- actionsLength = input.readUnsignedShort();//empty header length\r
- actionsList.add(ActionsDeserializer.createCopyTtlOutAction(input));\r
- break;\r
- \r
- case 12: \r
- actionsLength = input.readUnsignedShort();//empty header length\r
- actionsList.add(ActionsDeserializer.createCopyTtlInAction(input));\r
- break;\r
- \r
- case 15: \r
- actionsLength = input.readUnsignedShort();//empty header length\r
- actionsList.add(ActionsDeserializer.createSetMplsTtlAction(input));\r
- break;\r
- \r
- case 16: \r
- actionsLength = input.readUnsignedShort();//empty header length\r
- actionsList.add(ActionsDeserializer.createDecMplsTtlOutAction(input));\r
- break;\r
- \r
- case 17: \r
- actionsLength = input.readUnsignedShort();\r
- actionsList.add(ActionsDeserializer.createPushVlanAction(input));\r
- break;\r
- \r
- case 18: \r
- actionsLength = input.readUnsignedShort();//empty header length\r
- actionsList.add(ActionsDeserializer.createPopVlanAction(input));\r
- break;\r
- \r
- case 19: \r
- actionsLength = input.readUnsignedShort();//8\r
- actionsList.add(ActionsDeserializer.createPushMplsAction(input));\r
- break;\r
- \r
- case 20: \r
- actionsLength = input.readUnsignedShort();//8\r
- actionsList.add(ActionsDeserializer.createPopMplsAction(input));\r
- break;\r
- \r
- case 21: \r
- actionsLength = input.readUnsignedShort();\r
- actionsList.add(ActionsDeserializer.createSetQueueAction(input));\r
- break;\r
- \r
- case 22: \r
- actionsLength = input.readUnsignedShort();//8\r
- actionsList.add(ActionsDeserializer.createGroupAction(input));\r
- break;\r
- \r
- case 23: \r
- actionsLength = input.readUnsignedShort();//8\r
- actionsList.add(ActionsDeserializer.createSetNwTtlAction(input));\r
- break;\r
- \r
- case 24: \r
- actionsLength = input.readUnsignedShort();//empty header length\r
- actionsList.add(ActionsDeserializer.createDecNwTtlAction(input));\r
- break;\r
- \r
- case 25:\r
- actionsLength = input.readUnsignedShort();//8\r
- actionsList.add(ActionsDeserializer.createSetFieldAction(input,\r
- actionsLength - ACTION_HEADER_LENGTH));\r
- break; \r
- case 26: \r
- actionsLength = input.readUnsignedShort();//8\r
- actionsList.add(ActionsDeserializer.createPushPbbAction(input));\r
- break;\r
- \r
- case 27: \r
- actionsLength = input.readUnsignedShort();//empty header length\r
- actionsList.add(ActionsDeserializer.createPopPbbAction(input));\r
- break;\r
- \r
- case 0xFFFF: \r
- actionsLength = input.readUnsignedShort();\r
- actionsList.add(ActionsDeserializer.createExperimenterAction(input));\r
- break;\r
- default: \r
- break;\r
- }\r
- bucketsCurrentLength += actionsLength;\r
- } \r
+ public static List<ActionsList> createActionsList(ByteBuf input, int actionsLength) {\r
+ ActionsListBuilder actionsListBuilder = new ActionsListBuilder();\r
+ List<ActionsList> actionsList = new ArrayList<>();\r
+ int length = 0;\r
+ while (length < actionsLength) {\r
+ int currentActionLength = 0;\r
+ switch(input.readUnsignedShort()) {\r
+ case 0: currentActionLength = input.readUnsignedShort(); //outputActionLength\r
+ actionsList.add(ActionsDeserializer.createOutputAction(input, actionsListBuilder));\r
+ break;\r
+ case 11: \r
+ currentActionLength = input.readUnsignedShort();//empty header length\r
+ actionsList.add(ActionsDeserializer.createCopyTtlOutAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 12: \r
+ currentActionLength = input.readUnsignedShort();//empty header length\r
+ actionsList.add(ActionsDeserializer.createCopyTtlInAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 15: \r
+ currentActionLength = input.readUnsignedShort();//empty header length\r
+ actionsList.add(ActionsDeserializer.createSetMplsTtlAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 16: \r
+ currentActionLength = input.readUnsignedShort();//empty header length\r
+ actionsList.add(ActionsDeserializer.createDecMplsTtlOutAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 17: \r
+ currentActionLength = input.readUnsignedShort();\r
+ actionsList.add(ActionsDeserializer.createPushVlanAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 18: \r
+ currentActionLength = input.readUnsignedShort();//empty header length\r
+ actionsList.add(ActionsDeserializer.createPopVlanAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 19: \r
+ currentActionLength = input.readUnsignedShort();//8\r
+ actionsList.add(ActionsDeserializer.createPushMplsAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 20: \r
+ currentActionLength = input.readUnsignedShort();//8\r
+ actionsList.add(ActionsDeserializer.createPopMplsAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 21: \r
+ currentActionLength = input.readUnsignedShort();\r
+ actionsList.add(ActionsDeserializer.createSetQueueAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 22: \r
+ currentActionLength = input.readUnsignedShort();//8\r
+ actionsList.add(ActionsDeserializer.createGroupAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 23: \r
+ currentActionLength = input.readUnsignedShort();//8\r
+ actionsList.add(ActionsDeserializer.createSetNwTtlAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 24: \r
+ currentActionLength = input.readUnsignedShort();//empty header length\r
+ actionsList.add(ActionsDeserializer.createDecNwTtlAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 25:\r
+ currentActionLength = input.readUnsignedShort();//8\r
+ actionsList.add(ActionsDeserializer.createSetFieldAction(input, actionsListBuilder,\r
+ currentActionLength));\r
+ break; \r
+ case 26: \r
+ currentActionLength = input.readUnsignedShort();//8\r
+ actionsList.add(ActionsDeserializer.createPushPbbAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 27: \r
+ currentActionLength = input.readUnsignedShort();//empty header length\r
+ actionsList.add(ActionsDeserializer.createPopPbbAction(input, actionsListBuilder));\r
+ break;\r
+\r
+ case 0xFFFF: \r
+ currentActionLength = input.readUnsignedShort();\r
+ actionsList.add(ActionsDeserializer.createExperimenterAction(input, actionsListBuilder));\r
+ break;\r
+ default: \r
+ break;\r
+ }\r
+ length += currentActionLength;\r
+ } \r
return actionsList;\r
}\r
\r
/**\r
* @param action input action that contains empty header\r
* @param in input ByteBuf \r
+ * @param actionsListBuilder \r
* @return Action\r
*/\r
private static ActionsList createEmptyHeader(Class<? extends org.opendaylight.yang.gen.v1.\r
- urn.opendaylight.openflow.common.types.rev130731.Action> action, ByteBuf in) {\r
+ urn.opendaylight.openflow.common.types.rev130731.Action> action,\r
+ ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
final byte PADDING_IN_ACTIONS_HEADER = 4;\r
- \r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
actionBuilder.setType(action);\r
in.skipBytes(PADDING_IN_ACTIONS_HEADER);\r
actionsListBuilder.setAction(actionBuilder.build());\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return Action\r
*/\r
- public static ActionsList createCopyTtlInAction(ByteBuf in) {\r
- return createEmptyHeader(CopyTtlIn.class, in);\r
+ public static ActionsList createCopyTtlInAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ return createEmptyHeader(CopyTtlIn.class, in, actionsListBuilder);\r
}\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return Action\r
*/\r
- public static ActionsList createCopyTtlOutAction(ByteBuf in) {\r
- return createEmptyHeader(CopyTtlOut.class, in);\r
+ public static ActionsList createCopyTtlOutAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ return createEmptyHeader(CopyTtlOut.class, in, actionsListBuilder);\r
}\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return Action\r
*/\r
- public static ActionsList createDecMplsTtlOutAction(ByteBuf in) {\r
- return createEmptyHeader(DecMplsTtl.class, in);\r
+ public static ActionsList createDecMplsTtlOutAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ return createEmptyHeader(DecMplsTtl.class, in, actionsListBuilder);\r
}\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return Action\r
*/\r
- public static ActionsList createPopVlanAction(ByteBuf in) {\r
- return createEmptyHeader(PopVlan.class, in);\r
+ public static ActionsList createPopVlanAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ return createEmptyHeader(PopVlan.class, in, actionsListBuilder);\r
}\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return Action\r
*/\r
- public static ActionsList createDecNwTtlAction(ByteBuf in) {\r
- return createEmptyHeader(DecNwTtl.class, in);\r
+ public static ActionsList createDecNwTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ return createEmptyHeader(DecNwTtl.class, in, actionsListBuilder);\r
}\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return Action\r
*/\r
- public static ActionsList createPopPbbAction(ByteBuf in) {\r
- return createEmptyHeader(PopPbb.class, in);\r
+ public static ActionsList createPopPbbAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ return createEmptyHeader(PopPbb.class, in, actionsListBuilder);\r
}\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return ActionList\r
*/\r
- public static ActionsList createOutputAction(ByteBuf in) {\r
+ public static ActionsList createOutputAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
final byte PADDING_IN_OUTPUT_ACTIONS_HEADER = 6;\r
- \r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
actionBuilder.setType(Output.class);\r
PortActionBuilder port = new PortActionBuilder();\r
port.setPort(new PortNumber(in.readUnsignedInt()));\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return ActionList\r
*/\r
- public static ActionsList createSetMplsTtlAction(ByteBuf in) {\r
+ public static ActionsList createSetMplsTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
final byte PADDING_IN_SET_MPLS_TTL_ACTIONS_HEADER = 3;\r
- \r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
actionBuilder.setType(SetMplsTtl.class);\r
MplsTtlActionBuilder mplsTtl = new MplsTtlActionBuilder();\r
mplsTtl.setMplsTtl(in.readUnsignedByte());\r
/**\r
* @param action input action that contains push\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return ActionList\r
*/\r
- private static ActionsList createPushAction(Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Action> action, ByteBuf in) {\r
+ private static ActionsList createPushAction(Class<? extends org.opendaylight.yang.gen.\r
+ v1.urn.opendaylight.openflow.common.types.rev130731.Action> action,\r
+ ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
final byte PADDING_IN_PUSH_VLAN_ACTIONS_HEADER = 2;\r
- \r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
actionBuilder.setType(action);\r
EthertypeActionBuilder etherType = new EthertypeActionBuilder();\r
etherType.setEthertype(new EtherType(in.readUnsignedShort()));\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return Action\r
*/\r
- public static ActionsList createPushVlanAction(ByteBuf in) {\r
- return createPushAction(PushVlan.class, in);\r
+ public static ActionsList createPushVlanAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ return createPushAction(PushVlan.class, in, actionsListBuilder);\r
}\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return Action\r
*/\r
- public static ActionsList createPushMplsAction(ByteBuf in) {\r
- return createPushAction(PushMpls.class, in);\r
+ public static ActionsList createPushMplsAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ return createPushAction(PushMpls.class, in, actionsListBuilder);\r
}\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return Action\r
*/\r
- public static ActionsList createPopMplsAction(ByteBuf in) {\r
- return createPushAction(PopMpls.class, in);\r
+ public static ActionsList createPopMplsAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ return createPushAction(PopMpls.class, in, actionsListBuilder);\r
}\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return Action\r
*/\r
- public static ActionsList createPushPbbAction(ByteBuf in) {\r
- return createPushAction(PushPbb.class, in);\r
+ public static ActionsList createPushPbbAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ return createPushAction(PushPbb.class, in, actionsListBuilder);\r
}\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return ActionList\r
*/\r
- public static ActionsList createSetQueueAction(ByteBuf in) {\r
+ public static ActionsList createSetQueueAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
actionBuilder.setType(SetQueue.class);\r
QueueIdActionBuilder queueId = new QueueIdActionBuilder();\r
queueId.setQueueId(in.readUnsignedInt());\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return ActionList\r
*/\r
- public static ActionsList createGroupAction(ByteBuf in) {\r
+ public static ActionsList createGroupAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
actionBuilder.setType(Group.class);\r
GroupIdActionBuilder group = new GroupIdActionBuilder();\r
group.setGroupId(in.readUnsignedInt());\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return ActionList\r
*/\r
- public static ActionsList createExperimenterAction(ByteBuf in) {\r
+ public static ActionsList createExperimenterAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
actionBuilder.setType(Experimenter.class);\r
ExperimenterActionBuilder experimenter = new ExperimenterActionBuilder();\r
experimenter.setExperimenter(in.readUnsignedInt());\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @return ActionList\r
*/\r
- public static ActionsList createSetNwTtlAction(ByteBuf in) {\r
+ public static ActionsList createSetNwTtlAction(ByteBuf in, ActionsListBuilder actionsListBuilder) {\r
final byte PADDING_IN_NW_TTL_ACTIONS_HEADER = 3;\r
- \r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
actionBuilder.setType(SetNwTtl.class);\r
NwTtlActionBuilder nwTtl = new NwTtlActionBuilder();\r
nwTtl.setNwTtl(in.readUnsignedByte());\r
\r
/**\r
* @param in input ByteBuf\r
+ * @param actionsListBuilder \r
* @param actionLength length of action\r
* @return ActionList\r
*/\r
- public static ActionsList createSetFieldAction(ByteBuf in, int actionLength) {\r
+ public static ActionsList createSetFieldAction(ByteBuf in, ActionsListBuilder actionsListBuilder, int actionLength) {\r
+ ActionBuilder actionBuilder = new ActionBuilder();\r
actionBuilder.setType(SetField.class);\r
OxmFieldsActionBuilder matchEntries = new OxmFieldsActionBuilder();\r
- matchEntries.setMatchEntries(MatchDeserializer.createMatchEntries(in, actionLength));\r
+ matchEntries.setMatchEntries(MatchDeserializer.createMatchEntry(in, actionLength - ACTION_HEADER_LENGTH));\r
actionBuilder.addAugmentation(OxmFieldsAction.class, matchEntries.build());\r
actionsListBuilder.setAction(actionBuilder.build());\r
\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.ActionsList;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.actions.list.Action;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.MatchEntries;\r
\r
/**\r
* Class for easy serialization of actions\r
*/\r
public abstract class ActionsSerializer {\r
\r
- private static final Logger LOGGER = LoggerFactory.getLogger(ActionsSerializer.class);\r
-\r
/**\r
* Encodes actions to ByteBuf\r
* @param actionsList list of actions to be encoded\r
\r
private static void encodeSetFieldAction(Action action, ByteBuf outBuffer) {\r
final int SET_FIELD_CODE = 25;\r
- final byte SET_FIELD_FIELDS_LENGTH = 4; // only type and length\r
- // TODO - figure out definition from testing + check length\r
+ final byte SET_FIELD_HEADER_LENGTH = 4; // only type and length\r
OxmFieldsAction oxmField = action.getAugmentation(OxmFieldsAction.class);\r
- int length = MatchSerializer.computeMatchEntriesLength(oxmField.getMatchEntries()) + SET_FIELD_FIELDS_LENGTH;\r
- LOGGER.warn("Received set-field action - possible wrong or no implementation");\r
+ int length = MatchSerializer.computeMatchEntriesLength(oxmField.getMatchEntries()) + SET_FIELD_HEADER_LENGTH;\r
outBuffer.writeShort(SET_FIELD_CODE);\r
int paddingRemainder = length % EncodeConstants.PADDING;\r
if (paddingRemainder != 0) {\r
public static int computeLengthOfActions(List<ActionsList> actionsList) {\r
final byte OUTPUT_LENGTH = 16;\r
final byte LENGTH_OF_OTHER_ACTIONS = 8;\r
+ final byte ACTION_HEADER_LENGTH = 4;\r
int lengthOfActions = 0;\r
if (actionsList != null) {\r
for (ActionsList list : actionsList) {\r
Action action = list.getAction();\r
if (action.getType().equals(Output.class)) {\r
lengthOfActions += OUTPUT_LENGTH;\r
+ } else if (action.getType().equals(SetField.class)){\r
+ List<MatchEntries> entries = action.getAugmentation(OxmFieldsAction.class).getMatchEntries();\r
+ int actionLength = ACTION_HEADER_LENGTH + MatchSerializer.computeMatchEntriesLength(entries);\r
+ lengthOfActions += actionLength;\r
+ int paddingRemainder = actionLength % EncodeConstants.PADDING;\r
+ if ((paddingRemainder) != 0) {\r
+ lengthOfActions += EncodeConstants.PADDING - paddingRemainder;\r
+ }\r
} else {\r
lengthOfActions += LENGTH_OF_OTHER_ACTIONS;\r
}\r
private static final byte SIZE_OF_SHORT_IN_BYTES = Short.SIZE / Byte.SIZE;\r
private static final byte SIZE_OF_BYTE_IN_BYTES = Byte.SIZE / Byte.SIZE;\r
private static final byte SIZE_OF_IPV6_ADDRESS_IN_BYTES = (8 * Short.SIZE) / Byte.SIZE;\r
- private static List<MatchEntries> matchEntriesList = new ArrayList<>();\r
- private static MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); \r
+ \r
\r
/**\r
* Creates match\r
MatchBuilder builder = new MatchBuilder();\r
int type = in.readUnsignedShort();\r
int length = in.readUnsignedShort();\r
- LOGGER.debug("length: " + length);\r
switch (type) {\r
case 0:\r
builder.setType(StandardMatchType.class);\r
return null;\r
}\r
\r
+ /**\r
+ * @param in input ByteBuf\r
+ * @param matchLength to infer size of array\r
+ * @return MatchEntriesList\r
+ */\r
+ public static List<MatchEntries> createMatchEntry(ByteBuf in, int matchLength) {\r
+ return createMatchEntriesInternal(in, matchLength, true);\r
+ }\r
+ \r
/**\r
* @param in input ByteBuf\r
* @param matchLength to infer size of array\r
* @return MatchEntriesList\r
*/\r
public static List<MatchEntries> createMatchEntries(ByteBuf in, int matchLength) {\r
+ return createMatchEntriesInternal(in, matchLength, false);\r
+ }\r
+ \r
+ private static List<MatchEntries> createMatchEntriesInternal(ByteBuf in, int matchLength, boolean oneEntry) {\r
+ List<MatchEntries> matchEntriesList = new ArrayList<>();\r
int currLength = 0;\r
while(currLength < matchLength) {\r
+ MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder(); \r
switch (in.readUnsignedShort()) { \r
case 0x0000:\r
matchEntriesBuilder.setOxmClass(Nxm0Class.class);\r
break;\r
}\r
matchEntriesList.add(matchEntriesBuilder.build());\r
+ if (oneEntry) {\r
+ break;\r
+ }\r
+ }\r
+ if ((matchLength - currLength) > 0) {\r
+ in.skipBytes(matchLength - currLength);\r
}\r
return matchEntriesList;\r
}\r
*/\r
public static void encodeMatchEntries(List<MatchEntries> matchEntries, ByteBuf out) {\r
if (matchEntries == null) {\r
- LOGGER.warn("Match entry is null");\r
+ LOGGER.warn("Match entries are null");\r
return;\r
}\r
for (MatchEntries entry : matchEntries) {\r
* @return length of MatchEntries\r
*/\r
public static int computeMatchEntriesLength(List<MatchEntries> matchEntries) {\r
+ final byte MATCH_ENTRY_HEADER_LENGTH = 4;\r
int length = 0;\r
if (matchEntries != null) {\r
for (MatchEntries entry : matchEntries) {\r
+ length += MATCH_ENTRY_HEADER_LENGTH;\r
Class<? extends MatchField> field = entry.getOxmMatchField();\r
if (field.equals(InPort.class)) {\r
length += Integer.SIZE / Byte.SIZE;\r
import org.junit.Assert;\r
import org.junit.Test;\r
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;\r
\r
/**\r
@Test\r
public void test() {\r
ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00"\r
- + " 01 02 03 00 01 02 03");\r
+ + " 00 01 41 00 01 02 03");\r
GetFeaturesOutput builtByFactory = BufferHelper.decodeV13(\r
FeaturesReplyMessageFactory.getInstance(), bb);\r
\r
Assert.assertEquals("Wrong buffers", 0x00010203L, builtByFactory.getBuffers().longValue());\r
Assert.assertEquals("Wrong number of tables", 0x01, builtByFactory.getTables().shortValue());\r
Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue());\r
- \r
- //TODO - fix test\r
- //Assert.assertEquals("Wrong capabilities", 0x00010203L, builtByFactory.getCapabilities().longValue());\r
+ Assert.assertEquals("Wrong capabilities", new Capabilities(true, false, false, true, false, true, false), builtByFactory.getCapabilities());\r
Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue());\r
}\r
}\r
import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortState;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPhyPort;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyPortStats;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyQueue;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyTable;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
\r
/**\r
* @author timotej.kubas\r
*/\r
public class MultipartReplyMessageFactoryTest {\r
\r
+ private static final Logger LOGGER = LoggerFactory\r
+ .getLogger(MultipartReplyMessageFactoryTest.class);\r
+ \r
/**\r
* Testing {@link MultipartReplyMessageFactory} for correct translation into POJO\r
*//*\r
message.getPorts().get(0).getHwAddr());\r
Assert.assertEquals("Wrong portName", "SampleText", \r
message.getPorts().get(0).getName());\r
- //TODO - fix test\r
- //Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), \r
- // message.getPorts().get(0).getConfig());\r
- //Assert.assertEquals("Wrong portState", new PortState(true, false, true), \r
- // message.getPorts().get(0).getState());\r
+ Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), \r
+ message.getPorts().get(0).getConfig());\r
+ Assert.assertEquals("Wrong portState", new PortState(false, true, true),\r
+ message.getPorts().get(0).getState());\r
Assert.assertEquals("Wrong currentFeatures", new PortFeatures(true, false, false, false,\r
false, false, false, true, \r
false, false, false, false, \r
"00 08 "+//copyTTLIntLen\r
"00 00 00 00"//copyTTLInPad\r
);\r
- \r
MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb);\r
\r
BufferHelper.checkHeaderV13(builtByFactory);\r
* Testing {@link MultipartReplyMessageFactory} for correct translation into POJO\r
* Test covers bodies of actions NW TTL, Experimenter\r
*/\r
- //@Test\r
- // TODO - fix test\r
+ @Test\r
public void testMultipartReplyGroupDescBody04(){\r
ByteBuf bb = BufferHelper.buildBuffer("00 07 00 01 00 00 00 00 "+\r
- "00 3C "+//len\r
+ "00 30 "+//len\r
"01 "+//type\r
"00 "+//pad\r
"00 00 00 08 "+//groupId\r
- "00 34 "+//bucketLen\r
+ "00 28 "+//bucketLen\r
"00 06 "+//bucketWeight\r
"00 00 00 05 "+//bucketWatchPort\r
"00 00 00 04 "+//bucketWatchGroup\r
"00 08 "+//nwTTlLen\r
"0E "+//nwTTlnwTTL\r
"00 00 00 "+//nwTTlPad\r
- "FF FF "+//experimenterType\r
- "00 08 "+//experimenterLen\r
- "00 01 02 03 "+//experimenterExperimenter\r
"00 19 "+//setFieldType\r
- "00 14 "+//setFieldLen\r
+ "00 10 "+//setFieldLen\r
"80 00 "+//setFieldOXMClass\r
"00 "+//setFieldOXMField\r
"04 "+//setFieldOXMLength\r
- "00 00 00 FF "+//setFieldPort\r
- \r
- "80 00 "+//setFieldOXMClass\r
- "03 "+//setFieldOXMField\r
- "04 "+//setFieldOXMLength\r
- "00 00 0F FF"//setFieldPort\r
- );\r
+ "00 00 00 FF "+ //setFieldPort\r
+ "00 00 00 00"\r
+ );\r
\r
MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb);\r
\r
message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(0).\r
getAction().getAugmentation(NwTtlAction.class).getNwTtl().intValue());\r
\r
- Assert.assertEquals("Wrong experimenterType", Experimenter.class, \r
- message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1).\r
- getAction().getType());\r
- \r
- Assert.assertEquals("Wrong experimenterExperimenter", 66051, \r
- message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1).\r
- getAction().getAugmentation(ExperimenterAction.class).getExperimenter().intValue());\r
- \r
Assert.assertEquals("Wrong setFieldType", SetField.class, \r
- message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2).\r
+ message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1).\r
getAction().getType());\r
\r
Assert.assertEquals("Wrong setFieldOXMClass", OpenflowBasicClass.class, \r
- message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2).\r
+ message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1).\r
getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).getOxmClass());\r
\r
Assert.assertEquals("Wrong setFieldOXMField", InPort.class, \r
- message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2).\r
+ message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1).\r
getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).getOxmMatchField());\r
\r
- Assert.assertEquals("Wrong setFieldOXMField", 255, \r
- message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2).\r
+ Assert.assertEquals("Wrong setFieldOXMValue", 255, \r
+ message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(1).\r
getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(0).\r
getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());\r
- \r
- \r
- Assert.assertEquals("Wrong setFieldOXMClass", OpenflowBasicClass.class, \r
- message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2).\r
- getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(1).getOxmClass());\r
- \r
- Assert.assertEquals("Wrong setFieldOXMField", InPhyPort.class, \r
- message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2).\r
- getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(1).getOxmMatchField());\r
- \r
- Assert.assertEquals("Wrong setFieldOXMField", 4095, \r
- message.getGroupDesc().get(0).getBucketsList().get(0).getActionsList().get(2).\r
- getAction().getAugmentation(OxmFieldsAction.class).getMatchEntries().get(1).\r
- getAugmentation(PortNumberMatchEntry.class).getPortNumber().getValue().intValue());\r
}\r
}\r
Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().getIntValue());\r
Assert.assertEquals("Wrong portNumber", 66051L, builtByFactory.getPortNo().longValue());\r
Assert.assertEquals("Wrong macAddress", new MacAddress("08002700B0EB"), builtByFactory.getHwAddr());\r
- //TODO - fix test\r
- //Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), builtByFactory.getConfig());\r
- //Assert.assertEquals("Wrong portState", new PortState(true, false, true), builtByFactory.getState());\r
+ Assert.assertEquals("Wrong portConfig", new PortConfig(false, true, false, true), builtByFactory.getConfig());\r
+ Assert.assertEquals("Wrong portState", new PortState(false, true, true), builtByFactory.getState());\r
Assert.assertEquals("Wrong currentFeatures", new PortFeatures(true, false, false, false,\r
false, false, false, true, false, false, false, false, \r
false, false, false, false), builtByFactory.getCurrentFeatures());\r
import org.junit.Assert;\r
import org.junit.Test;\r
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;\r
* Testing of {@link QueueGetConfigReplyMessageFactory} for correct\r
* translation into POJO\r
*/\r
- //@Test\r
- // TODO - fix test\r
+ @Test\r
public void test() {\r
ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 " + // port\r
"00 00 00 00 " + // padding\r
"00 00 00 01 " + // queueId\r
"00 00 00 01 " + // port\r
- "00 00 00 00 00 00 00 00 " + // pad\r
- "00 01 " + // property\r
+ "00 20 " + // length\r
+ "00 00 00 00 00 00 " + // pad\r
+ "00 02 " + // property\r
+ "00 10 " + // length\r
+ "00 00 00 00 " + // pad\r
+ "00 05 " + // rate\r
"00 00 00 00 00 00 " + // pad\r
"00 00 00 02 " + // queueId\r
"00 00 00 02 " + // port\r
- "00 00 00 00 00 00 00 00 " + // pad\r
- "00 01 " + // property\r
+ "00 20 " + // length\r
"00 00 00 00 00 00 " + // pad\r
- "00 00 00 03 " + // queueId\r
- "00 00 00 03 " + // port\r
- "00 00 00 00 00 00 00 00 " + // pad\r
- "00 01 " + // property\r
- "00 00 00 00 00 00" // pad\r
+ "00 02 " + // property\r
+ "00 10 " + // length\r
+ "00 00 00 00 " + // pad\r
+ "00 05 " + // rate\r
+ "00 00 00 00 00 00 " // pad\r
);\r
\r
GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(\r
\r
BufferHelper.checkHeaderV13(builtByFactory);\r
Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue());\r
- Assert.assertEquals("Wrong queues", builtByFactory.getQueues(),\r
- createQueuesList());\r
+ Assert.assertEquals("Wrong queues", createQueuesList(), builtByFactory.getQueues());\r
}\r
\r
private static List<Queues> createQueuesList() {\r
List<Queues> queuesList = new ArrayList<>();\r
- QueuesBuilder qb = new QueuesBuilder();\r
- for (int i = 1; i <= 3; i++) {\r
+ for (int i = 1; i < 3; i++) {\r
+ QueuesBuilder qb = new QueuesBuilder();\r
qb.setQueueId(new QueueId((long) i));\r
qb.setPort(new PortNumber((long) i));\r
qb.setQueueProperty(createPropertiesList());\r
private static List<QueueProperty> createPropertiesList() {\r
List<QueueProperty> propertiesList = new ArrayList<>();\r
QueuePropertyBuilder pb = new QueuePropertyBuilder();\r
- pb.setProperty(QueueProperties.forValue(1));\r
+ pb.setProperty(QueueProperties.forValue(2));\r
+ RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();\r
+ rateBuilder.setRate(5);\r
+ pb.addAugmentation(RateQueueProperty.class, rateBuilder.build());\r
propertiesList.add(pb.build());\r
return propertiesList;\r
}\r
import org.junit.Assert;\r
import org.junit.Test;\r
import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;\r
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;\r
/**\r
* Testing {@link QueueGetConfigReplyMessageFactory} for correct translation into POJO\r
*/\r
- //@Test\r
- // TODO - fix test\r
+ @Test\r
public void test(){\r
- 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");\r
+ 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");\r
GetQueueConfigOutput builtByFactory = BufferHelper.decodeV13(QueueGetConfigReplyMessageFactory.getInstance(), bb);\r
BufferHelper.checkHeaderV13(builtByFactory);\r
- Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue());\r
+ Assert.assertEquals("Wrong port", 3L, builtByFactory.getPort().getValue().longValue());\r
Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), createQueuesList());\r
}\r
\r
List<Queues> queuesList = new ArrayList<>();\r
QueuesBuilder qb = new QueuesBuilder();\r
qb.setQueueId(new QueueId(1L));\r
- qb.setPort(new PortNumber(1L));\r
+ qb.setPort(new PortNumber(3L));\r
qb.setQueueProperty(createPropertiesList());\r
queuesList.add(qb.build());\r
\r
List<QueueProperty> propertiesList = new ArrayList<>();\r
QueuePropertyBuilder pb = new QueuePropertyBuilder();\r
pb.setProperty(QueueProperties.forValue(2));\r
+ RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();\r
+ rateBuilder.setRate(5);\r
+ pb.addAugmentation(RateQueueProperty.class, rateBuilder.build());\r
propertiesList.add(pb.build());\r
- \r
return propertiesList;\r
}\r
}\r
* @throws Exception\r
* Testing of {@link MultipartRequestMessageFactory} for correct translation from POJO\r
*/\r
- //@Test\r
- //TODO - fix test\r
+ @Test\r
public void testMultipartRequestExperimenterMessageFactory() throws Exception {\r
MultipartRequestMessageBuilder builder = new MultipartRequestMessageBuilder();\r
BufferHelper.setupHeader(builder);\r
public void testMultipartRequestTableFeaturesMessageFactory() throws Exception {\r
MultipartRequestMessageBuilder builder = new MultipartRequestMessageBuilder();\r
BufferHelper.setupHeader(builder);\r
- builder.setType(MultipartType.forValue(0xffff));\r
+ builder.setType(MultipartType.forValue(12));\r
builder.setFlags(new MultipartRequestFlags(true));\r
builder.setMultipartRequestBody(createRequestTableFeatures());\r
MultipartRequestMessage message = builder.build();\r
BufferHelper.setupHeader(builder);\r
builder.setPortNo(new PortNumber(9L));\r
builder.setHwAddress(new MacAddress("08002700B0EB"));\r
- //TODO - fix test\r
builder.setConfig(new PortConfig(true, false, true, false));\r
builder.setMask(new PortConfig(false, true, false, true));\r
builder.setAdvertise(new PortFeatures(true, false, false, false,\r
TableModInputBuilder builder = new TableModInputBuilder();\r
BufferHelper.setupHeader(builder);\r
builder.setTableId(new TableId(9L));\r
- //TODO - fix test\r
builder.setConfig(new PortConfig(true, false, true, false));\r
TableModInput message = builder.build();\r
\r