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
8 package org.opendaylight.genius.interfacemanager.renderer.ovs.confighelpers;
10 import com.google.common.base.Optional;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.util.ArrayList;
13 import java.util.List;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
17 import org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils;
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.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
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 writeTransaction = dataBroker.newWriteOnlyTransaction();
34 InterfaceManagerCommonUtils.createInterfaceChildEntry(parentRefs.getParentInterface(),
35 interfaceNew.getName(), Optional.of(writeTransaction));
36 futures.add(writeTransaction.submit());
38 InterfaceKey interfaceKey = new InterfaceKey(parentRefs.getParentInterface());
39 Interface ifaceParent = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
40 if (ifaceParent == null) {
41 LOG.info("Parent Interface: {} not found when adding child interface: {}",
42 parentRefs.getParentInterface(), interfaceNew.getName());
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);
52 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
53 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker);
54 LOG.debug("add interface state info for vlan member {}, with ifState for parent {}",interfaceNew.getName(), ifState);
55 InterfaceManagerCommonUtils.addStateEntry(interfaceNew.getName(), dataBroker, idManager, futures, ifState);