blob: a0a5809af9c9cbbd0e47b0afdeb19e1b74446399 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
slowr577f3222017-08-28 10:49:08 -07002 * Copyright 2015-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
17package org.onosproject.xran.providers;
18
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;
39import org.onosproject.xran.controller.XranController;
40import org.onosproject.xran.entities.RnibCell;
41import org.slf4j.Logger;
42
43import static org.onosproject.net.DeviceId.deviceId;
slowr577f3222017-08-28 10:49:08 -070044import static org.onosproject.xran.entities.RnibCell.uri;
slowr13fa5b02017-08-08 16:32:31 -070045import static org.slf4j.LoggerFactory.getLogger;
46
slowr13fa5b02017-08-08 16:32:31 -070047/**
slowr577f3222017-08-28 10:49:08 -070048 * Cell device provider.
slowr13fa5b02017-08-08 16:32:31 -070049 */
slowr13fa5b02017-08-08 16:32:31 -070050@Component(immediate = true)
51public class CellDeviceProvider extends AbstractProvider implements DeviceProvider {
52
53 private static final Logger log = getLogger(CellDeviceProvider.class);
54 private final InternalDeviceListener listener = new InternalDeviceListener();
55 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
56 protected DeviceProviderRegistry providerRegistry;
57 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 protected XranController controller;
59 private DeviceProviderService providerService;
60
61 public CellDeviceProvider() {
slowrd337c932017-08-18 13:54:02 -070062 super(new ProviderId("xran", "org.onosproject.providers.cell"));
slowr13fa5b02017-08-08 16:32:31 -070063 }
64
65 @Activate
66 public void activate() {
67 providerService = providerRegistry.register(this);
68 controller.addListener(listener);
69
70 log.info("XRAN Device Provider Started");
71 }
72
73 @Deactivate
74 public void deactivate() {
75 controller.removeListener(listener);
76 providerRegistry.unregister(this);
77
78 providerService = null;
79 log.info("XRAN Device Provider Stopped");
80 }
81
82 @Override
83 public void triggerProbe(DeviceId deviceId) {
84
85 }
86
87 @Override
88 public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
89
90 }
91
92 @Override
93 public boolean isReachable(DeviceId deviceId) {
94 return true;
95 }
96
97 @Override
98 public void changePortState(DeviceId deviceId, PortNumber portNumber, boolean enable) {
99
100 }
101
slowr577f3222017-08-28 10:49:08 -0700102 /**
103 * Internal device listener.
104 */
slowr13fa5b02017-08-08 16:32:31 -0700105 private class InternalDeviceListener implements XranDeviceListener {
106
107 @Override
108 public void deviceAdded(RnibCell cell) {
109 if (providerService == null) {
110 return;
111 }
112
slowr577f3222017-08-28 10:49:08 -0700113 // use ECGI as device ID URI
slowr13fa5b02017-08-08 16:32:31 -0700114 DeviceId id = deviceId(uri(cell.getEcgi()));
115
116 ChassisId cId = new ChassisId(id.hashCode());
117
118 Device.Type type = Device.Type.OTHER;
119 SparseAnnotations annotations = DefaultAnnotations.builder()
slowrd337c932017-08-18 13:54:02 -0700120 .set(AnnotationKeys.NAME, "eNodeB " + cell.getEcgi().getEUTRANcellIdentifier())
slowr13fa5b02017-08-08 16:32:31 -0700121 .set(AnnotationKeys.PROTOCOL, "SCTP")
122 .set(AnnotationKeys.CHANNEL_ID, "xxx")
123 .set(AnnotationKeys.MANAGEMENT_ADDRESS, "127.0.0.1")
124 .build();
125
126 DeviceDescription descBase =
127 new DefaultDeviceDescription(id.uri(), type,
128 "xran", "0.1", "0.1", id.uri().toString(),
129 cId);
130 DeviceDescription desc = new DefaultDeviceDescription(descBase, annotations);
131
132 providerService.deviceConnected(id, desc);
133 }
134
135 @Override
136 public void deviceRemoved(DeviceId id) {
137 providerService.deviceDisconnected(id);
138 }
139 }
140}