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 {
* @param isVpn true if VPN info is present
* @param routeDistinguisher unique for each VPN
*/
BGPNodeLSNlriVer4(long identifier, byte protocolId, BGPNodeLSIdentifier localNodeDescriptors, boolean isVpn,
public BGPNodeLSNlriVer4(long identifier, byte protocolId, BGPNodeLSIdentifier localNodeDescriptors, boolean isVpn,
RouteDistinguisher routeDistinguisher) {
this.identifier = identifier;
this.protocolId = protocolId;
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015 Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<app name="org.onosproject.bgp" origin="ON.Lab" version="${project.version}"
featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
features="${project.artifactId}">
<description>${project.description}</description>
<artifact>mvn:${project.groupId}/onos-bgpio/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-bgp-api/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-bgp-ctl/${project.version}</artifact>
<artifact>mvn:${project.groupId}/onos-bgp-provider-topology/${project.version}</artifact>
</app>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ Copyright 2015 Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
<repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository>
<feature name="${project.artifactId}" version="${project.version}"
description="${project.description}">
<feature>onos-api</feature>
<bundle>mvn:${project.groupId}/onos-bgpio/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-bgp-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-bgp-ctl/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-bgp-provider-topology/${project.version}</bundle>
</feature>
</features>
<!--
~ Copyright 2015 Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-bgp-providers</artifactId>
<version>1.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-bgp-app</artifactId>
<packaging>pom</packaging>
<description>BGP protocol southbound providers</description>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-bgpio</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-bgp-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-bgp-ctl</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-bgp-provider-topology</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
<!--
~ Copyright 2015 Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-providers</artifactId>
<version>1.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-bgp-providers</artifactId>
<packaging>pom</packaging>
<description>BGP-LS protocol providers root</description>
<modules>
<module>topology</module>
<module>app</module>
</modules>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-bgp-api</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-bgpio</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onlab-junit</artifactId>
</dependency>
</dependencies>
</project>
<!--
~ Copyright 2015 Open Networking Laboratory
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-bgp-providers</artifactId>
<version>1.4.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>onos-bgp-provider-topology</artifactId>
<packaging>bundle</packaging>
<description>BGP topology provider</description>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-bgp-api</artifactId>
</dependency>
</dependencies>
</project>
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.onosproject.provider.bgp.topology.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.bgp.controller.BgpDpid.uri;
import static org.onosproject.net.DeviceId.deviceId;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.onlab.packet.ChassisId;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.bgp.controller.BGPController;
import org.onosproject.bgp.controller.BgpDpid;
import org.onosproject.bgp.controller.BgpLinkListener;
import org.onosproject.bgp.controller.BgpNodeListener;
import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.device.DefaultDeviceDescription;
import org.onosproject.net.device.DefaultPortDescription;
import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceProvider;
import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceProviderService;
import org.onosproject.net.device.PortDescription;
import org.onosproject.net.link.DefaultLinkDescription;
import org.onosproject.net.link.LinkDescription;
import org.onosproject.net.link.LinkProvider;
import org.onosproject.net.link.LinkProviderRegistry;
import org.onosproject.net.link.LinkProviderService;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Provider which uses an BGP controller to detect network infrastructure topology.
*/
@Component(immediate = true)
public class BgpTopologyProvider extends AbstractProvider implements LinkProvider, DeviceProvider {
public BgpTopologyProvider() {
super(new ProviderId("bgp", "org.onosproject.provider.bgp"));
}
private static final Logger log = LoggerFactory.getLogger(BgpTopologyProvider.class);
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LinkProviderRegistry linkProviderRegistry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceProviderRegistry deviceProviderRegistry;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected BGPController controller;
private DeviceProviderService deviceProviderService;
private LinkProviderService linkProviderService;
private HashMap<String, List<PortDescription>> portMap = new HashMap<>();
private InternalBgpProvider listener = new InternalBgpProvider();
private static final String UNKNOWN = "unknown";
@Activate
public void activate() {
linkProviderService = linkProviderRegistry.register(this);
deviceProviderService = deviceProviderRegistry.register(this);
controller.addListener(listener);
controller.addLinkListener(listener);
}
@Deactivate
public void deactivate() {
linkProviderRegistry.unregister(this);
linkProviderService = null;
controller.removeListener(listener);
controller.removeLinkListener(listener);
}
private List<PortDescription> buildPortDescriptions(String linkUri) {
List<PortDescription> portList;
if (portMap.containsKey(linkUri)) {
portList = portMap.get(linkUri);
} else {
portList = new ArrayList<>();
}
// TODO: port description
portList.add(new DefaultPortDescription(null, true));
portMap.put(linkUri, portList);
return portList;
}
/**
* Build a link description from a bgp link.
*
* @param bgpLink bgp link
* @return linkDescription link description
*/
private LinkDescription buildLinkDescription(BgpLinkLsNlriVer4 bgpLink) {
LinkDescription ld = null;
checkNotNull(bgpLink);
BgpDpid localNodeUri = new BgpDpid(bgpLink, BgpDpid.NODE_DESCRIPTOR_LOCAL);
DeviceId srcDeviceID = deviceId(uri(localNodeUri.toString()));
BgpDpid remoteNodeUri = new BgpDpid(bgpLink, BgpDpid.NODE_DESCRIPTOR_REMOTE);
DeviceId dstDeviceID = deviceId(uri(remoteNodeUri.toString()));
deviceProviderService.updatePorts(srcDeviceID, buildPortDescriptions(localNodeUri.toString()));
deviceProviderService.updatePorts(dstDeviceID, buildPortDescriptions(remoteNodeUri.toString()));
ConnectPoint src = new ConnectPoint(srcDeviceID, null);
ConnectPoint dst = new ConnectPoint(dstDeviceID, null);
ld = new DefaultLinkDescription(src, dst, Link.Type.INDIRECT);
return ld;
}
/*
* Implements device and link update.
*/
private class InternalBgpProvider implements BgpNodeListener, BgpLinkListener {
@Override
public void addNode(BGPNodeLSNlriVer4 nodeNlri) {
log.debug("Add node {}", nodeNlri.toString());
if (deviceProviderService == null) {
return;
}
BgpDpid nodeUri = new BgpDpid(nodeNlri);
DeviceId deviceId = deviceId(uri(nodeUri.toString()));
ChassisId cId = new ChassisId();
DeviceDescription description = new DefaultDeviceDescription(uri(nodeUri.toString()), Device.Type.ROUTER,
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cId);
deviceProviderService.deviceConnected(deviceId, description);
}
@Override
public void deleteNode(BGPNodeLSNlriVer4 nodeNlri) {
log.debug("Delete node {}", nodeNlri.toString());
if (deviceProviderService == null) {
return;
}
BgpDpid nodeUri = new BgpDpid(nodeNlri);
deviceProviderService.deviceDisconnected(deviceId(uri(nodeUri.toString())));
}
@Override
public void addLink(BgpLinkLsNlriVer4 linkNlri) {
log.debug("Add link {}", linkNlri.toString());
if (linkProviderService == null) {
return;
}
LinkDescription ld = buildLinkDescription(linkNlri);
if (ld == null) {
log.error("Invalid link info.");
return;
}
linkProviderService.linkDetected(ld);
}
@Override
public void deleteLink(BgpLinkLsNlriVer4 linkNlri) {
log.debug("Delete link {}", linkNlri.toString());
if (linkProviderService == null) {
return;
}
LinkDescription ld = buildLinkDescription(linkNlri);
if (ld == null) {
log.error("Invalid link info.");
return;
}
linkProviderService.linkVanished(ld);
}
}
@Override
public void triggerProbe(DeviceId deviceId) {
// TODO Auto-generated method stub
}
@Override
public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
}
@Override
public boolean isReachable(DeviceId deviceId) {
// TODO Auto-generated method stub
return true;
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*Provider that uses BGP controller as a means of infrastructure topology discovery.
*/
package org.onosproject.provider.bgp.topology.impl;
\ No newline at end of file
/*
* Copyright 2014-2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.onosproject.provider.bgp.topology.impl;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.bgp.controller.BGPCfg;
import org.onosproject.bgp.controller.BGPController;
import org.onosproject.bgp.controller.BGPId;
import org.onosproject.bgp.controller.BGPPeer;
import org.onosproject.bgp.controller.BgpLinkListener;
import org.onosproject.bgp.controller.BgpNodeListener;
import org.onosproject.bgp.controller.BgpPeerManager;
import org.onosproject.bgpio.exceptions.BGPParseException;
import org.onosproject.bgpio.protocol.BGPMessage;
import org.onosproject.bgpio.protocol.linkstate.BGPLinkLSIdentifier;
import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSIdentifier;
import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4;
import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors;
import org.onosproject.bgpio.types.AutonomousSystemTlv;
import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv;
import org.onosproject.bgpio.types.BGPValueType;
import org.onosproject.bgpio.types.RouteDistinguisher;
import org.onosproject.bgpio.util.Constants;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceProvider;
import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceProviderService;
import org.onosproject.net.device.PortDescription;
import org.onosproject.net.device.PortStatistics;
import org.onosproject.net.link.LinkDescription;
import org.onosproject.net.link.LinkProvider;
import org.onosproject.net.link.LinkProviderRegistry;
import org.onosproject.net.link.LinkProviderService;
import org.onosproject.net.provider.ProviderId;
public class BgpTopologyProviderTest {
private static final DeviceId DID1 = DeviceId
.deviceId("bgp:bgpls://0:direct:0/&=bgpnodelsidentifier%7bnodedescriptors=nodedescriptors%7bdestype=512,"
+ "%20deslength=4,%20subtlvs=[autonomoussystemtlv%7btype=512,%20length=4,%20asnum=100%7d]%7d%7d");
private static final DeviceId DID2 = DeviceId
.deviceId("bgp:bgpls://0:direct:0/&=bgpnodelsidentifier%7bnodedescriptors=nodedescriptors%7bdestype=512,"
+ "%20deslength=4,%20subtlvs=[autonomoussystemtlv%7btype=512,%20length=4,%20asnum=10%7d]%7d%7d");
private static final DeviceId DID3 = DeviceId
.deviceId("bgp:bgpls://direct:0/&=nodedescriptors%7bdestype=512,%20deslength=4,"
+ "%20subtlvs=[autonomoussystemtlv%7btype=512,%20length=4,%20asnum=100%7d]%7d");
private final BgpTopologyProvider provider = new BgpTopologyProvider();
private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry();
private final TestLinkRegistry linkRegistry = new TestLinkRegistry();
private final TestController controller = new TestController();
@Before
public void startUp() {
provider.deviceProviderRegistry = nodeRegistry;
provider.linkProviderRegistry = linkRegistry;
provider.controller = controller;
provider.activate();
assertNotNull("provider should be registered", nodeRegistry.provider);
assertNotNull("provider should be registered", linkRegistry.provider);
assertNotNull("listener should be registered", controller.nodeListener);
}
@After
public void tearDown() {
provider.deactivate();
assertNull("listener should be removed", controller.nodeListener);
provider.controller = null;
provider.deviceProviderRegistry = null;
provider.linkProviderRegistry = null;
}
/* Class implement device test registry */
private class TestDeviceRegistry implements DeviceProviderRegistry {
DeviceProvider provider;
Set<DeviceId> connected = new HashSet<>();
@Override
public DeviceProviderService register(DeviceProvider provider) {
this.provider = provider;
return new TestProviderService();
}
@Override
public void unregister(DeviceProvider provider) {
}
@Override
public Set<ProviderId> getProviders() {
return null;
}
private class TestProviderService implements DeviceProviderService {
@Override
public DeviceProvider provider() {
return null;
}
@Override
public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) {
if (deviceId.equals(DID1)) {
connected.add(deviceId);
}
}
@Override
public void deviceDisconnected(DeviceId deviceId) {
if (deviceId.equals(DID1)) {
connected.remove(deviceId);
}
}
@Override
public void updatePorts(DeviceId deviceId, List<PortDescription> portDescriptions) {
// TODO Auto-generated method stub
}
@Override
public void portStatusChanged(DeviceId deviceId, PortDescription portDescription) {
// TODO Auto-generated method stub
}
@Override
public void receivedRoleReply(DeviceId deviceId, MastershipRole requested, MastershipRole response) {
// TODO Auto-generated method stub
}
@Override
public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
// TODO Auto-generated method stub
}
}
}
/* class implement link test registery */
private class TestLinkRegistry implements LinkProviderRegistry {
LinkProvider provider;
Set<DeviceId> connected = new HashSet<>();
@Override
public LinkProviderService register(LinkProvider provider) {
this.provider = provider;
return new TestProviderService();
}
@Override
public void unregister(LinkProvider provider) {
}
@Override
public Set<ProviderId> getProviders() {
return null;
}
private class TestProviderService implements LinkProviderService {
@Override
public LinkProvider provider() {
// TODO Auto-generated method stub
return null;
}
@Override
public void linkDetected(LinkDescription linkDescription) {
if ((linkDescription.src().deviceId().equals(DID3))
&& (linkDescription.dst().deviceId().equals(DID3))) {
connected.add(linkDescription.src().deviceId());
}
}
@Override
public void linkVanished(LinkDescription linkDescription) {
if ((linkDescription.src().deviceId().equals(DID3))
&& (linkDescription.dst().deviceId().equals(DID3))) {
connected.remove(linkDescription.src().deviceId());
}
}
@Override
public void linksVanished(ConnectPoint connectPoint) {
// TODO Auto-generated method stub
}
@Override
public void linksVanished(DeviceId deviceId) {
connected.remove(deviceId);
}
}
}
/* class implement test controller */
private class TestController implements BGPController {
protected Set<BgpNodeListener> nodeListener = new CopyOnWriteArraySet<>();
protected Set<BgpLinkListener> linkListener = new CopyOnWriteArraySet<>();
@Override
public void addListener(BgpNodeListener nodeListener) {
this.nodeListener.add(nodeListener);
}
@Override
public void removeListener(BgpNodeListener nodeListener) {
this.nodeListener = null;
}
@Override
public void addLinkListener(BgpLinkListener linkListener) {
this.linkListener.add(linkListener);
}
@Override
public void removeLinkListener(BgpLinkListener linkListener) {
this.linkListener = null;
}
@Override
public Iterable<BGPPeer> getPeers() {
// TODO Auto-generated method stub
return null;
}
@Override
public BGPPeer getPeer(BGPId bgpId) {
// TODO Auto-generated method stub
return null;
}
@Override
public void writeMsg(BGPId bgpId, BGPMessage msg) {
// TODO Auto-generated method stub
}
@Override
public void processBGPPacket(BGPId bgpId, BGPMessage msg) throws BGPParseException {
// TODO Auto-generated method stub
}
@Override
public void closeConnectedPeers() {
// TODO Auto-generated method stub
}
@Override
public BGPCfg getConfig() {
// TODO Auto-generated method stub
return null;
}
@Override
public int connectedPeerCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public BgpPeerManager peerManager() {
// TODO Auto-generated method stub
return null;
}
@Override
public Map<BGPId, BGPPeer> connectedPeers() {
// TODO Auto-generated method stub
return null;
}
@Override
public Set<BgpNodeListener> listener() {
// TODO Auto-generated method stub
return null;
}
@Override
public Set<BgpLinkListener> linkListener() {
// TODO Auto-generated method stub
return null;
}
}
/* Validate node is added to the device validating URI, RIB should get updated properly */
@Test
public void bgpTopologyProviderTestAddDevice1() {
int deviceAddCount = 0;
LinkedList<BGPValueType> subTlvs;
subTlvs = new LinkedList<>();
BGPValueType tlv = new AutonomousSystemTlv(100);
short deslength = AutonomousSystemTlv.LENGTH;
short desType = AutonomousSystemTlv.TYPE;
subTlvs.add(tlv);
BGPNodeLSIdentifier localNodeDescriptors = new BGPNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength,
desType));
BGPNodeLSNlriVer4 nodeNlri = new BGPNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
new RouteDistinguisher());
nodeNlri.setNodeLSIdentifier(localNodeDescriptors);
for (BgpNodeListener l : controller.nodeListener) {
l.addNode(nodeNlri);
deviceAddCount = nodeRegistry.connected.size();
assertTrue(deviceAddCount == 1);
l.deleteNode(nodeNlri);
deviceAddCount = nodeRegistry.connected.size();
assertTrue(deviceAddCount == 0);
}
}
/* Validate node is not added to the device for invalid URI, RIB count should be zero */
@Test
public void bgpTopologyProviderTestAddDevice2() {
LinkedList<BGPValueType> subTlvs;
BGPValueType tlv = new AutonomousSystemTlv(10);
short deslength = AutonomousSystemTlv.LENGTH;
short desType = AutonomousSystemTlv.TYPE;
subTlvs = new LinkedList<>();
subTlvs.add(tlv);
BGPNodeLSIdentifier localNodeDescriptors = new BGPNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength,
desType));
BGPNodeLSNlriVer4 nodeNlri = new BGPNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
new RouteDistinguisher());
nodeNlri.setNodeLSIdentifier(localNodeDescriptors);
for (BgpNodeListener l : controller.nodeListener) {
l.addNode(nodeNlri);
assertTrue("Failed to add device", (nodeRegistry.connected.size() == 0));
}
}
/* Delete node when node does not exist, RIB count should be zero */
@Test
public void bgpTopologyProviderTestAddDevice3() {
LinkedList<BGPValueType> subTlvs;
BGPValueType tlv = new AutonomousSystemTlv(10);
short deslength = AutonomousSystemTlv.LENGTH;
short desType = AutonomousSystemTlv.TYPE;
subTlvs = new LinkedList<>();
subTlvs.add(tlv);
BGPNodeLSIdentifier localNodeDescriptors = new BGPNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength,
desType));
BGPNodeLSNlriVer4 nodeNlri = new BGPNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
new RouteDistinguisher());
nodeNlri.setNodeLSIdentifier(localNodeDescriptors);
for (BgpNodeListener l : controller.nodeListener) {
l.deleteNode(nodeNlri);
assertTrue("Failed to add device", (nodeRegistry.connected.size() == 0));
}
}
/* Validate link is added to the device validating URI, RIB should get updated properly */
@Test
public void bgpTopologyProviderTestAddLink1() {
NodeDescriptors localNodeDescriptors;
NodeDescriptors remoteNodeDescriptors;
LinkedList<BGPValueType> subTlvs;
LinkedList<BGPValueType> linkDescriptor = new LinkedList<>();
BGPValueType tlvLocalRemoteId;
short deslength = AutonomousSystemTlv.LENGTH;
short desType = AutonomousSystemTlv.TYPE;
BGPValueType tlv = new AutonomousSystemTlv(100);
subTlvs = new LinkedList<>();
subTlvs.add(tlv);
localNodeDescriptors = new NodeDescriptors(subTlvs, deslength, desType);
remoteNodeDescriptors = new NodeDescriptors(subTlvs, deslength, desType);
tlvLocalRemoteId = new LinkLocalRemoteIdentifiersTlv(1, 2);
linkDescriptor.add(tlvLocalRemoteId);
BGPLinkLSIdentifier linkLSIdentifier = new BGPLinkLSIdentifier(localNodeDescriptors, remoteNodeDescriptors,
linkDescriptor);
BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkLSIdentifier, null, false);
for (BgpLinkListener l : controller.linkListener) {
l.addLink(linkNlri);
assertTrue(linkRegistry.connected.size() == 1);
l.deleteLink(linkNlri);
assertTrue(linkRegistry.connected.size() == 0);
}
}
}
......@@ -39,6 +39,7 @@
<module>null</module>
<module>pcep</module>
<module>ovsdb</module>
<module>bgp</module>
</modules>
<dependencies>
......