Ejemplo n.º 1
0
  def kill(self):
    '''Kill the process the controller is running in.'''
    msg.event("Killing controller %s" % (str(self.uuid)))
    if self.sync_connection:
      self.sync_connection.close()

    kill_procs([self.process])
    self._unregister_proc(self.process)
    self.alive = False
    self.process = None
Ejemplo n.º 2
0
  def basic_test(self):
    simulation = None
    try:
      start_cmd = ('''./pox.py --verbose '''
                   '''openflow.discovery forwarding.l2_multi '''
                   '''sts.util.socket_mux.pox_monkeypatcher --snapshot_address=../snapshot_socket '''
                   '''openflow.of_01 --address=__address__ --port=__port__''')

      IPAddressSpace._claimed_addresses.clear()
      ControllerConfig._controller_labels.clear()
      controllers = [ControllerConfig(start_cmd, cwd="pox", snapshot_address="./snapshot_socket")]
      topology_class = MeshTopology
      topology_params = "num_switches=2"

      simulation_config = SimulationConfig(controller_configs=controllers,
                                           topology_class=topology_class,
                                           topology_params=topology_params,
                                           multiplex_sockets=True)
      simulation = simulation_config.bootstrap(RecordingSyncCallback(None))
      simulation.connect_to_controllers()

      c1 = simulation.controller_manager.controllers[0]
      c1_pid = c1.pid

      snapshotter = Snapshotter(simulation, c1)
      snapshotter.snapshot_controller()
      # TODO(cs): time.sleep() is a broken way to synchronize
      time.sleep(1)
      kill_procs([c1.process])
      snapshotter.snapshot_proceed()

      self.assertEqual(1, len(simulation.controller_manager.controllers))
      c2 = simulation.controller_manager.controllers[0]
      c2_pid = c2.pid
      self.assertTrue(c1_pid != c2_pid)
      # Controller object itself should not have changed
      self.assertTrue(c1 == c2)

      # snapshotting should work multiple times
      snapshotter = Snapshotter(simulation, c2)
      snapshotter.snapshot_controller()
      # TODO(cs): time.sleep() is a broken way to synchronize
      time.sleep(1)
      kill_procs([c2.process])
      snapshotter.snapshot_proceed()

      self.assertEqual(1, len(simulation.controller_manager.controllers))
      c3 = simulation.controller_manager.controllers[0]
      self.assertTrue(c2_pid != c3.pid)
    finally:
      try:
        if simulation is not None:
          simulation.clean_up()
      except Exception as e:
        print "SnapshotTest.test_basic: exception encountered in finally clause: %s" % e
Ejemplo n.º 3
0
 def kill(self):
   ''' Kill the process the controller is running in '''
   if self.state != ControllerState.ALIVE:
     self.log.warn("Killing controller %s when it is not alive!" % self.label)
     return
   msg.event("Killing controller %s" % self.cid)
   kill_procs([self.process])
   if self.config.kill_cmd != "":
     self.log.info("Killing controller %s: %s" % (self.label, " ".join(self.config.expanded_kill_cmd)))
     popen_filtered("[%s]" % self.label, self.config.expanded_kill_cmd, self.config.cwd)
   self._unregister_proc(self.process)
   self.process = None
   self.state = ControllerState.DEAD
Ejemplo n.º 4
0
 def kill(self):
     """ Kill the process the controller is running in """
     if self.state != ControllerState.ALIVE:
         self.log.warn("Killing controller %s when it is not alive!" %
                       self.label)
         return
     msg.event("Killing controller %s (pid %d)" % (self.cid, self.pid))
     kill_procs([self.process])
     if self.config.kill_cmd not in ["", None]:
         self.log.info(
             "Killing controller %s: %s" %
             (self.label, " ".join(self.config.expanded_kill_cmd)))
         popen_filtered("[%s]" % self.label, self.config.expanded_kill_cmd,
                        self.config.cwd)
     self._unregister_proc(self.process)
     self.process = None
     self.state = ControllerState.DEAD
Ejemplo n.º 5
0
 def kill_active_procs():
   '''Kill the active processes. Used by the simulator module to shut down the
   controllers because python can only have a single method to handle SIG* stuff.'''
   kill_procs(Controller._active_processes)
Ejemplo n.º 6
0
    def basic_test(self):
        simulation = None
        try:
            start_cmd = (
                '''./pox.py --verbose '''
                '''openflow.discovery forwarding.l2_multi '''
                '''sts.util.socket_mux.pox_monkeypatcher --snapshot_address=../snapshot_socket '''
                '''openflow.of_01 --address=__address__ --port=__port__''')

            IPAddressSpace._claimed_addresses.clear()
            ControllerConfig._controller_labels.clear()
            controllers = [
                ControllerConfig(start_cmd,
                                 cwd="pox",
                                 snapshot_address="./snapshot_socket")
            ]
            topology_class = MeshTopology
            topology_params = "num_switches=2"

            simulation_config = SimulationConfig(
                controller_configs=controllers,
                topology_class=topology_class,
                topology_params=topology_params,
                multiplex_sockets=True)
            simulation = simulation_config.bootstrap(
                RecordingSyncCallback(None))
            simulation.connect_to_controllers()

            c1 = simulation.controller_manager.controllers[0]
            c1_pid = c1.pid

            snapshotter = Snapshotter(simulation, c1)
            snapshotter.snapshot_controller()
            # TODO(cs): time.sleep() is a broken way to synchronize
            time.sleep(1)
            kill_procs([c1.process])
            snapshotter.snapshot_proceed()

            self.assertEqual(1, len(simulation.controller_manager.controllers))
            c2 = simulation.controller_manager.controllers[0]
            c2_pid = c2.pid
            self.assertTrue(c1_pid != c2_pid)
            # Controller object itself should not have changed
            self.assertTrue(c1 == c2)

            # snapshotting should work multiple times
            snapshotter = Snapshotter(simulation, c2)
            snapshotter.snapshot_controller()
            # TODO(cs): time.sleep() is a broken way to synchronize
            time.sleep(1)
            kill_procs([c2.process])
            snapshotter.snapshot_proceed()

            self.assertEqual(1, len(simulation.controller_manager.controllers))
            c3 = simulation.controller_manager.controllers[0]
            self.assertTrue(c2_pid != c3.pid)
        finally:
            try:
                if simulation is not None:
                    simulation.clean_up()
            except Exception as e:
                print "SnapshotTest.test_basic: exception encountered in finally clause: %s" % e