}
}
+ @Override
public ConcurrentMap<String, StaticRouteConfig> getStaticRouteConfigs() {
return staticRouteConfigs;
}
}
private void notifyHostUpdate(HostNodeConnector host, boolean added) {
- if (host == null)
+ if (host == null) {
return;
+ }
for (StaticRoute s : staticRoutes.values()) {
- if (s.getType() == StaticRoute.NextHopType.SWITCHPORT)
+ if (s.getType() == StaticRoute.NextHopType.SWITCHPORT) {
continue;
+ }
if (s.getNextHopAddress().equals(host.getNetworkAddress())) {
if (added) {
s.setHost(host);
}
public boolean isIPv4AddressValid(String cidr) {
- if (cidr == null)
+ if (cidr == null) {
return false;
+ }
String values[] = cidr.split("/");
Pattern ipv4Pattern = Pattern
return 0;
}
+ @Override
public StaticRoute getBestMatchStaticRoute(InetAddress ipAddress) {
ByteBuffer bblongestPrefix = null;
try {
return longestPrefixRoute;
}
+ @Override
public Status addStaticRoute(StaticRouteConfig config) {
- Status status;
-
- status = config.isValid();
+ Status status = config.isValid();
if (!status.isSuccess()) {
return status;
}
"A valid Static Route configuration with this name " +
"already exists. Please use a different name");
}
- for (StaticRouteConfig s : staticRouteConfigs.values()) {
- if (s.equals(config)) {
+
+ // Update database
+ StaticRoute sRoute = new StaticRoute(config);
+
+ for (Map.Entry<String, StaticRoute> entry : staticRoutes.entrySet()) {
+ if (entry.getValue().compareTo(sRoute) == 0) {
return new Status(StatusCode.CONFLICT,
- "This conflicts with an existing Static Route " +
- "Configuration. Please check the configuration " +
- "and try again");
+ "This conflicts with an existing Static Route " +
+ "Configuration. Please check the configuration " +
+ "and try again");
}
}
+ staticRoutes.put(config.getName(), sRoute);
+ // Update config databse
staticRouteConfigs.put(config.getName(), config);
- StaticRoute sRoute = new StaticRoute(config);
- staticRoutes.put(config.getName(), sRoute);
+
+ // Notify
checkAndUpdateListeners(sRoute, true);
return status;
}
+ @Override
public Status removeStaticRoute(String name) {
staticRouteConfigs.remove(name);
StaticRoute sRoute = staticRoutes.remove(name);
allocateCaches();
retrieveCaches();
this.executor = Executors.newFixedThreadPool(1);
- if (staticRouteConfigs.isEmpty())
+ if (staticRouteConfigs.isEmpty()) {
loadConfiguration();
+ }
/*
* Slow probe to identify any gateway that might have silently appeared
Assert.assertFalse(staticRoute1.equals(staticRoute3));
Assert.assertFalse(staticRoute1.equals(staticRoute4));
- Assert.assertTrue(staticRoute1.compareTo(staticRoute2) == 0 ? true : false);
- Assert.assertFalse(staticRoute1.compareTo(staticRoute3) == 0 ? true : false);
- Assert.assertTrue(staticRoute1.compareTo(staticRoute4) == 0 ? true : false);
+ Assert.assertTrue(staticRoute1.compareTo(staticRoute2) == 0);
+ Assert.assertFalse(staticRoute1.compareTo(staticRoute3) == 0);
+ Assert.assertTrue(staticRoute1.compareTo(staticRoute4) == 0);
}
/**
* Returns the list of Flow entries across network nodes which are part of
- * the same flow group, policy
+ * the same flow group, policy. This list contains the flows as they were
+ * requested to be installed by the applications, before any merging with
+ * container flow is done.
*
* @param group
* the group name
- * @return the list of flow entries belonging to the specified group
+ * @return the original list of flow entries belonging to the specified group
*/
public List<FlowEntry> getFlowEntriesForGroup(String group);
+ /**
+ * Returns the list of Flow entries installed in network nodes which are part of
+ * the same flow group, policy. This list contains the effective flows installed
+ * on the nodes after the merging with any possible container flow was performed.
+ * If no container flow are specified, this method returns the same list returned
+ * by getFlowEntriesForGroup(String group).
+ *
+ * @param group
+ * the group name
+ * @return the list of container flow merged flow entries belonging to the specified group
+ */
+ public List<FlowEntry> getInstalledFlowEntriesForGroup(String policyName);
+
/**
* Add a list of output port to the flow with the specified name on the
* specified network node
return list;
}
+ @Override
+ public List<FlowEntry> getInstalledFlowEntriesForGroup(String policyName) {
+ List<FlowEntry> list = new ArrayList<FlowEntry>();
+ if (policyName != null && !policyName.trim().isEmpty()) {
+ for (Map.Entry<FlowEntryInstall, FlowEntryInstall> entry : this.installedSwView.entrySet()) {
+ if (policyName.equals(entry.getKey().getGroupName())) {
+ list.add(entry.getKey().getInstall().clone());
+ }
+ }
+ }
+ return list;
+ }
+
@Override
public void addOutputPort(Node node, String flowName, List<NodeConnector> portList) {
switchConfig = new SwitchConfig(nodeId, updateProperties);
} else {
// check if description is configured or was published by any other node
- for (Node n : nodeProps.keySet()) {
+ for (Map.Entry<Node, Map<String, Property>> entry : nodeProps.entrySet()) {
+ Node n = entry.getKey();
Description desc = (Description) getNodeProp(n, Description.propertyName);
NodeDescription nDesc = (this.statisticsManager == null) ? null : this.statisticsManager
.getNodeDescription(n);
return new Status(StatusCode.SUCCESS);
}
Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
- for (String prop : prevNodeProperties.keySet()) {
+ for (Map.Entry<String, Property> entry : prevNodeProperties.entrySet()) {
+ String prop = entry.getKey();
if (!updateProperties.containsKey(prop)) {
if (prop.equals(Description.propertyName)) {
if (!advertisedDesc.isEmpty()) {
Map<String, Property> propMapCurr = nodeProps.get(node);
if ((propMapCurr != null) && (nodeProperties != null) && (!nodeProperties.isEmpty())) {
Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
- for (String prop : nodeProperties.keySet()) {
+ for (Map.Entry<String, Property> entry : nodeProperties.entrySet()) {
+ String prop = entry.getKey();
if (prop.equals(Description.propertyName)) {
Map<Node, Map<String, Property>> nodeProp = this.inventoryService.getNodeProps();
if (nodeProp.get(node) != null) {
return;
}
nodeProps.remove(node);
+ nodeConnectorNames.remove(node);
+ Set<NodeConnector> removeNodeConnectorSet = new HashSet<NodeConnector>();
+ for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+ NodeConnector nodeConnector = entry.getKey();
+ if (nodeConnector.getNode().equals(node)) {
+ removeNodeConnectorSet.add(nodeConnector);
+ }
+ }
+ for (NodeConnector nc : removeNodeConnectorSet) {
+ nodeConnectorProps.remove(nc);
+ }
// check if span ports need to be cleaned up
removeSpanPorts(node);
}
Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
- for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+ for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+ NodeConnector nodeConnector = entry.getKey();
if (!nodeConnector.getNode().equals(node)) {
continue;
}
}
Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
- for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+ for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+ NodeConnector nodeConnector = entry.getKey();
if (!nodeConnector.getNode().equals(node)) {
continue;
}
}
Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
- for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+ for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+ NodeConnector nodeConnector = entry.getKey();
if (!nodeConnector.getNode().equals(node)
|| isSpecial(nodeConnector)) {
continue;
Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
if (mapCurr != null) {
- for (String s : mapCurr.keySet()) {
+ for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+ String s = entry.getKey();
try {
- map.put(s, new NodeConnector(mapCurr.get(s)));
+ map.put(s, new NodeConnector(entry.getValue()));
} catch (ConstructionException e) {
e.printStackTrace();
}
Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
if (mapCurr != null) {
Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
- for (String s : mapCurr.keySet()) {
+ for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+ String s = entry.getKey();
try {
- map.put(s, new NodeConnector(mapCurr.get(s)));
+ map.put(s, new NodeConnector(entry.getValue()));
} catch (ConstructionException e) {
e.printStackTrace();
}
Map<String, NodeConnector> mapCurr = nodeConnectorNames.get(node);
if (mapCurr != null) {
Map<String, NodeConnector> map = new HashMap<String, NodeConnector>();
- for (String s : mapCurr.keySet()) {
+ for (Map.Entry<String, NodeConnector> entry : mapCurr.entrySet()) {
+ String s = entry.getKey();
try {
- map.put(s, new NodeConnector(mapCurr.get(s)));
+ map.put(s, new NodeConnector(entry.getValue()));
} catch (ConstructionException e) {
e.printStackTrace();
}
service.notifyNode(node, type, propMap);
}
- for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
+ for (Map.Entry<NodeConnector, Map<String, Property>> entry : nodeConnectorProps.entrySet()) {
+ NodeConnector nodeConnector = entry.getKey();
propMap = nodeConnectorProps.get(nodeConnector);
service.notifyNodeConnector(nodeConnector, type, propMap);
}
}
for (UserConfig conf : confList.values()) {
- addLocalUser(conf);
+ addRemoveLocalUserInternal(conf, false);
}
}
/*
* Interaction with GUI START
*/
- public Status addRemoveLocalUser(UserConfig AAAconf, boolean delete) {
+ private Status addRemoveLocalUser(UserConfig AAAconf, boolean delete) {
// UserConfig Validation check
Status validCheck = AAAconf.validate();
if (!validCheck.isSuccess()) {
return validCheck;
}
+ String user = AAAconf.getUser();
+
+ // Check default admin user
+ if (user.equals(UserManagerImpl.defaultAdmin)) {
+ String msg = "Invalid Request: Default Network Admin User cannot be " + ((delete)? "removed" : "added");
+ logger.debug(msg);
+ return new Status(StatusCode.NOTALLOWED, msg);
+ }
+
+ // Check user presence/conflict
+ StatusCode statusCode = null;
+ String reason = null;
+ if (delete && !localUserConfigList.containsKey(user)) {
+ reason = "not found";
+ statusCode = StatusCode.NOTFOUND;
+ } else if (!delete && localUserConfigList.containsKey(user)) {
+ reason = "already present";
+ statusCode = StatusCode.CONFLICT;
+ }
+ if (statusCode != null) {
+ String msg = String.format("User %s %s in configuration database", user, reason);
+ logger.debug(msg);
+ return new Status(statusCode, msg);
+ }
+
+ return addRemoveLocalUserInternal(AAAconf, delete);
+ }
+
+ private Status addRemoveLocalUserInternal(UserConfig AAAconf, boolean delete) {
// Update Config database
if (delete) {
- if (AAAconf.getUser().equals(UserManagerImpl.defaultAdmin)) {
- String msg = "Invalid Request: Default Network Admin User "
- + "cannot be deleted";
- logger.debug(msg);
- return new Status(StatusCode.NOTALLOWED, msg);
- }
localUserConfigList.remove(AAAconf.getUser());
/*
* A user account has been removed form local database, we assume
*/
removeUserFromActiveList(AAAconf.getUser());
} else {
- if (AAAconf.getUser().equals(UserManagerImpl.defaultAdmin)) {
- String msg = "Invalid Request: Default Network Admin User "
- + "cannot be added";
- logger.debug(msg);
- return new Status(StatusCode.NOTALLOWED, msg);
- }
localUserConfigList.put(AAAconf.getUser(), AAAconf);
}
- return new Status(StatusCode.SUCCESS, null);
+ return new Status(StatusCode.SUCCESS);
}
private Status addRemoveAAAServer(ServerConfig AAAconf, boolean delete) {
remoteServerConfigList.put(AAAconf.getAddress(), AAAconf);
}
- return new Status(StatusCode.SUCCESS, null);
+ return new Status(StatusCode.SUCCESS);
}
private Status addRemoveAuthInfo(AuthorizationConfig AAAconf, boolean delete) {
authorizationConfList.put(AAAconf.getUser(), AAAconf);
}
- return new Status(StatusCode.SUCCESS, null);
+ return new Status(StatusCode.SUCCESS);
}
@Override
if (userName == null || userName.trim().isEmpty()) {
return new Status(StatusCode.BADREQUEST, "Invalid user name");
}
+
if (!localUserConfigList.containsKey(userName)) {
return new Status(StatusCode.NOTFOUND, "User does not exist");
}
+
return addRemoveLocalUser(localUserConfigList.get(userName), true);
}
}
if (success) {
- return new Status(StatusCode.SUCCESS, null);
+ return new Status(StatusCode.SUCCESS);
}
- return new Status(StatusCode.INTERNALERROR,
- "Failed to save user configurations");
+ return new Status(StatusCode.INTERNALERROR, "Failed to save user configurations");
}
@Override