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;
12 import static org.junit.Assert.assertTrue;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.UnpooledByteBufAllocator;
16 import java.util.Arrays;
17 import java.util.Collections;
18 import java.util.List;
19 import org.junit.Test;
20 import org.opendaylight.openflowjava.util.ByteBufUtils;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.reply.multipart.reply.body.MultipartReplyMeterFeatures;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandDrop;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBandDscpRemark;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterBurst;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterKbps;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterPktps;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterStats;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
30 public class MultipartReplyMeterFeaturesDeserializerTest extends AbstractMultipartDeserializerTest {
31 private static final int MAX_METER = 3;
32 private static final List BANDS_SUPPORTED = Collections.singletonList(MeterBandDrop.class);
33 private static final List CAPABILITIES_SUPPORTED = Arrays.asList(MeterKbps.class, MeterBurst.class);
34 private static final byte MAX_BANDS = 56;
35 private static final byte MAX_COLOR = 48;
38 public void deserialize() throws Exception {
39 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
40 buffer.writeInt(MAX_METER);
42 int bitMaskBands = ByteBufUtils.fillBitMask(0,
43 BANDS_SUPPORTED.contains(MeterBandDrop.class),
44 BANDS_SUPPORTED.contains(MeterBandDscpRemark.class));
45 buffer.writeInt(bitMaskBands);
47 int bitMaskCapabilities = ByteBufUtils.fillBitMask(0,
48 CAPABILITIES_SUPPORTED.contains(MeterKbps.class),
49 CAPABILITIES_SUPPORTED.contains(MeterPktps.class),
50 CAPABILITIES_SUPPORTED.contains(MeterBurst.class),
51 CAPABILITIES_SUPPORTED.contains(MeterStats.class));
52 buffer.writeInt(bitMaskCapabilities);
54 buffer.writeByte(MAX_BANDS);
55 buffer.writeByte(MAX_COLOR);
57 final MultipartReplyMeterFeatures reply = (MultipartReplyMeterFeatures) deserializeMultipart(buffer);
59 assertEquals(MAX_METER, reply.getMaxMeter().getValue().intValue());
60 assertTrue(reply.getMeterBandSupported().containsAll(BANDS_SUPPORTED));
61 assertTrue(reply.getMeterCapabilitiesSupported().containsAll(CAPABILITIES_SUPPORTED));
62 assertEquals(MAX_BANDS, reply.getMaxBands().byteValue());
63 assertEquals(MAX_COLOR, reply.getMaxColor().byteValue());
64 assertEquals(0, buffer.readableBytes());
68 protected int getType() {
69 return MultipartType.OFPMPMETERFEATURES.getIntValue();