Merge "Fix checkstyle warnings for impl/protocol test package"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / multipart / MultipartReplyMeterFeaturesDeserializerTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.protocol.deserialization.multipart;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.UnpooledByteBufAllocator;
16 import java.util.Arrays;
17 import java.util.List;
18 import org.junit.Test;
19 import org.opendaylight.openflowjava.util.ByteBufUtils;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterFeatures;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandDrop;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandDscpRemark;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBurst;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterKbps;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterPktps;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
28
29 public class MultipartReplyMeterFeaturesDeserializerTest extends AbstractMultipartDeserializerTest {
30     private static final int MAX_METER = 3;
31     private static final List BANDS_SUPPORTED = Arrays.asList(MeterBandDrop.class);
32     private static final List CAPABILITIES_SUPPORTED = Arrays.asList(MeterKbps.class, MeterBurst.class);
33     private static final byte MAX_BANDS = 56;
34     private static final byte MAX_COLOR = 48;
35
36     @Test
37     public void deserialize() throws Exception {
38         ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
39         buffer.writeInt(MAX_METER);
40
41         int bitMaskBands = ByteBufUtils.fillBitMask(0,
42                 BANDS_SUPPORTED.contains(MeterBandDrop.class),
43                 BANDS_SUPPORTED.contains(MeterBandDscpRemark.class));
44         buffer.writeInt(bitMaskBands);
45
46         int bitMaskCapabilities = ByteBufUtils.fillBitMask(0,
47                 CAPABILITIES_SUPPORTED.contains(MeterKbps.class),
48                 CAPABILITIES_SUPPORTED.contains(MeterPktps.class),
49                 CAPABILITIES_SUPPORTED.contains(MeterBurst.class),
50                 CAPABILITIES_SUPPORTED.contains(MeterStats.class));
51         buffer.writeInt(bitMaskCapabilities);
52
53         buffer.writeByte(MAX_BANDS);
54         buffer.writeByte(MAX_COLOR);
55
56         final MultipartReplyMeterFeatures reply = (MultipartReplyMeterFeatures) deserializeMultipart(buffer);
57
58         assertEquals(MAX_METER, reply.getMaxMeter().getValue().intValue());
59         assertTrue(reply.getMeterBandSupported().containsAll(BANDS_SUPPORTED));
60         assertTrue(reply.getMeterCapabilitiesSupported().containsAll(CAPABILITIES_SUPPORTED));
61         assertEquals(MAX_BANDS, reply.getMaxBands().byteValue());
62         assertEquals(MAX_COLOR, reply.getMaxColor().byteValue());
63         assertEquals(0, buffer.readableBytes());
64     }
65
66     @Override
67     protected int getType() {
68         return MultipartType.OFPMPMETERFEATURES.getIntValue();
69     }
70 }