2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.impl.protocol.deserialization.multipart;
11 import static org.junit.Assert.assertEquals;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.UnpooledByteBufAllocator;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.util.ByteBufUtils;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterConfig;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterFlags;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.Drop;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.band.type.band.type.DscpRemark;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
23 public class MultipartReplyMeterConfigDeserializerTest extends AbstractMultipartDeserializerTest {
24 private static final byte PADDING_IN_METER_BAND_DROP_HEADER = 4;
25 private static final byte PADDING_IN_METER_BAND_DSCP_HEADER = 3;
26 private static final int OFPMBTDROP = 1;
27 private static final int OFPMBTDSCP = 2;
28 private static final short ITEM_LENGTH = 16;
29 private static final boolean MF_KBPS = true;
30 private static final boolean MF_PKTPS = false;
31 private static final boolean MF_BURST = true;
32 private static final boolean MF_STATS = true;
33 private static final MeterFlags FLAGS = new MeterFlags(MF_KBPS, MF_PKTPS, MF_BURST, MF_STATS);
34 private static final int METER_ID = 1;
35 private static final short SUB_ITEM = 8;
36 private static final int DROP_RATE = 2;
37 private static final int DROP_BURST_SIZE = 3;
38 private static final int DSCP_REMARK_RATE = 3;
39 private static final int DSCP_REMARK_BURST_SIZE = 3;
40 private static final byte PREC_LEVEL = 3;
43 public void deserializeDrop() {
44 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
45 writeCommonAtributes(buffer);
46 buffer.writeShort(OFPMBTDROP);
47 buffer.writeShort(SUB_ITEM);
48 buffer.writeInt(DROP_RATE);
49 buffer.writeInt(DROP_BURST_SIZE);
50 buffer.writeZero(PADDING_IN_METER_BAND_DROP_HEADER);
52 final MultipartReplyMeterConfig reply = (MultipartReplyMeterConfig) deserializeMultipart(buffer);
54 assertEquals(METER_ID,
55 reply.nonnullMeterConfigStats().values().iterator().next().getMeterId().getValue().intValue());
56 assertEquals(FLAGS, reply.nonnullMeterConfigStats().values().iterator().next().getFlags());
57 final Drop drop = (Drop) reply.nonnullMeterConfigStats().values().iterator().next()
58 .getMeterBandHeaders().nonnullMeterBandHeader().values().iterator().next().getBandType();
59 assertEquals(DROP_RATE, drop.getDropRate().intValue());
60 assertEquals(DROP_BURST_SIZE, drop.getDropBurstSize().intValue());
64 public void deserializeDscp() {
65 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
66 writeCommonAtributes(buffer);
67 buffer.writeShort(OFPMBTDSCP);
68 buffer.writeShort(SUB_ITEM);
69 buffer.writeInt(DSCP_REMARK_RATE);
70 buffer.writeInt(DSCP_REMARK_BURST_SIZE);
71 buffer.writeByte(PREC_LEVEL);
72 buffer.writeZero(PADDING_IN_METER_BAND_DSCP_HEADER);
74 final MultipartReplyMeterConfig reply = (MultipartReplyMeterConfig) deserializeMultipart(buffer);
76 final DscpRemark dscpRemark = (DscpRemark) reply.nonnullMeterConfigStats().values().iterator().next()
77 .getMeterBandHeaders().nonnullMeterBandHeader().values().iterator().next().getBandType();
78 assertEquals(DSCP_REMARK_RATE, dscpRemark.getDscpRemarkRate().intValue());
79 assertEquals(DSCP_REMARK_BURST_SIZE, dscpRemark.getDscpRemarkBurstSize().intValue());
80 assertEquals(PREC_LEVEL, dscpRemark.getPrecLevel().byteValue());
84 protected int getType() {
85 return MultipartType.OFPMPMETERCONFIG.getIntValue();
88 private void writeCommonAtributes(final ByteBuf buffer) {
89 buffer.writeShort(ITEM_LENGTH);
90 buffer.writeShort(ByteBufUtils.fillBitMask(0,
94 FLAGS.isMeterStats()));
95 buffer.writeInt(METER_ID);