src/devices/serial/serial-net-device.cc
changeset 345 47b41507a45a
parent 342 ceb372b1309c
child 350 32f443f96560
equal deleted inserted replaced
344:b547ec7dbbc1 345:47b41507a45a
    21 
    21 
    22 #include <iostream>
    22 #include <iostream>
    23 #include <cassert>
    23 #include <cassert>
    24 #include "ns3/debug.h"
    24 #include "ns3/debug.h"
    25 #include "ns3/queue.h"
    25 #include "ns3/queue.h"
       
    26 #include "ns3/composite-trace-resolver.h"
    26 #include "serial-net-device.h"
    27 #include "serial-net-device.h"
    27 #include "serial-channel.h"
    28 #include "serial-channel.h"
    28 #include "serial-phy.h"
    29 #include "serial-phy.h"
    29 
    30 
    30 NS_DEBUG_COMPONENT_DEFINE ("SerialNetDevice");
    31 NS_DEBUG_COMPONENT_DEFINE ("SerialNetDevice");
    49 }
    50 }
    50 
    51 
    51 SerialNetDevice::~SerialNetDevice()
    52 SerialNetDevice::~SerialNetDevice()
    52 {
    53 {
    53   NS_DEBUG ("SerialNetDevice::~SerialNetDevice ()");
    54   NS_DEBUG ("SerialNetDevice::~SerialNetDevice ()");
       
    55   delete m_phy;
    54 }
    56 }
    55 
    57 
    56 
    58 
    57   bool
    59 bool
    58 SerialNetDevice::SendTo (Packet& p, const MacAddress& dest)
    60 SerialNetDevice::SendTo (Packet& p, const MacAddress& dest)
    59 {
    61 {
    60   NS_DEBUG ("SerialNetDevice::SendTo (" << &p << ", " << &dest << ")");
    62   NS_DEBUG ("SerialNetDevice::SendTo (" << &p << ", " << &dest << ")");
    61 
    63 
    62   assert (IsLinkUp ());
    64   assert (IsLinkUp ());
    72         return true;
    74         return true;
    73       }
    75       }
    74     return false;
    76     return false;
    75 }
    77 }
    76 
    78 
    77   bool
    79 TraceResolver *
       
    80 SerialNetDevice::DoCreateTraceResolver (TraceContext const &context)
       
    81 {
       
    82   CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
       
    83   resolver->Add ("queue", 
       
    84                  MakeCallback (&Queue::CreateTraceResolver, m_queue),
       
    85                  SerialNetDevice::QUEUE);
       
    86   return resolver;
       
    87 }
       
    88 
       
    89 bool
    78 SerialNetDevice::Attach (SerialChannel* ch)
    90 SerialNetDevice::Attach (SerialChannel* ch)
    79 {
    91 {
    80   NS_DEBUG ("SerialNetDevice::Attach (" << &ch << ")");
    92   NS_DEBUG ("SerialNetDevice::Attach (" << &ch << ")");
    81 
    93 
    82   m_channel = ch;
    94   m_channel = ch;
       
    95   m_phy->Attach (m_channel);
    83   /* 
    96   /* 
    84    * For now, this device is up whenever a channel is attached to it.
    97    * For now, this device is up whenever a channel is attached to it.
    85    * In fact, it should become up only when the second device
    98    * In fact, it should become up only when the second device
    86    * is attached to the channel. So, there should be a way for
    99    * is attached to the channel. So, there should be a way for
    87    * a SerialChannel to notify both of its attached devices
   100    * a SerialChannel to notify both of its attached devices
   104 SerialNetDevice::Receive (Packet& p)
   117 SerialNetDevice::Receive (Packet& p)
   105 {
   118 {
   106   // ignore return value for now.
   119   // ignore return value for now.
   107   NS_DEBUG ("SerialNetDevice::Receive (" << &p << ")");
   120   NS_DEBUG ("SerialNetDevice::Receive (" << &p << ")");
   108 
   121 
   109   // Dispatch this to SerialPhy::Receive
   122   ForwardUp (p);
   110   m_phy->Receive (p);
       
   111 }
   123 }
   112 
   124 
   113 void
   125 void
   114 SerialNetDevice::NotifyDataAvailable(void)
   126 SerialNetDevice::NotifyDataAvailable(void)
   115 {
   127 {
   123       struct NetDevicePacketDestAddress tag;
   135       struct NetDevicePacketDestAddress tag;
   124       p.PeekTag (tag);
   136       p.PeekTag (tag);
   125       // send packet to address tag.address
   137       // send packet to address tag.address
   126 #endif
   138 #endif
   127       NS_DEBUG ("SerialNetDevice::NotifyDataAvailable (): Dequeued");
   139       NS_DEBUG ("SerialNetDevice::NotifyDataAvailable (): Dequeued");
   128       m_channel->Propagate(p, this);
   140       m_phy->Send(p);
   129     }
   141     }
   130 }
   142 }
   131 
   143 
   132 Queue* 
   144 Queue* 
   133 SerialNetDevice::GetQueue(void) const 
   145 SerialNetDevice::GetQueue(void) const