/*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.vpnservice.interfacemgr.commons;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.idmanager.IdManager;
import org.opendaylight.vpnservice.interfacemgr.IfmConstants;
import org.opendaylight.vpnservice.interfacemgr.IfmUtil;
+import org.opendaylight.vpnservice.interfacemgr.globals.InterfaceInfo;
import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
-import org.opendaylight.vpnservice.mdsalutil.*;
+import org.opendaylight.vpnservice.mdsalutil.FlowEntity;
+import org.opendaylight.vpnservice.mdsalutil.InstructionInfo;
+import org.opendaylight.vpnservice.mdsalutil.InstructionType;
+import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
+import org.opendaylight.vpnservice.mdsalutil.MatchFieldType;
+import org.opendaylight.vpnservice.mdsalutil.MatchInfo;
+import org.opendaylight.vpnservice.mdsalutil.MetaDataUtil;
+import org.opendaylight.vpnservice.mdsalutil.NwConstants;
import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfaceType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
public class InterfaceManagerCommonUtils {
private static final Logger LOG = LoggerFactory.getLogger(InterfaceManagerCommonUtils.class);
return interfaceInstanceIdentifierBuilder.build();
}
+ public static List<Interface> getAllTunnelInterfaces(DataBroker dataBroker, InterfaceInfo.InterfaceType interfaceType) {
+ List<Interface> vxlanList = new ArrayList<Interface>();
+ InstanceIdentifier<Interfaces> interfacesInstanceIdentifier = InstanceIdentifier.builder(Interfaces.class).build();
+ Optional<Interfaces> interfacesOptional = IfmUtil.read(LogicalDatastoreType.CONFIGURATION, interfacesInstanceIdentifier, dataBroker);
+ if (!interfacesOptional.isPresent()) {
+ return vxlanList;
+ }
+ Interfaces interfaces = interfacesOptional.get();
+ List<Interface> interfacesList = interfaces.getInterface();
+ for (Interface iface : interfacesList) {
+ if(IfmUtil.getInterfaceType(iface) == InterfaceInfo.InterfaceType.VXLAN_TRUNK_INTERFACE &&
+ iface.getAugmentation(IfTunnel.class).isInternal()) {
+ vxlanList.add(iface);
+ }
+ }
+ return vxlanList;
+ }
+
+ public static Interface getInterfaceFromConfigDS(String interfaceName, DataBroker dataBroker) {
+ InterfaceKey interfaceKey = new InterfaceKey(interfaceName);
+ return getInterfaceFromConfigDS(interfaceKey, dataBroker);
+ }
+
public static Interface getInterfaceFromConfigDS(InterfaceKey interfaceKey, DataBroker dataBroker) {
InstanceIdentifier<Interface> interfaceId = getInterfaceIdentifier(interfaceKey);
Optional<Interface> interfaceOptional = IfmUtil.read(LogicalDatastoreType.CONFIGURATION, interfaceId, dataBroker);
public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface getInterfaceStateFromOperDS(String interfaceName, DataBroker dataBroker) {
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
IfmUtil.buildStateInterfaceId(interfaceName);
+ return getInterfaceStateFromOperDS(ifStateId, dataBroker);
+ }
+
+ public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface getInterfaceStateFromOperDS
+ (InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId, DataBroker dataBroker) {
Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateOptional =
IfmUtil.read(LogicalDatastoreType.OPERATIONAL, ifStateId, dataBroker);
if (!ifStateOptional.isPresent()) {
}
public static void makeTunnelIngressFlow(List<ListenableFuture<Void>> futures, IMdsalApiManager mdsalApiManager,
IfTunnel tunnel, BigInteger dpnId, long portNo, Interface iface, int ifIndex, int addOrRemoveFlow) {
+ LOG.debug("make tunnel ingress flow for {}",iface.getName());
String flowRef = InterfaceManagerCommonUtils.getTunnelInterfaceFlowRef(dpnId, NwConstants.VLAN_INTERFACE_INGRESS_TABLE, iface.getName());
List<MatchInfo> matches = new ArrayList<MatchInfo>();
List<InstructionInfo> mkInstructions = new ArrayList<InstructionInfo>();
dpnId, BigInteger.valueOf(portNo) }));
mkInstructions.add(new InstructionInfo(
InstructionType.write_metadata, new BigInteger[] {
- MetaDataUtil.getLportTagMetaData(ifIndex),
- MetaDataUtil.METADATA_MASK_LPORT_TAG}));
+ MetaDataUtil.getLportTagMetaData(ifIndex).or(BigInteger.ONE),
+ MetaDataUtil.METADATA_MASK_LPORT_TAG_SH_FLAG}));
short tableId = tunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeMplsOverGre.class) ? NwConstants.L3_LFIB_TABLE :
- tunnel.isInternal() ? NwConstants.INTERNAL_TUNNEL_TABLE : NwConstants.EXTERNAL_TUNNEL_TABLE;
+ tunnel.isInternal() ? NwConstants.INTERNAL_TUNNEL_TABLE : NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL;
mkInstructions.add(new InstructionInfo(InstructionType.goto_table, new long[] {tableId}));
}
MDSALUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, interfaceId, interfaceData);
}
- public static void updateTunnelMonitorDetailsInConfigDS(DataBroker broker, String interfaceName, boolean monitorEnabled, long monitorInterval) {
- InstanceIdentifier<Interface> id = IfmUtil.buildId(interfaceName);
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder ifaceBuilder = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder();
- ifaceBuilder.setKey(new InterfaceKey(interfaceName));
- IfTunnelBuilder ifTunnelBuilder = new IfTunnelBuilder();
- ifTunnelBuilder.setMonitorEnabled(monitorEnabled);
- ifTunnelBuilder.setMonitorInterval(monitorInterval);
- ifaceBuilder.addAugmentation(IfTunnel.class, ifTunnelBuilder.build());
-
- LOG.trace("Updating trunk interface {} in Config DS", interfaceName);
- MDSALUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, id, ifaceBuilder.build());
- }
-
- public static void createInterfaceParentEntryIfNotPresent(DataBroker dataBroker, WriteTransaction t,
- String parentInterface){
- InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
- InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIdentifier =
- InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
- InterfaceParentEntry interfaceParentEntry =
- InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIdentifier, dataBroker);
-
- if(interfaceParentEntry != null){
- LOG.info("Not Found entry for Parent Interface: {} in Vlan Trunk-Member Interface Renderer ConfigDS. " +
- "Creating...", parentInterface);
- InterfaceParentEntryBuilder interfaceParentEntryBuilder = new InterfaceParentEntryBuilder()
- .setKey(interfaceParentEntryKey).setParentInterface(parentInterface);
- t.put(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIdentifier,
- interfaceParentEntryBuilder.build(), true);
- }
- }
-
public static void createInterfaceChildEntry( WriteTransaction t,
String parentInterface, String childInterface){
InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
t.put(LogicalDatastoreType.CONFIGURATION, intfId, entryBuilder.build(),true);
}
- /*public static void updateStateEntry(Interface interfaceInfo, DataBroker dataBroker, WriteTransaction transaction,
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) {
- String ncStr = ifState.getLowerLayerIf().get(0);
- NodeConnectorId nodeConnectorId = new NodeConnectorId(ncStr);
- NodeConnector nodeConnector =
- InterfaceManagerCommonUtils.getNodeConnectorFromInventoryOperDS(nodeConnectorId, dataBroker);
- if(nodeConnector != null) {
- FlowCapableNodeConnector flowCapableNodeConnector =
- nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
- //State state = flowCapableNodeConnector.getState();
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus =
- flowCapableNodeConnector == null ? org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down : org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up;
-
- if (ifState.getOperStatus() != operStatus) {
- InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
- IfmUtil.buildStateInterfaceId(interfaceInfo.getName());
- InterfaceBuilder ifaceBuilder = new InterfaceBuilder();
- ifaceBuilder.setOperStatus(operStatus);
- ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceInfo.getName()));
- transaction.merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build());
- }
- }
- }*/
-
public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus
updateStateEntry(Interface interfaceNew, DataBroker dataBroker, WriteTransaction transaction,
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) {
public static void updateOperStatus(String interfaceName, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus,
WriteTransaction transaction) {
+ LOG.debug("updating operational status for interface {}",interfaceName);
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifChildStateId =
IfmUtil.buildStateInterfaceId(interfaceName);
InterfaceBuilder ifaceBuilderChild = new InterfaceBuilder();
public static void addStateEntry(String interfaceName, WriteTransaction transaction, DataBroker dataBroker, IdManagerService idManager,
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState) {
+ LOG.debug("adding interface state for {}",interfaceName);
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus = ifState.getOperStatus();
PhysAddress physAddress = ifState.getPhysAddress();
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus adminStatus = ifState.getAdminStatus();
IfmUtil.buildStateInterfaceId(interfaceName);
List<String> childLowerLayerIfList = new ArrayList<>();
childLowerLayerIfList.add(0, nodeConnectorId.getValue());
- //childLowerLayerIfList.add(1, interfaceName);
InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setAdminStatus(adminStatus)
.setOperStatus(operStatus).setPhysAddress(physAddress).setLowerLayerIf(childLowerLayerIfList);
if(interfaceInfo != null){
ifaceBuilder.setType(interfaceInfo.getType());
}
- ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceInfo.getName()));
+ ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceName));
transaction.put(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), true);
// create lportTag Interface Map
// install ingress flow
BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
- if(interfaceInfo.isEnabled() && ifState.getOperStatus() == org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up) {
+ if(interfaceInfo != null && interfaceInfo.isEnabled() && ifState.getOperStatus() == org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up) {
List<MatchInfo> matches = FlowBasedServicesUtils.getMatchInfoForVlanPortAtIngressTable(dpId, portNo, interfaceInfo);
FlowBasedServicesUtils.installVlanFlow(dpId, portNo, interfaceInfo, transaction, matches, ifIndex);
}
PhysAddress physAddress, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus,
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus adminStatus,
NodeConnectorId nodeConnectorId) {
+ LOG.debug("adding interface state for {}",portName);
if (interfaceInfo != null && !interfaceInfo.isEnabled()) {
operStatus = org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down;
}
IfmUtil.buildStateInterfaceId(portName);
List<String> childLowerLayerIfList = new ArrayList<>();
childLowerLayerIfList.add(0, nodeConnectorId.getValue());
- //childLowerLayerIfList.add(1, interfaceInfo.getName());
InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setAdminStatus(adminStatus)
.setOperStatus(operStatus).setPhysAddress(physAddress).setLowerLayerIf(childLowerLayerIfList);
}
public static void deleteStateEntry(String interfaceName, WriteTransaction transaction) {
+ LOG.debug("removing interface state for {}",interfaceName);
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifChildStateId =
IfmUtil.buildStateInterfaceId(interfaceName);
transaction.delete(LogicalDatastoreType.OPERATIONAL, ifChildStateId);
}
+
+ // For trunk interfaces, binding to a parent interface which is already bound to another trunk interface should not
+ // be allowed
+ public static boolean createInterfaceChildEntryIfNotPresent( DataBroker dataBroker, WriteTransaction t,
+ String parentInterface, String childInterface){
+ InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
+ InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIdentifier =
+ InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
+ InterfaceParentEntry interfaceParentEntry =
+ InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIdentifier, dataBroker);
+
+ if(interfaceParentEntry != null){
+ LOG.error("Trying to bind the same parent interface {} to multiple trunk interfaces. ", parentInterface);
+ return false;
+ }
+
+ LOG.info("First vlan trunk {} bound on parent-interface {}", childInterface, parentInterface);
+ InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(childInterface);
+ InstanceIdentifier<InterfaceChildEntry> intfId =
+ InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
+ InterfaceChildEntryBuilder entryBuilder = new InterfaceChildEntryBuilder().setKey(interfaceChildEntryKey)
+ .setChildInterface(childInterface);
+ t.put(LogicalDatastoreType.CONFIGURATION, intfId, entryBuilder.build(),true);
+ return true;
+ }
+
+ public static boolean deleteParentInterfaceEntry( WriteTransaction t, String parentInterface){
+ InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
+ InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIdentifier = InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
+ t.delete(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIdentifier);
+ return true;
+ }
+
+ public static void deleteInterfaceChildEntry(WriteTransaction transaction, DataBroker dataBroker, String parentInterface, String childInterface){
+ InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
+ InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIid =
+ InterfaceMetaUtils.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
+ InterfaceParentEntry interfaceParentEntry =
+ InterfaceMetaUtils.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIid, dataBroker);
+
+ if(interfaceParentEntry == null){
+ return;
+ }
+
+ List<InterfaceChildEntry> interfaceChildEntries = interfaceParentEntry.getInterfaceChildEntry();
+ if (interfaceChildEntries.size() <= 1) {
+ transaction.delete(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIid);
+ } else {
+ InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(childInterface);
+ InstanceIdentifier<InterfaceChildEntry> interfaceChildEntryIid =
+ InterfaceMetaUtils.getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
+ transaction.delete(LogicalDatastoreType.CONFIGURATION, interfaceChildEntryIid);
+ }
+ }
+
+ /*
+ * update operational state of interface based on events like tunnel monitoring
+ */
+ public static void updateOpState(WriteTransaction transaction, String interfaceName,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus){
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId =
+ IfmUtil.buildStateInterfaceId(interfaceName);
+ LOG.debug("updating tep interface state as {} for {}", operStatus.name(), interfaceName);
+ InterfaceBuilder ifaceBuilder = new InterfaceBuilder().setOperStatus(operStatus);
+ ifaceBuilder.setKey(IfmUtil.getStateInterfaceKeyFromName(interfaceName));
+ transaction.merge(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build());
+ }
+
}
\ No newline at end of file