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 List<ListenableFuture<Void>> futures = new ArrayList<>();
45 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
47 InterfaceManagerCommonUtils.createInterfaceParentEntryIfNotPresent(dataBroker, t, parentRefs.getParentInterface());
48 InterfaceManagerCommonUtils.createInterfaceChildEntry(t, parentRefs.getParentInterface(), interfaceNew.getName());
50 InterfaceKey interfaceKey = new InterfaceKey(parentRefs.getParentInterface());
51 Interface ifaceParent = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
52 if (ifaceParent == null) {
53 LOG.info("Parent Interface: {} not found when adding child interface: {}",
54 parentRefs.getParentInterface(), interfaceNew.getName());
55 futures.add(t.submit());
59 IfL2vlan parentIfL2Vlan = ifaceParent.getAugmentation(IfL2vlan.class);
60 if (parentIfL2Vlan == null || parentIfL2Vlan.getL2vlanMode() != IfL2vlan.L2vlanMode.Trunk) {
61 LOG.error("Parent Interface: {} not of trunk Type when adding trunk-member: {}", ifaceParent, interfaceNew);
62 futures.add(t.submit());
66 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
67 InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(parentRefs.getParentInterface(), dataBroker);
68 if (ifState != null) {
69 OperStatus operStatus = ifState.getOperStatus();
70 AdminStatus adminStatus = ifState.getAdminStatus();
71 PhysAddress physAddress = ifState.getPhysAddress();
73 if (!interfaceNew.isEnabled()) {
74 operStatus = OperStatus.Down;
77 InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
78 IfmUtil.buildStateInterfaceId(interfaceNew.getName());
79 List<String> lowerLayerIfList = new ArrayList<>();
80 lowerLayerIfList.add(ifState.getLowerLayerIf().get(0));
81 //lowerLayerIfList.add(parentRefs.getParentInterface());
82 Integer ifIndex = IfmUtil.allocateId(idManager, IfmConstants.IFM_IDPOOL_NAME, interfaceNew.getName());
83 InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setAdminStatus(adminStatus).setOperStatus(operStatus)
84 .setPhysAddress(physAddress).setLowerLayerIf(lowerLayerIfList).setIfIndex(ifIndex);
85 ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceNew.getName()));
86 t.put(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), true);
88 // create lportTag Interface Map
89 InterfaceMetaUtils.createLportTagInterfaceMap(t, interfaceNew.getName(), ifIndex);
90 //Installing vlan flow for vlan member
91 NodeConnectorId nodeConnectorId = new NodeConnectorId(ifState.getLowerLayerIf().get(0));
92 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
93 long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
94 if (operStatus == OperStatus.Up) {
95 List<MatchInfo> matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, interfaceNew);
96 FlowBasedServicesUtils.installVlanFlow(dpId, portNo, interfaceNew, t, matches, ifIndex);
99 // FIXME: Maybe, add the new interface to the higher-layer if of the parent interface-state.
100 // That may not serve any purpose though for interface manager.... Unless some external parties are interested in it.
102 /* FIXME -- Below code is needed to add vlan-trunks to the of-port. Is this really needed.
103 String lowerLayerIf = ifState.getLowerLayerIf().get(0);
105 NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
106 BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
108 BridgeRefEntryKey BridgeRefEntryKey = new BridgeRefEntryKey(dpId);
109 InstanceIdentifier<BridgeRefEntry> dpnBridgeEntryIid =
110 InterfaceMetaUtils.getBridgeRefEntryIdentifier(BridgeRefEntryKey);
111 BridgeRefEntry bridgeRefEntry =
112 InterfaceMetaUtils.getBridgeRefEntryFromOperDS(dpnBridgeEntryIid, dataBroker);
113 if (bridgeRefEntry != null) {
114 InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
115 (InstanceIdentifier<OvsdbBridgeAugmentation>)bridgeRefEntry.getBridgeReference().getValue();
116 Optional<OvsdbBridgeAugmentation> bridgeNodeOptional =
117 IfmUtil.read(LogicalDatastoreType.OPERATIONAL, bridgeIid, dataBroker);
118 if (bridgeNodeOptional.isPresent()) {
119 OvsdbBridgeAugmentation ovsdbBridgeAugmentation = bridgeNodeOptional.get();
120 String bridgeName = ovsdbBridgeAugmentation.getBridgeName().getValue();
121 VlanTrunkSouthboundUtils.addVlanPortToBridge(bridgeIid, ifL2vlan,
122 ovsdbBridgeAugmentation, bridgeName, parentRefs.getParentInterface(), dataBroker, t);
125 // FIXME: Need to add the Group here with actions: Push-Vlan, output_port. May not be needed here...
128 futures.add(t.submit());