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 com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
13 import org.opendaylight.vpnservice.interfacemgr.IfmConstants;
14 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
15 import org.opendaylight.vpnservice.interfacemgr.commons.AlivenessMonitorUtils;
16 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
17 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
18 import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
19 import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
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 java.math.BigInteger;
37 import java.util.ArrayList;
38 import java.util.List;
41 * This worker is responsible for adding the openflow-interfaces/of-port-info container
42 * in odl-interface-openflow yang.
44 * Create the entries in Interface-State OperDS.
45 * Create the entries in Inventory OperDS.
48 public class OvsInterfaceStateAddHelper {
49 private static final Logger LOG = LoggerFactory.getLogger(OvsInterfaceStateAddHelper.class);
51 public static List<ListenableFuture<Void>> addState(DataBroker dataBroker, IdManagerService idManager,
52 IMdsalApiManager mdsalApiManager,AlivenessMonitorService alivenessMonitorService,
53 NodeConnectorId nodeConnectorId, String portName, FlowCapableNodeConnector fcNodeConnectorNew) {
54 LOG.debug("Adding Interface State to Oper DS for port: {}", portName);
55 List<ListenableFuture<Void>> futures = new ArrayList<>();
56 WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
58 //Retrieve PbyAddress & OperState from the DataObject
59 PhysAddress physAddress = new PhysAddress(fcNodeConnectorNew.getHardwareAddress().getValue());
61 State state = fcNodeConnectorNew.getState();
62 Interface.OperStatus operStatus =
63 fcNodeConnectorNew == null ? Interface.OperStatus.Down : Interface.OperStatus.Up;
64 Interface.AdminStatus adminStatus = state.isBlocked() ? Interface.AdminStatus.Down : Interface.AdminStatus.Up;
66 Interface.OperStatus operStatus = Interface.OperStatus.Up;
67 Interface.AdminStatus adminStatus = Interface.AdminStatus.Up;
69 // Fetch the interface name corresponding to the port Name
70 InterfaceKey interfaceKey = new InterfaceKey(portName);
71 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface =
72 InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
74 Interface ifState = InterfaceManagerCommonUtils.addStateEntry(iface, portName, transaction, idManager,
75 physAddress, operStatus, adminStatus, nodeConnectorId);
76 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
77 long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
78 // If this interface is a tunnel interface, create the tunnel ingress flow
80 IfTunnel tunnel = iface.getAugmentation(IfTunnel.class);
82 InterfaceManagerCommonUtils.makeTunnelIngressFlow(futures, mdsalApiManager, tunnel, dpId, portNo, iface,
83 ifState.getIfIndex(), NwConstants.ADD_FLOW);
84 futures.add(transaction.submit());
85 AlivenessMonitorUtils.startLLDPMonitoring(alivenessMonitorService, dataBroker, iface);
90 // For all other interfaces except tunnel interfaces, interface name won't be same as port name.
91 // In that case fetch the interface corresponding to the portName, and update the state accordingly
92 InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(portName);
93 InterfaceParentEntry interfaceParentEntry =
94 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryKey, dataBroker);
95 if (interfaceParentEntry == null || interfaceParentEntry.getInterfaceChildEntry() == null) {
96 futures.add(transaction.submit());
100 //FIXME: If the no. of child entries exceeds 100, perform txn updates in batches of 100.
101 //List<Trunks> trunks = new ArrayList<>();
103 String higherlayerChild = interfaceParentEntry.getInterfaceChildEntry().get(0).getChildInterface();
104 InterfaceManagerCommonUtils.addStateEntry(higherlayerChild, transaction, dataBroker, idManager,
107 // If this interface maps to a Vlan trunk entity, operational states of all the vlan-trunk-members
108 // should also be created here.
109 InterfaceParentEntryKey higherLayerParentEntryKey = new InterfaceParentEntryKey(higherlayerChild);
110 InterfaceParentEntry higherLayerParent =
111 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(higherLayerParentEntryKey, dataBroker);
112 if(higherLayerParent != null && higherLayerParent.getInterfaceChildEntry() != null) {
113 for (InterfaceChildEntry interfaceChildEntry : higherLayerParent.getInterfaceChildEntry()){
114 InterfaceManagerCommonUtils.addStateEntry(interfaceChildEntry.getChildInterface(), transaction, dataBroker, idManager,
118 /** Below code will be needed if we want to update the vlan-trunks on the of-port
119 if (trunks.isEmpty()) {
120 futures.add(t.submit());
124 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
126 BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
127 InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
128 InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
129 BridgeRefEntry bridgeRefEntry =
130 InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
131 if (bridgeRefEntry == null) {
132 futures.add(t.submit());
136 InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
137 (InstanceIdentifier<OvsdbBridgeAugmentation>)bridgeRefEntry.getBridgeReference().getValue();
138 VlanTrunkSouthboundUtils.addTerminationPointWithTrunks(bridgeIid, trunks, iface.getName(), t);
141 futures.add(transaction.submit());