param is a 16 bit integer. implement proper llc encapsulation/decapsulation
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 28 Jul 2007 13:15:04 +0200
changeset 99522821dd9152e
parent 994 a7252b11c8d2
child 996 3888206177b8
param is a 16 bit integer. implement proper llc encapsulation/decapsulation
src/devices/csma-cd/csma-cd-net-device.cc
src/devices/csma-cd/csma-cd-net-device.h
     1.1 --- a/src/devices/csma-cd/csma-cd-net-device.cc	Sat Jul 28 13:14:24 2007 +0200
     1.2 +++ b/src/devices/csma-cd/csma-cd-net-device.cc	Sat Jul 28 13:15:04 2007 +0200
     1.3 @@ -150,65 +150,76 @@
     1.4  }
     1.5  void 
     1.6  CsmaCdNetDevice::AddHeader (Packet& p, const MacAddress& dest,
     1.7 -                                  uint16_t protocolNumber)
     1.8 +                            uint16_t protocolNumber)
     1.9  {
    1.10 -  if ((m_encapMode == ETHERNET_V1) || (m_encapMode == IP_ARP))
    1.11 +  if (m_encapMode == RAW)
    1.12      {
    1.13 -      EthernetHeader  header;
    1.14 -      EthernetTrailer trailer;
    1.15 -      
    1.16 -      header.SetSource(this->GetAddress());
    1.17 -      header.SetDestination(dest);
    1.18 -      switch (m_encapMode)
    1.19 -        {
    1.20 -        case IP_ARP:
    1.21 -          header.SetLengthType(protocolNumber);
    1.22 -          break;
    1.23 -        default:
    1.24 -          header.SetLengthType(p.GetSize() + header.GetSize() + trailer.GetSize());
    1.25 -          break;
    1.26 -        }
    1.27 -      p.AddHeader(header);
    1.28 -      trailer.CalcFcs(p);
    1.29 -      p.AddTrailer(trailer);
    1.30 -    } 
    1.31 -  else if (m_encapMode == LLC) 
    1.32 +      return;
    1.33 +    }
    1.34 +  EthernetHeader header (false);
    1.35 +  EthernetTrailer trailer;
    1.36 +  header.SetSource(this->GetAddress());
    1.37 +  header.SetDestination(dest);
    1.38 +
    1.39 +  uint16_t lengthType;
    1.40 +  switch (m_encapMode) 
    1.41      {
    1.42 +    case ETHERNET_V1:
    1.43 +      lengthType = p.GetSize() + header.GetSize() + trailer.GetSize();
    1.44 +      break;
    1.45 +    case IP_ARP:
    1.46 +      lengthType = protocolNumber;
    1.47 +      break;
    1.48 +    case LLC: {
    1.49        LlcSnapHeader llc;
    1.50        llc.SetType (protocolNumber);
    1.51        p.AddHeader (llc);
    1.52 +    } break;
    1.53 +    case RAW:
    1.54 +      NS_ASSERT (false);
    1.55 +      break;
    1.56      }
    1.57 +  header.SetLengthType (lengthType);
    1.58 +  p.AddHeader(header);
    1.59 +  trailer.CalcFcs(p);
    1.60 +  p.AddTrailer(trailer);
    1.61  }
    1.62  bool 
    1.63 -CsmaCdNetDevice::ProcessHeader(Packet& p, int& param)
    1.64 +CsmaCdNetDevice::ProcessHeader (Packet& p, uint16_t & param)
    1.65  {
    1.66 -  bool retVal = true;
    1.67 +  if (m_encapMode == RAW)
    1.68 +    {
    1.69 +      return true;
    1.70 +    }
    1.71 +  EthernetHeader header (false);
    1.72 +  EthernetTrailer trailer;
    1.73 +      
    1.74 +  p.RemoveTrailer(trailer);
    1.75 +  trailer.CheckFcs(p);
    1.76 +  p.RemoveHeader(header);
    1.77  
    1.78 -  if ((m_encapMode == ETHERNET_V1) || (m_encapMode == IP_ARP))
    1.79 +  if ((header.GetDestination() != this->GetBroadcast()) &&
    1.80 +      (header.GetDestination() != this->GetAddress()))
    1.81      {
    1.82 -      EthernetHeader  header;
    1.83 -      EthernetTrailer trailer;
    1.84 -      
    1.85 -      p.RemoveTrailer(trailer);
    1.86 -      trailer.CheckFcs(p);
    1.87 -      p.RemoveHeader(header);
    1.88 -      
    1.89 +      return false;
    1.90 +    }
    1.91 +
    1.92 +  switch (m_encapMode)
    1.93 +    {
    1.94 +    case ETHERNET_V1:
    1.95 +    case IP_ARP:
    1.96        param = header.GetLengthType();
    1.97 -      if ((header.GetDestination() != this->GetBroadcast()) &&
    1.98 -          (header.GetDestination() != this->GetAddress()))
    1.99 -        {
   1.100 -          retVal = false;
   1.101 -        }
   1.102 -    }
   1.103 -  else if (m_encapMode == LLC)
   1.104 -    {
   1.105 +      break;
   1.106 +    case LLC: {
   1.107        LlcSnapHeader llc;
   1.108        p.RemoveHeader (llc);
   1.109 -
   1.110        param = llc.GetType ();
   1.111 +    } break;
   1.112 +    case RAW:
   1.113 +      NS_ASSERT (false);
   1.114 +      break;
   1.115      }
   1.116 -
   1.117 -  return retVal;
   1.118 +  return true;
   1.119  }
   1.120  
   1.121  bool
   1.122 @@ -440,14 +451,16 @@
   1.123    if (!IsReceiveEnabled())
   1.124      return;
   1.125  
   1.126 -  int param = 0;
   1.127 +  uint16_t param = 0;
   1.128    Packet packet = p;
   1.129  
   1.130    if (ProcessHeader(packet, param))
   1.131      {
   1.132        m_rxTrace (packet);
   1.133        ForwardUp (packet, param);
   1.134 -    } else {
   1.135 +    } 
   1.136 +  else 
   1.137 +    {
   1.138        m_dropTrace (packet);
   1.139      }
   1.140  }
     2.1 --- a/src/devices/csma-cd/csma-cd-net-device.h	Sat Jul 28 13:14:24 2007 +0200
     2.2 +++ b/src/devices/csma-cd/csma-cd-net-device.h	Sat Jul 28 13:15:04 2007 +0200
     2.3 @@ -222,7 +222,7 @@
     2.4     * \return Returns true if the packet should be forwarded up the
     2.5     * protocol stack.
     2.6     */
     2.7 -  bool ProcessHeader (Packet& p, int& param);
     2.8 +  bool ProcessHeader (Packet& p, uint16_t & param);
     2.9  
    2.10  private:
    2.11    // disable copy constructor and operator =