View | Details | Raw Unified | Return to bug 753
Collapse All | Expand All

(-)a/src/devices/emu/emu-net-device.cc (-28 / +78 lines)
 Lines 34-39    Link Here 
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>
 Lines 83-88    Link Here 
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
 Lines 193-198    Link Here 
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
{
 Lines 632-662    Link Here 
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;
 Lines 795-813    Link Here 
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
  //
(-)a/src/devices/emu/emu-net-device.h (+32 lines)
 Lines 47-52    Link Here 
47
  static TypeId GetTypeId (void);
47
  static TypeId GetTypeId (void);
48
48
49
  /**
49
  /**
50
   * Enumeration of the types of packets supported in the class.
51
   */
52
  enum EncapsulationMode {
53
    ILLEGAL,     /**< Encapsulation mode not set */
54
    DIX,         /**< DIX II / Ethernet II packet */
55
    LLC,         /**< 802.2 LLC/SNAP Packet*/  
56
  };
57
58
  /**
50
   * Construct a EmuNetDevice
59
   * Construct a EmuNetDevice
51
   *
60
   *
52
   * This is the constructor for the EmuNetDevice.  It takes as a
61
   * This is the constructor for the EmuNetDevice.  It takes as a
 Lines 176-181    Link Here 
176
185
177
  virtual bool SupportsSendFrom (void) const;
186
  virtual bool SupportsSendFrom (void) const;
178
187
188
  /**
189
   * Set the encapsulation mode of this device.
190
   *
191
   * \param mode The encapsulation mode of this device.
192
   *
193
   * \see SetFrameSize
194
   */
195
  void SetEncapsulationMode (EmuNetDevice::EncapsulationMode mode);
196
197
  /**
198
   * Get the encapsulation mode of this device.
199
   *
200
   * \returns The encapsulation mode of this device.
201
   */
202
  EmuNetDevice::EncapsulationMode  GetEncapsulationMode (void) const;
203
179
private:
204
private:
180
205
181
  virtual void DoDispose (void);
206
  virtual void DoDispose (void);
 Lines 445-450    Link Here 
445
  int32_t m_sll_ifindex;
470
  int32_t m_sll_ifindex;
446
471
447
  /**
472
  /**
473
   * The type of packet that should be created by the AddHeader
474
   * function and that should be processed by the ProcessHeader
475
   * function.
476
   */
477
  EncapsulationMode m_encapMode;
478
479
  /**
448
   * Flag indicating whether or not the link is up.  In this case,
480
   * Flag indicating whether or not the link is up.  In this case,
449
   * whether or not the device is connected to a channel.
481
   * whether or not the device is connected to a channel.
450
   */
482
   */

Return to bug 753