blob: 94ccf9a4771516a74e8dc2b6817424b4ef6fa2f3 [file] [log] [blame]
Gamze Abaka1e5ccf52018-07-02 11:59:03 +00001/*
2 * Copyright 2017-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 */
16package org.opencord.sadis.impl;
17
18import org.junit.Before;
19import org.junit.Test;
20import org.opencord.sadis.BandwidthProfileInformation;
21import org.opencord.sadis.BaseConfig;
22import org.opencord.sadis.BaseInformation;
23import org.opencord.sadis.BaseInformationService;
24
25import java.util.List;
Gamze Abakad46003f2021-03-03 10:37:07 +000026import java.util.Objects;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000027
28import static org.junit.Assert.assertEquals;
29import static org.junit.Assert.assertTrue;
30
31public class BandwidthProfileManagerTest extends BaseSadis {
32
Gamze Abakad46003f2021-03-03 10:37:07 +000033 BandwidthProfileBuilder bp1 = BandwidthProfileBuilder.build("High Speed", 0, null, 1000000000,
34 384000L, 100000000, 384000L, 100000000);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000035
Gamze Abakad46003f2021-03-03 10:37:07 +000036 BandwidthProfileBuilder bp2 = BandwidthProfileBuilder.build("Home User Speed", 0, null, 1000000000,
37 200000L, 100000000, 200000L, 100000000);
38
39 BandwidthProfileBuilder bp3 = BandwidthProfileBuilder.build("TCONT_TYPE1_100Mbps_Fixed", 100000, 10000L,
40 0, 0L, 0, null, 100000);
41
42 BandwidthProfileBuilder bp4 = BandwidthProfileBuilder.build("TCONT_TYPE2_50Mbps_Assured", 50000, 10000L,
43 50000, 10000L, 0, null, 0);
44
45 BandwidthProfileBuilder bp5 = BandwidthProfileBuilder.build("TCONT_TYPE3_50Mbps_Assured_100Mbps_Peak",
46 100000, 10000L, 50000, 10000L, 0, null, 0);
47
48 BandwidthProfileBuilder bp6 = BandwidthProfileBuilder.build("TCONT_TYPE4_200Mbps_Peak", 200000, 10000L,
49 0, 0L, 0, null, 0);
50
51 BandwidthProfileBuilder bp7 = BandwidthProfileBuilder.build(
52 "TCONT_TYPE5_100Mbps_Peak_50Mbps_Assured_10Mbps_Fixed", 100000, 10000L, 50000, 10000L,
53 0, null, 10000);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000054
55 @Before
56 public void setUp() throws Exception {
57 config = new BandwidthProfileConfig();
58 super.setUp("/LocalBpConfig.json", BandwidthProfileConfig.class);
59 }
60
61 @Test
62 public void testConfiguration() {
63 BandwidthProfileConfig bpConfig = sadis.cfgService.getConfig(null, BandwidthProfileConfig.class);
64 checkConfigInfo(60, "PT1m", bpConfig);
65 checkEntriesForBandwidthProfiles(bpConfig);
66 }
67
68 @Test
69 public void testLocalMode() throws Exception {
70
71 BaseInformationService<BandwidthProfileInformation> bpService = sadis.getBandwidthProfileService();
72 checkGetForExisting("High Speed", bp1, bpService);
73 checkGetForExisting("Home User Speed", bp2, bpService);
Gamze Abakad46003f2021-03-03 10:37:07 +000074 checkGetForExisting("TCONT_TYPE1_100Mbps_Fixed", bp3, bpService);
75 checkGetForExisting("TCONT_TYPE2_50Mbps_Assured", bp4, bpService);
76 checkGetForExisting("TCONT_TYPE3_50Mbps_Assured_100Mbps_Peak", bp5, bpService);
77 checkGetForExisting("TCONT_TYPE4_200Mbps_Peak", bp6, bpService);
78 checkGetForExisting("TCONT_TYPE5_100Mbps_Peak_50Mbps_Assured_10Mbps_Fixed", bp7, bpService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000079
80 invalidateId("High Speed", bpService);
81 checkFromBoth("High Speed", bp1, bpService);
82
83 invalidateAll(bpService);
84 checkFromBoth("Home User Speed", bp2, bpService);
85 }
86
87 @Test
88 public void testRemoteMode() throws Exception {
89 BaseInformationService<BandwidthProfileInformation> service = sadis.getBandwidthProfileService();
90 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
91 configListener.event(event);
92
93 checkGetForExisting("HighSpeed", bp1, service);
94
95 invalidateId("HighSpeed", service);
96 checkFromBoth("HighSpeed", bp1, service);
97
98 invalidateAll(service);
99 checkFromBoth("HighSpeed", bp1, service);
100 }
101
102 private void checkEntriesForBandwidthProfiles(BaseConfig config) {
103 List<BandwidthProfileInformation> entries = config.getEntries();
Gamze Abakad46003f2021-03-03 10:37:07 +0000104 assertEquals(7, entries.size());
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000105
Gamze Abakad46003f2021-03-03 10:37:07 +0000106 BandwidthProfileInformation bpi = BandwidthProfileBuilder.build("High Speed", 0, null,
107 1000000000, 384000L, 100000000, 384000L, 100000000);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000108 assertTrue(checkEquality(bpi, entries.get(0)));
109
Gamze Abakad46003f2021-03-03 10:37:07 +0000110 bpi = BandwidthProfileBuilder.build("Home User Speed", 0, null, 1000000000, 200000L,
111 100000000, 200000L, 100000000);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000112 assertTrue(checkEquality(bpi, entries.get(1)));
Gamze Abakad46003f2021-03-03 10:37:07 +0000113
114 bpi = BandwidthProfileBuilder.build("TCONT_TYPE1_100Mbps_Fixed", 100000, 10000L, 0, 0L,
115 0, null, 100000);
116 assertTrue(checkEquality(bpi, entries.get(2)));
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000117 }
118
119 private static final class BandwidthProfileBuilder extends BandwidthProfileInformation {
120
Gamze Abakad46003f2021-03-03 10:37:07 +0000121 public static BandwidthProfileBuilder build(String id, long pir, Long pbs,
122 long cir, Long cbs, long eir, Long ebs, long gir) {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000123 BandwidthProfileBuilder info = new BandwidthProfileBuilder();
124 info.setId(id);
125
Gamze Abakad46003f2021-03-03 10:37:07 +0000126 if (pir != 0) {
127 info.setPeakInformationRate(pir);
128 info.setPeakBurstSize(pbs);
129 }
130
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000131 if (cbs != null) {
132 info.setCommittedBurstSize(cbs);
133 } else {
134 info.setCommittedBurstSize(0L);
135 }
136 info.setCommittedInformationRate(cir);
137
Gamze Abakad46003f2021-03-03 10:37:07 +0000138 if (eir != 0) {
139 info.setExceededInformationRate(eir);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000140 info.setExceededBurstSize(ebs);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000141 }
142
Gamze Abakad46003f2021-03-03 10:37:07 +0000143 info.setGuaranteedInformationRate(gir);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000144 return info;
145 }
146 }
147
148 @Override
149 boolean checkEquality(BaseInformation localEntry, BaseInformation entry) {
150 BandwidthProfileInformation bpi = (BandwidthProfileInformation) localEntry;
151 BandwidthProfileInformation other = (BandwidthProfileInformation) entry;
152
153 if (other == null) {
154 return false;
155 }
156
157 if (bpi.id() == null) {
158 if (other.id() != null) {
159 return false;
160 }
161 } else if (!bpi.id().equals(other.id())) {
162 return false;
163 }
164
Gamze Abakad46003f2021-03-03 10:37:07 +0000165 if (bpi.peakInformationRate() != other.peakInformationRate()) {
166 return false;
167 }
168
169 if (!Objects.equals(bpi.peakBurstSize(), other.peakBurstSize())) {
170 return false;
171 }
172
173
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000174 if (bpi.committedInformationRate() != other.committedInformationRate()) {
175 return false;
176 }
177
178 if (!bpi.committedBurstSize().equals(other.committedBurstSize())) {
179 return false;
180 }
181
182 if (bpi.exceededInformationRate() != other.exceededInformationRate()) {
183 return false;
184 }
185
Gamze Abakad46003f2021-03-03 10:37:07 +0000186 if (!Objects.equals(bpi.exceededBurstSize(), other.exceededBurstSize())) {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000187 return false;
188 }
189
Gamze Abakad46003f2021-03-03 10:37:07 +0000190 if (bpi.guaranteedInformationRate() != other.guaranteedInformationRate()) {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000191 return false;
192 }
193
194 return true;
195 }
196
197}