|
739 |
return; |
739 |
return; |
740 |
} |
740 |
} |
741 |
|
741 |
|
|
|
742 |
|
743 |
if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) ) |
744 |
{ |
745 |
NS_LOG_LOGIC ("Dropping pkt due to error model "); |
746 |
m_phyRxDropTrace (packet); |
747 |
return; |
748 |
} |
749 |
|
742 |
// |
750 |
// |
743 |
// Trace sinks will expect complete packets, not packets without some of the |
751 |
// Trace sinks will expect complete packets, not packets without some of the |
744 |
// headers. |
752 |
// headers. |
745 |
// |
753 |
// |
746 |
Ptr<Packet> originalPacket = packet->Copy (); |
754 |
Ptr<Packet> originalPacket = packet->Copy (); |
747 |
|
|
|
748 |
EthernetTrailer trailer; |
755 |
EthernetTrailer trailer; |
749 |
packet->RemoveTrailer (trailer); |
756 |
packet->RemoveTrailer (trailer); |
750 |
trailer.CheckFcs (packet); |
757 |
trailer.CheckFcs (packet); |
751 |
|
|
|
752 |
EthernetHeader header (false); |
758 |
EthernetHeader header (false); |
753 |
packet->RemoveHeader (header); |
759 |
packet->RemoveHeader (header); |
754 |
|
760 |
|
755 |
NS_LOG_LOGIC ("Pkt source is " << header.GetSource ()); |
761 |
NS_LOG_LOGIC ("Pkt source is " << header.GetSource ()); |
756 |
NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ()); |
762 |
NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ()); |
757 |
|
763 |
|
758 |
if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) ) |
764 |
uint16_t protocol; |
|
|
765 |
// |
766 |
// If the length/type is less than 1500, it corresponds to a length |
767 |
// interpretation packet. In this case, it is an 802.3 packet and |
768 |
// will also have an 802.2 LLC header. If greater than 1500, we |
769 |
// find the protocol number (Ethernet type) directly. |
770 |
// |
771 |
if (header.GetLengthType () <= 1500) |
759 |
{ |
772 |
{ |
760 |
NS_LOG_LOGIC ("Dropping pkt due to error model "); |
773 |
LlcSnapHeader llc; |
761 |
m_phyRxDropTrace (packet); |
774 |
packet->RemoveHeader (llc); |
|
|
775 |
protocol = llc.GetType (); |
762 |
} |
776 |
} |
763 |
else |
777 |
else |
764 |
{ |
778 |
{ |
765 |
uint16_t protocol; |
779 |
protocol = header.GetLengthType (); |
766 |
// |
780 |
} |
767 |
// If the length/type is less than 1500, it corresponds to a length |
|
|
768 |
// interpretation packet. In this case, it is an 802.3 packet and |
769 |
// will also have an 802.2 LLC header. If greater than 1500, we |
770 |
// find the protocol number (Ethernet type) directly. |
771 |
// |
772 |
if (header.GetLengthType () <= 1500) |
773 |
{ |
774 |
LlcSnapHeader llc; |
775 |
packet->RemoveHeader (llc); |
776 |
protocol = llc.GetType (); |
777 |
} |
778 |
else |
779 |
{ |
780 |
protocol = header.GetLengthType (); |
781 |
} |
782 |
|
781 |
|
783 |
// |
782 |
// |
784 |
// Classify the packet based on its destination. |
783 |
// Classify the packet based on its destination. |
785 |
// |
784 |
// |
786 |
PacketType packetType; |
785 |
PacketType packetType; |
787 |
|
786 |
|
788 |
if (header.GetDestination ().IsBroadcast ()) |
787 |
if (header.GetDestination ().IsBroadcast ()) |
789 |
{ |
788 |
{ |
790 |
packetType = PACKET_BROADCAST; |
789 |
packetType = PACKET_BROADCAST; |
791 |
} |
790 |
} |
792 |
else if (header.GetDestination ().IsGroup ()) |
791 |
else if (header.GetDestination ().IsGroup ()) |
793 |
{ |
792 |
{ |
794 |
packetType = PACKET_MULTICAST; |
793 |
packetType = PACKET_MULTICAST; |
795 |
} |
794 |
} |
796 |
else if (header.GetDestination () == m_address) |
795 |
else if (header.GetDestination () == m_address) |
797 |
{ |
796 |
{ |
798 |
packetType = PACKET_HOST; |
797 |
packetType = PACKET_HOST; |
799 |
} |
798 |
} |
800 |
else |
799 |
else |
801 |
{ |
800 |
{ |
802 |
packetType = PACKET_OTHERHOST; |
801 |
packetType = PACKET_OTHERHOST; |
803 |
} |
802 |
} |
804 |
|
803 |
|
805 |
// |
804 |
// |
806 |
// For all kinds of packetType we receive, we hit the promiscuous sniffer |
805 |
// For all kinds of packetType we receive, we hit the promiscuous sniffer |
807 |
// hook and pass a copy up to the promiscuous callback. Pass a copy to |
806 |
// hook and pass a copy up to the promiscuous callback. Pass a copy to |
808 |
// make sure that nobody messes with our packet. |
807 |
// make sure that nobody messes with our packet. |
809 |
// |
808 |
// |
810 |
m_promiscSnifferTrace (originalPacket); |
809 |
m_promiscSnifferTrace (originalPacket); |
811 |
if (!m_promiscRxCallback.IsNull ()) |
810 |
if (!m_promiscRxCallback.IsNull ()) |
812 |
{ |
811 |
{ |
813 |
m_macPromiscRxTrace (originalPacket); |
812 |
m_macPromiscRxTrace (originalPacket); |
814 |
m_promiscRxCallback (this, packet, protocol, header.GetSource (), header.GetDestination (), packetType); |
813 |
m_promiscRxCallback (this, packet, protocol, header.GetSource (), header.GetDestination (), packetType); |
815 |
} |
814 |
} |
816 |
|
815 |
|
817 |
// |
816 |
// |
818 |
// If this packet is not destined for some other host, it must be for us |
817 |
// If this packet is not destined for some other host, it must be for us |
819 |
// as either a broadcast, multicast or unicast. We need to hit the mac |
818 |
// as either a broadcast, multicast or unicast. We need to hit the mac |
820 |
// packet received trace hook and forward the packet up the stack. |
819 |
// packet received trace hook and forward the packet up the stack. |
821 |
// |
820 |
// |
822 |
if (packetType != PACKET_OTHERHOST) |
821 |
if (packetType != PACKET_OTHERHOST) |
823 |
{ |
822 |
{ |
824 |
m_snifferTrace (originalPacket); |
823 |
m_snifferTrace (originalPacket); |
825 |
m_macRxTrace (originalPacket); |
824 |
m_macRxTrace (originalPacket); |
826 |
m_rxCallback (this, packet, protocol, header.GetSource ()); |
825 |
m_rxCallback (this, packet, protocol, header.GetSource ()); |
827 |
} |
|
|
828 |
} |
826 |
} |
829 |
} |
827 |
} |
830 |
|
828 |
|