slowr | 13fa5b0 | 2017-08-08 16:32:31 -0700 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.xran.providers; |
| 18 | |
| 19 | import com.google.common.collect.Sets; |
| 20 | import org.apache.felix.scr.annotations.*; |
| 21 | import org.onlab.packet.VlanId; |
| 22 | import org.onosproject.net.*; |
| 23 | import org.onosproject.net.host.DefaultHostDescription; |
| 24 | import org.onosproject.net.host.HostProvider; |
| 25 | import org.onosproject.net.host.HostProviderRegistry; |
| 26 | import org.onosproject.net.host.HostProviderService; |
| 27 | import org.onosproject.net.provider.AbstractProvider; |
| 28 | import org.onosproject.net.provider.ProviderId; |
| 29 | import org.onosproject.xran.codecs.api.ECGI; |
| 30 | import org.onosproject.xran.controller.XranController; |
| 31 | import org.onosproject.xran.entities.RnibUe; |
| 32 | import org.slf4j.Logger; |
| 33 | |
| 34 | import java.util.Set; |
| 35 | |
| 36 | import static org.onosproject.net.DeviceId.*; |
| 37 | import static org.onosproject.xran.entities.RnibCell.*; |
| 38 | import static org.slf4j.LoggerFactory.getLogger; |
| 39 | |
| 40 | /** |
| 41 | * Created by dimitris on 7/28/17. |
| 42 | */ |
| 43 | |
| 44 | @Component(immediate = true) |
| 45 | public class UeProvider extends AbstractProvider implements HostProvider { |
| 46 | |
| 47 | private static final Logger log = getLogger(UeProvider.class); |
| 48 | private final InternalHostListener listener = new InternalHostListener(); |
| 49 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 50 | private HostProviderRegistry providerRegistry; |
| 51 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 52 | private XranController controller; |
| 53 | private HostProviderService providerService; |
| 54 | |
| 55 | public UeProvider() { |
| 56 | super(new ProviderId("xran", "org.onosproject.providers.cell")); |
| 57 | } |
| 58 | |
| 59 | @Activate |
| 60 | public void activate() { |
| 61 | providerService = providerRegistry.register(this); |
| 62 | controller.addListener(listener); |
| 63 | |
| 64 | log.info("XRAN Host Provider Started"); |
| 65 | } |
| 66 | |
| 67 | @Deactivate |
| 68 | public void deactivate() { |
| 69 | controller.removeListener(listener); |
| 70 | providerRegistry.unregister(this); |
| 71 | |
| 72 | providerService = null; |
| 73 | log.info("XRAN Host Provider Stopped"); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void triggerProbe(Host host) { |
| 78 | |
| 79 | } |
| 80 | |
| 81 | class InternalHostListener implements XranHostListener { |
| 82 | |
| 83 | @Override |
| 84 | public void hostAdded(RnibUe ue, Set<ECGI> ecgiSet) { |
| 85 | if (providerService == null) { |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | if (ue == null) { |
| 90 | log.error("UE {} is not found", ue); |
| 91 | return; |
| 92 | } |
| 93 | |
| 94 | try { |
| 95 | Set<HostLocation> hostLocations = Sets.newConcurrentHashSet(); |
| 96 | |
| 97 | ecgiSet.forEach(ecgi -> hostLocations.add(new HostLocation(deviceId(uri(ecgi)), PortNumber.portNumber(0), 0))); |
| 98 | |
| 99 | SparseAnnotations annotations = DefaultAnnotations.builder() |
| 100 | .set(AnnotationKeys.NAME, "UE #" + ue.getMmeS1apId()) |
| 101 | .build(); |
| 102 | |
| 103 | DefaultHostDescription desc = new DefaultHostDescription( |
| 104 | ue.getHostId().mac(), |
| 105 | VlanId.vlanId(VlanId.UNTAGGED), |
| 106 | hostLocations, |
| 107 | Sets.newConcurrentHashSet(), |
| 108 | true, |
| 109 | annotations |
| 110 | ); |
| 111 | |
| 112 | providerService.hostDetected(ue.getHostId(), desc, false); |
| 113 | } catch (Exception e) { |
| 114 | log.warn(e.getMessage()); |
| 115 | e.printStackTrace(); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public void hostRemoved(HostId id) { |
| 121 | providerService.hostVanished(id); |
| 122 | } |
| 123 | } |
| 124 | } |