Search in sources :

Example 6 with TunnelOperStatus

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus in project genius by opendaylight.

the class ItmTunnelStateAddHelper method addTunnel.

@SuppressWarnings("checkstyle:IllegalCatch")
public static List<ListenableFuture<Void>> addTunnel(Interface iface, IInterfaceManager ifaceManager, DataBroker broker) throws Exception {
    LOG.debug("Invoking ItmTunnelStateAddHelper for Interface {} ", iface);
    final WriteTransaction writeTransaction = broker.newWriteOnlyTransaction();
    StateTunnelListKey tlKey = ItmUtils.getTunnelStateKey(iface);
    LOG.trace("TunnelStateKey: {} for interface: {}", tlKey, iface.getName());
    InstanceIdentifier<StateTunnelList> stListId = ItmUtils.buildStateTunnelListId(tlKey);
    StateTunnelList tunnelStateList;
    TunnelOperStatus tunnelOperStatus;
    boolean tunnelState = iface.getOperStatus().equals(Interface.OperStatus.Up);
    switch(iface.getOperStatus()) {
        case Up:
            tunnelOperStatus = TunnelOperStatus.Up;
            break;
        case Down:
            tunnelOperStatus = TunnelOperStatus.Down;
            break;
        case Unknown:
            tunnelOperStatus = TunnelOperStatus.Unknown;
            break;
        default:
            tunnelOperStatus = TunnelOperStatus.Ignore;
    }
    // Create new Tunnel State
    try {
        /*
             * FIXME: A defensive try-catch to find issues without
             * disrupting existing behavior.
             */
        tunnelStateList = ItmUtils.buildStateTunnelList(tlKey, iface.getName(), tunnelState, tunnelOperStatus, ifaceManager, broker);
        LOG.trace("Batching the Creation of tunnel_state: {} for Id: {}", tunnelStateList, stListId);
        ITMBatchingUtils.write(stListId, tunnelStateList, ITMBatchingUtils.EntityType.DEFAULT_OPERATIONAL);
    } catch (Exception e) {
        LOG.warn("Exception trying to create tunnel state for {}", iface.getName(), e);
    }
    return Collections.singletonList(writeTransaction.submit());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) StateTunnelListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey) TunnelOperStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus) StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList)

Example 7 with TunnelOperStatus

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus in project genius by opendaylight.

the class InterfaceStateListener method updateTunnel.

private List<ListenableFuture<Void>> updateTunnel(Interface updated) throws Exception {
    LOG.debug("Invoking ItmTunnelStateUpdateHelper for Interface {} ", updated);
    final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
    StateTunnelListKey tlKey = ItmUtils.getTunnelStateKey(updated);
    LOG.trace("TunnelStateKey: {} for interface: {}", tlKey, updated.getName());
    InstanceIdentifier<StateTunnelList> stListId = ItmUtils.buildStateTunnelListId(tlKey);
    Optional<StateTunnelList> tunnelsState = tunnelStateCache.get(stListId);
    StateTunnelListBuilder stlBuilder;
    TunnelOperStatus tunnelOperStatus;
    boolean tunnelState = updated.getOperStatus().equals(Interface.OperStatus.Up);
    switch(updated.getOperStatus()) {
        case Up:
            tunnelOperStatus = TunnelOperStatus.Up;
            break;
        case Down:
            tunnelOperStatus = TunnelOperStatus.Down;
            break;
        case Unknown:
            tunnelOperStatus = TunnelOperStatus.Unknown;
            break;
        default:
            tunnelOperStatus = TunnelOperStatus.Ignore;
    }
    if (tunnelsState.isPresent()) {
        stlBuilder = new StateTunnelListBuilder(tunnelsState.get());
        stlBuilder.setTunnelState(tunnelState);
        stlBuilder.setOperState(tunnelOperStatus);
        StateTunnelList stList = stlBuilder.build();
        LOG.trace("Batching the updation of tunnel_state: {} for Id: {}", stList, stListId);
        ITMBatchingUtils.update(stListId, stList, ITMBatchingUtils.EntityType.DEFAULT_OPERATIONAL);
    }
    return Collections.singletonList(writeTransaction.submit());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) StateTunnelListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey) StateTunnelListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListBuilder) TunnelOperStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus) StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList)

Aggregations

TunnelOperStatus (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus)6 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)3 BigInteger (java.math.BigInteger)2 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface)2 IfTunnel (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel)2 ParentRefs (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs)2 StateTunnelList (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList)2 StateTunnelListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey)2 Optional (com.google.common.base.Optional)1 Strings (com.google.common.base.Strings)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1