Shashikanth VH
Committed by Gerrit Code Review

[ONOS-4243]Config support for RPD and flow spec

Change-Id: I459ac88caa3c57afe00f49938131a4163f1a9f5f
......@@ -61,6 +61,12 @@ public class BgpAppConfig extends Config<ApplicationId> {
static final int MAX_SHORT_AS_NUMBER = 65535;
static final long MAX_LONG_AS_NUMBER = 4294967295L;
static final int MIN_SESSION_NUMBER = 1;
static final long MAX_SESSION_NUMBER = 21;
static final int MIN_HOLDTIME = 0;
static final long MAX_HOLDTIME = 65535;
@Override
public boolean isValid() {
boolean fields = false;
......@@ -71,7 +77,8 @@ public class BgpAppConfig extends Config<ApplicationId> {
fields = hasOnlyFields(ROUTER_ID, LOCAL_AS, MAX_SESSION, LS_CAPABILITY,
HOLD_TIME, LARGE_AS_CAPABILITY, FLOW_SPEC_CAPABILITY, FLOW_SPEC_RPD_CAPABILITY, BGP_PEER) &&
isIpAddress(ROUTER_ID, MANDATORY) && isNumber(LOCAL_AS, MANDATORY) &&
isNumber(MAX_SESSION, OPTIONAL, 20) && isNumber(HOLD_TIME, OPTIONAL, 180) &&
isNumber(MAX_SESSION, OPTIONAL, MIN_SESSION_NUMBER, MAX_SESSION_NUMBER)
&& isNumber(HOLD_TIME, OPTIONAL, MIN_HOLDTIME, MAX_HOLDTIME) &&
isBoolean(LS_CAPABILITY, OPTIONAL) && isBoolean(LARGE_AS_CAPABILITY, OPTIONAL) &&
isString(FLOW_SPEC_CAPABILITY, OPTIONAL) && isBoolean(FLOW_SPEC_RPD_CAPABILITY, OPTIONAL);
......@@ -171,6 +178,21 @@ public class BgpAppConfig extends Config<ApplicationId> {
}
/**
* Validates the hold time value.
*
* @return true if valid else false
*/
public boolean validateHoldTime() {
if (holdTime() != 0) {
short holdTime = holdTime();
if ((holdTime == 1) || (holdTime == 2)) {
return false;
}
}
return true;
}
/**
* Validates the Bgp local and peer configuration.
*
* @return true if valid else false
......@@ -192,6 +214,10 @@ public class BgpAppConfig extends Config<ApplicationId> {
if (!validateFlowSpec()) {
return false;
}
if (!validateHoldTime()) {
return false;
}
return true;
}
......@@ -205,10 +231,6 @@ public class BgpAppConfig extends Config<ApplicationId> {
long localAs = 0;
localAs = localAs();
if (bgpController.connectedPeerCount() != 0) {
return false;
}
if (largeAsCapability()) {
if (localAs == 0 || localAs >= MAX_LONG_AS_NUMBER) {
......@@ -250,9 +272,7 @@ public class BgpAppConfig extends Config<ApplicationId> {
*/
public boolean validateRouterId() {
String routerId = routerId();
if (bgpController.connectedPeerCount() != 0) {
return false;
}
// TODO: router ID validation
return true;
}
......
......@@ -167,25 +167,25 @@ public class BgpCfgProvider extends AbstractProvider {
/* Update the self configuration */
if (bgpController.connectedPeerCount() == 0) {
bgpConfig.setRouterId(config.routerId());
bgpConfig.setAsNumber(config.localAs());
bgpConfig.setLsCapability(config.lsCapability());
bgpConfig.setHoldTime(config.holdTime());
bgpConfig.setMaxSession(config.maxSession());
bgpConfig.setLargeASCapability(config.largeAsCapability());
if (config.flowSpecCapability().equals("IPV4")) {
bgpConfig.setFlowSpecCapability(BgpCfg.FlowSpec.IPV4);
} else if (config.flowSpecCapability().equals("VPNV4")) {
bgpConfig.setFlowSpecCapability(BgpCfg.FlowSpec.VPNV4);
} else if (config.flowSpecCapability().equals("IPV4_VPNV4")) {
bgpConfig.setFlowSpecCapability(BgpCfg.FlowSpec.IPV4_VPNV4);
} else {
bgpConfig.setFlowSpecCapability(BgpCfg.FlowSpec.NONE);
}
if (bgpController.connectedPeerCount() != 0) {
//TODO: If connections already exist, disconnect
bgpController.closeConnectedPeers();
}
bgpConfig.setRouterId(config.routerId());
bgpConfig.setAsNumber(config.localAs());
bgpConfig.setLsCapability(config.lsCapability());
bgpConfig.setHoldTime(config.holdTime());
bgpConfig.setMaxSession(config.maxSession());
bgpConfig.setLargeASCapability(config.largeAsCapability());
if (config.flowSpecCapability().equals("IPV4")) {
bgpConfig.setFlowSpecCapability(BgpCfg.FlowSpec.IPV4);
} else if (config.flowSpecCapability().equals("VPNV4")) {
bgpConfig.setFlowSpecCapability(BgpCfg.FlowSpec.VPNV4);
} else if (config.flowSpecCapability().equals("IPV4_VPNV4")) {
bgpConfig.setFlowSpecCapability(BgpCfg.FlowSpec.IPV4_VPNV4);
} else {
log.info(" Self configuration cannot be modified as there is existing connections ");
bgpConfig.setFlowSpecCapability(BgpCfg.FlowSpec.NONE);
}
bgpConfig.setFlowSpecRpdCapability(config.rpdCapability());
......@@ -227,6 +227,11 @@ public class BgpCfgProvider extends AbstractProvider {
absPeerList.add(peer);
exists = false;
}
if (peer.connectPeer() != null) {
peer.connectPeer().disconnectPeer();
peer.setConnectPeer(null);
}
}
/* Remove the absent nodes. */
......