blob: d2bc07c8e09ae0b64bf82722188733f064dc3106 [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;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000027
Matteo Scandoloe4f4b632020-01-07 23:54:35 +000028import org.opencord.sadis.BaseConfig;
Matteo Scandoloe4f4b632020-01-07 23:54:35 +000029import org.opencord.sadis.BaseInformation;
Matteo Scandolo198aef92020-01-08 00:43:17 +000030import org.opencord.sadis.BaseInformationService;
31import org.opencord.sadis.SubscriberAndDeviceInformation;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000032
33/**
34 * Set of tests of the SADIS ONOS application component.
35 */
36public class SubscriberAndDeviceManagerTest extends BaseSadis {
37
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000038 @Before
39 public void setUp() throws Exception {
40 config = new SubscriberAndDeviceInformationConfig();
41 super.setUp("/LocalSubConfig.json", SubscriberAndDeviceInformationConfig.class);
42 }
43
44 @After
45 public void tearDown() {
46 super.tearDown();
47 }
48
49 @Test
50 public void testConfiguration() {
51 SubscriberAndDeviceInformationConfig config = sadis.cfgService.getConfig(null,
52 SubscriberAndDeviceInformationConfig.class);
53 checkConfigInfo(50, "PT1m", config);
54 checkEntriesForSubscriberAndAccessDevice(config);
55 }
56
57 private void checkEntriesForSubscriberAndAccessDevice(BaseConfig config) {
58 List<SubscriberAndDeviceInformation> entries = config.getEntries();
yasin sapli2c93ddb2021-06-11 17:46:26 +030059 assertEquals(4, entries.size());
Matteo Scandolo198aef92020-01-08 00:43:17 +000060 assertTrue(checkEquality(entry1, entries.get(0)));
61 assertTrue(checkEquality(entry2, entries.get(1)));
62 assertTrue(checkEquality(entry5, entries.get(2)));
yasin sapli2c93ddb2021-06-11 17:46:26 +030063 assertTrue(checkEquality(entry6, entries.get(3)));
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000064 }
65
66 @Test
67 public void testLocalMode() throws Exception {
68
69 BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
70
Matteo Scandolo198aef92020-01-08 00:43:17 +000071 checkGetForExisting(ID1, entry1, subscriberService);
72 checkGetForExisting(ID2, entry2, subscriberService);
73 checkGetForExisting(ID5, entry5, subscriberService);
yasin sapli2c93ddb2021-06-11 17:46:26 +030074 checkGetForExisting(ID6, entry6, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000075
Matteo Scandolo198aef92020-01-08 00:43:17 +000076 invalidateId(ID1, subscriberService);
77 checkFromBoth(ID1, entry1, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000078
79 invalidateAll(subscriberService);
Matteo Scandolo198aef92020-01-08 00:43:17 +000080 checkFromBoth(ID2, entry2, subscriberService);
yasin sapli2c93ddb2021-06-11 17:46:26 +030081 checkFromBoth(ID6, entry6, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000082 }
83
84
85 private void checkGetForNonExist(String id, BaseInformationService service) {
86 BaseInformation entry = service.get(id);
87 assertNull(entry);
88 }
89
90 @Test
91 public void testRemoteMode() throws Exception {
Matteo Scandoloc3e53722020-12-08 15:14:53 -080092
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000093 BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
94 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
95 configListener.event(event);
96
Matteo Scandolo198aef92020-01-08 00:43:17 +000097 checkGetForExisting(ID3, entry3, subscriberService);
98 checkGetForExisting(ID4, entry4, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000099
Matteo Scandolo198aef92020-01-08 00:43:17 +0000100 invalidateId(ID3, subscriberService);
101 checkFromBoth(ID3, entry3, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000102
103 invalidateAll(subscriberService);
Matteo Scandolo198aef92020-01-08 00:43:17 +0000104 checkFromBoth(ID4, entry4, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000105 }
106
107 @Test
108 public void testModeSwitch() throws Exception {
109 BaseInformationService<SubscriberAndDeviceInformation> service = sadis.getSubscriberInfoService();
110 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
111 configListener.event(event);
112
Matteo Scandoloc3e53722020-12-08 15:14:53 -0800113 service.clearLocalData();
114
Matteo Scandolo198aef92020-01-08 00:43:17 +0000115 checkGetForExisting(ID3, null, service);
116 checkGetForNonExist(ID1, service);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000117
118 config.init(subject, "sadis-local-mode-test", node("/LocalSubConfig.json"), mapper, delegate);
119 configListener.event(event);
120
Matteo Scandolo198aef92020-01-08 00:43:17 +0000121 checkGetForExisting(ID1, null, service);
122 checkGetForNonExist(ID3, service);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000123 }
124
Matteo Scandoloc3e53722020-12-08 15:14:53 -0800125 // test the hybrid mode (both local and remote data in the config)
126 // ids 1 and 2 are local, others are remote
127 @Test
128 public void testHybridMode() throws Exception {
129 BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
130 config.init(subject, "sadis-hybrid-mode-test", node("/HybridSubConfig.json"), mapper, delegate);
131 configListener.event(event);
132
133 // check that I can fetch from remote
134 checkGetForExisting(ID3, entry3, subscriberService);
135 checkGetForExisting(ID4, entry4, subscriberService);
136
137 // check that I can fetch from local
138 checkGetForExisting(ID1, entry1, subscriberService);
139 checkGetForExisting(ID2, entry2, subscriberService);
140 }
141
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000142 public boolean checkEquality(BaseInformation localEntry, BaseInformation entry) {
143 SubscriberAndDeviceInformation sub = (SubscriberAndDeviceInformation) localEntry;
144 SubscriberAndDeviceInformation other = (SubscriberAndDeviceInformation) localEntry;
145
146 if (other == null) {
147 return false;
148 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000149 if (sub.hardwareIdentifier() == null) {
150 if (other.hardwareIdentifier() != null) {
151 return false;
152 }
153 } else if (!sub.hardwareIdentifier().equals(other.hardwareIdentifier())) {
154 return false;
155 }
156 if (sub.id() == null) {
157 if (other.id() != null) {
158 return false;
159 }
160 } else if (!sub.id().equals(other.id())) {
161 return false;
162 }
163 if (sub.nasPortId() == null) {
164 if (other.nasPortId() != null) {
165 return false;
166 }
167 } else if (!sub.nasPortId().equals(other.nasPortId())) {
168 return false;
169 }
170 if (sub.nasId() == null) {
171 if (other.nasId() != null) {
172 return false;
173 }
174 } else if (!sub.nasId().equals(other.nasId())) {
175 return false;
176 }
177 if (sub.ipAddress() == null) {
178 if (other.ipAddress() != null) {
179 return false;
180 }
181 } else if (!sub.ipAddress().equals(other.ipAddress())) {
182 return false;
183 }
184 if (sub.uplinkPort() != other.uplinkPort()) {
185 return false;
186 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000187 if (sub.slot() != other.slot()) {
188 return false;
189 }
190 if (sub.circuitId() == null) {
191 if (other.circuitId() != null) {
192 return false;
193 }
194 } else if (!sub.circuitId().equals(other.circuitId())) {
195 return false;
196 }
197 if (sub.remoteId() == null) {
198 if (other.remoteId() != null) {
199 return false;
200 }
201 } else if (!sub.remoteId().equals(other.remoteId())) {
202 return false;
203 }
Matteo Scandolo198aef92020-01-08 00:43:17 +0000204 if (sub.uniTagList() == null) {
205 if (other.uniTagList() != null) {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000206 return false;
207 }
Matteo Scandolo198aef92020-01-08 00:43:17 +0000208 } else if (!sub.uniTagList().equals(other.uniTagList())) {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000209 return false;
210 }
211 return true;
212 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000213}