Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.opencord.olt.impl; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | |
| 20 | import java.util.Set; |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | |
| 24 | import org.onlab.packet.ChassisId; |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 25 | import org.onosproject.net.AnnotationKeys; |
| 26 | import org.onosproject.net.Annotations; |
| 27 | import org.onosproject.net.ConnectPoint; |
| 28 | import org.onosproject.net.DefaultAnnotations; |
| 29 | import org.onosproject.net.DefaultDevice; |
| 30 | import org.onosproject.net.Device; |
| 31 | import org.onosproject.net.DeviceId; |
| 32 | import org.onosproject.net.Element; |
| 33 | import org.onosproject.net.Port; |
| 34 | import org.onosproject.net.PortNumber; |
| 35 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 36 | import org.onosproject.net.provider.ProviderId; |
| 37 | import org.opencord.sadis.SubscriberAndDeviceInformation; |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 38 | import org.slf4j.Logger; |
| 39 | import org.slf4j.LoggerFactory; |
| 40 | |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 41 | public class OltTest extends TestBase { |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 42 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 43 | private Olt olt; |
| 44 | |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 45 | |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 46 | 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 Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 54 | olt.sadisService = new MockSadisService(); |
| 55 | olt.subsService = olt.sadisService.getSubscriberInfoService(); |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 56 | } |
| 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 Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 81 | 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, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 90 | chassisId, annotations); |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 91 | } |
| 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, |
Andrea Campanella | cbbb795 | 2019-11-25 06:38:41 +0000 | [diff] [blame] | 98 | "foo.inc", "0", "0", OLT_DEV_ID, new ChassisId(), |
| 99 | DEVICE_ANNOTATIONS); |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 100 | |
| 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 Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 157 | |
| 158 | |
Gamze Abaka | 641fc07 | 2018-09-04 09:16:27 +0000 | [diff] [blame] | 159 | |
Matteo Scandolo | 962a6ad | 2018-12-11 15:39:42 -0800 | [diff] [blame] | 160 | |
| 161 | } |