--- a/examples/csma-multicast.cc Thu Sep 04 22:38:52 2008 -0700
+++ b/examples/csma-multicast.cc Fri Sep 05 11:56:17 2008 -0700
@@ -58,8 +58,8 @@
//
// Set up default values for the simulation.
//
- // Select Ethernet II-style encapsulation (no LLC/Snap header)
- Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("IpArp"));
+ // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header)
+ Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix"));
// Allow the user to override any of the defaults at
// run-time, via command-line arguments
--- a/src/devices/csma/csma-net-device.cc Thu Sep 04 22:38:52 2008 -0700
+++ b/src/devices/csma/csma-net-device.cc Fri Sep 05 11:56:17 2008 -0700
@@ -61,8 +61,6 @@
EnumValue (LLC),
MakeEnumAccessor (&CsmaNetDevice::SetEncapsulationMode),
MakeEnumChecker (DIX, "Dix",
- IP_ARP, "IpArp",
- RAW, "Raw",
LLC, "Llc"))
.AddAttribute ("SendEnable",
"Enable or disable the transmitter section of the device.",
@@ -103,13 +101,16 @@
m_tInterframeGap = Seconds (0);
m_channel = 0;
- m_encapMode = LLC;
+ //
+ // We would like to let the attribute system take care of initializing the packet encapsulation stuff, but we also don't want to
+ // get caught up in initialization order changes. So we'll get the three problem variables into a consistent state here before the
+ // attribute calls, and then depend on the semantics of the setters to preserve a consistent state. This really doesn't have to be
+ // the same set of values as the initial values set by the attributes, but it does have to be a consistent set. That is, you can
+ // just change the ddfault encapsulation mode above without having to change it here. We keep it the same for GP.
+ //
+ m_encapMode = DIX;
m_frameSize = DEFAULT_FRAME_SIZE;
m_mtu = MtuFromFrameSize (m_frameSize);
-
- NS_LOG_LOGIC ("m_encapMode = " << m_encapMode);
- NS_LOG_LOGIC ("m_frameSize = " << m_frameSize);
- NS_LOG_LOGIC ("m_mtu = " << m_mtu);
}
CsmaNetDevice::~CsmaNetDevice()
@@ -134,21 +135,24 @@
switch (m_encapMode)
{
- case RAW:
- case IP_ARP:
case DIX:
- return frameSize - 18;
+ return frameSize - ETHERNET_OVERHEAD;
case LLC:
{
LlcSnapHeader llc;
- NS_ASSERT_MSG ((uint32_t)(frameSize - 18) >= llc.GetSerializedSize (), "CsmaNetDevice::MtuFromFrameSize(): "
- "Given frame size too small to support LLC mode");
- return frameSize - 18 - llc.GetSerializedSize ();
+ NS_ASSERT_MSG ((uint32_t)(frameSize - ETHERNET_OVERHEAD) >= llc.GetSerializedSize (),
+ "CsmaNetDevice::MtuFromFrameSize(): Given frame size too small to support LLC mode");
+ return frameSize - ETHERNET_OVERHEAD - llc.GetSerializedSize ();
}
+ case ILLEGAL:
+ default:
+ NS_FATAL_ERROR ("CsmaNetDevice::MtuFromFrameSize(): Unknown packet encapsulation mode");
+ return 0;
}
-
- NS_ASSERT_MSG (false, "CsmaNetDevice::MtuFromFrameSize(): Unexpected encapsulation mode");
+ //
+ // Prevent compiler from complaining
+ //
return 0;
}
@@ -159,18 +163,22 @@
switch (m_encapMode)
{
- case RAW:
- case IP_ARP:
case DIX:
- return mtu + 18;
+ return mtu + ETHERNET_OVERHEAD;
case LLC:
{
LlcSnapHeader llc;
- return mtu + 18 + llc.GetSerializedSize ();
+ return mtu + ETHERNET_OVERHEAD + llc.GetSerializedSize ();
}
+ case ILLEGAL:
+ default:
+ NS_FATAL_ERROR ("CsmaNetDevice::FrameSizeFromMtu(): Unknown packet encapsulation mode");
+ return 0;
}
- NS_ASSERT_MSG (false, "CsmaNetDevice::FrameSizeFromMtu(): Unexpected encapsulation mode");
+ //
+ // Prevent compiler from complaining
+ //
return 0;
}
@@ -293,11 +301,6 @@
{
NS_LOG_FUNCTION (p << source << dest << protocolNumber);
- if (m_encapMode == RAW)
- {
- return;
- }
-
EthernetHeader header (false);
header.SetSource (source);
header.SetDestination (dest);
@@ -312,11 +315,10 @@
uint16_t lengthType = 0;
switch (m_encapMode)
{
- case IP_ARP:
case DIX:
- NS_LOG_LOGIC ("Encapsulating packet as DIX or IP_ARP (type interpretation)");
+ NS_LOG_LOGIC ("Encapsulating packet as DIX (type interpretation)");
//
- // This corresponds to the type interpretation of the lengthType field.
+ // This corresponds to the type interpretation of the lengthType field as in the old Ethernet Blue Book.
//
lengthType = protocolNumber;
break;
@@ -329,7 +331,7 @@
p->AddHeader (llc);
//
// This corresponds to the length interpretation of the lengthType field,
- // but with an LLC/SNAP header added to the payload.
+ // but with an LLC/SNAP header added to the payload as in IEEE 802.2
//
lengthType = p->GetSize ();
NS_ASSERT_MSG (lengthType <= m_frameSize - 18,
@@ -337,8 +339,9 @@
"length interpretation must not exceed device frame size minus overhead");
}
break;
- case RAW:
- NS_ASSERT_MSG (false, "CsmaNetDevice::AddHeader(): RAW packet encapsulation not supported");
+ case ILLEGAL:
+ default:
+ NS_FATAL_ERROR ("CsmaNetDevice::AddHeader(): Unknown packet encapsulation mode");
break;
}
@@ -355,11 +358,6 @@
{
NS_LOG_FUNCTION (p << param);
- if (m_encapMode == RAW)
- {
- return true;
- }
-
EthernetTrailer trailer;
p->RemoveTrailer (trailer);
@@ -377,16 +375,18 @@
switch (m_encapMode)
{
case DIX:
- case IP_ARP:
param = header.GetLengthType ();
break;
- case LLC: {
- LlcSnapHeader llc;
- p->RemoveHeader (llc);
- param = llc.GetType ();
- } break;
- case RAW:
- NS_ASSERT (false);
+ case LLC:
+ {
+ LlcSnapHeader llc;
+ p->RemoveHeader (llc);
+ param = llc.GetType ();
+ }
+ break;
+ case ILLEGAL:
+ default:
+ NS_FATAL_ERROR ("CsmaNetDevice::ProcessHeader(): Unknown packet encapsulation mode");
break;
}
return true;
@@ -605,17 +605,6 @@
return;
}
- if (m_encapMode == RAW)
- {
- m_rxTrace (packet);
- if (!m_promiscRxCallback.IsNull ())
- {
- m_promiscRxCallback (this, packet, 0, GetBroadcast (), GetAddress (), PACKET_HOST);
- }
- m_rxCallback (this, packet, 0, GetBroadcast ());
- return;
- }
-
//
// Trace sinks will expect complete packets, not packets without some of the
// headers.
@@ -647,7 +636,6 @@
switch (m_encapMode)
{
case DIX:
- case IP_ARP:
protocol = header.GetLengthType ();
break;
case LLC:
@@ -657,8 +645,9 @@
protocol = llc.GetType ();
}
break;
- case RAW:
- NS_ASSERT (false);
+ case ILLEGAL:
+ default:
+ NS_FATAL_ERROR ("CsmaNetDevice::Receive(): Unknown packet encapsulation mode");
break;
}
@@ -916,14 +905,7 @@
CsmaNetDevice::NeedsArp (void) const
{
NS_LOG_FUNCTION_NOARGS ();
- if ((m_encapMode == IP_ARP) || (m_encapMode == LLC))
- {
- return true;
- }
- else
- {
- return false;
- }
+ return true;
}
void
--- a/src/devices/csma/csma-net-device.h Thu Sep 04 22:38:52 2008 -0700
+++ b/src/devices/csma/csma-net-device.h Fri Sep 05 11:56:17 2008 -0700
@@ -64,10 +64,9 @@
*
*/
enum EncapsulationMode {
+ ILLEGAL, /**< Encapsulation mode not set */
DIX, /**< DIX II / Ethernet II packet */
- IP_ARP, /**< Ethernet packet encapsulates IP/ARP packet */
- RAW, /**< Packet that contains no headers */
- LLC, /**< LLC packet encapsulation */
+ LLC, /**< 802.2 LLC/SNAP Packet*/
};
/**
@@ -216,10 +215,10 @@
* seen in RFC 791.
*
* To make this concrete, consider DIX II (Digital Equipment, Intel, Xerox type II) framing, which is used in most TCP/IP
- * stacks. NetWare calls this framing Ethernet II, by the way. In this framing scheme, a real packet on the wire starts
- * with the preamble and Start-of-Frame-Delimeter (10101011). We ignore these bits on this device since it they are not
- * needed. In DIX II, the SFD is followed by the MAC (48) destination address (6 bytes), source address (6 bytes), the
- * EtherType field (2 bytes), payload (0-1500 bytes) and a CRC (4 bytes) -- this corresponds to our entire frame. The
+ * stacks. NetWare and Wireshark call this framing Ethernet II, by the way. In this framing scheme, a real packet on the
+ * wire starts with the preamble and Start-of-Frame-Delimeter (10101011). We ignore these bits on this device since it they
+ * are not needed. In DIX II, the SFD is followed by the MAC (48) destination address (6 bytes), source address (6 bytes),
+ * the EtherType field (2 bytes), payload (0-1500 bytes) and a CRC (4 bytes) -- this corresponds to our entire frame. The
* payload of the packet/frame in DIX can be from 0 to 1500 bytes. It is the maxmimum value of this payload that we call
* the MTU. Typically, one sees the MTU set to 1500 bytes and the maximum frame size set to 1518 bytes in Ethernet-based
* networks.
@@ -685,7 +684,8 @@
Callback<void> m_linkChangeCallback;
static const uint16_t DEFAULT_FRAME_SIZE = 1518;
- static const uint16_t DEFAULT_MTU = 1500;
+ static const uint16_t ETHERNET_OVERHEAD = 18;
+ static const uint16_t DEFAULT_MTU = (DEFAULT_FRAME_SIZE - ETHERNET_OVERHEAD);
/**
* There are two MTU types that are used in this driver. The MAC-level