import com.google.common.util.concurrent.ListenableFuture;
import java.math.BigInteger;
import java.util.ArrayList;
-import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.DpnToInterfaceList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info.InterfaceParentEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info.InterfaceParentEntryKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info._interface.parent.entry.InterfaceChildEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info._interface.parent.entry.InterfaceChildEntryBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._interface.child.info._interface.parent.entry.InterfaceChildEntryKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.dpn.to._interface.list.DpnToInterface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.dpn.to._interface.list.DpnToInterfaceKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.dpn.to._interface.list.dpn.to._interface.InterfaceNameEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.dpn.to._interface.list.dpn.to._interface.InterfaceNameEntryBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.dpn.to._interface.list.dpn.to._interface.InterfaceNameEntryKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfL2vlan;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeMplsOverGre;
private static final Logger LOG = LoggerFactory.getLogger(InterfaceManagerCommonUtils.class);
private static ConcurrentHashMap<String, Interface> interfaceConfigMap = new ConcurrentHashMap<>();
private static ConcurrentHashMap<String, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface> interfaceStateMap = new ConcurrentHashMap<>();
+ private static ConcurrentHashMap<String, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus> bfdStateMap =
+ new ConcurrentHashMap<>();
+
private static final String NOVA_OR_TUNNEL_PORT_REGEX = "(tap|vhu)[0-9a-f]{8}-[0-9a-f]{2}|tun[0-9a-f]{11}";
private static final Pattern pattern = Pattern.compile(NOVA_OR_TUNNEL_PORT_REGEX);
.child(Node.class, new NodeKey(nodeId))
.child(NodeConnector.class, new NodeConnectorKey(nodeConnectorId)).build();
- Optional<NodeConnector> nodeConnectorOptional = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, ncIdentifier,
- dataBroker);
- if (!nodeConnectorOptional.isPresent()) {
- return null;
- }
- return nodeConnectorOptional.get();
+ return IfmUtil.read(LogicalDatastoreType.OPERATIONAL, ncIdentifier, dataBroker).orNull();
}
public static boolean isNodePresent(DataBroker dataBroker, NodeConnectorId nodeConnectorId) {
NodeId nodeID = IfmUtil.getNodeIdFromNodeConnectorId(nodeConnectorId);
InstanceIdentifier<Node> nodeInstanceIdentifier = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, new NodeKey(nodeID)).build();
- Optional<Node> node = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, nodeInstanceIdentifier, dataBroker);
-
- if (node.isPresent()) {
- return true;
- }
- return false;
+ return IfmUtil.read(LogicalDatastoreType.OPERATIONAL, nodeInstanceIdentifier, dataBroker).isPresent();
}
public static InstanceIdentifier<Interface> getInterfaceIdentifier(InterfaceKey interfaceKey) {
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()) {
- return null;
- }
-
- return ifStateOptional.get();
+ return IfmUtil.read(LogicalDatastoreType.OPERATIONAL, ifStateId, dataBroker).orNull();
}
public static void makeTunnelIngressFlow(List<ListenableFuture<Void>> futures, IMdsalApiManager mdsalApiManager,
}
public static String getTunnelInterfaceFlowRef(BigInteger dpnId, short tableId, String ifName) {
- return new StringBuilder().append(dpnId).append(tableId).append(ifName).toString();
+ return String.valueOf(dpnId) + tableId + ifName;
}
public static void setOpStateForInterface(DataBroker broker, String interfaceName,
interfaceOperShardTransaction.put(LogicalDatastoreType.OPERATIONAL, ifStateId, ifaceBuilder.build(), true);
// install ingress flow
- BigInteger dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
+ BigInteger dpId = IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId);
long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
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) {
FlowBasedServicesUtils.installLportIngressFlow(dpId, portNo, interfaceInfo, futures, dataBroker, ifIndex);
FlowBasedServicesUtils.bindDefaultEgressDispatcherService(dataBroker, futures, interfaceInfo, Long.toString(portNo), interfaceName, ifIndex);
}
+
+ // Update the DpnToInterfaceList OpDS
+ createOrUpdateDpnToInterface(dpId, interfaceName,interfaceOperShardTransaction);
+ }
+
+ public static boolean checkIfBfdStateIsDown(String interfaceName){
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus =
+ InterfaceManagerCommonUtils.getBfdStateFromCache(interfaceName);
+ return (operStatus == org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Down);
}
public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface addStateEntry(
- Interface interfaceInfo, String interfaceName, WriteTransaction transaction, IdManagerService idManager,
+ DataBroker dataBroker, Interface interfaceInfo, String interfaceName, WriteTransaction transaction, IdManagerService idManager,
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,
InterfaceBuilder ifaceBuilder = new InterfaceBuilder();
Integer ifIndex = null;
if (interfaceInfo != null) {
- if (!interfaceInfo.isEnabled()) {
+ if(!interfaceInfo.isEnabled() || (InterfaceManagerCommonUtils.isTunnelInterface(interfaceInfo) &&
+ checkIfBfdStateIsDown(interfaceInfo.getName()))){
operStatus = 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 ifState = ifaceBuilder
.build();
transaction.put(LogicalDatastoreType.OPERATIONAL, ifStateId, ifState, true);
+
+ BigInteger dpId = IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId);
+ // Update the DpnToInterfaceList OpDS
+ createOrUpdateDpnToInterface(dpId, interfaceName, transaction);
return ifState;
}
.getInterfaceParentEntryFromConfigDS(interfaceParentEntryIdentifier, dataBroker);
if (interfaceParentEntry != null) {
- LOG.error("Trying to bind the same parent interface {} to multiple trunk interfaces. ", parentInterface);
+ if (!Objects.equals(parentInterface, interfaceParentEntry.getParentInterface())) {
+ LOG.error("Trying to bind the same parent interface {} to multiple trunk interfaces. ", parentInterface);
+ } else {
+ LOG.trace("Child entry for interface {} already exists", childInterface);
+ }
return false;
}
}
public static boolean isTunnelInterface(Interface interfaceInfo) {
- if (interfaceInfo != null && interfaceInfo.getAugmentation(IfTunnel.class) != null) {
- return true;
- }
- return false;
+ return interfaceInfo != null && interfaceInfo.getAugmentation(IfTunnel.class) != null;
}
public static boolean isVlanInterface(Interface interfaceInfo) {
- if (interfaceInfo != null && interfaceInfo.getAugmentation(IfL2vlan.class) != null) {
- return true;
- }
- return false;
+ return interfaceInfo != null && interfaceInfo.getAugmentation(IfL2vlan.class) != null;
}
// Cache Util methods
interfaceStateMap.remove(iface.getName());
}
+ public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus getBfdStateFromCache(String interfaceName) {
+ return bfdStateMap.get(interfaceName);
+ }
+
+ public static void addBfdStateToCache(String interfaceName,
+ org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus operStatus) {
+ bfdStateMap.put(interfaceName, operStatus);
+ }
+
+ public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus removeBfdStateFromCache(String interfaceName){
+ return bfdStateMap.remove(interfaceName);
+ }
+
public static boolean isNovaOrTunnelPort(String portName) {
Matcher matcher = pattern.matcher(portName);
return matcher.matches();
}
+
+ public static void createOrUpdateDpnToInterface(BigInteger dpId, String infName, WriteTransaction transaction) {
+ DpnToInterfaceKey dpnToInterfaceKey = new DpnToInterfaceKey(dpId);
+ InterfaceNameEntryKey interfaceNameEntryKey = new InterfaceNameEntryKey(infName);
+ InstanceIdentifier<InterfaceNameEntry> intfid = InstanceIdentifier.builder(DpnToInterfaceList.class)
+ .child(DpnToInterface.class, dpnToInterfaceKey)
+ .child(InterfaceNameEntry.class, interfaceNameEntryKey)
+ .build();
+ InterfaceNameEntryBuilder entryBuilder = new InterfaceNameEntryBuilder().setKey(interfaceNameEntryKey).setInterfaceName(infName);
+ transaction.put(LogicalDatastoreType.OPERATIONAL, intfid, entryBuilder.build(), true);
+ }
+
+ public static void deleteDpnToInterface(DataBroker dataBroker, BigInteger dpId, String infName, WriteTransaction transaction) {
+ DpnToInterfaceKey dpnToInterfaceKey = new DpnToInterfaceKey(dpId);
+ InstanceIdentifier<DpnToInterface> dpnToInterfaceId = InstanceIdentifier.builder(DpnToInterfaceList.class)
+ .child(DpnToInterface.class, dpnToInterfaceKey).build();
+ Optional<DpnToInterface> dpnToInterfaceOptional = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, dpnToInterfaceId, dataBroker);
+ if (!dpnToInterfaceOptional.isPresent()) {
+ LOG.debug("DPN {} is already removed from the Operational DS", dpId);
+ return;
+ }
+
+ List<InterfaceNameEntry> interfaceNameEntries = dpnToInterfaceOptional.get().getInterfaceNameEntry();
+ InterfaceNameEntryKey interfaceNameEntryKey = new InterfaceNameEntryKey(infName);
+ InstanceIdentifier<InterfaceNameEntry> intfid = InstanceIdentifier.builder(DpnToInterfaceList.class)
+ .child(DpnToInterface.class, dpnToInterfaceKey)
+ .child(InterfaceNameEntry.class, interfaceNameEntryKey)
+ .build();
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, intfid);
+
+ if (interfaceNameEntries.size() <=1) {
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, dpnToInterfaceId);
+ }
+ }
+
}