support umip(mip6d) with ns-3-linux for NEMO/MIP6
diff -r e503e546d382 model/dce-fd.cc
--- a/model/dce-fd.cc Mon Apr 09 10:03:33 2012 +0900
+++ b/model/dce-fd.cc Wed Apr 11 09:28:15 2012 +0900
@@ -367,11 +367,30 @@
}
UnixFd *socket = factory->CreateSocket (domain, type, protocol);
+ if (!socket)
+ return -1;
socket->IncFdCount ();
current->process->openFiles[fd] = new FileUsage (fd, socket);
return fd;
}
+int dce_socketpair (int domain, int type, int protocol, int sv[2])
+{
+ sv[0] = dce_socket (domain, type, protocol);
+ if (sv[0] < 0)
+ {
+ return -1;
+ }
+
+ sv[1] = dce_socket (domain, type, protocol);
+ if (sv[1] < 0)
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
int dce_bind (int fd, const struct sockaddr *my_addr, socklen_t addrlen)
{
Thread *current = Current ();
diff -r e503e546d382 model/dce-manager.cc
--- a/model/dce-manager.cc Mon Apr 09 10:03:33 2012 +0900
+++ b/model/dce-manager.cc Wed Apr 11 09:28:15 2012 +0900
@@ -1096,6 +1096,22 @@
libpthread_setup = (void (*)(const struct Libc *))(symbol);
libpthread_setup (libc);
+ h = ld->Load ("librt-ns3.so", RTLD_GLOBAL);
+ if (h == 0)
+ {
+ err = ENOMEM;
+ return 0;
+ }
+ symbol = ld->Lookup (h, "librt_setup");
+ if (symbol == 0)
+ {
+ NS_FATAL_ERROR ("This is not our fake librt !");
+ }
+ // construct librt now
+ void (*librt_setup)(const struct Libc *fn);
+ librt_setup = (void (*)(const struct Libc *))(symbol);
+ librt_setup (libc);
+
// finally, call into 'main'.
h = ld->Load (filename, RTLD_GLOBAL);
diff -r e503e546d382 model/dce-poll.cc
--- a/model/dce-poll.cc Mon Apr 09 10:03:33 2012 +0900
+++ b/model/dce-poll.cc Wed Apr 11 09:28:15 2012 +0900
@@ -180,7 +180,12 @@
}
}
nfds = eventByFd.size ();
- if (nfds == 0)
+
+ // select(2):
+ // Some code calls select() with all three sets empty, nfds zero, and a
+ // non-NULL timeout as a fairly portable way to sleep with subsecond
+ // precision.
+ if (nfds == 0 && !timeout)
{
current->err = EINVAL;
return -1;
diff -r e503e546d382 model/dce-signal.cc
--- a/model/dce-signal.cc Mon Apr 09 10:03:33 2012 +0900
+++ b/model/dce-signal.cc Wed Apr 11 09:28:15 2012 +0900
@@ -3,6 +3,7 @@
#include "process.h"
#include "ns3/log.h"
#include "ns3/assert.h"
+#include "waiter.h"
#include <vector>
#include <errno.h>
@@ -98,6 +99,18 @@
return 0;
}
+
+int dce_sigwait (const sigset_t *set, int *sig)
+{
+ int ret = 0;
+ // current->process->signalHandlers.push_back (handler);
+
+ Waiter waiter;
+ waiter.SetTimeout (Seconds (0.0));
+ waiter.WaitDoSignal ();
+
+ return ret;
+}
int dce_sigprocmask(int how, const sigset_t *set, sigset_t *oldset)
{
Thread *current = Current ();
diff -r e503e546d382 model/dce-signal.h
--- a/model/dce-signal.h Mon Apr 09 10:03:33 2012 +0900
+++ b/model/dce-signal.h Wed Apr 11 09:28:15 2012 +0900
@@ -17,6 +17,7 @@
int dce_pthread_kill (pthread_t thread, int sig);
void dce_abort ();
int dce_sigprocmask(int how, const sigset_t *set, sigset_t *oldset);
+int dce_sigwait (const sigset_t *set, int *sig);
#ifdef __cplusplus
}
diff -r e503e546d382 model/dce-time.cc
--- a/model/dce-time.cc Mon Apr 09 10:03:33 2012 +0900
+++ b/model/dce-time.cc Wed Apr 11 09:28:15 2012 +0900
@@ -54,3 +54,12 @@
return asctime_r (tm, Current ()->process->asctime_result);
}
+
+int dce_clock_gettime(clockid_t which_clock, struct timespec *tp)
+{
+ NS_LOG_FUNCTION (Current () << UtilsGetNodeId ());
+ NS_ASSERT (Current () != 0);
+ NS_ASSERT (tp != 0);
+ *tp = UtilsTimeToTimespec (UtilsSimulationTimeToTime (Now ()));
+ return 0;
+}
diff -r e503e546d382 model/dce-time.h
--- a/model/dce-time.h Mon Apr 09 10:03:33 2012 +0900
+++ b/model/dce-time.h Wed Apr 11 09:28:15 2012 +0900
@@ -3,6 +3,7 @@
#include "sys/dce-time.h"
#include <time.h>
+#include <sys/sysinfo.h>
#ifdef __cplusplus
extern "C" {
@@ -13,6 +14,8 @@
struct tm *dce_localtime(const time_t *timep);
char *dce_ctime(const time_t *timep);
char *dce_asctime(const struct tm *tm);
+int dce_clock_gettime(clockid_t which_clock, struct timespec *tp);
+int dce_sysinfo (struct sysinfo *info);
#ifdef __cplusplus
}
diff -r e503e546d382 model/dce.cc
--- a/model/dce.cc Mon Apr 09 10:03:33 2012 +0900
+++ b/model/dce.cc Wed Apr 11 09:28:15 2012 +0900
@@ -22,6 +22,8 @@
#include <getopt.h>
#include <limits.h>
#include <fcntl.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
#include "dce-random.h"
#include "net/dce-if.h"
#include "ns3/node.h"
@@ -30,6 +32,7 @@
#include "ns3/names.h"
#include "ns3/random-variable.h"
#include "ns3/ipv4-l3-protocol.h"
+#include "socket-fd-factory.h"
NS_LOG_COMPONENT_DEFINE ("Dce");
@@ -639,20 +642,60 @@
}
unsigned dce_if_nametoindex (const char *ifname)
{
- int index = 0;
- Ptr<Node> node = Current ()->process->manager->GetObject<Node> ();
- Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
+ Thread *current = Current ();
+ Ptr<SocketFdFactory> factory = 0;
+ factory = current->process->manager->GetObject<SocketFdFactory> ();
- for (uint32_t i = 0; i < node->GetNDevices (); ++i)
+ if (factory->GetInstanceTypeId () == TypeId::LookupByName ("ns3::LinuxSocketFdFactory"))
{
- Ptr<NetDevice> dev = node->GetDevice (i);
- if (ifname == Names::FindName (dev))
+ struct ifreq ifr;
+ int fd = dce_socket (AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0)
{
- index = ipv4->GetInterfaceForDevice (dev);
- return index;
+ return 0;
}
+
+ strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
+ if (dce_ioctl (fd, SIOCGIFINDEX, (char *)&ifr) < 0)
+ {
+ current->err = errno;
+ return -1;
+ }
+ return ifr.ifr_ifindex;
}
- return 0;
+ else
+ {
+ int index = 0;
+ Ptr<Node> node = Current ()->process->manager->GetObject<Node> ();
+ Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
+
+ for (uint32_t i = 0; i < node->GetNDevices (); ++i)
+ {
+ Ptr<NetDevice> dev = node->GetDevice (i);
+ if (ifname == Names::FindName (dev))
+ {
+ index = ipv4->GetInterfaceForDevice (dev);
+ return index;
+ }
+ }
+ return 0;
+ }
+}
+char *dce_if_indextoname (unsigned ifindex, char *ifname)
+{
+ struct ifreq ifr;
+ int fd = dce_socket (AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0)
+ {
+ return 0;
+ }
+
+ ifr.ifr_ifindex = ifindex;
+ if (dce_ioctl (fd, SIOCGIFNAME, (char *)&ifr) < 0)
+ {
+ return 0;
+ }
+ return strncpy (ifname, ifr.ifr_name, IFNAMSIZ);
}
pid_t dce_fork (void)
{
@@ -849,6 +892,21 @@
static char loc[] = "";
return loc;
}
+int dce_sysinfo (struct sysinfo *info)
+{
+ Thread *current = Current ();
+ NS_LOG_FUNCTION (current << UtilsGetNodeId ());
+ NS_ASSERT (current != 0);
+ if (!info)
+ {
+ current->err = ENAMETOOLONG;
+ return -1;
+ }
+
+ info->uptime = (long)UtilsSimulationTimeToTime (Now ()).GetSeconds ();
+ // XXX
+ return 0;
+}
#ifdef HAVE_GETCPUFEATURES
extern "C"
{
diff -r e503e546d382 model/elf-cache.cc
--- a/model/elf-cache.cc Mon Apr 09 10:03:33 2012 +0900
+++ b/model/elf-cache.cc Wed Apr 11 09:28:15 2012 +0900
@@ -26,6 +26,9 @@
overriden.from = "libpthread.so.0";
overriden.to = "libpthread-ns3.so";
m_overriden.push_back (overriden);
+ overriden.from = "librt.so.1";
+ overriden.to = "librt-ns3.so";
+ m_overriden.push_back (overriden);
}
std::string
diff -r e503e546d382 model/libc-dce.cc
--- a/model/libc-dce.cc Mon Apr 09 10:03:33 2012 +0900
+++ b/model/libc-dce.cc Wed Apr 11 09:28:15 2012 +0900
@@ -52,6 +52,7 @@
#include <netdb.h>
#include <net/if.h>
#include <netinet/in.h>
+#include <netinet/ether.h>
#include <poll.h>
#include <semaphore.h>
#include <signal.h>
diff -r e503e546d382 model/libc-ns3.h
--- a/model/libc-ns3.h Mon Apr 09 10:03:33 2012 +0900
+++ b/model/libc-ns3.h Wed Apr 11 09:28:15 2012 +0900
@@ -73,6 +73,7 @@
NATIVE (ntohl)
NATIVE (ntohs)
DCE (socket)
+DCE (socketpair)
DCE (getsockname)
DCE (getpeername)
DCE (bind)
@@ -214,6 +215,7 @@
DCE (setregid)
DCE (setresuid)
DCE (setresgid)
+NATIVE (lockf)
NATIVE (inet_aton)
NATIVE (inet_ntoa)
DCE (inet_ntop)
@@ -223,6 +225,8 @@
NATIVE (inet_lnaof)
NATIVE (inet_netof)
NATIVE (inet_addr)
+NATIVE (inet6_opt_find)
+NATIVE (ether_aton)
DCE (mmap)
DCE (mmap64)
DCE (munmap)
@@ -254,6 +258,7 @@
DCE (realloc)
DCE (gettimeofday)
DCE (time)
+DCE (sysinfo)
DCE (isatty)
DCE (send)
DCE (sendto)
@@ -279,6 +284,7 @@
NATIVE (sigaddset)
NATIVE (sigdelset)
NATIVE (sigismember)
+DCE (sigwait)
DCE_WITH_ALIAS2(strtol, __strtol_internal)
DCET (long long int, strtoll)
DCE (strtoul)
@@ -343,6 +349,13 @@
DCE (pthread_cond_wait)
DCE (pthread_condattr_destroy)
DCE (pthread_condattr_init)
+NATIVE (pthread_rwlock_init)
+NATIVE (pthread_rwlock_unlock)
+NATIVE (pthread_rwlock_wrlock)
+NATIVE (pthread_rwlock_rdlock)
+NATIVE (pthread_rwlock_destroy)
+NATIVE (pthread_setcancelstate)
+NATIVE (pthread_sigmask)
// netdb.h
DCE (gethostbyname)
@@ -381,6 +394,7 @@
DCE (timerfd_gettime)
DCE (if_nametoindex)
+DCE (if_indextoname)
DCE (fork)
NATIVE (qsort)
@@ -442,8 +456,8 @@
NATIVE (pathconf)
// this is wrong. clock should be changed to DCE implementation
-//DCE (__vdso_clock_gettime)
-NATIVE_WITH_ALIAS2 (clock_gettime, __vdso_clock_gettime)
+DCE_WITH_ALIAS2 (clock_gettime, __vdso_clock_gettime)
+//NATIVE_WITH_ALIAS2 (clock_gettime, __vdso_clock_gettime)
// setjmp.h
NATIVE (__sigsetjmp)
diff -r e503e546d382 model/librt-ns3.version
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/model/librt-ns3.version Wed Apr 11 09:28:15 2012 +0900
@@ -0,0 +1,4 @@
+NS3 {
+global:
+ librt_setup;
+};
diff -r e503e546d382 model/linux-socket-fd-factory.cc
--- a/model/linux-socket-fd-factory.cc Mon Apr 09 10:03:33 2012 +0900
+++ b/model/linux-socket-fd-factory.cc Wed Apr 11 09:28:15 2012 +0900
@@ -464,6 +464,7 @@
void
LinuxSocketFdFactory::SetTask (std::string path, std::string value)
{
+ NS_LOG_FUNCTION (path << value);
std::vector<std::pair<std::string,struct SimSysFile *> > files = GetSysFileList ();
for (uint32_t i = 0; i < files.size (); i++)
{
@@ -537,6 +538,7 @@
this));
Set (".net.ipv4.conf.all.forwarding", "1");
Set (".net.ipv4.conf.all.log_martians", "1");
+ Set (".net.ipv6.conf.all.forwarding", "0");
while (!m_earlySysfs.empty ())
{
diff -r e503e546d382 model/linux-socket-fd.cc
--- a/model/linux-socket-fd.cc Mon Apr 09 10:03:33 2012 +0900
+++ b/model/linux-socket-fd.cc Wed Apr 11 09:28:15 2012 +0900
@@ -177,6 +177,7 @@
return 0;
break;
default:
+ return 0;
//XXX commands missing
NS_FATAL_ERROR ("fcntl not implemented on socket");
return -1;
diff -r e503e546d382 model/net/dce-if.h
--- a/model/net/dce-if.h Mon Apr 09 10:03:33 2012 +0900
+++ b/model/net/dce-if.h Wed Apr 11 09:28:15 2012 +0900
@@ -7,6 +7,7 @@
#endif
unsigned dce_if_nametoindex (const char *ifname);
+char *dce_if_indextoname (unsigned ifindex, char *ifname);
#ifdef __cplusplus
diff -r e503e546d382 model/ns3-socket-fd-factory.cc
--- a/model/ns3-socket-fd-factory.cc Mon Apr 09 10:03:33 2012 +0900
+++ b/model/ns3-socket-fd-factory.cc Wed Apr 11 09:28:15 2012 +0900
@@ -142,7 +142,8 @@
}
else
{
- NS_FATAL_ERROR ("unsupported domain");
+ // NS_FATAL_ERROR ("unsupported domain");
+ return 0;
}
return socket;
diff -r e503e546d382 model/sys/dce-socket.h
--- a/model/sys/dce-socket.h Mon Apr 09 10:03:33 2012 +0900
+++ b/model/sys/dce-socket.h Wed Apr 11 09:28:15 2012 +0900
@@ -28,6 +28,7 @@
ssize_t dce_sendmsg(int s, const struct msghdr *msg, int flags);
int dce_getsockname(int s, struct sockaddr *name, socklen_t *namelen);
int dce_getpeername(int s, struct sockaddr *name, socklen_t *namelen);
+int dce_socketpair (int domain, int type, int protocol, int sv[2]);
#ifdef __cplusplus
}
diff -r e503e546d382 wscript
--- a/wscript Mon Apr 09 10:03:33 2012 +0900
+++ b/wscript Wed Apr 11 09:28:15 2012 +0900
@@ -26,7 +26,7 @@
ns3waf.check_modules(conf, ['point-to-point', 'tap-bridge', 'netanim'], mandatory = False)
ns3waf.check_modules(conf, ['wifi', 'point-to-point', 'csma', 'mobility'], mandatory = False)
ns3waf.check_modules(conf, ['point-to-point-layout'], mandatory = False)
- ns3waf.check_modules(conf, ['topology-read', 'applications'], mandatory = False)
+ ns3waf.check_modules(conf, ['topology-read', 'applications', 'visualizer'], mandatory = False)
conf.check_tool('compiler_cc')
conf.check(header_name='stdint.h', define_name='HAVE_STDINT_H', mandatory=False)
conf.check(header_name='inttypes.h', define_name='HAVE_INTTYPES_H', mandatory=False)
@@ -71,6 +71,17 @@
conf.end_msg(libpthread, True)
conf.env['LIBPTHREAD_FILE'] = libpthread
+ conf.start_msg('Searching rt library')
+ librt = search_file ([
+ '/lib64/librt.so.1',
+ '/lib/librt.so.1',
+ ])
+ if librt is None:
+ conf.fatal('not found')
+ else:
+ conf.end_msg(librt, True)
+ conf.env['LIBRT_FILE'] = librt
+
conf.find_program('readversiondef', var='READVERSIONDEF', mandatory=True)
if Options.options.kernel_stack is not None and os.path.isdir(Options.options.kernel_stack):
@@ -426,6 +437,11 @@
rule='%s %s | cat ${SRC[0].abspath()} - > ${TGT}' %
(bld.env['READVERSIONDEF'], bld.env['LIBPTHREAD_FILE']))
+ bld(source=['model/librt-ns3.version'],
+ target='model/librt.version',
+ rule='%s %s | cat ${SRC[0].abspath()} - > ${TGT}' %
+ (bld.env['READVERSIONDEF'], bld.env['LIBRT_FILE']))
+
bld.add_group('dce_use_version_files')
# The very small libc used to replace the glibc
@@ -445,3 +461,13 @@
linkflags=['-nostdlib', '-lc',
'-Wl,--version-script=' + os.path.join('model', 'libpthread.version'),
'-Wl,-soname=libpthread.so.0'])
+
+ # The very small librt used to replace the glibc
+ # and forward to the dce_* code
+ bld.shlib(source = ['model/libc.cc', 'model/libc-setup.cc'],
+ target='lib/rt-ns3', cflags=['-g'],
+ defines=['LIBSETUP=librt_setup'],
+ linkflags=['-nostdlib', '-lc',
+ '-Wl,--version-script=' + os.path.join('model', 'librt.version'),
+ '-Wl,-soname=librt.so.1'])
+