X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fweb%2Ftroubleshoot%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Ftroubleshoot%2Fweb%2FTroubleshoot.java;h=36b5043dd94ebf6956c499da4ad4909864a9c936;hp=dfa21075ea845eaf3140a701cf99d706553c41dc;hb=6fd408a04fe4a3611843e2246ece6d7c34b76903;hpb=2ed2e3f076e2d3bdab22fdcb94672d850c6c64a8 diff --git a/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java b/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java index dfa21075ea..36b5043dd9 100644 --- a/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java +++ b/opendaylight/web/troubleshoot/src/main/java/org/opendaylight/controller/troubleshoot/web/Troubleshoot.java @@ -14,12 +14,25 @@ import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; +import javax.servlet.http.HttpServletRequest; + import org.opendaylight.controller.sal.action.Action; import org.opendaylight.controller.sal.action.Output; +import org.opendaylight.controller.sal.action.SetDlDst; +import org.opendaylight.controller.sal.action.SetDlSrc; +import org.opendaylight.controller.sal.action.SetNwDst; +import org.opendaylight.controller.sal.action.SetNwSrc; +import org.opendaylight.controller.sal.action.SetNwTos; +import org.opendaylight.controller.sal.action.SetTpDst; +import org.opendaylight.controller.sal.action.SetTpSrc; import org.opendaylight.controller.sal.action.SetVlanId; +import org.opendaylight.controller.sal.action.SetVlanPcp; +import org.opendaylight.controller.sal.authorization.Privilege; import org.opendaylight.controller.sal.authorization.UserLevel; +import org.opendaylight.controller.sal.core.Description; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.core.TimeStamp; @@ -36,6 +49,7 @@ import org.opendaylight.controller.sal.utils.NetUtils; import org.opendaylight.controller.sal.utils.ServiceHelper; import org.opendaylight.controller.statisticsmanager.IStatisticsManager; import org.opendaylight.controller.switchmanager.ISwitchManager; +import org.opendaylight.controller.web.DaylightWebUtil; import org.opendaylight.controller.web.IDaylightWeb; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -47,10 +61,21 @@ import org.springframework.web.bind.annotation.ResponseBody; @RequestMapping("/") public class Troubleshoot implements IDaylightWeb { private static final UserLevel AUTH_LEVEL = UserLevel.CONTAINERUSER; + private static final List flowStatsColumnNames = Arrays.asList("Node", "In Port", + "DL Src", "DL Dst", "DL Type", "DL Vlan","Vlan Priority", "NW Src", "NW Dst","ToS Bits", + "NW Proto", "TP Src", "TP Dst", "Actions", "Bytes", "Packets", + "Time (s)", "Timeout (s)", + "Priority"); + private static final List portStatsColumnNames = Arrays.asList("Node Connector", + "Rx Pkts", "Tx Pkts", "Rx Bytes", "Tx Bytes", "Rx Drops", + "Tx Drops", "Rx Errs", "Tx Errs", "Rx Frame Errs", + "Rx OverRun Errs", "Rx CRC Errs", "Collisions"); + private static final List nodesColumnNames = Arrays.asList("Node", "Node ID", "Statistics"); + private static final List nodeStatsColumnNames = Arrays.asList("Node", "Node ID", "Statistics"); private final String WEB_NAME = "Troubleshoot"; private final String WEB_ID = "troubleshoot"; private final short WEB_ORDER = 4; - private final String containerName = GlobalConstants.DEFAULT.toString(); + public Troubleshoot() { ServiceHelper.registerGlobalService(IDaylightWeb.class, this, null); @@ -78,65 +103,65 @@ public class Troubleshoot implements IDaylightWeb { @RequestMapping(value = "/existingNodes", method = RequestMethod.GET) @ResponseBody - public TroubleshootingJsonBean getExistingNodes() { - ISwitchManager switchManager = (ISwitchManager) ServiceHelper - .getInstance(ISwitchManager.class, containerName, this); - List> lines = new ArrayList>(); - Set nodeSet = null; - if (switchManager != null) { - nodeSet = switchManager.getNodes(); - } - if (nodeSet != null) { - for (Node node : nodeSet) { - HashMap device = new HashMap(); - device.put("nodeName", switchManager.getNodeDescription(node)); - device.put("nodeId", node.toString()); - lines.add(device); + public TroubleshootingJsonBean getExistingNodes(HttpServletRequest request, @RequestParam(required = false) String container) { + List> lines = new ArrayList>(); + 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); + + if (privilege != Privilege.NONE) { + ISwitchManager switchManager = (ISwitchManager) ServiceHelper + .getInstance(ISwitchManager.class, containerName, this); + Set nodeSet = (switchManager != null) ? switchManager.getNodes() : null; + if (nodeSet != null) { + for (Node node : nodeSet) { + Map device = new HashMap(); + device.put("nodeName", getNodeDesc(node, switchManager)); + device.put("nodeId", node.toString()); + lines.add(device); + } } } - TroubleshootingJsonBean result = new TroubleshootingJsonBean(); - List guiFieldNames = new ArrayList(); - guiFieldNames.add("Node"); - guiFieldNames.add("Node ID"); - guiFieldNames.add("Statistics"); - - result.setColumnNames(guiFieldNames); + TroubleshootingJsonBean result = new TroubleshootingJsonBean(); + result.setColumnNames(nodesColumnNames); result.setNodeData(lines); return result; } @RequestMapping(value = "/uptime", method = RequestMethod.GET) @ResponseBody - public TroubleshootingJsonBean getUptime() { - ISwitchManager switchManager = (ISwitchManager) ServiceHelper - .getInstance(ISwitchManager.class, containerName, this); - List> lines = new ArrayList>(); - Set nodeSet = null; - if (switchManager != null) { - nodeSet = switchManager.getNodes(); - } - if (nodeSet != null) { - for (Node node : nodeSet) { - HashMap device = new HashMap(); - device.put("nodeName", switchManager.getNodeDescription(node)); - device.put("nodeId", node.toString()); - TimeStamp timeStamp = (TimeStamp) switchManager.getNodeProp( - node, TimeStamp.TimeStampPropName); - Long time = (timeStamp == null) ? 0 : timeStamp.getValue(); - String date = (time == 0) ? "" : (new Date(time)).toString(); - device.put("connectedSince", date); - lines.add(device); + public TroubleshootingJsonBean getUptime(HttpServletRequest request, @RequestParam(required = false) String container) { + List> lines = new ArrayList>(); + 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); + + if (privilege != Privilege.NONE) { + ISwitchManager switchManager = (ISwitchManager) ServiceHelper + .getInstance(ISwitchManager.class, containerName, this); + Set nodeSet = (switchManager != null) ? switchManager.getNodes() : null; + if (nodeSet != null) { + for (Node node : nodeSet) { + Map device = new HashMap(); + device.put("nodeName", getNodeDesc(node, switchManager)); + device.put("nodeId", node.toString()); + TimeStamp timeStamp = (TimeStamp) switchManager.getNodeProp( + node, TimeStamp.TimeStampPropName); + Long time = (timeStamp == null) ? 0 : timeStamp.getValue(); + String date = (time == 0) ? "" : (new Date(time)).toString(); + device.put("connectedSince", date); + lines.add(device); + } } } - TroubleshootingJsonBean result = new TroubleshootingJsonBean(); - List guiFieldNames = new ArrayList(); - guiFieldNames.add("Node"); - guiFieldNames.add("Node ID"); - guiFieldNames.add("Connected"); - - result.setColumnNames(guiFieldNames); + TroubleshootingJsonBean result = new TroubleshootingJsonBean(); + result.setColumnNames(nodeStatsColumnNames); result.setNodeData(lines); return result; } @@ -144,24 +169,29 @@ public class Troubleshoot implements IDaylightWeb { @RequestMapping(value = "/flowStats", method = RequestMethod.GET) @ResponseBody public TroubleshootingJsonBean getFlowStats( - @RequestParam("nodeId") String nodeId) { - Node node = Node.fromString(nodeId); - List> cells = new ArrayList>(); - IStatisticsManager statisticsManager = (IStatisticsManager) ServiceHelper - .getInstance(IStatisticsManager.class, containerName, this); - - List statistics = statisticsManager.getFlows(node); - for (FlowOnNode stats : statistics) { - cells.add(this.convertFlowStatistics(node, stats)); + @RequestParam("nodeId") String nodeId, + HttpServletRequest request, @RequestParam(required = false) String container) { + List> cells = new ArrayList>(); + 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); + + if (privilege != Privilege.NONE) { + IStatisticsManager statisticsManager = (IStatisticsManager) ServiceHelper + .getInstance(IStatisticsManager.class, containerName, this); + if (statisticsManager != null) { + Node node = Node.fromString(nodeId); + List statistics = statisticsManager.getFlows(node); + for (FlowOnNode stats : statistics) { + cells.add(this.convertFlowStatistics(node, stats, containerName)); + } + } } - List columnNames = new ArrayList(); - columnNames.addAll(Arrays.asList(new String[] { "Node", "In Port", - "DL Src", "DL Dst", "DL Type", "DL Vlan", "NW Src", "NW Dst", - "NW Proto", "TP Src", "TP Dst", "Actions", "Bytes", "Packets", - "Time (s)", "Timeout (s)", "Out Port(s)", "Out Vlan", - "Priority" })); + TroubleshootingJsonBean result = new TroubleshootingJsonBean(); - result.setColumnNames(columnNames); + result.setColumnNames(flowStatsColumnNames); result.setNodeData(cells); return result; } @@ -169,33 +199,49 @@ public class Troubleshoot implements IDaylightWeb { @RequestMapping(value = "/portStats", method = RequestMethod.GET) @ResponseBody public TroubleshootingJsonBean getPortStats( - @RequestParam("nodeId") String nodeId) { - Node node = Node.fromString(nodeId); - List> cells = new ArrayList>(); - IStatisticsManager statisticsManager = (IStatisticsManager) ServiceHelper - .getInstance(IStatisticsManager.class, containerName, this); - List statistics = statisticsManager - .getNodeConnectorStatistics(node); - for (NodeConnectorStatistics stats : statistics) { - cells.add(this.convertPortsStatistics(stats)); + @RequestParam("nodeId") String nodeId, + HttpServletRequest request, @RequestParam(required = false) String container) { + List> cells = new ArrayList>(); + 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); + + if (privilege != Privilege.NONE) { + IStatisticsManager statisticsManager = (IStatisticsManager) ServiceHelper + .getInstance(IStatisticsManager.class, containerName, this); + if (statisticsManager != null) { + Node node = Node.fromString(nodeId); + List statistics = statisticsManager + .getNodeConnectorStatistics(node); + for (NodeConnectorStatistics stats : statistics) { + cells.add(this.convertPortsStatistics(stats, containerName)); + } + } } + TroubleshootingJsonBean result = new TroubleshootingJsonBean(); - List columnNames = new ArrayList(); - columnNames.addAll(Arrays.asList(new String[] { "Node Connector", - "Rx Pkts", "Tx Pkts", "Rx Bytes", "Tx Bytes", "Rx Drops", - "Tx Drops", "Rx Errs", "Tx Errs", "Rx Frame Errs", - "Rx OverRun Errs", "Rx CRC Errs", "Collisions" })); - result.setColumnNames(columnNames); + result.setColumnNames(portStatsColumnNames); result.setNodeData(cells); return result; } - private HashMap convertPortsStatistics( - NodeConnectorStatistics ncStats) { - HashMap row = new HashMap(); + private Map convertPortsStatistics( + NodeConnectorStatistics ncStats, String containerName) { + Map row = new HashMap(); + + ISwitchManager switchManager = (ISwitchManager) ServiceHelper + .getInstance(ISwitchManager.class, containerName, this); + NodeConnector nodeConnector = ncStats.getNodeConnector(); + Description description = (Description) switchManager.getNodeProp(nodeConnector.getNode(), Description.propertyName); + String desc = (description == null) ? "" : description.getValue(); + String nodeName = desc.equalsIgnoreCase("none") ? nodeConnector.getNode().getNodeIDString() : desc; + String nodeConnectorDisplayName = nodeConnector.getType() + "|" + nodeConnector.getID() + "@" + nodeName; row.put("nodeConnector", - String.valueOf(ncStats.getNodeConnector().toString())); + String.valueOf(nodeConnectorDisplayName)); + row.put("rxPkts", String.valueOf(ncStats.getReceivePacketCount())); row.put("txPkts", String.valueOf(ncStats.getTransmitPacketCount())); row.put("rxBytes", String.valueOf(ncStats.getReceiveByteCount())); @@ -215,17 +261,17 @@ public class Troubleshoot implements IDaylightWeb { return row; } - private HashMap convertFlowStatistics(Node node, - FlowOnNode flowOnNode) { - HashMap row = new HashMap(); + private Map convertFlowStatistics(Node node, + FlowOnNode flowOnNode, + String containerName) { + Map row = new HashMap(); Flow flow = flowOnNode.getFlow(); Match match = flow.getMatch(); ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); - String desc = (switchManager == null)? - "" : switchManager.getNodeDescription(node); - desc = (desc.isEmpty() || desc.equalsIgnoreCase("none"))? - node.toString(): desc; + String desc = getNodeDesc(node, switchManager); + desc = (desc == null || desc.isEmpty() || desc.equalsIgnoreCase("none"))? + node.toString() : desc; row.put("nodeName", desc); if (match.isPresent(MatchType.IN_PORT)) { row.put(MatchType.IN_PORT.id(), ((NodeConnector) flow.getMatch() @@ -268,6 +314,19 @@ public class Troubleshoot implements IDaylightWeb { } else { row.put(MatchType.DL_VLAN.id(), "*"); } + //Vlan Priority + if (match.isPresent(MatchType.DL_VLAN_PR)) { + if (((Byte) flow.getMatch().getField(MatchType.DL_VLAN_PR).getValue()) + .shortValue() < 0) { + row.put(MatchType.DL_VLAN_PR.id(), "0"); + } else { + row.put(MatchType.DL_VLAN_PR.id(), ((Byte) flow.getMatch() + .getField(MatchType.DL_VLAN_PR).getValue()).toString()); + } + } else { + row.put(MatchType.DL_VLAN_PR.id(), "*"); + } + if (match.isPresent(MatchType.NW_SRC)) { row.put(MatchType.NW_SRC.id(), ((InetAddress) flow.getMatch() .getField(MatchType.NW_SRC).getValue()).getHostAddress()); @@ -280,6 +339,12 @@ public class Troubleshoot implements IDaylightWeb { } else { row.put(MatchType.NW_DST.id(), "*"); } + if (match.isPresent(MatchType.NW_TOS)) { + row.put(MatchType.NW_TOS.id(), ((Byte) flow.getMatch() + .getField(MatchType.NW_TOS).getValue()).toString()); + } else { + row.put(MatchType.NW_TOS.id(), "*"); + } if (match.isPresent(MatchType.NW_PROTO)) { row.put(MatchType.NW_PROTO.id(), IPProtocols.getProtocolName(((Byte) flow.getMatch() @@ -291,7 +356,7 @@ public class Troubleshoot implements IDaylightWeb { Short tpSrc = (Short) (flow.getMatch().getField(MatchType.TP_SRC) .getValue()); row.put(MatchType.TP_SRC.id(), - String.valueOf(NetUtils.getUnsignedShort(tpSrc))); + String.valueOf(NetUtils.getUnsignedShort(tpSrc))); } else { row.put(MatchType.TP_SRC.id(), "*"); } @@ -299,7 +364,7 @@ public class Troubleshoot implements IDaylightWeb { Short tpDst = (Short) (flow.getMatch().getField(MatchType.TP_DST) .getValue()); row.put(MatchType.TP_DST.id(), - String.valueOf(NetUtils.getUnsignedShort(tpDst))); + String.valueOf(NetUtils.getUnsignedShort(tpDst))); } else { row.put(MatchType.TP_DST.id(), "*"); } @@ -309,34 +374,61 @@ public class Troubleshoot implements IDaylightWeb { StringBuffer actions = new StringBuffer(); StringBuffer outPorts = new StringBuffer(); - String outVlanId = null; for (Action action : flow.getActions()) { - actions.append(action.getType().toString() + "\n"); + if (action instanceof Output) { Output ao = (Output) action; if (outPorts.length() > 0) { outPorts.append(" "); } - outPorts.append(ao.getPort().getNodeConnectorIdAsString()); + actions.append(action.getType().toString()).append(" = ").append(ao.getPort().getNodeConnectorIdAsString()).append("
"); } else if (action instanceof SetVlanId) { SetVlanId av = (SetVlanId) action; - outVlanId = String.valueOf(av.getVlanId()); + String outVlanId = String.valueOf(av.getVlanId()); + actions.append(action.getType().toString()).append(" = ").append(outVlanId).append("
"); + } else if (action instanceof SetDlSrc) { + SetDlSrc ads = (SetDlSrc) action; + actions.append(action.getType().toString()).append(" = ").append(HexEncode.bytesToHexStringFormat(ads.getDlAddress())).append("
"); + } else if (action instanceof SetDlDst) { + SetDlDst add = (SetDlDst) action; + actions.append(action.getType().toString()).append(" = ").append(HexEncode.bytesToHexStringFormat(add.getDlAddress())).append("
"); + } else if (action instanceof SetNwSrc) { + SetNwSrc ans = (SetNwSrc) action; + actions.append(action.getType().toString()).append(" = ").append(ans.getAddressAsString()).append("
"); + } else if (action instanceof SetNwDst) { + SetNwDst and = (SetNwDst) action; + actions.append(action.getType().toString()).append(" = ").append(and.getAddressAsString()).append("
"); + } else if (action instanceof SetNwTos) { + SetNwTos ant = (SetNwTos) action; + actions.append(action.getType().toString()).append(" = ").append(ant.getNwTos()).append("
"); + } else if (action instanceof SetTpSrc) { + SetTpSrc ads = (SetTpSrc) action; + actions.append(action.getType().toString()).append(" = ").append(ads.getPort()).append("
"); + } else if (action instanceof SetTpDst) { + SetTpDst atd = (SetTpDst) action; + actions.append(action.getType().toString()).append(" = ").append(atd.getPort()).append("
"); + } else if (action instanceof SetVlanPcp) { + SetVlanPcp avp = (SetVlanPcp) action; + actions.append(action.getType().toString()).append(" = ").append(avp.getPcp()).append("
"); + // } else if (action instanceof SetDlSrc) { + // SetDlSrc ads = (SetDlSrc) action; + } else { + actions.append(action.getType().toString()).append("
"); } } - if (outPorts.length() == 0) { - outPorts.append("*"); - } - if (outVlanId == null) { - outVlanId = "*"; - } row.put("actions", actions.toString()); - row.put("outPorts", outPorts.toString()); - row.put("outVlanId", outVlanId); row.put("durationSeconds", ((Integer) flowOnNode.getDurationSeconds()).toString()); row.put("idleTimeout", ((Short) flow.getIdleTimeout()).toString()); - row.put("priority", String.valueOf(flow.getPriority())); + row.put("priority", String.valueOf(NetUtils.getUnsignedShort(flow.getPriority()))); return row; } + private String getNodeDesc(Node node, ISwitchManager switchManager) { + if (switchManager == null) { + return null; + } + Description desc = (Description) switchManager.getNodeProp(node, Description.propertyName); + return (desc == null) ? "" : desc.getValue(); + } }