2 * Copyright (c) 2016, 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.interfacemanager.renderer.hwvtep.statehelpers;
10 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
11 import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
12 import static org.opendaylight.mdsal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.ArrayList;
16 import java.util.Collections;
17 import java.util.List;
18 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
19 import org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils;
20 import org.opendaylight.genius.interfacemanager.commons.InterfaceMetaUtils;
21 import org.opendaylight.genius.interfacemanager.renderer.hwvtep.utilities.SouthboundUtils;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.Tunnels;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical._switch.attributes.TunnelsKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdParams;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.tunnel.attributes.BfdStatus;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public final class HwVTEPInterfaceStateUpdateHelper {
33 private static final Logger LOG = LoggerFactory.getLogger(HwVTEPInterfaceStateUpdateHelper.class);
35 private HwVTEPInterfaceStateUpdateHelper() {
38 public static List<ListenableFuture<Void>> updatePhysicalSwitch(ManagedNewTransactionRunner txRunner,
39 InstanceIdentifier<Tunnels> tunnelsInstanceIdentifier, Tunnels tunnelsNew) {
40 LOG.debug("updating physical switch for tunnels");
41 return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
42 String interfaceName = InterfaceMetaUtils
43 .getInterfaceForTunnelInstanceIdentifier(tunnelsInstanceIdentifier.toString(), tx);
44 if (interfaceName != null) {
45 // update opstate of interface if TEP has gone down/up as a result of
47 InterfaceManagerCommonUtils.updateOpState(tx, interfaceName,
48 getTunnelOpState(tunnelsNew.getBfdStatus()));
53 private static OperStatus getTunnelOpState(List<BfdStatus> tunnelBfdStatus) {
54 OperStatus livenessState = OperStatus.Down;
55 if (tunnelBfdStatus != null && !tunnelBfdStatus.isEmpty()) {
56 for (BfdStatus bfdState : tunnelBfdStatus) {
57 if (SouthboundUtils.BFD_OP_STATE.equalsIgnoreCase(bfdState.getBfdStatusKey())) {
58 String bfdOpState = bfdState.getBfdStatusValue();
59 if (SouthboundUtils.BFD_STATE_UP.equalsIgnoreCase(bfdOpState)) {
60 livenessState = OperStatus.Up;
62 livenessState = OperStatus.Down;
71 public static List<ListenableFuture<Void>> startBfdMonitoring(ManagedNewTransactionRunner txRunner,
72 InstanceIdentifier<Tunnels> tunnelsInstanceIdentifier, Tunnels tunnelsNew) {
73 LOG.debug("starting bfd monitoring for the hwvtep {}", tunnelsInstanceIdentifier);
75 TunnelsBuilder tunnelsBuilder = new TunnelsBuilder();
76 tunnelsBuilder.withKey(new TunnelsKey(tunnelsNew.getLocalLocatorRef(), tunnelsNew.getRemoteLocatorRef()));
77 tunnelsBuilder.setLocalLocatorRef(tunnelsNew.getLocalLocatorRef());
78 tunnelsBuilder.setRemoteLocatorRef(tunnelsNew.getLocalLocatorRef());
79 List<BfdParams> bfdParams = new ArrayList<>();
80 SouthboundUtils.fillBfdParameters(bfdParams, null);
81 tunnelsBuilder.setBfdParams(bfdParams);
82 return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
83 tx -> tx.put(tunnelsInstanceIdentifier, tunnelsBuilder.build(), CREATE_MISSING_PARENTS)));