mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-25 22:31:07 +02:00
Implementing Bgp connect
Change-Id: I6dd6d91c083bec54f31251e06c700d0a0dd54cd4
This commit is contained in:
parent
423fe2b487
commit
0008f1dabd
@ -52,6 +52,9 @@ public class BgpAppConfig extends Config<ApplicationId> {
|
|||||||
public static final String PEER_IP = "peerIp";
|
public static final String PEER_IP = "peerIp";
|
||||||
public static final String REMOTE_AS = "remoteAs";
|
public static final String REMOTE_AS = "remoteAs";
|
||||||
public static final String PEER_HOLD_TIME = "peerHoldTime";
|
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 int MAX_SHORT_AS_NUMBER = 65535;
|
||||||
static final long MAX_LONG_AS_NUMBER = 4294967295L;
|
static final long MAX_LONG_AS_NUMBER = 4294967295L;
|
||||||
@ -229,12 +232,15 @@ public class BgpAppConfig extends Config<ApplicationId> {
|
|||||||
*/
|
*/
|
||||||
public boolean validateBgpPeers() {
|
public boolean validateBgpPeers() {
|
||||||
List<BgpPeerConfig> nodes;
|
List<BgpPeerConfig> nodes;
|
||||||
|
String connectMode;
|
||||||
|
|
||||||
nodes = bgpPeer();
|
nodes = bgpPeer();
|
||||||
for (int i = 0; i < nodes.size(); i++) {
|
for (int i = 0; i < nodes.size(); i++) {
|
||||||
|
connectMode = nodes.get(i).connectMode();
|
||||||
if ((IpAddress.valueOf(nodes.get(i).hostname()) == null) ||
|
if ((IpAddress.valueOf(nodes.get(i).hostname()) == null) ||
|
||||||
!validateRemoteAs(nodes.get(i).asNumber()) ||
|
!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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -258,7 +264,8 @@ public class BgpAppConfig extends Config<ApplicationId> {
|
|||||||
jsonNodes.forEach(jsonNode -> nodes.add(new BgpPeerConfig(
|
jsonNodes.forEach(jsonNode -> nodes.add(new BgpPeerConfig(
|
||||||
jsonNode.path(PEER_IP).asText(),
|
jsonNode.path(PEER_IP).asText(),
|
||||||
jsonNode.path(REMOTE_AS).asInt(),
|
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;
|
return nodes;
|
||||||
}
|
}
|
||||||
@ -271,11 +278,13 @@ public class BgpAppConfig extends Config<ApplicationId> {
|
|||||||
private final String hostname;
|
private final String hostname;
|
||||||
private final int asNumber;
|
private final int asNumber;
|
||||||
private final short holdTime;
|
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.hostname = checkNotNull(hostname);
|
||||||
this.asNumber = asNumber;
|
this.asNumber = asNumber;
|
||||||
this.holdTime = (short) holdTime;
|
this.holdTime = (short) holdTime;
|
||||||
|
this.connectMode = connectMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -304,5 +313,14 @@ public class BgpAppConfig extends Config<ApplicationId> {
|
|||||||
public short holdTime() {
|
public short holdTime() {
|
||||||
return this.holdTime;
|
return this.holdTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns connection mode for the peer node.
|
||||||
|
*
|
||||||
|
* @return active or passive connection
|
||||||
|
*/
|
||||||
|
public String connectMode() {
|
||||||
|
return this.connectMode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,6 @@ import org.apache.felix.scr.annotations.Component;
|
|||||||
import org.apache.felix.scr.annotations.Deactivate;
|
import org.apache.felix.scr.annotations.Deactivate;
|
||||||
import org.apache.felix.scr.annotations.Reference;
|
import org.apache.felix.scr.annotations.Reference;
|
||||||
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
||||||
import org.apache.felix.scr.annotations.Service;
|
|
||||||
|
|
||||||
import org.onosproject.bgp.controller.BgpCfg;
|
import org.onosproject.bgp.controller.BgpCfg;
|
||||||
import org.onosproject.core.ApplicationId;
|
import org.onosproject.core.ApplicationId;
|
||||||
@ -45,7 +44,6 @@ import static org.slf4j.LoggerFactory.getLogger;
|
|||||||
* BGP config provider to validate and populate the configuration.
|
* BGP config provider to validate and populate the configuration.
|
||||||
*/
|
*/
|
||||||
@Component(immediate = true)
|
@Component(immediate = true)
|
||||||
@Service
|
|
||||||
public class BgpCfgProvider extends AbstractProvider {
|
public class BgpCfgProvider extends AbstractProvider {
|
||||||
|
|
||||||
private static final Logger log = getLogger(BgpCfgProvider.class);
|
private static final Logger log = getLogger(BgpCfgProvider.class);
|
||||||
@ -127,7 +125,11 @@ public class BgpCfgProvider extends AbstractProvider {
|
|||||||
|
|
||||||
nodes = config.bgpPeer();
|
nodes = config.bgpPeer();
|
||||||
for (int i = 0; i < nodes.size(); i++) {
|
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());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user