Add CCNx sample. before_ns3.11
authorfrederic.urbani@inria.fr
Fri, 24 Jun 2011 17:01:03 +0200
changeset 113 858825f2de97
parent 112 b511169523f5
child 114 4db294457161
child 115 f9b5b78b896a
Add CCNx sample.
example/ccnx/README
example/ccnx/dce-ccnd-linear-multiple.cc
example/ccnx/dce-ccnd-simple.cc
example/ccnx/run-ccnd-linear-multiple.sh
example/ccnx/run-ccnx-common.sh
example/udp-echo-client.cc
example/udp-echo-server.cc
model/utils.cc
wscript
--- a/example/ccnx/README	Mon Jun 20 13:00:21 2011 +0200
+++ b/example/ccnx/README	Fri Jun 24 17:01:03 2011 +0200
@@ -32,4 +32,3 @@
 Si tu peux lire ca ca marche !
 Si tu peux lire ca ca marche !
 Si tu peux lire ca ca marche !
-Si tu peux lire ca ca marche !
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/ccnx/dce-ccnd-linear-multiple.cc	Fri Jun 24 17:01:03 2011 +0200
@@ -0,0 +1,188 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  Author: Frederic Urbani <frederic.urbani@inria.fr>
+ *
+*/
+
+#include "ns3/network-module.h"
+#include "ns3/core-module.h"
+#include "ns3/internet-module.h"
+#include "ns3/dce-module.h"
+#include "ns3/point-to-point-helper.h"
+
+using namespace ns3;
+//
+// Network topology
+//     1   2  3   4  5   6
+//  n0 ---  n1 --- n2 --- nx  1Gbps, 2ms
+//
+// Every node run a ccnd daemon,
+//
+// node 0 put a file and node X get the file
+//
+//
+NS_LOG_COMPONENT_DEFINE ("CcndInLine");
+
+static std::string Ipv4AddressToString (Ipv4Address ad)
+{
+  std::ostringstream oss;
+  ad.Print (oss);
+  return oss.str ();
+}
+
+int main (int argc, char *argv[])
+{
+  //
+  // Default number of nodes.  Overridable by command line argument.
+  //
+  uint32_t nNodes = 8;
+  bool useTcp = 0;
+
+  CommandLine cmd;
+  cmd.AddValue("nNodes", "Number of nodes to place in the line", nNodes);
+  cmd.AddValue ("tcp", "Use TCP to link ccnd daemons.", useTcp);
+  cmd.Parse (argc, argv);
+
+  NS_LOG_INFO( "useTcp: " << useTcp );
+
+  NodeContainer nodes;
+  nodes.Create (nNodes);
+
+  PointToPointHelper pointToPoint;
+  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("1000Mbps"));
+  pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
+
+  Ipv4AddressHelper address;
+  address.SetBase ("10.0.0.0", "255.255.0.0");
+
+  InternetStackHelper stack;
+  stack.Install (nodes);
+
+  NetDeviceContainer devices;
+  std::vector<Ipv4InterfaceContainer> vInterfaces;
+
+  for (int n=0; n < (nNodes-1) ; n++)
+    {
+      devices = pointToPoint.Install (nodes.Get (n), nodes.Get ( 1 + n ) );
+      Ipv4InterfaceContainer interfaces = address.Assign (devices);
+      address.NewNetwork ();
+      vInterfaces.push_back ( interfaces );
+    }
+
+  // setup ip routes
+  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
+
+  DceManagerHelper dceManager;
+  dceManager.Install (nodes);
+
+  DceApplicationHelper dce;
+  ApplicationContainer apps;
+
+  // Install ccnd on each node
+  for (int n=0; n < nNodes ; n++)
+    {
+      dce.SetStackSize (1 << 20);
+
+      dce.SetBinary ("ccnd");
+      dce.ResetArguments ();
+      dce.ResetEnvironment ();
+
+      dce.AddEnvironment ("CCND_CAP", "50000");
+      dce.AddEnvironment ("CCND_DEBUG", "-1");
+      dce.AddEnvironment ("CCN_LOCAL_PORT", "");
+
+      dce.AddEnvironment ("CCND_CAP", "");
+      dce.AddEnvironment ("CCND_AUTOREG", "");
+      dce.AddEnvironment ("CCND_LISTEN_ON", "");
+      dce.AddEnvironment ("CCND_MTU", "");
+      dce.AddEnvironment ("CCND_LOCAL_SOCKNAME", "");
+      dce.AddEnvironment ("CCND_DATA_PAUSE_MICROSEC", "");
+      dce.AddEnvironment ("CCND_KEYSTORE_DIRECTORY", "");
+
+      apps = dce.Install (nodes.Get (n));
+      apps.Start (Seconds (1.0));
+    }
+
+  for (int n=0; n < nNodes ; n++)
+    {
+      if ( n > 0 )
+        { // Forward /NODE0 interrest to prec node
+          dce.SetBinary ("ccndc");
+          dce.ResetArguments();
+          dce.ResetEnvironment();
+          dce.AddEnvironment("HOME", "/home/furbani");
+          dce.AddArgument ("-v");
+          dce.AddArgument ("add");
+          dce.AddArgument ("/NODE0");
+          dce.AddArgument (useTcp?"tcp":"udp");
+          dce.AddArgument ( Ipv4AddressToString(vInterfaces[n-1].GetAddress ( 0 )) );
+
+          apps = dce.Install (nodes.Get (n));
+          apps.Start (Seconds ( ( 20.0 + n ) / 10  )); // Every 0.1s from time 2s
+        }
+    }
+
+  // Publish a file using NODE number 0 : ccnput /NODE0/LeReadme </tmp/README
+  dce.ResetArguments();
+  dce.ResetEnvironment();
+  dce.AddEnvironment("HOME", "/home/furbani");
+  dce.SetBinary ("ccnput");
+  dce.SetStdinFile ("/tmp/README");
+  dce.AddArgument ("/NODE0/LeReadme");
+  dce.AddEnvironment("HOME", "/home/furbani");
+
+  apps = dce.Install (nodes.Get (0));
+  apps.Start (Seconds (60.0));
+
+
+  // Retrieve the file using last NODE using a big CCN_LINGER value in order to have a chance of having a
+  // response expecially when we use tcp to link daemons.
+  // ccnget -c -a /NODE0/LeReadme
+  dce.ResetArguments();
+  dce.ResetEnvironment();
+  dce.AddEnvironment("HOME", "/home/furbani");
+  dce.AddEnvironment("CCN_LINGER", "3540"); // 1 little hour or less
+  dce.SetBinary ("ccnget"); // First get can take 105s when ccnd daemons are linked with tcp, with 500 nodes.
+  dce.SetStdinFile ("");
+  dce.AddArgument ("-c");
+  dce.AddArgument ("-a");
+  dce.AddArgument ("/NODE0/LeReadme");
+
+  apps = dce.Install (nodes.Get (nNodes - 1));
+  apps.Start (Seconds (60.0));
+
+  // The second get is very fast but not furious :) because of cache usage the data is allready in the local node !
+  dce.ResetArguments();
+  dce.ResetEnvironment();
+  dce.AddEnvironment("HOME", "/home/furbani");
+  dce.AddEnvironment("CCN_LINGER", "1");
+  dce.SetBinary ("ccnget");
+  dce.SetStdinFile ("");
+  dce.AddArgument ("-c");
+  dce.AddArgument ("-a");
+  dce.AddArgument ("/NODE0/LeReadme");
+
+  apps = dce.Install (nodes.Get (nNodes - 1));
+  apps.Start (Seconds (3500.0));
+
+  Simulator::Stop (Seconds(3600.0));
+  Simulator::Run ();
+  Simulator::Destroy ();
+
+  return 0;
+}
--- a/example/ccnx/dce-ccnd-simple.cc	Mon Jun 20 13:00:21 2011 +0200
+++ b/example/ccnx/dce-ccnd-simple.cc	Fri Jun 24 17:01:03 2011 +0200
@@ -40,7 +40,6 @@
   dce.AddEnvironment("CCND_DATA_PAUSE_MICROSEC", "");
   dce.AddEnvironment("CCND_KEYSTORE_DIRECTORY", "");
 
