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; |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame^] | 32 | import org.onosproject.net.PortNumber; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 33 | import org.onosproject.net.device.DefaultDeviceDescription; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 34 | import org.onosproject.net.device.DeviceDescription; |
| 35 | import org.onosproject.net.device.DeviceProvider; |
| 36 | import org.onosproject.net.device.DeviceProviderRegistry; |
| 37 | import org.onosproject.net.device.DeviceProviderService; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 38 | import org.onosproject.net.provider.AbstractProvider; |
| 39 | import org.onosproject.net.provider.ProviderId; |
| 40 | import org.slf4j.Logger; |
| 41 | import org.slf4j.LoggerFactory; |
| 42 | |
| 43 | /** |
| 44 | * Provider which uses an BGP controller to detect network infrastructure topology. |
| 45 | */ |
| 46 | @Component(immediate = true) |
Shashikanth VH | 00af33f | 2015-11-29 03:27:26 +0530 | [diff] [blame] | 47 | public class BgpTopologyProvider extends AbstractProvider implements DeviceProvider { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 48 | |
| 49 | public BgpTopologyProvider() { |
| 50 | super(new ProviderId("bgp", "org.onosproject.provider.bgp")); |
| 51 | } |
| 52 | |
| 53 | private static final Logger log = LoggerFactory.getLogger(BgpTopologyProvider.class); |
| 54 | |
| 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 56 | protected DeviceProviderRegistry deviceProviderRegistry; |
| 57 | |
| 58 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 59 | protected BgpController controller; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 60 | |
| 61 | private DeviceProviderService deviceProviderService; |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 62 | |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 63 | private InternalBgpProvider listener = new InternalBgpProvider(); |
| 64 | private static final String UNKNOWN = "unknown"; |
| 65 | |
| 66 | @Activate |
| 67 | public void activate() { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 68 | deviceProviderService = deviceProviderRegistry.register(this); |
| 69 | controller.addListener(listener); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Deactivate |
| 73 | public void deactivate() { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 74 | controller.removeListener(listener); |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Implements device and link update. |
| 79 | */ |
Shashikanth VH | 00af33f | 2015-11-29 03:27:26 +0530 | [diff] [blame] | 80 | private class InternalBgpProvider implements BgpNodeListener { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 81 | |
| 82 | @Override |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 83 | public void addNode(BgpNodeLSNlriVer4 nodeNlri) { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 84 | log.debug("Add node {}", nodeNlri.toString()); |
| 85 | |
| 86 | if (deviceProviderService == null) { |
| 87 | return; |
| 88 | } |
| 89 | BgpDpid nodeUri = new BgpDpid(nodeNlri); |
| 90 | DeviceId deviceId = deviceId(uri(nodeUri.toString())); |
| 91 | ChassisId cId = new ChassisId(); |
| 92 | |
| 93 | DeviceDescription description = new DefaultDeviceDescription(uri(nodeUri.toString()), Device.Type.ROUTER, |
| 94 | UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cId); |
| 95 | deviceProviderService.deviceConnected(deviceId, description); |
| 96 | |
| 97 | } |
| 98 | |
| 99 | @Override |
Shashikanth VH | 5dd8dbe | 2015-11-26 13:22:18 +0530 | [diff] [blame] | 100 | public void deleteNode(BgpNodeLSNlriVer4 nodeNlri) { |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 101 | log.debug("Delete node {}", nodeNlri.toString()); |
| 102 | |
| 103 | if (deviceProviderService == null) { |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | BgpDpid nodeUri = new BgpDpid(nodeNlri); |
| 108 | deviceProviderService.deviceDisconnected(deviceId(uri(nodeUri.toString()))); |
| 109 | } |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public void triggerProbe(DeviceId deviceId) { |
| 114 | // TODO Auto-generated method stub |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void roleChanged(DeviceId deviceId, MastershipRole newRole) { |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public boolean isReachable(DeviceId deviceId) { |
| 123 | // TODO Auto-generated method stub |
| 124 | return true; |
| 125 | } |
Saurav Das | a2d3750 | 2016-03-25 17:50:40 -0700 | [diff] [blame^] | 126 | |
| 127 | @Override |
| 128 | public void changePortState(DeviceId deviceId, PortNumber portNumber, |
| 129 | boolean enable) { |
| 130 | } |
Shashikanth VH | 1ca26ce | 2015-11-20 23:19:49 +0530 | [diff] [blame] | 131 | } |