package org.opendaylight.controller.flows.web;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@RequestMapping(value = "/main")
@ResponseBody
- public Map<String, Object> getFlows(HttpServletRequest request, @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
+ public Map<String, Object> getFlows(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();
- Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName, containerName, this);
- if (privilege == Privilege.NONE) {
+ Privilege privilege = DaylightWebUtil.getContainerPrivilege(userName,
+ containerName, this);
+ if (privilege == Privilege.NONE) {
return null;
}
flowSet.add(entry);
}
- Map <String, Object> output = new HashMap<String, Object>(2);
+ Map<String, Object> output = new HashMap<String, Object>(2);
output.put("flows", flowSet);
output.put("privilege", privilege);
return output;
@RequestMapping(value = "/node-ports")
@ResponseBody
- public Map<String, Object> getNodePorts(HttpServletRequest request, @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
+ public Map<String, Object> 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();
- if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) == Privilege.NONE) {
+ if (DaylightWebUtil
+ .getContainerPrivilege(userName, containerName, this) == Privilege.NONE) {
return null;
}
@RequestMapping(value = "/node-flows")
@ResponseBody
- public Map<String, Object> getNodeFlows(HttpServletRequest request, @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
+ public Map<String, Object> getNodeFlows(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();
- if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) == Privilege.NONE) {
+ if (DaylightWebUtil
+ .getContainerPrivilege(userName, containerName, this) == Privilege.NONE) {
return null;
}
List<FlowConfig> flows = frm.getStaticFlows(node);
String nodeDesc = node.toString();
- SwitchConfig config = switchManager.getSwitchConfig(node
- .toString());
- if ((config != null) && (config.getProperty(Description.propertyName) != null)) {
- nodeDesc = ((Description) config.getProperty(Description.propertyName)).getValue();
+ SwitchConfig config = switchManager
+ .getSwitchConfig(node.toString());
+ if ((config != null)
+ && (config.getProperty(Description.propertyName) != null)) {
+ nodeDesc = ((Description) config
+ .getProperty(Description.propertyName)).getValue();
}
nodes.put(nodeDesc, flows.size());
public String actionFlow(@RequestParam(required = true) String action,
@RequestParam(required = false) String body,
@RequestParam(required = true) String nodeId,
- HttpServletRequest request, @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
+ HttpServletRequest request,
+ @RequestParam(required = false) String container) {
+ String containerName = (container == null) ? GlobalConstants.DEFAULT
+ .toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
- if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
+ if (DaylightWebUtil
+ .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
return "Operation not authorized";
}
Status result = new Status(StatusCode.BADREQUEST, "Invalid request");
if (action.equals("add")) {
result = frm.addStaticFlow(flow);
- DaylightWebUtil.auditlog("Flow", userName, "added", flow.getName(), containerName);
+ DaylightWebUtil.auditlog("Flow", userName, "added", flow.getName(),
+ containerName);
}
return (result.isSuccess()) ? StatusCode.SUCCESS.toString() : result
public String removeFlow(@PathVariable("nodeId") String nodeId,
@PathVariable("name") String name,
@RequestParam(required = true) String action,
- HttpServletRequest request, @RequestParam(required = false) String container) {
- String containerName = (container == null) ? GlobalConstants.DEFAULT.toString() : container;
+ HttpServletRequest request,
+ @RequestParam(required = false) String container) {
+ String containerName = (container == null) ? GlobalConstants.DEFAULT
+ .toString() : container;
// Authorization check
String userName = request.getUserPrincipal().getName();
- if (DaylightWebUtil.getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
+ if (DaylightWebUtil
+ .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
return "Operation not authorized";
}
}
if (action.equals("remove")) {
result = frm.removeStaticFlow(name, node);
- if(result.isSuccess()) {
- DaylightWebUtil.auditlog("Flow", userName, "removed", name, containerName);
+ if (result.isSuccess()) {
+ DaylightWebUtil.auditlog("Flow", userName, "removed", name,
+ containerName);
}
} else if (action.equals("toggle")) {
result = frm.toggleStaticFlowStatus(name, node);
- if(result.isSuccess()) {
- DaylightWebUtil.auditlog("Flow", userName, "toggled", name, containerName);
+ if (result.isSuccess()) {
+ DaylightWebUtil.auditlog("Flow", userName, "toggled", name,
+ containerName);
}
} else {
result = new Status(StatusCode.BADREQUEST, "Unknown action");
.getDescription();
}
+ @SuppressWarnings("unchecked")
+ @RequestMapping(value = "/flow/deleteFlows", method = RequestMethod.POST)
+ @ResponseBody
+ public String removeSelectedFlows(
+ @RequestParam(required = false) String body,
+ HttpServletRequest request,
+ @RequestParam(required = false) String container) {
+ String containerName = (container == null) ? GlobalConstants.DEFAULT
+ .toString() : container;
+
+ // Authorization check
+ String userName = request.getUserPrincipal().getName();
+ if (DaylightWebUtil
+ .getContainerPrivilege(userName, containerName, this) != Privilege.WRITE) {
+ return "Operation not authorized";
+ }
+
+ IForwardingRulesManager frm = (IForwardingRulesManager) ServiceHelper
+ .getInstance(IForwardingRulesManager.class, containerName, this);
+ if (frm == null) {
+ return "Forwarding Rules Manager is not available";
+ }
+
+ Gson gson = new Gson();
+ List<Map<String, String>> flowList = new ArrayList<Map<String, String>>();
+ flowList = gson.fromJson(body, flowList.getClass());
+ Status result = new Status(StatusCode.BADREQUEST, "Invalid request");
+ String status = "";
+ for (Map<String, String> flowEntry : flowList) {
+ Node node = Node.fromString(flowEntry.get("node"));
+ result = frm.removeStaticFlow(flowEntry.get("name"), node);
+ if (result.isSuccess()) {
+ DaylightWebUtil.auditlog("Flow", userName, "removed",
+ flowEntry.get("name"), containerName);
+ } else {
+ status = flowEntry.get("name") + ", " + status;
+ }
+ }
+ if (!status.equals("")) {
+ return "Could not remove "
+ + status.substring(0, status.length() - 2) + " Flow(s)";
+ } else {
+ return "Success";
+ }
+ }
+
private String getNodeDesc(Node node, ISwitchManager switchManager) {
- Description desc = (Description) switchManager.getNodeProp(node, Description.propertyName);
+ Description desc = (Description) switchManager.getNodeProp(node,
+ Description.propertyName);
String description = (desc == null) ? "" : desc.getValue();
- return (description.isEmpty() || description.equalsIgnoreCase("none")) ? node.toString() : description;
+ return (description.isEmpty() || description.equalsIgnoreCase("none")) ? node
+ .toString() : description;
}
}
main : "/main",
flows : "/node-flows",
nodes : "/node-ports",
- flow : "/flow"
+ flow : "/flow",
+ deleteFlows:"/flow/deleteFlows"
}
}
id : {
dashlet : {
add : "one_f_flows_id_dashlet_add",
+ removeMultiple : "one_f_flows_id_dashlet_removeMultiple",
remove : "one_f_flows_id_dashlet_remove",
toggle : "one_f_flows_id_dashlet_toggle",
- datagrid: "one_f_flows_id_dashlet_datagrid"
+ datagrid : "one_f_flows_id_dashlet_datagrid",
+ selectAllFlows : "one_f_flows_id_dashlet_selectAllFlows"
},
modal : {
install : "one_f_flows_id_modal_install",
$modal.modal();
});
$dashlet.append($button);
+ var button = one.lib.dashlet.button.single("Remove Flow Entry", one.f.flows.id.dashlet.removeMultiple, "btn-primary", "btn-mini");
+ var $button = one.lib.dashlet.button.button(button);
+
+ $button.click(function() {
+ var checkedCheckBoxes = $('.flowEntry[type=checkbox]:checked');
+
+ var requestData = [];
+
+ var resource = {};
+ checkedCheckBoxes.each(function(index, value) {
+ var flowEntry = {};
+ flowEntry['name'] = checkedCheckBoxes[index].name;
+ flowEntry['node'] = checkedCheckBoxes[index].getAttribute("node");
+ requestData.push(flowEntry);
+ });
+ resource['body'] = JSON.stringify(requestData);
+
+ $.post(one.f.address.root+one.f.address.flows.deleteFlows, resource, function(response) {
+ if(response == "Success") {
+ one.lib.alert("Flow(s) successfully removed");
+ } else {
+ one.lib.alert(response);
+ }
+ one.main.dashlet.right.bottom.empty();
+ one.f.detail.dashlet(one.main.dashlet.right.bottom);
+ one.main.dashlet.left.top.empty();
+ one.f.flows.dashlet(one.main.dashlet.left.top);
+ });
+ });
+ $dashlet.append($button);
}
$dashlet.append($gridHTML);
var dataSource = one.f.flows.data.flowsDataGrid(data);
$("#" + one.f.flows.id.dashlet.datagrid).datagrid({dataSource: dataSource}).on("loaded", function() {
- $("#" + one.f.flows.id.dashlet.datagrid).find("tbody tr").each(function(index, tr) {
+ $("#"+one.f.flows.id.dashlet.datagrid.selectAllFlows).click(function() {
+ $("#" + one.f.flows.id.dashlet.datagrid).find(':checkbox').prop('checked',
+ $("#"+one.f.flows.id.dashlet.datagrid.selectAllFlows).is(':checked'));
+ });
+
+ $("#" + one.f.flows.id.dashlet.datagrid).find("tbody tr").each(function(index, tr) {
$tr = $(tr);
$span = $("td span", $tr);
var flowstatus = $span.data("flowstatus");
});
// attach click event
$tr.click(function() {
- var $td = $($(this).find("td")[0]);
+ var $td = $($(this).find("td")[1]);
var id = $td.text();
var node = $td.find("span").data("nodeid");
- one.f.flows.detail(id, node);
+ one.f.flows.detail(id, node);
+ });
+ $(".flowEntry").click(function(){
+ if (!$('.flowEntry[type=checkbox]:not(:checked)').length) {
+ $("#"+one.f.flows.id.dashlet.datagrid.selectAllFlows)
+ .prop("checked",
+ true);
+ } else {
+ $("#"+one.f.flows.id.dashlet.datagrid.selectAllFlows)
+ .prop("checked",
+ false);
+ }
+ event.stopPropagation();
});
});
});
flowsDataGrid: function(data) {
var source = new StaticDataSource({
columns: [
+ {
+ property: 'selector',
+ label: "<input type='checkbox' id='"+one.f.flows.id.dashlet.datagrid.selectAllFlows+"'/>",
+ sortable: false
+ },
{
property: 'name',
label: 'Flow Name',
data: data.flows,
formatter: function(items) {
$.each(items, function(index, item) {
- item["name"] = '<span data-installInHw=' + item["flow"]["installInHw"] +
+ var $checkbox = document.createElement("input");
+ $checkbox.setAttribute("type", "checkbox");
+ $checkbox.setAttribute("name", item.name);
+ $checkbox.setAttribute("node", item.node);
+ $checkbox.setAttribute('class','flowEntry')
+ item.selector = $checkbox.outerHTML;
+ item["name"] = '<span data-installInHw=' + item["flow"]["installInHw"] +
' data-flowstatus=' + item["flow"]["status"] +
' data-nodeId=' + item["nodeId"] + '>' + item["name"] + '</span>';
});
$(data).each(function(index, value) {
var tr = {};
var entry = [];
+
+
entry.push(value['name']);
entry.push(value['node']);
if (value['flow']['installInHw'] == 'true' && value['flow']['status'] == 'Success')
var $table = one.lib.dashlet.table.table(attributes);
var headers = ['Flow Name', 'Node'];
+
var $thead = one.lib.dashlet.table.header(headers);
$table.append($thead);
var $tbody = one.lib.dashlet.table.body(body);
$table.append($tbody);
-
return $table;
}
}