use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata 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();
if (pktInReason == NoMatch.class && tableId == NwConstants.ELAN_SMAC_TABLE) {
ElanManagerCounters.unknown_smac_pktin_rcv.inc();
try {
byte[] data = notification.getPayload();
Ethernet res = new Ethernet();
res.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
byte[] srcMac = res.getSourceMACAddress();
final String macAddress = NWUtil.toStringMacAddress(srcMac);
final BigInteger metadata = notification.getMatch().getMetadata().getMetadata();
final long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
long portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
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).orNull();
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).setKey(new MacEntryKey(physAddress)).setControllerLearnedForwardingEntryTimestamp(timeStamp).setIsStaticAddress(false).build();
} else {
newMacEntry = new MacEntryBuilder().setInterface(interfaceName).setMacAddress(physAddress).setIpPrefix(srcIpAddress.get()).setKey(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).orNull();
evpnUtils.advertisePrefix(elanInstance, macAddress, prefix, interfaceName, interfaceInfo.getDpId());
}
enqueueJobForMacSpecificTasks(macAddress, elanTag, interfaceName, elanName, physAddress, oldMacEntry, newMacEntry, isVlanOrFlatProviderIface);
ElanInstance elanInstance = elanInstanceCache.get(elanName).orNull();
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.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.
the class ElanSmacFlowEventListener method onFlowRemoved.
@Override
public void onFlowRemoved(FlowRemoved flowRemoved) {
short tableId = flowRemoved.getTableId();
if (tableId == NwConstants.ELAN_SMAC_TABLE) {
BigInteger metadata = flowRemoved.getMatch().getMetadata().getMetadata();
long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
ElanTagName elanTagInfo = elanUtils.getElanInfoByElanTag(elanTag);
if (elanTagInfo == null) {
return;
}
final String srcMacAddress = flowRemoved.getMatch().getEthernetMatch().getEthernetSource().getAddress().getValue().toUpperCase(Locale.getDefault());
int portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
if (portTag == 0) {
LOG.debug("Flow removed event on SMAC flow entry. But having port Tag as 0 ");
return;
}
Optional<IfIndexInterface> existingInterfaceInfo = elanUtils.getInterfaceInfoByInterfaceTag(portTag);
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<Void>> 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);
if (macEntry != null && interfaceInfo != null) {
ListenableFuture<Void> result = txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> elanUtils.deleteMacFlows(elanInstanceCache.get(elanInstanceName).orNull(), interfaceInfo, macEntry, 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()) {
ListenableFuture<Void> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
tx.delete(LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInterface);
MacEntry macEntryInElanInstance = elanUtils.getMacEntryForElanInstance(elanInstanceName, physAddress).orNull();
if (macEntryInElanInstance != null && macEntryInElanInstance.getInterface().equals(interfaceName)) {
InstanceIdentifier<MacEntry> macEntryIdForElanInstance = ElanUtils.getMacEntryOperationalDataPath(elanInstanceName, physAddress);
tx.delete(LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInstance);
}
});
elanFutures.add(future);
addCallBack(future, srcMacAddress);
}
return elanFutures;
}, ElanConstants.JOB_MAX_RETRIES);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.
the class SubnetRoutePacketInHandler method handleInternalVpnSubnetRoutePacket.
private void handleInternalVpnSubnetRoutePacket(BigInteger metadata, byte[] dstIp, String srcIpStr, String dstIpStr, int destinationAddress, String vpnIdVpnInstanceName, long elanTag) throws InterruptedException, ExecutionException, UnknownHostException {
String vmVpnInterfaceName = VpnUtil.getVpnInterfaceName(odlInterfaceRpcService, metadata);
if (isTunnel(vmVpnInterfaceName)) {
handlePacketFromTunnelToExternalNetwork(vpnIdVpnInstanceName, srcIpStr, dstIp, elanTag);
}
VpnInterface vmVpnInterface = VpnUtil.getVpnInterface(dataBroker, vmVpnInterfaceName);
if (vmVpnInterface == null) {
LOG.error("Vpn interface {} doesn't exist.", vmVpnInterfaceName);
VpnManagerCounters.subnet_route_packet_failed.inc();
return;
}
if (VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnIdVpnInstanceName, vmVpnInterface.getVpnInstanceNames()) && !VpnUtil.isBgpVpnInternet(dataBroker, vpnIdVpnInstanceName)) {
LOG.trace("Unknown IP is in internal network");
handlePacketToInternalNetwork(dstIp, dstIpStr, destinationAddress, elanTag);
} else {
LOG.trace("Unknown IP is in external network");
String vpnName = VpnUtil.getInternetVpnFromVpnInstanceList(dataBroker, vmVpnInterface.getVpnInstanceNames());
if (vpnName != null) {
handlePacketToExternalNetwork(new Uuid(vpnIdVpnInstanceName), vpnName, dstIp, elanTag);
} else {
vpnName = VpnHelper.getFirstVpnNameFromVpnInterface(vmVpnInterface);
LOG.trace("Unknown IP is in external network, but internet VPN not found." + " fallback to first VPN");
handlePacketToExternalNetwork(new Uuid(vpnIdVpnInstanceName), vpnName, dstIp, elanTag);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.
the class SubnetRoutePacketInHandler method onPacketReceived.
@Override
public void onPacketReceived(PacketReceived notification) {
short tableId = notification.getTableId().getValue();
LOG.trace("{} onPacketReceived: Packet punted from table {}", LOGGING_PREFIX, tableId);
byte[] data = notification.getPayload();
if (notification.getMatch() == null || notification.getMatch().getMetadata() == null) {
LOG.error("{} onPacketReceived: Received from table {} where the match or metadata are null", LOGGING_PREFIX, tableId);
return;
}
BigInteger metadata = notification.getMatch().getMetadata().getMetadata();
Ethernet res = new Ethernet();
if (tableId == NwConstants.L3_SUBNET_ROUTE_TABLE) {
LOG.trace("{} onPacketReceived: Some packet received as {}", LOGGING_PREFIX, notification);
try {
res.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
} catch (PacketException e) {
LOG.error("{} onPacketReceived: Failed to decode Packet ", LOGGING_PREFIX, e);
VpnManagerCounters.subnet_route_packet_failed.inc();
return;
}
try {
Packet pkt = res.getPayload();
if (pkt instanceof IPv4) {
IPv4 ipv4 = (IPv4) pkt;
byte[] srcIp = Ints.toByteArray(ipv4.getSourceAddress());
byte[] dstIp = Ints.toByteArray(ipv4.getDestinationAddress());
String dstIpStr = NWUtil.toStringIpAddress(dstIp);
String srcIpStr = NWUtil.toStringIpAddress(srcIp);
// It is an ARP request on a configured VPN. So we must
// attempt to respond.
long vpnId = MetaDataUtil.getVpnIdFromMetadata(metadata);
LOG.info("{} onPacketReceived: Processing IPv4 Packet received with Source IP {} and Target IP {}" + " and vpnId {}", LOGGING_PREFIX, srcIpStr, dstIpStr, vpnId);
Optional<VpnIds> vpnIdsOptional = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnUtil.getVpnIdToVpnInstanceIdentifier(vpnId));
if (!vpnIdsOptional.isPresent()) {
// Donot trigger subnetroute logic for packets from
// unknown VPNs
VpnManagerCounters.subnet_route_packet_ignored.inc();
LOG.info("{} onPacketReceived: Ignoring IPv4 packet with destination Ip {} and source Ip {}" + " as it came on unknown VPN with ID {}", LOGGING_PREFIX, dstIpStr, srcIpStr, vpnId);
return;
}
String vpnIdVpnInstanceName = vpnIdsOptional.get().getVpnInstanceName();
if (VpnUtil.getNeutronPortFromVpnPortFixedIp(dataBroker, vpnIdVpnInstanceName, dstIpStr) != null) {
VpnManagerCounters.subnet_route_packet_ignored.inc();
LOG.info("{} onPacketReceived: IPv4 Packet received with Target IP {} source IP {} vpnId {} " + "is a valid Neutron port,ignoring subnet route processing", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
return;
}
if (VpnUtil.getLearntVpnVipToPort(dataBroker, vpnIdVpnInstanceName, dstIpStr) != null) {
VpnManagerCounters.subnet_route_packet_ignored.inc();
LOG.info("{} onPacketReceived: IPv4 Packet received with Target IP {} source Ip {} vpnId {}" + " is an already discovered IPAddress, ignoring subnet route processing", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
return;
}
long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
if (elanTag == 0L) {
VpnManagerCounters.subnet_route_packet_failed.inc();
LOG.error("{} onPacketReceived: elanTag value from metadata found to be 0, for IPv4 " + " Packet received with Target IP {} src Ip {} vpnId {}", LOGGING_PREFIX, dstIpStr, srcIp, vpnId);
return;
}
if (!vpnIdsOptional.get().isExternalVpn()) {
handleInternalVpnSubnetRoutePacket(metadata, dstIp, srcIpStr, dstIpStr, ipv4.getDestinationAddress(), vpnIdVpnInstanceName, elanTag);
return;
}
byte[] srcMac = res.getSourceMACAddress();
handleBgpVpnSubnetRoute(ipv4, srcMac, dstIp, dstIpStr, srcIpStr, elanTag);
}
} catch (UnknownHostException | InterruptedException | ExecutionException ex) {
// Failed to handle packet
VpnManagerCounters.subnet_route_packet_failed.inc();
LOG.error("{} onPacketReceived: Failed to handle subnetroute packet.", LOGGING_PREFIX, ex);
}
return;
}
// All Arp responses learning for invisble IPs is handled by
// ArpNotificationHandler
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata in project netvirt by opendaylight.
the class AclServiceUtils method buildMatchesForLPortTagAndRemoteAclTag.
public static List<MatchInfoBase> buildMatchesForLPortTagAndRemoteAclTag(Integer lportTag, Integer remoteAclTag, Class<? extends ServiceModeBase> serviceMode) {
List<MatchInfoBase> matches = new ArrayList<>();
if (serviceMode != null && serviceMode.isAssignableFrom(ServiceModeEgress.class)) {
matches.add(AclServiceUtils.buildLPortTagMatch(lportTag, serviceMode));
matches.add(AclServiceUtils.buildRemoteAclTagMetadataMatch(remoteAclTag));
} else {
// In case of ingress service mode, only metadata is used for
// matching both lportTag and aclTag. Hence performing "or"
// operation on both lportTag and aclTag metadata.
BigInteger metaData = MetaDataUtil.getLportTagMetaData(lportTag).or(getRemoteAclTagMetadata(BigInteger.valueOf(remoteAclTag)));
BigInteger metaDataMask = MetaDataUtil.METADATA_MASK_LPORT_TAG.or(MetaDataUtil.METADATA_MASK_REMOTE_ACL_TAG);
matches.add(new MatchMetadata(metaData, metaDataMask));
}
return matches;
}
Aggregations