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.apache.commons.lang3.BooleanUtils;
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.genius.interfacemanager.IfmConstants;
import org.opendaylight.genius.interfacemanager.IfmUtil;
import org.opendaylight.genius.interfacemanager.globals.InterfaceInfo;
+import org.opendaylight.genius.interfacemanager.renderer.ovs.utilities.BatchingUtils;
import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.utilities.FlowBasedServicesUtils;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
import org.opendaylight.genius.mdsalutil.MDSALUtil;
import org.opendaylight.genius.mdsalutil.MatchFieldType;
import org.opendaylight.genius.mdsalutil.MatchInfo;
+import org.opendaylight.genius.mdsalutil.MatchInfoBase;
import org.opendaylight.genius.mdsalutil.MetaDataUtil;
import org.opendaylight.genius.mdsalutil.NwConstants;
+import org.opendaylight.genius.mdsalutil.NxMatchFieldType;
+import org.opendaylight.genius.mdsalutil.NxMatchInfo;
import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
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.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus;
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._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.DpnToInterfaceBuilder;
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;
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);
+ private static final String NOVA_PORT_REGEX = "(tap|vhu)[0-9a-f]{8}-[0-9a-f]{2}";
+ private static final String TUNNEL_PORT_REGEX = "tun[0-9a-f]{11}";
+
+ private static final Pattern novaOrTunnelPortPattern = Pattern.compile(NOVA_OR_TUNNEL_PORT_REGEX);
+ private static final Pattern tunnelPortPattern = Pattern.compile(TUNNEL_PORT_REGEX);
+ private static final Pattern novaPortPattern = Pattern.compile(NOVA_PORT_REGEX);
public static NodeConnector getNodeConnectorFromInventoryOperDS(NodeConnectorId nodeConnectorId,
DataBroker dataBroker) {
.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,
LOG.debug("make tunnel ingress flow for {}", interfaceName);
String flowRef = InterfaceManagerCommonUtils.getTunnelInterfaceFlowRef(dpnId,
NwConstants.VLAN_INTERFACE_INGRESS_TABLE, interfaceName);
- List<MatchInfo> matches = new ArrayList<>();
+ List<MatchInfoBase> matches = new ArrayList<>();
List<InstructionInfo> mkInstructions = new ArrayList<>();
if (NwConstants.ADD_FLOW == addOrRemoveFlow) {
matches.add(new MatchInfo(MatchFieldType.in_port, new BigInteger[] { dpnId, BigInteger.valueOf(portNo) }));
+ if(BooleanUtils.isTrue(tunnel.isTunnelRemoteIpFlow())) {
+ matches.add(new NxMatchInfo(NxMatchFieldType.tun_src_ip,
+ new String[] { tunnel.getTunnelDestination().getIpv4Address().getValue() }));
+ }
+ if(BooleanUtils.isTrue(tunnel.isTunnelSourceIpFlow())) {
+ matches.add(new NxMatchInfo(NxMatchFieldType.tun_dst_ip,
+ new String[] { tunnel.getTunnelSource().getIpv4Address().getValue() }));
+ }
+
mkInstructions.add(new InstructionInfo(InstructionType.write_metadata,
new BigInteger[] { MetaDataUtil.getLportTagMetaData(ifIndex).or(BigInteger.ONE),
MetaDataUtil.METADATA_MASK_LPORT_TAG_SH_FLAG }));
- short tableId = (tunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeMplsOverGre.class))
+ short tableId = tunnel.getTunnelInterfaceType().isAssignableFrom(TunnelTypeMplsOverGre.class)
? NwConstants.L3_LFIB_TABLE
: tunnel.isInternal() ? NwConstants.INTERNAL_TUNNEL_TABLE : NwConstants.DHCP_TABLE_EXTERNAL_TUNNEL;
mkInstructions.add(new InstructionInfo(InstructionType.goto_table, new long[] { tableId }));
}
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,
MDSALUtil.syncUpdate(broker, LogicalDatastoreType.OPERATIONAL, interfaceId, interfaceData);
}
- public static void createInterfaceChildEntry(WriteTransaction t, String parentInterface, String childInterface) {
+ public static void createInterfaceChildEntry(String parentInterface, String childInterface) {
InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(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);
+ BatchingUtils.write(intfId, entryBuilder.build(), BatchingUtils.EntityType.DEFAULT_CONFIG);
+ }
+
+ public static void deleteInterfaceChildEntry(String parentInterface, String childInterface) {
+ InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
+ InterfaceChildEntryKey interfaceChildEntryKey = new InterfaceChildEntryKey(childInterface);
+ InstanceIdentifier<InterfaceChildEntry> intfId = InterfaceMetaUtils
+ .getInterfaceChildEntryIdentifier(interfaceParentEntryKey, interfaceChildEntryKey);
+ BatchingUtils.delete(intfId, BatchingUtils.EntityType.DEFAULT_CONFIG);
}
public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus updateStateEntry(
// install ingress flow
BigInteger dpId = IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId);
- long portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
+ long portNo = IfmUtil.getPortNumberFromNodeConnectorId(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);
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);
+ 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(
- 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,
- NodeConnectorId nodeConnectorId) {
+ Interface interfaceInfo, String interfaceName, WriteTransaction transaction, IdManagerService idManager,
+ PhysAddress physAddress, OperStatus operStatus, AdminStatus adminStatus, NodeConnectorId nodeConnectorId) {
LOG.debug("adding interface state for {}", interfaceName);
InterfaceBuilder ifaceBuilder = new InterfaceBuilder();
- Integer ifIndex = null;
+ Integer ifIndex;
if (interfaceInfo != null) {
- if(!interfaceInfo.isEnabled() || (InterfaceManagerCommonUtils.isTunnelInterface(interfaceInfo) &&
- checkIfBfdStateIsDown(interfaceInfo.getName()))){
+ 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;
}
return true;
}
- public static boolean deleteParentInterfaceEntry(WriteTransaction t, String parentInterface) {
+ public static boolean deleteParentInterfaceEntry(String parentInterface) {
+ if(parentInterface == null) {
+ return false;
+ }
InterfaceParentEntryKey interfaceParentEntryKey = new InterfaceParentEntryKey(parentInterface);
InstanceIdentifier<InterfaceParentEntry> interfaceParentEntryIdentifier = InterfaceMetaUtils
.getInterfaceParentEntryIdentifier(interfaceParentEntryKey);
- t.delete(LogicalDatastoreType.CONFIGURATION, interfaceParentEntryIdentifier);
+ BatchingUtils.delete(interfaceParentEntryIdentifier, BatchingUtils.EntityType.DEFAULT_CONFIG);
return true;
}
}
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
}
public static boolean isNovaOrTunnelPort(String portName) {
+ Matcher matcher = novaOrTunnelPortPattern.matcher(portName);
+ return matcher.matches();
+ }
+
+ public static boolean isNovaPort(String portName){
+ Matcher matcher = novaPortPattern.matcher(portName);
+ return matcher.matches();
+ }
- Matcher matcher = pattern.matcher(portName);
+ public static boolean isTunnelPort(String portName){
+ Matcher matcher = tunnelPortPattern.matcher(portName);
return matcher.matches();
}