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

(-)a/src/devices/tap-bridge/tap-bridge.cc (-39 / +31 lines)
 Lines 34-39    Link Here 
34
#include "ns3/realtime-simulator-impl.h"
34
#include "ns3/realtime-simulator-impl.h"
35
#include "ns3/system-thread.h"
35
#include "ns3/system-thread.h"
36
36
37
// XXX below two includes only necessary until base class NetDevice fixed
38
#include "ns3/wifi-mac.h"
39
#include "ns3/wifi-net-device.h"
40
37
#include <sys/wait.h>
41
#include <sys/wait.h>
38
#include <sys/stat.h>
42
#include <sys/stat.h>
39
#include <sys/socket.h>
43
#include <sys/socket.h>
 Lines 131-137    Link Here 
131
  m_startEvent (),
135
  m_startEvent (),
132
  m_stopEvent (),
136
  m_stopEvent (),
133
  m_readThread (0),
137
  m_readThread (0),
134
  m_learnedMac (Mac48Address ("ff:ff:ff:ff:ff:ff"))
138
  m_ns3AddressRewritten (false)
135
{
139
{
136
  NS_LOG_FUNCTION_NOARGS ();
140
  NS_LOG_FUNCTION_NOARGS ();
137
  Start (m_tStart);
141
  Start (m_tStart);
 Lines 641-647    Link Here 
641
          return;
645
          return;
642
        }
646
        }
643
647
644
      NS_LOG_INFO ("TapBridge::ReadThread(): Received packet");
648
      NS_LOG_INFO ("TapBridge::ReadThread(): Received packet on node " << m_node->GetId ());
645
      NS_LOG_INFO ("TapBridge::ReadThread(): Scheduling handler");
649
      NS_LOG_INFO ("TapBridge::ReadThread(): Scheduling handler");
646
      DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())->ScheduleRealtimeNow (
650
      DynamicCast<RealtimeSimulatorImpl> (Simulator::GetImplementation ())->ScheduleRealtimeNow (
647
        MakeEvent (&TapBridge::ForwardToBridgedDevice, this, buf, len));
651
        MakeEvent (&TapBridge::ForwardToBridgedDevice, this, buf, len));
 Lines 713-733    Link Here 
713
      //
717
      //
714
      NS_ASSERT_MSG (Mac48Address::ConvertFrom (src) != Mac48Address ("ff:ff:ff:ff:ff:ff"), 
718
      NS_ASSERT_MSG (Mac48Address::ConvertFrom (src) != Mac48Address ("ff:ff:ff:ff:ff:ff"), 
715
                     "TapBridge::ForwardToBridgedDevice:  Source addr is broadcast");
719
                     "TapBridge::ForwardToBridgedDevice:  Source addr is broadcast");
716
      //
720
      if (m_ns3AddressRewritten == false)
717
      // Remember the Mac address since we are going to spoof it when we go
721
        {
718
      // the other way.
722
          //
719
      //
723
          // Set the ns-3 device's mac address to the overlying container's
720
      m_learnedMac = Mac48Address::ConvertFrom (src);
724
          // mac address
721
      NS_LOG_LOGIC ("Learned MacAddr is " << m_learnedMac);
725
          //
722
726
          Mac48Address learned_mac = Mac48Address::ConvertFrom (src);
727
          NS_LOG_LOGIC ("Learned MacAddr is " << learned_mac << ": setting ns-3 device to use this address");
728
          m_ns3AddressRewritten = true;
729
          // Here, a call to NetDevice::SetAddress() would help, but that
730
          // method is not there yet, so here is a hack
731
          Ptr<WifiNetDevice> wfnd = DynamicCast<WifiNetDevice> (m_bridgedDevice);
732
          if (wfnd)
733
            {
734
              wfnd->GetMac ()->SetAddress (learned_mac);
735
            } 
736
        }
723
      // 
737
      // 
724
      // If we are operating in USE_LOCAL mode, we may be attached to an ns-3
738
      // If we are operating in USE_LOCAL mode, we may be attached to an ns-3
725
      // device that does not support bridging (SupportsSendFrom returns false).
739
      // device that does not support bridging (SupportsSendFrom returns false).
726
      // The whole point of this mode is really to support this case.  We allow
740
      // But, since the mac addresses are now aligned, we can call Send()
727
      // only packets from one source MAC to flow across the TapBridge in this 
728
      // mode and will spoof that address when packets flow the other way.  
729
      // Since we will be doing this spoofing, we can relax the normal bridged
730
      // device requirement to support SendFrom and use Send.
731
      //
741
      //
732
      NS_LOG_LOGIC ("Forwarding packet to ns-3 device via Send()");
742
      NS_LOG_LOGIC ("Forwarding packet to ns-3 device via Send()");
733
      m_bridgedDevice->Send (packet, dst, type);
743
      m_bridgedDevice->Send (packet, dst, type);
 Lines 864-874    Link Here 
864
    }
874
    }
865
875
866
  //
876
  //
877
  // XXX Not implemented yet
878
  // Unregister the protocol handlers for m_bridgedDevice; we own it now
879
  //
880
867
  // Tell the bridged device to forward its received packets here.  We use the 
881
  // Tell the bridged device to forward its received packets here.  We use the 
868
  // promiscuous mode hook to get both the source and destination addresses.
