2 * Copyright (c) 2016, 2017 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 static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.ArrayList;
14 import java.util.List;
15 import javax.inject.Inject;
16 import javax.inject.Singleton;
17 import org.apache.aries.blueprint.annotation.service.Reference;
18 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
19 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
20 import org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils;
21 import org.opendaylight.mdsal.binding.api.DataBroker;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 public class OvsVlanMemberConfigAddHelper {
31 private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigAddHelper.class);
32 private static final Logger EVENT_LOGGER = LoggerFactory.getLogger("GeniusEventLogger");
34 private final ManagedNewTransactionRunner txRunner;
35 private final InterfaceManagerCommonUtils interfaceManagerCommonUtils;
38 public OvsVlanMemberConfigAddHelper(@Reference DataBroker dataBroker,
39 InterfaceManagerCommonUtils interfaceManagerCommonUtils) {
40 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
41 this.interfaceManagerCommonUtils = interfaceManagerCommonUtils;
44 public List<ListenableFuture<Void>> addConfiguration(ParentRefs parentRefs, Interface interfaceNew) {
45 LOG.info("adding vlan member configuration for interface {}", interfaceNew.getName());
46 EVENT_LOGGER.debug("IFM-OVSVlanMemberConfig,ADD Parent {},Child {}", parentRefs.getParentInterface(),
47 interfaceNew.getName());
48 List<ListenableFuture<Void>> futures = new ArrayList<>();
49 futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
50 tx -> interfaceManagerCommonUtils.createInterfaceChildEntry(tx, parentRefs.getParentInterface(),
51 interfaceNew.getName())));
53 InterfaceKey interfaceKey = new InterfaceKey(parentRefs.getParentInterface());
54 Interface ifaceParent = interfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey);
55 if (ifaceParent == null) {
56 LOG.info("Parent Interface: {} not found when adding child interface: {}", parentRefs.getParentInterface(),
57 interfaceNew.getName());
61 IfL2vlan parentIfL2Vlan = ifaceParent.augmentation(IfL2vlan.class);
62 if (parentIfL2Vlan == null || parentIfL2Vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.Trunk) {
63 LOG.error("Parent Interface: {} not of trunk Type when adding trunk-member: {}", ifaceParent, interfaceNew);
67 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
68 .ietf.interfaces.rev140508.interfaces.state.Interface ifState = interfaceManagerCommonUtils
69 .getInterfaceState(parentRefs.getParentInterface());
70 interfaceManagerCommonUtils.addStateEntry(interfaceNew.getName(), futures, ifState);