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;
18 import org.apache.aries.blueprint.annotation.service.Reference;
19 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
20 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
21 import org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils;
22 import org.opendaylight.mdsal.binding.api.DataBroker;
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.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 public class OvsVlanMemberConfigAddHelper {
32 private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigAddHelper.class);
33 private static final Logger EVENT_LOGGER = LoggerFactory.getLogger("GeniusEventLogger");
35 private final ManagedNewTransactionRunner txRunner;
36 private final InterfaceManagerCommonUtils interfaceManagerCommonUtils;
39 public OvsVlanMemberConfigAddHelper(@Reference DataBroker dataBroker,
40 InterfaceManagerCommonUtils interfaceManagerCommonUtils) {
41 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
42 this.interfaceManagerCommonUtils = interfaceManagerCommonUtils;
45 public List<ListenableFuture<Void>> addConfiguration(ParentRefs parentRefs, Interface interfaceNew) {
46 LOG.info("adding vlan member configuration for interface {}", interfaceNew.getName());
47 EVENT_LOGGER.debug("IFM-OVSVlanMemberConfig,ADD Parent {},Child {}", parentRefs.getParentInterface(),
48 interfaceNew.getName());
49 List<ListenableFuture<Void>> futures = new ArrayList<>();
50 futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
51 tx -> interfaceManagerCommonUtils.createInterfaceChildEntry(tx, parentRefs.getParentInterface(),
52 interfaceNew.getName())));
54 InterfaceKey interfaceKey = new InterfaceKey(parentRefs.getParentInterface());
55 Interface ifaceParent = interfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey);
56 if (ifaceParent == null) {
57 LOG.info("Parent Interface: {} not found when adding child interface: {}", parentRefs.getParentInterface(),
58 interfaceNew.getName());
62 IfL2vlan parentIfL2Vlan = ifaceParent.augmentation(IfL2vlan.class);
63 if (parentIfL2Vlan == null || parentIfL2Vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.Trunk) {
64 LOG.error("Parent Interface: {} not of trunk Type when adding trunk-member: {}", ifaceParent, interfaceNew);
68 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
69 .ietf.interfaces.rev140508.interfaces.state.Interface ifState = interfaceManagerCommonUtils
70 .getInterfaceState(parentRefs.getParentInterface());
71 interfaceManagerCommonUtils.addStateEntry(interfaceNew.getName(), futures, ifState);