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 @@ ...@@ -17,13 +17,14 @@
17 package org.onosproject.bgp.controller; 17 package org.onosproject.bgp.controller;
18 18
19 import java.util.Map; 19 import java.util.Map;
20 +import java.util.Set;
20 21
21 import org.onosproject.bgpio.exceptions.BGPParseException; 22 import org.onosproject.bgpio.exceptions.BGPParseException;
22 import org.onosproject.bgpio.protocol.BGPMessage; 23 import org.onosproject.bgpio.protocol.BGPMessage;
23 24
24 /** 25 /**
25 - * Abstraction of an BGP controller. Serves as a one stop shop for obtaining BGP devices and (un)register listeners 26 + * Abstraction of an BGP controller. Serves as a one stop shop for obtaining BGP devices and (un)register listeners on
26 - * on bgp events 27 + * bgp events
27 */ 28 */
28 public interface BGPController { 29 public interface BGPController {
29 30
...@@ -43,6 +44,34 @@ public interface BGPController { ...@@ -43,6 +44,34 @@ public interface BGPController {
43 BGPPeer getPeer(BGPId bgpId); 44 BGPPeer getPeer(BGPId bgpId);
44 45
45 /** 46 /**
47 + * Register a listener for BGP message events.
48 + *
49 + * @param listener the listener to notify
50 + */
51 + void addListener(BgpNodeListener listener);
52 +
53 + /**
54 + * Unregister a listener.
55 + *
56 + * @param listener the listener to unregister
57 + */
58 + void removeListener(BgpNodeListener listener);
59 +
60 + /**
61 + * Register a listener for BGP message events.
62 + *
63 + * @param listener the listener to notify
64 + */
65 + void addLinkListener(BgpLinkListener listener);
66 +
67 + /**
68 + * Unregister a listener.
69 + *
70 + * @param listener the listener to unregister
71 + */
72 + void removeLinkListener(BgpLinkListener listener);
73 +
74 + /**
46 * Send a message to a particular bgp peer. 75 * Send a message to a particular bgp peer.
47 * 76 *
48 * @param bgpId the id of the peer to send message. 77 * @param bgpId the id of the peer to send message.
...@@ -92,4 +121,18 @@ public interface BGPController { ...@@ -92,4 +121,18 @@ public interface BGPController {
92 * @return connectedPeers connected peers 121 * @return connectedPeers connected peers
93 */ 122 */
94 Map<BGPId, BGPPeer> connectedPeers(); 123 Map<BGPId, BGPPeer> connectedPeers();
124 +
125 + /**
126 + * Return BGP node listener.
127 + *
128 + * @return node listener
129 + */
130 + Set<BgpNodeListener> listener();
131 +
132 + /**
133 + * Return BGP link listener.
134 + *
135 + * @return link listener
136 + */
137 + Set<BgpLinkListener> linkListener();
95 } 138 }
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
16 16
17 package org.onosproject.bgp.controller.impl; 17 package org.onosproject.bgp.controller.impl;
18 18
19 +import java.util.Set;
19 import java.util.concurrent.ConcurrentHashMap; 20 import java.util.concurrent.ConcurrentHashMap;
21 +import java.util.concurrent.CopyOnWriteArraySet;
20 import java.util.concurrent.locks.Lock; 22 import java.util.concurrent.locks.Lock;
21 import java.util.concurrent.locks.ReentrantLock; 23 import java.util.concurrent.locks.ReentrantLock;
22 24
...@@ -28,6 +30,8 @@ import org.onosproject.bgp.controller.BGPCfg; ...@@ -28,6 +30,8 @@ import org.onosproject.bgp.controller.BGPCfg;
28 import org.onosproject.bgp.controller.BGPController; 30 import org.onosproject.bgp.controller.BGPController;
29 import org.onosproject.bgp.controller.BGPId; 31 import org.onosproject.bgp.controller.BGPId;
30 import org.onosproject.bgp.controller.BGPPeer; 32 import org.onosproject.bgp.controller.BGPPeer;
33 +import org.onosproject.bgp.controller.BgpLinkListener;
34 +import org.onosproject.bgp.controller.BgpNodeListener;
31 import org.onosproject.bgp.controller.BgpPeerManager; 35 import org.onosproject.bgp.controller.BgpPeerManager;
32 import org.onosproject.bgpio.exceptions.BGPParseException; 36 import org.onosproject.bgpio.exceptions.BGPParseException;
33 import org.onosproject.bgpio.protocol.BGPMessage; 37 import org.onosproject.bgpio.protocol.BGPMessage;
...@@ -43,6 +47,10 @@ public class BGPControllerImpl implements BGPController { ...@@ -43,6 +47,10 @@ public class BGPControllerImpl implements BGPController {
43 protected ConcurrentHashMap<BGPId, BGPPeer> connectedPeers = new ConcurrentHashMap<BGPId, BGPPeer>(); 47 protected ConcurrentHashMap<BGPId, BGPPeer> connectedPeers = new ConcurrentHashMap<BGPId, BGPPeer>();
44 48
45 protected BGPPeerManagerImpl peerManager = new BGPPeerManagerImpl(); 49 protected BGPPeerManagerImpl peerManager = new BGPPeerManagerImpl();
50 +
51 + protected Set<BgpNodeListener> bgpNodeListener = new CopyOnWriteArraySet<>();
52 + protected Set<BgpLinkListener> bgpLinkListener = new CopyOnWriteArraySet<>();
53 +
46 final Controller ctrl = new Controller(this); 54 final Controller ctrl = new Controller(this);
47 55
48 private BGPConfig bgpconfig = new BGPConfig(); 56 private BGPConfig bgpconfig = new BGPConfig();
...@@ -72,6 +80,36 @@ public class BGPControllerImpl implements BGPController { ...@@ -72,6 +80,36 @@ public class BGPControllerImpl implements BGPController {
72 } 80 }
73 81
74 @Override 82 @Override
83 + public void addListener(BgpNodeListener listener) {
84 + this.bgpNodeListener.add(listener);
85 + }
86 +
87 + @Override
88 + public void removeListener(BgpNodeListener listener) {
89 + this.bgpNodeListener.remove(listener);
90 + }
91 +
92 + @Override
93 + public Set<BgpNodeListener> listener() {
94 + return bgpNodeListener;
95 + }
96 +
97 + @Override
98 + public void addLinkListener(BgpLinkListener listener) {
99 + this.bgpLinkListener.add(listener);
100 + }
101 +
102 + @Override
103 + public void removeLinkListener(BgpLinkListener listener) {
104 + this.bgpLinkListener.remove(listener);
105 + }
106 +
107 + @Override
108 + public Set<BgpLinkListener> linkListener() {
109 + return bgpLinkListener;
110 + }
111 +
112 + @Override
75 public void writeMsg(BGPId bgpId, BGPMessage msg) { 113 public void writeMsg(BGPId bgpId, BGPMessage msg) {
76 this.getPeer(bgpId).sendMessage(msg); 114 this.getPeer(bgpId).sendMessage(msg);
77 } 115 }
......