blob: fa689663cdb2d44b863a6074b903950a47cb649b [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 {
89 BaseInformationService<SubscriberAndDeviceInformation> subscriberService = sadis.getSubscriberInfoService();
90 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
91 configListener.event(event);
92
Matteo Scandolo198aef92020-01-08 00:43:17 +000093 checkGetForExisting(ID3, entry3, subscriberService);
94 checkGetForExisting(ID4, entry4, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000095
Matteo Scandolo198aef92020-01-08 00:43:17 +000096 invalidateId(ID3, subscriberService);
97 checkFromBoth(ID3, entry3, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000098
99 invalidateAll(subscriberService);
Matteo Scandolo198aef92020-01-08 00:43:17 +0000100 checkFromBoth(ID4, entry4, subscriberService);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000101 }
102
103 @Test
104 public void testModeSwitch() throws Exception {
105 BaseInformationService<SubscriberAndDeviceInformation> service = sadis.getSubscriberInfoService();
106 config.init(subject, "sadis-remote-mode-test", node("/RemoteConfig.json"), mapper, delegate);
107 configListener.event(event);
108
Matteo Scandolo198aef92020-01-08 00:43:17 +0000109 checkGetForExisting(ID3, null, service);
110 checkGetForNonExist(ID1, service);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000111
112 config.init(subject, "sadis-local-mode-test", node("/LocalSubConfig.json"), mapper, delegate);
113 configListener.event(event);
114
Matteo Scandolo198aef92020-01-08 00:43:17 +0000115 checkGetForExisting(ID1, null, service);
116 checkGetForNonExist(ID3, service);
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000117 }
118
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000119 public boolean checkEquality(BaseInformation localEntry, BaseInformation entry) {
120 SubscriberAndDeviceInformation sub = (SubscriberAndDeviceInformation) localEntry;
121 SubscriberAndDeviceInformation other = (SubscriberAndDeviceInformation) localEntry;
122
123 if (other == null) {
124 return false;
125 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000126 if (sub.hardwareIdentifier() == null) {
127 if (other.hardwareIdentifier() != null) {
128 return false;
129 }
130 } else if (!sub.hardwareIdentifier().equals(other.hardwareIdentifier())) {
131 return false;
132 }
133 if (sub.id() == null) {
134 if (other.id() != null) {
135 return false;
136 }
137 } else if (!sub.id().equals(other.id())) {
138 return false;
139 }
140 if (sub.nasPortId() == null) {
141 if (other.nasPortId() != null) {
142 return false;
143 }
144 } else if (!sub.nasPortId().equals(other.nasPortId())) {
145 return false;
146 }
147 if (sub.nasId() == null) {
148 if (other.nasId() != null) {
149 return false;
150 }
151 } else if (!sub.nasId().equals(other.nasId())) {
152 return false;
153 }
154 if (sub.ipAddress() == null) {
155 if (other.ipAddress() != null) {
156 return false;
157 }
158 } else if (!sub.ipAddress().equals(other.ipAddress())) {
159 return false;
160 }
161 if (sub.uplinkPort() != other.uplinkPort()) {
162 return false;
163 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000164 if (sub.slot() != other.slot()) {
165 return false;
166 }
167 if (sub.circuitId() == null) {
168 if (other.circuitId() != null) {
169 return false;
170 }
171 } else if (!sub.circuitId().equals(other.circuitId())) {
172 return false;
173 }
174 if (sub.remoteId() == null) {
175 if (other.remoteId() != null) {
176 return false;
177 }
178 } else if (!sub.remoteId().equals(other.remoteId())) {
179 return false;
180 }
Matteo Scandolo198aef92020-01-08 00:43:17 +0000181 if (sub.uniTagList() == null) {
182 if (other.uniTagList() != null) {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000183 return false;
184 }
Matteo Scandolo198aef92020-01-08 00:43:17 +0000185 } else if (!sub.uniTagList().equals(other.uniTagList())) {
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000186 return false;
187 }
188 return true;
189 }
Gamze Abaka1e5ccf52018-07-02 11:59:03 +0000190}