882
  // promiscuous mode hook to get both the source and destination addresses.
869
  //
883
  //
870
  m_node->RegisterProtocolHandler (MakeCallback (&TapBridge::ReceiveFromBridgedDevice, this), 0, bridgedDevice, true);
884
  m_node->RegisterProtocolHandler (MakeCallback (&TapBridge::ReceiveFromBridgedDevice, this), 0, bridgedDevice, true);
871
  m_bridgedDevice = bridgedDevice;
885
  m_bridgedDevice = bridgedDevice;
886
872
}
887
}
873
888
874
void
889
void
 Lines 916-947    Link Here 
916
      return;
931
      return;
917
    }
932
    }
918
933
919
  //
920
  // We have received a packet from the ns-3 net device that has been associated
921
  // with this bridge.  We want to take these bits and send them off to the tap
922
  // device on the Linux host.  The only question we have to answer is, what 
923
  // should the destination address be?
924
  //
925
  // If we are in CONFIGURE_LOCAL mode, then the destination address is just
926
  // left alone since it can only be the shared single MAC address, broadcast
927
  // or multicast.
928
  //
929
  // If we are in USE_LOCAL mode, then we need to spoof the destination 
930
  // address with the one we saved.
931
  //
932
  // If we are in USE_BRIDGE mode, then we need to do the equvalent of a 
933
  // SendFrom and leave the source and destination alone.
934
  //
935
  Mac48Address from = Mac48Address::ConvertFrom (src);
934
  Mac48Address from = Mac48Address::ConvertFrom (src);
936
  Mac48Address to;
935
  Mac48Address to = Mac48Address::ConvertFrom (dst);
937
  if (m_mode == USE_LOCAL)
938
    {
939
      to = Mac48Address::ConvertFrom (m_learnedMac);
940
    }
941
  else 
942
    {
943
      to = Mac48Address::ConvertFrom (dst);
944
    }
945
936
946
  Ptr<Packet> p = packet->Copy ();
937
  Ptr<Packet> p = packet->Copy ();
947
  EthernetHeader header = EthernetHeader (false);
938
  EthernetHeader header = EthernetHeader (false);
 Lines 956-961    Link Here 
956
  NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ());
947
  NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ());
957
  NS_LOG_LOGIC ("Pkt LengthType is " << header.GetLengthType ());
948
  NS_LOG_LOGIC ("Pkt LengthType is " << header.GetLengthType ());
958
  NS_LOG_LOGIC ("Pkt size is " << p->GetSize ());
949
  NS_LOG_LOGIC ("Pkt size is " << p->GetSize ());
950
  NS_LOG_LOGIC ("End of receive packet handling on node " << m_node->GetId ());
959
951
960
  uint32_t bytesWritten = write (m_sock, p->PeekData (), p->GetSize ());
952
  uint32_t bytesWritten = write (m_sock, p->PeekData (), p->GetSize ());
961
  NS_ABORT_MSG_IF (bytesWritten != p->GetSize (), "TapBridge::ReceiveFromBridgedDevice(): Write error.");
953
  NS_ABORT_MSG_IF (bytesWritten != p->GetSize (), "TapBridge::ReceiveFromBridgedDevice(): Write error.");
(-)a/src/devices/tap-bridge/tap-bridge.h (-6 / +3 lines)
 Lines 443-455    Link Here 
443
  /**
443
  /**
444
   * \internal
444
   * \internal
445
   *
445
   *
446
   * The MAC address of the local tap device is stored in this variable.
446
   * Whether the MAC address of the underlying ns-3 device has already been
447
   * When in UseLocal mode, this address is added back to the destination 
447
   * rewritten is stored in this variable (for UseLocal mode only).
448
   * Mac address for frames destined to the tap device.  It is learned from
449
   * the first frame sent from the host to the TapBridge device.  In the
450
   * other modes of this device, this value is unused.  
451
   */
448
   */
452
  Mac48Address m_learnedMac;
449
  bool m_ns3AddressRewritten;
453
450
454
};
451
};
455
452
(-)a/src/node/node.cc (-13 / +2 lines)
 Lines 185-207    Link Here 
185
               i != m_devices.end (); i++)
185
               i != m_devices.end (); i++)
186
            {
186
            {
187
              Ptr<NetDevice> dev = *i;
187
              Ptr<NetDevice> dev = *i;
188
              if (dev->SupportsSendFrom ())
188
              dev->SetPromiscReceiveCallback (MakeCallback (&Node::PromiscReceiveFromDevice, this));
189
                {
190
                  dev->SetPromiscReceiveCallback (MakeCallback (&Node::PromiscReceiveFromDevice, this));
191
                }
192
            }
189
            }
193
        }
190
        }
194
      else
191
      else
195
        {
192
        {
196
          if (device->SupportsSendFrom ())
193
          device->SetPromiscReceiveCallback (MakeCallback (&Node::PromiscReceiveFromDevice, this));
197
            {
198
              device->SetPromiscReceiveCallback (MakeCallback (&Node::PromiscReceiveFromDevice, this));
199
            }
200
          else
201
            {
202
              NS_LOG_WARN ("Protocol handler request promiscuous mode for a specific netdevice,"
203
                           " but netdevice does not support promiscuous mode.");
204
            }
205
        }
194
        }
206
    }
195
    }
207
196

Return to bug 569