Allow to disable default gw feature 29/6429/2
authorAlessandro Boch <aboch@cisco.com>
Sun, 27 Apr 2014 17:08:03 +0000 (10:08 -0700)
committerAlessandro Boch <aboch@cisco.com>
Sun, 27 Apr 2014 17:31:15 +0000 (10:31 -0700)
- Default gateway is a good feature for having host discovery, and
  consequently hosts' pings, work out of the box.
  But in real scenarios a controlled network node may be connected to a
  legacy switch's trunk port which exposes thousand of hosts which ARP
  packets would easily stress controller functionality.
  Even though today this can be prevented by configuring a more
  specific subnet gateway, the issue is very much possible at first
  controller boot, and can always re-occur during subnet config manipulation
  if at any point of time we have no user configured subnet gateways.
- This patch provides a way to disable he default gw feature by mean of
  a property in config.ini. Property addition is not included, current
  behavior is unchanged.

Change-Id: I15b63233e3ed46a8a9fb57bb0988a0d4a2984b11
Signed-off-by: Alessandro Boch <aboch@cisco.com>
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java

index 07252b06f78dfb2a80a4c88d112f6b3f41fd5422..e95ab8095d08c8b3fcf80094fc958d0053b4d256 100644 (file)
@@ -115,6 +115,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
      * only subnet returned. As soon as a user-configured subnet is created this one will
      * vanish.
      */
+    private static final String DISABLE_DEFAULT_SUBNET_PROP = "switchmanager.disableDefaultSubnetGateway";
+    private static final String DISABLE_DEFAULT_SUBNET_PROP_VAL = System.getProperty(DISABLE_DEFAULT_SUBNET_PROP);
+    private static final boolean USE_DEFAULT_SUBNET_GW = !Boolean.valueOf(DISABLE_DEFAULT_SUBNET_PROP_VAL);
     protected static final SubnetConfig DEFAULT_SUBNETCONFIG;
     protected static final Subnet DEFAULT_SUBNET;
     protected static final String DEFAULT_SUBNET_NAME = "default (cannot be modifed)";
@@ -288,9 +291,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
     @Override
     public List<SubnetConfig> getSubnetsConfigList() {
         // if there are no subnets, return the default subnet
-        if(subnetsConfigList.size() == 0){
+        if (USE_DEFAULT_SUBNET_GW && subnetsConfigList.isEmpty()) {
             return Collections.singletonList(DEFAULT_SUBNETCONFIG);
-        }else{
+        } else {
             return new ArrayList<SubnetConfig>(subnetsConfigList.values());
         }
     }
@@ -298,9 +301,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
     @Override
     public SubnetConfig getSubnetConfig(String subnet) {
         // if there are no subnets, return the default subnet
-        if(subnetsConfigList.isEmpty() && subnet.equalsIgnoreCase(DEFAULT_SUBNET_NAME)){
+        if (USE_DEFAULT_SUBNET_GW && subnetsConfigList.isEmpty() && subnet.equalsIgnoreCase(DEFAULT_SUBNET_NAME)) {
             return DEFAULT_SUBNETCONFIG;
-        }else{
+        } else {
             return subnetsConfigList.get(subnet);
         }
     }