use of org.opendaylight.openflowplugin.libraries.liblldp.Packet 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.openflowplugin.libraries.liblldp.Packet in project genius by opendaylight.
the class AlivenessMonitor method onPacketReceived.
@Override
public void onPacketReceived(PacketReceived packetReceived) {
Class<? extends PacketInReason> pktInReason = packetReceived.getPacketInReason();
if (LOG.isTraceEnabled()) {
LOG.trace("Packet Received {}", packetReceived);
}
if (pktInReason == SendToController.class) {
Packet packetInFormatted;
byte[] data = packetReceived.getPayload();
Ethernet res = new Ethernet();
try {
packetInFormatted = res.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
} catch (PacketException e) {
LOG.warn("Failed to decode packet: ", e);
return;
}
if (packetInFormatted == null) {
LOG.warn("Failed to deserialize Received Packet from table {}", packetReceived.getTableId().getValue());
return;
}
Packet objPayload = packetInFormatted.getPayload();
if (objPayload == null) {
LOG.trace("Unsupported packet type. Ignoring the packet...");
return;
}
if (LOG.isTraceEnabled()) {
LOG.trace("onPacketReceived packet: {}, packet class: {}", packetReceived, objPayload.getClass());
}
AlivenessProtocolHandler<Packet> livenessProtocolHandler = alivenessProtocolHandlerRegistry.getOpt(Packet.class);
if (livenessProtocolHandler == null) {
return;
}
String monitorKey = livenessProtocolHandler.handlePacketIn(packetInFormatted.getPayload(), packetReceived);
if (monitorKey != null) {
processReceivedMonitorKey(monitorKey);
} else {
LOG.debug("No monitorkey associated with received packet");
}
}
}
use of org.opendaylight.openflowplugin.libraries.liblldp.Packet in project genius by opendaylight.
the class ArpUtilImpl method onPacketReceived.
@Override
public void onPacketReceived(PacketReceived packetReceived) {
Class<? extends PacketInReason> pktInReason = packetReceived.getPacketInReason();
LOG.trace("Packet Received {}", packetReceived);
if (pktInReason == SendToController.class) {
try {
int tableId = packetReceived.getTableId().getValue();
byte[] data = packetReceived.getPayload();
Ethernet ethernet = new Ethernet();
ethernet.deserialize(data, 0, data.length * NetUtils.NUM_BITS_IN_A_BYTE);
if (ethernet.getEtherType() != ArpConstants.ETH_TYPE_ARP) {
return;
}
Packet pkt = ethernet.getPayload();
ARP arp = (ARP) pkt;
InetAddress srcInetAddr = InetAddress.getByAddress(arp.getSenderProtocolAddress());
InetAddress dstInetAddr = InetAddress.getByAddress(arp.getTargetProtocolAddress());
byte[] srcMac = ethernet.getSourceMACAddress();
byte[] dstMac = ethernet.getDestinationMACAddress();
Metadata metadata = packetReceived.getMatch().getMetadata();
String interfaceName = getInterfaceName(metadata);
checkAndFireMacChangedNotification(interfaceName, srcInetAddr, srcMac);
macsDB.put(interfaceName + "-" + srcInetAddr.getHostAddress(), NWUtil.toStringMacAddress(srcMac));
if (arp.getOpCode() == ArpConstants.ARP_REQUEST_OP) {
fireArpReqRecvdNotification(interfaceName, srcInetAddr, srcMac, dstInetAddr, tableId, metadata.getMetadata());
} else {
fireArpRespRecvdNotification(interfaceName, srcInetAddr, srcMac, tableId, metadata.getMetadata(), dstInetAddr, dstMac);
}
if (macAddrs.get(srcInetAddr.getHostAddress()) != null) {
threadPool.execute(new MacResponderTask(arp));
}
} catch (PacketException | UnknownHostException | InterruptedException | ExecutionException e) {
LOG.trace("Failed to decode packet", e);
}
}
}
Aggregations