2 * Copyright (c) 2016 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
9 package org.opendaylight.genius.interfacemanager.commons;
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.genius.interfacemanager.IfmConstants;
17 import org.opendaylight.genius.interfacemanager.IfmUtil;
18 import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
19 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
20 import org.opendaylight.genius.mdsalutil.*;
21 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info.InterfaceParentEntry;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info.InterfaceParentEntryKey;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info._interface.parent.entry.InterfaceChildEntry;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info._interface.parent.entry.InterfaceChildEntryBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info._interface.parent.entry.InterfaceChildEntryKey;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnelBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeMplsOverGre;
45 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
49 import java.math.BigInteger;
50 import java.util.ArrayList;
51 import java.util.List;
53 public class InterfaceManagerCommonUtils {
54 private static final Logger LOG = LoggerFactory.getLogger(InterfaceManagerCommonUtils.class);
55 public static NodeConnector getNodeConnectorFromInventoryOperDS(NodeConnectorId nodeConnectorId,
56 DataBroker dataBroker) {
57 NodeId nodeId = IfmUtil.getNodeIdFromNodeConnectorId(nodeConnectorId);
58 InstanceIdentifier<NodeConnector> ncIdentifier = InstanceIdentifier.builder(Nodes.class)
59 .child(Node.class, new NodeKey(nodeId))
60 .child(NodeConnector.class, new NodeConnectorKey(nodeConnectorId)).build();
62 Optional<NodeConnector> nodeConnectorOptional = IfmUtil.read(LogicalDatastoreType.OPERATIONAL,
63 ncIdentifier, dataBroker);
64 if (!nodeConnectorOptional.isPresent()) {
67 return nodeConnectorOptional.get();
70 public static boolean isNodePresent(DataBroker dataBroker, NodeConnectorId nodeConnectorId){
71 NodeId nodeID = IfmUtil.getNodeIdFromNodeConnectorId(nodeConnectorId);
72 InstanceIdentifier<Node> nodeInstanceIdentifier = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(nodeID)).build();
73 Optional<Node> node = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, nodeInstanceIdentifier, dataBroker);
81 public static InstanceIdentifier<Interface> getInterfaceIdentifier(InterfaceKey interfaceKey) {
82 InstanceIdentifier.InstanceIdentifierBuilder<Interface> interfaceInstanceIdentifierBuilder =
83 InstanceIdentifier.builder(Interfaces.class).child(Interface.class, interfaceKey);
84 return interfaceInstanceIdentifierBuilder.build();
87 public static List<Interface> getAllTunnelInterfaces(DataBroker dataBroker, InterfaceInfo.InterfaceType interfaceType) {
88 List<Interface> vxlanList = new ArrayList<Interface>();
89 InstanceIdentifier<Interfaces> interfacesInstanceIdentifier = InstanceIdentifier.builder(Interfaces.class).build();
90 Optional<Interfaces> interfacesOptional = IfmUtil.read(LogicalDatastoreType.CONFIGURATION, interfacesInstanceIdentifier, dataBroker);
91 if (!interfacesOptional.isPresent()) {
94 Interfaces interfaces = interfacesOptional.get();
95 List<Interface> interfacesList = interfaces.getInterface();
96 for (Interface iface : interfacesList) {
97 if(IfmUtil.getInterfaceType(iface) == InterfaceInfo.InterfaceType.VXLAN_TRUNK_INTERFACE &&
98 iface.getAugmentation(IfTunnel.class).isInternal()) {
105 public static Interface getInterfaceFromConfigDS(String interfaceName, DataBroker dataBroker) {
106 InterfaceKey interfaceKey = new InterfaceKey(interfaceName);
107 return getInterfaceFromConfigDS(interfaceKey, dataBroker);
110 public static Interface getInterfaceFromConfigDS(InterfaceKey interfaceKey, DataBroker dataBroker) {
111 InstanceIdentifier<Interface> interfaceId = getInterfaceIdentifier(interfaceKey);
112 Optional<Interface> interfaceOptional = IfmUtil.read(LogicalDatastoreType.CONFIGURATION, interfaceId, dataBroker);
113 if (!interfaceOptional.isPresent()) {
117 return interfaceOptional.get();
120 public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface getInterfaceStateFromOperDS(String interfaceName, DataBroker dataBroker) {
121 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
122 IfmUtil.buildStateInterfaceId(interfaceName);
123 return getInterfaceStateFromOperDS(ifStateId, dataBroker);
126 public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface getInterfaceStateFromOperDS
127 (InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId, DataBroker dataBroker) {
128 Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateOptional =
129 IfmUtil.read(LogicalDatastoreType.OPERATIONAL, ifStateId, dataBroker);
130 if (!ifStateOptional.isPresent()) {
134 return ifStateOptional.get();
136 public static void makeTunnelIngressFlow(List<ListenableFuture<Void>> futures, IMdsalApiManager mdsalApiManager,
137 IfTunnel tunnel, BigInteger dpnId, long portNo, String interfaceName, int ifIndex, int addOrRemoveFlow) {
138 LOG.debug("make tunnel ingress flow for {}",interfaceName);
139 String flowRef = InterfaceManagerCommonUtils.getTunnelInterfaceFlowRef(dpnId, NwConstants.VLAN_INTERFACE_INGRESS_TABLE, interfaceName);
140 List<MatchInfo> matches = new ArrayList<MatchInfo>();
141 List<InstructionInfo> mkInstructions = new ArrayList<InstructionInfo>();
142 if (NwConstants.ADD_FLOW == addOrRemoveFlow) {
143 matches.add(new MatchInfo(MatchFieldType.in_port, new BigInteger[] {
144 dpnId, BigInteger.valueOf(portNo) }));
145 mkInstructions.add(new InstructionInfo(
146 InstructionType.write_metadata, new BigInteger[] {
147 MetaDataUtil.getLportTagMetaData(ifIndex).or(BigInteger.ONE),
148 MetaDataUtil.METADATA_MASK_LPORT_TAG_SH_FLAG}));
149 short tableId = (tunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeMplsOverGre.class)) ? NwConstants.L3_LFIB_TABLE :
150 tunnel.isInternal() ? NwConstants.INTERNAL_TUNNEL_TABLE : NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL;
151 mkInstructions.add(new InstructionInfo(InstructionType.goto_table, new long[] {tableId}));
154 BigInteger COOKIE_VM_INGRESS_TABLE = new BigInteger("8000001", 16);
155 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.VLAN_INTERFACE_INGRESS_TABLE, flowRef,
156 IfmConstants.DEFAULT_FLOW_PRIORITY, interfaceName, 0, 0, COOKIE_VM_INGRESS_TABLE, matches, mkInstructions);
157 if (NwConstants.ADD_FLOW == addOrRemoveFlow) {
158 futures.add(mdsalApiManager.installFlow(dpnId, flowEntity));
160 futures.add(mdsalApiManager.removeFlow(dpnId, flowEntity));
163 public static String getTunnelInterfaceFlowRef(BigInteger dpnId, short tableId, String ifName) {
164 return new StringBuilder().append(dpnId).append(tableId).append(ifName).toString();
167 public static void setOpStateForInterface(DataBroker broker, String interfaceName, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus opStatus) {
168 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> interfaceId = IfmUtil.buildStateInterfaceId(interfaceName);
169 InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setKey(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey(interfaceName));
170 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceData = ifaceBuilder.setOperStatus(opStatus).build();
171 MDSALUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, interfaceId, interfaceData);
174 public static void createInterfaceChildEntry( WriteTransaction t,
175 String parentInterface, String childInterface){
176 InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
177 InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(childInterface);
178 InstanceIdentifier<InterfaceChildEntry> intfId =
179 InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
180 InterfaceChildEntryBuilder entryBuilder = new InterfaceChildEntryBuilder().setKey(interfaceChildEntryKey)
181 .setChildInterface(childInterface);
182 t.put(LogicalDatastoreType.CONFIGURATION, intfId, entryBuilder.build(),true);
185 public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus
186 updateStateEntry(Interface interfaceNew, DataBroker dataBroker, WriteTransaction transaction,
187 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) {
188 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus;
189 if (!interfaceNew.isEnabled()) {
190 operStatus = org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down;
192 String ncStr = ifState.getLowerLayerIf().get(0);
193 NodeConnectorId nodeConnectorId = new NodeConnectorId(ncStr);
194 NodeConnector nodeConnector =
195 InterfaceManagerCommonUtils.getNodeConnectorFromInventoryOperDS(nodeConnectorId, dataBroker);
196 FlowCapableNodeConnector flowCapableNodeConnector =
197 nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
198 //State state = flowCapableNodeConnector.getState();
199 operStatus = flowCapableNodeConnector == null ? org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down : org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up;
202 String ifName = interfaceNew.getName();
203 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
204 IfmUtil.buildStateInterfaceId(interfaceNew.getName());
205 InterfaceBuilder ifaceBuilder = new InterfaceBuilder();
206 ifaceBuilder.setOperStatus(operStatus);
207 ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(ifName));
208 transaction.merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build());
212 public static void updateOperStatus(String interfaceName, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus,
213 WriteTransaction transaction) {
214 LOG.debug("updating operational status for interface {}",interfaceName);
215 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifChildStateId =
216 IfmUtil.buildStateInterfaceId(interfaceName);
217 InterfaceBuilder ifaceBuilderChild = new InterfaceBuilder();
218 ifaceBuilderChild.setOperStatus(operStatus);
219 ifaceBuilderChild.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceName));
220 transaction.merge(LogicalDatastoreType.OPERATIONAL, ifChildStateId, ifaceBuilderChild.build());
223 public static void addStateEntry(String interfaceName, WriteTransaction transaction, DataBroker dataBroker, IdManagerService idManager,
224 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) {
225 // allocate lport tag and create interface-if-index map.
226 // This is done even if interface-state is not present, so that there is no throttling
227 // on id allocation even when multiple southbound port_up events come in one shot
228 Integer ifIndex = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, interfaceName);
229 InterfaceMetaUtils.createLportTagInterfaceMap(transaction, interfaceName, ifIndex);
231 LOG.debug("could not retrieve interface state corresponding to {}",interfaceName);
234 LOG.debug("adding interface state for {}",interfaceName);
235 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus = ifState.getOperStatus();
236 PhysAddress physAddress = ifState.getPhysAddress();
237 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus adminStatus = ifState.getAdminStatus();
238 NodeConnectorId nodeConnectorId = new NodeConnectorId(ifState.getLowerLayerIf().get(0));
239 InterfaceKey interfaceKey = new InterfaceKey(interfaceName);
240 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface interfaceInfo =
241 InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
243 if (interfaceInfo != null && !interfaceInfo.isEnabled()) {
244 operStatus = org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down;
247 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
248 IfmUtil.buildStateInterfaceId(interfaceName);
249 List<String> childLowerLayerIfList = new ArrayList<>();
250 childLowerLayerIfList.add(0, nodeConnectorId.getValue());
251 InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setAdminStatus(adminStatus)
252 .setOperStatus(operStatus).setPhysAddress(physAddress).setLowerLayerIf(childLowerLayerIfList);
253 ifaceBuilder.setIfIndex(ifIndex);
255 if(interfaceInfo != null){
256 ifaceBuilder.setType(interfaceInfo.getType());
258 ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceName));
259 transaction.put(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), true);
261 // install ingress flow
262 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
263 long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
264 if(interfaceInfo != null && interfaceInfo.isEnabled() &&
265 ifState.getOperStatus() == org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up) {
266 List<MatchInfo> matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, interfaceInfo);
267 FlowBasedServicesUtils.installVlanFlow(dpId, portNo, interfaceInfo, transaction, matches, ifIndex);
271 public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface addStateEntry(Interface interfaceInfo, String portName, WriteTransaction transaction, IdManagerService idManager,
272 PhysAddress physAddress, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus,
273 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus adminStatus,
274 NodeConnectorId nodeConnectorId) {
275 LOG.debug("adding interface state for {}",portName);
276 InterfaceBuilder ifaceBuilder = new InterfaceBuilder();
277 Integer ifIndex = null;
278 if (interfaceInfo != null){
279 if(!interfaceInfo.isEnabled()){
280 operStatus = org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down;
283 ifaceBuilder.setType(interfaceInfo.getType());
284 // retrieve if-index only for northbound configured interfaces
285 ifIndex = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, portName);
286 ifaceBuilder.setIfIndex(ifIndex);
288 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
289 IfmUtil.buildStateInterfaceId(portName);
290 List<String> childLowerLayerIfList = new ArrayList<>();
291 childLowerLayerIfList.add(0, nodeConnectorId.getValue());
292 ifaceBuilder.setAdminStatus(adminStatus)
293 .setOperStatus(operStatus).setPhysAddress(physAddress).setLowerLayerIf(childLowerLayerIfList);
294 ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(portName));
295 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState = ifaceBuilder.build();
296 transaction.put(LogicalDatastoreType.OPERATIONAL, ifStateId, ifState , true);
300 public static void deleteStateEntry(String interfaceName, WriteTransaction transaction) {
301 LOG.debug("removing interface state entry for {}",interfaceName);
302 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifChildStateId =
303 IfmUtil.buildStateInterfaceId(interfaceName);
304 transaction.delete(LogicalDatastoreType.OPERATIONAL, ifChildStateId);
307 public static void deleteInterfaceStateInformation(String interfaceName, WriteTransaction transaction, IdManagerService idManagerService) {
308 LOG.debug("removing interface state information for {}",interfaceName);
309 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
310 IfmUtil.buildStateInterfaceId(interfaceName);
311 transaction.delete(LogicalDatastoreType.OPERATIONAL, ifStateId);
312 InterfaceMetaUtils.removeLportTagInterfaceMap(idManagerService, transaction, interfaceName);
315 // For trunk interfaces, binding to a parent interface which is already bound to another trunk interface should not
317 public static boolean createInterfaceChildEntryIfNotPresent( DataBroker dataBroker, WriteTransaction t,
318 String parentInterface, String childInterface){
319 InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
320 InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIdentifier =
321 InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
322 InterfaceParentEntry interfaceParentEntry =
323 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIdentifier, dataBroker);
325 if(interfaceParentEntry != null){
326 LOG.error("Trying to bind the same parent interface {} to multiple trunk interfaces. ", parentInterface);
330 LOG.info("First vlan trunk {} bound on parent-interface {}", childInterface, parentInterface);
331 InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(childInterface);
332 InstanceIdentifier<InterfaceChildEntry> intfId =
333 InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
334 InterfaceChildEntryBuilder entryBuilder = new InterfaceChildEntryBuilder().setKey(interfaceChildEntryKey)
335 .setChildInterface(childInterface);
336 t.put(LogicalDatastoreType.CONFIGURATION, intfId, entryBuilder.build(),true);
340 public static boolean deleteParentInterfaceEntry( WriteTransaction t, String parentInterface){
341 InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
342 InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIdentifier = InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
343 t.delete(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIdentifier);
348 * update operational state of interface based on events like tunnel monitoring
350 public static void updateOpState(WriteTransaction transaction, String interfaceName,
351 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus){
352 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
353 IfmUtil.buildStateInterfaceId(interfaceName);
354 LOG.debug("updating tep interface state as {} for {}", operStatus.name(), interfaceName);
355 InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setOperStatus(operStatus);
356 ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceName));
357 transaction.merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build());
360 public static boolean isTunnelInterface(Interface interfaceInfo){
361 if(interfaceInfo != null && interfaceInfo.getAugmentation(IfTunnel.class) != null){
367 public static boolean isVlanInterface(Interface interfaceInfo){
368 if(interfaceInfo != null && interfaceInfo.getAugmentation(IfL2vlan.class) != null){