adding ccnx tree topology streamming over Internet example
[nepi.git] / src / nepi / testbeds / planetlab / application.py
index 53592ec..a5170a4 100644 (file)
@@ -19,6 +19,8 @@ import re
 
 from nepi.util.constants import ApplicationStatus as AS
 
+_ccnre = re.compile("\s*(udp|tcp)\s+(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\s*$")
+
 class Dependency(object):
     """
     A Dependency is in every respect like an application.
@@ -89,7 +91,10 @@ class Dependency(object):
             self.__class__.__name__,
             ' '.join(filter(bool,(self.depends, self.sources)))
         )
-    
+   
+    def deployed(self):
+        return self._setup
+
     def validate(self):
         if self.home_path is None:
             raise AssertionError, "Misconfigured application: missing home path"
@@ -567,7 +572,7 @@ class Dependency(object):
     def _do_install(self):
         if self.install:
             self._logger.info("Installing %s at %s", self, self.node.hostname)
-            
+           
             # Install application
             try:
                 self._popen_ssh_command(
@@ -580,7 +585,8 @@ class Dependency(object):
             except RuntimeError, e:
                 if self.check_bad_host(e.args[0], e.args[1]):
                     self.node.blacklist()
-                raise RuntimeError, "Failed install build sources: %s %s" % (e.args[0], e.args[1],)
+                raise RuntimeError, "Failed install build sources on node %s: %s %s" % (
+                        self.node.hostname, e.args[0], e.args[1],)
 
     def set_master(self, master):
         self._master = master
@@ -748,7 +754,6 @@ class Application(Dependency):
             stdout = 'stdout' if self.stdout else '/dev/null',
             stderr = 'stderr' if self.stderr else '/dev/null',
             sudo = self.sudo,
-            
             host = self.node.hostname,
             port = None,
             user = self.node.slicename,
@@ -903,9 +908,10 @@ class NS3Dependency(Dependency):
         self.buildDepends = 'make waf gcc gcc-c++ gccxml unzip bzr'
         
         # We have to download the sources, untar, build...
-        pygccxml_source_url = "http://leaseweb.dl.sourceforge.net/project/pygccxml/pygccxml/pygccxml-1.0/pygccxml-1.0.0.zip"
-        ns3_source_url = "http://nepi.pl.sophia.inria.fr/code/nepi-ns3.13/archive/tip.tar.gz"
-        passfd_source_url = "http://nepi.pl.sophia.inria.fr/code/python-passfd/archive/tip.tar.gz"
+        #pygccxml_source_url = "http://leaseweb.dl.sourceforge.net/project/pygccxml/pygccxml/pygccxml-1.0/pygccxml-1.0.0.zip"
+        pygccxml_source_url = "http://yans.pl.sophia.inria.fr/libs/pygccxml-1.0.0.zip"
+        ns3_source_url = "http://nepi.inria.fr/code/nepi-ns3.13/archive/tip.tar.gz"
+        passfd_source_url = "http://nepi.inria.fr/code/python-passfd/archive/tip.tar.gz"
         
         pybindgen_version = "797"
 
@@ -1105,43 +1111,66 @@ class CCNxDaemon(Application):
         super(CCNxDaemon,self).__init__(api)
         
         # Attributes
-        self.ccnroutes = None
-        self.ccnsources = None
-        
-        self.default_ccnx_sources = "http://www.ccnx.org/releases/ccnx-0.5.1.tar.gz"
+        self.ccnLocalPort = None
+        self.ccnRoutes = None
+        self.ccnxVersion = "ccnx-0.6.0"
+        
+        #self.ccnx_0_5_1_sources = "http://www.ccnx.org/releases/ccnx-0.5.1.tar.gz"
+        self.ccnx_0_5_1_sources = "http://yans.pl.sophia.inria.fr/libs/ccnx-0.5.1.tar.gz"
+        #self.ccnx_0_6_0_sources = "http://www.ccnx.org/releases/ccnx-0.6.0.tar.gz"
+        self.ccnx_0_6_0_sources = "http://yans.pl.sophia.inria.fr/libs/ccnx-0.6.0.tar.gz"
         self.buildDepends = 'make gcc development-tools openssl-devel expat-devel libpcap-devel libxml2-devel'
 
-        self.default_build = (
+        self.ccnx_0_5_1_build = (
             " ( "
             "  cd .. && "
-            "  test -d ccnx-src/build/bin "
+            "  test -d ccnx-0.5.1-src/build/bin "
             " ) || ( "
                 # Not working, rebuild
                 "("
-                     " mkdir -p ccnx-src && "
-                     " ( %(not_custom_source)s &&"
-                     " wget -q -c -O ccnx-src.tar.gz %(ccnx_source_url)s &&"
-                     " tar xf ccnx-src.tar.gz --strip-components=1 -C ccnx-src "
-                     " ) || ( "
-                     " tar xf %(user_ccnx_tar)s --strip-components=1 -C ccnx-src "
-                     " ) "
+                     " mkdir -p ccnx-0.5.1-src && "
+                     " wget -q -c -O ccnx-0.5.1-src.tar.gz %(ccnx_source_url)s &&"
+                     " tar xf ccnx-0.5.1-src.tar.gz --strip-components=1 -C ccnx-0.5.1-src "
                 ") && "
-                     "cd ccnx-src && "
+                     "cd ccnx-0.5.1-src && "
                      "mkdir -p build/include &&"
                      "mkdir -p build/lib &&"
                      "mkdir -p build/bin &&"
                      "I=$PWD/build && "
                      "INSTALL_BASE=$I ./configure &&"
                      "make && make install"
-             " )")
+             " )") % dict(
+                     ccnx_source_url = server.shell_escape(self.ccnx_0_5_1_sources),
+                )
 
-        self.default_install = (
+        self.ccnx_0_5_1_install = (
+            " ( "
+            "  test -d ${BUILD}/ccnx-0.5.1-src/build/bin && "
+            "  cp -r ${BUILD}/ccnx-0.5.1-src/build/bin ${SOURCES}"
+            " )"
+        )
+
+        self.ccnx_0_6_0_build = (
             " ( "
             "  cd .. && "
-            "  test -d ${SOURCES}/bin "
+            "  test -d ccnx-0.6.0-src/build/bin "
             " ) || ( "
-            "  test -d ${BUILD}/ccnx-src/build/bin && "
-            "  cp -r ${BUILD}/ccnx-src/build/bin ${SOURCES}"
+                # Not working, rebuild
+                "("
+                     " mkdir -p ccnx-0.6.0-src && "
+                     " wget -q -c -O ccnx-0.6.0-src.tar.gz %(ccnx_source_url)s &&"
+                     " tar xf ccnx-0.6.0-src.tar.gz --strip-components=1 -C ccnx-0.6.0-src "
+                ") && "
+                     "cd ccnx-0.6.0-src && "
+                     "./configure && make"
+             " )") % dict(
+                     ccnx_source_url = server.shell_escape(self.ccnx_0_6_0_sources),
+                )
+
+        self.ccnx_0_6_0_install = (
+            " ( "
+            "  test -d ${BUILD}/ccnx-0.6.0-src/bin && "
+            "  cp -r ${BUILD}/ccnx-0.6.0-src/bin ${SOURCES}"
             " )"
         )
 
@@ -1149,33 +1178,41 @@ class CCNxDaemon(Application):
 
     def setup(self):
         # setting ccn sources
-        not_custom_source = "true"
-        sources = ""
-        if self.ccnsources:
-            self.sources = self.ccnsources
-            sources = "${SOURCES}/%s" % os.path.basename(self.ccnsources)
-            not_custom_source = "false"
-
         if not self.build:
-            self.build = self.default_build  % dict(
-                     ccnx_source_url = server.shell_escape(self.default_ccnx_sources),
-                     not_custom_source = server.shell_escape(not_custom_source),
-                     user_ccnx_tar = sources
-                )
-        
+            if self.ccnxVersion == 'ccnx-0.6.0':
+                self.build = self.ccnx_0_6_0_build
+            elif self.ccnxVersion == 'ccnx-0.5.1':
+                self.build = self.ccnx_0_5_1_build
+
         if not self.install:
-            self.install = self.default_install
+            if self.ccnxVersion == 'ccnx-0.6.0':
+                self.install = self.ccnx_0_6_0_install
+            elif self.ccnxVersion == 'ccnx-0.5.1':
+                self.install = self.ccnx_0_5_1_install
 
         super(CCNxDaemon, self).setup()
 
     def start(self):
+        self.command = ""
+        if self.ccnLocalPort:
+            self.command = "export CCN_LOCAL_PORT=%s ; " % self.ccnLocalPort
+        self.command += " ccndstart "
+
         # configure ccn routes
-        routes = ""
-        if self.ccnroutes:
+        if self.ccnRoutes:
+            routes = self.ccnRoutes.split("|")
+            
+            if self.ccnLocalPort:
+                routes = map(lambda route: "%s %s" %(route, 
+                    self.ccnLocalPort) if _ccnre.match(route) else route, 
+                        routes)
+
             routes = map(lambda route: "ccndc add ccnx:/ %s" % route, 
-                self.ccnroutes.split("|"))
-            routes = "; " + " ; ".join(routes)
-        self.command = "ccndstart %s" % routes
+                routes)
+
+            routescmd = " ; ".join(routes)
+            self.command += " ; "
+            self.command += routescmd
 
         # Start will be invoked in prestart step
         super(CCNxDaemon, self).start()
@@ -1183,7 +1220,12 @@ class CCNxDaemon(Application):
     def kill(self):
         self._logger.info("Killing %s", self)
 
-        cmd = self._replace_paths("${SOURCES}/bin/ccndstop")
+        command = "${SOURCES}/bin/ccndstop"
+
+        if self.ccnLocalPort:
+            self.command = "export CCN_LOCAL_PORT=%s; %s" % (self.ccnLocalPort, command)
+
+        cmd = self._replace_paths(command)
         command = cStringIO.StringIO()
         command.write(cmd)
         command.seek(0)