use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.
the class ElanTunnelInterfaceStateListener method add.
@Override
public void add(InstanceIdentifier<StateTunnelList> key, StateTunnelList add) {
LOG.info("processing add state for StateTunnelList {}", add);
if (!isInternalTunnel(add)) {
LOG.trace("tunnel {} is not a internal vxlan tunnel", add);
return;
}
if (elanUtils.isTunnelInLogicalGroup(add.getTunnelInterfaceName())) {
LOG.trace("MULTIPLE_VxLAN_TUNNELS: ignoring the tunnel event for {}", add.getTunnelInterfaceName());
return;
}
TunnelOperStatus tunOpStatus = add.getOperState();
if (tunOpStatus != TunnelOperStatus.Down && tunOpStatus != TunnelOperStatus.Up) {
LOG.trace("Returning because unsupported tunnelOperStatus {}", tunOpStatus);
return;
}
try {
Uint64 srcDpId = Uint64.valueOf(add.getSrcInfo().getTepDeviceId());
Uint64 dstDpId = Uint64.valueOf(add.getDstInfo().getTepDeviceId());
jobCoordinator.enqueueJob(add.getTunnelInterfaceName(), () -> {
LOG.info("Handling tunnel state event for srcDpId {} and dstDpId {} ", srcDpId, dstDpId);
elanInterfaceManager.handleInternalTunnelStateEvent(srcDpId, dstDpId);
return Collections.emptyList();
}, ElanConstants.JOB_MAX_RETRIES);
} catch (NumberFormatException e) {
LOG.error("Invalid source TepDeviceId {} or destination TepDeviceId {}", add.getSrcInfo().getTepDeviceId(), add.getDstInfo().getTepDeviceId());
}
}
use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.
the class ElanEvpnFlowUtils method evpnRemoveFlowThatSendsThePacketOnAnExternalTunnel.
private List<ListenableFuture<?>> evpnRemoveFlowThatSendsThePacketOnAnExternalTunnel(long elanTag, Uint64 dpId, String nexthopIp, String macToRemove) {
String flowId = ElanEvpnFlowUtils.evpnGetKnownDynamicmacFlowRef(NwConstants.ELAN_DMAC_TABLE, dpId, nexthopIp, macToRemove, elanTag, false);
Flow flowToRemove = new FlowBuilder().setId(new FlowId(flowId)).setTableId(NwConstants.ELAN_DMAC_TABLE).build();
return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> mdsalManager.removeFlow(tx, dpId, flowToRemove)));
}
use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.
the class ElanPacketInHandler method onPacketReceived.
@Override
public void onPacketReceived(PacketReceived notification) {
Class<? extends PacketInReason> pktInReason = notification.getPacketInReason();
short tableId = notification.getTableId().getValue().toJava();
if (pktInReason == NoMatch.class && tableId == NwConstants.ELAN_SMAC_TABLE) {
elanManagerCounters.unknownSmacPktinRcv();
try {
byte[] data = notification.getPayload();
Ethernet res = new Ethernet();
res.deserialize(data, 0, data.length * Byte.SIZE);
byte[] srcMac = res.getSourceMACAddress();
final String macAddress = NWUtil.toStringMacAddress(srcMac);
final Uint64 metadata = notification.getMatch().getMetadata().getMetadata();
final Uint32 elanTag = Uint32.valueOf(MetaDataUtil.getElanTagFromMetadata(metadata));
Uint32 portTag = Uint32.valueOf(MetaDataUtil.getLportFromMetadata(metadata).longValue());
Optional<IfIndexInterface> interfaceInfoOp = elanUtils.getInterfaceInfoByInterfaceTag(portTag);
if (!interfaceInfoOp.isPresent()) {
LOG.warn("There is no interface for given portTag {}", portTag);
return;
}
String interfaceName = interfaceInfoOp.get().getInterfaceName();
LOG.debug("Received a packet with srcMac: {} ElanTag: {} PortTag: {} InterfaceName: {}", macAddress, elanTag, portTag, interfaceName);
ElanTagName elanTagName = elanUtils.getElanInfoByElanTag(elanTag);
if (elanTagName == null) {
LOG.warn("not able to find elanTagName in elan-tag-name-map for elan tag {}", elanTag);
return;
}
ElanInterfaceMac elanInterfaceMac = elanUtils.getElanInterfaceMacByInterfaceName(interfaceName);
if (elanInterfaceMac == null) {
LOG.info("There is no ElanInterfaceForwardingEntryDS created for interface :{}", interfaceName);
return;
}
String elanName = elanTagName.getName();
PhysAddress physAddress = new PhysAddress(macAddress);
MacEntry oldMacEntry = elanUtils.getMacEntryForElanInstance(elanName, physAddress).orElse(null);
boolean isVlanOrFlatProviderIface = interfaceManager.isExternalInterface(interfaceName);
Optional<IpAddress> srcIpAddress = elanUtils.getSourceIpAddress(res);
MacEntry newMacEntry = null;
BigInteger timeStamp = new BigInteger(String.valueOf(System.currentTimeMillis()));
if (!srcIpAddress.isPresent()) {
newMacEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress).withKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp).setIsStaticAddress(false).build();
} else {
newMacEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress).setIpPrefix(srcIpAddress.get()).withKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp).setIsStaticAddress(false).build();
}
if (srcIpAddress.isPresent()) {
String prefix = srcIpAddress.get().getIpv4Address().getValue();
InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
ElanInstance elanInstance = elanInstanceCache.get(elanName).orElse(null);
evpnUtils.advertisePrefix(elanInstance, macAddress, prefix, interfaceName, interfaceInfo.getDpId());
}
enqueueJobForMacSpecificTasks(macAddress, elanTag, interfaceName, elanName, physAddress, oldMacEntry, newMacEntry, isVlanOrFlatProviderIface);
ElanInstance elanInstance = elanInstanceCache.get(elanName).orElse(null);
InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
if (interfaceInfo == null) {
LOG.trace("Interface:{} is not present under Config DS", interfaceName);
return;
}
enqueueJobForDPNSpecificTasks(macAddress, elanTag, interfaceName, physAddress, elanInstance, interfaceInfo, oldMacEntry, newMacEntry, isVlanOrFlatProviderIface);
} catch (PacketException e) {
LOG.error("Failed to decode packet: {}", notification, e);
}
}
}
use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.
the class ElanSmacFlowEventListener method onFlowRemoved.
@Override
public void onFlowRemoved(FlowRemoved flowRemoved) {
short tableId = flowRemoved.getTableId().toJava();
if (tableId == NwConstants.ELAN_SMAC_TABLE) {
Uint64 metadata = flowRemoved.getMatch().getMetadata().getMetadata();
Uint32 elanTag = Uint32.valueOf(MetaDataUtil.getElanTagFromMetadata(metadata));
ElanTagName elanTagInfo = elanUtils.getElanInfoByElanTag(elanTag);
if (elanTagInfo == null) {
return;
}
final String srcMacAddress = flowRemoved.getMatch().getEthernetMatch().getEthernetSource().getAddress().getValue().toUpperCase(Locale.getDefault());
Uint64 portTag = MetaDataUtil.getLportFromMetadata(metadata);
if (portTag.intValue() == 0) {
LOG.debug("Flow removed event on SMAC flow entry. But having port Tag as 0 ");
return;
}
Optional<IfIndexInterface> existingInterfaceInfo = elanUtils.getInterfaceInfoByInterfaceTag(Uint32.valueOf(portTag.longValue()));
if (!existingInterfaceInfo.isPresent()) {
LOG.debug("Interface is not available for port Tag {}", portTag);
return;
}
String interfaceName = existingInterfaceInfo.get().getInterfaceName();
PhysAddress physAddress = new PhysAddress(srcMacAddress);
if (interfaceName == null) {
LOG.error("LPort record not found for tag {}", portTag);
return;
}
jobCoordinator.enqueueJob(ElanUtils.getElanInterfaceJobKey(interfaceName), () -> {
List<ListenableFuture<?>> elanFutures = new ArrayList<>();
MacEntry macEntry = elanUtils.getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
String elanInstanceName = elanTagInfo.getName();
LOG.info("Deleting the Mac-Entry:{} present on ElanInstance:{}", macEntry, elanInstanceName);
FluentFuture<? extends Object> result = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
if (macEntry != null && interfaceInfo != null) {
deleteSmacAndDmacFlows(elanInstanceCache.get(elanInstanceName).orElse(null), interfaceInfo, srcMacAddress, tx);
} else if (macEntry == null) {
// Remove flow of src flow entry only for MAC movement
MacEntry macEntryOfElanForwarding = elanUtils.getMacEntryForElanInstance(elanTagInfo.getName(), physAddress).orElse(null);
if (macEntryOfElanForwarding != null) {
String macAddress = macEntryOfElanForwarding.getMacAddress().getValue();
elanUtils.deleteSmacFlowOnly(elanInstanceCache.get(elanInstanceName).orElse(null), interfaceInfo, macAddress, tx);
} else {
deleteSmacAndDmacFlows(elanInstanceCache.get(elanInstanceName).orElse(null), interfaceInfo, srcMacAddress, tx);
}
}
});
elanFutures.add(result);
addCallBack(result, srcMacAddress);
InstanceIdentifier<MacEntry> macEntryIdForElanInterface = ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
Optional<MacEntry> existingInterfaceMacEntry = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInterface);
if (existingInterfaceMacEntry.isPresent()) {
FluentFuture<? extends Object> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(OPERATIONAL, tx -> {
tx.delete(macEntryIdForElanInterface);
MacEntry macEntryInElanInstance = elanUtils.getMacEntryForElanInstance(elanInstanceName, physAddress).orElse(null);
if (macEntryInElanInstance != null && macEntryInElanInstance.getInterface().equals(interfaceName)) {
InstanceIdentifier<MacEntry> macEntryIdForElanInstance = ElanUtils.getMacEntryOperationalDataPath(elanInstanceName, physAddress);
tx.delete(macEntryIdForElanInstance);
}
});
elanFutures.add(future);
addCallBack(future, srcMacAddress);
}
return elanFutures;
}, ElanConstants.JOB_MAX_RETRIES);
}
}
use of org.opendaylight.yangtools.yang.common.Uint64 in project netvirt by opendaylight.
the class QosNeutronUtils method getDpnForInterface.
public Uint64 getDpnForInterface(String ifName) {
Uint64 nodeId = Uint64.ZERO;
try {
GetDpidFromInterfaceInput dpIdInput = new GetDpidFromInterfaceInputBuilder().setIntfName(ifName).build();
Future<RpcResult<GetDpidFromInterfaceOutput>> dpIdOutput = odlInterfaceRpcService.getDpidFromInterface(dpIdInput);
RpcResult<GetDpidFromInterfaceOutput> dpIdResult = dpIdOutput.get();
if (dpIdResult.isSuccessful()) {
nodeId = dpIdResult.getResult().getDpid();
} else {
LOG.error("Could not retrieve DPN Id for interface {}", ifName);
}
} catch (NullPointerException | InterruptedException | ExecutionException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Exception when getting DPN for interface {} exception ", ifName, e);
} else {
LOG.error("Could not retrieve DPN for interface {}", ifName);
}
}
return nodeId;
}
Aggregations