Exemplo n.º 1
0
 def setUp(self):
     oflog.start_logging(self)
     self.clean_shutdown = True
     logging.info("** START DataPlaneOnly CASE " + str(self))
     self.dataplane = dataplane.DataPlane(config)
     for of_port, ifname in config["port_map"].items():
         self.dataplane.port_add(ifname, of_port)
Exemplo n.º 2
0
class DataPlaneOnly(unittest.TestCase):
    """
    Root class that sets up only the dataplane
    """
    def sig_handler(self, v1, v2):
        basic_logger.critical("Received interrupt signal; exiting")
        print "Received interrupt signal; exiting"
        self.clean_shutdown = False
        self.tearDown()
        raise KeyboardInterrupt

    def setUp(self):
        self.clean_shutdown = True
        self.logger = basic_logger
        self.config = basic_config
        #@todo Test cases shouldn't monkey with signals; move SIGINT handler
        # to top-level oft
        try:
            signal.signal(signal.SIGINT, self.sig_handler)
        except ValueError, e:
            basic_logger.info("Could not set SIGINT handler: %s" % e)
        basic_logger.info("** START DataPlaneOnly CASE " + str(self))
        self.dataplane = dataplane.DataPlane(self.config)
        for of_port, ifname in basic_port_map.items():
            self.dataplane.port_add(ifname, of_port)
Exemplo n.º 3
0
 def setUp(self):
     self.clean_shutdown = False
     self.logger = basic_logger
     self.config = basic_config
     #signal.signal(signal.SIGINT, self.sig_handler)
     basic_logger.info("** START DataPlaneOnly CASE " + str(self))
     self.dataplane = dataplane.DataPlane()
     for of_port, ifname in basic_port_map.items():
         self.dataplane.port_add(ifname, of_port)
Exemplo n.º 4
0
 def setUp(self):
     SimpleProtocol.setUp(self)
     self.dataplane = dataplane.DataPlane(config)
     for of_port, ifname in config["port_map"].items():
         self.dataplane.port_add(ifname, of_port)
Exemplo n.º 5
0
 def setUp(self):
     SimpleProtocol.setUp(self)
     self.dataplane = dataplane.DataPlane()
     for of_port, ifname in basic_port_map.items():
         self.dataplane.port_add(ifname, of_port)
Exemplo n.º 6
0
    def run(self):
        """
        Main execute function for running the switch
        """

        logging.basicConfig(filename="", level=logging.DEBUG)
        self.logger.info("Switch thread running")
        host = self.config.controller_ip
        if self.config.passive_connect:
            host = None
        self.controller = ControllerInterface(host=host,
                                              port=self.config.controller_port)
        self.dataplane = dataplane.DataPlane()
        self.logger.info("Dataplane started")
        self.pipeline = FlowPipeline(self, self.config.n_tables)
        self.pipeline.controller_set(self.controller)
        self.pipeline.start()
        self.logger.info("Pipeline started")
        link_status = ofp.OFPPF_1GB_FD  #@todo dynamically infer this from the interface status
        for of_port, ifname in self.config.port_map.items():
            self.dataplane.port_add(ifname, of_port)
            port = ofp.ofp_port()
            port.port_no = of_port
            port.name = ifname
            port.max_speed = 9999999
            port.curr_speed = 9999999
            mac = netutils.get_if_hwaddr(port.name)
            self.logger.info(
                "Added port %s (ind=%d) with mac %x:%x:%x:%x:%x:%x" %
                ((ifname, of_port) + mac))
            port.hw_addr = list(
                mac
            )  # stupid frickin' python; need to convert a tuple to a list
            port.config = 0
            port.state = 0  #@todo infer if link is up/down and set OFPPS_LINK_DOWN
            port.advertised = link_status
            port.supported = link_status
            port.curr = link_status
            port.peer = link_status
            self.ports[of_port] = port
        # Register to receive all controller packets
        self.controller.register("all",
                                 self.ctrl_pkt_handler,
                                 calling_obj=self)
        self.controller.start()
        self.logger.info("Controller started")

        # Process packets when they arrive
        self.logger.info("Entering packet processing loop")
        while True:
            (of_port, data, recv_time) = self.dataplane.poll(timeout=5)
            if not self.controller.isAlive():
                # @todo Implement fail open/closed
                self.logger.error("Controller dead\n")
                break
            if not self.pipeline.isAlive():
                # @todo Implement fail open/closed
                self.logger.error("Pipeline dead\n")
                break
            if data is None:
                self.logger.debug("No packet for 5 seconds\n")
                continue
            self.logger.debug("Packet len " + str(len(data)) + " in on port " +
                              str(of_port))
            packet = Packet(in_port=of_port, data=data)
            self.pipeline.apply_pipeline(self, packet)

        self.logger.error("Exiting OFSwitch thread")
        self.pipeline.kill()
        self.dataplane.kill()
        self.pipeline.join()
        self.controller.join()