Committed by
Gerrit Code Review
Implementing Bgp connect
Change-Id: I6dd6d91c083bec54f31251e06c700d0a0dd54cd4
Showing
2 changed files
with
25 additions
and
5 deletions
| ... | @@ -52,6 +52,9 @@ public class BgpAppConfig extends Config<ApplicationId> { | ... | @@ -52,6 +52,9 @@ public class BgpAppConfig extends Config<ApplicationId> { |
| 52 | public static final String PEER_IP = "peerIp"; | 52 | public static final String PEER_IP = "peerIp"; |
| 53 | public static final String REMOTE_AS = "remoteAs"; | 53 | public static final String REMOTE_AS = "remoteAs"; |
| 54 | public static final String PEER_HOLD_TIME = "peerHoldTime"; | 54 | public static final String PEER_HOLD_TIME = "peerHoldTime"; |
| 55 | + public static final String PEER_CONNECT_MODE = "connectMode"; | ||
| 56 | + public static final String PEER_CONNECT_PASSIVE = "passive"; | ||
| 57 | + public static final String PEER_CONNECT_ACTIVE = "active"; | ||
| 55 | 58 | ||
| 56 | static final int MAX_SHORT_AS_NUMBER = 65535; | 59 | static final int MAX_SHORT_AS_NUMBER = 65535; |
| 57 | static final long MAX_LONG_AS_NUMBER = 4294967295L; | 60 | static final long MAX_LONG_AS_NUMBER = 4294967295L; |
| ... | @@ -229,12 +232,15 @@ public class BgpAppConfig extends Config<ApplicationId> { | ... | @@ -229,12 +232,15 @@ public class BgpAppConfig extends Config<ApplicationId> { |
| 229 | */ | 232 | */ |
| 230 | public boolean validateBgpPeers() { | 233 | public boolean validateBgpPeers() { |
| 231 | List<BgpPeerConfig> nodes; | 234 | List<BgpPeerConfig> nodes; |
| 235 | + String connectMode; | ||
| 232 | 236 | ||
| 233 | nodes = bgpPeer(); | 237 | nodes = bgpPeer(); |
| 234 | for (int i = 0; i < nodes.size(); i++) { | 238 | for (int i = 0; i < nodes.size(); i++) { |
| 239 | + connectMode = nodes.get(i).connectMode(); | ||
| 235 | if ((IpAddress.valueOf(nodes.get(i).hostname()) == null) || | 240 | if ((IpAddress.valueOf(nodes.get(i).hostname()) == null) || |
| 236 | !validateRemoteAs(nodes.get(i).asNumber()) || | 241 | !validateRemoteAs(nodes.get(i).asNumber()) || |
| 237 | - !validatePeerHoldTime(nodes.get(i).holdTime())) { | 242 | + !validatePeerHoldTime(nodes.get(i).holdTime()) || |
| 243 | + !(connectMode.equals(PEER_CONNECT_ACTIVE) || connectMode.equals(PEER_CONNECT_PASSIVE))) { | ||
| 238 | return false; | 244 | return false; |
| 239 | } | 245 | } |
| 240 | } | 246 | } |
| ... | @@ -258,7 +264,8 @@ public class BgpAppConfig extends Config<ApplicationId> { | ... | @@ -258,7 +264,8 @@ public class BgpAppConfig extends Config<ApplicationId> { |
| 258 | jsonNodes.forEach(jsonNode -> nodes.add(new BgpPeerConfig( | 264 | jsonNodes.forEach(jsonNode -> nodes.add(new BgpPeerConfig( |
| 259 | jsonNode.path(PEER_IP).asText(), | 265 | jsonNode.path(PEER_IP).asText(), |
| 260 | jsonNode.path(REMOTE_AS).asInt(), | 266 | jsonNode.path(REMOTE_AS).asInt(), |
| 261 | - jsonNode.path(PEER_HOLD_TIME).asInt()))); | 267 | + jsonNode.path(PEER_HOLD_TIME).asInt(), |
| 268 | + jsonNode.path(PEER_CONNECT_MODE).asText()))); | ||
| 262 | 269 | ||
| 263 | return nodes; | 270 | return nodes; |
| 264 | } | 271 | } |
| ... | @@ -271,11 +278,13 @@ public class BgpAppConfig extends Config<ApplicationId> { | ... | @@ -271,11 +278,13 @@ public class BgpAppConfig extends Config<ApplicationId> { |
| 271 | private final String hostname; | 278 | private final String hostname; |
| 272 | private final int asNumber; | 279 | private final int asNumber; |
| 273 | private final short holdTime; | 280 | private final short holdTime; |
| 281 | + private final String connectMode; | ||
| 274 | 282 | ||
| 275 | - public BgpPeerConfig(String hostname, int asNumber, int holdTime) { | 283 | + public BgpPeerConfig(String hostname, int asNumber, int holdTime, String connectMode) { |
| 276 | this.hostname = checkNotNull(hostname); | 284 | this.hostname = checkNotNull(hostname); |
| 277 | this.asNumber = asNumber; | 285 | this.asNumber = asNumber; |
| 278 | this.holdTime = (short) holdTime; | 286 | this.holdTime = (short) holdTime; |
| 287 | + this.connectMode = connectMode; | ||
| 279 | } | 288 | } |
| 280 | 289 | ||
| 281 | /** | 290 | /** |
| ... | @@ -304,5 +313,14 @@ public class BgpAppConfig extends Config<ApplicationId> { | ... | @@ -304,5 +313,14 @@ public class BgpAppConfig extends Config<ApplicationId> { |
| 304 | public short holdTime() { | 313 | public short holdTime() { |
| 305 | return this.holdTime; | 314 | return this.holdTime; |
| 306 | } | 315 | } |
| 316 | + | ||
| 317 | + /** | ||
| 318 | + * Returns connection mode for the peer node. | ||
| 319 | + * | ||
| 320 | + * @return active or passive connection | ||
| 321 | + */ | ||
| 322 | + public String connectMode() { | ||
| 323 | + return this.connectMode; | ||
| 324 | + } | ||
| 307 | } | 325 | } |
| 308 | } | 326 | } | ... | ... |
| ... | @@ -20,7 +20,6 @@ import org.apache.felix.scr.annotations.Component; | ... | @@ -20,7 +20,6 @@ import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Deactivate; | 20 | import org.apache.felix.scr.annotations.Deactivate; |
| 21 | import org.apache.felix.scr.annotations.Reference; | 21 | import org.apache.felix.scr.annotations.Reference; |
| 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 23 | -import org.apache.felix.scr.annotations.Service; | ||
| 24 | 23 | ||
| 25 | import org.onosproject.bgp.controller.BgpCfg; | 24 | import org.onosproject.bgp.controller.BgpCfg; |
| 26 | import org.onosproject.core.ApplicationId; | 25 | import org.onosproject.core.ApplicationId; |
| ... | @@ -45,7 +44,6 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -45,7 +44,6 @@ import static org.slf4j.LoggerFactory.getLogger; |
| 45 | * BGP config provider to validate and populate the configuration. | 44 | * BGP config provider to validate and populate the configuration. |
| 46 | */ | 45 | */ |
| 47 | @Component(immediate = true) | 46 | @Component(immediate = true) |
| 48 | -@Service | ||
| 49 | public class BgpCfgProvider extends AbstractProvider { | 47 | public class BgpCfgProvider extends AbstractProvider { |
| 50 | 48 | ||
| 51 | private static final Logger log = getLogger(BgpCfgProvider.class); | 49 | private static final Logger log = getLogger(BgpCfgProvider.class); |
| ... | @@ -127,7 +125,11 @@ public class BgpCfgProvider extends AbstractProvider { | ... | @@ -127,7 +125,11 @@ public class BgpCfgProvider extends AbstractProvider { |
| 127 | 125 | ||
| 128 | nodes = config.bgpPeer(); | 126 | nodes = config.bgpPeer(); |
| 129 | for (int i = 0; i < nodes.size(); i++) { | 127 | for (int i = 0; i < nodes.size(); i++) { |
| 128 | + String connectMode = nodes.get(i).connectMode(); | ||
| 130 | bgpConfig.addPeer(nodes.get(i).hostname(), nodes.get(i).asNumber(), nodes.get(i).holdTime()); | 129 | bgpConfig.addPeer(nodes.get(i).hostname(), nodes.get(i).asNumber(), nodes.get(i).holdTime()); |
| 130 | + if (connectMode.equals(BgpAppConfig.PEER_CONNECT_ACTIVE)) { | ||
| 131 | + bgpConfig.connectPeer(nodes.get(i).hostname()); | ||
| 132 | + } | ||
| 131 | } | 133 | } |
| 132 | } | 134 | } |
| 133 | 135 | ... | ... |
-
Please register or login to post a comment