2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.genius.itm.confighelpers;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Collections;
12 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
15 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
16 import org.opendaylight.genius.itm.impl.ITMBatchingUtils;
17 import org.opendaylight.genius.itm.impl.ItmUtils;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.TunnelOperStatus;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelListKey;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public final class ItmTunnelStateAddHelper {
27 private static final Logger LOG = LoggerFactory.getLogger(ItmTunnelStateAddHelper.class);
29 private ItmTunnelStateAddHelper() { }
31 @SuppressWarnings("checkstyle:IllegalCatch")
32 public static List<ListenableFuture<Void>> addTunnel(Interface iface, IInterfaceManager ifaceManager,
33 DataBroker broker) throws Exception {
34 LOG.debug("Invoking ItmTunnelStateAddHelper for Interface {} ", iface);
35 final WriteTransaction writeTransaction = broker.newWriteOnlyTransaction();
36 StateTunnelListKey tlKey = ItmUtils.getTunnelStateKey(iface);
37 LOG.trace("TunnelStateKey: {} for interface: {}", tlKey, iface.getName());
38 InstanceIdentifier<StateTunnelList> stListId = ItmUtils.buildStateTunnelListId(tlKey);
39 StateTunnelList tunnelStateList;
40 TunnelOperStatus tunnelOperStatus;
41 boolean tunnelState = iface.getOperStatus().equals(Interface.OperStatus.Up);
42 switch (iface.getOperStatus()) {
44 tunnelOperStatus = TunnelOperStatus.Up;
47 tunnelOperStatus = TunnelOperStatus.Down;
50 tunnelOperStatus = TunnelOperStatus.Unknown;
53 tunnelOperStatus = TunnelOperStatus.Ignore;
56 // Create new Tunnel State
59 * FIXME: A defensive try-catch to find issues without
60 * disrupting existing behavior.
62 tunnelStateList = ItmUtils.buildStateTunnelList(tlKey, iface.getName(), tunnelState, tunnelOperStatus,
63 ifaceManager, broker);
64 LOG.trace("Batching the Creation of tunnel_state: {} for Id: {}", tunnelStateList, stListId);
65 ITMBatchingUtils.write(stListId, tunnelStateList, ITMBatchingUtils.EntityType.DEFAULT_OPERATIONAL);
66 } catch (Exception e) {
67 LOG.warn("Exception trying to create tunnel state for {}", iface.getName(), e);
70 return Collections.singletonList(writeTransaction.submit());