import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@RequestMapping("/")
public class Devices implements IDaylightWeb {
private static final UserLevel AUTH_LEVEL = UserLevel.CONTAINERUSER;
- private final String WEB_NAME = "Devices";
- private final String WEB_ID = "devices";
- private final short WEB_ORDER = 1;
+ private static final String WEB_NAME = "Devices";
+ private static final String WEB_ID = "devices";
+ private static final short WEB_ORDER = 1;
public Devices() {
ServiceHelper.registerGlobalService(IDaylightWeb.class, this, null);
nodeDatum.put("tierName", TierHelper.getTierName(tierNumber) + " (Tier-" + tierNumber + ")");
nodeDatum.put("tier", tierNumber + "");
String modeStr = "0";
- ForwardingMode mode = (ForwardingMode) switchManager.getNodeProp(node, ForwardingMode.name);
+ ForwardingMode mode = null;
+ if (!containerName.equals(GlobalConstants.DEFAULT.toString())) {
+ ISwitchManager switchManagerDefault = (ISwitchManager) ServiceHelper.getInstance(
+ ISwitchManager.class, GlobalConstants.DEFAULT.toString(), this);
+ mode = (ForwardingMode) switchManagerDefault.getNodeProp(node, ForwardingMode.name);
+ } else {
+ mode = (ForwardingMode) switchManager.getNodeProp(node, ForwardingMode.name);
+ }
if (mode != null) {
modeStr = String.valueOf(mode.getValue());
}
State portState = ((State) switchManager
.getNodeConnectorProp(nodeConnector,
State.StatePropName));
-
String nodeConnectorName = (ncName != null) ? ncName
.getValue() : "";
nodeConnectorName += " (" + nodeConnector.getID() + ")";
nodeProperties.put(desc.getName(), desc);
Property nodeTier = new Tier(Integer.parseInt(tier));
nodeProperties.put(nodeTier.getName(), nodeTier);
- Property mode = new ForwardingMode(Integer.parseInt(operationMode));
- nodeProperties.put(mode.getName(), mode);
+ if (containerName.equals(GlobalConstants.DEFAULT.toString())) {
+ Property mode = new ForwardingMode(Integer.parseInt(operationMode));
+ nodeProperties.put(mode.getName(), mode);
+ }
SwitchConfig cfg = new SwitchConfig(nodeId, nodeProperties);
Status result = switchManager.updateNodeConfig(cfg);
if (!result.isSuccess()) {
} else {
resultBean.setStatus(true);
resultBean.setMessage("Updated node information successfully");
+ DaylightWebUtil.auditlog("Node", userName, "updated", nodeId + " to "+ nodeName, containerName);
}
} catch (Exception e) {
resultBean.setStatus(false);
if (addStaticRouteResult.isSuccess()) {
result.setStatus(true);
result.setMessage("Static Route saved successfully");
+ DaylightWebUtil.auditlog("Static Route", userName, "added", routeName, containerName);
} else {
result.setStatus(false);
result.setMessage(addStaticRouteResult.getDescription());
resultBean.setMessage(result.getDescription());
break;
}
+ DaylightWebUtil.auditlog("Static Route", userName, "removed", route, containerName);
}
} catch (Exception e) {
resultBean.setStatus(false);
@RequestParam(required = false) String container) {
Gson gson = new Gson();
List<Map<String, String>> subnets = new ArrayList<Map<String, String>>();
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Derive the privilege this user has on the current container
String userName = request.getUserPrincipal().getName();
- Privilege privilege = DaylightWebUtil.getContainerPrivilege(
- userName, containerName, this);
+ Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this);
if (privilege != Privilege.NONE) {
- ISwitchManager switchManager = (ISwitchManager) ServiceHelper
- .getInstance(ISwitchManager.class, containerName, this);
+ ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class,
+ containerName, this);
if (switchManager != null) {
for (SubnetConfig conf : switchManager.getSubnetsConfigList()) {
Map<String, String> subnet = new HashMap<String, String>();
subnet.put("name", conf.getName());
subnet.put("subnet", conf.getSubnet());
- subnet.put("json", gson.toJson(conf));
+ List<SubnetGatewayPortBean> portsList = new ArrayList<SubnetGatewayPortBean>();
+ Iterator<NodeConnector> itor = conf.getNodeConnectors().iterator();
+ while(itor.hasNext()) {
+ SubnetGatewayPortBean bean = new SubnetGatewayPortBean();
+ NodeConnector nodeConnector = itor.next();
+ String nodeName = getNodeDesc(nodeConnector.getNode().toString(), containerName);
+ Name ncName = ((Name) switchManager.getNodeConnectorProp(nodeConnector, Name.NamePropName));
+ String nodeConnectorName = (ncName != null) ? ncName.getValue() : "";
+ bean.setNodeName(nodeName);
+ bean.setNodePortName(nodeConnectorName);
+ bean.setNodeId(nodeConnector.getNode().toString());
+ bean.setNodePortId(nodeConnector.toString());
+ portsList.add(bean);
+ }
+ subnet.put("nodePorts", gson.toJson(portsList));
subnets.add(subnet);
}
}
if (result.isSuccess()) {
resultBean.setStatus(true);
resultBean.setMessage("Added gateway address successfully");
+ DaylightWebUtil.auditlog("Subnet Gateway", userName, "added", gatewayName, containerName);
} else {
resultBean.setStatus(false);
resultBean.setMessage(result.getDescription());
resultBean.setMessage(result.getDescription());
break;
}
+ DaylightWebUtil.auditlog("Subnet Gateway", userName, "removed", subnet, containerName);
}
} catch (Exception e) {
resultBean.setStatus(false);
try {
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
.getInstance(ISwitchManager.class, containerName, this);
- Status result = switchManager.addPortsToSubnet(portsName, nodeId
- + "/" + ports);
+ List<String> toAdd = new ArrayList<String>();
+ for (String port : ports.split(",")) {
+ toAdd.add(port);
+ }
+ Status result = switchManager.addPortsToSubnet(portsName, toAdd);
if (result.isSuccess()) {
resultBean.setStatus(true);
resultBean
.setMessage("Added ports to subnet gateway address successfully");
+ DaylightWebUtil.auditlog("Ports to Subnet Gateway", userName, "added", ports, containerName);
} else {
resultBean.setStatus(false);
resultBean.setMessage(result.getDescription());
try {
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
.getInstance(ISwitchManager.class, containerName, this);
- Status result = switchManager.removePortsFromSubnet(gatewayName,
- nodePort);
+ List<String> toRemove = new ArrayList<String>();
+ for (String port : nodePort.split(",")) {
+ toRemove.add(port);
+ }
+ Status result = switchManager.removePortsFromSubnet(gatewayName, toRemove);
if (result.isSuccess()) {
resultBean.setStatus(true);
- resultBean
- .setMessage("Deleted port from subnet gateway address successfully");
+ resultBean.setMessage("Deleted port from subnet gateway address successfully");
+ DaylightWebUtil.auditlog("Ports from Subnet Gateway", userName, "removed", nodePort, containerName);
} else {
resultBean.setStatus(false);
resultBean.setMessage(result.getDescription());
Map<String, String> config = new HashMap<String, String>();
for (String name : config_data.keySet()) {
config.put(name, config_data.get(name));
- // Add switch name value (non-configuration field)
+ // Add switch portName value (non-configuration field)
config.put("nodeName",
getNodeDesc(config_data.get("nodeId"), containerName));
}
@RequestMapping(value = "/nodeports")
@ResponseBody
- public Map<String, Object> getNodePorts(HttpServletRequest request,
- @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT
- .toString() : container;
+ public String getNodePorts(HttpServletRequest request, @RequestParam(required = false) String container) {
+ String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
// Derive the privilege this user has on the current container
String userName = request.getUserPrincipal().getName();
return null;
}
-
ISwitchManager switchManager = (ISwitchManager) ServiceHelper
.getInstance(ISwitchManager.class, containerName, this);
if (switchManager == null) {
return null;
}
-
- Map<String, Object> nodes = new HashMap<String, Object>();
- Map<Short, String> port;
+ List<NodeJsonBean> nodeJsonBeans = new ArrayList<NodeJsonBean>();
for (Switch node : switchManager.getNetworkDevices()) {
- port = new HashMap<Short, String>(); // new port
+ NodeJsonBean nodeJsonBean = new NodeJsonBean();
+ List<PortJsonBean> port = new ArrayList<PortJsonBean>();
Set<NodeConnector> nodeConnectorSet = node.getNodeConnectors();
-
if (nodeConnectorSet != null) {
for (NodeConnector nodeConnector : nodeConnectorSet) {
String nodeConnectorName = ((Name) switchManager
- .getNodeConnectorProp(nodeConnector,
- Name.NamePropName)).getValue();
- port.put((Short) nodeConnector.getID(), nodeConnectorName
- + "(" + nodeConnector.getID() + ")");
+ .getNodeConnectorProp(nodeConnector, Name.NamePropName)).getValue();
+ port.add(new PortJsonBean(nodeConnector.getID().toString(), nodeConnectorName, nodeConnector.toString()));
}
}
-
- nodes.put(node.getNode().toString(), port);
+ nodeJsonBean.setNodeId(node.getNode().toString());
+ nodeJsonBean.setNodeName(getNodeDesc(node.getNode().toString(), containerName));
+ nodeJsonBean.setNodePorts(port);
+ nodeJsonBeans.add(nodeJsonBean);
}
- return nodes;
+ return new Gson().toJson(nodeJsonBeans);
}
@RequestMapping(value = "/spanPorts/add", method = RequestMethod.GET)
if (result.isSuccess()) {
resultBean.setStatus(true);
resultBean.setMessage("SPAN Port added successfully");
+ DaylightWebUtil.auditlog("SPAN Port", userName, "added", cfgObject.getNodeId(), containerName);
} else {
resultBean.setStatus(false);
resultBean.setMessage(result.getDescription());
resultBean.setMessage(result.getDescription());
break;
}
+ DaylightWebUtil.auditlog("SPAN Port", userName, "removed", cfgObject.getNodeId(), containerName);
}
}
} catch (Exception e) {