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

(-)a/src/tap-bridge/model/tap-bridge.cc (-20 / +36 lines)
 Lines 39-67    Link Here 
39
#include <sys/stat.h>
39
#include <sys/stat.h>
40
#include <sys/socket.h>
40
#include <sys/socket.h>
41
#include <sys/un.h>
41
#include <sys/un.h>
42
#include <sys/ioctl.h>
43
#include <net/if.h>
42
#include <cerrno>
44
#include <cerrno>
43
#include <limits>
45
#include <limits>
44
#include <cstdlib>
46
#include <cstdlib>
45
#include <unistd.h>
47
#include <unistd.h>
46
48
47
//
48
// Sometimes having a tap-creator is actually more trouble than solution.  In 
49
// these cases you can uncomment the define of TAP_CREATOR below and the 
50
// simulation will just use a device you have preconfigured.  This is useful
51
// if you are running in an environment where you have got to run as root,
52
// such as ORBIT or CORE.
53
//
54
55
56
// #define NO_CREATOR
57
58
#ifdef NO_CREATOR
59
#include <fcntl.h>
60
#include <net/if.h>
61
#include <linux/if_tun.h>
62
#include <sys/ioctl.h>
63
#endif
64
65
NS_LOG_COMPONENT_DEFINE ("TapBridge");
49
NS_LOG_COMPONENT_DEFINE ("TapBridge");
66
50
67
namespace ns3 {
51
namespace ns3 {
 Lines 630-636    Link Here 
630
                  int *rawSocket = (int*)CMSG_DATA (cmsg);
614
                  int *rawSocket = (int*)CMSG_DATA (cmsg);
631
                  NS_LOG_INFO ("Got the socket from the socket creator = " << *rawSocket);
615
                  NS_LOG_INFO ("Got the socket from the socket creator = " << *rawSocket);
632
                  m_sock = *rawSocket;
616
                  m_sock = *rawSocket;
633
                  return;
617
                  break;
634
                }
618
                }
635
              else
619
              else
636
                {
620
                {
 Lines 638-645    Link Here 
638
                }
622
                }
639
            }
623
            }
640
        }
624
        }
641
      NS_FATAL_ERROR ("Did not get the raw socket from the socket creator");
625
      if (cmsg == NULL)
626
        {
627
          NS_FATAL_ERROR ("Did not get the raw socket from the socket creator");
628
        }
629
630
      if (m_mode == USE_LOCAL || m_mode == USE_BRIDGE)
631
        {
632
          //
633
          // Set the ns-3 device's mac address to the overlying container's
634
          // mac address
635
          //
636
          struct ifreq s;
637
          strncpy (s.ifr_name, m_tapDeviceName.c_str (), sizeof (s.ifr_name));
638
639
          NS_LOG_INFO ("Trying to get MacAddr of " << m_tapDeviceName);
640
          int ioctlResult = ioctl (sock, SIOCGIFHWADDR, &s);
641
          if (ioctlResult == 0)
642
            {
643
              Mac48Address learnedMac;
644
              learnedMac.CopyFrom ((uint8_t *)s.ifr_hwaddr.sa_data);
645
              NS_LOG_INFO ("Learned Tap device MacAddr is " << learnedMac << ": setting ns-3 device to use this address");
646
              m_bridgedDevice->SetAddress (learnedMac);
647
              m_ns3AddressRewritten = true;
648
            }
649
650
          if (!m_ns3AddressRewritten)
651
            {
652
              NS_LOG_INFO ("Cannot get MacAddr of Tap device: " << m_tapDeviceName << " while in USE_LOCAL/USE_BRIDGE mode: " << std::strerror (errno));
653
              NS_LOG_INFO ("Underlying ns-3 device will continue to use default address, what can lead to connectivity errors");
654
            }
655
        }
642
    }
656
    }
657
658
  close (sock);
643
}
659
}
644
660
645
void
661
void
(-)a/src/tap-bridge/model/tap-bridge.h (-1 / +1 lines)
 Lines 448-454    Link Here 
448
   * \internal
448
   * \internal
449
   *
449
   *
450
   * Whether the MAC address of the underlying ns-3 device has already been
450
   * Whether the MAC address of the underlying ns-3 device has already been
451
   * rewritten is stored in this variable (for UseLocal mode only).
451
   * rewritten is stored in this variable (for UseLocal/UseBridge mode only).
452
   */
452
   */
453
  bool m_ns3AddressRewritten;
453
  bool m_ns3AddressRewritten;
454
454

Return to bug 1777