Priyanka B
Committed by Gerrit Code Review

[Goldeneye] [ONOS-4161] BGP L3 Topology

Change-Id: I81ae4e88f6ab75202b98ed03cbe1597d0f6ddd1e
...@@ -128,4 +128,25 @@ public interface BgpController { ...@@ -128,4 +128,25 @@ public interface BgpController {
128 * @return node listener 128 * @return node listener
129 */ 129 */
130 Set<BgpNodeListener> listener(); 130 Set<BgpNodeListener> listener();
131 +
132 + /**
133 + * Register a listener for BGP message events.
134 + *
135 + * @param listener the listener to notify
136 + */
137 + void addLinkListener(BgpLinkListener listener);
138 +
139 + /**
140 + * Unregister a listener.
141 + *
142 + * @param listener the listener to unregister
143 + */
144 + void removeLinkListener(BgpLinkListener listener);
145 +
146 + /**
147 + * Return BGP link listener.
148 + *
149 + * @return link listener
150 + */
151 + Set<BgpLinkListener> linkListener();
131 } 152 }
......
...@@ -20,12 +20,9 @@ import java.net.URISyntaxException; ...@@ -20,12 +20,9 @@ import java.net.URISyntaxException;
20 import java.util.List; 20 import java.util.List;
21 import java.util.ListIterator; 21 import java.util.ListIterator;
22 22
23 -import org.onosproject.bgpio.exceptions.BgpParseException;
24 import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; 23 import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
25 -import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier;
26 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; 24 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
27 import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; 25 import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors;
28 -import org.onosproject.bgpio.types.AreaIDTlv;
29 import org.onosproject.bgpio.types.AutonomousSystemTlv; 26 import org.onosproject.bgpio.types.AutonomousSystemTlv;
30 import org.onosproject.bgpio.types.BgpLSIdentifierTlv; 27 import org.onosproject.bgpio.types.BgpLSIdentifierTlv;
31 import org.onosproject.bgpio.types.BgpValueType; 28 import org.onosproject.bgpio.types.BgpValueType;
...@@ -49,9 +46,9 @@ public final class BgpDpid { ...@@ -49,9 +46,9 @@ public final class BgpDpid {
49 public static final int NODE_DESCRIPTOR_REMOTE = 2; 46 public static final int NODE_DESCRIPTOR_REMOTE = 2;
50 47
51 /** 48 /**
52 - * Initialize bgp id to generate URI. 49 + * Initialize BGP id to generate URI.
53 * 50 *
54 - * @param linkNlri node Nlri. 51 + * @param linkNlri node NLRI.
55 * @param nodeDescriptorType node descriptor type, local/remote 52 * @param nodeDescriptorType node descriptor type, local/remote
56 */ 53 */
57 public BgpDpid(final BgpLinkLsNlriVer4 linkNlri, int nodeDescriptorType) { 54 public BgpDpid(final BgpLinkLsNlriVer4 linkNlri, int nodeDescriptorType) {
...@@ -61,26 +58,13 @@ public final class BgpDpid { ...@@ -61,26 +58,13 @@ public final class BgpDpid {
61 this.stringBuilder.append("RD=").append(linkNlri.getRouteDistinguisher() 58 this.stringBuilder.append("RD=").append(linkNlri.getRouteDistinguisher()
62 .getRouteDistinguisher()).append(":"); 59 .getRouteDistinguisher()).append(":");
63 } 60 }
64 - 61 + this.stringBuilder.append(":ROUTINGUNIVERSE=").append(((BgpLinkLsNlriVer4) linkNlri).getIdentifier());
65 - try {
66 - if ((linkNlri.getProtocolId() == BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_ONE)
67 - || (linkNlri.getProtocolId() == BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO)) {
68 - this.stringBuilder.append("PROTO=").append("ISIS").append(":ID=")
69 - .append(linkNlri.getIdentifier());
70 - } else {
71 - this.stringBuilder.append("PROTO=").append(linkNlri.getProtocolId()).append(":ID=")
72 - .append(linkNlri.getIdentifier());
73 - }
74 62
75 if (nodeDescriptorType == NODE_DESCRIPTOR_LOCAL) { 63 if (nodeDescriptorType == NODE_DESCRIPTOR_LOCAL) {
76 add(linkNlri.localNodeDescriptors()); 64 add(linkNlri.localNodeDescriptors());
77 } else if (nodeDescriptorType == NODE_DESCRIPTOR_REMOTE) { 65 } else if (nodeDescriptorType == NODE_DESCRIPTOR_REMOTE) {
78 add(linkNlri.remoteNodeDescriptors()); 66 add(linkNlri.remoteNodeDescriptors());
79 } 67 }
80 - } catch (BgpParseException e) {
81 - log.info("Exception BgpId string: " + e.toString());
82 - }
83 -
84 } 68 }
85 69
86 /* 70 /*
...@@ -96,72 +80,52 @@ public final class BgpDpid { ...@@ -96,72 +80,52 @@ public final class BgpDpid {
96 } 80 }
97 81
98 /** 82 /**
99 - * Initialize bgp id to generate URI. 83 + * Initialize BGP id to generate URI.
100 * 84 *
101 - * @param nodeNlri node Nlri. 85 + * @param nlri node NLRI.
102 */ 86 */
103 - public BgpDpid(final BgpNodeLSNlriVer4 nodeNlri) { 87 + public BgpDpid(final BgpNodeLSNlriVer4 nlri) {
104 this.stringBuilder = new StringBuilder(""); 88 this.stringBuilder = new StringBuilder("");
105 - 89 + if (((BgpNodeLSNlriVer4) nlri).getRouteDistinguisher() != null) {
106 - if (nodeNlri.getRouteDistinguisher() != null) { 90 + this.stringBuilder.append("RD=")
107 - this.stringBuilder.append("RD=").append(nodeNlri.getRouteDistinguisher() 91 + .append(((BgpNodeLSNlriVer4) nlri).getRouteDistinguisher().getRouteDistinguisher()).append(":");
108 - .getRouteDistinguisher()).append(":");
109 } 92 }
110 93
111 - try { 94 + this.stringBuilder.append(":ROUTINGUNIVERSE=").append(((BgpNodeLSNlriVer4) nlri).getIdentifier());
112 - if ((nodeNlri.getProtocolId() == BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_ONE) 95 + add(((BgpNodeLSNlriVer4) nlri).getLocalNodeDescriptors().getNodedescriptors());
113 - || (nodeNlri.getProtocolId() == BgpNodeLSNlriVer4.ProtocolType.ISIS_LEVEL_TWO)) { 96 + log.info("BgpDpid :: add");
114 -
115 - this.stringBuilder.append("PROTO=").append("ISIS").append(":ID=")
116 - .append(nodeNlri.getIdentifier());
117 - } else {
118 - this.stringBuilder.append("PROTO=").append(nodeNlri.getProtocolId()).append(":ID=")
119 - .append(nodeNlri.getIdentifier());
120 } 97 }
121 - add(nodeNlri.getLocalNodeDescriptors());
122 98
123 - } catch (BgpParseException e) { 99 + /**
124 - log.info("Exception node string: " + e.toString()); 100 + * Obtains instance of this class by appending stringBuilder with node descriptor value.
125 - } 101 + *
126 - } 102 + * @param value node descriptor
127 - 103 + * @return instance of this class
128 - BgpDpid add(final Object value) { 104 + */
129 - NodeDescriptors nodeDescriptors = null; 105 + public BgpDpid add(final NodeDescriptors value) {
130 - if (value instanceof BgpNodeLSIdentifier) { 106 + log.info("BgpDpid :: add function");
131 - BgpNodeLSIdentifier nodeLsIdentifier = (BgpNodeLSIdentifier) value; 107 + if (value != null) {
132 - nodeDescriptors = nodeLsIdentifier.getNodedescriptors(); 108 + List<BgpValueType> subTlvs = value.getSubTlvs();
133 - } else if (value instanceof NodeDescriptors) {
134 - nodeDescriptors = (NodeDescriptors) value;
135 - }
136 -
137 - if (nodeDescriptors != null) {
138 - List<BgpValueType> subTlvs = nodeDescriptors.getSubTlvs();
139 ListIterator<BgpValueType> listIterator = subTlvs.listIterator(); 109 ListIterator<BgpValueType> listIterator = subTlvs.listIterator();
140 while (listIterator.hasNext()) { 110 while (listIterator.hasNext()) {
141 BgpValueType tlv = listIterator.next(); 111 BgpValueType tlv = listIterator.next();
142 if (tlv.getType() == AutonomousSystemTlv.TYPE) { 112 if (tlv.getType() == AutonomousSystemTlv.TYPE) {
143 - AutonomousSystemTlv autonomousSystem = (AutonomousSystemTlv) tlv; 113 + this.stringBuilder.append(":ASN=").append(((AutonomousSystemTlv) tlv).getAsNum());
144 - this.stringBuilder.append(":AS=").append(autonomousSystem.getAsNum());
145 } else if (tlv.getType() == BgpLSIdentifierTlv.TYPE) { 114 } else if (tlv.getType() == BgpLSIdentifierTlv.TYPE) {
146 - BgpLSIdentifierTlv lsIdentifierTlv = (BgpLSIdentifierTlv) tlv; 115 + this.stringBuilder.append(":DOMAINID=").append(((BgpLSIdentifierTlv) tlv).getBgpLsIdentifier());
147 - this.stringBuilder.append(":LSID=").append(lsIdentifierTlv.getBgpLsIdentifier());
148 - } else if (tlv.getType() == AreaIDTlv.TYPE) {
149 - AreaIDTlv areaIdTlv = (AreaIDTlv) tlv;
150 - this.stringBuilder.append(":AREA=").append(areaIdTlv.getAreaID());
151 } else if (tlv.getType() == NodeDescriptors.IGP_ROUTERID_TYPE) { 116 } else if (tlv.getType() == NodeDescriptors.IGP_ROUTERID_TYPE) {
152 if (tlv instanceof IsIsNonPseudonode) { 117 if (tlv instanceof IsIsNonPseudonode) {
153 - IsIsNonPseudonode isisNonPseudonode = (IsIsNonPseudonode) tlv; 118 + this.stringBuilder.append(":ISOID=").append(
154 - this.stringBuilder.append(":ISOID=").append(isoNodeIdString(isisNonPseudonode.getIsoNodeId())); 119 + isoNodeIdString(((IsIsNonPseudonode) tlv).getIsoNodeId()));
155 } else if (tlv instanceof IsIsPseudonode) { 120 } else if (tlv instanceof IsIsPseudonode) {
156 - IsIsPseudonode isisPseudonode = (IsIsPseudonode) tlv; 121 + IsIsPseudonode isisPseudonode = ((IsIsPseudonode) tlv);
157 - this.stringBuilder.append(":ISOID=").append(isoNodeIdString(isisPseudonode.getIsoNodeId())); 122 + this.stringBuilder.append(":ISOID=").append(
123 + isoNodeIdString(((IsIsPseudonode) tlv).getIsoNodeId()));
158 this.stringBuilder.append(":PSN=").append(isisPseudonode.getPsnIdentifier()); 124 this.stringBuilder.append(":PSN=").append(isisPseudonode.getPsnIdentifier());
159 } else if (tlv instanceof OspfNonPseudonode) { 125 } else if (tlv instanceof OspfNonPseudonode) {
160 - OspfNonPseudonode ospfNonPseudonode = (OspfNonPseudonode) tlv; 126 + this.stringBuilder.append(":RID=").append(((OspfNonPseudonode) tlv).getrouterID());
161 - this.stringBuilder.append(":RID=").append(ospfNonPseudonode.getrouterID());
162 } else if (tlv instanceof OspfPseudonode) { 127 } else if (tlv instanceof OspfPseudonode) {
163 - OspfPseudonode ospfPseudonode = (OspfPseudonode) tlv; 128 + this.stringBuilder.append(":RID=").append(((OspfPseudonode) tlv).getrouterID());
164 - this.stringBuilder.append(":RID=").append(ospfPseudonode.getrouterID());
165 } 129 }
166 } 130 }
167 } 131 }
......
...@@ -12,24 +12,29 @@ ...@@ -12,24 +12,29 @@
12 */ 12 */
13 package org.onosproject.bgp.controller; 13 package org.onosproject.bgp.controller;
14 14
15 +import org.onosproject.bgpio.exceptions.BgpParseException;
15 import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; 16 import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
17 +import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
16 18
17 /** 19 /**
18 - * Allows for providers interested in Link events to be notified. 20 + * Allows for providers interested in link events to be notified.
19 */ 21 */
20 public interface BgpLinkListener { 22 public interface BgpLinkListener {
21 23
22 /** 24 /**
23 - * Notify that got a packet of link from network and need do processing. 25 + * Notify that got a packet of link from network and adds link.
24 * 26 *
25 - * @param linkNlri bgp link 27 + * @param linkNlri BGP link NLRI
28 + * @param details path attributes and NLRI information
29 + * @throws BgpParseException BGP parse exception
26 */ 30 */
27 - void addLink(BgpLinkLsNlriVer4 linkNlri); 31 + void addLink(BgpLinkLsNlriVer4 linkNlri, PathAttrNlriDetails details) throws BgpParseException;
28 32
29 /** 33 /**
30 - * Notify that got a packet of link from network and need do processing. 34 + * Notify that got a packet of link from network and remove link.
31 * 35 *
32 - * @param linkNlri bgp link 36 + * @param linkNlri BGP link NLRI
37 + * @throws BgpParseException BGP parse exception
33 */ 38 */
34 - void deleteLink(BgpLinkLsNlriVer4 linkNlri); 39 + void deleteLink(BgpLinkLsNlriVer4 linkNlri) throws BgpParseException;
35 } 40 }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 13
14 package org.onosproject.bgp.controller; 14 package org.onosproject.bgp.controller;
15 15
16 +import org.onosproject.bgpio.exceptions.BgpParseException;
16 import org.onosproject.bgpio.protocol.BgpLSNlri; 17 import org.onosproject.bgpio.protocol.BgpLSNlri;
17 import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; 18 import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
18 import org.onosproject.bgpio.types.RouteDistinguisher; 19 import org.onosproject.bgpio.types.RouteDistinguisher;
...@@ -27,16 +28,18 @@ public interface BgpLocalRib { ...@@ -27,16 +28,18 @@ public interface BgpLocalRib {
27 * 28 *
28 * @param sessionInfo session info 29 * @param sessionInfo session info
29 * @param nlri network layer reach info 30 * @param nlri network layer reach info
30 - * @param details nlri details 31 + * @param details path attributes and NLRI information
32 + * @throws BgpParseException while adding NLRI to local rib
31 */ 33 */
32 - void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details); 34 + void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details) throws BgpParseException;
33 35
34 /** 36 /**
35 * Removes NLRI identifier if it exists. 37 * Removes NLRI identifier if it exists.
36 * 38 *
37 * @param nlri info 39 * @param nlri info
40 + * @throws BgpParseException while deleting NLRI from local rib
38 */ 41 */
39 - void delete(BgpLSNlri nlri); 42 + void delete(BgpLSNlri nlri) throws BgpParseException;
40 43
41 /** 44 /**
42 * Update NLRI identifier mapped with route distinguisher if it exists in tree otherwise add NLRI infomation mapped 45 * Update NLRI identifier mapped with route distinguisher if it exists in tree otherwise add NLRI infomation mapped
...@@ -46,15 +49,17 @@ public interface BgpLocalRib { ...@@ -46,15 +49,17 @@ public interface BgpLocalRib {
46 * @param nlri info 49 * @param nlri info
47 * @param details has pathattribute, protocol id and identifier 50 * @param details has pathattribute, protocol id and identifier
48 * @param routeDistinguisher unique for each VPN 51 * @param routeDistinguisher unique for each VPN
52 + * @throws BgpParseException while adding NLRI updation
49 */ 53 */
50 void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details, 54 void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details,
51 - RouteDistinguisher routeDistinguisher); 55 + RouteDistinguisher routeDistinguisher) throws BgpParseException;
52 56
53 /** 57 /**
54 * Removes VPN NLRI identifier mapped to route distinguisher if it exists. 58 * Removes VPN NLRI identifier mapped to route distinguisher if it exists.
55 * 59 *
56 * @param nlri info 60 * @param nlri info
57 * @param routeDistinguisher unique for each VPN 61 * @param routeDistinguisher unique for each VPN
62 + * @throws BgpParseException while deleting NLRI from local rib
58 */ 63 */
59 - void delete(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher); 64 + void delete(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher) throws BgpParseException;
60 } 65 }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
13 package org.onosproject.bgp.controller; 13 package org.onosproject.bgp.controller;
14 14
15 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; 15 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
16 +import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
16 17
17 /** 18 /**
18 * Allows for providers interested in node events to be notified. 19 * Allows for providers interested in node events to be notified.
...@@ -22,14 +23,15 @@ public interface BgpNodeListener { ...@@ -22,14 +23,15 @@ public interface BgpNodeListener {
22 /** 23 /**
23 * Notifies that the node was added. 24 * Notifies that the node was added.
24 * 25 *
25 - * @param nodeNlri node rechability info 26 + * @param nodeNlri node reachability info
27 + * @param details attributes and nlri details
26 */ 28 */
27 - void addNode(BgpNodeLSNlriVer4 nodeNlri); 29 + void addNode(BgpNodeLSNlriVer4 nodeNlri, PathAttrNlriDetails details);
28 30
29 /** 31 /**
30 * Notifies that the node was removed. 32 * Notifies that the node was removed.
31 * 33 *
32 - * @param nodeNlri node rechability info 34 + * @param nodeNlri node reachability info
33 */ 35 */
34 void deleteNode(BgpNodeLSNlriVer4 nodeNlri); 36 void deleteNode(BgpNodeLSNlriVer4 nodeNlri);
35 } 37 }
......
...@@ -260,6 +260,14 @@ public class NodeDescriptors { ...@@ -260,6 +260,14 @@ public class NodeDescriptors {
260 log.debug("NodeDescriptor compare subtlv's"); 260 log.debug("NodeDescriptor compare subtlv's");
261 for (BgpValueType tlv : ((NodeDescriptors) o).subTlvs) { 261 for (BgpValueType tlv : ((NodeDescriptors) o).subTlvs) {
262 if (tlv.getType() == tlv1.getType()) { 262 if (tlv.getType() == tlv1.getType()) {
263 + if (tlv.getType() == IGP_ROUTERID_TYPE) {
264 + if ((tlv1 instanceof IsIsNonPseudonode && tlv instanceof IsIsPseudonode)
265 + || (tlv1 instanceof IsIsPseudonode && tlv instanceof IsIsNonPseudonode)
266 + || (tlv1 instanceof OspfNonPseudonode && tlv instanceof OspfPseudonode)
267 + || (tlv1 instanceof OspfPseudonode && tlv instanceof OspfNonPseudonode)) {
268 + continue;
269 + }
270 + }
263 int result = subTlvs.get(subTlvs.indexOf(tlv1)).compareTo( 271 int result = subTlvs.get(subTlvs.indexOf(tlv1)).compareTo(
264 ((NodeDescriptors) o).subTlvs.get(((NodeDescriptors) o).subTlvs.indexOf(tlv))); 272 ((NodeDescriptors) o).subTlvs.get(((NodeDescriptors) o).subTlvs.indexOf(tlv)));
265 if (result != 0) { 273 if (result != 0) {
......
...@@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.Service; ...@@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.Service;
23 import org.onosproject.bgp.controller.BgpCfg; 23 import org.onosproject.bgp.controller.BgpCfg;
24 import org.onosproject.bgp.controller.BgpController; 24 import org.onosproject.bgp.controller.BgpController;
25 import org.onosproject.bgp.controller.BgpId; 25 import org.onosproject.bgp.controller.BgpId;
26 +import org.onosproject.bgp.controller.BgpLinkListener;
26 import org.onosproject.bgp.controller.BgpLocalRib; 27 import org.onosproject.bgp.controller.BgpLocalRib;
27 import org.onosproject.bgp.controller.BgpNodeListener; 28 import org.onosproject.bgp.controller.BgpNodeListener;
28 import org.onosproject.bgp.controller.BgpPeer; 29 import org.onosproject.bgp.controller.BgpPeer;
...@@ -58,6 +59,7 @@ public class BgpControllerImpl implements BgpController { ...@@ -58,6 +59,7 @@ public class BgpControllerImpl implements BgpController {
58 private BgpLocalRib bgplocalRibVpn = new BgpLocalRibImpl(this); 59 private BgpLocalRib bgplocalRibVpn = new BgpLocalRibImpl(this);
59 60
60 protected Set<BgpNodeListener> bgpNodeListener = new CopyOnWriteArraySet<>(); 61 protected Set<BgpNodeListener> bgpNodeListener = new CopyOnWriteArraySet<>();
62 + protected Set<BgpLinkListener> bgpLinkListener = new CopyOnWriteArraySet<>();
61 63
62 final Controller ctrl = new Controller(this); 64 final Controller ctrl = new Controller(this);
63 65
...@@ -278,4 +280,19 @@ public class BgpControllerImpl implements BgpController { ...@@ -278,4 +280,19 @@ public class BgpControllerImpl implements BgpController {
278 public BgpLocalRib bgpLocalRibVpn() { 280 public BgpLocalRib bgpLocalRibVpn() {
279 return bgplocalRibVpn; 281 return bgplocalRibVpn;
280 } 282 }
283 +
284 + @Override
285 + public void addLinkListener(BgpLinkListener listener) {
286 + this.bgpLinkListener.add(listener);
287 + }
288 +
289 + @Override
290 + public void removeLinkListener(BgpLinkListener listener) {
291 + this.bgpLinkListener.remove(listener);
292 + }
293 +
294 + @Override
295 + public Set<BgpLinkListener> linkListener() {
296 + return bgpLinkListener;
297 + }
281 } 298 }
......
...@@ -14,11 +14,14 @@ ...@@ -14,11 +14,14 @@
14 package org.onosproject.bgp.controller.impl; 14 package org.onosproject.bgp.controller.impl;
15 15
16 import com.google.common.base.MoreObjects; 16 import com.google.common.base.MoreObjects;
17 +
17 import org.onosproject.bgp.controller.BgpController; 18 import org.onosproject.bgp.controller.BgpController;
18 import org.onosproject.bgp.controller.BgpId; 19 import org.onosproject.bgp.controller.BgpId;
20 +import org.onosproject.bgp.controller.BgpLinkListener;
19 import org.onosproject.bgp.controller.BgpLocalRib; 21 import org.onosproject.bgp.controller.BgpLocalRib;
20 import org.onosproject.bgp.controller.BgpNodeListener; 22 import org.onosproject.bgp.controller.BgpNodeListener;
21 import org.onosproject.bgp.controller.BgpSessionInfo; 23 import org.onosproject.bgp.controller.BgpSessionInfo;
24 +import org.onosproject.bgpio.exceptions.BgpParseException;
22 import org.onosproject.bgpio.protocol.BgpLSNlri; 25 import org.onosproject.bgpio.protocol.BgpLSNlri;
23 import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier; 26 import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier;
24 import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; 27 import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
...@@ -116,7 +119,7 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -116,7 +119,7 @@ public class BgpLocalRibImpl implements BgpLocalRib {
116 } 119 }
117 120
118 @Override 121 @Override
119 - public void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details) { 122 + public void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details) throws BgpParseException {
120 int decisionResult; 123 int decisionResult;
121 124
122 log.debug("Add to local RIB {}", details.toString()); 125 log.debug("Add to local RIB {}", details.toString());
...@@ -133,13 +136,16 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -133,13 +136,16 @@ public class BgpLocalRibImpl implements BgpLocalRib {
133 // Compare local RIB entry with the current attribute 136 // Compare local RIB entry with the current attribute
134 decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib); 137 decisionResult = selectionAlgo.compare(nodeTree.get(nodeLsIdentifier), detailsLocRib);
135 if (decisionResult < 0) { 138 if (decisionResult < 0) {
139 + for (BgpNodeListener l : bgpController.listener()) {
140 + l.addNode((BgpNodeLSNlriVer4) nlri, details);
141 + }
136 nodeTree.replace(nodeLsIdentifier, detailsLocRib); 142 nodeTree.replace(nodeLsIdentifier, detailsLocRib);
137 log.debug("Local RIB update node: {}", detailsLocRib.toString()); 143 log.debug("Local RIB update node: {}", detailsLocRib.toString());
138 } 144 }
139 } else { 145 } else {
140 nodeTree.put(nodeLsIdentifier, detailsLocRib); 146 nodeTree.put(nodeLsIdentifier, detailsLocRib);
141 for (BgpNodeListener l : bgpController.listener()) { 147 for (BgpNodeListener l : bgpController.listener()) {
142 - l.addNode((BgpNodeLSNlriVer4) nlri); 148 + l.addNode((BgpNodeLSNlriVer4) nlri, details);
143 } 149 }
144 log.debug("Local RIB ad node: {}", detailsLocRib.toString()); 150 log.debug("Local RIB ad node: {}", detailsLocRib.toString());
145 } 151 }
...@@ -151,10 +157,16 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -151,10 +157,16 @@ public class BgpLocalRibImpl implements BgpLocalRib {
151 decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib); 157 decisionResult = selectionAlgo.compare(linkTree.get(linkLsIdentifier), detailsLocRib);
152 if (decisionResult < 0) { 158 if (decisionResult < 0) {
153 linkTree.replace(linkLsIdentifier, detailsLocRib); 159 linkTree.replace(linkLsIdentifier, detailsLocRib);
160 + for (BgpLinkListener l : bgpController.linkListener()) {
161 + l.addLink((BgpLinkLsNlriVer4) nlri, details);
162 + }
154 log.debug("Local RIB update link: {}", detailsLocRib.toString()); 163 log.debug("Local RIB update link: {}", detailsLocRib.toString());
155 } 164 }
156 } else { 165 } else {
157 linkTree.put(linkLsIdentifier, detailsLocRib); 166 linkTree.put(linkLsIdentifier, detailsLocRib);
167 + for (BgpLinkListener l : bgpController.linkListener()) {
168 + l.addLink((BgpLinkLsNlriVer4) nlri, details);
169 + }
158 log.debug("Local RIB add link: {}", detailsLocRib.toString()); 170 log.debug("Local RIB add link: {}", detailsLocRib.toString());
159 } 171 }
160 } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) { 172 } else if (nlri instanceof BgpPrefixIPv4LSNlriVer4) {
...@@ -175,7 +187,7 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -175,7 +187,7 @@ public class BgpLocalRibImpl implements BgpLocalRib {
175 } 187 }
176 188
177 @Override 189 @Override
178 - public void delete(BgpLSNlri nlri) { 190 + public void delete(BgpLSNlri nlri) throws BgpParseException {
179 log.debug("Delete from local RIB."); 191 log.debug("Delete from local RIB.");
180 192
181 // Update local RIB 193 // Update local RIB
...@@ -186,8 +198,9 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -186,8 +198,9 @@ public class BgpLocalRibImpl implements BgpLocalRib {
186 * Update local RIB based on selection algorithm. 198 * Update local RIB based on selection algorithm.
187 * 199 *
188 * @param nlri NLRI to update 200 * @param nlri NLRI to update
201 + * @throws BgpParseException while updating to local RIB
189 */ 202 */
190 - public void decisionProcess(BgpLSNlri nlri) { 203 + public void decisionProcess(BgpLSNlri nlri) throws BgpParseException {
191 checkNotNull(nlri); 204 checkNotNull(nlri);
192 if (nlri instanceof BgpNodeLSNlriVer4) { 205 if (nlri instanceof BgpNodeLSNlriVer4) {
193 selectionProcessNode(nlri, false); 206 selectionProcessNode(nlri, false);
...@@ -203,8 +216,9 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -203,8 +216,9 @@ public class BgpLocalRibImpl implements BgpLocalRib {
203 * 216 *
204 * @param nlri NLRI to update 217 * @param nlri NLRI to update
205 * @param routeDistinguisher VPN id to update 218 * @param routeDistinguisher VPN id to update
219 + * @throws BgpParseException BGP parse exception
206 */ 220 */
207 - public void decisionProcess(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher) { 221 + public void decisionProcess(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher) throws BgpParseException {
208 checkNotNull(nlri); 222 checkNotNull(nlri);
209 if (nlri instanceof BgpNodeLSNlriVer4) { 223 if (nlri instanceof BgpNodeLSNlriVer4) {
210 if (vpnNodeTree.containsKey(routeDistinguisher)) { 224 if (vpnNodeTree.containsKey(routeDistinguisher)) {
...@@ -235,8 +249,9 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -235,8 +249,9 @@ public class BgpLocalRibImpl implements BgpLocalRib {
235 * 249 *
236 * @param nlri NLRI to update 250 * @param nlri NLRI to update
237 * @param isVpnRib true if VPN local RIB, otherwise false 251 * @param isVpnRib true if VPN local RIB, otherwise false
252 + * @throws BgpParseException throws BGP parse exception
238 */ 253 */
239 - public void selectionProcessNode(BgpLSNlri nlri, boolean isVpnRib) { 254 + public void selectionProcessNode(BgpLSNlri nlri, boolean isVpnRib) throws BgpParseException {
240 BgpPeerImpl peer; 255 BgpPeerImpl peer;
241 BgpSessionInfo sessionInfo; 256 BgpSessionInfo sessionInfo;
242 int decisionResult; 257 int decisionResult;
...@@ -298,8 +313,9 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -298,8 +313,9 @@ public class BgpLocalRibImpl implements BgpLocalRib {
298 * 313 *
299 * @param nlri NLRI to update 314 * @param nlri NLRI to update
300 * @param isVpnRib true if VPN local RIB, otherwise false 315 * @param isVpnRib true if VPN local RIB, otherwise false
316 + * @throws BgpParseException BGP parse exception
301 */ 317 */
302 - public void selectionProcessLink(BgpLSNlri nlri, boolean isVpnRib) { 318 + public void selectionProcessLink(BgpLSNlri nlri, boolean isVpnRib) throws BgpParseException {
303 BgpPeerImpl peer; 319 BgpPeerImpl peer;
304 BgpSessionInfo sessionInfo; 320 BgpSessionInfo sessionInfo;
305 int decisionResult; 321 int decisionResult;
...@@ -309,6 +325,9 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -309,6 +325,9 @@ public class BgpLocalRibImpl implements BgpLocalRib {
309 325
310 if (linkTree.containsKey(linkLsIdentifier)) { 326 if (linkTree.containsKey(linkLsIdentifier)) {
311 log.debug("Local RIB remove link: {}", linkLsIdentifier.toString()); 327 log.debug("Local RIB remove link: {}", linkLsIdentifier.toString());
328 + for (BgpLinkListener l : bgpController.linkListener()) {
329 + l.deleteLink((BgpLinkLsNlriVer4) nlri);
330 + }
312 linkTree.remove(linkLsIdentifier); 331 linkTree.remove(linkLsIdentifier);
313 } 332 }
314 333
...@@ -361,8 +380,9 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -361,8 +380,9 @@ public class BgpLocalRibImpl implements BgpLocalRib {
361 * 380 *
362 * @param nlri NLRI to update 381 * @param nlri NLRI to update
363 * @param isVpnRib true if VPN local RIB, otherwise false 382 * @param isVpnRib true if VPN local RIB, otherwise false
383 + * @throws BgpParseException BGP parse exception
364 */ 384 */
365 - public void selectionProcessPrefix(BgpLSNlri nlri, boolean isVpnRib) { 385 + public void selectionProcessPrefix(BgpLSNlri nlri, boolean isVpnRib) throws BgpParseException {
366 BgpPeerImpl peer; 386 BgpPeerImpl peer;
367 BgpSessionInfo sessionInfo; 387 BgpSessionInfo sessionInfo;
368 int decisionResult; 388 int decisionResult;
...@@ -419,7 +439,7 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -419,7 +439,7 @@ public class BgpLocalRibImpl implements BgpLocalRib {
419 439
420 @Override 440 @Override
421 public void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details, 441 public void add(BgpSessionInfo sessionInfo, BgpLSNlri nlri, PathAttrNlriDetails details,
422 - RouteDistinguisher routeDistinguisher) { 442 + RouteDistinguisher routeDistinguisher) throws BgpParseException {
423 add(sessionInfo, nlri, details); 443 add(sessionInfo, nlri, details);
424 if (nlri instanceof BgpNodeLSNlriVer4) { 444 if (nlri instanceof BgpNodeLSNlriVer4) {
425 if (!vpnNodeTree.containsKey(routeDistinguisher)) { 445 if (!vpnNodeTree.containsKey(routeDistinguisher)) {
...@@ -437,7 +457,7 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -437,7 +457,7 @@ public class BgpLocalRibImpl implements BgpLocalRib {
437 } 457 }
438 458
439 @Override 459 @Override
440 - public void delete(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher) { 460 + public void delete(BgpLSNlri nlri, RouteDistinguisher routeDistinguisher) throws BgpParseException {
441 // Update local RIB 461 // Update local RIB
442 decisionProcess(nlri, routeDistinguisher); 462 decisionProcess(nlri, routeDistinguisher);
443 } 463 }
...@@ -446,8 +466,9 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -446,8 +466,9 @@ public class BgpLocalRibImpl implements BgpLocalRib {
446 * Update local RIB node based on avaliable peer adjacency RIB. 466 * Update local RIB node based on avaliable peer adjacency RIB.
447 * 467 *
448 * @param o adjacency-in/VPN adjacency-in 468 * @param o adjacency-in/VPN adjacency-in
469 + * @throws BgpParseException BGP parse exception
449 */ 470 */
450 - public void localRibUpdateNode(Object o) { 471 + public void localRibUpdateNode(Object o) throws BgpParseException {
451 472
452 if (o instanceof AdjRibIn) { 473 if (o instanceof AdjRibIn) {
453 AdjRibIn adjRib = (AdjRibIn) o; 474 AdjRibIn adjRib = (AdjRibIn) o;
...@@ -487,8 +508,9 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -487,8 +508,9 @@ public class BgpLocalRibImpl implements BgpLocalRib {
487 * Update localRIB link based on avaliable peer adjacency RIB. 508 * Update localRIB link based on avaliable peer adjacency RIB.
488 * 509 *
489 * @param o adjacency-in/VPN adjacency-in 510 * @param o adjacency-in/VPN adjacency-in
511 + * @throws BgpParseException BGP parse exceptions
490 */ 512 */
491 - public void localRibUpdateLink(Object o) { 513 + public void localRibUpdateLink(Object o) throws BgpParseException {
492 514
493 if (o instanceof AdjRibIn) { 515 if (o instanceof AdjRibIn) {
494 AdjRibIn adjRib = (AdjRibIn) o; 516 AdjRibIn adjRib = (AdjRibIn) o;
...@@ -528,8 +550,9 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -528,8 +550,9 @@ public class BgpLocalRibImpl implements BgpLocalRib {
528 * Update localRIB prefix based on avaliable peer adjacency RIB. 550 * Update localRIB prefix based on avaliable peer adjacency RIB.
529 * 551 *
530 * @param o instance of adjacency-in/VPN adjacency-in 552 * @param o instance of adjacency-in/VPN adjacency-in
553 + * @throws BgpParseException BGP parse exception
531 */ 554 */
532 - public void localRibUpdatePrefix(Object o) { 555 + public void localRibUpdatePrefix(Object o) throws BgpParseException {
533 556
534 if (o instanceof AdjRibIn) { 557 if (o instanceof AdjRibIn) {
535 AdjRibIn adjRib = (AdjRibIn) o; 558 AdjRibIn adjRib = (AdjRibIn) o;
...@@ -572,8 +595,9 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -572,8 +595,9 @@ public class BgpLocalRibImpl implements BgpLocalRib {
572 * Update localRIB. 595 * Update localRIB.
573 * 596 *
574 * @param adjRibIn adjacency RIB-in 597 * @param adjRibIn adjacency RIB-in
598 + * @throws BgpParseException BGP parse exception
575 */ 599 */
576 - public void localRibUpdate(AdjRibIn adjRibIn) { 600 + public void localRibUpdate(AdjRibIn adjRibIn) throws BgpParseException {
577 log.debug("Update local RIB."); 601 log.debug("Update local RIB.");
578 602
579 localRibUpdateNode(adjRibIn); 603 localRibUpdateNode(adjRibIn);
...@@ -585,8 +609,9 @@ public class BgpLocalRibImpl implements BgpLocalRib { ...@@ -585,8 +609,9 @@ public class BgpLocalRibImpl implements BgpLocalRib {
585 * Update localRIB. 609 * Update localRIB.
586 * 610 *
587 * @param vpnAdjRibIn VPN adjacency RIB-in 611 * @param vpnAdjRibIn VPN adjacency RIB-in
612 + * @throws BgpParseException BGP parse exception
588 */ 613 */
589 - public void localRibUpdate(VpnAdjRibIn vpnAdjRibIn) { 614 + public void localRibUpdate(VpnAdjRibIn vpnAdjRibIn) throws BgpParseException {
590 log.debug("Update VPN local RIB."); 615 log.debug("Update VPN local RIB.");
591 616
592 localRibUpdateNode(vpnAdjRibIn); 617 localRibUpdateNode(vpnAdjRibIn);
......
...@@ -425,8 +425,9 @@ public class BgpPeerImpl implements BgpPeer { ...@@ -425,8 +425,9 @@ public class BgpPeerImpl implements BgpPeer {
425 * 425 *
426 * @param peerImpl BGP peer instance 426 * @param peerImpl BGP peer instance
427 * @param nlri NLRI information 427 * @param nlri NLRI information
428 + * @throws BgpParseException BGP parse exception
428 */ 429 */
429 - public void callRemove(BgpPeerImpl peerImpl, List<BgpLSNlri> nlri) { 430 + public void callRemove(BgpPeerImpl peerImpl, List<BgpLSNlri> nlri) throws BgpParseException {
430 ListIterator<BgpLSNlri> listIterator = nlri.listIterator(); 431 ListIterator<BgpLSNlri> listIterator = nlri.listIterator();
431 while (listIterator.hasNext()) { 432 while (listIterator.hasNext()) {
432 BgpLSNlri nlriInfo = listIterator.next(); 433 BgpLSNlri nlriInfo = listIterator.next();
...@@ -479,8 +480,9 @@ public class BgpPeerImpl implements BgpPeer { ...@@ -479,8 +480,9 @@ public class BgpPeerImpl implements BgpPeer {
479 /** 480 /**
480 * Update localRIB on peer disconnect. 481 * Update localRIB on peer disconnect.
481 * 482 *
483 + * @throws BgpParseException while updating local RIB
482 */ 484 */
483 - public void updateLocalRibOnPeerDisconnect() { 485 + public void updateLocalRibOnPeerDisconnect() throws BgpParseException {
484 BgpLocalRibImpl localRib = (BgpLocalRibImpl) bgplocalRib; 486 BgpLocalRibImpl localRib = (BgpLocalRibImpl) bgplocalRib;
485 BgpLocalRibImpl localRibVpn = (BgpLocalRibImpl) bgplocalRibVpn; 487 BgpLocalRibImpl localRibVpn = (BgpLocalRibImpl) bgplocalRibVpn;
486 488
...@@ -490,7 +492,6 @@ public class BgpPeerImpl implements BgpPeer { ...@@ -490,7 +492,6 @@ public class BgpPeerImpl implements BgpPeer {
490 492
491 /** 493 /**
492 * Update peer flow specification RIB on peer disconnect. 494 * Update peer flow specification RIB on peer disconnect.
493 - *
494 */ 495 */
495 public void updateFlowSpecOnPeerDisconnect() { 496 public void updateFlowSpecOnPeerDisconnect() {
496 497
......
...@@ -15,6 +15,11 @@ package org.onosproject.provider.bgp.topology.impl; ...@@ -15,6 +15,11 @@ package org.onosproject.provider.bgp.topology.impl;
15 15
16 import static org.onosproject.bgp.controller.BgpDpid.uri; 16 import static org.onosproject.bgp.controller.BgpDpid.uri;
17 import static org.onosproject.net.DeviceId.deviceId; 17 import static org.onosproject.net.DeviceId.deviceId;
18 +import static org.onosproject.net.Device.Type.ROUTER;
19 +import static org.onosproject.net.Device.Type.VIRTUAL;
20 +
21 +import java.util.List;
22 +import java.util.Set;
18 23
19 import org.onlab.packet.ChassisId; 24 import org.onlab.packet.ChassisId;
20 import org.apache.felix.scr.annotations.Activate; 25 import org.apache.felix.scr.annotations.Activate;
...@@ -24,10 +29,31 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -24,10 +29,31 @@ import org.apache.felix.scr.annotations.Reference;
24 import org.apache.felix.scr.annotations.ReferenceCardinality; 29 import org.apache.felix.scr.annotations.ReferenceCardinality;
25 import org.onosproject.bgp.controller.BgpController; 30 import org.onosproject.bgp.controller.BgpController;
26 import org.onosproject.bgp.controller.BgpDpid; 31 import org.onosproject.bgp.controller.BgpDpid;
32 +import org.onosproject.bgp.controller.BgpLinkListener;
27 import org.onosproject.bgp.controller.BgpNodeListener; 33 import org.onosproject.bgp.controller.BgpNodeListener;
34 +import org.onosproject.bgpio.exceptions.BgpParseException;
35 +import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier;
36 +import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
37 +import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier;
28 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; 38 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
39 +import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors;
40 +import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
41 +import org.onosproject.bgpio.types.AutonomousSystemTlv;
42 +import org.onosproject.bgpio.types.BgpLSIdentifierTlv;
43 +import org.onosproject.bgpio.types.BgpValueType;
44 +import org.onosproject.bgpio.types.IPv4AddressTlv;
45 +import org.onosproject.bgpio.types.IsIsNonPseudonode;
46 +import org.onosproject.bgpio.types.IsIsPseudonode;
47 +import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv;
48 +import org.onosproject.bgpio.types.OspfNonPseudonode;
49 +import org.onosproject.bgpio.types.OspfPseudonode;
50 +import org.onosproject.core.CoreService;
51 +import org.onosproject.net.AnnotationKeys;
52 +import org.onosproject.net.ConnectPoint;
53 +import org.onosproject.net.DefaultAnnotations;
29 import org.onosproject.net.Device; 54 import org.onosproject.net.Device;
30 import org.onosproject.net.DeviceId; 55 import org.onosproject.net.DeviceId;
56 +import org.onosproject.net.Link;
31 import org.onosproject.net.MastershipRole; 57 import org.onosproject.net.MastershipRole;
32 import org.onosproject.net.PortNumber; 58 import org.onosproject.net.PortNumber;
33 import org.onosproject.net.device.DefaultDeviceDescription; 59 import org.onosproject.net.device.DefaultDeviceDescription;
...@@ -35,6 +61,13 @@ import org.onosproject.net.device.DeviceDescription; ...@@ -35,6 +61,13 @@ import org.onosproject.net.device.DeviceDescription;
35 import org.onosproject.net.device.DeviceProvider; 61 import org.onosproject.net.device.DeviceProvider;
36 import org.onosproject.net.device.DeviceProviderRegistry; 62 import org.onosproject.net.device.DeviceProviderRegistry;
37 import org.onosproject.net.device.DeviceProviderService; 63 import org.onosproject.net.device.DeviceProviderService;
64 +import org.onosproject.net.device.DeviceService;
65 +import org.onosproject.net.link.DefaultLinkDescription;
66 +import org.onosproject.net.link.LinkDescription;
67 +import org.onosproject.net.link.LinkProvider;
68 +import org.onosproject.net.link.LinkProviderRegistry;
69 +import org.onosproject.net.link.LinkProviderService;
70 +import org.onosproject.net.link.LinkService;
38 import org.onosproject.net.provider.AbstractProvider; 71 import org.onosproject.net.provider.AbstractProvider;
39 import org.onosproject.net.provider.ProviderId; 72 import org.onosproject.net.provider.ProviderId;
40 import org.slf4j.Logger; 73 import org.slf4j.Logger;
...@@ -44,7 +77,7 @@ import org.slf4j.LoggerFactory; ...@@ -44,7 +77,7 @@ import org.slf4j.LoggerFactory;
44 * Provider which uses an BGP controller to detect network infrastructure topology. 77 * Provider which uses an BGP controller to detect network infrastructure topology.
45 */ 78 */
46 @Component(immediate = true) 79 @Component(immediate = true)
47 -public class BgpTopologyProvider extends AbstractProvider implements DeviceProvider { 80 +public class BgpTopologyProvider extends AbstractProvider implements DeviceProvider, LinkProvider {
48 81
49 public BgpTopologyProvider() { 82 public BgpTopologyProvider() {
50 super(new ProviderId("bgp", "org.onosproject.provider.bgp")); 83 super(new ProviderId("bgp", "org.onosproject.provider.bgp"));
...@@ -56,42 +89,100 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -56,42 +89,100 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
56 protected DeviceProviderRegistry deviceProviderRegistry; 89 protected DeviceProviderRegistry deviceProviderRegistry;
57 90
58 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 91 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
92 + protected LinkProviderRegistry linkProviderRegistry;
93 +
94 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
59 protected BgpController controller; 95 protected BgpController controller;
60 96
97 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
98 + protected LinkService linkService;
99 +
100 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
101 + protected DeviceService deviceService;
102 +
103 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
104 + protected CoreService coreService;
105 +
61 private DeviceProviderService deviceProviderService; 106 private DeviceProviderService deviceProviderService;
107 + private LinkProviderService linkProviderService;
62 108
63 private InternalBgpProvider listener = new InternalBgpProvider(); 109 private InternalBgpProvider listener = new InternalBgpProvider();
64 private static final String UNKNOWN = "unknown"; 110 private static final String UNKNOWN = "unknown";
111 + public static final long IDENTIFIER_SET = 0x100000000L;
112 + public static final String AS_NUMBER = "asNumber";
113 + public static final String DOMAIN_IDENTIFIER = "domainIdentifier";
114 + public static final String ROUTING_UNIVERSE = "routingUniverse";
115 + public static final long PSEUDO_PORT = 0xffffffff;
65 116
66 @Activate 117 @Activate
67 public void activate() { 118 public void activate() {
119 + log.debug("BgpTopologyProvider activate");
68 deviceProviderService = deviceProviderRegistry.register(this); 120 deviceProviderService = deviceProviderRegistry.register(this);
121 + linkProviderService = linkProviderRegistry.register(this);
69 controller.addListener(listener); 122 controller.addListener(listener);
123 + controller.addLinkListener(listener);
70 } 124 }
71 125
72 @Deactivate 126 @Deactivate
73 public void deactivate() { 127 public void deactivate() {
128 + log.debug("BgpTopologyProvider deactivate");
129 + deviceProviderRegistry.unregister(this);
130 + deviceProviderService = null;
131 + linkProviderRegistry.unregister(this);
132 + linkProviderService = null;
74 controller.removeListener(listener); 133 controller.removeListener(listener);
134 + controller.removeLinkListener(listener);
75 } 135 }
76 136
77 /* 137 /*
78 * Implements device and link update. 138 * Implements device and link update.
79 */ 139 */
80 - private class InternalBgpProvider implements BgpNodeListener { 140 + private class InternalBgpProvider implements BgpNodeListener, BgpLinkListener {
81 141
82 @Override 142 @Override
83 - public void addNode(BgpNodeLSNlriVer4 nodeNlri) { 143 + public void addNode(BgpNodeLSNlriVer4 nodeNlri, PathAttrNlriDetails details) {
84 log.debug("Add node {}", nodeNlri.toString()); 144 log.debug("Add node {}", nodeNlri.toString());
85 145
86 if (deviceProviderService == null) { 146 if (deviceProviderService == null) {
87 return; 147 return;
88 } 148 }
149 + Device.Type deviceType = ROUTER;
89 BgpDpid nodeUri = new BgpDpid(nodeNlri); 150 BgpDpid nodeUri = new BgpDpid(nodeNlri);
90 DeviceId deviceId = deviceId(uri(nodeUri.toString())); 151 DeviceId deviceId = deviceId(uri(nodeUri.toString()));
91 ChassisId cId = new ChassisId(); 152 ChassisId cId = new ChassisId();
92 153
93 - DeviceDescription description = new DefaultDeviceDescription(uri(nodeUri.toString()), Device.Type.ROUTER, 154 + DefaultAnnotations.Builder newBuilder = DefaultAnnotations.builder();
94 - UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, cId); 155 +
156 + newBuilder.set(AnnotationKeys.TYPE, "L3");
157 + newBuilder.set(ROUTING_UNIVERSE, Long.toString(nodeNlri.getIdentifier()));
158 +
159 + List<BgpValueType> tlvs = nodeNlri.getLocalNodeDescriptors().getNodedescriptors().getSubTlvs();
160 + for (BgpValueType tlv : tlvs) {
161 + if (tlv instanceof AutonomousSystemTlv) {
162 + newBuilder.set(AS_NUMBER, Integer.toString(((AutonomousSystemTlv) tlv).getAsNum()));
163 + } else if (tlv instanceof BgpLSIdentifierTlv) {
164 + newBuilder.set(DOMAIN_IDENTIFIER,
165 + Integer.toString(((BgpLSIdentifierTlv) tlv).getBgpLsIdentifier()));
166 + }
167 + if (tlv.getType() == NodeDescriptors.IGP_ROUTERID_TYPE) {
168 + if (tlv instanceof IsIsPseudonode) {
169 + deviceType = VIRTUAL;
170 + newBuilder.set(AnnotationKeys.ROUTER_ID, new String(((IsIsPseudonode) tlv).getIsoNodeId()));
171 + } else if (tlv instanceof OspfPseudonode) {
172 + deviceType = VIRTUAL;
173 + newBuilder
174 + .set(AnnotationKeys.ROUTER_ID, Integer.toString(((OspfPseudonode) tlv).getrouterID()));
175 + } else if (tlv instanceof IsIsNonPseudonode) {
176 + newBuilder.set(AnnotationKeys.ROUTER_ID, new String(((IsIsNonPseudonode) tlv).getIsoNodeId()));
177 + } else if (tlv instanceof OspfNonPseudonode) {
178 + newBuilder.set(AnnotationKeys.ROUTER_ID,
179 + Integer.toString(((OspfNonPseudonode) tlv).getrouterID()));
180 + }
181 + }
182 + }
183 +
184 + DeviceDescription description = new DefaultDeviceDescription(uri(nodeUri.toString()), deviceType, UNKNOWN,
185 + UNKNOWN, UNKNOWN, UNKNOWN, cId, newBuilder.build());
95 deviceProviderService.deviceConnected(deviceId, description); 186 deviceProviderService.deviceConnected(deviceId, description);
96 187
97 } 188 }
...@@ -104,8 +195,131 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -104,8 +195,131 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
104 return; 195 return;
105 } 196 }
106 197
107 - BgpDpid nodeUri = new BgpDpid(nodeNlri); 198 + BgpDpid deviceUri = new BgpDpid(nodeNlri);
108 - deviceProviderService.deviceDisconnected(deviceId(uri(nodeUri.toString()))); 199 + DeviceId deviceId = deviceId(uri(deviceUri.toString()));
200 + deviceProviderService.deviceDisconnected(deviceId);
201 + }
202 +
203 + @Override
204 + public void addLink(BgpLinkLsNlriVer4 linkNlri, PathAttrNlriDetails details) throws BgpParseException {
205 + log.debug("Addlink {}", linkNlri.toString());
206 +
207 + if (linkProviderService == null) {
208 + return;
209 + }
210 + LinkDescription linkDes = buildLinkDes(linkNlri, details, true);
211 + linkProviderService.linkDetected(linkDes);
212 + }
213 +
214 + //Build link description.
215 + private LinkDescription buildLinkDes(BgpLinkLsNlriVer4 linkNlri, PathAttrNlriDetails details, boolean isAddLink)
216 + throws BgpParseException {
217 + long srcAddress = 0;
218 + long dstAddress = 0;
219 + boolean localPseduo = false;
220 + boolean remotePseduo = false;
221 +
222 + List<BgpValueType> localTlvs = linkNlri.getLinkIdentifier().localNodeDescriptors().getSubTlvs();
223 + for (BgpValueType localTlv : localTlvs) {
224 + if (localTlv instanceof IsIsPseudonode || localTlv instanceof OspfPseudonode) {
225 + localPseduo = true;
226 + }
227 + }
228 + List<BgpValueType> remoteTlvs = linkNlri.getLinkIdentifier().remoteNodeDescriptors().getSubTlvs();
229 + for (BgpValueType remoteTlv : remoteTlvs) {
230 + if (remoteTlv instanceof IsIsPseudonode || remoteTlv instanceof OspfPseudonode) {
231 + remotePseduo = true;
232 + }
233 + }
234 +
235 + List<BgpValueType> tlvs = linkNlri.getLinkIdentifier().linkDescriptors();
236 + for (BgpValueType tlv : tlvs) {
237 + if (tlv instanceof LinkLocalRemoteIdentifiersTlv) {
238 + srcAddress = ((LinkLocalRemoteIdentifiersTlv) tlv).getLinkLocalIdentifier();
239 + //Set 32nd bit.
240 + srcAddress = srcAddress | IDENTIFIER_SET;
241 + dstAddress = ((LinkLocalRemoteIdentifiersTlv) tlv).getLinkRemoteIdentifier();
242 + dstAddress = dstAddress | IDENTIFIER_SET;
243 + } else if (tlv instanceof IPv4AddressTlv) {
244 + if (tlv.getType() == BgpLinkLSIdentifier.IPV4_INTERFACE_ADDRESS_TYPE) {
245 + srcAddress = ((IPv4AddressTlv) tlv).address().toInt();
246 + } else {
247 + dstAddress = ((IPv4AddressTlv) tlv).address().toInt();
248 + }
249 + }
250 + }
251 +
252 + DeviceId srcId = deviceId(uri(new BgpDpid(linkNlri, BgpDpid.NODE_DESCRIPTOR_LOCAL).toString()));
253 + DeviceId dstId = deviceId(uri(new BgpDpid(linkNlri, BgpDpid.NODE_DESCRIPTOR_REMOTE).toString()));
254 +
255 + if (localPseduo && srcAddress == 0) {
256 + srcAddress = PSEUDO_PORT;
257 + } else if (remotePseduo && dstAddress == 0) {
258 + dstAddress = PSEUDO_PORT;
259 + }
260 +
261 + ConnectPoint src = new ConnectPoint(srcId, PortNumber.portNumber(srcAddress));
262 + ConnectPoint dst = new ConnectPoint(dstId, PortNumber.portNumber(dstAddress));
263 + BgpNodeLSNlriVer4 srcNodeNlri = new BgpNodeLSNlriVer4(linkNlri.getIdentifier(), linkNlri.getProtocolId()
264 + .getType(), new BgpNodeLSIdentifier(linkNlri.getLinkIdentifier().localNodeDescriptors()), false,
265 + linkNlri.getRouteDistinguisher());
266 +
267 + BgpNodeLSNlriVer4 dstNodeNlri = new BgpNodeLSNlriVer4(linkNlri.getIdentifier(), linkNlri.getProtocolId()
268 + .getType(), new BgpNodeLSIdentifier(linkNlri.getLinkIdentifier().remoteNodeDescriptors()), false,
269 + linkNlri.getRouteDistinguisher());
270 +
271 + addOrDeletePseudoNode(isAddLink, localPseduo, remotePseduo, srcNodeNlri,
272 + dstNodeNlri, srcId, dstId, details);
273 + return new DefaultLinkDescription(src, dst, Link.Type.DIRECT, false);
274 + }
275 +
276 + private void addOrDeletePseudoNode(boolean isAddLink, boolean localPseduo, boolean remotePseduo,
277 + BgpNodeLSNlriVer4 srcNodeNlri, BgpNodeLSNlriVer4 dstNodeNlri, DeviceId srcId, DeviceId dstId,
278 + PathAttrNlriDetails details) {
279 + if (isAddLink) {
280 + if (localPseduo) {
281 + if (deviceService.getDevice(srcId) == null) {
282 + for (BgpNodeListener l : controller.listener()) {
283 + l.addNode(srcNodeNlri, details);
284 + }
285 + }
286 + } else if (remotePseduo) {
287 + if (deviceService.getDevice(dstId) == null) {
288 + for (BgpNodeListener l : controller.listener()) {
289 + l.addNode(dstNodeNlri, details);
290 + }
291 + }
292 + }
293 + } else {
294 + if (localPseduo) {
295 + Set<Link> links = linkService.getDeviceLinks(srcId);
296 + if (links == null || links.isEmpty()) {
297 + for (BgpNodeListener l : controller.listener()) {
298 + l.deleteNode(srcNodeNlri);
299 + }
300 + }
301 + } else if (remotePseduo) {
302 + log.info("Remote pseudo delete link ");
303 + Set<Link> links = linkService.getDeviceLinks(dstId);
304 + if (links == null || links.isEmpty()) {
305 + for (BgpNodeListener l : controller.listener()) {
306 + l.deleteNode(dstNodeNlri);
307 + }
308 + }
309 + }
310 + }
311 + }
312 +
313 + @Override
314 + public void deleteLink(BgpLinkLsNlriVer4 linkNlri) throws BgpParseException {
315 + log.debug("Delete link {}", linkNlri.toString());
316 +
317 + if (linkProviderService == null) {
318 + return;
319 + }
320 +
321 + LinkDescription linkDes = buildLinkDes(linkNlri, null, false);
322 + linkProviderService.linkVanished(linkDes);
109 } 323 }
110 } 324 }
111 325
......
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.provider.bgp.topology.impl;
17 +
18 +import org.onosproject.bgp.controller.BgpCfg;
19 +import org.onosproject.bgp.controller.BgpController;
20 +import org.onosproject.bgp.controller.BgpId;
21 +import org.onosproject.bgp.controller.BgpLinkListener;
22 +import org.onosproject.bgp.controller.BgpLocalRib;
23 +import org.onosproject.bgp.controller.BgpNodeListener;
24 +import org.onosproject.bgp.controller.BgpPeer;
25 +import org.onosproject.bgp.controller.BgpPeerManager;
26 +import org.onosproject.bgpio.exceptions.BgpParseException;
27 +import org.onosproject.bgpio.protocol.BgpMessage;
28 +
29 +import java.util.Map;
30 +import java.util.Set;
31 +
32 +/**
33 + * Adapter implementation for BGP controller.
34 + */
35 +public class BgpControllerAdapter implements BgpController {
36 + @Override
37 + public Iterable<BgpPeer> getPeers() {
38 + // TODO Auto-generated method stub
39 + return null;
40 + }
41 +
42 + @Override
43 + public BgpPeer getPeer(BgpId bgpId) {
44 + // TODO Auto-generated method stub
45 + return null;
46 + }
47 +
48 + @Override
49 + public void writeMsg(BgpId bgpId, BgpMessage msg) {
50 + // TODO Auto-generated method stub
51 + }
52 +
53 + @Override
54 + public void processBgpPacket(BgpId bgpId, BgpMessage msg) throws BgpParseException {
55 + // TODO Auto-generated method stub
56 + }
57 +
58 + @Override
59 + public void closeConnectedPeers() {
60 + // TODO Auto-generated method stub
61 + }
62 +
63 + @Override
64 + public BgpCfg getConfig() {
65 + // TODO Auto-generated method stub
66 + return null;
67 + }
68 +
69 + @Override
70 + public int connectedPeerCount() {
71 + // TODO Auto-generated method stub
72 + return 0;
73 + }
74 +
75 + @Override
76 + public BgpLocalRib bgpLocalRibVpn() {
77 + // TODO Auto-generated method stub
78 + return null;
79 + }
80 +
81 + @Override
82 + public BgpLocalRib bgpLocalRib() {
83 + // TODO Auto-generated method stub
84 + return null;
85 + }
86 +
87 + @Override
88 + public BgpPeerManager peerManager() {
89 + // TODO Auto-generated method stub
90 + return null;
91 + }
92 +
93 + @Override
94 + public Map<BgpId, BgpPeer> connectedPeers() {
95 + // TODO Auto-generated method stub
96 + return null;
97 + }
98 +
99 + @Override
100 + public Set<BgpNodeListener> listener() {
101 + // TODO Auto-generated method stub
102 + return null;
103 + }
104 +
105 + @Override
106 + public Set<BgpLinkListener> linkListener() {
107 + // TODO Auto-generated method stub
108 + return null;
109 + }
110 +
111 + @Override
112 + public void addListener(BgpNodeListener listener) {
113 + // TODO Auto-generated method stub
114 + }
115 +
116 + @Override
117 + public void removeListener(BgpNodeListener listener) {
118 + // TODO Auto-generated method stub
119 + }
120 +
121 + @Override
122 + public void addLinkListener(BgpLinkListener listener) {
123 + // TODO Auto-generated method stub
124 + }
125 +
126 + @Override
127 + public void removeLinkListener(BgpLinkListener listener) {
128 + // TODO Auto-generated method stub
129 + }
130 +}
...@@ -12,11 +12,13 @@ ...@@ -12,11 +12,13 @@
12 */ 12 */
13 package org.onosproject.provider.bgp.topology.impl; 13 package org.onosproject.provider.bgp.topology.impl;
14 14
15 -import static org.junit.Assert.assertNotNull; 15 +import static org.hamcrest.MatcherAssert.assertThat;
16 -import static org.junit.Assert.assertNull; 16 +import static org.hamcrest.core.Is.is;
17 -import static org.junit.Assert.assertTrue; 17 +import static org.hamcrest.core.IsNot.not;
18 +import static org.onosproject.net.Link.State.ACTIVE;
18 19
19 import java.util.Collection; 20 import java.util.Collection;
21 +import java.util.HashMap;
20 import java.util.HashSet; 22 import java.util.HashSet;
21 import java.util.LinkedList; 23 import java.util.LinkedList;
22 import java.util.List; 24 import java.util.List;
...@@ -27,59 +29,80 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -27,59 +29,80 @@ import java.util.concurrent.CopyOnWriteArraySet;
27 import org.junit.After; 29 import org.junit.After;
28 import org.junit.Before; 30 import org.junit.Before;
29 import org.junit.Test; 31 import org.junit.Test;
30 -import org.onosproject.bgp.controller.BgpCfg; 32 +import org.onlab.packet.ChassisId;
31 -import org.onosproject.bgp.controller.BgpController; 33 +import org.onosproject.bgp.controller.BgpLinkListener;
32 -import org.onosproject.bgp.controller.BgpId;
33 -import org.onosproject.bgp.controller.BgpPeer;
34 -import org.onosproject.bgp.controller.BgpLocalRib;
35 import org.onosproject.bgp.controller.BgpNodeListener; 34 import org.onosproject.bgp.controller.BgpNodeListener;
36 -import org.onosproject.bgp.controller.BgpPeerManager;
37 import org.onosproject.bgpio.exceptions.BgpParseException; 35 import org.onosproject.bgpio.exceptions.BgpParseException;
38 -import org.onosproject.bgpio.protocol.BgpMessage; 36 +import org.onosproject.bgpio.protocol.linkstate.BgpLinkLSIdentifier;
37 +import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4;
39 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier; 38 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSIdentifier;
40 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; 39 import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
40 +import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType;
41 import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; 41 import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors;
42 +import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails;
42 import org.onosproject.bgpio.types.AutonomousSystemTlv; 43 import org.onosproject.bgpio.types.AutonomousSystemTlv;
43 import org.onosproject.bgpio.types.BgpValueType; 44 import org.onosproject.bgpio.types.BgpValueType;
45 +import org.onosproject.bgpio.types.IsIsNonPseudonode;
46 +import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv;
44 import org.onosproject.bgpio.types.RouteDistinguisher; 47 import org.onosproject.bgpio.types.RouteDistinguisher;
45 import org.onosproject.bgpio.util.Constants; 48 import org.onosproject.bgpio.util.Constants;
49 +import org.onosproject.net.ConnectPoint;
50 +import org.onosproject.net.DefaultDevice;
51 +import org.onosproject.net.DefaultLink;
52 +import org.onosproject.net.Device;
46 import org.onosproject.net.DeviceId; 53 import org.onosproject.net.DeviceId;
54 +import org.onosproject.net.Link;
47 import org.onosproject.net.MastershipRole; 55 import org.onosproject.net.MastershipRole;
48 import org.onosproject.net.device.DeviceDescription; 56 import org.onosproject.net.device.DeviceDescription;
49 import org.onosproject.net.device.DeviceProvider; 57 import org.onosproject.net.device.DeviceProvider;
50 import org.onosproject.net.device.DeviceProviderRegistry; 58 import org.onosproject.net.device.DeviceProviderRegistry;
51 import org.onosproject.net.device.DeviceProviderService; 59 import org.onosproject.net.device.DeviceProviderService;
60 +import org.onosproject.net.device.DeviceServiceAdapter;
52 import org.onosproject.net.device.PortDescription; 61 import org.onosproject.net.device.PortDescription;
53 import org.onosproject.net.device.PortStatistics; 62 import org.onosproject.net.device.PortStatistics;
63 +import org.onosproject.net.link.LinkDescription;
64 +import org.onosproject.net.link.LinkProvider;
65 +import org.onosproject.net.link.LinkProviderRegistry;
66 +import org.onosproject.net.link.LinkProviderService;
54 import org.onosproject.net.provider.ProviderId; 67 import org.onosproject.net.provider.ProviderId;
55 68
69 +/**
70 + * Test for BGP topology provider.
71 + */
56 public class BgpTopologyProviderTest { 72 public class BgpTopologyProviderTest {
73 + private static final DeviceId DID2 = DeviceId.deviceId("bgp:rd=0::routinguniverse=0:asn=10");
74 + private static final String UNKNOWN = new String("unknown");
75 + public static ProviderId providerId = new ProviderId("bgp", "foo");
57 76
58 - private static final DeviceId DID1 = DeviceId
59 - .deviceId("bgp:rd=0:proto=direct:id=0:as=100");
60 - private static final DeviceId DID2 = DeviceId
61 - .deviceId("bgp:rd=0:proto=direct:id=0:as=10");
62 - private static final DeviceId DID3 = DeviceId
63 - .deviceId("bgp:rd=0:proto=direct:id=0:as=100");
64 private final BgpTopologyProvider provider = new BgpTopologyProvider(); 77 private final BgpTopologyProvider provider = new BgpTopologyProvider();
65 private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry(); 78 private final TestDeviceRegistry nodeRegistry = new TestDeviceRegistry();
66 - private final TestController controller = new TestController(); 79 + private final TestLinkRegistry linkRegistry = new TestLinkRegistry();
80 + private final MockBgpController controller = new MockBgpController();
81 + private MockDeviceService deviceService = new MockDeviceService();
82 + private Map<DeviceId, Device> deviceMap = new HashMap<>();
83 +
67 84
68 @Before 85 @Before
69 public void startUp() { 86 public void startUp() {
70 provider.deviceProviderRegistry = nodeRegistry; 87 provider.deviceProviderRegistry = nodeRegistry;
88 + provider.linkProviderRegistry = linkRegistry;
71 provider.controller = controller; 89 provider.controller = controller;
90 + provider.deviceService = deviceService;
72 provider.activate(); 91 provider.activate();
73 - assertNotNull("provider should be registered", nodeRegistry.provider); 92 + assertThat("device provider should be registered", not(nodeRegistry.provider));
74 - assertNotNull("listener should be registered", controller.nodeListener); 93 + assertThat("link provider should be registered", not(linkRegistry.linkProvider));
94 + assertThat("node listener should be registered", not(controller.nodeListener));
95 + assertThat("link listener should be registered", not(controller.linkListener));
75 } 96 }
76 97
77 @After 98 @After
78 public void tearDown() { 99 public void tearDown() {
79 provider.deactivate(); 100 provider.deactivate();
80 - assertNull("listener should be removed", controller.nodeListener);
81 provider.controller = null; 101 provider.controller = null;
102 + provider.deviceService = null;
82 provider.deviceProviderRegistry = null; 103 provider.deviceProviderRegistry = null;
104 + assertThat(controller.nodeListener, is(new HashSet<BgpNodeListener>()));
105 + assertThat(controller.linkListener, is(new HashSet<BgpLinkListener>()));
83 } 106 }
84 107
85 /* Class implement device test registry */ 108 /* Class implement device test registry */
...@@ -112,15 +135,19 @@ public class BgpTopologyProviderTest { ...@@ -112,15 +135,19 @@ public class BgpTopologyProviderTest {
112 135
113 @Override 136 @Override
114 public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) { 137 public void deviceConnected(DeviceId deviceId, DeviceDescription deviceDescription) {
115 - if (deviceId.equals(DID1)) { 138 + if (!deviceId.equals(DID2)) {
116 connected.add(deviceId); 139 connected.add(deviceId);
140 + Device device = new DefaultDevice(BgpTopologyProviderTest.providerId, deviceId, Device.Type.ROUTER,
141 + UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, new ChassisId());
142 + deviceMap.put(deviceId, device);
117 } 143 }
118 } 144 }
119 145
120 @Override 146 @Override
121 public void deviceDisconnected(DeviceId deviceId) { 147 public void deviceDisconnected(DeviceId deviceId) {
122 - if (deviceId.equals(DID1)) { 148 + if (!deviceId.equals(DID2)) {
123 connected.remove(deviceId); 149 connected.remove(deviceId);
150 + deviceMap.remove(deviceId);
124 } 151 }
125 } 152 }
126 153
...@@ -150,99 +177,101 @@ public class BgpTopologyProviderTest { ...@@ -150,99 +177,101 @@ public class BgpTopologyProviderTest {
150 } 177 }
151 } 178 }
152 179
153 - /* class implement test controller */ 180 + /* Class implement device test registry */
154 - private class TestController implements BgpController { 181 + private class TestLinkRegistry implements LinkProviderRegistry {
155 - protected Set<BgpNodeListener> nodeListener = new CopyOnWriteArraySet<>(); 182 + LinkProvider linkProvider;
183 + Set<Link> links = new HashSet<>();
156 184
157 @Override 185 @Override
158 - public void addListener(BgpNodeListener nodeListener) { 186 + public LinkProviderService register(LinkProvider provider) {
159 - this.nodeListener.add(nodeListener); 187 + this.linkProvider = provider;
188 + return new TestProviderService();
160 } 189 }
161 190
162 @Override 191 @Override
163 - public void removeListener(BgpNodeListener nodeListener) { 192 + public void unregister(LinkProvider provider) {
164 - this.nodeListener = null; 193 + // TODO Auto-generated method stub
165 } 194 }
166 195
167 @Override 196 @Override
168 - public Iterable<BgpPeer> getPeers() { 197 + public Set<ProviderId> getProviders() {
169 - // TODO Auto-generated method stub
170 return null; 198 return null;
171 } 199 }
172 200
201 + private class TestProviderService implements LinkProviderService {
202 +
173 @Override 203 @Override
174 - public BgpPeer getPeer(BgpId bgpId) { 204 + public void linkDetected(LinkDescription linkDescription) {
175 - // TODO Auto-generated method stub 205 + links.add(DefaultLink.builder().src(linkDescription.src())
176 - return null; 206 + .dst(linkDescription.dst()).state(ACTIVE).type(linkDescription.type())
207 + .providerId(BgpTopologyProviderTest.providerId).build());
177 } 208 }
178 209
179 @Override 210 @Override
180 - public void writeMsg(BgpId bgpId, BgpMessage msg) { 211 + public void linkVanished(LinkDescription linkDescription) {
181 - // TODO Auto-generated method stub 212 + links.remove(DefaultLink.builder().src(linkDescription.src())
182 - 213 + .dst(linkDescription.dst()).state(ACTIVE).type(linkDescription.type())
214 + .providerId(BgpTopologyProviderTest.providerId).build());
183 } 215 }
184 216
185 @Override 217 @Override
186 - public void processBgpPacket(BgpId bgpId, BgpMessage msg) throws BgpParseException { 218 + public void linksVanished(ConnectPoint connectPoint) {
187 // TODO Auto-generated method stub 219 // TODO Auto-generated method stub
188 -
189 } 220 }
190 221
191 @Override 222 @Override
192 - public void closeConnectedPeers() { 223 + public void linksVanished(DeviceId deviceId) {
193 // TODO Auto-generated method stub 224 // TODO Auto-generated method stub
194 -
195 } 225 }
196 226
197 @Override 227 @Override
198 - public BgpCfg getConfig() { 228 + public LinkProvider provider() {
199 // TODO Auto-generated method stub 229 // TODO Auto-generated method stub
200 return null; 230 return null;
201 } 231 }
202 - 232 + }
203 - @Override
204 - public int connectedPeerCount() {
205 - // TODO Auto-generated method stub
206 - return 0;
207 } 233 }
208 234
235 + /* Test class for BGP controller */
236 + private class MockBgpController extends BgpControllerAdapter {
237 + protected Set<BgpNodeListener> nodeListener = new CopyOnWriteArraySet<>();
238 + protected Set<BgpLinkListener> linkListener = new CopyOnWriteArraySet<>();
239 +
209 @Override 240 @Override
210 - public BgpLocalRib bgpLocalRibVpn() { 241 + public void addListener(BgpNodeListener nodeListener) {
211 - // TODO Auto-generated method stub 242 + this.nodeListener.add(nodeListener);
212 - return null;
213 } 243 }
214 244
215 @Override 245 @Override
216 - public BgpLocalRib bgpLocalRib() { 246 + public void removeListener(BgpNodeListener nodeListener) {
217 - // TODO Auto-generated method stub 247 + this.nodeListener.remove(nodeListener);
218 - return null;
219 } 248 }
220 249
221 @Override 250 @Override
222 - public BgpPeerManager peerManager() { 251 + public void addLinkListener(BgpLinkListener linkListener) {
223 - // TODO Auto-generated method stub 252 + this.linkListener.add(linkListener);
224 - return null;
225 } 253 }
226 254
227 @Override 255 @Override
228 - public Map<BgpId, BgpPeer> connectedPeers() { 256 + public void removeLinkListener(BgpLinkListener linkListener) {
229 - // TODO Auto-generated method stub 257 + this.linkListener.remove(linkListener);
230 - return null; 258 + }
231 } 259 }
232 260
261 + /* Mock test for device service */
262 + private class MockDeviceService extends DeviceServiceAdapter {
233 @Override 263 @Override
234 - public Set<BgpNodeListener> listener() { 264 + public Device getDevice(DeviceId deviceId) {
235 - // TODO Auto-generated method stub 265 + return deviceMap.get(deviceId);
236 - return null;
237 } 266 }
238 } 267 }
239 268
240 - /* Validate node is added to the device validating URI, RIB should get updated properly */ 269 + /**
270 + * Validate node is added to the device validating URI, RIB should get updated properly.
271 + */
241 @Test 272 @Test
242 public void bgpTopologyProviderTestAddDevice1() { 273 public void bgpTopologyProviderTestAddDevice1() {
243 - int deviceAddCount = 0; 274 + LinkedList<BgpValueType> subTlvs = new LinkedList<>();
244 - LinkedList<BgpValueType> subTlvs;
245 - subTlvs = new LinkedList<>();
246 BgpValueType tlv = new AutonomousSystemTlv(100); 275 BgpValueType tlv = new AutonomousSystemTlv(100);
247 short deslength = AutonomousSystemTlv.LENGTH; 276 short deslength = AutonomousSystemTlv.LENGTH;
248 short desType = AutonomousSystemTlv.TYPE; 277 short desType = AutonomousSystemTlv.TYPE;
...@@ -253,18 +282,23 @@ public class BgpTopologyProviderTest { ...@@ -253,18 +282,23 @@ public class BgpTopologyProviderTest {
253 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, 282 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
254 new RouteDistinguisher()); 283 new RouteDistinguisher());
255 284
256 - nodeNlri.setNodeLSIdentifier(localNodeDescriptors); 285 + PathAttrNlriDetails details = new PathAttrNlriDetails();
286 + details.setIdentifier(0);
287 + details.setProtocolID(ProtocolType.DIRECT);
288 + List<BgpValueType> pathAttributes = new LinkedList<>();
289 + details.setPathAttribute(pathAttributes);
290 +
257 for (BgpNodeListener l : controller.nodeListener) { 291 for (BgpNodeListener l : controller.nodeListener) {
258 - l.addNode(nodeNlri); 292 + l.addNode(nodeNlri, details);
259 - deviceAddCount = nodeRegistry.connected.size(); 293 + assertThat(nodeRegistry.connected.size(), is(1));
260 - assertTrue(deviceAddCount == 1);
261 l.deleteNode(nodeNlri); 294 l.deleteNode(nodeNlri);
262 - deviceAddCount = nodeRegistry.connected.size(); 295 + assertThat(nodeRegistry.connected.size(), is(0));
263 - assertTrue(deviceAddCount == 0);
264 } 296 }
265 } 297 }
266 298
267 - /* Validate node is not added to the device for invalid URI, RIB count should be zero */ 299 + /**
300 + * Validate node is not added to the device for invalid URI, RIB count should be zero.
301 + */
268 @Test 302 @Test
269 public void bgpTopologyProviderTestAddDevice2() { 303 public void bgpTopologyProviderTestAddDevice2() {
270 LinkedList<BgpValueType> subTlvs; 304 LinkedList<BgpValueType> subTlvs;
...@@ -272,6 +306,12 @@ public class BgpTopologyProviderTest { ...@@ -272,6 +306,12 @@ public class BgpTopologyProviderTest {
272 short deslength = AutonomousSystemTlv.LENGTH; 306 short deslength = AutonomousSystemTlv.LENGTH;
273 short desType = AutonomousSystemTlv.TYPE; 307 short desType = AutonomousSystemTlv.TYPE;
274 308
309 + PathAttrNlriDetails details = new PathAttrNlriDetails();
310 + details.setIdentifier(0);
311 + details.setProtocolID(ProtocolType.DIRECT);
312 + List<BgpValueType> pathAttributes = new LinkedList<>();
313 + details.setPathAttribute(pathAttributes);
314 +
275 subTlvs = new LinkedList<>(); 315 subTlvs = new LinkedList<>();
276 subTlvs.add(tlv); 316 subTlvs.add(tlv);
277 BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength, 317 BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(new NodeDescriptors(subTlvs, deslength,
...@@ -279,14 +319,16 @@ public class BgpTopologyProviderTest { ...@@ -279,14 +319,16 @@ public class BgpTopologyProviderTest {
279 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, 319 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
280 new RouteDistinguisher()); 320 new RouteDistinguisher());
281 321
282 - nodeNlri.setNodeLSIdentifier(localNodeDescriptors); 322 +
283 for (BgpNodeListener l : controller.nodeListener) { 323 for (BgpNodeListener l : controller.nodeListener) {
284 - l.addNode(nodeNlri); 324 + l.addNode(nodeNlri, details);
285 - assertTrue("Failed to add device", (nodeRegistry.connected.size() == 0)); 325 + assertThat(nodeRegistry.connected.size(), is(0));
286 } 326 }
287 } 327 }
288 328
289 - /* Delete node when node does not exist, RIB count should be zero */ 329 + /**
330 + * Delete node when node does not exist, RIB count should be zero.
331 + */
290 @Test 332 @Test
291 public void bgpTopologyProviderTestAddDevice3() { 333 public void bgpTopologyProviderTestAddDevice3() {
292 LinkedList<BgpValueType> subTlvs; 334 LinkedList<BgpValueType> subTlvs;
...@@ -301,10 +343,173 @@ public class BgpTopologyProviderTest { ...@@ -301,10 +343,173 @@ public class BgpTopologyProviderTest {
301 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false, 343 BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
302 new RouteDistinguisher()); 344 new RouteDistinguisher());
303 345
304 - nodeNlri.setNodeLSIdentifier(localNodeDescriptors);
305 for (BgpNodeListener l : controller.nodeListener) { 346 for (BgpNodeListener l : controller.nodeListener) {
306 l.deleteNode(nodeNlri); 347 l.deleteNode(nodeNlri);
307 - assertTrue("Failed to add device", (nodeRegistry.connected.size() == 0)); 348 + assertThat(nodeRegistry.connected.size(), is(0));
349 + }
350 + }
351 +
352 + /**
353 + * Add a link and two devices.
354 + *
355 + * @throws BgpParseException while adding a link.
356 + */
357 + @Test
358 + public void bgpTopologyProviderTestAddLink1() throws BgpParseException {
359 + LinkedList<BgpValueType> localTlvs = new LinkedList<>();
360 + LinkedList<BgpValueType> remoteTlvs = new LinkedList<>();
361 + LinkedList<BgpValueType> linkdes = new LinkedList<>();
362 + BgpValueType tlv = new AutonomousSystemTlv(10);
363 + short deslength = AutonomousSystemTlv.LENGTH;
364 + short desType = AutonomousSystemTlv.TYPE;
365 +
366 + localTlvs.add(tlv);
367 + remoteTlvs.add(tlv);
368 + tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20});
369 + localTlvs.add(tlv);
370 + tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30});
371 + remoteTlvs.add(tlv);
372 + NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType);
373 + NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType);
374 + BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode);
375 + BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
376 + new RouteDistinguisher());
377 +
378 + BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode);
379 + BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false,
380 + new RouteDistinguisher());
381 +
382 + PathAttrNlriDetails details = new PathAttrNlriDetails();
383 + details.setIdentifier(0);
384 + details.setProtocolID(ProtocolType.DIRECT);
385 + List<BgpValueType> pathAttributes = new LinkedList<>();
386 + details.setPathAttribute(pathAttributes);
387 +
388 + tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100);
389 + linkdes.add(tlv);
390 + BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes);
391 + BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId,
392 + new RouteDistinguisher(), false);
393 + for (BgpNodeListener l : controller.nodeListener) {
394 + l.addNode(nodeNlri, details);
395 + assertThat(nodeRegistry.connected.size(), is(1));
396 + l.addNode(remNodeNlri, details);
397 + assertThat(nodeRegistry.connected.size(), is(2));
398 + }
399 + for (BgpLinkListener l : controller.linkListener) {
400 + l.addLink(linkNlri, details);
401 + assertThat(linkRegistry.links.size(), is(1));
402 + }
403 + }
404 +
405 + /**
406 + * Add a link and delete a link.
407 + *
408 + * @throws BgpParseException while adding or removing the link
409 + */
410 + @Test
411 + public void bgpTopologyProviderTestAddLink2() throws BgpParseException {
412 + LinkedList<BgpValueType> localTlvs = new LinkedList<>();
413 + LinkedList<BgpValueType> remoteTlvs = new LinkedList<>();
414 + LinkedList<BgpValueType> linkdes = new LinkedList<>();
415 + BgpValueType tlv = new AutonomousSystemTlv(10);
416 + short deslength = AutonomousSystemTlv.LENGTH;
417 + short desType = AutonomousSystemTlv.TYPE;
418 +
419 + localTlvs.add(tlv);
420 + remoteTlvs.add(tlv);
421 + tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20});
422 + localTlvs.add(tlv);
423 + tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30});
424 + remoteTlvs.add(tlv);
425 + NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType);
426 + NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType);
427 + BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode);
428 + BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
429 + new RouteDistinguisher());
430 +
431 + BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode);
432 + BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false,
433 + new RouteDistinguisher());
434 +
435 + PathAttrNlriDetails details = new PathAttrNlriDetails();
436 + details.setIdentifier(0);
437 + details.setProtocolID(ProtocolType.DIRECT);
438 + List<BgpValueType> pathAttributes = new LinkedList<>();
439 + details.setPathAttribute(pathAttributes);
440 +
441 + tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100);
442 + linkdes.add(tlv);
443 + BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes);
444 + BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId,
445 + new RouteDistinguisher(), false);
446 + for (BgpNodeListener l : controller.nodeListener) {
447 + l.addNode(nodeNlri, details);
448 + assertThat(nodeRegistry.connected.size(), is(1));
449 + l.addNode(remNodeNlri, details);
450 + assertThat(nodeRegistry.connected.size(), is(2));
451 + l.deleteNode(nodeNlri);
452 + assertThat(nodeRegistry.connected.size(), is(1));
453 + }
454 + for (BgpLinkListener l : controller.linkListener) {
455 + l.addLink(linkNlri, details);
456 + assertThat(linkRegistry.links.size(), is(1));
457 + l.deleteLink(linkNlri);
458 + assertThat(linkRegistry.links.size(), is(0));
459 + }
460 + }
461 +
462 + /**
463 + * Invalid link.
464 + *
465 + * @throws BgpParseException while adding or deleting a link
466 + */
467 + @Test
468 + public void bgpTopologyProviderTestDeleteLink3() throws BgpParseException {
469 + LinkedList<BgpValueType> localTlvs = new LinkedList<>();
470 + LinkedList<BgpValueType> remoteTlvs = new LinkedList<>();
471 + LinkedList<BgpValueType> linkdes = new LinkedList<>();
472 + BgpValueType tlv = new AutonomousSystemTlv(10);
473 + short deslength = AutonomousSystemTlv.LENGTH;
474 + short desType = AutonomousSystemTlv.TYPE;
475 +
476 + localTlvs.add(tlv);
477 + remoteTlvs.add(tlv);
478 + tlv = IsIsNonPseudonode.of(new byte[] {20, 20, 20, 20, 00, 20});
479 + localTlvs.add(tlv);
480 + tlv = IsIsNonPseudonode.of(new byte[] {30, 30, 30, 30, 00, 30});
481 + remoteTlvs.add(tlv);
482 + NodeDescriptors localNode = new NodeDescriptors(localTlvs, deslength, desType);
483 + NodeDescriptors remoteNode = new NodeDescriptors(remoteTlvs, deslength, desType);
484 + BgpNodeLSIdentifier localNodeDescriptors = new BgpNodeLSIdentifier(localNode);
485 + BgpNodeLSNlriVer4 nodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, localNodeDescriptors, false,
486 + new RouteDistinguisher());
487 +
488 + BgpNodeLSIdentifier remoteNodeDescriptors = new BgpNodeLSIdentifier(remoteNode);
489 + BgpNodeLSNlriVer4 remNodeNlri = new BgpNodeLSNlriVer4(0, (byte) Constants.DIRECT, remoteNodeDescriptors, false,
490 + new RouteDistinguisher());
491 +
492 + PathAttrNlriDetails details = new PathAttrNlriDetails();
493 + details.setIdentifier(0);
494 + details.setProtocolID(ProtocolType.DIRECT);
495 + List<BgpValueType> pathAttributes = new LinkedList<>();
496 + details.setPathAttribute(pathAttributes);
497 +
498 + tlv = LinkLocalRemoteIdentifiersTlv.of(99, 100);
499 + linkdes.add(tlv);
500 + BgpLinkLSIdentifier linkId = new BgpLinkLSIdentifier(localNode, remoteNode, linkdes);
501 + BgpLinkLsNlriVer4 linkNlri = new BgpLinkLsNlriVer4((byte) Constants.DIRECT, 0, linkId,
502 + new RouteDistinguisher(), false);
503 + for (BgpNodeListener l : controller.nodeListener) {
504 + l.addNode(nodeNlri, details);
505 + l.addNode(remNodeNlri, details);
506 + assertThat(nodeRegistry.connected.size(), is(2));
507 + l.deleteNode(nodeNlri);
508 + assertThat(nodeRegistry.connected.size(), is(1));
509 + }
510 + for (BgpLinkListener l : controller.linkListener) {
511 + l.deleteLink(linkNlri);
512 + assertThat(linkRegistry.links.size(), is(0));
308 } 513 }
309 } 514 }
310 } 515 }
......