mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-22 04:40:59 +02:00
Updating MockFlowRuleService with new semantics
Change-Id: I0a373e6cb25728ca48736902feedc3ed8869fa44
This commit is contained in:
parent
74c83135c4
commit
5811ac2285
@ -396,14 +396,14 @@ public class IntentManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void errorIntentInstallFromFlows() {
|
public void errorIntentInstallFromFlows() {
|
||||||
final Long id = MockIntent.nextId();
|
final Long id = MockIntent.nextId();
|
||||||
flowRuleService.setFuture(false, 1);
|
flowRuleService.setFuture(false);
|
||||||
MockIntent intent = new MockIntent(id);
|
MockIntent intent = new MockIntent(id);
|
||||||
listener.setLatch(1, Type.FAILED);
|
listener.setLatch(1, Type.FAILED);
|
||||||
listener.setLatch(1, Type.INSTALL_REQ);
|
listener.setLatch(1, Type.INSTALL_REQ);
|
||||||
service.submit(intent);
|
service.submit(intent);
|
||||||
listener.await(Type.INSTALL_REQ);
|
listener.await(Type.INSTALL_REQ);
|
||||||
delay(10); // need to make sure we have some failed futures returned first
|
delay(10); // need to make sure we have some failed futures returned first
|
||||||
flowRuleService.setFuture(true, 0);
|
flowRuleService.setFuture(true);
|
||||||
listener.await(Type.FAILED);
|
listener.await(Type.FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +429,7 @@ public class IntentManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void errorIntentInstallNeverTrue() {
|
public void errorIntentInstallNeverTrue() {
|
||||||
final Long id = MockIntent.nextId();
|
final Long id = MockIntent.nextId();
|
||||||
flowRuleService.setFuture(false, 1);
|
flowRuleService.setFuture(false);
|
||||||
MockIntent intent = new MockIntent(id);
|
MockIntent intent = new MockIntent(id);
|
||||||
listener.setLatch(1, Type.WITHDRAWN);
|
listener.setLatch(1, Type.WITHDRAWN);
|
||||||
listener.setLatch(1, Type.INSTALL_REQ);
|
listener.setLatch(1, Type.INSTALL_REQ);
|
||||||
@ -437,7 +437,7 @@ public class IntentManagerTest {
|
|||||||
listener.await(Type.INSTALL_REQ);
|
listener.await(Type.INSTALL_REQ);
|
||||||
// The delay here forces the retry loop in the intent manager to time out
|
// The delay here forces the retry loop in the intent manager to time out
|
||||||
delay(100);
|
delay(100);
|
||||||
flowRuleService.setFuture(false, 1);
|
flowRuleService.setFuture(false);
|
||||||
service.withdraw(intent);
|
service.withdraw(intent);
|
||||||
listener.await(Type.WITHDRAWN);
|
listener.await(Type.WITHDRAWN);
|
||||||
}
|
}
|
||||||
|
@ -15,68 +15,67 @@
|
|||||||
*/
|
*/
|
||||||
package org.onosproject.net.intent.impl;
|
package org.onosproject.net.intent.impl;
|
||||||
|
|
||||||
import java.util.Collections;
|
import com.google.common.collect.Sets;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.Future;
|
|
||||||
|
|
||||||
import org.onosproject.core.ApplicationId;
|
import org.onosproject.core.ApplicationId;
|
||||||
import org.onosproject.net.DeviceId;
|
import org.onosproject.net.DeviceId;
|
||||||
import org.onosproject.net.flow.CompletedBatchOperation;
|
import org.onosproject.net.flow.CompletedBatchOperation;
|
||||||
|
import org.onosproject.net.flow.DefaultFlowEntry;
|
||||||
import org.onosproject.net.flow.FlowEntry;
|
import org.onosproject.net.flow.FlowEntry;
|
||||||
import org.onosproject.net.flow.FlowRule;
|
import org.onosproject.net.flow.FlowRule;
|
||||||
import org.onosproject.net.flow.FlowRuleBatchEntry;
|
|
||||||
import org.onosproject.net.flow.FlowRuleBatchOperation;
|
import org.onosproject.net.flow.FlowRuleBatchOperation;
|
||||||
import org.onosproject.net.flow.FlowRuleListener;
|
import org.onosproject.net.flow.FlowRuleListener;
|
||||||
import org.onosproject.net.flow.FlowRuleOperations;
|
import org.onosproject.net.flow.FlowRuleOperations;
|
||||||
import org.onosproject.net.flow.FlowRuleService;
|
import org.onosproject.net.flow.FlowRuleService;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import java.util.Set;
|
||||||
import com.google.common.collect.Sets;
|
import java.util.concurrent.Future;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
public class MockFlowRuleService implements FlowRuleService {
|
public class MockFlowRuleService implements FlowRuleService {
|
||||||
|
|
||||||
private Future<CompletedBatchOperation> future;
|
|
||||||
final Set<FlowRule> flows = Sets.newHashSet();
|
final Set<FlowRule> flows = Sets.newHashSet();
|
||||||
|
boolean success;
|
||||||
|
|
||||||
public void setFuture(boolean success) {
|
public void setFuture(boolean success) {
|
||||||
setFuture(success, 0);
|
this.success = success;
|
||||||
}
|
|
||||||
|
|
||||||
public void setFuture(boolean success, long intentId) {
|
|
||||||
if (success) {
|
|
||||||
future = Futures.immediateFuture(new CompletedBatchOperation(true, Collections.emptySet(), null));
|
|
||||||
} else {
|
|
||||||
final Set<Long> failedIds = ImmutableSet.of(intentId);
|
|
||||||
future = Futures.immediateFuture(
|
|
||||||
new CompletedBatchOperation(false, flows, failedIds, null));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Future<CompletedBatchOperation> applyBatch(FlowRuleBatchOperation batch) {
|
public Future<CompletedBatchOperation> applyBatch(FlowRuleBatchOperation batch) {
|
||||||
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
|
throw new UnsupportedOperationException("deprecated");
|
||||||
FlowRule fr = fbe.target();
|
|
||||||
switch (fbe.operator()) {
|
|
||||||
case ADD:
|
|
||||||
flows.add(fr);
|
|
||||||
break;
|
|
||||||
case REMOVE:
|
|
||||||
flows.remove(fr);
|
|
||||||
break;
|
|
||||||
case MODIFY:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return future;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(FlowRuleOperations ops) {
|
public void apply(FlowRuleOperations ops) {
|
||||||
|
ops.stages().forEach(stage -> stage.forEach(flow -> {
|
||||||
|
switch (flow.type()) {
|
||||||
|
case ADD:
|
||||||
|
case MODIFY: //TODO is this the right behavior for modify?
|
||||||
|
flows.add(flow.rule());
|
||||||
|
break;
|
||||||
|
case REMOVE:
|
||||||
|
flows.remove(flow.rule());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
if (success) {
|
||||||
|
ops.callback().onSuccess(ops);
|
||||||
|
} else {
|
||||||
|
ops.callback().onError(ops);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addListener(FlowRuleListener listener) {
|
||||||
|
//TODO not implemented
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeListener(FlowRuleListener listener) {
|
||||||
|
//TODO not implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -86,39 +85,43 @@ public class MockFlowRuleService implements FlowRuleService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
|
public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
|
||||||
return null;
|
return flows.stream()
|
||||||
|
.filter(flow -> flow.deviceId().equals(deviceId))
|
||||||
|
.map(DefaultFlowEntry::new)
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyFlowRules(FlowRule... flowRules) {
|
public void applyFlowRules(FlowRule... flowRules) {
|
||||||
|
for (FlowRule flow : flowRules) {
|
||||||
|
flows.add(flow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeFlowRules(FlowRule... flowRules) {
|
public void removeFlowRules(FlowRule... flowRules) {
|
||||||
|
for (FlowRule flow : flowRules) {
|
||||||
|
flows.remove(flow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeFlowRulesById(ApplicationId appId) {
|
public void removeFlowRulesById(ApplicationId appId) {
|
||||||
|
//TODO not implemented
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<FlowRule> getFlowRulesById(ApplicationId id) {
|
public Iterable<FlowRule> getFlowRulesById(ApplicationId id) {
|
||||||
return null;
|
return flows.stream()
|
||||||
|
.filter(flow -> flow.appId() == id.id())
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
|
public Iterable<FlowRule> getFlowRulesByGroupId(ApplicationId appId, short groupId) {
|
||||||
return null;
|
return flows.stream()
|
||||||
}
|
.filter(flow -> flow.appId() == appId.id() && flow.groupId().id() == groupId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
@Override
|
|
||||||
public void addListener(FlowRuleListener listener) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeListener(FlowRuleListener listener) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user