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
Showing
10 changed files
with
869 additions
and
1 deletions
... | @@ -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; | ... | ... |
providers/bgp/app/app.xml
0 → 100755
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> |
providers/bgp/app/features.xml
0 → 100755
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> |
providers/bgp/app/pom.xml
0 → 100755
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> |
providers/bgp/pom.xml
0 → 100755
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> |
providers/bgp/topology/pom.xml
0 → 100755
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 | +} |
providers/bgp/topology/src/main/java/org/onosproject/provider/bgp/topology/impl/package-info.java
0 → 100755
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 |
1 | +/* | ||
2 | + * Copyright 2014-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 | +package org.onosproject.provider.bgp.topology.impl; | ||
14 | + | ||
15 | +import static org.junit.Assert.assertNotNull; | ||
16 | +import static org.junit.Assert.assertNull; | ||
17 | +import static org.junit.Assert.assertTrue; | ||
18 | + | ||
19 | +import java.util.Collection; | ||
20 | +import java.util.HashSet; | ||
21 | +import java.util.LinkedList; | ||
22 | +import java.util.List; | ||
23 | +import java.util.Map; | ||
24 | +import java.util.Set; | ||
25 | +import java.util.concurrent.CopyOnWriteArraySet; | ||
26 | + | ||
27 | +import org.junit.After; | ||
28 | +import org.junit.Before; | ||
29 | +import org.junit.Test; | ||
30 | +import org.onosproject.bgp.controller.BGPCfg; | ||
31 | +import org.onosproject.bgp.controller.BGPController; | ||
32 | +import org.onosproject.bgp.controller.BGPId; | ||
33 | +import org.onosproject.bgp.controller.BGPPeer; | ||
34 | +import org.onosproject.bgp.controller.BgpLinkListener; | ||
35 | +import org.onosproject.bgp.controller.BgpNodeListener; | ||
36 | +import org.onosproject.bgp.controller.BgpPeerManager; | ||
37 | +import org.onosproject.bgpio.exceptions.BGPParseException; | ||
38 | +import org.onosproject.bgpio.protocol.BGPMessage; | ||
39 | +import org.onosproject.bgpio.protocol.linkstate.BGPLinkLSIdentifier; | ||
40 | +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSIdentifier; | ||
41 | +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4; | ||
42 | +import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; | ||
43 | +import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; | ||
44 | +import org.onosproject.bgpio.types.AutonomousSystemTlv; | ||
45 | +import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv; | ||
46 | +import org.onosproject.bgpio.types.BGPValueType; | ||
47 | +import org.onosproject.bgpio.types.RouteDistinguisher; | ||
48 | +import org.onosproject.bgpio.util.Constants; | ||
49 | +import org.onosproject.net.ConnectPoint; | ||
50 | +import org.onosproject.net.DeviceId; | ||
51 | +import org.onosproject.net.MastershipRole; | ||
52 | +import org.onosproject.net.device.DeviceDescription; | ||
53 | +import org.onosproject.net.device.DeviceProvider; | ||
54 | +import org.onosproject.net.device.DeviceProviderRegistry; | ||
55 | +import org.onosproject.net.device.DeviceProviderService; | ||
56 | +import org.onosproject.net.device.PortDescription; | ||
57 | +import org.onosproject.net.device.PortStatistics; | ||
58 | +import org.onosproject.net.link.LinkDescription; | ||
59 | +import org.onosproject.net.link.LinkProvider; | ||
60 | +import org.onosproject.net.link.LinkProviderRegistry; | ||
61 | +import org.onosproject.net.link.LinkProviderService; | ||
62 | +import org.onosproject.net.provider.ProviderId; | ||
63 | + | ||
64 | +public class BgpTopologyProviderTest { | ||
65 | + | ||
66 | + private static final DeviceId DID1 = DeviceId | ||
67 | + .deviceId("bgp:bgpls://0:direct:0/&=bgpnodelsidentifier%7bnodedescriptors=nodedescriptors%7bdestype=512," | ||
68 | + + "%20deslength=4,%20subtlvs=[autonomoussystemtlv%7btype=512,%20length=4,%20asnum=100%7d]%7d%7d"); | ||
69 | + private static final DeviceId DID2 = DeviceId | ||
70 | + .deviceId("bgp:bgpls://0:direct:0/&=bgpnodelsidentifier%7bnodedescriptors=nodedescriptors%7bdestype=512," | ||
71 | + + "%20deslength=4,%20subtlvs=[autonomoussystemtlv%7btype=512,%20length=4,%20asnum=10%7d]%7d%7d"); | ||
72 | + private static final DeviceId DID3 = DeviceId | ||
73 | + .deviceId("bgp:bgpls://direct:0/&=nodedescriptors%7bdestype=512,%20deslength=4," | ||
74 | + + "%20subtlvs=[autonomoussystemtlv%7btype=512,%20length=4,%20asnum=100%7d]%7d"); | ||
75 | + private final BgpTopologyProvider provider = new BgpTopologyProvider(); | ||
76 | + private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry(); | ||
77 | + private final TestLinkRegistry linkRegistry = new TestLinkRegistry(); | ||
78 | + private final TestController controller = new TestController(); | ||
79 | + | ||
80 | + @Before | ||
81 | + public void startUp() { | ||
82 | + provider.deviceProviderRegistry = nodeRegistry; | ||
83 | + provider.linkProviderRegistry = linkRegistry; | ||
84 | + provider.controller = controller; | ||
85 | + provider.activate(); | ||
86 | + assertNotNull("provider should be registered", nodeRegistry.provider); | ||
87 | + assertNotNull("provider should be registered", linkRegistry.provider); | ||
88 | + assertNotNull("listener should be registered", controller.nodeListener); | ||
89 | + } | ||
90 | + | ||
91 | + @After | ||
92 | + public void tearDown() { | ||
93 | + provider.deactivate(); | ||
94 | + assertNull("listener should be removed", controller.nodeListener); | ||
95 | + provider.controller = null; | ||
96 | + provider.deviceProviderRegistry = null; | ||
97 | + provider.linkProviderRegistry = null; | ||
98 | + } | ||
99 | + | ||
100 | + /* Class implement device test registry */ | ||
101 | + private class TestDeviceRegistry implements DeviceProviderRegistry { | ||
102 | + DeviceProvider provider; | ||
103 | + | ||
104 | + Set<DeviceId> connected = new HashSet<>(); | ||
105 | + | ||
106 | + @Override | ||
107 | + public DeviceProviderService register(DeviceProvider provider) { | ||
108 | + this.provider = provider; | ||
109 | + return new TestProviderService(); | ||
110 | + } | ||
111 | + | ||
112 | + @Override | ||
113 | + public void unregister(DeviceProvider provider) { | ||
114 | + } | ||
115 | + | ||
116 | + @Override | ||
117 | + public Set<ProviderId> getProviders() { | ||
118 | + return null; | ||
119 | + } | ||
120 | + | ||
121 | + private class TestProviderService implements DeviceProviderService { | ||
122 | + | ||
123 | + @Override | ||
124 | + public DeviceProvider provider() { | ||
125 | + return null; | ||
126 | + } | ||
127 | + | ||
128 | + @Override | ||
129 | + public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) { | ||
130 | + if (deviceId.equals(DID1)) { | ||
131 | + connected.add(deviceId); | ||
132 | + } | ||
133 | + } | ||
134 | + | ||
135 | + @Override | ||
136 | + public void deviceDisconnected(DeviceId deviceId) { | ||
137 | + if (deviceId.equals(DID1)) { | ||
138 | + connected.remove(deviceId); | ||
139 | + } | ||
140 | + } | ||
141 | + | ||
142 | + @Override | ||
143 | + public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) { | ||
144 | + // TODO Auto-generated method stub | ||
145 | + | ||
146 | + } | ||
147 | + | ||
148 | + @Override | ||
149 | + public void portStatusChanged(DeviceId deviceId, PortDescription portDescription) { | ||
150 | + // TODO Auto-generated method stub | ||
151 | + | ||
152 | + } | ||
153 | + | ||
154 | + @Override | ||
155 | + public void receivedRoleReply(DeviceId deviceId, MastershipRole requested, MastershipRole response) { | ||
156 | + // TODO Auto-generated method stub | ||
157 | + | ||
158 | + } | ||
159 | + | ||
160 | + @Override | ||
161 | + public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) { | ||
162 | + // TODO Auto-generated method stub | ||
163 | + | ||
164 | + } | ||
165 | + } | ||
166 | + } | ||
167 | + | ||
168 | + /* class implement link test registery */ | ||
169 | + private class TestLinkRegistry implements LinkProviderRegistry { | ||
170 | + LinkProvider provider; | ||
171 | + | ||
172 | + Set<DeviceId> connected = new HashSet<>(); | ||
173 | + | ||
174 | + @Override | ||
175 | + public LinkProviderService register(LinkProvider provider) { | ||
176 | + this.provider = provider; | ||
177 | + return new TestProviderService(); | ||
178 | + } | ||
179 | + | ||
180 | + @Override | ||
181 | + public void unregister(LinkProvider provider) { | ||
182 | + } | ||
183 | + | ||
184 | + @Override | ||
185 | + public Set<ProviderId> getProviders() { | ||
186 | + return null; | ||
187 | + } | ||
188 | + | ||
189 | + private class TestProviderService implements LinkProviderService { | ||
190 | + | ||
191 | + @Override | ||
192 | + public LinkProvider provider() { | ||
193 | + // TODO Auto-generated method stub | ||
194 | + return null; | ||
195 | + } | ||
196 | + | ||
197 | + @Override | ||
198 | + public void linkDetected(LinkDescription linkDescription) { | ||
199 | + if ((linkDescription.src().deviceId().equals(DID3)) | ||
200 | + && (linkDescription.dst().deviceId().equals(DID3))) { | ||
201 | + connected.add(linkDescription.src().deviceId()); | ||
202 | + } | ||
203 | + } | ||
204 | + | ||
205 | + @Override | ||
206 | + public void linkVanished(LinkDescription linkDescription) { | ||
207 | + if ((linkDescription.src().deviceId().equals(DID3)) | ||
208 | + && (linkDescription.dst().deviceId().equals(DID3))) { | ||
209 | + connected.remove(linkDescription.src().deviceId()); | ||
210 | + } | ||
211 | + } | ||
212 | + | ||
213 | + @Override | ||
214 | + public void linksVanished(ConnectPoint connectPoint) { | ||
215 | + // TODO Auto-generated method stub | ||
216 | + | ||
217 | + } | ||
218 | + | ||
219 | + @Override | ||
220 | + public void linksVanished(DeviceId deviceId) { | ||
221 | + connected.remove(deviceId); | ||
222 | + } | ||
223 | + | ||
224 | + } | ||
225 | + } | ||
226 | + | ||
227 | + /* class implement test controller */ | ||
228 | + private class TestController implements BGPController { | ||
229 | + protected Set<BgpNodeListener> nodeListener = new CopyOnWriteArraySet<>(); | ||
230 | + protected Set<BgpLinkListener> linkListener = new CopyOnWriteArraySet<>(); | ||
231 | + | ||
232 | + @Override | ||
233 | + public void addListener(BgpNodeListener nodeListener) { | ||
234 | + this.nodeListener.add(nodeListener); | ||
235 | + } | ||
236 | + | ||
237 | + @Override | ||
238 | + public void removeListener(BgpNodeListener nodeListener) { | ||
239 | + this.nodeListener = null; | ||
240 | + } | ||
241 | + | ||
242 | + @Override | ||
243 | + public void addLinkListener(BgpLinkListener linkListener) { | ||
244 | + this.linkListener.add(linkListener); | ||
245 | + } | ||
246 | + | ||
247 | + @Override | ||
248 | + public void removeLinkListener(BgpLinkListener linkListener) { | ||
249 | + this.linkListener = null; | ||
250 | + } | ||
251 | + | ||
252 | + @Override | ||
253 | + public Iterable<BGPPeer> getPeers() { | ||
254 | + // TODO Auto-generated method stub | ||
255 | + return null; | ||
256 | + } | ||
257 | + | ||
258 | + @Override | ||
259 | + public BGPPeer getPeer(BGPId bgpId) { | ||
260 | + // TODO Auto-generated method stub | ||
261 | + return null; | ||
262 | + } | ||
263 | + | ||
264 | + @Override | ||
265 | + public void writeMsg(BGPId bgpId, BGPMessage msg) { | ||
266 | + // TODO Auto-generated method stub | ||
267 | + | ||
268 | + } | ||
269 | + | ||
270 | + @Override | ||
271 | + public void processBGPPacket(BGPId bgpId, BGPMessage msg) throws BGPParseException { | ||
272 | + // TODO Auto-generated method stub | ||
273 | + | ||
274 | + } | ||
275 | + | ||
276 | + @Override | ||
277 | + public void closeConnectedPeers() { | ||
278 | + // TODO Auto-generated method stub | ||
279 | + | ||
280 | + } | ||
281 | + | ||
282 | + @Override | ||
283 | + public BGPCfg getConfig() { | ||
284 | + // TODO Auto-generated method stub | ||
285 | + return null; | ||
286 | + } | ||
287 | + | ||
288 | + @Override | ||
289 | + public int connectedPeerCount() { | ||
290 | + // TODO Auto-generated method stub | ||
291 | + return 0; | ||
292 | + } | ||
293 | + | ||
294 | + | ||
295 | + @Override | ||
296 | + public BgpPeerManager peerManager() { | ||
297 | + // TODO Auto-generated method stub | ||
298 | + return null; | ||
299 | + } | ||
300 | + | ||
301 | + @Override | ||
302 | + public Map<BGPId, BGPPeer> connectedPeers() { | ||
303 | + // TODO Auto-generated method stub | ||
304 | + return null; | ||
305 | + } | ||
306 | + | ||
307 | + @Override | ||
308 | + public Set<BgpNodeListener> listener() { | ||
309 | + // TODO Auto-generated method stub | ||
310 | + return null; | ||
311 | + } | ||
312 | + | ||
313 | + @Override | ||
314 | + public Set<BgpLinkListener> linkListener() { | ||
315 | + // TODO Auto-generated method stub | ||
316 | + return null; | ||
317 | + } | ||
318 | + } | ||
319 | + | ||
320 | + /* Validate node is added to the device validating URI, RIB should get updated properly */ | ||
321 | + @Test | ||
322 | + public void bgpTopologyProviderTestAddDevice1() { | ||
323 | + int deviceAddCount = 0; | ||
324 | + LinkedList<BGPValueType> subTlvs; | ||
325 | + subTlvs = new LinkedList<>(); | ||
326 | + BGPValueType tlv = new AutonomousSystemTlv(100); | ||
327 | + short deslength = AutonomousSystemTlv.LENGTH; | ||
328 | + short desType = AutonomousSystemTlv.TYPE; | ||
329 | + | ||
330 | + subTlvs.add(tlv); | ||
331 | + BGPNodeLSIdentifier localNodeDescriptors = new BGPNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, | ||
332 | + desType)); | ||
333 | + BGPNodeLSNlriVer4 nodeNlri = new BGPNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, | ||
334 | + new RouteDistinguisher()); | ||
335 | + | ||
336 | + nodeNlri.setNodeLSIdentifier(localNodeDescriptors); | ||
337 | + for (BgpNodeListener l : controller.nodeListener) { | ||
338 | + l.addNode(nodeNlri); | ||
339 | + deviceAddCount = nodeRegistry.connected.size(); | ||
340 | + assertTrue(deviceAddCount == 1); | ||
341 | + l.deleteNode(nodeNlri); | ||
342 | + deviceAddCount = nodeRegistry.connected.size(); | ||
343 | + assertTrue(deviceAddCount == 0); | ||
344 | + } | ||
345 | + } | ||
346 | + | ||
347 | + /* Validate node is not added to the device for invalid URI, RIB count should be zero */ | ||
348 | + @Test | ||
349 | + public void bgpTopologyProviderTestAddDevice2() { | ||
350 | + LinkedList<BGPValueType> subTlvs; | ||
351 | + BGPValueType tlv = new AutonomousSystemTlv(10); | ||
352 | + short deslength = AutonomousSystemTlv.LENGTH; | ||
353 | + short desType = AutonomousSystemTlv.TYPE; | ||
354 | + | ||
355 | + subTlvs = new LinkedList<>(); | ||
356 | + subTlvs.add(tlv); | ||
357 | + BGPNodeLSIdentifier localNodeDescriptors = new BGPNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, | ||
358 | + desType)); | ||
359 | + BGPNodeLSNlriVer4 nodeNlri = new BGPNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, | ||
360 | + new RouteDistinguisher()); | ||
361 | + | ||
362 | + nodeNlri.setNodeLSIdentifier(localNodeDescriptors); | ||
363 | + for (BgpNodeListener l : controller.nodeListener) { | ||
364 | + l.addNode(nodeNlri); | ||
365 | + assertTrue("Failed to add device", (nodeRegistry.connected.size() == 0)); | ||
366 | + } | ||
367 | + } | ||
368 | + | ||
369 | + /* Delete node when node does not exist, RIB count should be zero */ | ||
370 | + @Test | ||
371 | + public void bgpTopologyProviderTestAddDevice3() { | ||
372 | + LinkedList<BGPValueType> subTlvs; | ||
373 | + BGPValueType tlv = new AutonomousSystemTlv(10); | ||
374 | + short deslength = AutonomousSystemTlv.LENGTH; | ||
375 | + short desType = AutonomousSystemTlv.TYPE; | ||
376 | + | ||
377 | + subTlvs = new LinkedList<>(); | ||
378 | + subTlvs.add(tlv); | ||
379 | + BGPNodeLSIdentifier localNodeDescriptors = new BGPNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, | ||
380 | + desType)); | ||
381 | + BGPNodeLSNlriVer4 nodeNlri = new BGPNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, | ||
382 | + new RouteDistinguisher()); | ||
383 | + | ||
384 | + nodeNlri.setNodeLSIdentifier(localNodeDescriptors); | ||
385 | + for (BgpNodeListener l : controller.nodeListener) { | ||
386 | + l.deleteNode(nodeNlri); | ||
387 | + assertTrue("Failed to add device", (nodeRegistry.connected.size() == 0)); | ||
388 | + } | ||
389 | + } | ||
390 | + | ||
391 | + /* Validate link is added to the device validating URI, RIB should get updated properly */ | ||
392 | + @Test | ||
393 | + public void bgpTopologyProviderTestAddLink1() { | ||
394 | + | ||
395 | + NodeDescriptors localNodeDescriptors; | ||
396 | + NodeDescriptors remoteNodeDescriptors; | ||
397 | + LinkedList<BGPValueType> subTlvs; | ||
398 | + LinkedList<BGPValueType> linkDescriptor = new LinkedList<>(); | ||
399 | + BGPValueType tlvLocalRemoteId; | ||
400 | + short deslength = AutonomousSystemTlv.LENGTH; | ||
401 | + short desType = AutonomousSystemTlv.TYPE; | ||
402 | + | ||
403 | + BGPValueType tlv = new AutonomousSystemTlv(100); | ||
404 | + subTlvs = new LinkedList<>(); | ||
405 | + subTlvs.add(tlv); | ||
406 | + | ||
407 | + localNodeDescriptors = new NodeDescriptors(subTlvs, deslength, desType); | ||
408 | + remoteNodeDescriptors = new NodeDescriptors(subTlvs, deslength, desType); | ||
409 | + tlvLocalRemoteId = new LinkLocalRemoteIdentifiersTlv(1, 2); | ||
410 | + linkDescriptor.add(tlvLocalRemoteId); | ||
411 | + | ||
412 | + BGPLinkLSIdentifier linkLSIdentifier = new BGPLinkLSIdentifier(localNodeDescriptors, remoteNodeDescriptors, | ||
413 | + linkDescriptor); | ||
414 | + BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkLSIdentifier, null, false); | ||
415 | + | ||
416 | + for (BgpLinkListener l : controller.linkListener) { | ||
417 | + l.addLink(linkNlri); | ||
418 | + assertTrue(linkRegistry.connected.size() == 1); | ||
419 | + l.deleteLink(linkNlri); | ||
420 | + assertTrue(linkRegistry.connected.size() == 0); | ||
421 | + } | ||
422 | + } | ||
423 | +} |
-
Please register or login to post a comment