[ONOS-4992] Modify the return signature for FlowRuleService for consistent return object
Change-Id: I06154d79ea9d875c503369dcb77d5fffcfbd4467
diff --git a/core/api/src/main/java/org/onosproject/net/flow/FlowRuleService.java b/core/api/src/main/java/org/onosproject/net/flow/FlowRuleService.java
index 52af84a..62e725e 100644
--- a/core/api/src/main/java/org/onosproject/net/flow/FlowRuleService.java
+++ b/core/api/src/main/java/org/onosproject/net/flow/FlowRuleService.java
@@ -88,9 +88,18 @@
* @param id the application ID to look up
* @return collection of flow rules
*/
+ @Deprecated
Iterable<FlowRule> getFlowRulesById(ApplicationId id);
/**
+ * Returns a list of rules with this application ID.
+ *
+ * @param id the application ID to look up
+ * @return collection of flow rules
+ */
+ Iterable<FlowEntry> getFlowEntriesById(ApplicationId id);
+
+ /**
* Returns a list of rules filtered by application and group id.
* <p>
* Note that the group concept here is simply a logical grouping of flows.
diff --git a/core/api/src/test/java/org/onosproject/net/flow/FlowRuleServiceAdapter.java b/core/api/src/test/java/org/onosproject/net/flow/FlowRuleServiceAdapter.java
index 4335983..297e553 100644
--- a/core/api/src/test/java/org/onosproject/net/flow/FlowRuleServiceAdapter.java
+++ b/core/api/src/test/java/org/onosproject/net/flow/FlowRuleServiceAdapter.java
@@ -55,6 +55,11 @@
}
@Override
+ public Iterable<FlowEntry> getFlowEntriesById(ApplicationId id) {
+ return null;
+ }
+
+ @Override
public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
return null;
}
diff --git a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
index 50d74fc..17df9c4 100644
--- a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
+++ b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
@@ -264,6 +264,7 @@
removeFlowRules(Iterables.toArray(getFlowRulesById(id), FlowRule.class));
}
+ @Deprecated
@Override
public Iterable<FlowRule> getFlowRulesById(ApplicationId id) {
checkPermission(FLOWRULE_READ);
@@ -280,6 +281,21 @@
}
@Override
+ public Iterable<FlowEntry> getFlowEntriesById(ApplicationId id) {
+ checkPermission(FLOWRULE_READ);
+
+ Set<FlowEntry> flowEntries = Sets.newHashSet();
+ for (Device d : deviceService.getDevices()) {
+ for (FlowEntry flowEntry : store.getFlowEntries(d.id())) {
+ if (flowEntry.appId() == id.id()) {
+ flowEntries.add(flowEntry);
+ }
+ }
+ }
+ return flowEntries;
+ }
+
+ @Override
public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
checkPermission(FLOWRULE_READ);
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 fa5c3c7..36b8d4c 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
@@ -206,12 +206,13 @@
public Response getFlowByAppId(@PathParam("appId") String appId) {
final ApplicationService appService = get(ApplicationService.class);
final ApplicationId idInstant = nullIsNotFound(appService.getId(appId), APP_ID_NOT_FOUND);
- final Iterable<FlowRule> flowRules = service.getFlowRulesById(idInstant);
+ final Iterable<FlowEntry> flowEntries = service.getFlowEntriesById(idInstant);
- flowRules.forEach(flow -> flowsNode.add(codec(FlowRule.class).encode(flow, this)));
+ flowEntries.forEach(flow -> flowsNode.add(codec(FlowEntry.class).encode(flow, this)));
return ok(root).build();
}
+
/**
* Removes flow rules by application ID.
* Removes a collection of flow rules generated by the given application.
diff --git a/web/api/src/test/java/org/onosproject/rest/resources/FlowsResourceTest.java b/web/api/src/test/java/org/onosproject/rest/resources/FlowsResourceTest.java
index 2ecd373..2ba847e 100644
--- a/web/api/src/test/java/org/onosproject/rest/resources/FlowsResourceTest.java
+++ b/web/api/src/test/java/org/onosproject/rest/resources/FlowsResourceTest.java
@@ -15,11 +15,19 @@
*/
package org.onosproject.rest.resources;
-import com.eclipsesource.json.Json;
-import com.eclipsesource.json.JsonArray;
-import com.eclipsesource.json.JsonObject;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Sets;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
import org.hamcrest.Description;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
@@ -46,7 +54,6 @@
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.FlowEntry;
import org.onosproject.net.flow.FlowId;
-import org.onosproject.net.flow.FlowRule.FlowRemoveReason;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleExtPayLoad;
import org.onosproject.net.flow.FlowRuleService;
@@ -55,17 +62,10 @@
import org.onosproject.net.flow.criteria.Criterion;
import org.onosproject.net.flow.instructions.Instruction;
-import javax.ws.rs.NotFoundException;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
+import com.eclipsesource.json.Json;
+import com.eclipsesource.json.JsonArray;
+import com.eclipsesource.json.JsonObject;
+import com.google.common.collect.ImmutableSet;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.easymock.EasyMock.anyObject;
@@ -115,13 +115,7 @@
final MockFlowEntry flow5 = new MockFlowEntry(deviceId2, 5);
final MockFlowEntry flow6 = new MockFlowEntry(deviceId2, 6);
- final MockFlowRule flowRule1 = new MockFlowRule(deviceId1, 1);
- final MockFlowRule flowRule2 = new MockFlowRule(deviceId1, 2);
-
- final MockFlowRule flowRule3 = new MockFlowRule(deviceId2, 3);
- final MockFlowRule flowRule4 = new MockFlowRule(deviceId2, 4);
-
- final Set<FlowRule> flowRules = Sets.newHashSet();
+ final Set<FlowEntry> flowEntries = ImmutableSet.of(flow1, flow2, flow3, flow4, flow5, flow6);
/**
* Mock class for a flow entry.
@@ -249,92 +243,6 @@
}
}
- /**
- * Mock class for a flow rule.
- */
- private static class MockFlowRule implements FlowRule {
-
- final DeviceId deviceId;
- final long baseValue;
- TrafficTreatment treatment;
- TrafficSelector selector;
-
- public MockFlowRule(DeviceId deviceId, long id) {
- this.deviceId = deviceId;
- this.baseValue = id * 100;
- }
-
- @Override
- public FlowId id() {
- final long id = baseValue + 55;
- return FlowId.valueOf(id);
- }
-
- @Override
- public short appId() {
- return 4;
- }
-
- @Override
- public GroupId groupId() {
- return new DefaultGroupId(3);
- }
-
- @Override
- public int priority() {
- return 0;
- }
-
- @Override
- public DeviceId deviceId() {
- return deviceId;
- }
-
- @Override
- public TrafficSelector selector() {
- return selector;
- }
-
- @Override
- public TrafficTreatment treatment() {
- return treatment;
- }
-
- @Override
- public int timeout() {
- return (int) (baseValue + 77);
- }
-
- @Override
- public int hardTimeout() {
- return 0;
- }
-
- @Override
- public FlowRemoveReason reason() {
- return FlowRemoveReason.NO_REASON;
- }
-
- @Override
- public boolean isPermanent() {
- return false;
- }
-
- @Override
- public int tableId() {
- return 0;
- }
-
- @Override
- public boolean exactMatch(FlowRule rule) {
- return false;
- }
-
- @Override
- public FlowRuleExtPayLoad payLoad() {
- return null;
- }
- }
/**
* Populates some flows used as testing data.
@@ -367,26 +275,6 @@
}
/**
- * Populates some flow rules used as testing data.
- */
- private void setupMockFlowRules() {
- flowRule2.treatment = DefaultTrafficTreatment.builder()
- .setEthDst(MacAddress.BROADCAST)
- .build();
- flowRule2.selector = DefaultTrafficSelector.builder()
- .matchEthType((short) 3)
- .matchIPProtocol((byte) 9)
- .build();
- flowRule4.treatment = DefaultTrafficTreatment.builder()
- .build();
-
- flowRules.add(flowRule1);
- flowRules.add(flowRule2);
- flowRules.add(flowRule3);
- flowRules.add(flowRule4);
- }
-
- /**
* Sets up the global values for all the tests.
*/
@Before
@@ -944,16 +832,16 @@
*/
@Test
public void testGetFlowByAppId() {
- setupMockFlowRules();
+ setupMockFlows();
expect(mockApplicationService.getId(anyObject())).andReturn(APP_ID).anyTimes();
replay(mockApplicationService);
- expect(mockFlowService.getFlowRulesById(APP_ID)).andReturn(flowRules).anyTimes();
+ expect(mockFlowService.getFlowEntriesById(APP_ID)).andReturn(flowEntries).anyTimes();
replay(mockFlowService);
final WebTarget wt = target();
- final String response = wt.path("flows/application/1").request().get(String.class);
+ final String response = wt.path("/flows/application/1").request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
@@ -961,10 +849,10 @@
assertThat(result.names().get(0), is("flows"));
final JsonArray jsonFlows = result.get("flows").asArray();
assertThat(jsonFlows, notNullValue());
- assertThat(jsonFlows, hasFlowRule(flowRule1));
- assertThat(jsonFlows, hasFlowRule(flowRule2));
- assertThat(jsonFlows, hasFlowRule(flowRule3));
- assertThat(jsonFlows, hasFlowRule(flowRule4));
+ assertThat(jsonFlows, hasFlowRule(flow1));
+ assertThat(jsonFlows, hasFlowRule(flow2));
+ assertThat(jsonFlows, hasFlowRule(flow3));
+ assertThat(jsonFlows, hasFlowRule(flow4));
}
/**
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java
index f55c6e8..ac4aeb2 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/FlowViewMessageHandler.java
@@ -203,16 +203,16 @@
super(FLOW_DETAILS_REQ);
}
- private FlowRule findFlowById(String appIdText, String flowId) {
+ private FlowEntry findFlowById(String appIdText, String flowId) {
String strippedFlowId = flowId.replaceAll(OX, EMPTY);
FlowRuleService fs = get(FlowRuleService.class);
int appIdInt = Integer.parseInt(appIdText);
ApplicationId appId = new DefaultApplicationId(appIdInt, DETAILS);
- Iterable<FlowRule> flows = fs.getFlowRulesById(appId);
+ Iterable<FlowEntry> entries = fs.getFlowEntriesById(appId);
- for (FlowRule flow : flows) {
- if (flow.id().toString().equals(strippedFlowId)) {
- return flow;
+ for (FlowEntry entry : entries) {
+ if (entry.id().toString().equals(strippedFlowId)) {
+ return entry;
}
}