2 * Copyright (c) 2014 Cisco Systems, Inc. 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.openflow.md.core.sal.convertor;
11 import static org.junit.Assert.assertEquals;
13 import java.math.BigInteger;
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Optional;
18 import org.junit.Test;
19 import org.opendaylight.openflowplugin.api.OFConstants;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.meter.band.stats.BandStat;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MeterId;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStatsBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStats;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStatsBuilder;
29 public class MeterStatsResponseConvertorTest {
30 private static final int PRESET_COUNT = 7;
33 private static List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply
34 .multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats> createMeterStatsLit() {
36 List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply
37 .multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.MeterStats>
38 allMeterStats = new ArrayList<>();
39 MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder();
40 for (int i = 0; i < PRESET_COUNT; i++) {
41 meterStatsBuilder.setByteInCount(BigInteger.valueOf(i));
42 meterStatsBuilder.setDurationNsec((long) 1000 * i);
43 meterStatsBuilder.setDurationSec((long) 10 * i);
44 meterStatsBuilder.setFlowCount((long) i);
45 MeterBandStatsBuilder meterBandStatsBuilder = new MeterBandStatsBuilder();
46 List<MeterBandStats> meterBandStatses = new ArrayList<>();
47 for (int j = 0; j < PRESET_COUNT; j++) {
48 meterBandStatsBuilder.setByteBandCount(BigInteger.valueOf(j));
49 meterBandStatsBuilder.setPacketBandCount(BigInteger.valueOf(j));
50 meterBandStatses.add(meterBandStatsBuilder.build());
52 meterStatsBuilder.setMeterBandStats(meterBandStatses);
53 meterStatsBuilder.setMeterId(new MeterId((long) i));
54 meterStatsBuilder.setPacketInCount(BigInteger.valueOf(i));
56 allMeterStats.add(meterStatsBuilder.build());
64 * Test of basic mapping functionality of {@link MeterStatsResponseConvertor#convert(java.util.List)}
66 public void testToSALMeterStatsList() {
67 final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
68 Optional<List<MeterStats>> meterStatsListOptional = convertorManager.convert(createMeterStatsLit(),
69 new VersionConvertorData(OFConstants.OFP_VERSION_1_3));
70 List<MeterStats> meterStatsList = meterStatsListOptional.orElse(Collections.emptyList());
71 assertEquals(PRESET_COUNT, meterStatsList.size());
74 for (MeterStats meterStats : meterStatsList) {
75 assertEquals(new MeterStatsKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918
76 .MeterId((long) cnt)).getMeterId(), meterStats.key().getMeterId());
77 assertEquals(BigInteger.valueOf(cnt), meterStats.getByteInCount().getValue());
78 assertEquals(new Long(1000 * cnt), meterStats.getDuration().getNanosecond().getValue());
79 assertEquals(new Long(10 * cnt), meterStats.getDuration().getSecond().getValue());
81 assertEquals(new Long(cnt), meterStats.getFlowCount().getValue());
82 assertEquals(BigInteger.valueOf(cnt), meterStats.getByteInCount().getValue());
84 assertEquals(PRESET_COUNT, meterStats.getMeterBandStats().getBandStat().size());
85 int bandStatCount = 0;
86 for (BandStat bandStat : meterStats.getMeterBandStats().getBandStat()) {
87 assertEquals(BigInteger.valueOf(bandStatCount), bandStat.getByteBandCount().getValue());
88 assertEquals(BigInteger.valueOf(bandStatCount), bandStat.getPacketBandCount().getValue());
91 assertEquals(new MeterStatsKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918
92 .MeterId((long) cnt)).getMeterId(), meterStats.getMeterId());
93 assertEquals(BigInteger.valueOf(cnt), meterStats.getPacketInCount().getValue());