blob: af63004213b2fbc972a01d756c7ec19051d32828 [file] [log] [blame]
Matteo Scandolo962a6ad2018-12-11 15:39:42 -08001/*
2 * Copyright 2016-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.olt.impl;
17
18import static org.junit.Assert.assertEquals;
19
20import java.util.Set;
Ilayda Ozdemir90a93622021-02-25 09:40:58 +000021
22import com.google.common.collect.Maps;
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080023import org.junit.Before;
24import org.junit.Test;
25
26import org.onlab.packet.ChassisId;
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080027import org.onosproject.net.AnnotationKeys;
28import org.onosproject.net.Annotations;
29import org.onosproject.net.ConnectPoint;
30import org.onosproject.net.DefaultAnnotations;
31import org.onosproject.net.DefaultDevice;
32import org.onosproject.net.Device;
33import org.onosproject.net.DeviceId;
34import org.onosproject.net.Element;
35import org.onosproject.net.Port;
36import org.onosproject.net.PortNumber;
37import org.onosproject.net.device.DeviceServiceAdapter;
38import org.onosproject.net.provider.ProviderId;
39import org.opencord.sadis.SubscriberAndDeviceInformation;
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080040import org.slf4j.Logger;
41import org.slf4j.LoggerFactory;
42
Andrea Campanellacbbb7952019-11-25 06:38:41 +000043public class OltTest extends TestBase {
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080044 private final Logger log = LoggerFactory.getLogger(getClass());
45 private Olt olt;
46
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080047
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080048 private static final String SCHEME_NAME = "olt";
49 private static final DefaultAnnotations DEVICE_ANNOTATIONS = DefaultAnnotations.builder()
50 .set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase()).build();
51
52 @Before
53 public void setUp() {
54 olt = new Olt();
55 olt.deviceService = new MockDeviceService();
Gamze Abaka641fc072018-09-04 09:16:27 +000056 olt.sadisService = new MockSadisService();
57 olt.subsService = olt.sadisService.getSubscriberInfoService();
Ilayda Ozdemir90a93622021-02-25 09:40:58 +000058 olt.pendingSubscribersForDevice = Maps.newConcurrentMap();
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080059 }
60
61 /**
62 * Tests that the getSubscriber method does throw a NullPointerException with a meaningful message.
63 */
64 @Test
65 public void testGetSubscriberError() {
66 ConnectPoint cp = ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1);
67 try {
68 olt.getSubscriber(cp);
69 } catch (NullPointerException e) {
70 assertEquals(e.getMessage(), "Invalid connect point");
71 }
72 }
73
74 /**
75 * Tests that the getSubscriber method returns Subscriber informations.
76 */
77 @Test
78 public void testGetSubscriber() {
79 ConnectPoint cp = ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 2);
80
Ilayda Ozdemir90a93622021-02-25 09:40:58 +000081 SubscriberAndDeviceInformation s = olt.getSubscriber(cp);
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080082
83 assertEquals(s.circuitId(), CLIENT_CIRCUIT_ID);
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080084 assertEquals(s.nasPortId(), CLIENT_NAS_PORT_ID);
85 }
86
87 private class MockDevice extends DefaultDevice {
88
89 public MockDevice(ProviderId providerId, DeviceId id, Type type,
90 String manufacturer, String hwVersion, String swVersion,
91 String serialNumber, ChassisId chassisId, Annotations... annotations) {
92 super(providerId, id, type, manufacturer, hwVersion, swVersion, serialNumber,
Andrea Campanellacbbb7952019-11-25 06:38:41 +000093 chassisId, annotations);
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080094 }
95 }
96
97 private class MockDeviceService extends DeviceServiceAdapter {
98
99 private ProviderId providerId = new ProviderId("of", "foo");
100 private final Device device1 = new MockDevice(providerId, DEVICE_ID_1, Device.Type.SWITCH,
Andrea Campanellacbbb7952019-11-25 06:38:41 +0000101 "foo.inc", "0", "0", OLT_DEV_ID, new ChassisId(),
102 DEVICE_ANNOTATIONS);
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800103
104 @Override
105 public Device getDevice(DeviceId devId) {
106 return device1;
107
108 }
109
110 @Override
111 public Port getPort(ConnectPoint cp) {
112 log.info("Looking up port {}", cp.port().toString());
113 if (cp.port().toString().equals("1")) {
114 return null;
115 }
116 return new MockPort();
117 }
118 }
119
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000120 private class MockPort implements Port {
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800121
122 @Override
123 public boolean isEnabled() {
124 return true;
125 }
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000126
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800127 @Override
128 public long portSpeed() {
129 return 1000;
130 }
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000131
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800132 @Override
133 public Element element() {
134 return null;
135 }
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000136
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800137 @Override
138 public PortNumber number() {
139 return null;
140 }
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000141
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800142 @Override
143 public Annotations annotations() {
144 return new MockAnnotations();
145 }
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000146
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800147 @Override
148 public Type type() {
149 return Port.Type.FIBER;
150 }
151
152 private class MockAnnotations implements Annotations {
153
154 @Override
155 public String value(String val) {
156 return "BRCM12345678";
157 }
Ilayda Ozdemir90a93622021-02-25 09:40:58 +0000158
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800159 @Override
160 public Set<String> keys() {
161 return null;
162 }
163 }
164 }
165
Gamze Abaka641fc072018-09-04 09:16:27 +0000166
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800167}