Thomas Vachuska
Committed by Gerrit Code Review

Intents are now removed after being withdrawn.

Change-Id: I7574fe94add00abf58c71c6122bb3dc5aafa0f79
......@@ -15,6 +15,7 @@
*/
package org.onlab.onos.cli.net;
import com.google.common.collect.Lists;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onlab.onos.cli.AbstractShellCommand;
......@@ -35,6 +36,7 @@ import org.onlab.onos.net.intent.PointToPointIntent;
import org.onlab.packet.Ethernet;
import org.onlab.packet.MacAddress;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
......@@ -89,39 +91,44 @@ public class IntentPushTestCommand extends AbstractShellCommand
add = true;
latch = new CountDownLatch(count);
IntentOperations operations = generateIntents(ingress, egress);
List<Intent> operations = generateIntents(ingress, egress);
submitIntents(operations);
add = false;
latch = new CountDownLatch(count);
operations = generateIntents(ingress, egress);
submitIntents(operations);
service.removeListener(this);
}
private IntentOperations generateIntents(ConnectPoint ingress, ConnectPoint egress) {
private List<Intent> generateIntents(ConnectPoint ingress, ConnectPoint egress) {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
.matchEthType(Ethernet.TYPE_IPV4);
TrafficTreatment treatment = DefaultTrafficTreatment.builder().build();
IntentOperations.Builder ops = IntentOperations.builder();
List<Intent> intents = Lists.newArrayList();
for (int i = 1; i <= count; i++) {
TrafficSelector s = selector
.matchEthSrc(MacAddress.valueOf(i))
.build();
Intent intent = new PointToPointIntent(appId(), s, treatment,
ingress, egress);
intents.add(new PointToPointIntent(appId(), s, treatment,
ingress, egress));
}
return intents;
}
private void submitIntents(List<Intent> intents) {
IntentOperations.Builder builder = IntentOperations.builder();
for (Intent intent : intents) {
if (add) {
ops.addSubmitOperation(intent);
builder.addSubmitOperation(intent);
} else {
ops.addWithdrawOperation(intent.id());
builder.addWithdrawOperation(intent.id());
}
}
return ops.build();
}
IntentOperations ops = builder.build();
private void submitIntents(IntentOperations ops) {
start = System.currentTimeMillis();
service.execute(ops);
try {
......
......@@ -42,9 +42,8 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
* Removes the specified intent from the inventory.
*
* @param intentId intent identification
* @return removed state transition event or null if intent was not found
*/
IntentEvent removeIntent(IntentId intentId);
void removeIntent(IntentId intentId);
/**
* Returns the number of intents in the store.
......@@ -103,8 +102,6 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
*/
List<Intent> getInstallableIntents(IntentId intentId);
// TODO: this should be triggered from with the store as a result of removeIntent call
/**
* Removes any installable intents which resulted from compilation of the
* specified original intent.
......
......@@ -694,6 +694,10 @@ public class IntentManager
if (event != null) {
eventDispatcher.post(event);
}
if (newState == WITHDRAWN) {
store.removeIntent(intent.id());
}
}
Map<Intent, IntentState> stateMap() {
......
......@@ -155,7 +155,8 @@ public class IntentManagerTest {
listener.setLatch(1, Type.WITHDRAWN);
service.withdraw(intent);
listener.await(Type.WITHDRAWN);
assertEquals(1L, service.getIntentCount());
delay(10); //FIXME this is a race
assertEquals(0L, service.getIntentCount());
assertEquals(0L, flowRuleService.getFlowRuleCount());
}
......@@ -176,7 +177,8 @@ public class IntentManagerTest {
listener.await(Type.INSTALLED);
listener.await(Type.WITHDRAWN);
assertEquals(1L, service.getIntentCount());
delay(10); //FIXME this is a race
assertEquals(0L, service.getIntentCount());
assertEquals(0L, flowRuleService.getFlowRuleCount());
}
......@@ -198,7 +200,8 @@ public class IntentManagerTest {
service.replace(intent.id(), intent2);
listener.await(Type.WITHDRAWN);
listener.await(Type.INSTALLED);
assertEquals(2L, service.getIntentCount());
delay(10); //FIXME this is a race
assertEquals(1L, service.getIntentCount());
assertEquals(1L, manager.flowRuleService.getFlowRuleCount());
assertEquals(intent2.number().intValue(),
flowRuleService.flows.iterator().next().priority());
......
......@@ -50,6 +50,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static com.google.common.base.Preconditions.checkState;
import static org.onlab.onos.net.intent.IntentState.*;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onlab.metrics.MetricsUtil.*;
......@@ -174,20 +175,15 @@ public class DistributedIntentStore
}
@Override
public IntentEvent removeIntent(IntentId intentId) {
public void removeIntent(IntentId intentId) {
Context timer = startTimer(removeIntentTimer);
checkState(getIntentState(intentId) == WITHDRAWN,
"Intent state for {} is not WITHDRAWN.", intentId);
try {
Intent intent = intents.remove(intentId);
installable.remove(intentId);
if (intent == null) {
// was already removed
return null;
}
IntentEvent event = this.setState(intent, WITHDRAWN);
intents.remove(intentId);
states.remove(intentId);
transientStates.remove(intentId);
// TODO: Should we callremoveInstalledIntents if this Intent was
return event;
installable.remove(intentId);
} finally {
stopTimer(timer);
}
......
......@@ -52,6 +52,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static com.google.common.base.Preconditions.checkState;
import static org.onlab.onos.net.intent.IntentState.*;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onlab.metrics.MetricsUtil.*;
......@@ -177,20 +178,15 @@ public class HazelcastIntentStore
}
@Override
public IntentEvent removeIntent(IntentId intentId) {
public void removeIntent(IntentId intentId) {
Context timer = startTimer(removeIntentTimer);
checkState(getIntentState(intentId) == WITHDRAWN,
"Intent state for {} is not WITHDRAWN.", intentId);
try {
Intent intent = intents.remove(intentId);
intents.remove(intentId);
installable.remove(intentId);
if (intent == null) {
// was already removed
return null;
}
IntentEvent event = this.setState(intent, WITHDRAWN);
states.remove(intentId);
transientStates.remove(intentId);
// TODO: Should we callremoveInstalledIntents if this Intent was
return event;
} finally {
stopTimer(timer);
}
......
......@@ -33,6 +33,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static com.google.common.base.Preconditions.checkState;
import static org.onlab.onos.net.intent.IntentState.WITHDRAWN;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -68,16 +69,12 @@ public class SimpleIntentStore
}
@Override
public IntentEvent removeIntent(IntentId intentId) {
Intent intent = intents.remove(intentId);
public void removeIntent(IntentId intentId) {
checkState(getIntentState(intentId) == WITHDRAWN,
"Intent state for {} is not WITHDRAWN.", intentId);
intents.remove(intentId);
installable.remove(intentId);
if (intent == null) {
// was already removed
return null;
}
IntentEvent event = this.setState(intent, WITHDRAWN);
states.remove(intentId);
return event;
}
@Override
......