mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-14 17:01:02 +02:00
when deactivate sdn-ip, also delete all relative intents
Change-Id: I7a6bd64b5a9525dc49ca2b9353fcc45dc9a16288
This commit is contained in:
parent
ed932a6554
commit
c07781f50f
@ -15,6 +15,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.onosproject.sdnip;
|
package org.onosproject.sdnip;
|
||||||
|
|
||||||
|
import static java.util.concurrent.Executors.newSingleThreadExecutor;
|
||||||
|
import static org.onlab.util.Tools.groupedThreads;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
import org.onosproject.core.ApplicationId;
|
import org.onosproject.core.ApplicationId;
|
||||||
import org.onosproject.net.intent.Intent;
|
import org.onosproject.net.intent.Intent;
|
||||||
import org.onosproject.net.intent.IntentService;
|
import org.onosproject.net.intent.IntentService;
|
||||||
@ -24,16 +35,6 @@ import org.onosproject.routing.IntentSynchronizationService;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
|
|
||||||
import static java.util.concurrent.Executors.newSingleThreadExecutor;
|
|
||||||
import static org.onlab.util.Tools.groupedThreads;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronizes intents between the in-memory intent store and the
|
* Synchronizes intents between the in-memory intent store and the
|
||||||
* IntentService.
|
* IntentService.
|
||||||
@ -97,57 +98,32 @@ public class IntentSynchronizer implements IntentSynchronizationService {
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
// Stop the thread(s)
|
// Stop the thread(s)
|
||||||
intentsSynchronizerExecutor.shutdownNow();
|
intentsSynchronizerExecutor.shutdownNow();
|
||||||
|
log.info("Intents Synchronizer Executor shutdown completed");
|
||||||
|
|
||||||
//
|
|
||||||
// Withdraw all app related intents
|
|
||||||
//
|
|
||||||
if (!isElectedLeader) {
|
|
||||||
return; // Nothing to do: not the leader anymore
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// NOTE: We don't withdraw the intents during shutdown, because
|
|
||||||
// it creates flux in the data plane during switchover.
|
|
||||||
//
|
|
||||||
|
|
||||||
/*
|
|
||||||
//
|
|
||||||
// Build a batch operation to withdraw all intents from this
|
|
||||||
// application.
|
|
||||||
//
|
|
||||||
log.debug("Intent Synchronizer shutdown: " +
|
|
||||||
"withdrawing all intents...");
|
|
||||||
IntentOperations.Builder builder = IntentOperations.builder(appId);
|
|
||||||
for (Intent intent : intentService.getIntents()) {
|
|
||||||
// Skip the intents from other applications
|
|
||||||
if (!intent.appId().equals(appId)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip the intents that are already withdrawn
|
|
||||||
IntentState intentState =
|
|
||||||
intentService.getIntentState(intent.id());
|
|
||||||
if ((intentState == null) ||
|
|
||||||
intentState.equals(IntentState.WITHDRAWING) ||
|
|
||||||
intentState.equals(IntentState.WITHDRAWN)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.trace("Intent Synchronizer withdrawing intent: {}",
|
|
||||||
intent);
|
|
||||||
builder.addWithdrawOperation(intent.id());
|
|
||||||
}
|
|
||||||
IntentOperations intentOperations = builder.build();
|
|
||||||
intentService.execute(intentOperations);
|
|
||||||
leaderChanged(false);
|
|
||||||
|
|
||||||
peerIntents.clear();
|
|
||||||
routeIntents.clear();
|
|
||||||
log.debug("Intent Synchronizer shutdown completed");
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Withdraws all intents.
|
||||||
|
*/
|
||||||
|
public void removeIntents() {
|
||||||
|
if (!isElectedLeader) {
|
||||||
|
// only leader will withdraw intents
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("Intent Synchronizer shutdown: withdrawing all intents...");
|
||||||
|
|
||||||
|
for (Entry<Key, Intent> entry : intents.entrySet()) {
|
||||||
|
intentService.withdraw(entry.getValue());
|
||||||
|
log.debug("Intent Synchronizer withdrawing intent: {}",
|
||||||
|
entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
intents.clear();
|
||||||
|
log.info("Tried to clean all intents");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void submit(Intent intent) {
|
public void submit(Intent intent) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@ -261,5 +237,4 @@ public class IntentSynchronizer implements IntentSynchronizationService {
|
|||||||
}
|
}
|
||||||
log.debug("Intent synchronization completed");
|
log.debug("Intent synchronization completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,12 +15,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.onosproject.sdnip;
|
package org.onosproject.sdnip;
|
||||||
|
|
||||||
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.felix.scr.annotations.Activate;
|
import org.apache.felix.scr.annotations.Activate;
|
||||||
import org.apache.felix.scr.annotations.Component;
|
import org.apache.felix.scr.annotations.Component;
|
||||||
import org.apache.felix.scr.annotations.Deactivate;
|
import org.apache.felix.scr.annotations.Deactivate;
|
||||||
import org.apache.felix.scr.annotations.Reference;
|
import org.apache.felix.scr.annotations.Reference;
|
||||||
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
import org.apache.felix.scr.annotations.ReferenceCardinality;
|
||||||
import org.apache.felix.scr.annotations.Service;
|
import org.apache.felix.scr.annotations.Service;
|
||||||
|
import org.onosproject.app.ApplicationService;
|
||||||
import org.onosproject.cluster.ClusterService;
|
import org.onosproject.cluster.ClusterService;
|
||||||
import org.onosproject.cluster.ControllerNode;
|
import org.onosproject.cluster.ControllerNode;
|
||||||
import org.onosproject.cluster.LeadershipEvent;
|
import org.onosproject.cluster.LeadershipEvent;
|
||||||
@ -28,8 +33,8 @@ import org.onosproject.cluster.LeadershipEventListener;
|
|||||||
import org.onosproject.cluster.LeadershipService;
|
import org.onosproject.cluster.LeadershipService;
|
||||||
import org.onosproject.core.ApplicationId;
|
import org.onosproject.core.ApplicationId;
|
||||||
import org.onosproject.core.CoreService;
|
import org.onosproject.core.CoreService;
|
||||||
import org.onosproject.net.config.NetworkConfigService;
|
|
||||||
import org.onosproject.incubator.net.intf.InterfaceService;
|
import org.onosproject.incubator.net.intf.InterfaceService;
|
||||||
|
import org.onosproject.net.config.NetworkConfigService;
|
||||||
import org.onosproject.net.host.HostService;
|
import org.onosproject.net.host.HostService;
|
||||||
import org.onosproject.net.intent.IntentService;
|
import org.onosproject.net.intent.IntentService;
|
||||||
import org.onosproject.routing.IntentSynchronizationService;
|
import org.onosproject.routing.IntentSynchronizationService;
|
||||||
@ -38,10 +43,6 @@ import org.onosproject.routing.SdnIpService;
|
|||||||
import org.onosproject.routing.config.RoutingConfigurationService;
|
import org.onosproject.routing.config.RoutingConfigurationService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import static org.slf4j.LoggerFactory.getLogger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component for the SDN-IP peering application.
|
* Component for the SDN-IP peering application.
|
||||||
*/
|
*/
|
||||||
@ -58,6 +59,9 @@ public class SdnIp implements SdnIpService {
|
|||||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
protected IntentService intentService;
|
protected IntentService intentService;
|
||||||
|
|
||||||
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
|
protected ApplicationService applicationService;
|
||||||
|
|
||||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
protected HostService hostService;
|
protected HostService hostService;
|
||||||
|
|
||||||
@ -84,7 +88,7 @@ public class SdnIp implements SdnIpService {
|
|||||||
private SdnIpFib fib;
|
private SdnIpFib fib;
|
||||||
|
|
||||||
private LeadershipEventListener leadershipEventListener =
|
private LeadershipEventListener leadershipEventListener =
|
||||||
new InnerLeadershipEventListener();
|
new InnerLeadershipEventListener();
|
||||||
private ApplicationId appId;
|
private ApplicationId appId;
|
||||||
private ControllerNode localControllerNode;
|
private ControllerNode localControllerNode;
|
||||||
|
|
||||||
@ -113,6 +117,10 @@ public class SdnIp implements SdnIpService {
|
|||||||
|
|
||||||
leadershipService.addListener(leadershipEventListener);
|
leadershipService.addListener(leadershipEventListener);
|
||||||
leadershipService.runForLeadership(appId.name());
|
leadershipService.runForLeadership(appId.name());
|
||||||
|
|
||||||
|
applicationService.registerDeactivateHook(appId,
|
||||||
|
intentSynchronizer::removeIntents);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deactivate
|
@Deactivate
|
||||||
|
Loading…
x
Reference in New Issue
Block a user