|
|
| 34 |
#include "ns3/system-thread.h" |
34 |
#include "ns3/system-thread.h" |
| 35 |
#include "ns3/realtime-simulator-impl.h" |
35 |
#include "ns3/realtime-simulator-impl.h" |
| 36 |
#include "ns3/mac48-address.h" |
36 |
#include "ns3/mac48-address.h" |
|
|
37 |
#include "ns3/enum.h" |
| 37 |
|
38 |
|
| 38 |
#include <sys/wait.h> |
39 |
#include <sys/wait.h> |
| 39 |
#include <sys/stat.h> |
40 |
#include <sys/stat.h> |
|
|
| 83 |
TimeValue (Seconds (0.)), |
85 |
TimeValue (Seconds (0.)), |
| 84 |
MakeTimeAccessor (&EmuNetDevice::m_tStop), |
86 |
MakeTimeAccessor (&EmuNetDevice::m_tStop), |
| 85 |
MakeTimeChecker ()) |
87 |
MakeTimeChecker ()) |
|
|
88 |
.AddAttribute ("EncapsulationMode", |
| 89 |
"The link-layer encapsulation type to use.", |
| 90 |
EnumValue (LLC), |
| 91 |
MakeEnumAccessor (&EmuNetDevice::SetEncapsulationMode), |
| 92 |
MakeEnumChecker (DIX, "Dix", |
| 93 |
LLC, "Llc")) |
| 86 |
|
94 |
|
| 87 |
// |
95 |
// |
| 88 |
// Transmit queueing discipline for the device which includes its own set |
96 |
// Transmit queueing discipline for the device which includes its own set |
|
|
| 193 |
NetDevice::DoDispose (); |
201 |
NetDevice::DoDispose (); |
| 194 |
} |
202 |
} |
| 195 |
|
203 |
|
|
|
204 |
void |
| 205 |
EmuNetDevice::SetEncapsulationMode (enum EncapsulationMode mode) |
| 206 |
{ |
| 207 |
NS_LOG_FUNCTION (mode); |
| 208 |
m_encapMode = mode; |
| 209 |
NS_LOG_LOGIC ("m_encapMode = " << m_encapMode); |
| 210 |
} |
| 211 |
|
| 212 |
EmuNetDevice::EncapsulationMode |
| 213 |
EmuNetDevice::GetEncapsulationMode (void) const |
| 214 |
{ |
| 215 |
NS_LOG_FUNCTION_NOARGS (); |
| 216 |
return m_encapMode; |
| 217 |
} |
| 218 |
|
| 196 |
void |
219 |
void |
| 197 |
EmuNetDevice::Start (Time tStart) |
220 |
EmuNetDevice::Start (Time tStart) |
| 198 |
{ |
221 |
{ |
|
|
| 632 |
|
655 |
|
| 633 |
uint16_t protocol; |
656 |
uint16_t protocol; |
| 634 |
|
657 |
|
| 635 |
// |
658 |
switch (m_encapMode) |
| 636 |
// If the length/type is less than 1500, it corresponds to a length |
|
|
| 637 |
// interpretation packet. In this case, it is an 802.3 packet and |
| 638 |
// will also have an 802.2 LLC header. If greater than 1500, we |
| 639 |
// find the protocol number (Ethernet type) directly. |
| 640 |
// |
| 641 |
if (header.GetLengthType () <= 1500) |
| 642 |
{ |
659 |
{ |
| 643 |
LlcSnapHeader llc; |
660 |
case LLC: |
| 644 |
// |
661 |
// |
| 645 |
// Check to see that the packet is long enough to possibly contain the |
662 |
// If the length/type is less than 1500, it corresponds to a length |
| 646 |
// header we want to remove before just naively calling. |
663 |
// interpretation packet. In this case, it is an 802.3 packet and |
|
|
664 |
// will also have an 802.2 LLC header. If greater than 1500, we |
| 665 |
// find the protocol number (Ethernet type) directly. |
| 647 |
// |
666 |
// |
| 648 |
if (packet->GetSize() < llc.GetSerializedSize()) |
667 |
if (header.GetLengthType () <= 1500) |
| 649 |
{ |
668 |
{ |
| 650 |
m_phyRxDropTrace (originalPacket); |
669 |
LlcSnapHeader llc; |
| 651 |
return; |
670 |
// |
|
|
671 |
// Check to see that the packet is long enough to possibly contain the |
| 672 |
// header we want to remove before just naively calling. |
| 673 |
// |
| 674 |
if (packet->GetSize() < llc.GetSerializedSize()) |
| 675 |
{ |
| 676 |
m_phyRxDropTrace (originalPacket); |
| 677 |
return; |
| 678 |
} |
| 679 |
|
| 680 |
packet->RemoveHeader (llc); |
| 681 |
protocol = llc.GetType (); |
| 652 |
} |
682 |
} |
|
|
683 |
else |
| 684 |
{ |
| 685 |
protocol = header.GetLengthType (); |
| 686 |
} |
| 687 |
break; |
| 653 |
|
688 |
|
| 654 |
packet->RemoveHeader (llc); |
689 |
case DIX: |
| 655 |
protocol = llc.GetType (); |
|
|
| 656 |
} |
| 657 |
else |
| 658 |
{ |
| 659 |
protocol = header.GetLengthType (); |
690 |
protocol = header.GetLengthType (); |
|
|
691 |
break; |
| 692 |
|
| 693 |
default: |
| 694 |
NS_FATAL_ERROR ("invalid encapsulation mode"); |
| 660 |
} |
695 |
} |
| 661 |
|
696 |
|
| 662 |
PacketType packetType; |
697 |
PacketType packetType; |
|
|
| 795 |
NS_LOG_LOGIC ("Transmit packet from " << source); |
831 |
NS_LOG_LOGIC ("Transmit packet from " << source); |
| 796 |
NS_LOG_LOGIC ("Transmit packet to " << destination); |
832 |
NS_LOG_LOGIC ("Transmit packet to " << destination); |
| 797 |
|
833 |
|
| 798 |
// |
|
|
| 799 |
// We've got to pick either DIX (Ethernet) or LLC/SNAP (IEEE 802.3) as a |
| 800 |
// packet format. IEEE 802.3 is slightly more formally correct, so we |
| 801 |
// go that route. |
| 802 |
// |
| 803 |
LlcSnapHeader llc; |
| 804 |
llc.SetType (protocolNumber); |
| 805 |
packet->AddHeader (llc); |
| 806 |
|
| 807 |
EthernetHeader header (false); |
834 |
EthernetHeader header (false); |
| 808 |
header.SetSource (source); |
835 |
header.SetSource (source); |
| 809 |
header.SetDestination (destination); |
836 |
header.SetDestination (destination); |
| 810 |
header.SetLengthType (packet->GetSize ()); |
837 |
|
|
|
838 |
switch (m_encapMode) |
| 839 |
{ |
| 840 |
case LLC: |
| 841 |
{ |
| 842 |
// |
| 843 |
// We've got to pick either DIX (Ethernet) or LLC/SNAP (IEEE 802.3) as a |
| 844 |
// packet format. IEEE 802.3 is slightly more formally correct, so we |
| 845 |
// go that route. |
| 846 |
// |
| 847 |
LlcSnapHeader llc; |
| 848 |
llc.SetType (protocolNumber); |
| 849 |
packet->AddHeader (llc); |
| 850 |
|
| 851 |
header.SetLengthType (packet->GetSize ()); |
| 852 |
} |
| 853 |
break; |
| 854 |
|
| 855 |
case DIX: |
| 856 |
header.SetLengthType (protocolNumber); |
| 857 |
break; |
| 858 |
|
| 859 |
default: |
| 860 |
NS_FATAL_ERROR ("invalid encapsulation mode"); |
| 861 |
} |
| 862 |
|
| 811 |
packet->AddHeader (header); |
863 |
packet->AddHeader (header); |
| 812 |
|
864 |
|
| 813 |
// |
865 |
// |