2 * Copyright (c) 2015 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.vpnservice.interfacemgr.renderer.ovs.statehelpers;
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
16 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
17 import org.opendaylight.vpnservice.interfacemgr.commons.AlivenessMonitorUtils;
18 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
19 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
20 import org.opendaylight.vpnservice.mdsalutil.NwConstants;
21 import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.AlivenessMonitorService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfTunnel;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
36 import com.google.common.util.concurrent.ListenableFuture;
39 * This worker is responsible for adding the openflow-interfaces/of-port-info container
40 * in odl-interface-openflow yang.
42 * Create the entries in Interface-State OperDS.
43 * Create the entries in Inventory OperDS.
46 public class OvsInterfaceStateAddHelper {
47 private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceStateAddHelper.class);
49 public static List<ListenableFuture<Void>> addState(DataBroker dataBroker, IdManagerService idManager,
50 IMdsalApiManager mdsalApiManager,AlivenessMonitorService alivenessMonitorService,
51 NodeConnectorId nodeConnectorId, String portName, FlowCapableNodeConnector fcNodeConnectorNew) {
52 LOG.debug("Adding Interface State to Oper DS for port: {}", portName);
53 List<ListenableFuture<Void>> futures = new ArrayList<>();
54 WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
56 //Retrieve PbyAddress & OperState from the DataObject
57 PhysAddress physAddress = new PhysAddress(fcNodeConnectorNew.getHardwareAddress().getValue());
59 State state = fcNodeConnectorNew.getState();
60 Interface.OperStatus operStatus =
61 fcNodeConnectorNew == null ? Interface.OperStatus.Down : Interface.OperStatus.Up;
62 Interface.AdminStatus adminStatus = state.isBlocked() ? Interface.AdminStatus.Down : Interface.AdminStatus.Up;
64 Interface.OperStatus operStatus = Interface.OperStatus.Up;
65 Interface.AdminStatus adminStatus = Interface.AdminStatus.Up;
67 // Fetch the interface name corresponding to the port Name
68 InterfaceKey interfaceKey = new InterfaceKey(portName);
69 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
70 InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
72 Interface ifState = InterfaceManagerCommonUtils.addStateEntry(iface, portName, transaction, idManager,
73 physAddress, operStatus, adminStatus, nodeConnectorId);
74 // If this interface is a tunnel interface, create the tunnel ingress flow
76 IfTunnel tunnel = iface.getAugmentation(IfTunnel.class);
78 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
79 long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
80 InterfaceManagerCommonUtils.makeTunnelIngressFlow(futures, mdsalApiManager, tunnel, dpId, portNo, iface,
81 ifState.getIfIndex(), NwConstants.ADD_FLOW);
82 futures.add(transaction.submit());
83 AlivenessMonitorUtils.startLLDPMonitoring(alivenessMonitorService, dataBroker, iface);
88 // For all other interfaces except tunnel interfaces, interface name won't be same as port name.
89 // In that case fetch the interface corresponding to the portName, and update the state accordingly
90 InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(portName);
91 InterfaceParentEntry interfaceParentEntry =
92 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryKey, dataBroker);
93 if (interfaceParentEntry == null || interfaceParentEntry.getInterfaceChildEntry() == null) {
94 futures.add(transaction.submit());
98 //FIXME: If the no. of child entries exceeds 100, perform txn updates in batches of 100.
99 //List<Trunks> trunks = new ArrayList<>();
101 String higherlayerChild = interfaceParentEntry.getInterfaceChildEntry().get(0).getChildInterface();
102 InterfaceManagerCommonUtils.addStateEntry(higherlayerChild, transaction, dataBroker, idManager,
105 // If this interface maps to a Vlan trunk entity, operational states of all the vlan-trunk-members
106 // should also be created here.
107 InterfaceParentEntryKey higherLayerParentEntryKey = new InterfaceParentEntryKey(higherlayerChild);
108 InterfaceParentEntry higherLayerParent =
109 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(higherLayerParentEntryKey, dataBroker);
110 if(higherLayerParent != null && higherLayerParent.getInterfaceChildEntry() != null) {
111 for (InterfaceChildEntry interfaceChildEntry : higherLayerParent.getInterfaceChildEntry()){
112 InterfaceManagerCommonUtils.addStateEntry(interfaceChildEntry.getChildInterface(), transaction, dataBroker, idManager,
116 /** Below code will be needed if we want to update the vlan-trunks on the of-port
117 if (trunks.isEmpty()) {
118 futures.add(t.submit());
122 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
124 BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
125 InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
126 InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
127 BridgeRefEntry bridgeRefEntry =
128 InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
129 if (bridgeRefEntry == null) {
130 futures.add(t.submit());
134 InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
135 (InstanceIdentifier<OvsdbBridgeAugmentation>)bridgeRefEntry.getBridgeReference().getValue();
136 VlanTrunkSouthboundUtils.addTerminationPointWithTrunks(bridgeIid, trunks, iface.getName(), t);
139 futures.add(transaction.submit());