From 2c2c6cc3e047faca0ccb7dae5e727d5dfb17d6cc Mon Sep 17 00:00:00 2001 From: rsahot036 Date: Fri, 22 Jun 2018 14:35:07 -0400 Subject: [PATCH] Adding get flow by table REST api, fixing exceptions in dhcp Change-Id: Idc07992a91c79f594c998b2d78b980036077c0ad --- .../dhcprelay/cli/DhcpRelayCommand.java | 2 +- .../dhcprelay/config/DhcpServerConfig.java | 22 +++++++++++++--- .../rest/resources/FlowsWebResource.java | 26 +++++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayCommand.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayCommand.java index 6bf46b8340..90816b013e 100644 --- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayCommand.java +++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/cli/DhcpRelayCommand.java @@ -109,7 +109,7 @@ public class DhcpRelayCommand extends AbstractShellCommand { boolean toResetFlag; if (counter != null) { - if (counter.equals("counter") || reset.equals("[counter]")) { + if (counter.equals("counter") || counter.equals("[counter]")) { print(CONUTER_HEADER); } else { print("first parameter is [counter]"); diff --git a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/config/DhcpServerConfig.java b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/config/DhcpServerConfig.java index cf71aa2aae..d60c6b0f30 100644 --- a/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/config/DhcpServerConfig.java +++ b/apps/dhcprelay/src/main/java/org/onosproject/dhcprelay/config/DhcpServerConfig.java @@ -76,10 +76,18 @@ public class DhcpServerConfig { if (node.isTextual()) { IpAddress ip = IpAddress.valueOf(node.asText()); if (ip.isIp4() && serverIp4Addr == null) { - serverIp4Addr = ip.getIp4Address(); + try { + serverIp4Addr = ip.getIp4Address(); + } catch (IllegalArgumentException iae) { + log.warn("Invalid IPv4 address {} found in DHCP server config. Ignored.", ip.toString()); + } } if (ip.isIp6() && serverIp6Addr == null) { + try { serverIp6Addr = ip.getIp6Address(); + } catch (IllegalArgumentException iae) { + log.warn("Invalid IPv6 address {} found in DHCP server config. Ignored.", ip.toString()); + } } } }); @@ -90,10 +98,18 @@ public class DhcpServerConfig { if (node.isTextual()) { IpAddress ip = IpAddress.valueOf(node.asText()); if (ip.isIp4() && gatewayIp4Addr == null) { - gatewayIp4Addr = ip.getIp4Address(); + try { + gatewayIp4Addr = ip.getIp4Address(); + } catch (IllegalArgumentException iae) { + log.warn("Invalid IPv4 address {} found in DHCP gateway config. Ignored.", ip.toString()); + } } if (ip.isIp6() && gatewayIp6Addr == null) { - gatewayIp6Addr = ip.getIp6Address(); + try { + gatewayIp6Addr = ip.getIp6Address(); + } catch (IllegalArgumentException iae) { + log.warn("Invalid IPv6 address {} found in DHCP gateway config. Ignored.", ip.toString()); + } } } }); diff --git a/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java index d8d3d80a8c..f789f77273 100644 --- a/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java +++ b/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java @@ -29,6 +29,7 @@ import org.onosproject.net.device.DeviceService; import org.onosproject.net.flow.FlowEntry; import org.onosproject.net.flow.FlowRule; import org.onosproject.net.flow.FlowRuleService; +import org.onosproject.net.flow.IndexTableId; import org.onosproject.rest.AbstractWebResource; import javax.ws.rs.Consumes; @@ -124,6 +125,31 @@ public class FlowsWebResource extends AbstractWebResource { return ok(root).build(); } + /** + * Gets all flow entries for a table. Returns array of all flow rules for a table. + * @param tableId table identifier + * @return 200 OK with a collection of flows + * @onos.rsModel FlowEntries + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("table/{tableId}") + public Response getTableFlows(@PathParam("tableId") int tableId) { + final Iterable devices = get(DeviceService.class).getDevices(); + for (final Device device : devices) { + final Iterable flowEntries = service.getFlowEntries(device.id()); + if (flowEntries != null) { + for (final FlowEntry entry : flowEntries) { + if (((IndexTableId) entry.table()).id() == tableId) { + flowsNode.add(codec(FlowEntry.class).encode(entry, this)); + } + } + } + } + + return ok(root).build(); + } + /** * Creates new flow rules. Creates and installs a new flow rules.
* Flow rule criteria and instruction description: