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 java.util.ArrayList;
11 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
15 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import com.google.common.util.concurrent.ListenableFuture;
26 public class OvsVlanMemberConfigAddHelper {
27 private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigAddHelper.class);
28 public static List<ListenableFuture<Void>> addConfiguration(DataBroker dataBroker, ParentRefs parentRefs,
29 Interface interfaceNew, IfL2vlan ifL2vlan,
30 IdManagerService idManager) {
31 LOG.debug("add vlan member configuration {}",interfaceNew.getName());
32 List<ListenableFuture<Void>> futures = new ArrayList<>();
33 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
35 InterfaceManagerCommonUtils.createInterfaceChildEntry(t, parentRefs.getParentInterface(), interfaceNew.getName());
37 InterfaceKey interfaceKey = new InterfaceKey(parentRefs.getParentInterface());
38 Interface ifaceParent = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
39 if (ifaceParent == null) {
40 LOG.info("Parent Interface: {} not found when adding child interface: {}",
41 parentRefs.getParentInterface(), interfaceNew.getName());
42 futures.add(t.submit());
46 IfL2vlan parentIfL2Vlan = ifaceParent.getAugmentation(IfL2vlan.class);
47 if (parentIfL2Vlan == null || parentIfL2Vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.Trunk) {
48 LOG.error("Parent Interface: {} not of trunk Type when adding trunk-member: {}", ifaceParent, interfaceNew);
49 futures.add(t.submit());
53 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
54 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker);
55 if (ifState != null) {
56 LOG.debug("add interface state info for vlan member {}",interfaceNew.getName());
57 InterfaceManagerCommonUtils.addStateEntry(interfaceNew.getName(), t, dataBroker, idManager, ifState);
60 // FIXME: Maybe, add the new interface to the higher-layer if of the parent interface-state.
61 // That may not serve any purpose though for interface manager.... Unless some external parties are interested in it.
63 /* FIXME -- Below code is needed to add vlan-trunks to the of-port. Is this really needed.
64 String lowerLayerIf = ifState.getLowerLayerIf().get(0);
66 NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
67 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
69 BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
70 InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
71 InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
72 BridgeRefEntry bridgeRefEntry =
73 InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
74 if (bridgeRefEntry != null) {
75 InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
76 (InstanceIdentifier<OvsdbBridgeAugmentation>)bridgeRefEntry.getBridgeReference().getValue();
77 Optional<OvsdbBridgeAugmentation> bridgeNodeOptional =
78 IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeIid, dataBroker);
79 if (bridgeNodeOptional.isPresent()) {
80 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNodeOptional.get();
81 String bridgeName = ovsdbBridgeAugmentation.getBridgeName().getValue();
82 VlanTrunkSouthboundUtils.addVlanPortToBridge(bridgeIid, ifL2vlan,
83 ovsdbBridgeAugmentation, bridgeName, parentRefs.getParentInterface(), dataBroker, t);
86 // FIXME: Need to add the Group here with actions: Push-Vlan, output_port. May not be needed here...
89 futures.add(t.submit());