Bump versions by 0.1.0 for next dev cycle
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / renderer / ovs / confighelpers / OvsVlanMemberConfigAddHelper.java
1 /*
2  * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
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;
23
24 import com.google.common.util.concurrent.ListenableFuture;
25
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();
34
35         InterfaceManagerCommonUtils.createInterfaceChildEntry(t, parentRefs.getParentInterface(), interfaceNew.getName());
36
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());
43             return futures;
44         }
45
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());
50             return futures;
51         }
52
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);
58         }
59
60         futures.add(t.submit());
61         return futures;
62     }
63 }