blob: 6ff5cc31ddd0c0a2c2c245ff52fe5f0b19c698f6 [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 static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertTrue;
20import static org.junit.Assert.assertNull;
21
22import java.util.List;
23
24import org.junit.After;
25import org.junit.Before;
26import org.junit.Test;
27import org.onlab.packet.Ip4Address;
28import org.onlab.packet.MacAddress;
29import org.onlab.packet.VlanId;
30
31import org.opencord.sadis.SubscriberAndDeviceInformation;
32import org.opencord.sadis.BaseConfig;
33import org.opencord.sadis.BaseInformationService;
34import org.opencord.sadis.BaseInformation;
35
36/**
37 * Set of tests of the SADIS ONOS application component.
38 */
39public class SubscriberAndDeviceManagerTest extends BaseSadis {
40
41 SubscriberAndDeviceInformationBuilder entry1 = SubscriberAndDeviceInformationBuilder.build("1", (short) 2,
42 (short) 2, "1/1/2", (short) 125, (short) 3, "aa:bb:cc:dd:ee:ff", "XXX-NASID", "10.10.10.10",
43 "circuit123", "remote123", 64, "1Gb", "1Gb");
44 SubscriberAndDeviceInformationBuilder entry2 = SubscriberAndDeviceInformationBuilder.build("2", (short) 4,
45 (short) 4, "1/1/2", (short) 129, (short) 4, "aa:bb:cc:dd:ee:ff", "YYY-NASID", "1.1.1.1",
46 "circuit234", "remote234", 64, "10Gb", "10Gb");
47 SubscriberAndDeviceInformationBuilder entry3 = SubscriberAndDeviceInformationBuilder.build("3", (short) 7,
48 (short) 8, "1/1/2", (short) 130, (short) 7, "ff:aa:dd:cc:bb:ee", "MNO-NASID", "30.30.30.30",
49 "circuit567", "remote567", 64, "10Gb", "10Gb");
50 SubscriberAndDeviceInformationBuilder entry4 = SubscriberAndDeviceInformationBuilder.build("4", (short) 2,
51 (short) 1, "1/1/2", (short) 132, (short) 1, "ff:cc:dd:aa:ee:bb", "PQR-NASID", "15.15.15.15",
52 "circuit678", "remote678", 64, "5Gb", "5Gb");
53
54
55 @Before
56 public void setUp() throws Exception {
57 config = new SubscriberAndDeviceInformationConfig();
58 super.setUp("/LocalSubConfig.json", SubscriberAndDeviceInformationConfig.class);
59 }
60
61 @After
62 public void tearDown() {
63 super.tearDown();
64 }
65
66 @Test
67 public void testConfiguration() {
68 SubscriberAndDeviceInformationConfig config = sadis.cfgService.getConfig(null,
69 SubscriberAndDeviceInformationConfig.class);
70 checkConfigInfo(50, "PT1m", config);
71 checkEntriesForSubscriberAndAccessDevice(config);
72 }
73
74 private void checkEntriesForSubscriberAndAccessDevice(BaseConfig config) {
75 List<SubscriberAndDeviceInformation> entries = config.getEntries();
76 assertEquals(3, entries.size());
77
78 SubscriberAndDeviceInformation sub = SubscriberAndDeviceInformationBuilder.build("1", (short) 2, (short) 2,
79 "1/1/2", (short) 125,
80 (short) 3, "aa:bb:cc:dd:ee:ff", "XXX-NASID", "10.10.10.10", "circuit123", "remote123",
81 64, "1Gb", "1Gb");
82 assertTrue(checkEquality(sub, entries.get(0)));
83
84
85 sub = SubscriberAndDeviceInformationBuilder.build("2", (short) 4, (short) 4, "1/1/2", (short) 129,
86 (short) 4, "aa:bb:cc:dd:ee:ff", "YYY-NASID", "1.1.1.1", "circuit234", "remote234",
87 64, "10Gb", "10Gb");
88 assertTrue(checkEquality(sub, entries.get(1)));
89
90 sub = SubscriberAndDeviceInformationBuilder.build("cc:dd:ee:ff:aa:bb", (short) -1, (short) -1, null,
91 (short) -1, (short) -1, "cc:dd:ee:ff:aa:bb", "CCC-NASID", "12.12.12.12", "circuit345", "remote345",
92 64, "10Gb", "10Gb");
93 assertTrue(checkEquality(sub, entries.get(2)));
94 }
95
96 @Test
97 public void testLocalMode() throws Exception {
98
99 BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
100
101 checkGetForExisting("1", entry1, subscriberService);
102 checkGetForExisting("2", entry2, subscriberService);
103
104 invalidateId("1", subscriberService);
105 checkFromBoth("1", entry1, subscriberService);
106
107 invalidateAll(subscriberService);
108 checkFromBoth("2", entry2, subscriberService);
109 }
110
111
112 private void checkGetForNonExist(String id, BaseInformationService service) {
113 BaseInformation entry = service.get(id);
114 assertNull(entry);
115 }
116
117 @Test
118 public void testRemoteMode() throws Exception {
119 BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
120 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
121 configListener.event(event);
122
123 checkGetForExisting("3", entry3, subscriberService);
124 checkGetForExisting("4", entry4, subscriberService);
125
126 invalidateId("3", subscriberService);
127 checkFromBoth("3", entry3, subscriberService);
128
129 invalidateAll(subscriberService);
130 checkFromBoth("4", entry4, subscriberService);
131 }
132
133 @Test
134 public void testModeSwitch() throws Exception {
135 BaseInformationService<SubscriberAndDeviceInformation> service = sadis.getSubscriberInfoService();
136 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
137 configListener.event(event);
138
139 checkGetForExisting("3", null, service);
140 checkGetForNonExist("1", service);
141
142 config.init(subject, "sadis-local-mode-test", node("/LocalSubConfig.json"), mapper, delegate);
143 configListener.event(event);
144
145 checkGetForExisting("1", null, service);
146 checkGetForNonExist("3", service);
147 }
148
149
150 private static final class SubscriberAndDeviceInformationBuilder extends SubscriberAndDeviceInformation {
151
152 public static SubscriberAndDeviceInformationBuilder build(String id, short cTag, short sTag, String nasPortId,
153 short port, short slot, String mac, String nasId,
154 String ipAddress, String circuitId, String remoteId,
155 int technologyProfileId,
156 String upstreamBandwidthProfile,
157 String downstreamBandwidthProfile) {
158
159 SubscriberAndDeviceInformationBuilder info = new SubscriberAndDeviceInformationBuilder();
160 info.setId(id);
161 if (cTag != -1) {
162 info.setCTag(VlanId.vlanId(cTag));
163 }
164 if (sTag != -1) {
165 info.setSTag(VlanId.vlanId(sTag));
166 }
167 info.setNasPortId(nasPortId);
168 if (port != -1) {
169 info.setUplinkPort(port);
170 }
171 if (slot != -1) {
172 info.setSlot(slot);
173 }
174 info.setHardwareIdentifier(MacAddress.valueOf(mac));
175 info.setIPAddress(Ip4Address.valueOf(ipAddress));
176 info.setNasId(nasId);
177 info.setCircuitId(circuitId);
178 info.setRemoteId(remoteId);
179
180 if (technologyProfileId != -1) {
181 info.setTechnologyProfileId(technologyProfileId);
182 }
183
184 info.setUpstreamBandwidthProfile(upstreamBandwidthProfile);
185 info.setDownstreamBandwidthProfile(downstreamBandwidthProfile);
186
187 return info;
188 }
189
190 }
191
192 @Override
193 public boolean checkEquality(BaseInformation localEntry, BaseInformation entry) {
194 SubscriberAndDeviceInformation sub = (SubscriberAndDeviceInformation) localEntry;
195 SubscriberAndDeviceInformation other = (SubscriberAndDeviceInformation) localEntry;
196
197 if (other == null) {
198 return false;
199 }
200 if (sub.cTag() == null) {
201 if (other.cTag() != null) {
202 return false;
203 }
204 } else if (!sub.cTag().equals(other.cTag())) {
205 return false;
206 }
207 if (sub.hardwareIdentifier() == null) {
208 if (other.hardwareIdentifier() != null) {
209 return false;
210 }
211 } else if (!sub.hardwareIdentifier().equals(other.hardwareIdentifier())) {
212 return false;
213 }
214 if (sub.id() == null) {
215 if (other.id() != null) {
216 return false;
217 }
218 } else if (!sub.id().equals(other.id())) {
219 return false;
220 }
221 if (sub.nasPortId() == null) {
222 if (other.nasPortId() != null) {
223 return false;
224 }
225 } else if (!sub.nasPortId().equals(other.nasPortId())) {
226 return false;
227 }
228 if (sub.nasId() == null) {
229 if (other.nasId() != null) {
230 return false;
231 }
232 } else if (!sub.nasId().equals(other.nasId())) {
233 return false;
234 }
235 if (sub.ipAddress() == null) {
236 if (other.ipAddress() != null) {
237 return false;
238 }
239 } else if (!sub.ipAddress().equals(other.ipAddress())) {
240 return false;
241 }
242 if (sub.uplinkPort() != other.uplinkPort()) {
243 return false;
244 }
245 if (sub.sTag() == null) {
246 if (other.sTag() != null) {
247 return false;
248 }
249 } else if (!sub.sTag().equals(other.sTag())) {
250 return false;
251 }
252 if (sub.slot() != other.slot()) {
253 return false;
254 }
255 if (sub.circuitId() == null) {
256 if (other.circuitId() != null) {
257 return false;
258 }
259 } else if (!sub.circuitId().equals(other.circuitId())) {
260 return false;
261 }
262 if (sub.remoteId() == null) {
263 if (other.remoteId() != null) {
264 return false;
265 }
266 } else if (!sub.remoteId().equals(other.remoteId())) {
267 return false;
268 }
269 if (sub.technologyProfileId() != other.technologyProfileId()) {
270 return false;
271 }
272 if (sub.upstreamBandwidthProfile() == null) {
273 if (other.upstreamBandwidthProfile() != null) {
274 return false;
275 }
276 } else if (!sub.upstreamBandwidthProfile().equals(other.upstreamBandwidthProfile())) {
277 return false;
278 }
279 if (sub.downstreamBandwidthProfile() == null) {
280 if (other.downstreamBandwidthProfile() != null) {
281 return false;
282 }
283 } else if (!sub.downstreamBandwidthProfile().equals(other.downstreamBandwidthProfile())) {
284 return false;
285 }
286 return true;
287 }
288
289
290}