package org.opendaylight.netvirt.vpnmanager;
import com.google.common.base.Optional;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
private static final Logger LOG = LoggerFactory.getLogger(InterfaceStateChangeListener.class);
private static final short DJC_MAX_RETRIES = 3;
-
private final DataBroker dataBroker;
private final ManagedNewTransactionRunner txRunner;
private final VpnInterfaceManager vpnInterfaceManager;
private final JobCoordinator jobCoordinator;
+ Table<OperStatus, OperStatus, IntfTransitionState> stateTable = HashBasedTable.create();
+
+ enum IntfTransitionState {
+ STATE_UP,
+ STATE_DOWN,
+ STATE_IGNORE
+ }
+
+ private void initialize() {
+ // Interface State Transition Table
+ // Up Down Unknown
+ // ---------------------------------------------------------------
+ /* Up { STATE_IGNORE, STATE_DOWN, STATE_IGNORE }, */
+ /* Down { STATE_UP, STATE_IGNORE, STATE_IGNORE }, */
+ /* Unknown { STATE_UP, STATE_DOWN, STATE_IGNORE }, */
+
+ stateTable.put(Interface.OperStatus.Up, Interface.OperStatus.Down, IntfTransitionState.STATE_DOWN);
+ stateTable.put(Interface.OperStatus.Down, Interface.OperStatus.Up, IntfTransitionState.STATE_UP);
+ stateTable.put(Interface.OperStatus.Unknown, Interface.OperStatus.Up, IntfTransitionState.STATE_UP);
+ stateTable.put(Interface.OperStatus.Unknown, Interface.OperStatus.Down, IntfTransitionState.STATE_DOWN);
+ }
+
@Inject
public InterfaceStateChangeListener(final DataBroker dataBroker, final VpnInterfaceManager vpnInterfaceManager,
final JobCoordinator jobCoordinator) {
this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
this.vpnInterfaceManager = vpnInterfaceManager;
this.jobCoordinator = jobCoordinator;
+ initialize();
}
@PostConstruct
Interface original, Interface update) {
final String ifName = update.getName();
try {
- OperStatus originalOperStatus = original.getOperStatus();
- OperStatus updateOperStatus = update.getOperStatus();
- if (originalOperStatus.equals(Interface.OperStatus.Unknown)
- || updateOperStatus.equals(Interface.OperStatus.Unknown)) {
- LOG.debug("Interface {} state change is from/to null/UNKNOWN. Ignoring the update event.",
- ifName);
- return;
- }
-
if (update.getIfIndex() == null) {
return;
}
LOG.error("remove: Unable to retrieve dpnId for interface {}", ifName, e);
return;
}
- if (update.getOperStatus().equals(OperStatus.Up)) {
+ IntfTransitionState state = getTransitionState(original.getOperStatus(),
+ update.getOperStatus());
+ if (state.equals(IntfTransitionState.STATE_IGNORE)) {
+ LOG.info("InterfaceStateChangeListener: Interface {} state original {}"
+ + "updated {} not handled", ifName, original.getOperStatus(),
+ update.getOperStatus());
+ return;
+ }
+ if (state.equals(IntfTransitionState.STATE_UP)) {
for (VpnInstanceNames vpnInterfaceVpnInstance :
vpnIf.getVpnInstanceNames()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
update, vpnName);
}
}
- } else if (update.getOperStatus().equals(OperStatus.Down)) {
+ } else if (state.equals(IntfTransitionState.STATE_DOWN)) {
for (VpnInstanceNames vpnInterfaceVpnInstance :
vpnIf.getVpnInstanceNames()) {
String vpnName = vpnInterfaceVpnInstance.getVpnName();
}
}
}
+
+ private IntfTransitionState getTransitionState(Interface.OperStatus original , Interface.OperStatus updated) {
+ IntfTransitionState transitionState = stateTable.get(original, updated);
+
+ if (transitionState == null) {
+ return IntfTransitionState.STATE_IGNORE;
+ }
+ return transitionState;
+ }
}