blob: f89fe0920cab876cea22641dbe69b204f117cd61 [file] [log] [blame]
slowr13fa5b02017-08-08 16:32:31 -07001/*
2 * Copyright 2015-present Open Networking Laboratory
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
17package org.onosproject.xran.providers;
18
19import org.apache.felix.scr.annotations.*;
20import org.onlab.packet.ChassisId;
21import org.onosproject.net.*;
22import org.onosproject.net.device.*;
23import org.onosproject.net.provider.AbstractProvider;
24import org.onosproject.net.provider.ProviderId;
25import org.onosproject.xran.controller.XranController;
26import org.onosproject.xran.entities.RnibCell;
27import org.slf4j.Logger;
28
29import static org.onosproject.net.DeviceId.deviceId;
30import static org.onosproject.xran.entities.RnibCell.*;
31import static org.slf4j.LoggerFactory.getLogger;
32
33
34/**
35 * Created by dimitris on 7/27/17.
36 */
37
38@Component(immediate = true)
39public class CellDeviceProvider extends AbstractProvider implements DeviceProvider {
40
41 private static final Logger log = getLogger(CellDeviceProvider.class);
42 private final InternalDeviceListener listener = new InternalDeviceListener();
43 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
44 protected DeviceProviderRegistry providerRegistry;
45 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
46 protected XranController controller;
47 private DeviceProviderService providerService;
48
49 public CellDeviceProvider() {
50 super(new ProviderId("xran", "org.onosproject.provider.xran"));
51 }
52
53 @Activate
54 public void activate() {
55 providerService = providerRegistry.register(this);
56 controller.addListener(listener);
57
58 log.info("XRAN Device Provider Started");
59 }
60
61 @Deactivate
62 public void deactivate() {
63 controller.removeListener(listener);
64 providerRegistry.unregister(this);
65
66 providerService = null;
67 log.info("XRAN Device Provider Stopped");
68 }
69
70 @Override
71 public void triggerProbe(DeviceId deviceId) {
72
73 }
74
75 @Override
76 public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
77
78 }
79
80 @Override
81 public boolean isReachable(DeviceId deviceId) {
82 return true;
83 }
84
85 @Override
86 public void changePortState(DeviceId deviceId, PortNumber portNumber, boolean enable) {
87
88 }
89
90 private class InternalDeviceListener implements XranDeviceListener {
91
92 @Override
93 public void deviceAdded(RnibCell cell) {
94 if (providerService == null) {
95 return;
96 }
97
98 DeviceId id = deviceId(uri(cell.getEcgi()));
99
100 ChassisId cId = new ChassisId(id.hashCode());
101
102 Device.Type type = Device.Type.OTHER;
103 SparseAnnotations annotations = DefaultAnnotations.builder()
104 .set(AnnotationKeys.NAME, "eNodeB #" + cell.getEcgi().getEUTRANcellIdentifier())
105 .set(AnnotationKeys.PROTOCOL, "SCTP")
106 .set(AnnotationKeys.CHANNEL_ID, "xxx")
107 .set(AnnotationKeys.MANAGEMENT_ADDRESS, "127.0.0.1")
108 .build();
109
110 DeviceDescription descBase =
111 new DefaultDeviceDescription(id.uri(), type,
112 "xran", "0.1", "0.1", id.uri().toString(),
113 cId);
114 DeviceDescription desc = new DefaultDeviceDescription(descBase, annotations);
115
116 providerService.deviceConnected(id, desc);
117 }
118
119 @Override
120 public void deviceRemoved(DeviceId id) {
121 providerService.deviceDisconnected(id);
122 }
123 }
124}