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> { ...@@ -61,6 +61,12 @@ public class BgpAppConfig extends Config<ApplicationId> {
61 static final int MAX_SHORT_AS_NUMBER = 65535; 61 static final int MAX_SHORT_AS_NUMBER = 65535;
62 static final long MAX_LONG_AS_NUMBER = 4294967295L; 62 static final long MAX_LONG_AS_NUMBER = 4294967295L;
63 63
64 + static final int MIN_SESSION_NUMBER = 1;
65 + static final long MAX_SESSION_NUMBER = 21;
66 +
67 + static final int MIN_HOLDTIME = 0;
68 + static final long MAX_HOLDTIME = 65535;
69 +
64 @Override 70 @Override
65 public boolean isValid() { 71 public boolean isValid() {
66 boolean fields = false; 72 boolean fields = false;
...@@ -71,7 +77,8 @@ public class BgpAppConfig extends Config<ApplicationId> { ...@@ -71,7 +77,8 @@ public class BgpAppConfig extends Config<ApplicationId> {
71 fields = hasOnlyFields(ROUTER_ID, LOCAL_AS, MAX_SESSION, LS_CAPABILITY, 77 fields = hasOnlyFields(ROUTER_ID, LOCAL_AS, MAX_SESSION, LS_CAPABILITY,
72 HOLD_TIME, LARGE_AS_CAPABILITY, FLOW_SPEC_CAPABILITY, FLOW_SPEC_RPD_CAPABILITY, BGP_PEER) && 78 HOLD_TIME, LARGE_AS_CAPABILITY, FLOW_SPEC_CAPABILITY, FLOW_SPEC_RPD_CAPABILITY, BGP_PEER) &&
73 isIpAddress(ROUTER_ID, MANDATORY) && isNumber(LOCAL_AS, MANDATORY) && 79 isIpAddress(ROUTER_ID, MANDATORY) && isNumber(LOCAL_AS, MANDATORY) &&
74 - isNumber(MAX_SESSION, OPTIONAL, 20) && isNumber(HOLD_TIME, OPTIONAL, 180) && 80 + isNumber(MAX_SESSION, OPTIONAL, MIN_SESSION_NUMBER, MAX_SESSION_NUMBER)
81 + && isNumber(HOLD_TIME, OPTIONAL, MIN_HOLDTIME, MAX_HOLDTIME) &&
75 isBoolean(LS_CAPABILITY, OPTIONAL) && isBoolean(LARGE_AS_CAPABILITY, OPTIONAL) && 82 isBoolean(LS_CAPABILITY, OPTIONAL) && isBoolean(LARGE_AS_CAPABILITY, OPTIONAL) &&
76 isString(FLOW_SPEC_CAPABILITY, OPTIONAL) && isBoolean(FLOW_SPEC_RPD_CAPABILITY, OPTIONAL); 83 isString(FLOW_SPEC_CAPABILITY, OPTIONAL) && isBoolean(FLOW_SPEC_RPD_CAPABILITY, OPTIONAL);
77 84
...@@ -171,6 +178,21 @@ public class BgpAppConfig extends Config<ApplicationId> { ...@@ -171,6 +178,21 @@ public class BgpAppConfig extends Config<ApplicationId> {
171 } 178 }
172 179
173 /** 180 /**
181 + * Validates the hold time value.
182 + *
183 + * @return true if valid else false
184 + */
185 + public boolean validateHoldTime() {
186 + if (holdTime() != 0) {
187 + short holdTime = holdTime();
188 + if ((holdTime == 1) || (holdTime == 2)) {
189 + return false;
190 + }
191 + }
192 + return true;
193 + }
194 +
195 + /**
174 * Validates the Bgp local and peer configuration. 196 * Validates the Bgp local and peer configuration.
175 * 197 *
176 * @return true if valid else false 198 * @return true if valid else false
...@@ -192,6 +214,10 @@ public class BgpAppConfig extends Config<ApplicationId> { ...@@ -192,6 +214,10 @@ public class BgpAppConfig extends Config<ApplicationId> {
192 if (!validateFlowSpec()) { 214 if (!validateFlowSpec()) {
193 return false; 215 return false;
194 } 216 }
217 +
218 + if (!validateHoldTime()) {
219 + return false;
220 + }
195 return true; 221 return true;
196 } 222 }
197 223
...@@ -205,10 +231,6 @@ public class BgpAppConfig extends Config<ApplicationId> { ...@@ -205,10 +231,6 @@ public class BgpAppConfig extends Config<ApplicationId> {
205 long localAs = 0; 231 long localAs = 0;
206 localAs = localAs(); 232 localAs = localAs();
207 233
208 - if (bgpController.connectedPeerCount() != 0) {
209 - return false;
210 - }
211 -
212 if (largeAsCapability()) { 234 if (largeAsCapability()) {
213 235
214 if (localAs == 0 || localAs >= MAX_LONG_AS_NUMBER) { 236 if (localAs == 0 || localAs >= MAX_LONG_AS_NUMBER) {
...@@ -250,9 +272,7 @@ public class BgpAppConfig extends Config<ApplicationId> { ...@@ -250,9 +272,7 @@ public class BgpAppConfig extends Config<ApplicationId> {
250 */ 272 */
251 public boolean validateRouterId() { 273 public boolean validateRouterId() {
252 String routerId = routerId(); 274 String routerId = routerId();
253 - if (bgpController.connectedPeerCount() != 0) { 275 + // TODO: router ID validation
254 - return false;
255 - }
256 return true; 276 return true;
257 } 277 }
258 278
......
...@@ -167,7 +167,10 @@ public class BgpCfgProvider extends AbstractProvider { ...@@ -167,7 +167,10 @@ public class BgpCfgProvider extends AbstractProvider {
167 167
168 168
169 /* Update the self configuration */ 169 /* Update the self configuration */
170 - if (bgpController.connectedPeerCount() == 0) { 170 + if (bgpController.connectedPeerCount() != 0) {
171 + //TODO: If connections already exist, disconnect
172 + bgpController.closeConnectedPeers();
173 + }
171 bgpConfig.setRouterId(config.routerId()); 174 bgpConfig.setRouterId(config.routerId());
172 bgpConfig.setAsNumber(config.localAs()); 175 bgpConfig.setAsNumber(config.localAs());
173 bgpConfig.setLsCapability(config.lsCapability()); 176 bgpConfig.setLsCapability(config.lsCapability());
...@@ -184,9 +187,6 @@ public class BgpCfgProvider extends AbstractProvider { ...@@ -184,9 +187,6 @@ public class BgpCfgProvider extends AbstractProvider {
184 } else { 187 } else {
185 bgpConfig.setFlowSpecCapability(BgpCfg.FlowSpec.NONE); 188 bgpConfig.setFlowSpecCapability(BgpCfg.FlowSpec.NONE);
186 } 189 }
187 - } else {
188 - log.info(" Self configuration cannot be modified as there is existing connections ");
189 - }
190 bgpConfig.setFlowSpecRpdCapability(config.rpdCapability()); 190 bgpConfig.setFlowSpecRpdCapability(config.rpdCapability());
191 191
192 /* update the peer configuration */ 192 /* update the peer configuration */
...@@ -227,6 +227,11 @@ public class BgpCfgProvider extends AbstractProvider { ...@@ -227,6 +227,11 @@ public class BgpCfgProvider extends AbstractProvider {
227 absPeerList.add(peer); 227 absPeerList.add(peer);
228 exists = false; 228 exists = false;
229 } 229 }
230 +
231 + if (peer.connectPeer() != null) {
232 + peer.connectPeer().disconnectPeer();
233 + peer.setConnectPeer(null);
234 + }
230 } 235 }
231 236
232 /* Remove the absent nodes. */ 237 /* Remove the absent nodes. */
......