blob: c417590c8ad64533df8ddc0e48e619585a6f75cc [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;
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080021import org.junit.Before;
22import org.junit.Test;
23
24import org.onlab.packet.ChassisId;
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080025import org.onosproject.net.AnnotationKeys;
26import org.onosproject.net.Annotations;
27import org.onosproject.net.ConnectPoint;
28import org.onosproject.net.DefaultAnnotations;
29import org.onosproject.net.DefaultDevice;
30import org.onosproject.net.Device;
31import org.onosproject.net.DeviceId;
32import org.onosproject.net.Element;
33import org.onosproject.net.Port;
34import org.onosproject.net.PortNumber;
35import org.onosproject.net.device.DeviceServiceAdapter;
36import org.onosproject.net.provider.ProviderId;
37import org.opencord.sadis.SubscriberAndDeviceInformation;
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080038import org.slf4j.Logger;
39import org.slf4j.LoggerFactory;
40
Gamze Abaka1b7816e2019-11-25 06:38:41 +000041public class OltTest extends TestBase {
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080042 private final Logger log = LoggerFactory.getLogger(getClass());
43 private Olt olt;
44
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080045
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080046 private static final String SCHEME_NAME = "olt";
47 private static final DefaultAnnotations DEVICE_ANNOTATIONS = DefaultAnnotations.builder()
48 .set(AnnotationKeys.PROTOCOL, SCHEME_NAME.toUpperCase()).build();
49
50 @Before
51 public void setUp() {
52 olt = new Olt();
53 olt.deviceService = new MockDeviceService();
Gamze Abaka641fc072018-09-04 09:16:27 +000054 olt.sadisService = new MockSadisService();
55 olt.subsService = olt.sadisService.getSubscriberInfoService();
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080056 }
57
58 /**
59 * Tests that the getSubscriber method does throw a NullPointerException with a meaningful message.
60 */
61 @Test
62 public void testGetSubscriberError() {
63 ConnectPoint cp = ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 1);
64 try {
65 olt.getSubscriber(cp);
66 } catch (NullPointerException e) {
67 assertEquals(e.getMessage(), "Invalid connect point");
68 }
69 }
70
71 /**
72 * Tests that the getSubscriber method returns Subscriber informations.
73 */
74 @Test
75 public void testGetSubscriber() {
76 ConnectPoint cp = ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + 2);
77
78 SubscriberAndDeviceInformation s = olt.getSubscriber(cp);
79
80 assertEquals(s.circuitId(), CLIENT_CIRCUIT_ID);
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080081 assertEquals(s.nasPortId(), CLIENT_NAS_PORT_ID);
82 }
83
84 private class MockDevice extends DefaultDevice {
85
86 public MockDevice(ProviderId providerId, DeviceId id, Type type,
87 String manufacturer, String hwVersion, String swVersion,
88 String serialNumber, ChassisId chassisId, Annotations... annotations) {
89 super(providerId, id, type, manufacturer, hwVersion, swVersion, serialNumber,
Gamze Abaka1b7816e2019-11-25 06:38:41 +000090 chassisId, annotations);
Matteo Scandolo962a6ad2018-12-11 15:39:42 -080091 }
92 }
93
94 private class MockDeviceService extends DeviceServiceAdapter {
95
96 private ProviderId providerId = new ProviderId("of", "foo");
97 private final Device device1 = new MockDevice(providerId, DEVICE_ID_1, Device.Type.SWITCH,
Gamze Abaka1b7816e2019-11-25 06:38:41 +000098 "foo.inc", "0", "0", OLT_DEV_ID, new ChassisId(),
99 DEVICE_ANNOTATIONS);
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800100
101 @Override
102 public Device getDevice(DeviceId devId) {
103 return device1;
104
105 }
106
107 @Override
108 public Port getPort(ConnectPoint cp) {
109 log.info("Looking up port {}", cp.port().toString());
110 if (cp.port().toString().equals("1")) {
111 return null;
112 }
113 return new MockPort();
114 }
115 }
116
117 private class MockPort implements Port {
118
119 @Override
120 public boolean isEnabled() {
121 return true;
122 }
123 @Override
124 public long portSpeed() {
125 return 1000;
126 }
127 @Override
128 public Element element() {
129 return null;
130 }
131 @Override
132 public PortNumber number() {
133 return null;
134 }
135 @Override
136 public Annotations annotations() {
137 return new MockAnnotations();
138 }
139 @Override
140 public Type type() {
141 return Port.Type.FIBER;
142 }
143
144 private class MockAnnotations implements Annotations {
145
146 @Override
147 public String value(String val) {
148 return "BRCM12345678";
149 }
150 @Override
151 public Set<String> keys() {
152 return null;
153 }
154 }
155 }
156
Gamze Abaka641fc072018-09-04 09:16:27 +0000157
158
Gamze Abaka641fc072018-09-04 09:16:27 +0000159
Matteo Scandolo962a6ad2018-12-11 15:39:42 -0800160
161}