blob: 34803663a5ee0d871adc28e4122755820262fc87 [file] [log] [blame]
Shashikanth VH1ca26ce2015-11-20 23:19:49 +05301/*
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
14package org.onosproject.provider.bgp.topology.impl;
15
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053016import static org.onosproject.bgp.controller.BgpDpid.uri;
17import static org.onosproject.net.DeviceId.deviceId;
18
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053019import org.onlab.packet.ChassisId;
20import 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;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053025import org.onosproject.bgp.controller.BgpController;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053026import org.onosproject.bgp.controller.BgpDpid;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053027import org.onosproject.bgp.controller.BgpNodeListener;
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053028import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053029import org.onosproject.net.Device;
30import org.onosproject.net.DeviceId;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053031import org.onosproject.net.MastershipRole;
32import org.onosproject.net.device.DefaultDeviceDescription;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053033import org.onosproject.net.device.DeviceDescription;
34import org.onosproject.net.device.DeviceProvider;
35import org.onosproject.net.device.DeviceProviderRegistry;
36import org.onosproject.net.device.DeviceProviderService;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053037import org.onosproject.net.provider.AbstractProvider;
38import org.onosproject.net.provider.ProviderId;
39import org.slf4j.Logger;
40import org.slf4j.LoggerFactory;
41
42/**
43 * Provider which uses an BGP controller to detect network infrastructure topology.
44 */
45@Component(immediate = true)
Shashikanth VH00af33f2015-11-29 03:27:26 +053046public class BgpTopologyProvider extends AbstractProvider implements DeviceProvider {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053047
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 VH1ca26ce2015-11-20 23:19:49 +053055 protected DeviceProviderRegistry deviceProviderRegistry;
56
57 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053058 protected BgpController controller;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053059
60 private DeviceProviderService deviceProviderService;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053061
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053062 private InternalBgpProvider listener = new InternalBgpProvider();
63 private static final String UNKNOWN = "unknown";
64
65 @Activate
66 public void activate() {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053067 deviceProviderService = deviceProviderRegistry.register(this);
68 controller.addListener(listener);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053069 }
70
71 @Deactivate
72 public void deactivate() {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053073 controller.removeListener(listener);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053074 }
75
76 /*
77 * Implements device and link update.
78 */
Shashikanth VH00af33f2015-11-29 03:27:26 +053079 private class InternalBgpProvider implements BgpNodeListener {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053080
81 @Override
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053082 public void addNode(BgpNodeLSNlriVer4 nodeNlri) {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053083 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 VH5dd8dbe2015-11-26 13:22:18 +053099 public void deleteNode(BgpNodeLSNlriVer4 nodeNlri) {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530100 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 VH1ca26ce2015-11-20 23:19:49 +0530109 }
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}