Wailok Shum | 90b988a | 2021-09-13 17:23:20 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2021-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.net.meter; |
| 17 | |
| 18 | import org.junit.Before; |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | |
| 22 | import java.util.Set; |
| 23 | |
| 24 | import static org.junit.Assert.assertEquals; |
| 25 | |
| 26 | /** |
| 27 | * DefaultMeterFeatures Tests. |
| 28 | */ |
| 29 | public class DefaultMeterFeaturesTest { |
| 30 | |
| 31 | private MeterFeatures mf; |
| 32 | private DeviceId did = DeviceId.deviceId("foo:foo"); |
| 33 | private short band = 2; |
| 34 | private short color = 3; |
| 35 | private Set<Band.Type> types; |
| 36 | private Set<Meter.Unit> units; |
| 37 | private MeterScope globalScope = MeterScope.globalScope(); |
| 38 | private MeterScope fooScope = MeterScope.of("foo"); |
| 39 | |
| 40 | @Before |
| 41 | public void setup() { |
| 42 | types = Set.of(Band.Type.DROP); |
| 43 | units = Set.of(Meter.Unit.KB_PER_SEC); |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void testZeroMaxMeter() { |
| 48 | mf = DefaultMeterFeatures.builder() |
| 49 | .forDevice(did) |
| 50 | .withMaxMeters(0L) |
| 51 | .withScope(globalScope) |
| 52 | .withMaxBands(band) |
| 53 | .withMaxColors(color) |
| 54 | .withBandTypes(types) |
| 55 | .withUnits(units) |
| 56 | .hasBurst(true) |
| 57 | .hasStats(true).build(); |
| 58 | |
| 59 | assertEquals(-1, mf.startIndex()); |
| 60 | assertEquals(-1, mf.endIndex()); |
| 61 | assertEquals(0L, mf.maxMeter()); |
| 62 | } |
| 63 | |
| 64 | @Test |
| 65 | public void testOfMaxMeter() { |
| 66 | mf = DefaultMeterFeatures.builder() |
| 67 | .forDevice(did) |
| 68 | .withMaxMeters(1024L) |
| 69 | .withScope(globalScope) |
| 70 | .withMaxBands(band) |
| 71 | .withMaxColors(color) |
| 72 | .withBandTypes(types) |
| 73 | .withUnits(units) |
| 74 | .hasBurst(true) |
| 75 | .hasStats(true).build(); |
| 76 | |
| 77 | assertEquals(1L, mf.startIndex()); |
| 78 | assertEquals(1024L, mf.endIndex()); |
| 79 | assertEquals(1024L, mf.maxMeter()); |
| 80 | } |
| 81 | |
| 82 | @Test |
| 83 | public void testNonOfMaxMeter() { |
| 84 | mf = DefaultMeterFeatures.builder() |
| 85 | .forDevice(did) |
| 86 | .withMaxMeters(1024L) |
| 87 | .withScope(fooScope) |
| 88 | .withMaxBands(band) |
| 89 | .withMaxColors(color) |
| 90 | .withBandTypes(types) |
| 91 | .withUnits(units) |
| 92 | .hasBurst(true) |
| 93 | .hasStats(true).build(); |
| 94 | |
| 95 | assertEquals(0L, mf.startIndex()); |
| 96 | assertEquals(1023L, mf.endIndex()); |
| 97 | assertEquals(1024L, mf.maxMeter()); |
| 98 | } |
| 99 | } |