blob: 33b49d639da78508a7413250f8302367bbdd89ac [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08002 * Copyright 2017-present Open Networking Foundation
slowr13fa5b02017-08-08 16:32:31 -07003 *
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
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -080017package org.onosproject.xran.impl.providers;
slowr13fa5b02017-08-08 16:32:31 -070018
slowr577f3222017-08-28 10:49:08 -070019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Reference;
23import org.apache.felix.scr.annotations.ReferenceCardinality;
slowr13fa5b02017-08-08 16:32:31 -070024import org.onlab.packet.ChassisId;
slowr577f3222017-08-28 10:49:08 -070025import org.onosproject.net.AnnotationKeys;
26import org.onosproject.net.DefaultAnnotations;
27import org.onosproject.net.Device;
28import org.onosproject.net.DeviceId;
29import org.onosproject.net.MastershipRole;
30import org.onosproject.net.PortNumber;
31import org.onosproject.net.SparseAnnotations;
32import org.onosproject.net.device.DefaultDeviceDescription;
33import org.onosproject.net.device.DeviceDescription;
34import org.onosproject.net.device.DeviceProvider;
35import org.onosproject.net.device.DeviceProviderRegistry;
36import org.onosproject.net.device.DeviceProviderService;
slowr13fa5b02017-08-08 16:32:31 -070037import org.onosproject.net.provider.AbstractProvider;
38import org.onosproject.net.provider.ProviderId;
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -080039import org.onosproject.xran.XranService;
40import org.onosproject.xran.XranDeviceListener;
41import org.onosproject.xran.impl.entities.RnibCell;
slowr13fa5b02017-08-08 16:32:31 -070042import org.slf4j.Logger;
43
44import static org.onosproject.net.DeviceId.deviceId;
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -080045import static org.onosproject.xran.impl.entities.RnibCell.uri;
slowr13fa5b02017-08-08 16:32:31 -070046import static org.slf4j.LoggerFactory.getLogger;
47
slowr13fa5b02017-08-08 16:32:31 -070048/**
slowr577f3222017-08-28 10:49:08 -070049 * Cell device provider.
slowr13fa5b02017-08-08 16:32:31 -070050 */
slowr13fa5b02017-08-08 16:32:31 -070051@Component(immediate = true)
52public class CellDeviceProvider extends AbstractProvider implements DeviceProvider {
53
54 private static final Logger log = getLogger(CellDeviceProvider.class);
55 private final InternalDeviceListener listener = new InternalDeviceListener();
56 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
57 protected DeviceProviderRegistry providerRegistry;
58 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -080059 protected XranService controller;
slowr13fa5b02017-08-08 16:32:31 -070060 private DeviceProviderService providerService;
61
62 public CellDeviceProvider() {
slowrd337c932017-08-18 13:54:02 -070063 super(new ProviderId("xran", "org.onosproject.providers.cell"));
slowr13fa5b02017-08-08 16:32:31 -070064 }
65
66 @Activate
67 public void activate() {
68 providerService = providerRegistry.register(this);
69 controller.addListener(listener);
70
71 log.info("XRAN Device Provider Started");
72 }
73
74 @Deactivate
75 public void deactivate() {
76 controller.removeListener(listener);
77 providerRegistry.unregister(this);
78
79 providerService = null;
80 log.info("XRAN Device Provider Stopped");
81 }
82
83 @Override
84 public void triggerProbe(DeviceId deviceId) {
85
86 }
87
88 @Override
89 public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
90
91 }
92
93 @Override
94 public boolean isReachable(DeviceId deviceId) {
95 return true;
96 }
97
98 @Override
99 public void changePortState(DeviceId deviceId, PortNumber portNumber, boolean enable) {
100
101 }
102
slowr577f3222017-08-28 10:49:08 -0700103 /**
104 * Internal device listener.
105 */
slowr13fa5b02017-08-08 16:32:31 -0700106 private class InternalDeviceListener implements XranDeviceListener {
107
108 @Override
109 public void deviceAdded(RnibCell cell) {
110 if (providerService == null) {
111 return;
112 }
113
slowr577f3222017-08-28 10:49:08 -0700114 // use ECGI as device ID URI
slowr13fa5b02017-08-08 16:32:31 -0700115 DeviceId id = deviceId(uri(cell.getEcgi()));
116
117 ChassisId cId = new ChassisId(id.hashCode());
118
119 Device.Type type = Device.Type.OTHER;
120 SparseAnnotations annotations = DefaultAnnotations.builder()
slowrd337c932017-08-18 13:54:02 -0700121 .set(AnnotationKeys.NAME, "eNodeB " + cell.getEcgi().getEUTRANcellIdentifier())
slowr13fa5b02017-08-08 16:32:31 -0700122 .set(AnnotationKeys.PROTOCOL, "SCTP")
123 .set(AnnotationKeys.CHANNEL_ID, "xxx")
124 .set(AnnotationKeys.MANAGEMENT_ADDRESS, "127.0.0.1")
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -0800125 .set(AnnotationKeys.UI_TYPE, "basestation")
slowr13fa5b02017-08-08 16:32:31 -0700126 .build();
127
128 DeviceDescription descBase =
129 new DefaultDeviceDescription(id.uri(), type,
130 "xran", "0.1", "0.1", id.uri().toString(),
131 cId);
132 DeviceDescription desc = new DefaultDeviceDescription(descBase, annotations);
133
134 providerService.deviceConnected(id, desc);
135 }
136
137 @Override
138 public void deviceRemoved(DeviceId id) {
139 providerService.deviceDisconnected(id);
140 }
141 }
142}