Shashikanth VH

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

…es of BGP Controller.

Change-Id: Iccd4af75e25c3d4da703bd8e34afb19aabf096a4
......@@ -17,13 +17,14 @@
package org.onosproject.bgp.controller;
import java.util.Map;
import java.util.Set;
import org.onosproject.bgpio.exceptions.BGPParseException;
import org.onosproject.bgpio.protocol.BGPMessage;
/**
* Abstraction of an BGP controller. Serves as a one stop shop for obtaining BGP devices and (un)register listeners
* on bgp events
* Abstraction of an BGP controller. Serves as a one stop shop for obtaining BGP devices and (un)register listeners on
* bgp events
*/
public interface BGPController {
......@@ -43,6 +44,34 @@ public interface BGPController {
BGPPeer getPeer(BGPId bgpId);
/**
* Register a listener for BGP message events.
*
* @param listener the listener to notify
*/
void addListener(BgpNodeListener listener);
/**
* Unregister a listener.
*
* @param listener the listener to unregister
*/
void removeListener(BgpNodeListener listener);
/**
* Register a listener for BGP message events.
*
* @param listener the listener to notify
*/
void addLinkListener(BgpLinkListener listener);
/**
* Unregister a listener.
*
* @param listener the listener to unregister
*/
void removeLinkListener(BgpLinkListener listener);
/**
* Send a message to a particular bgp peer.
*
* @param bgpId the id of the peer to send message.
......@@ -92,4 +121,18 @@ public interface BGPController {
* @return connectedPeers connected peers
*/
Map<BGPId, BGPPeer> connectedPeers();
}
\ No newline at end of file
/**
* Return BGP node listener.
*
* @return node listener
*/
Set<BgpNodeListener> listener();
/**
* Return BGP link listener.
*
* @return link listener
*/
Set<BgpLinkListener> linkListener();
}
......
......@@ -16,7 +16,9 @@
package org.onosproject.bgp.controller.impl;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
......@@ -28,6 +30,8 @@ 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;
......@@ -43,6 +47,10 @@ public class BGPControllerImpl implements BGPController {
protected ConcurrentHashMap<BGPId, BGPPeer> connectedPeers = new ConcurrentHashMap<BGPId, BGPPeer>();
protected BGPPeerManagerImpl peerManager = new BGPPeerManagerImpl();
protected Set<BgpNodeListener> bgpNodeListener = new CopyOnWriteArraySet<>();
protected Set<BgpLinkListener> bgpLinkListener = new CopyOnWriteArraySet<>();
final Controller ctrl = new Controller(this);
private BGPConfig bgpconfig = new BGPConfig();
......@@ -72,6 +80,36 @@ public class BGPControllerImpl implements BGPController {
}
@Override
public void addListener(BgpNodeListener listener) {
this.bgpNodeListener.add(listener);
}
@Override
public void removeListener(BgpNodeListener listener) {
this.bgpNodeListener.remove(listener);
}
@Override
public Set<BgpNodeListener> listener() {
return bgpNodeListener;
}
@Override
public void addLinkListener(BgpLinkListener listener) {
this.bgpLinkListener.add(listener);
}
@Override
public void removeLinkListener(BgpLinkListener listener) {
this.bgpLinkListener.remove(listener);
}
@Override
public Set<BgpLinkListener> linkListener() {
return bgpLinkListener;
}
@Override
public void writeMsg(BGPId bgpId, BGPMessage msg) {
this.getPeer(bgpId).sendMessage(msg);
}
......