Avantika-Huawei
Committed by Gerrit Code Review

[GoldenEye] [ONOS-4163] Add provider service update API with status change

Change-Id: Id8774f5577f735566b1826ab4adfe5969c3aa168
......@@ -60,6 +60,14 @@ public interface TunnelProviderService extends ProviderService<TunnelProvider> {
void tunnelUpdated(TunnelDescription tunnel);
/**
* Signals that the tunnel was changed with tunnel status change.
*
* @param tunnel tunnel information
* @param state tunnel working status
*/
void tunnelUpdated(TunnelDescription tunnel, State state);
/**
* Signals that the a tunnel was queried.
*
* @param tunnelId tunnel identity
......
......@@ -19,6 +19,7 @@ import java.util.Collection;
import com.google.common.annotations.Beta;
import org.onosproject.core.ApplicationId;
import org.onosproject.incubator.net.tunnel.Tunnel.State;
import org.onosproject.incubator.net.tunnel.Tunnel.Type;
import org.onosproject.net.Annotations;
import org.onosproject.net.provider.ProviderId;
......@@ -38,6 +39,15 @@ public interface TunnelStore extends Store<TunnelEvent, TunnelStoreDelegate> {
TunnelId createOrUpdateTunnel(Tunnel tunnel);
/**
* Creates a tunnel or updates a tunnel with the new state given in input.
*
* @param tunnel tunnel
* @param state tunnel state
* @return tunnel identity
*/
TunnelId createOrUpdateTunnel(Tunnel tunnel, State state);
/**
* Deletes a tunnel by a specific tunnel identifier.
*
* @param tunnelId tunnel unique identifier generated by ONOS
......
......@@ -337,6 +337,20 @@ public class TunnelManager
}
@Override
public void tunnelUpdated(TunnelDescription tunnel, State state) {
Tunnel storedTunnel = new DefaultTunnel(provider().id(),
tunnel.src(), tunnel.dst(),
tunnel.type(),
state,
tunnel.groupId(),
tunnel.id(),
tunnel.tunnelName(),
tunnel.path(),
tunnel.annotations());
store.createOrUpdateTunnel(storedTunnel, state);
}
@Override
public void tunnelRemoved(TunnelDescription tunnel) {
if (tunnel.id() != null) {
store.deleteTunnel(tunnel.id());
......
......@@ -38,6 +38,7 @@ import org.onosproject.core.CoreService;
import org.onosproject.core.IdGenerator;
import org.onosproject.incubator.net.tunnel.DefaultTunnel;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.Tunnel.State;
import org.onosproject.incubator.net.tunnel.Tunnel.Type;
import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
import org.onosproject.incubator.net.tunnel.TunnelEvent;
......@@ -147,6 +148,15 @@ public class DistributedTunnelStore
@Override
public TunnelId createOrUpdateTunnel(Tunnel tunnel) {
return handleCreateOrUpdateTunnel(tunnel, null);
}
@Override
public TunnelId createOrUpdateTunnel(Tunnel tunnel, State state) {
return handleCreateOrUpdateTunnel(tunnel, state);
}
private TunnelId handleCreateOrUpdateTunnel(Tunnel tunnel, State state) {
// tunnelIdAsKeyStore.
if (tunnel.tunnelId() != null && !"".equals(tunnel.tunnelId().toString())) {
Tunnel old = tunnelIdAsKeyStore.get(tunnel.tunnelId());
......@@ -156,24 +166,25 @@ public class DistributedTunnelStore
}
DefaultAnnotations oldAnno = (DefaultAnnotations) old.annotations();
SparseAnnotations newAnno = (SparseAnnotations) tunnel.annotations();
State newTunnelState = (state != null) ? state : old.state();
Tunnel newT = new DefaultTunnel(old.providerId(), old.src(),
old.dst(), old.type(),
old.state(), old.groupId(),
newTunnelState, old.groupId(),
old.tunnelId(),
old.tunnelName(),
old.path(),
DefaultAnnotations.merge(oldAnno, newAnno));
tunnelIdAsKeyStore.put(tunnel.tunnelId(), newT);
TunnelEvent event = new TunnelEvent(
TunnelEvent.Type.TUNNEL_UPDATED,
TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_UPDATED,
tunnel);
notifyDelegate(event);
return tunnel.tunnelId();
} else {
TunnelId tunnelId = TunnelId.valueOf(idGenerator.getNewId());
State tunnelState = (state != null) ? state : tunnel.state();
Tunnel newT = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
tunnel.dst(), tunnel.type(),
tunnel.state(), tunnel.groupId(),
tunnelState, tunnel.groupId(),
tunnelId,
tunnel.tunnelName(),
tunnel.path(),
......
......@@ -182,6 +182,11 @@ public class OvsdbTunnelProviderTest {
}
@Override
public void tunnelUpdated(TunnelDescription tunnel, State state) {
}
@Override
public Tunnel tunnelQueryById(TunnelId tunnelId) {
return null;
}
......
......@@ -70,6 +70,10 @@ public class TunnelProviderRegistryAdapter implements TunnelProviderRegistry {
}
@Override
public void tunnelUpdated(TunnelDescription tunnel, State state) {
}
@Override
public Tunnel tunnelQueryById(TunnelId tunnelId) {
return null;
}
......