Shashikanth VH
Committed by Gerrit Code Review

[ONOS-2607] Implement BGP LS topology provider and listen on Node and Link chang…

…es of BGP Controller.

Change-Id: I811ca8d078ab5825819cef81fd8096d842f76c44
...@@ -104,7 +104,7 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri { ...@@ -104,7 +104,7 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri {
104 * @param isVpn true if VPN info is present 104 * @param isVpn true if VPN info is present
105 * @param routeDistinguisher unique for each VPN 105 * @param routeDistinguisher unique for each VPN
106 */ 106 */
107 - BGPNodeLSNlriVer4(long identifier, byte protocolId, BGPNodeLSIdentifier localNodeDescriptors, boolean isVpn, 107 + public BGPNodeLSNlriVer4(long identifier, byte protocolId, BGPNodeLSIdentifier localNodeDescriptors, boolean isVpn,
108 RouteDistinguisher routeDistinguisher) { 108 RouteDistinguisher routeDistinguisher) {
109 this.identifier = identifier; 109 this.identifier = identifier;
110 this.protocolId = protocolId; 110 this.protocolId = protocolId;
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<app name="org.onosproject.bgp" origin="ON.Lab" version="${project.version}"
18 + featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
19 + features="${project.artifactId}">
20 + <description>${project.description}</description>
21 + <artifact>mvn:${project.groupId}/onos-bgpio/${project.version}</artifact>
22 + <artifact>mvn:${project.groupId}/onos-bgp-api/${project.version}</artifact>
23 + <artifact>mvn:${project.groupId}/onos-bgp-ctl/${project.version}</artifact>
24 + <artifact>mvn:${project.groupId}/onos-bgp-provider-topology/${project.version}</artifact>
25 +</app>
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 + <repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository>
19 + <feature name="${project.artifactId}" version="${project.version}"
20 + description="${project.description}">
21 + <feature>onos-api</feature>
22 + <bundle>mvn:${project.groupId}/onos-bgpio/${project.version}</bundle>
23 + <bundle>mvn:${project.groupId}/onos-bgp-api/${project.version}</bundle>
24 + <bundle>mvn:${project.groupId}/onos-bgp-ctl/${project.version}</bundle>
25 + <bundle>mvn:${project.groupId}/onos-bgp-provider-topology/${project.version}</bundle>
26 + </feature>
27 +</features>
1 +<!--
2 + ~ Copyright 2015 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 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18 + <modelVersion>4.0.0</modelVersion>
19 + <parent>
20 + <groupId>org.onosproject</groupId>
21 + <artifactId>onos-bgp-providers</artifactId>
22 + <version>1.4.0-SNAPSHOT</version>
23 + <relativePath>../pom.xml</relativePath>
24 + </parent>
25 +
26 + <artifactId>onos-bgp-app</artifactId>
27 + <packaging>pom</packaging>
28 + <description>BGP protocol southbound providers</description>
29 +
30 + <dependencies>
31 + <dependency>
32 + <groupId>org.onosproject</groupId>
33 + <artifactId>onos-bgpio</artifactId>
34 + <version>${project.version}</version>
35 + </dependency>
36 + <dependency>
37 + <groupId>org.onosproject</groupId>
38 + <artifactId>onos-bgp-api</artifactId>
39 + <version>${project.version}</version>
40 + </dependency>
41 + <dependency>
42 + <groupId>org.onosproject</groupId>
43 + <artifactId>onos-bgp-ctl</artifactId>
44 + <version>${project.version}</version>
45 + </dependency>
46 + <dependency>
47 + <groupId>org.onosproject</groupId>
48 + <artifactId>onos-bgp-provider-topology</artifactId>
49 + <version>${project.version}</version>
50 + </dependency>
51 + </dependencies>
52 +</project>
1 +<!--
2 + ~ Copyright 2015 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 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
17 + <modelVersion>4.0.0</modelVersion>
18 + <parent>
19 + <groupId>org.onosproject</groupId>
20 + <artifactId>onos-providers</artifactId>
21 + <version>1.4.0-SNAPSHOT</version>
22 + <relativePath>../pom.xml</relativePath>
23 + </parent>
24 + <artifactId>onos-bgp-providers</artifactId>
25 + <packaging>pom</packaging>
26 + <description>BGP-LS protocol providers root</description>
27 + <modules>
28 + <module>topology</module>
29 + <module>app</module>
30 + </modules>
31 + <dependencies>
32 +
33 + <dependency>
34 + <groupId>org.onosproject</groupId>
35 + <artifactId>onos-bgp-api</artifactId>
36 + </dependency>
37 + <dependency>
38 + <groupId>org.onosproject</groupId>
39 + <artifactId>onos-bgpio</artifactId>
40 + </dependency>
41 + <dependency>
42 + <groupId>org.onosproject</groupId>
43 + <artifactId>onos-api</artifactId>
44 + <classifier>tests</classifier>
45 + <scope>test</scope>
46 + </dependency>
47 +
48 + <dependency>
49 + <groupId>io.netty</groupId>
50 + <artifactId>netty</artifactId>
51 + </dependency>
52 +
53 + <dependency>
54 + <groupId>org.onosproject</groupId>
55 + <artifactId>onlab-junit</artifactId>
56 + </dependency>
57 + </dependencies>
58 +</project>
1 +<!--
2 + ~ Copyright 2015 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 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
17 + <modelVersion>4.0.0</modelVersion>
18 + <parent>
19 + <groupId>org.onosproject</groupId>
20 + <artifactId>onos-bgp-providers</artifactId>
21 + <version>1.4.0-SNAPSHOT</version>
22 + <relativePath>../pom.xml</relativePath>
23 + </parent>
24 + <artifactId>onos-bgp-provider-topology</artifactId>
25 + <packaging>bundle</packaging>
26 + <description>BGP topology provider</description>
27 + <dependencies>
28 + <dependency>
29 + <groupId>org.onosproject</groupId>
30 + <artifactId>onos-bgp-api</artifactId>
31 + </dependency>
32 + </dependencies>
33 +</project>
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 +
16 +import static com.google.common.base.Preconditions.checkNotNull;
17 +import static org.onosproject.bgp.controller.BgpDpid.uri;
18 +import static org.onosproject.net.DeviceId.deviceId;
19 +
20 +import java.util.ArrayList;
21 +import java.util.HashMap;
22 +import java.util.List;
23 +
24 +import org.onlab.packet.ChassisId;
25 +import org.apache.felix.scr.annotations.Activate;
26 +import org.apache.felix.scr.annotations.Component;
27 +import org.apache.felix.scr.annotations.Deactivate;
28 +import org.apache.felix.scr.annotations.Reference;
29 +import org.apache.felix.scr.annotations.ReferenceCardinality;
30 +import org.onosproject.bgp.controller.BGPController;
31 +import org.onosproject.bgp.controller.BgpDpid;
32 +import org.onosproject.bgp.controller.BgpLinkListener;
33 +import org.onosproject.bgp.controller.BgpNodeListener;
34 +import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
35 +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4;
36 +import org.onosproject.net.ConnectPoint;
37 +import org.onosproject.net.Device;
38 +import org.onosproject.net.DeviceId;
39 +import org.onosproject.net.Link;
40 +import org.onosproject.net.MastershipRole;
41 +import org.onosproject.net.device.DefaultDeviceDescription;
42 +import org.onosproject.net.device.DefaultPortDescription;
43 +import org.onosproject.net.device.DeviceDescription;
44 +import org.onosproject.net.device.DeviceProvider;
45 +import org.onosproject.net.device.DeviceProviderRegistry;
46 +import org.onosproject.net.device.DeviceProviderService;
47 +import org.onosproject.net.device.PortDescription;
48 +import org.onosproject.net.link.DefaultLinkDescription;
49 +import org.onosproject.net.link.LinkDescription;
50 +import org.onosproject.net.link.LinkProvider;
51 +import org.onosproject.net.link.LinkProviderRegistry;
52 +import org.onosproject.net.link.LinkProviderService;
53 +import org.onosproject.net.provider.AbstractProvider;
54 +import org.onosproject.net.provider.ProviderId;
55 +import org.slf4j.Logger;
56 +import org.slf4j.LoggerFactory;
57 +
58 +/**
59 + * Provider which uses an BGP controller to detect network infrastructure topology.
60 + */
61 +@Component(immediate = true)
62 +public class BgpTopologyProvider extends AbstractProvider implements LinkProvider, DeviceProvider {
63 +
64 + public BgpTopologyProvider() {
65 + super(new ProviderId("bgp", "org.onosproject.provider.bgp"));
66 + }
67 +
68 + private static final Logger log = LoggerFactory.getLogger(BgpTopologyProvider.class);
69 +
70 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
71 + protected LinkProviderRegistry linkProviderRegistry;
72 +
73 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
74 + protected DeviceProviderRegistry deviceProviderRegistry;
75 +
76 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
77 + protected BGPController controller;
78 +
79 + private DeviceProviderService deviceProviderService;
80 + private LinkProviderService linkProviderService;
81 +
82 + private HashMap<String, List<PortDescription>> portMap = new HashMap<>();
83 + private InternalBgpProvider listener = new InternalBgpProvider();
84 + private static final String UNKNOWN = "unknown";
85 +
86 + @Activate
87 + public void activate() {
88 + linkProviderService = linkProviderRegistry.register(this);
89 + deviceProviderService = deviceProviderRegistry.register(this);
90 + controller.addListener(listener);
91 + controller.addLinkListener(listener);
92 + }
93 +
94 + @Deactivate
95 + public void deactivate() {
96 + linkProviderRegistry.unregister(this);
97 + linkProviderService = null;
98 + controller.removeListener(listener);
99 + controller.removeLinkListener(listener);
100 + }
101 +
102 + private List<PortDescription> buildPortDescriptions(String linkUri) {
103 +
104 + List<PortDescription> portList;
105 +
106 + if (portMap.containsKey(linkUri)) {
107 + portList = portMap.get(linkUri);
108 + } else {
109 + portList = new ArrayList<>();
110 + }
111 +
112 + // TODO: port description
113 + portList.add(new DefaultPortDescription(null, true));
114 +
115 + portMap.put(linkUri, portList);
116 + return portList;
117 + }
118 +
119 + /**
120 + * Build a link description from a bgp link.
121 + *
122 + * @param bgpLink bgp link
123 + * @return linkDescription link description
124 + */
125 + private LinkDescription buildLinkDescription(BgpLinkLsNlriVer4 bgpLink) {
126 + LinkDescription ld = null;
127 + checkNotNull(bgpLink);
128 +
129 + BgpDpid localNodeUri = new BgpDpid(bgpLink, BgpDpid.NODE_DESCRIPTOR_LOCAL);
130 + DeviceId srcDeviceID = deviceId(uri(localNodeUri.toString()));
131 +
132 + BgpDpid remoteNodeUri = new BgpDpid(bgpLink, BgpDpid.NODE_DESCRIPTOR_REMOTE);
133 + DeviceId dstDeviceID = deviceId(uri(remoteNodeUri.toString()));
134 +
135 + deviceProviderService.updatePorts(srcDeviceID, buildPortDescriptions(localNodeUri.toString()));
136 +
137 + deviceProviderService.updatePorts(dstDeviceID, buildPortDescriptions(remoteNodeUri.toString()));
138 +
139 + ConnectPoint src = new ConnectPoint(srcDeviceID, null);
140 +
141 + ConnectPoint dst = new ConnectPoint(dstDeviceID, null);
142 +
143 + ld = new DefaultLinkDescription(src, dst, Link.Type.INDIRECT);
144 + return ld;
145 + }
146 +
147 + /*
148 + * Implements device and link update.
149 + */
150 + private class InternalBgpProvider implements BgpNodeListener, BgpLinkListener {
151 +
152 + @Override
153 + public void addNode(BGPNodeLSNlriVer4 nodeNlri) {
154 + log.debug("Add node {}", nodeNlri.toString());
155 +
156 + if (deviceProviderService == null) {
157 + return;
158 + }
159 + BgpDpid nodeUri = new BgpDpid(nodeNlri);
160 + DeviceId deviceId = deviceId(uri(nodeUri.toString()));
161 + ChassisId cId = new ChassisId();
162 +
163 + DeviceDescription description = new DefaultDeviceDescription(uri(nodeUri.toString()), Device.Type.ROUTER,
164 + UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cId);
165 + deviceProviderService.deviceConnected(deviceId, description);
166 +
167 + }
168 +
169 + @Override
170 + public void deleteNode(BGPNodeLSNlriVer4 nodeNlri) {
171 + log.debug("Delete node {}", nodeNlri.toString());
172 +
173 + if (deviceProviderService == null) {
174 + return;
175 + }
176 +
177 + BgpDpid nodeUri = new BgpDpid(nodeNlri);
178 + deviceProviderService.deviceDisconnected(deviceId(uri(nodeUri.toString())));
179 + }
180 +
181 + @Override
182 + public void addLink(BgpLinkLsNlriVer4 linkNlri) {
183 + log.debug("Add link {}", linkNlri.toString());
184 +
185 + if (linkProviderService == null) {
186 + return;
187 + }
188 +
189 + LinkDescription ld = buildLinkDescription(linkNlri);
190 + if (ld == null) {
191 + log.error("Invalid link info.");
192 + return;
193 + }
194 +
195 + linkProviderService.linkDetected(ld);
196 + }
197 +
198 + @Override
199 + public void deleteLink(BgpLinkLsNlriVer4 linkNlri) {
200 + log.debug("Delete link {}", linkNlri.toString());
201 +
202 + if (linkProviderService == null) {
203 + return;
204 + }
205 +
206 + LinkDescription ld = buildLinkDescription(linkNlri);
207 + if (ld == null) {
208 + log.error("Invalid link info.");
209 + return;
210 + }
211 +
212 + linkProviderService.linkVanished(ld);
213 + }
214 + }
215 +
216 + @Override
217 + public void triggerProbe(DeviceId deviceId) {
218 + // TODO Auto-generated method stub
219 + }
220 +
221 + @Override
222 + public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
223 + }
224 +
225 + @Override
226 + public boolean isReachable(DeviceId deviceId) {
227 + // TODO Auto-generated method stub
228 + return true;
229 + }
230 +}
1 +/*
2 + * Copyright 2015 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 + *Provider that uses BGP controller as a means of infrastructure topology discovery.
18 + */
19 +package org.onosproject.provider.bgp.topology.impl;
...\ No newline at end of file ...\ No newline at end of file
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
39 <module>null</module> 39 <module>null</module>
40 <module>pcep</module> 40 <module>pcep</module>
41 <module>ovsdb</module> 41 <module>ovsdb</module>
42 + <module>bgp</module>
42 </modules> 43 </modules>
43 44
44 <dependencies> 45 <dependencies>
......