Node Name in non-default container should default to Node Name in Default Slice
[controller.git] / opendaylight / switchmanager / implementation / src / main / java / org / opendaylight / controller / switchmanager / internal / SwitchManager.java
index 07252b06f78dfb2a80a4c88d112f6b3f41fd5422..8372f88e7dce895e135debf1daef17e18d02b0f1 100644 (file)
@@ -54,6 +54,7 @@ import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
 import org.opendaylight.controller.sal.reader.NodeDescription;
 import org.opendaylight.controller.sal.utils.GlobalConstants;
 import org.opendaylight.controller.sal.utils.IObjectReader;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.controller.sal.utils.Status;
 import org.opendaylight.controller.sal.utils.StatusCode;
 import org.opendaylight.controller.statisticsmanager.IStatisticsManager;
@@ -115,6 +116,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 +292,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 +302,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);
         }
     }
@@ -1014,6 +1018,18 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
                     ForwardingMode mode = (ForwardingMode) nodeProperties.get(ForwardingMode.name);
                     forwardingModeChanged = mode.isProactive();
                 }
+            } else if ((conf == null) &&  !(GlobalConstants.DEFAULT.toString().equals(containerName))) {
+                ISwitchManager defaultSwitchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, GlobalConstants.DEFAULT.toString(), this);
+                if (defaultSwitchManager != null) {
+                    Property defaultContainerSwitchDesc = (Description) defaultSwitchManager.getNodeProp(node, Description.propertyName);
+                    if (defaultContainerSwitchDesc != null) {
+                        Map<String, Property> descPropMap = new HashMap<String, Property>();
+                        descPropMap.put(Description.propertyName, defaultContainerSwitchDesc);
+                        conf = new SwitchConfig(nodeId, descPropMap);
+                        updateNodeConfig(conf);
+                        propMap.put(Description.propertyName, defaultContainerSwitchDesc);
+                    }
+                }
             }
         }