blob: 1fbfbcdb9067ac1550b58aa7b9d5b5cc5dcc2754 [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();
59 assertEquals(3, 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)));
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000063 }
64
65 @Test
66 public void testLocalMode() throws Exception {
67
68 BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
69
Matteo Scandolo198aef92020-01-08 00:43:17 +000070 checkGetForExisting(ID1, entry1, subscriberService);
71 checkGetForExisting(ID2, entry2, subscriberService);
72 checkGetForExisting(ID5, entry5, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000073
Matteo Scandolo198aef92020-01-08 00:43:17 +000074 invalidateId(ID1, subscriberService);
75 checkFromBoth(ID1, entry1, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000076
77 invalidateAll(subscriberService);
Matteo Scandolo198aef92020-01-08 00:43:17 +000078 checkFromBoth(ID2, entry2, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000079 }
80
81
82 private void checkGetForNonExist(String id, BaseInformationService service) {
83 BaseInformation entry = service.get(id);
84 assertNull(entry);
85 }
86
87 @Test
88 public void testRemoteMode() throws Exception {
Matteo Scandoloc3e53722020-12-08 15:14:53 -080089
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000090 BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
91 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
92 configListener.event(event);
93
Matteo Scandolo198aef92020-01-08 00:43:17 +000094 checkGetForExisting(ID3, entry3, subscriberService);
95 checkGetForExisting(ID4, entry4, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000096
Matteo Scandolo198aef92020-01-08 00:43:17 +000097 invalidateId(ID3, subscriberService);
98 checkFromBoth(ID3, entry3, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000099
100 invalidateAll(subscriberService);
Matteo Scandolo198aef92020-01-08 00:43:17 +0000101 checkFromBoth(ID4, entry4, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000102 }
103
104 @Test
105 public void testModeSwitch() throws Exception {
106 BaseInformationService<SubscriberAndDeviceInformation> service = sadis.getSubscriberInfoService();
107 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
108 configListener.event(event);
109
Matteo Scandoloc3e53722020-12-08 15:14:53 -0800110 service.clearLocalData();
111
Matteo Scandolo198aef92020-01-08 00:43:17 +0000112 checkGetForExisting(ID3, null, service);
113 checkGetForNonExist(ID1, service);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000114
115 config.init(subject, "sadis-local-mode-test", node("/LocalSubConfig.json"), mapper, delegate);
116 configListener.event(event);
117
Matteo Scandolo198aef92020-01-08 00:43:17 +0000118 checkGetForExisting(ID1, null, service);
119 checkGetForNonExist(ID3, service);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000120 }
121
Matteo Scandoloc3e53722020-12-08 15:14:53 -0800122 // test the hybrid mode (both local and remote data in the config)
123 // ids 1 and 2 are local, others are remote
124 @Test
125 public void testHybridMode() throws Exception {
126 BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
127 config.init(subject, "sadis-hybrid-mode-test", node("/HybridSubConfig.json"), mapper, delegate);
128 configListener.event(event);
129
130 // check that I can fetch from remote
131 checkGetForExisting(ID3, entry3, subscriberService);
132 checkGetForExisting(ID4, entry4, subscriberService);
133
134 // check that I can fetch from local
135 checkGetForExisting(ID1, entry1, subscriberService);
136 checkGetForExisting(ID2, entry2, subscriberService);
137 }
138
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000139 public boolean checkEquality(BaseInformation localEntry, BaseInformation entry) {
140 SubscriberAndDeviceInformation sub = (SubscriberAndDeviceInformation) localEntry;
141 SubscriberAndDeviceInformation other = (SubscriberAndDeviceInformation) localEntry;
142
143 if (other == null) {
144 return false;
145 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000146 if (sub.hardwareIdentifier() == null) {
147 if (other.hardwareIdentifier() != null) {
148 return false;
149 }
150 } else if (!sub.hardwareIdentifier().equals(other.hardwareIdentifier())) {
151 return false;
152 }
153 if (sub.id() == null) {
154 if (other.id() != null) {
155 return false;
156 }
157 } else if (!sub.id().equals(other.id())) {
158 return false;
159 }
160 if (sub.nasPortId() == null) {
161 if (other.nasPortId() != null) {
162 return false;
163 }
164 } else if (!sub.nasPortId().equals(other.nasPortId())) {
165 return false;
166 }
167 if (sub.nasId() == null) {
168 if (other.nasId() != null) {
169 return false;
170 }
171 } else if (!sub.nasId().equals(other.nasId())) {
172 return false;
173 }
174 if (sub.ipAddress() == null) {
175 if (other.ipAddress() != null) {
176 return false;
177 }
178 } else if (!sub.ipAddress().equals(other.ipAddress())) {
179 return false;
180 }
181 if (sub.uplinkPort() != other.uplinkPort()) {
182 return false;
183 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000184 if (sub.slot() != other.slot()) {
185 return false;
186 }
187 if (sub.circuitId() == null) {
188 if (other.circuitId() != null) {
189 return false;
190 }
191 } else if (!sub.circuitId().equals(other.circuitId())) {
192 return false;
193 }
194 if (sub.remoteId() == null) {
195 if (other.remoteId() != null) {
196 return false;
197 }
198 } else if (!sub.remoteId().equals(other.remoteId())) {
199 return false;
200 }
Matteo Scandolo198aef92020-01-08 00:43:17 +0000201 if (sub.uniTagList() == null) {
202 if (other.uniTagList() != null) {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000203 return false;
204 }
Matteo Scandolo198aef92020-01-08 00:43:17 +0000205 } else if (!sub.uniTagList().equals(other.uniTagList())) {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000206 return false;
207 }
208 return true;
209 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000210}