blob: 9ea46c4b3e79c70d453f8688f72f8eb89d79526c [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;
26
27import static org.junit.Assert.assertEquals;
28import static org.junit.Assert.assertTrue;
29
30public class BandwidthProfileManagerTest extends BaseSadis {
31
32 BandwidthProfileBuilder bp1 = BandwidthProfileBuilder.build("High Speed", 1000000000, 384000L,
33 100000000, 384000L, 100000000);
34
35 BandwidthProfileBuilder bp2 = BandwidthProfileBuilder.build("Home User Speed", 1000000000, 200000L,
36 100000000, 200000L, 100000000);
37
38 @Before
39 public void setUp() throws Exception {
40 config = new BandwidthProfileConfig();
41 super.setUp("/LocalBpConfig.json", BandwidthProfileConfig.class);
42 }
43
44 @Test
45 public void testConfiguration() {
46 BandwidthProfileConfig bpConfig = sadis.cfgService.getConfig(null, BandwidthProfileConfig.class);
47 checkConfigInfo(60, "PT1m", bpConfig);
48 checkEntriesForBandwidthProfiles(bpConfig);
49 }
50
51 @Test
52 public void testLocalMode() throws Exception {
53
54 BaseInformationService<BandwidthProfileInformation> bpService = sadis.getBandwidthProfileService();
55 checkGetForExisting("High Speed", bp1, bpService);
56 checkGetForExisting("Home User Speed", bp2, bpService);
57
58 invalidateId("High Speed", bpService);
59 checkFromBoth("High Speed", bp1, bpService);
60
61 invalidateAll(bpService);
62 checkFromBoth("Home User Speed", bp2, bpService);
63 }
64
65 @Test
66 public void testRemoteMode() throws Exception {
67 BaseInformationService<BandwidthProfileInformation> service = sadis.getBandwidthProfileService();
68 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
69 configListener.event(event);
70
71 checkGetForExisting("HighSpeed", bp1, service);
72
73 invalidateId("HighSpeed", service);
74 checkFromBoth("HighSpeed", bp1, service);
75
76 invalidateAll(service);
77 checkFromBoth("HighSpeed", bp1, service);
78 }
79
80 private void checkEntriesForBandwidthProfiles(BaseConfig config) {
81 List<BandwidthProfileInformation> entries = config.getEntries();
82 assertEquals(2, entries.size());
83
84 BandwidthProfileInformation bpi = BandwidthProfileBuilder.build("High Speed", 1000000000, 384000L, 100000000,
85 384000L, 100000000);
86 assertTrue(checkEquality(bpi, entries.get(0)));
87
88 bpi = BandwidthProfileBuilder.build("Home User Speed", 1000000000, 200000L, 100000000,
89 200000L, 100000000);
90 assertTrue(checkEquality(bpi, entries.get(1)));
91 }
92
93 private static final class BandwidthProfileBuilder extends BandwidthProfileInformation {
94
95 public static BandwidthProfileBuilder build(String id, long cir, Long cbs, long eir, Long ebs, long air) {
96 BandwidthProfileBuilder info = new BandwidthProfileBuilder();
97 info.setId(id);
98
99 if (cbs != null) {
100 info.setCommittedBurstSize(cbs);
101 } else {
102 info.setCommittedBurstSize(0L);
103 }
104 info.setCommittedInformationRate(cir);
105
106 info.setExceededInformationRate(eir);
107 if (ebs != null) {
108 info.setExceededBurstSize(ebs);
109 } else {
110 info.setExceededBurstSize(0L);
111 }
112
113 info.setAssuredInformationRate(air);
114 return info;
115 }
116 }
117
118 @Override
119 boolean checkEquality(BaseInformation localEntry, BaseInformation entry) {
120 BandwidthProfileInformation bpi = (BandwidthProfileInformation) localEntry;
121 BandwidthProfileInformation other = (BandwidthProfileInformation) entry;
122
123 if (other == null) {
124 return false;
125 }
126
127 if (bpi.id() == null) {
128 if (other.id() != null) {
129 return false;
130 }
131 } else if (!bpi.id().equals(other.id())) {
132 return false;
133 }
134
135 if (bpi.committedInformationRate() != other.committedInformationRate()) {
136 return false;
137 }
138
139 if (!bpi.committedBurstSize().equals(other.committedBurstSize())) {
140 return false;
141 }
142
143 if (bpi.exceededInformationRate() != other.exceededInformationRate()) {
144 return false;
145 }
146
147 if (!bpi.exceededBurstSize().equals(other.exceededBurstSize())) {
148 return false;
149 }
150
151 if (bpi.assuredInformationRate() != other.assuredInformationRate()) {
152 return false;
153 }
154
155 return true;
156 }
157
158}