-
   apps = dce.Install (nodes.Get (0));
   apps.Start (Seconds (4.0));
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/ccnx/run-ccnd-linear-multiple.sh	Fri Jun 24 17:01:03 2011 +0200
@@ -0,0 +1,41 @@
+#!/bin/bash
+. run-ccnx-common.sh
+echo init keystores
+NNODES=500
+NNODES=500
+for (( i=0; i<$NNODES; i++ ))
+do
+    install_ccnd_keystore $i
+    install_user_keystore $i
+    mkdir -p files-$i/tmp
+#    cp ccnd$i.conf files-$i/tmp
+#    echo 'GET / ' > files-$i/tmp/getSlash.txt
+done
+echo setting test file
+cp README files-0/tmp
+EXE=dce-ccnd-linear-multiple
+FIBER=--ns3::TaskManager::FiberManagerType=UcontextFiberManager
+NS_LOG=$NS_LOG:CcndInLine
+# Comment out to use TCP instead of UDP
+USE_TCP=--tcp=0
+echo Run NS3
+if [ "" == "$GDB" ]
+then
+    $NS3_BIN/$EXE $FIBER --nNodes=$NNODES $USE_TCP 2>&1 | tee -a output.txt
+else
+    $GDB $NS3_BIN/$EXE $FIBER --nNodes=$NNODES $USE_TCP
+fi
+emacs output.txt  files-*/var/log/*/* &
+
+# avec UcontextFiberManager
+#real	0m43.150s
+#user	0m21.672s
+#sys	0m14.837s
+# et sans :
+#real	0m49.192s
+#user	0m24.258s
+#sys	0m18.596s
+# 500 nodes avec
+#real	2m56.723s
+#user	1m29.995s
+#sys	1m20.047s
--- a/example/ccnx/run-ccnx-common.sh	Mon Jun 20 13:00:21 2011 +0200
+++ b/example/ccnx/run-ccnx-common.sh	Fri Jun 24 17:01:03 2011 +0200
@@ -13,11 +13,11 @@
 VIRTUAL_USER_KEYSTORE=/home/furbani
 ################################################################################
 # NS3 LOG LEVEL
-#export NS_LOG=
+export NS_LOG=
 #export NS_LOG='*'
 #export NS_LOG='Simulator:DceManager:TaskManager:DceStdio'
 #export NS_LOG=LocalDatagramSocketFd:DceStdio:SimuFd:TcpSocketBase:Simulator:UnixStreamSocketFd:UnixSocketFd:LocalSocketFd:LocalStreamSocketFd
-export NS_LOG=LocalStreamSocketFd:DceManager
+#export NS_LOG=LocalStreamSocketFd:DceManager
 ################################################################################
 # GDB or not GDB ? 
 GDB=
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/udp-echo-client.cc	Fri Jun 24 17:01:03 2011 +0200
@@ -0,0 +1,55 @@
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <string.h>
+#include <iostream>
+#include <stdlib.h>
+#include <errno.h>
+
+int main (int argc, char *argv[])
+{
+  if (argc != 3)
+    {
+      std::cout << "Usage:" << std::endl;
+      std::cout << argv[0] << " host message" << std::endl;
+      return 0;
+    }
+  sleep (2);
+
+  int sock;
+  sock = socket (PF_INET, SOCK_DGRAM, 0);
+
+  struct sockaddr_in addr;
+  addr.sin_family = AF_INET;
+  addr.sin_port = htons (2000);
+
+  struct hostent *host = gethostbyname (argv[1]);
+  memcpy (&addr.sin_addr.s_addr, host->h_addr_list[0], host->h_length);
+
+  size_t bLen = 1 + strlen (argv[2] );
+  char *buffer = (char * )malloc ( bLen );
+
+  memset (buffer, 0 ,sizeof(buffer) );
+
+  socklen_t aLen = sizeof(addr);
+
+  ssize_t wLen = sendto (sock, argv[2], bLen, 0, (struct sockaddr *)&addr, aLen);
+
+  std::cout << "len:" << wLen << "errno:"<< errno << std::endl;
+
+  if (wLen > 0)
+    {
+      memset (buffer, 0 ,sizeof(buffer) );
+      ssize_t n = read (sock, buffer, bLen);
+
+      if (n > 0)
+        {
+          std::cout << "echo:" << buffer << std::endl;
+        }
+    }
+
+  close (sock);
+
+  return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example/udp-echo-server.cc	Fri Jun 24 17:01:03 2011 +0200
@@ -0,0 +1,65 @@
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <string.h>
+#include <errno.h>
+#include <iostream>
+#include <stdlib.h>
+#include <stdio.h>
+
+int main (int argc, char *argv[])
+{
+  int sock;
+  sock = socket (PF_INET, SOCK_DGRAM, 0);
+  if (sock == -1)
+    {
+      std::cout << "error: " << strerror (errno) << std::endl;
+      exit (-1);
+    }
+
+  struct sockaddr_in addr;
+  addr.sin_family = AF_INET;
+  addr.sin_port = htons (2000);
+  addr.sin_addr.s_addr = INADDR_ANY;
+
+  if (argc > 1)
+    {
+      struct hostent *host = gethostbyname (argv[1]);
+      memcpy (&addr.sin_addr.s_addr, host->h_addr_list[0], host->h_length);
+    }
+
+  int status;
+  status = bind (sock, (const struct sockaddr *) &addr, sizeof (addr));
+  if (status == -1)
+    {
+      std::cout << "error: " << strerror (errno) << std::endl;
+      exit (-1);
+    }
+
+  while (true)
+    {
+      struct sockaddr_in remoteAddr;
+      socklen_t len = sizeof(remoteAddr);
+      char buf[1024];
+
+      memset (&remoteAddr, 0, len);
+      memset (buf, 0, sizeof(buf));
+
+      ssize_t rLen = recvfrom ( sock, buf, sizeof(buf) , 0, (struct sockaddr *)&remoteAddr, &len);
+
+      std::cout << "recvfrom len:" << rLen << std::endl;
+
+      if (rLen <= 0) break;
+
+      ssize_t wLen = sendto (sock, buf, (size_t) rLen, 0, (struct sockaddr *)&remoteAddr, len);
+
+      if (wLen <= 0) break;
+
+      std::cout << "Echo sended, len:" << wLen << " over " << rLen << std::endl;
+    }
+
+  close (sock);
+
+  return 0;
+}
--- a/model/utils.cc	Mon Jun 20 13:00:21 2011 +0200
+++ b/model/utils.cc	Fri Jun 24 17:01:03 2011 +0200
@@ -154,7 +154,6 @@
 {
   unsigned long secondsSinceEpochOnFridayApril042008 = 1207284276;
   return secondsSinceEpochOnFridayApril042008;
-
 }
 Time UtilsSimulationTimeToTime (Time time)
 {
--- a/wscript	Mon Jun 20 13:00:21 2011 +0200
+++ b/wscript	Fri Jun 24 17:01:03 2011 +0200
@@ -189,6 +189,10 @@
                        target='bin/dce-tap-ccnd',
                        source=['example/ccnx/dce-tap-ccnd.cc'])                
 
+    module.add_example(needed = ['core', 'internet', 'dce', 'point-to-point'], 
+                       target='bin/dce-ccnd-linear-multiple',
+                       source=['example/ccnx/dce-ccnd-linear-multiple.cc'])
+                       
 def build_dce_kernel_examples(module):
     module.add_example(needed = ['core', 'network', 'dce'], 
                        target='bin/dce-linux-simple',