Implementing Bgp connect
Change-Id: I6dd6d91c083bec54f31251e06c700d0a0dd54cd4
diff --git a/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpAppConfig.java b/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpAppConfig.java
index 4bf916c..4bd6e70 100644
--- a/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpAppConfig.java
+++ b/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpAppConfig.java
@@ -52,6 +52,9 @@
public static final String PEER_IP = "peerIp";
public static final String REMOTE_AS = "remoteAs";
public static final String PEER_HOLD_TIME = "peerHoldTime";
+ public static final String PEER_CONNECT_MODE = "connectMode";
+ public static final String PEER_CONNECT_PASSIVE = "passive";
+ public static final String PEER_CONNECT_ACTIVE = "active";
static final int MAX_SHORT_AS_NUMBER = 65535;
static final long MAX_LONG_AS_NUMBER = 4294967295L;
@@ -229,12 +232,15 @@
*/
public boolean validateBgpPeers() {
List<BgpPeerConfig> nodes;
+ String connectMode;
nodes = bgpPeer();
for (int i = 0; i < nodes.size(); i++) {
+ connectMode = nodes.get(i).connectMode();
if ((IpAddress.valueOf(nodes.get(i).hostname()) == null) ||
!validateRemoteAs(nodes.get(i).asNumber()) ||
- !validatePeerHoldTime(nodes.get(i).holdTime())) {
+ !validatePeerHoldTime(nodes.get(i).holdTime()) ||
+ !(connectMode.equals(PEER_CONNECT_ACTIVE) || connectMode.equals(PEER_CONNECT_PASSIVE))) {
return false;
}
}
@@ -258,7 +264,8 @@
jsonNodes.forEach(jsonNode -> nodes.add(new BgpPeerConfig(
jsonNode.path(PEER_IP).asText(),
jsonNode.path(REMOTE_AS).asInt(),
- jsonNode.path(PEER_HOLD_TIME).asInt())));
+ jsonNode.path(PEER_HOLD_TIME).asInt(),
+ jsonNode.path(PEER_CONNECT_MODE).asText())));
return nodes;
}
@@ -271,11 +278,13 @@
private final String hostname;
private final int asNumber;
private final short holdTime;
+ private final String connectMode;
- public BgpPeerConfig(String hostname, int asNumber, int holdTime) {
+ public BgpPeerConfig(String hostname, int asNumber, int holdTime, String connectMode) {
this.hostname = checkNotNull(hostname);
this.asNumber = asNumber;
this.holdTime = (short) holdTime;
+ this.connectMode = connectMode;
}
/**
@@ -304,5 +313,14 @@
public short holdTime() {
return this.holdTime;
}
+
+ /**
+ * Returns connection mode for the peer node.
+ *
+ * @return active or passive connection
+ */
+ public String connectMode() {
+ return this.connectMode;
+ }
}
}
diff --git a/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpCfgProvider.java b/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpCfgProvider.java
index 523a38b..d79c4b8 100755
--- a/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpCfgProvider.java
+++ b/providers/bgp/cfg/src/main/java/org/onosproject/provider/bgp/cfg/impl/BgpCfgProvider.java
@@ -20,7 +20,6 @@
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.Service;
import org.onosproject.bgp.controller.BgpCfg;
import org.onosproject.core.ApplicationId;
@@ -45,7 +44,6 @@
* BGP config provider to validate and populate the configuration.
*/
@Component(immediate = true)
-@Service
public class BgpCfgProvider extends AbstractProvider {
private static final Logger log = getLogger(BgpCfgProvider.class);
@@ -127,7 +125,11 @@
nodes = config.bgpPeer();
for (int i = 0; i < nodes.size(); i++) {
+ String connectMode = nodes.get(i).connectMode();
bgpConfig.addPeer(nodes.get(i).hostname(), nodes.get(i).asNumber(), nodes.get(i).holdTime());
+ if (connectMode.equals(BgpAppConfig.PEER_CONNECT_ACTIVE)) {
+ bgpConfig.connectPeer(nodes.get(i).hostname());
+ }
}
}