def runhook(self, state, hooks=None):
     ''' Run hook scripts upon changing states.
     If hooks is not specified, run all hooks in the given state.
     '''
     if state not in self._hooks:
         return
     if hooks is None:
         hooks = self._hooks[state]
     for (filename, data) in hooks:
         try:
             f = open(os.path.join(self.sessiondir, filename), "w")
             f.write(data)
             f.close()
         except Exception, e:
             self.warn("Error writing hook '%s': %s" % (filename, e))
         self.info("Running hook %s for state %s" % (filename, state))
         try:
             stdout = open(os.path.join(self.sessiondir, filename + '.log'),
                           'w')
             stderr = subprocess.STDOUT
         except:
             stdout = None
             stderr = None
         try:
             check_call(["/bin/sh", filename],
                        stdin=open(os.devnull, 'r'),
                        stdout=stdout,
                        stderr=stderr,
                        close_fds=True,
                        cwd=self.sessiondir,
                        env=self.getenviron())
         except Exception, e:
             self.warn("Error running hook '%s' for state %s: %s" %
                       (filename, state, e))
Beispiel #2
0
 def runhook(self, state, hooks=None):
     ''' Run hook scripts upon changing states.
     If hooks is not specified, run all hooks in the given state.
     '''
     if state not in self._hooks:
         return
     if hooks is None:
         hooks = self._hooks[state]
     for (filename, data) in hooks:
         try:
             f = open(os.path.join(self.sessiondir, filename), "w")
             f.write(data)
             f.close()
         except Exception, e:
             self.warn("Error writing hook '%s': %s" % (filename, e))
         self.info("Running hook %s for state %s" % (filename, state))
         try:
             stdout = open(os.path.join(self.sessiondir,
                                        filename + '.log'), 'w')
             stderr = subprocess.STDOUT
         except:
             stdout = None
             stderr = None
         try:
             check_call(["/bin/sh", filename], stdin=open(os.devnull, 'r'),
                        stdout=stdout, stderr=stderr, close_fds=True,
                        cwd=self.sessiondir, env=self.getenviron())
         except Exception, e:
             self.warn("Error running hook '%s' for state %s: %s" %
                       (filename, state, e))
Beispiel #3
0
 def statescript(self, typestr):
     filename = None
     if typestr == "run" or typestr == "unpause":
         filename = self.script_start
     elif typestr == "pause":
         filename = self.script_pause
     elif typestr == "stop":
         filename = self.script_stop
     if filename is None or filename == '':
         return
     filename = self.findfile(filename)
     try:
         check_call(["/bin/sh", filename, typestr],
                    cwd=self.session.sessiondir,
                    env=self.session.getenviron())
     except Exception as e:
         self.session.warn("Error running script '%s' for WLAN state %s: " \
                          "%s" % (filename, typestr, e))
Beispiel #4
0
 def statescript(self, typestr):
     filename = None
     if typestr == "run" or typestr == "unpause":
         filename = self.script_start
     elif typestr == "pause":
         filename = self.script_pause
     elif typestr == "stop":
         filename = self.script_stop
     if filename is None or filename == '':
         return
     filename = self.findfile(filename)
     try:
         check_call(["/bin/sh", filename, typestr],
                    cwd=self.session.sessiondir,
                    env=self.session.getenviron())
     except Exception, e:
         self.session.warn("Error running script '%s' for WLAN state %s: " \
                          "%s" % (filename, typestr, e))
Beispiel #5
0
 def attach(self, netif):
     ''' Invoked from netif.attach(). Create a TAP device using the TapBridge
     object. Call getns3dev() to get model-specific device.
     '''
     self._netif[netif] = netif
     self._linked[netif] = {}
     ns3dev = self.getns3dev(netif.node)
     self.tapbridge.SetAttribute("Mode", ns.core.StringValue("UseLocal"))
     #self.tapbridge.SetAttribute("Mode",
     #                ns.core.IntegerValue(ns.tap_bridge.TapBridge.USE_LOCAL))
     tap = self.tapbridge.Install(netif.node, ns3dev) 
     #tap.SetMode(ns.tap_bridge.TapBridge.USE_LOCAL)
     print "using TAP device %s for %s/%s" % \
         (netif.localname, netif.node.name, netif.name)
     check_call(['tunctl', '-t', netif.localname, '-n'])
     #check_call([IP_BIN, 'link', 'set', 'dev', netif.localname, \
     #    'address', '%s' % netif.hwaddr])
     check_call([IP_BIN, 'link', 'set', netif.localname, 'up'])
     tap.SetAttribute("DeviceName", ns.core.StringValue(netif.localname))
     self._ns3devs[netif] = ns3dev
     self._tapdevs[netif] = tap
 def attach(self, netif):
     ''' Invoked from netif.attach(). Create a TAP device using the TapBridge
     object. Call getns3dev() to get model-specific device.
     '''
     self._netif[netif] = netif
     self._linked[netif] = {}
     ns3dev = self.getns3dev(netif.node)
     self.tapbridge.SetAttribute("Mode", ns.core.StringValue("UseLocal"))
     #self.tapbridge.SetAttribute("Mode",
     #                ns.core.IntegerValue(ns.tap_bridge.TapBridge.USE_LOCAL))
     tap = self.tapbridge.Install(netif.node, ns3dev)
     #tap.SetMode(ns.tap_bridge.TapBridge.USE_LOCAL)
     print "using TAP device %s for %s/%s" % \
         (netif.localname, netif.node.name, netif.name)
     check_call(['tunctl', '-t', netif.localname, '-n'])
     #check_call([IP_BIN, 'link', 'set', 'dev', netif.localname, \
     #    'address', '%s' % netif.hwaddr])
     check_call([IP_BIN, 'link', 'set', netif.localname, 'up'])
     tap.SetAttribute("DeviceName", ns.core.StringValue(netif.localname))
     self._ns3devs[netif] = ns3dev
     self._tapdevs[netif] = tap
Beispiel #7
0
 def runhook(self, state, hooks=None):
     ''' Run hook scripts upon changing states.
     If hooks is not specified, run all hooks in the given state.
     '''
     if state not in self._hooks:
         return
     if hooks is None:
         hooks = self._hooks[state]
     for (filename, data) in hooks:
         try:
             f = open(os.path.join(self.sessiondir, filename), "w")
             f.write(data)
             f.close()
         except Exception, e:
             self.warn("Error writing hook '%s': %s" % (filename, e))
         self.info("Running hook %s for state %s" % (filename, state))
         try:
             check_call(["/bin/sh", filename], cwd=self.sessiondir,
                        env=self.getenviron())
         except Exception, e:
             self.warn("Error running hook '%s' for state %s: %s" %
                       (filename, state, e))