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 com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.vpnservice.interfacemgr.IfmConstants;
16 import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
17 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceManagerCommonUtils;
18 import org.opendaylight.vpnservice.interfacemgr.commons.InterfaceMetaUtils;
19 import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
20 import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
22 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
23 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.IfL2vlan;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 import java.math.BigInteger;
36 import java.util.ArrayList;
37 import java.util.List;
39 public class OvsVlanMemberConfigAddHelper {
40 private static final Logger LOG = LoggerFactory.getLogger(OvsVlanMemberConfigAddHelper.class);
41 public static List<ListenableFuture<Void>> addConfiguration(DataBroker dataBroker, ParentRefs parentRefs,
42 Interface interfaceNew, IfL2vlan ifL2vlan,
43 IdManagerService idManager) {
44 LOG.debug("add vlan member configuration {}",interfaceNew.getName());
45 List<ListenableFuture<Void>> futures = new ArrayList<>();
46 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
48 InterfaceManagerCommonUtils.createInterfaceParentEntryIfNotPresent(dataBroker, t, parentRefs.getParentInterface());
49 InterfaceManagerCommonUtils.createInterfaceChildEntry(t, parentRefs.getParentInterface(), interfaceNew.getName());
51 InterfaceKey interfaceKey = new InterfaceKey(parentRefs.getParentInterface());
52 Interface ifaceParent = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
53 if (ifaceParent == null) {
54 LOG.info("Parent Interface: {} not found when adding child interface: {}",
55 parentRefs.getParentInterface(), interfaceNew.getName());
56 futures.add(t.submit());
60 IfL2vlan parentIfL2Vlan = ifaceParent.getAugmentation(IfL2vlan.class);
61 if (parentIfL2Vlan == null || parentIfL2Vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.Trunk) {
62 LOG.error("Parent Interface: {} not of trunk Type when adding trunk-member: {}", ifaceParent, interfaceNew);
63 futures.add(t.submit());
67 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
68 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker);
69 if (ifState != null) {
70 LOG.debug("add interface state info for vlan member {}",interfaceNew.getName());
71 OperStatus operStatus = ifState.getOperStatus();
72 AdminStatus adminStatus = ifState.getAdminStatus();
73 PhysAddress physAddress = ifState.getPhysAddress();
75 if (!interfaceNew.isEnabled()) {
76 operStatus = OperStatus.Down;
79 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
80 IfmUtil.buildStateInterfaceId(interfaceNew.getName());
81 List<String> lowerLayerIfList = new ArrayList<>();
82 lowerLayerIfList.add(ifState.getLowerLayerIf().get(0));
83 //lowerLayerIfList.add(parentRefs.getParentInterface());
84 Integer ifIndex = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, interfaceNew.getName());
85 InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setAdminStatus(adminStatus).setOperStatus(operStatus)
86 .setPhysAddress(physAddress).setLowerLayerIf(lowerLayerIfList).setIfIndex(ifIndex);
87 ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceNew.getName()));
88 t.put(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), true);
90 // create lportTag Interface Map
91 InterfaceMetaUtils.createLportTagInterfaceMap(t, interfaceNew.getName(), ifIndex);
92 //Installing vlan flow for vlan member
93 NodeConnectorId nodeConnectorId = new NodeConnectorId(ifState.getLowerLayerIf().get(0));
94 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
95 long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
96 if (operStatus == OperStatus.Up) {
97 List<MatchInfo> matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, interfaceNew);
98 FlowBasedServicesUtils.installVlanFlow(dpId, portNo, interfaceNew, t, matches, ifIndex);
101 // FIXME: Maybe, add the new interface to the higher-layer if of the parent interface-state.
102 // That may not serve any purpose though for interface manager.... Unless some external parties are interested in it.
104 /* FIXME -- Below code is needed to add vlan-trunks to the of-port. Is this really needed.
105 String lowerLayerIf = ifState.getLowerLayerIf().get(0);
107 NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
108 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
110 BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
111 InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
112 InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
113 BridgeRefEntry bridgeRefEntry =
114 InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
115 if (bridgeRefEntry != null) {
116 InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
117 (InstanceIdentifier<OvsdbBridgeAugmentation>)bridgeRefEntry.getBridgeReference().getValue();
118 Optional<OvsdbBridgeAugmentation> bridgeNodeOptional =
119 IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeIid, dataBroker);
120 if (bridgeNodeOptional.isPresent()) {
121 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNodeOptional.get();
122 String bridgeName = ovsdbBridgeAugmentation.getBridgeName().getValue();
123 VlanTrunkSouthboundUtils.addVlanPortToBridge(bridgeIid, ifL2vlan,
124 ovsdbBridgeAugmentation, bridgeName, parentRefs.getParentInterface(), dataBroker, t);
127 // FIXME: Need to add the Group here with actions: Push-Vlan, output_port. May not be needed here...
130 futures.add(t.submit());