blob: 064745d049941e90d3ba6a2cbd617b033a794007 [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;
Saurav Dasa2d37502016-03-25 17:50:40 -070032import org.onosproject.net.PortNumber;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053033import org.onosproject.net.device.DefaultDeviceDescription;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053034import org.onosproject.net.device.DeviceDescription;
35import org.onosproject.net.device.DeviceProvider;
36import org.onosproject.net.device.DeviceProviderRegistry;
37import org.onosproject.net.device.DeviceProviderService;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053038import org.onosproject.net.provider.AbstractProvider;
39import org.onosproject.net.provider.ProviderId;
40import org.slf4j.Logger;
41import org.slf4j.LoggerFactory;
42
43/**
44 * Provider which uses an BGP controller to detect network infrastructure topology.
45 */
46@Component(immediate = true)
Shashikanth VH00af33f2015-11-29 03:27:26 +053047public class BgpTopologyProvider extends AbstractProvider implements DeviceProvider {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053048
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 VH1ca26ce2015-11-20 23:19:49 +053056 protected DeviceProviderRegistry deviceProviderRegistry;
57
58 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053059 protected BgpController controller;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053060
61 private DeviceProviderService deviceProviderService;
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053062
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053063 private InternalBgpProvider listener = new InternalBgpProvider();
64 private static final String UNKNOWN = "unknown";
65
66 @Activate
67 public void activate() {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053068 deviceProviderService = deviceProviderRegistry.register(this);
69 controller.addListener(listener);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053070 }
71
72 @Deactivate
73 public void deactivate() {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053074 controller.removeListener(listener);
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053075 }
76
77 /*
78 * Implements device and link update.
79 */
Shashikanth VH00af33f2015-11-29 03:27:26 +053080 private class InternalBgpProvider implements BgpNodeListener {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053081
82 @Override
Shashikanth VH5dd8dbe2015-11-26 13:22:18 +053083 public void addNode(BgpNodeLSNlriVer4 nodeNlri) {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +053084 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 VH5dd8dbe2015-11-26 13:22:18 +0530100 public void deleteNode(BgpNodeLSNlriVer4 nodeNlri) {
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530101 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 VH1ca26ce2015-11-20 23:19:49 +0530110 }
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 Dasa2d37502016-03-25 17:50:40 -0700126
127 @Override
128 public void changePortState(DeviceId deviceId, PortNumber portNumber,
129 boolean enable) {
130 }
Shashikanth VH1ca26ce2015-11-20 23:19:49 +0530131}