use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey in project genius by opendaylight.
the class ItmUtils method buildStateTunnelList.
public static StateTunnelList buildStateTunnelList(StateTunnelListKey tlKey, String name, boolean state, TunnelOperStatus tunOpStatus, IInterfaceManager ifaceManager, DataBroker broker) {
StateTunnelListBuilder stlBuilder = new StateTunnelListBuilder();
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface = ItmUtils.getInterface(name, ifaceManager);
IfTunnel ifTunnel = iface.getAugmentation(IfTunnel.class);
ParentRefs parentRefs = iface.getAugmentation(ParentRefs.class);
if (ifTunnel == null || parentRefs == null) {
return null;
}
DstInfoBuilder dstInfoBuilder = new DstInfoBuilder();
SrcInfoBuilder srcInfoBuilder = new SrcInfoBuilder();
dstInfoBuilder.setTepIp(ifTunnel.getTunnelDestination());
srcInfoBuilder.setTepIp(ifTunnel.getTunnelSource());
// TODO: Add/Improve logic for device type
InternalTunnel internalTunnel = ItmUtils.ITM_CACHE.getInternalTunnel(name);
ExternalTunnel externalTunnel = ItmUtils.ITM_CACHE.getExternalTunnel(name);
if (internalTunnel == null && externalTunnel == null) {
// both not present in cache. let us update and try again.
ItmUtils.updateTunnelsCache(broker);
internalTunnel = ItmUtils.ITM_CACHE.getInternalTunnel(name);
externalTunnel = ItmUtils.ITM_CACHE.getExternalTunnel(name);
}
if (internalTunnel != null) {
srcInfoBuilder.setTepDeviceId(internalTunnel.getSourceDPN().toString()).setTepDeviceType(TepTypeInternal.class);
dstInfoBuilder.setTepDeviceId(internalTunnel.getDestinationDPN().toString()).setTepDeviceType(TepTypeInternal.class);
stlBuilder.setTransportType(internalTunnel.getTransportType());
} else if (externalTunnel != null) {
ExternalTunnel tunnel = ItmUtils.ITM_CACHE.getExternalTunnel(name);
srcInfoBuilder.setTepDeviceId(tunnel.getSourceDevice()).setTepDeviceType(getDeviceType(tunnel.getSourceDevice()));
dstInfoBuilder.setTepDeviceId(tunnel.getDestinationDevice()).setTepDeviceType(getDeviceType(tunnel.getDestinationDevice())).setTepIp(ifTunnel.getTunnelDestination());
stlBuilder.setTransportType(tunnel.getTransportType());
}
stlBuilder.setKey(tlKey).setTunnelInterfaceName(name).setOperState(tunOpStatus).setTunnelState(state).setDstInfo(dstInfoBuilder.build()).setSrcInfo(srcInfoBuilder.build());
return stlBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey in project genius by opendaylight.
the class ItmTunnelStateRemoveHelper method removeTunnel.
public static List<ListenableFuture<Void>> removeTunnel(Interface iface, DataBroker broker) throws Exception {
LOG.debug("Invoking ItmTunnelStateRemoveHelper for Interface {} ", iface);
WriteTransaction writeTransaction = broker.newWriteOnlyTransaction();
StateTunnelListKey tlKey = ItmUtils.getTunnelStateKey(iface);
InstanceIdentifier<StateTunnelList> stListId = ItmUtils.buildStateTunnelListId(tlKey);
LOG.trace("Deleting tunnel_state for Id: {}", stListId);
ITMBatchingUtils.delete(stListId, ITMBatchingUtils.EntityType.DEFAULT_OPERATIONAL);
return Collections.singletonList(writeTransaction.submit());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey 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());
}
Aggregations