Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 5 | * the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 10 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | * specific language governing permissions and limitations under the License. |
| 12 | */ |
| 13 | |
| 14 | package org.onosproject.provider.bgp.topology.impl; |
| 15 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 16 | import static org.onosproject.bgp.controller.BgpDpid.uri; |
| 17 | import static org.onosproject.net.DeviceId.deviceId; |
| 18 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 19 | import org.onlab.packet.ChassisId; |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 25 | import org.onosproject.bgp.controller.BgpController; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 26 | import org.onosproject.bgp.controller.BgpDpid; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 27 | import org.onosproject.bgp.controller.BgpNodeListener; |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 28 | import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 29 | import org.onosproject.net.Device; |
| 30 | import org.onosproject.net.DeviceId; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 31 | import org.onosproject.net.MastershipRole; |
| 32 | import org.onosproject.net.device.DefaultDeviceDescription; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 33 | import org.onosproject.net.device.DeviceDescription; |
| 34 | import org.onosproject.net.device.DeviceProvider; |
| 35 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 36 | import org.onosproject.net.device.DeviceProviderService; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 37 | import org.onosproject.net.provider.AbstractProvider; |
| 38 | import org.onosproject.net.provider.ProviderId; |
| 39 | import org.slf4j.Logger; |
| 40 | import org.slf4j.LoggerFactory; |
| 41 | |
| 42 | /** |
| 43 | * Provider which uses an BGP controller to detect network infrastructure topology. |
| 44 | */ |
| 45 | @Component(immediate = true) |
Shashikanth VH | 00af33f | 2015-11-29 03:27:26 +0530 | [diff] [blame] | 46 | public class BgpTopologyProvider extends AbstractProvider implements DeviceProvider { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 47 | |
| 48 | public BgpTopologyProvider() { |
| 49 | super(new ProviderId("bgp", "org.onosproject.provider.bgp")); |
| 50 | } |
| 51 | |
| 52 | private static final Logger log = LoggerFactory.getLogger(BgpTopologyProvider.class); |
| 53 | |
| 54 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 55 | protected DeviceProviderRegistry deviceProviderRegistry; |
| 56 | |
| 57 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 58 | protected BgpController controller; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 59 | |
| 60 | private DeviceProviderService deviceProviderService; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 61 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 62 | private InternalBgpProvider listener = new InternalBgpProvider(); |
| 63 | private static final String UNKNOWN = "unknown"; |
| 64 | |
| 65 | @Activate |
| 66 | public void activate() { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 67 | deviceProviderService = deviceProviderRegistry.register(this); |
| 68 | controller.addListener(listener); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Deactivate |
| 72 | public void deactivate() { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 73 | controller.removeListener(listener); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Implements device and link update. |
| 78 | */ |
Shashikanth VH | 00af33f | 2015-11-29 03:27:26 +0530 | [diff] [blame] | 79 | private class InternalBgpProvider implements BgpNodeListener { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 80 | |
| 81 | @Override |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 82 | public void addNode(BgpNodeLSNlriVer4 nodeNlri) { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 83 | log.debug("Add node {}", nodeNlri.toString()); |
| 84 | |
| 85 | if (deviceProviderService == null) { |
| 86 | return; |
| 87 | } |
| 88 | BgpDpid nodeUri = new BgpDpid(nodeNlri); |
| 89 | DeviceId deviceId = deviceId(uri(nodeUri.toString())); |
| 90 | ChassisId cId = new ChassisId(); |
| 91 | |
| 92 | DeviceDescription description = new DefaultDeviceDescription(uri(nodeUri.toString()), Device.Type.ROUTER, |
| 93 | UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cId); |
| 94 | deviceProviderService.deviceConnected(deviceId, description); |
| 95 | |
| 96 | } |
| 97 | |
| 98 | @Override |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 99 | public void deleteNode(BgpNodeLSNlriVer4 nodeNlri) { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 100 | log.debug("Delete node {}", nodeNlri.toString()); |
| 101 | |
| 102 | if (deviceProviderService == null) { |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | BgpDpid nodeUri = new BgpDpid(nodeNlri); |
| 107 | deviceProviderService.deviceDisconnected(deviceId(uri(nodeUri.toString()))); |
| 108 | } |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void triggerProbe(DeviceId deviceId) { |
| 113 | // TODO Auto-generated method stub |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public void roleChanged(DeviceId deviceId, MastershipRole newRole) { |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public boolean isReachable(DeviceId deviceId) { |
| 122 | // TODO Auto-generated method stub |
| 123 | return true; |
| 124 | } |
| 125 | } |