blob: e618e3ba13be3b937d9c2f224086bfe1247b4e6b [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
19import com.google.common.collect.Sets;
slowr577f3222017-08-28 10:49:08 -070020import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
slowr13fa5b02017-08-08 16:32:31 -070025import org.onlab.packet.VlanId;
slowr577f3222017-08-28 10:49:08 -070026import org.onosproject.net.AnnotationKeys;
27import org.onosproject.net.DefaultAnnotations;
28import org.onosproject.net.Host;
29import org.onosproject.net.HostId;
30import org.onosproject.net.HostLocation;
31import org.onosproject.net.PortNumber;
32import org.onosproject.net.SparseAnnotations;
slowr13fa5b02017-08-08 16:32:31 -070033import org.onosproject.net.host.DefaultHostDescription;
34import org.onosproject.net.host.HostProvider;
35import org.onosproject.net.host.HostProviderRegistry;
36import org.onosproject.net.host.HostProviderService;
37import 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.XranHostListener;
41import org.onosproject.xran.asn1lib.api.ECGI;
42import org.onosproject.xran.impl.entities.RnibUe;
slowr13fa5b02017-08-08 16:32:31 -070043import org.slf4j.Logger;
44
45import java.util.Set;
46
slowr577f3222017-08-28 10:49:08 -070047import static org.onosproject.net.DeviceId.deviceId;
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -080048import static org.onosproject.xran.impl.entities.RnibCell.uri;
slowr13fa5b02017-08-08 16:32:31 -070049import static org.slf4j.LoggerFactory.getLogger;
50
51/**
slowr577f3222017-08-28 10:49:08 -070052 * UE Provider.
slowr13fa5b02017-08-08 16:32:31 -070053 */
slowr13fa5b02017-08-08 16:32:31 -070054@Component(immediate = true)
55public class UeProvider extends AbstractProvider implements HostProvider {
56
57 private static final Logger log = getLogger(UeProvider.class);
58 private final InternalHostListener listener = new InternalHostListener();
59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
60 private HostProviderRegistry providerRegistry;
61 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -080062 private XranService controller;
slowr13fa5b02017-08-08 16:32:31 -070063 private HostProviderService providerService;
64
65 public UeProvider() {
slowrd337c932017-08-18 13:54:02 -070066 super(new ProviderId("xran", "org.onosproject.providers.ue"));
slowr13fa5b02017-08-08 16:32:31 -070067 }
68
69 @Activate
70 public void activate() {
71 providerService = providerRegistry.register(this);
72 controller.addListener(listener);
73
74 log.info("XRAN Host Provider Started");
75 }
76
77 @Deactivate
78 public void deactivate() {
79 controller.removeListener(listener);
80 providerRegistry.unregister(this);
81
82 providerService = null;
83 log.info("XRAN Host Provider Stopped");
84 }
85
86 @Override
87 public void triggerProbe(Host host) {
88
89 }
90
slowr577f3222017-08-28 10:49:08 -070091 /**
92 * Internal host listener.
93 */
slowr13fa5b02017-08-08 16:32:31 -070094 class InternalHostListener implements XranHostListener {
95
96 @Override
97 public void hostAdded(RnibUe ue, Set<ECGI> ecgiSet) {
98 if (providerService == null) {
99 return;
100 }
101
102 if (ue == null) {
slowrd337c932017-08-18 13:54:02 -0700103 log.error("UE is not found");
slowr13fa5b02017-08-08 16:32:31 -0700104 return;
105 }
106
107 try {
108 Set<HostLocation> hostLocations = Sets.newConcurrentHashSet();
109
slowr577f3222017-08-28 10:49:08 -0700110 ecgiSet.forEach(ecgi -> hostLocations
111 .add(new HostLocation(deviceId(uri(ecgi)),
112 PortNumber.portNumber(0), 0)));
slowr13fa5b02017-08-08 16:32:31 -0700113
114 SparseAnnotations annotations = DefaultAnnotations.builder()
slowrc86750e2017-08-22 17:26:47 -0700115 .set(AnnotationKeys.NAME, "UE " + ue.getId())
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -0800116 .set(AnnotationKeys.UI_TYPE, "mobile")
slowr13fa5b02017-08-08 16:32:31 -0700117 .build();
118
slowr577f3222017-08-28 10:49:08 -0700119 // Host ID is calculated from UE ID with some hacky function to represent a MAC address.
slowr13fa5b02017-08-08 16:32:31 -0700120 DefaultHostDescription desc = new DefaultHostDescription(
121 ue.getHostId().mac(),
122 VlanId.vlanId(VlanId.UNTAGGED),
123 hostLocations,
124 Sets.newConcurrentHashSet(),
125 true,
126 annotations
127 );
128
129 providerService.hostDetected(ue.getHostId(), desc, false);
130 } catch (Exception e) {
131 log.warn(e.getMessage());
132 e.printStackTrace();
133 }
134 }
135
136 @Override
137 public void hostRemoved(HostId id) {
138 providerService.hostVanished(id);
139 }
140 }
141}