import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+
import org.apache.commons.lang3.StringUtils;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.genius.interfacemanager.globals.InterfaceServiceUtil;
import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
import org.opendaylight.genius.itm.globals.ITMConstants;
+import org.opendaylight.genius.mdsalutil.ActionInfo;
+import org.opendaylight.genius.mdsalutil.ActionType;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.InstructionInfo;
import org.opendaylight.genius.mdsalutil.InstructionType;
import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
import org.opendaylight.genius.utils.ServiceIndex;
import org.opendaylight.netvirt.elan.ElanException;
-import org.opendaylight.netvirt.elan.internal.ElanBridgeManager;
import org.opendaylight.netvirt.elan.internal.ElanInstanceManager;
import org.opendaylight.netvirt.elan.internal.ElanInterfaceManager;
import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayMulticastUtils;
import org.opendaylight.netvirt.elan.l2gw.utils.ElanL2GatewayUtils;
import org.opendaylight.netvirt.elan.l2gw.utils.L2GatewayConnectionUtils;
-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.InterfacesState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
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.opendaylight.genius.interfacemanager.meta.rev160406.IfIndexesInterfaceMap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfExternal;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeVxlan;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetDpidFromInterfaceInputBuilder;
private final ElanInstanceManager elanInstanceManager;
private final OdlInterfaceRpcService interfaceManagerRpcService;
private final ItmRpcService itmRpcService;
- private ElanL2GatewayUtils elanL2GatewayUtils;
- private ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
- private L2GatewayConnectionUtils l2GatewayConnectionUtils;
- private ElanBridgeManager bridgeManager;
+ private final ElanL2GatewayUtils elanL2GatewayUtils;
+ private final ElanL2GatewayMulticastUtils elanL2GatewayMulticastUtils;
+ private final L2GatewayConnectionUtils l2GatewayConnectionUtils;
+ private final IInterfaceManager interfaceManager;
public static final FutureCallback<Void> DEFAULT_CALLBACK = new FutureCallback<Void>() {
@Override
public ElanUtils(DataBroker dataBroker, IMdsalApiManager mdsalManager, ElanInstanceManager elanInstanceManager,
OdlInterfaceRpcService interfaceManagerRpcService, ItmRpcService itmRpcService,
ElanInterfaceManager elanInterfaceManager,
- EntityOwnershipService entityOwnershipService, ElanBridgeManager bridgeManager) {
+ EntityOwnershipService entityOwnershipService, IInterfaceManager interfaceManager) {
this.broker = dataBroker;
this.mdsalManager = mdsalManager;
this.elanInstanceManager = elanInstanceManager;
this.interfaceManagerRpcService = interfaceManagerRpcService;
this.itmRpcService = itmRpcService;
- this.bridgeManager = bridgeManager;
+ this.interfaceManager = interfaceManager;
elanL2GatewayMulticastUtils =
new ElanL2GatewayMulticastUtils(broker, elanInstanceManager, elanInterfaceManager, this);
elanL2GatewayUtils = new ElanL2GatewayUtils(broker, itmRpcService, this,
entityOwnershipService, elanL2GatewayMulticastUtils);
+ elanL2GatewayMulticastUtils.setEElanL2GatewayUtils(elanL2GatewayUtils);
l2GatewayConnectionUtils = new L2GatewayConnectionUtils(broker,
elanInstanceManager, entityOwnershipService, this);
}
return elanInstanceLocalCache.get(elanInstanceName);
}
+ public static Set<String> getAllElanNames() {
+ return elanInstanceLocalCache.keySet();
+ }
+
public static void addElanInterfaceIntoCache(String interfaceName, ElanInterface elanInterface) {
elanInterfaceLocalCache.put(interfaceName, elanInterface);
}
return elanObj;
}
InstanceIdentifier<ElanInstance> elanIdentifierId = getElanInstanceConfigurationDataPath(elanInstanceName);
- Optional<ElanInstance> elanInstance = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION,
- elanIdentifierId);
- if (elanInstance.isPresent()) {
- return elanInstance.get();
- }
- return null;
+ return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, elanIdentifierId).orNull();
}
public static InstanceIdentifier<ElanInstance> getElanInstanceConfigurationDataPath(String elanInstanceName) {
return elanInterfaceObj;
}
InstanceIdentifier<ElanInterface> elanInterfaceId = getElanInterfaceConfigurationDataPathId(elanInterfaceName);
- Optional<ElanInterface> existingElanInterface = MDSALUtil.read(broker,
- LogicalDatastoreType.CONFIGURATION, elanInterfaceId);
- if (existingElanInterface.isPresent()) {
- return existingElanInterface.get();
- }
- return null;
+ return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, elanInterfaceId).orNull();
}
public static EtreeInterface getEtreeInterfaceByElanInterfaceName(DataBroker broker, String elanInterfaceName) {
// elan-state Operational container
public static Elan getElanByName(DataBroker broker, String elanInstanceName) {
InstanceIdentifier<Elan> elanIdentifier = getElanInstanceOperationalDataPath(elanInstanceName);
- Optional<Elan> elanInstance = MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL,
- elanIdentifier);
- if (elanInstance.isPresent()) {
- return elanInstance.get();
- }
- return null;
+ return MDSALUtil.read(broker, LogicalDatastoreType.OPERATIONAL, elanIdentifier).orNull();
}
public static InstanceIdentifier<Elan> getElanInstanceOperationalDataPath(String elanInstanceName) {
public MacEntry getInterfaceMacEntriesOperationalDataPath(String interfaceName, PhysAddress physAddress) {
InstanceIdentifier<MacEntry> existingMacEntryId = getInterfaceMacEntriesIdentifierOperationalDataPath(
interfaceName, physAddress);
- Optional<MacEntry> existingInterfaceMacEntry = read(broker,
- LogicalDatastoreType.OPERATIONAL, existingMacEntryId);
- if (existingInterfaceMacEntry.isPresent()) {
- return existingInterfaceMacEntry.get();
- }
- return null;
+ return read(broker, LogicalDatastoreType.OPERATIONAL, existingMacEntryId).orNull();
}
public MacEntry getInterfaceMacEntriesOperationalDataPathFromId(InstanceIdentifier identifier) {
Optional<MacEntry> existingInterfaceMacEntry = read(broker,
LogicalDatastoreType.OPERATIONAL, identifier);
- if (existingInterfaceMacEntry.isPresent()) {
- return existingInterfaceMacEntry.get();
- }
- return null;
+ return existingInterfaceMacEntry.orNull();
}
public static InstanceIdentifier<MacEntry> getInterfaceMacEntriesIdentifierOperationalDataPath(String interfaceName,
}
// elan-forwarding-tables Operational container
- public MacEntry getMacTableByElanName(String elanName, PhysAddress physAddress) {
+ public Optional<MacEntry> getMacEntryForElanInstance(String elanName, PhysAddress physAddress) {
InstanceIdentifier<MacEntry> macId = getMacEntryOperationalDataPath(elanName, physAddress);
- Optional<MacEntry> existingElanMacEntry = read(broker,
- LogicalDatastoreType.OPERATIONAL, macId);
- if (existingElanMacEntry.isPresent()) {
- return existingElanMacEntry.get();
- }
- return null;
+ return read(broker, LogicalDatastoreType.OPERATIONAL, macId);
}
public MacEntry getMacEntryFromElanMacId(InstanceIdentifier identifier) {
Optional<MacEntry> existingInterfaceMacEntry = read(broker,
LogicalDatastoreType.OPERATIONAL, identifier);
- if (existingInterfaceMacEntry.isPresent()) {
- return existingInterfaceMacEntry.get();
- }
- return null;
+ return existingInterfaceMacEntry.orNull();
}
public static InstanceIdentifier<MacEntry> getMacEntryOperationalDataPath(String elanName,
public ElanInterfaceMac getElanInterfaceMacByInterfaceName(String interfaceName) {
InstanceIdentifier<ElanInterfaceMac> elanInterfaceId = getElanInterfaceMacEntriesOperationalDataPath(
interfaceName);
- Optional<ElanInterfaceMac> existingElanInterface = read(broker,
- LogicalDatastoreType.OPERATIONAL, elanInterfaceId);
- if (existingElanInterface.isPresent()) {
- return existingElanInterface.get();
- }
- return null;
+ return read(broker, LogicalDatastoreType.OPERATIONAL, elanInterfaceId).orNull();
}
/**
public DpnInterfaces getElanInterfaceInfoByElanDpn(String elanInstanceName, BigInteger dpId) {
InstanceIdentifier<DpnInterfaces> elanDpnInterfacesId = getElanDpnInterfaceOperationalDataPath(elanInstanceName,
dpId);
- Optional<DpnInterfaces> elanDpnInterfaces = read(broker,
- LogicalDatastoreType.OPERATIONAL, elanDpnInterfacesId);
- if (elanDpnInterfaces.isPresent()) {
- return elanDpnInterfaces.get();
- }
- return null;
+ return read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfacesId).orNull();
}
/**
InstanceIdentifier<ElanTagName> elanId = getElanInfoEntriesOperationalDataPath(elanTag);
Optional<ElanTagName> existingElanInfo = read(broker,
LogicalDatastoreType.OPERATIONAL, elanId);
- if (existingElanInfo.isPresent()) {
- return existingElanInfo.get();
- }
- return null;
+ return existingElanInfo.orNull();
}
public EtreeLeafTagName getEtreeLeafTagByElanTag(long elanTag) {
LogicalDatastoreType.OPERATIONAL, elanId);
if (existingElanInfo.isPresent()) {
ElanTagName elanTagName = existingElanInfo.get();
- EtreeLeafTagName etreeAugmentation = elanTagName.getAugmentation(EtreeLeafTagName.class);
- return etreeAugmentation;
+ return elanTagName.getAugmentation(EtreeLeafTagName.class);
}
return null;
}
public ElanDpnInterfacesList getElanDpnInterfacesList(String elanName) {
InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanName);
- Optional<ElanDpnInterfacesList> existingElanDpnInterfaces = read(broker,
- LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
- if (existingElanDpnInterfaces.isPresent()) {
- return existingElanDpnInterfaces.get();
- }
- return null;
+ return read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId).orNull();
}
public ElanDpnInterfaces getElanDpnInterfacesList() {
InstanceIdentifier<ElanDpnInterfaces> elanDpnInterfaceId = InstanceIdentifier.builder(ElanDpnInterfaces.class)
.build();
- Optional<ElanDpnInterfaces> existingElanDpnInterfaces = read(broker,
- LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
- if (existingElanDpnInterfaces.isPresent()) {
- return existingElanDpnInterfaces.get();
- }
- return null;
+ return read(broker, LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId).orNull();
}
/**
* the elan instance name
* @return list of dpIds
*/
- public List<BigInteger> getParticipatingDPNsInElanInstance(String elanInstanceName) {
+ public List<BigInteger> getParticipatingDpnsInElanInstance(String elanInstanceName) {
List<BigInteger> dpIds = new ArrayList<>();
InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanInstanceName);
Optional<ElanDpnInterfacesList> existingElanDpnInterfaces = read(broker,
* @return true if dpId is already present, otherwise return false
*/
public boolean isDpnAlreadyPresentInElanInstance(BigInteger dpId, String elanInstanceName) {
- boolean isDpIdPresent = false;
InstanceIdentifier<ElanDpnInterfacesList> elanDpnInterfaceId = getElanDpnOperationDataPath(elanInstanceName);
Optional<ElanDpnInterfacesList> existingElanDpnInterfaces = read(broker,
LogicalDatastoreType.OPERATIONAL, elanDpnInterfaceId);
if (!existingElanDpnInterfaces.isPresent()) {
- return isDpIdPresent;
+ return false;
}
List<DpnInterfaces> dpnInterfaces = existingElanDpnInterfaces.get().getDpnInterfaces();
for (DpnInterfaces dpnInterface : dpnInterfaces) {
if (dpnInterface.getDpId().equals(dpId)) {
- isDpIdPresent = true;
- break;
+ return true;
}
}
- return isDpIdPresent;
+ return false;
}
public ElanForwardingTables getElanForwardingList() {
InstanceIdentifier<ElanForwardingTables> elanForwardingTableId = InstanceIdentifier
.builder(ElanForwardingTables.class).build();
- Optional<ElanForwardingTables> existingElanForwardingList = read(broker,
- LogicalDatastoreType.OPERATIONAL, elanForwardingTableId);
- if (existingElanForwardingList.isPresent()) {
- return existingElanForwardingList.get();
- }
- return null;
+ return read(broker, LogicalDatastoreType.OPERATIONAL, elanForwardingTableId).orNull();
+ }
+
+ public static long getElanRemoteBroadCastGroupID(long elanTag) {
+ return ElanConstants.ELAN_GID_MIN + (((elanTag % ElanConstants.ELAN_GID_MIN) * 2));
}
/**
*/
public MacTable getElanMacTable(String elanName) {
InstanceIdentifier<MacTable> elanMacTableId = getElanMacTableOperationalDataPath(elanName);
- Optional<MacTable> existingElanMacTable = read(broker,
- LogicalDatastoreType.OPERATIONAL, elanMacTableId);
- if (existingElanMacTable.isPresent()) {
- return existingElanMacTable.get();
- }
- return null;
+ return read(broker, LogicalDatastoreType.OPERATIONAL, elanMacTableId).orNull();
}
public static long getElanLocalBCGId(long elanTag) {
* the flow group tx
* @throws ElanException in case of issues creating the flow objects
*/
- public void setupMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, long macTimeout,
- String macAddress, boolean configureRemoteFlows, WriteTransaction writeFlowGroupTx) throws ElanException {
- synchronized (macAddress) {
- LOG.debug("Acquired lock for mac : " + macAddress + ". Proceeding with install operation.");
+ public void setupMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo,
+ long macTimeout, String macAddress, boolean configureRemoteFlows,
+ WriteTransaction writeFlowGroupTx) throws ElanException {
+ synchronized (getElanMacKey(elanInfo.getElanTag(), macAddress)) {
setupKnownSmacFlow(elanInfo, interfaceInfo, macTimeout, macAddress, mdsalManager,
- writeFlowGroupTx);
+ writeFlowGroupTx);
setupOrigDmacFlows(elanInfo, interfaceInfo, macAddress, configureRemoteFlows, mdsalManager,
- broker, writeFlowGroupTx);
+ broker, writeFlowGroupTx);
}
}
- /**
- * Setting INTERNAL_TUNNEL_TABLE, SMAC, DMAC, UDMAC in this DPN and on other DPNs.
- *
- * @param elanInfo
- * the elan info
- * @param interfaceInfo
- * the interface info
- * @param macTimeout
- * the mac timeout
- * @param macAddress
- * the mac address
- * @param writeFlowGroupTx
- * the flow group tx
- * @throws ElanException in case of issues creating the flow objects
- */
- public void setupMacFlows(ElanInstance elanInfo, InterfaceInfo interfaceInfo, long macTimeout,
- String macAddress, WriteTransaction writeFlowGroupTx) throws ElanException {
- setupMacFlows(elanInfo, interfaceInfo, macTimeout, macAddress, true, writeFlowGroupTx);
- }
-
public void setupDMacFlowonRemoteDpn(ElanInstance elanInfo, InterfaceInfo interfaceInfo, BigInteger dstDpId,
String macAddress, WriteTransaction writeFlowTx) throws ElanException {
- synchronized (macAddress) {
+ synchronized (getElanMacKey(elanInfo.getElanTag(), macAddress)) {
LOG.debug("Acquired lock for mac : " + macAddress + ". Proceeding with install operation.");
setupOrigDmacFlowsonRemoteDpn(elanInfo, interfaceInfo, dstDpId, macAddress, writeFlowTx);
}
String macAddress, IMdsalApiManager mdsalApiManager, WriteTransaction writeFlowGroupTx) {
FlowEntity flowEntity = buildKnownSmacFlow(elanInfo, interfaceInfo, macTimeout, macAddress);
mdsalApiManager.addFlowToTx(flowEntity, writeFlowGroupTx);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Known Smac flow entry created for elan Name:{}, logical Interface port:{} and mac address:{}",
- elanInfo.getElanInstanceName(), elanInfo.getDescription(), macAddress);
- }
+ LOG.debug("Known Smac flow entry created for elan Name:{}, logical Interface port:{} and mac address:{}",
+ elanInfo.getElanInstanceName(), elanInfo.getDescription(), macAddress);
}
public FlowEntity buildKnownSmacFlow(ElanInstance elanInfo, InterfaceInfo interfaceInfo, long macTimeout,
} else { // Leaf
EtreeInstance etreeInstance = elanInfo.getAugmentation(EtreeInstance.class);
if (etreeInstance == null) {
- LOG.warn("EtreeInterface " + interfaceInfo.getInterfaceName() + " is connected to a non-Etree network: "
- + elanInfo.getElanInstanceName());
+ LOG.warn("EtreeInterface {} is connected to a non-Etree network: {}",
+ interfaceInfo.getInterfaceName(), elanInfo.getElanInstanceName());
return elanInfo.getElanTag();
} else {
return etreeInstance.getEtreeLeafTagVal().getValue();
getTunnelIdMatchForFilterEqualsLPortTag(lportTag),
getInstructionsInPortForOutGroup(interfaceInfo.getInterfaceName()));
mdsalApiManager.addFlowToTx(dpId, flow, writeFlowGroupTx);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Terminating service table flow entry created on dpn:{} for logical Interface port:{}", dpId,
- interfaceInfo.getPortName());
- }
+ LOG.debug("Terminating service table flow entry created on dpn:{} for logical Interface port:{}", dpId,
+ interfaceInfo.getPortName());
}
/**
// Check for the Remote DPN present in Inventory Manager
setupRemoteDmacFlow(dstDpId, dpId, interfaceInfo.getInterfaceTag(), elanTag, macAddress,
elanInstanceName, writeFlowTx, interfaceInfo.getInterfaceName(), elanInfo);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Dmac flow entry created for elan Name:{}, logical port Name:{} and mac address {} on"
- + " dpn:{}", elanInstanceName, interfaceInfo.getPortName(), macAddress, remoteFE.getDpId());
- }
+ LOG.debug("Dmac flow entry created for elan Name:{}, logical port Name:{} and mac address {} on dpn:{}",
+ elanInstanceName, interfaceInfo.getPortName(), macAddress, remoteFE.getDpId());
break;
}
}
if (etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
EtreeLeafTagName etreeTagName = getEtreeLeafTagByElanTag(elanTag);
if (etreeTagName == null) {
- LOG.warn("Interface " + ifName + " seems like it belongs to Etree but etreeTagName from elanTag "
- + elanTag + " is null.");
+ LOG.warn("Interface {} seems like it belongs to Etree but etreeTagName from elanTag {} is null",
+ ifName, elanTag);
} else {
Flow flowEntity = buildLocalDmacFlowEntry(etreeTagName.getEtreeLeafTag().getValue(), dpId, ifName,
macAddress, displayName, ifTag);
.toString();
}
+ public static String getKnownDynamicmacFlowRef(short tableId, BigInteger dpId, String macAddress, long elanTag) {
+ return new StringBuffer().append(tableId).append(elanTag).append(dpId).append(macAddress).toString();
+ }
+
private static String getKnownDynamicmacFlowRef(short elanDmacTable, BigInteger dpId, String extDeviceNodeId,
String dstMacAddress, long elanTag, boolean shFlag) {
return new StringBuffer().append(elanDmacTable).append(elanTag).append(dpId).append(extDeviceNodeId)
return;
}
String macAddress = macEntry.getMacAddress().getValue();
- synchronized (macAddress) {
- LOG.debug("Acquired lock for mac : " + macAddress + ". Proceeding with remove operation.");
+ synchronized (getElanMacKey(elanInfo.getElanTag(), macAddress)) {
deleteMacFlows(elanInfo, interfaceInfo, macAddress, /* alsoDeleteSMAC */ true, deleteFlowGroupTx);
}
}
MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE, getKnownDynamicmacFlowRef(
NwConstants.ELAN_DMAC_TABLE, dstDpId, srcdpId, macAddress, elanTag)),
deleteFlowGroupTx);
- if (LOG.isDebugEnabled()) {
- LOG.debug("Dmac flow entry deleted for elan:{}, logical interface port:{} and mac address:{} on dpn:{}",
- elanInstanceName, interfaceInfo.getPortName(), macAddress, dstDpId);
- }
+ LOG.debug("Dmac flow entry deleted for elan:{}, logical interface port:{} and mac address:{} on dpn:{}",
+ elanInstanceName, interfaceInfo.getPortName(), macAddress, dstDpId);
}
return isFlowsRemovedInSrcDpn;
}
MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE,
getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, srcdpId, ifTag, macAddress, elanTag)),
deleteFlowGroupTx);
- if (LOG.isDebugEnabled()) {
- LOG.debug("All the required flows deleted for elan:{}, logical Interface port:{} and MAC address:{} "
- + "on dpn:{}", elanInstanceName, interfaceInfo.getPortName(), macAddress, srcdpId);
- }
+ LOG.debug("All the required flows deleted for elan:{}, logical Interface port:{} and MAC address:{} on dpn:{}",
+ elanInstanceName, interfaceInfo.getPortName(), macAddress, srcdpId);
}
/**
InstanceIdentifier<Node> node = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(nodeId))
.build();
- Optional<Node> nodePresent = read(broker, LogicalDatastoreType.OPERATIONAL, node);
- return nodePresent.isPresent();
+ return read(broker, LogicalDatastoreType.OPERATIONAL, node).isPresent();
}
public static ServicesInfo getServiceInfo(String elanInstanceName, long elanTag, String interfaceName) {
if (output.get().isSuccessful()) {
GetExternalTunnelInterfaceNameOutput tunnelInterfaceNameOutput = output.get().getResult();
String tunnelIfaceName = tunnelInterfaceNameOutput.getInterfaceName();
- if (LOG.isDebugEnabled()) {
- LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
- }
+ LOG.debug("Received tunnelInterfaceName from getTunnelInterfaceName RPC {}", tunnelIfaceName);
result = buildTunnelItmEgressActions(tunnelIfaceName, vni);
}
public static TunnelList buildInternalTunnel(DataBroker broker) {
InstanceIdentifier<TunnelList> tunnelListInstanceIdentifier = InstanceIdentifier.builder(TunnelList.class)
.build();
- Optional<TunnelList> tunnelList = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION,
- tunnelListInstanceIdentifier);
- if (tunnelList.isPresent()) {
- return tunnelList.get();
- }
- return null;
+ return MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, tunnelListInstanceIdentifier).orNull();
}
/**
*/
public ExternalTunnel getExternalTunnel(String sourceDevice, String destinationDevice,
LogicalDatastoreType datastoreType) {
- ExternalTunnel externalTunnel = null;
Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
InstanceIdentifier<ExternalTunnel> iid = InstanceIdentifier.builder(ExternalTunnelList.class)
.child(ExternalTunnel.class, new ExternalTunnelKey(destinationDevice, sourceDevice, tunType)).build();
- Optional<ExternalTunnel> tunnelList = read(broker, datastoreType, iid);
- if (tunnelList.isPresent()) {
- externalTunnel = tunnelList.get();
- }
- return externalTunnel;
+ return read(broker, datastoreType, iid).orNull();
}
/**
* @return the all external tunnels
*/
public List<ExternalTunnel> getAllExternalTunnels(LogicalDatastoreType datastoreType) {
- List<ExternalTunnel> result = null;
InstanceIdentifier<ExternalTunnelList> iid = InstanceIdentifier.builder(ExternalTunnelList.class).build();
- Optional<ExternalTunnelList> tunnelList = read(broker, datastoreType, iid);
- if (tunnelList.isPresent()) {
- result = tunnelList.get().getExternalTunnel();
- }
- if (result == null) {
- result = Collections.emptyList();
- }
- return result;
+ return read(broker, datastoreType, iid).transform(ExternalTunnelList::getExternalTunnel).or(
+ Collections.emptyList());
}
/**
* the display name
* @throws ElanException in case of issues creating the flow objects
*/
- public void installDmacFlowsToInternalRemoteMac(BigInteger localDpId, BigInteger remoteDpId, long lportTag,
+ public void installDmacFlowsToInternalRemoteMac(BigInteger localDpId, BigInteger remoteDpId, int lportTag,
long elanTag, String macAddress, String displayName) throws ElanException {
Flow flow = buildDmacFlowForInternalRemoteMac(localDpId, remoteDpId, lportTag, elanTag, macAddress,
displayName);
String extDeviceNodeId, Long elanTag, Long vni, String macAddress, String displayName,
String interfaceName) throws ElanException {
List<ListenableFuture<Void>> futures = new ArrayList<>();
- synchronized (macAddress) {
+ synchronized (getElanMacKey(elanTag, macAddress)) {
Flow flow = buildDmacFlowForExternalRemoteMac(dpnId, extDeviceNodeId, elanTag, vni, macAddress,
displayName);
futures.add(mdsalManager.installFlow(dpnId, flow));
* @throws ElanException in case of issues creating the flow objects
*/
@SuppressWarnings("checkstyle:IllegalCatch")
- public Flow buildDmacFlowForInternalRemoteMac(BigInteger localDpId, BigInteger remoteDpId, long lportTag,
+ public Flow buildDmacFlowForInternalRemoteMac(BigInteger localDpId, BigInteger remoteDpId, int lportTag,
long elanTag, String macAddress, String displayName) throws ElanException {
List<MatchInfo> mkMatches = buildMatchesForElanTagShFlagAndDstMac(elanTag, /* shFlag */ false, macAddress);
public List<ListenableFuture<Void>> deleteDmacFlowsToExternalMac(long elanTag, BigInteger dpId,
String extDeviceNodeId, String macToRemove) {
List<ListenableFuture<Void>> futures = new ArrayList<>();
- synchronized (macToRemove) {
+ synchronized (getElanMacKey(elanTag, macToRemove)) {
// Removing the flows that sends the packet on an external tunnel
removeFlowThatSendsThePacketOnAnExternalTunnel(elanTag, dpId, extDeviceNodeId, macToRemove, futures);
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
.ietf.interfaces.rev140508.interfaces.state.Interface> ifStateId = createInterfaceStateInstanceIdentifier(
interfaceName);
- Optional<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.interfaces.rev140508.interfaces.state.Interface> ifStateOptional = MDSALUtil
- .read(dataBroker, LogicalDatastoreType.OPERATIONAL, ifStateId);
- if (ifStateOptional.isPresent()) {
- return ifStateOptional.get();
- }
- return null;
- }
-
- /**
- * Gets the interface from config ds.
- *
- * @param interfaceName
- * the interface name
- * @param dataBroker
- * the data broker
- * @return the interface from config ds
- */
- public static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.interfaces.rev140508.interfaces.Interface getInterfaceFromConfigDS(
- String interfaceName, DataBroker dataBroker) {
- InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.interfaces.rev140508.interfaces.Interface> ifaceId = createInterfaceInstanceIdentifier(interfaceName);
- Optional<org.opendaylight.yang.gen.v1.urn
- .ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface> iface = MDSALUtil
- .read(dataBroker, LogicalDatastoreType.CONFIGURATION, ifaceId);
- if (iface.isPresent()) {
- return iface.get();
- }
- return null;
+ return MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, ifStateId).orNull();
}
/**
return idBuilder.build();
}
- /**
- * Creates the interface instance identifier.
- *
- * @param interfaceName
- * the interface name
- * @return the instance identifier
- */
- public static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.interfaces.rev140508.interfaces.Interface> createInterfaceInstanceIdentifier(
- String interfaceName) {
- InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.interfaces.rev140508.interfaces.Interface> idBuilder = InstanceIdentifier
- .builder(Interfaces.class)
- .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.interfaces.rev140508.interfaces.Interface.class,
- new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.interfaces.rev140508.interfaces.InterfaceKey(
- interfaceName));
- return idBuilder.build();
- }
-
public static CheckedFuture<Void, TransactionCommitFailedException> waitForTransactionToComplete(
WriteTransaction tx) {
CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit();
&& elanInstance.getSegmentType().isAssignableFrom(SegmentTypeFlat.class);
}
- public boolean isExternal(String interfaceName) {
- return isExternal(getInterfaceFromConfigDS(interfaceName, broker));
- }
-
- public static boolean isExternal(
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.interfaces.rev140508.interfaces.Interface iface) {
- if (iface == null) {
- return false;
- }
-
- IfExternal ifExternal = iface.getAugmentation(IfExternal.class);
- return ifExternal != null && Boolean.TRUE.equals(ifExternal.isExternal());
- }
-
public static boolean isEtreeRootInterfaceByInterfaceName(DataBroker broker, String interfaceName) {
EtreeInterface etreeInterface = getEtreeInterfaceByElanInterfaceName(broker, interfaceName);
if (etreeInterface != null && etreeInterface.getEtreeInterfaceType() == EtreeInterfaceType.Root) {
return false;
}
+ public void handleDmacRedirectToDispatcherFlows(Long elanTag, String displayName,
+ String macAddress, int addOrRemove, List<BigInteger> dpnIds) {
+ for (BigInteger dpId : dpnIds) {
+ if (addOrRemove == NwConstants.ADD_FLOW) {
+ WriteTransaction writeTx = broker.newWriteOnlyTransaction();
+ mdsalManager.addFlowToTx(buildDmacRedirectToDispatcherFlow(dpId, macAddress, displayName, elanTag),
+ writeTx);
+ writeTx.submit();
+ } else {
+ String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, macAddress, elanTag);
+ mdsalManager.removeFlow(dpId, MDSALUtil.buildFlow(NwConstants.ELAN_DMAC_TABLE, flowId));
+ }
+ }
+ }
+
+ public static FlowEntity buildDmacRedirectToDispatcherFlow(BigInteger dpId, String dstMacAddress,
+ String displayName, long elanTag) {
+ List<MatchInfo> matches = new ArrayList<MatchInfo>();
+ matches.add(new MatchInfo(MatchFieldType.metadata,
+ new BigInteger[] { getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE }));
+ matches.add(new MatchInfo(MatchFieldType.eth_dst, new String[] { dstMacAddress }));
+ List<InstructionInfo> instructions = new ArrayList<InstructionInfo>();
+ List<ActionInfo> actions = new ArrayList<ActionInfo>();
+ actions.add(new ActionInfo(ActionType.nx_resubmit,
+ new String[] { String.valueOf(NwConstants.LPORT_DISPATCHER_TABLE) }));
+
+ instructions.add(new InstructionInfo(InstructionType.apply_actions, actions));
+ String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, dstMacAddress, elanTag);
+ FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 20, displayName, 0, 0,
+ ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)),
+ matches, instructions);
+ return flow;
+ }
+
+ public static FlowEntity buildDmacRedirectToDispatcherFlowMacNoActions(BigInteger dpId, String dstMacAddress,
+ String displayName, long elanTag) {
+ List<MatchInfo> matches = new ArrayList<MatchInfo>();
+ matches.add(new MatchInfo(MatchFieldType.metadata,
+ new BigInteger[] { getElanMetadataLabel(elanTag), MetaDataUtil.METADATA_MASK_SERVICE }));
+ matches.add(new MatchInfo(MatchFieldType.eth_dst, new String[] { dstMacAddress }));
+
+ String flowId = getKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, dstMacAddress, elanTag);
+ FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 20, displayName, 0, 0,
+ ElanConstants.COOKIE_ELAN_KNOWN_DMAC.add(BigInteger.valueOf(elanTag)),
+ matches, new ArrayList<InstructionInfo>());
+ return flow;
+ }
+
/**
* Add Mac Address to ElanInterfaceForwardingEntries and ElanForwardingTables
* Install SMAC and DMAC flows.
InstanceIdentifier<MacEntry> elanMacEntryId = ElanUtils.getMacEntryOperationalDataPath(elanName, physAddress);
tx.put(LogicalDatastoreType.OPERATIONAL, elanMacEntryId, macEntry);
ElanInstance elanInstance = ElanUtils.getElanInstanceByName(broker, elanName);
- setupMacFlows(elanInstance, interfaceManager.getInterfaceInfo(interfaceName), macTimeOut, macAddress,
+ setupMacFlows(elanInstance, interfaceManager.getInterfaceInfo(interfaceName), macTimeOut, macAddress, true,
flowWritetx);
}
}
for (String dpnInterface : dpnInterfaces.getInterfaces()) {
- if (isExternal(dpnInterface)) {
+ if (interfaceManager.isExternalInterface(dpnInterface)) {
return dpnInterface;
}
}
LOG.trace("Elan {} does not have any external interace attached to DPN {}", elanInstanceName, dpnId);
return null;
}
+
+ public static String getElanMacKey(long elanTag, String macAddress) {
+ return ("MAC-" + macAddress + " ELAN_TAG-" + elanTag).intern();
+ }
}