From 55c40fd972a68ae81a1c6b8a3e4977e2aa838464 Mon Sep 17 00:00:00 2001 From: Colin Dixon Date: Thu, 7 Nov 2013 14:27:16 -0600 Subject: [PATCH 1/1] creating a default subnet This changes how SwitchManager handles subnets so that when there are no configured subents, it returns a default subnet that spans all ports in the network and spans all IP addresses, i.e., 0.0.0.0/0. This makes it so that HostTracker will discover all hosts by default instead of only discovering hosts in configured subents. This, in turn, makes SimpleForwarding forward traffic correctly without any configuration. Change-Id: Ice31b6035b970dd69fc69df3d9560b4aac41630d Signed-off-by: Colin Dixon --- .../integrationtest/NorthboundIT.java | 2 +- .../switchmanager/internal/SwitchManager.java | 32 +++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java b/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java index 7bec2722bf..602de9a1c6 100644 --- a/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java +++ b/opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java @@ -310,7 +310,7 @@ public class NorthboundIT { JSONTokener jt = new JSONTokener(result); JSONObject json = new JSONObject(jt); JSONArray subnetConfigs = json.getJSONArray("subnetConfig"); - Assert.assertEquals(subnetConfigs.length(), 0); + Assert.assertEquals(subnetConfigs.length(), 1); // should only get the default subnet // Test GET subnet1 expecting 404 result = getJsonResult(baseURL + "default/subnet/" + name1); diff --git a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java index 99482debd6..4d2aea2036 100644 --- a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java +++ b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java @@ -111,6 +111,19 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa private boolean isDefaultContainer = true; private static final int REPLACE_RETRY = 1; + /* Information about the default subnet. If there have been no configured subnets, i.e., + * subnets.size() == 0 or subnetsConfigList.size() == 0, then this subnet will be the + * only subnet returned. As soon as a user-configured subnet is created this one will + * vanish. + */ + protected static SubnetConfig DEFAULT_SUBNETCONFIG; + protected static Subnet DEFAULT_SUBNET; + protected static String DEFAULT_SUBNET_NAME = "default (cannot be modifed)"; + static{ + DEFAULT_SUBNETCONFIG = new SubnetConfig(DEFAULT_SUBNET_NAME, "0.0.0.0/0", new ArrayList()); + DEFAULT_SUBNET = new Subnet(DEFAULT_SUBNETCONFIG); + } + public void notifySubnetChange(Subnet sub, boolean add) { synchronized (switchManagerAware) { for (Object subAware : switchManagerAware) { @@ -295,12 +308,22 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa @Override public List getSubnetsConfigList() { - return new ArrayList(subnetsConfigList.values()); + // if there are no subnets, return the default subnet + if(subnetsConfigList.size() == 0){ + return Collections.singletonList(DEFAULT_SUBNETCONFIG); + }else{ + return new ArrayList(subnetsConfigList.values()); + } } @Override public SubnetConfig getSubnetConfig(String subnet) { - return subnetsConfigList.get(subnet); + // if there are no subnets, return the default subnet + if(subnetsConfigList.size() == 0 && subnet == DEFAULT_SUBNET_NAME){ + return DEFAULT_SUBNETCONFIG; + }else{ + return subnetsConfigList.get(subnet); + } } private List getSpanConfigList(Node node) { @@ -646,6 +669,11 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa @Override public Subnet getSubnetByNetworkAddress(InetAddress networkAddress) { + // if there are no subnets, return the default subnet + if (subnets.size() == 0) { + return DEFAULT_SUBNET; + } + Subnet sub; Set indices = subnets.keySet(); for (InetAddress i : indices) { -- 2.36.6