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.confighelpers;
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.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.idmanager.IdManager;
15 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
16 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
17 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntry;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info.InterfaceParentEntryKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntry;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.meta.rev151007._interface.child.info._interface.parent.entry.InterfaceChildEntryKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import java.util.ArrayList;
30 import java.util.List;
32 public class OvsVlanMemberConfigRemoveHelper {
33 private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigRemoveHelper.class);
34 public static List<ListenableFuture<Void>> removeConfiguration(DataBroker dataBroker, ParentRefs parentRefs,
35 Interface interfaceOld, IfL2vlan ifL2vlan,
36 IdManager idManager) {
37 List<ListenableFuture<Void>> futures = new ArrayList<>();
38 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
40 InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentRefs.getParentInterface());
41 InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIid =
42 InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
43 InterfaceParentEntry interfaceParentEntry =
44 InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIid, dataBroker);
46 List<InterfaceChildEntry> interfaceChildEntries = interfaceParentEntry.getInterfaceChildEntry();
47 if (interfaceChildEntries.size() <= 1) {
48 t.delete(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIid);
50 InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(interfaceOld.getName());
51 InstanceIdentifier<InterfaceChildEntry> interfaceChildEntryIid =
52 InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
53 t.delete(LogicalDatastoreType.CONFIGURATION, interfaceChildEntryIid);
56 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
57 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker);
58 if (ifState != null) {
59 /* FIXME -- The below code is needed if vlan-trunks should be updated in the of-port
61 String lowerLayerIf = ifState.getLowerLayerIf().get(0);
62 NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
63 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
65 BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
66 InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
67 InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
68 BridgeRefEntry bridgeRefEntry =
69 InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
70 if (bridgeRefEntry != null) {
71 InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
72 (InstanceIdentifier<OvsdbBridgeAugmentation>)bridgeRefEntry.getBridgeReference().getValue();
73 Optional<OvsdbBridgeAugmentation> bridgeNodeOptional =
74 IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeIid, dataBroker);
75 if (bridgeNodeOptional.isPresent()) {
76 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNodeOptional.get();
77 String bridgeName = ovsdbBridgeAugmentation.getBridgeName().getValue();
78 VlanTrunkSouthboundUtils.updateVlanMemberInTrunk(bridgeIid, ifL2vlan,
79 ovsdbBridgeAugmentation, bridgeName, parentRefs.getParentInterface(), dataBroker, t);
83 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
84 IfmUtil.buildStateInterfaceId(interfaceOld.getName());
85 t.delete(LogicalDatastoreType.OPERATIONAL, ifStateId);
88 futures.add(t.submit());