Exemple #1
0
    def runTest(self):
        logging = get_logger()

        logging.info("Running TestNo50 No Common Version Test")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,
                                               timeout=5)
        request = message.hello()
        logging.info(
            "Changing hello message version to 0 and sending it to control plane"
        )
        request.header.version = 0
        rv = self.controller.message_send(request)

        logging.info("Expecting OFPT_ERROR message")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
                                               timeout=5)

        self.assertTrue(response is not None,
                        'Switch did not reply with error message')
        logging.info("Error message received")

        if response.type == ofp.OFPET_BAD_REQUEST:
            (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
                                                   timeout=5)

        self.assertTrue(response.type == ofp.OFPET_HELLO_FAILED,
                        'Message field type is not HELLO_FAILED')
        logging.info("Received message is of type HELLO_FAILED")
        self.assertTrue(response.code == ofp.OFPHFC_INCOMPATIBLE,
                        'Message field code is not OFPHFC_INCOMPATIBLE')
Exemple #2
0
    def runTest(self):
        logging = get_logger()

        logging.info("Running TestNo50 No Common Version Test")                
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,         
                                               timeout=5)
        request = message.hello()                                               
        logging.info("Changing hello message version to 0 and sending it to control plane")
        request.header.version=0
        rv = self.controller.message_send(request)      
        
        logging.info("Expecting OFPT_ERROR message")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,         
                                               timeout=5)
        
        self.assertTrue(response is not None, 
                               'Switch did not reply with error message')
        logging.info("Error message received") 

        if response.type == ofp.OFPET_BAD_REQUEST:
            (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,         
                                               timeout=5)

        self.assertTrue(response.type==ofp.OFPET_HELLO_FAILED, 
                               'Message field type is not HELLO_FAILED')
        logging.info("Received message is of type HELLO_FAILED") 
        self.assertTrue(response.code==ofp.OFPHFC_INCOMPATIBLE, 
                        'Message field code is not OFPHFC_INCOMPATIBLE')        
Exemple #3
0
    def setUp(self):
        logging = get_logger()
        #This is almost same as setUp in SimpleProtocol except that intial hello is set to false
        self.controller = controller.Controller(
            host=config["controller_host"],
            port=config["controller_port"])
        time_out = config["controller_timeout"]

        # clean_shutdown should be set to False to force quit app
        self.clean_shutdown = True
        #set initial hello to False
        self.controller.initial_hello=False
        self.controller.start()

        self.controller.connect(timeout=time_out)
        # By default, respond to echo requests
        self.controller.keep_alive = True
        if not self.controller.active:
            raise Exception("Controller startup failed")
        if self.controller.switch_addr is None: 
            raise Exception("Controller startup failed (no switch addr)")
        logging.info("Connected " + str(self.controller.switch_addr))

        logging.info("Sending Hello message with incorrect version..")
        request = message.hello()                                               
        logging.info("Change hello message version to 0 and send it to control plane")
        request.header.version=0
        rv = self.controller.message_send(request)
Exemple #4
0
 def _send_hand_shake(self):
     """
     This is send only; All of the negotiation happens elsewhere, e.g., 
         if the remote side speaks a different protocol version
     """
     self.logger.debug("Sending initial HELLO")
     ret = self.message_send(message.hello())
     if ret != 0:
         self.logger.error("Got %d when sending initial HELL0" % (ret))
Exemple #5
0
 def _send_hand_shake(self):
     """
     This is send only; All of the negotiation happens elsewhere, e.g., 
         if the remote side speaks a different protocol version
     """
     self.logger.debug("Sending initial HELLO")
     ret = self.message_send(message.hello())
     if ret != 0 :
         self.logger.error("Got %d when sending initial HELL0" % (ret))
Exemple #6
0
    def runTest(self):
        self.num_controllers = test_param_get('num_controllers', default=1)
        self.controller_timeout = test_param_get('controller_timeout',
                                                 default=-1)

        for i in range(self.num_controllers):
            self.controllerSetup(config["controller_host"],
                                 config["controller_port"] + i)
        for i in range(self.num_controllers):
            self.controllers[i].handshake_done = False

        # try to maintain switch connections for specified timeout
        # -1 means forever
        while True:
            for con in self.controllers:
                if con.switch_socket and con.handshake_done:
                    if (self.controller_timeout < 0
                            or con.count < self.controller_timeout):
                        logging.info(con.host + ":" + str(con.port) +
                                     ": maintaining connection to " +
                                     str(con.switch_addr))
                        con.count = con.count + 1
                    else:
                        logging.info(con.host + ":" + str(con.port) +
                                     ": disconnecting from " +
                                     str(con.switch_addr))
                        con.disconnect()
                        con.handshake_done = False
                        con.count = 0
                    time.sleep(1)
                else:
                    #@todo Add an option to wait for a pkt transaction to
                    # ensure version compatibilty?
                    con.connect(self.default_timeout)
                    if not con.switch_socket:
                        logging.info("Did not connect to switch")
                        continue
                    logging.info("TCP Connected " + str(con.switch_addr))
                    logging.info("Sending hello")
                    con.message_send(message.hello())
                    request = message.features_request()
                    reply, pkt = con.transact(request,
                                              timeout=self.default_timeout)
                    if reply:
                        logging.info("Handshake complete with " +
                                     str(con.switch_addr))
                        con.handshake_done = True
                        con.keep_alive = True
                        con.count = 0
                    else:
                        logging.info("Did not complete features_request " +
                                     "for handshake")
                        con.disconnect()
                        con.handshake_done = False
                        con.count = 0
Exemple #7
0
    def runTest(self):
        self.num_controllers = test_param_get('num_controllers', default=1)
        self.controller_timeout = test_param_get('controller_timeout',
                                                 default=-1)

        for i in range(self.num_controllers):
            self.controllerSetup(config["controller_host"],
                                 config["controller_port"]+i)
        for i in range(self.num_controllers):
            self.controllers[i].handshake_done = False

        # try to maintain switch connections for specified timeout
        # -1 means forever
        while True:
            for con in self.controllers:
                if con.switch_socket and con.handshake_done:
                    if (self.controller_timeout < 0 or
                        con.count < self.controller_timeout):
                        logging.info(con.host + ":" + str(con.port) + 
                                     ": maintaining connection to " +
                                     str(con.switch_addr))
                        con.count = con.count + 1
                    else:
                        logging.info(con.host + ":" + str(con.port) + 
                                     ": disconnecting from " +
                                     str(con.switch_addr))
                        con.disconnect()
                        con.handshake_done = False
                        con.count = 0
                    time.sleep(1)
                else:
                    #@todo Add an option to wait for a pkt transaction to 
                    # ensure version compatibilty?
                    con.connect(self.default_timeout)
                    if not con.switch_socket:
                        logging.info("Did not connect to switch")
                        continue
                    logging.info("TCP Connected " + str(con.switch_addr))
                    logging.info("Sending hello")
                    con.message_send(message.hello())
                    request = message.features_request()
                    reply, pkt = con.transact(request, 
                                              timeout=self.default_timeout)
                    if reply:
                        logging.info("Handshake complete with " + 
                                    str(con.switch_addr))
                        con.handshake_done = True
                        con.keep_alive = True
                        con.count = 0
                    else:
                        logging.info("Did not complete features_request " +
                                     "for handshake")
                        con.disconnect()
                        con.handshake_done = False
                        con.count = 0
Exemple #8
0
    def runTest(self):

        logging.info("Running Grp20No100 Hello test")

        logging.info("Sending Hello")
        logging.info("Expecting a Hello on the control plane with version--1.0.0")

        # Send Hello message
        request = message.hello()
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO, timeout=1)
        self.assertTrue(response is not None, "Switch did not exchange hello message in return")
        self.assertTrue(response.header.version == 0x01, "switch openflow-version field is not 1.0.0")
Exemple #9
0
    def runTest(self):

        logging.info("Running TestNo60 Version Announcement test")
        
        of_version = test_param_get('version',default = 0x01)
        request = message.hello()  
        rv = self.controller.message_send(request)  
        self.assertTrue(rv != -1, "Error sending Hello message")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,         
                                               timeout=5)
        self.assertTrue(response is not None, 
                               'Switch did not exchange hello message in return') 
        self.assertTrue(response.header.version == of_version, 'switch openflow-version field is not 1.0.0') 
Exemple #10
0
 def runTest(self):
     logging = get_logger()
     logging.info("Running Grp80No10 HelloWithoutBody Test")            
     (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,         
                                           timeout=5)
     request = message.hello()                                          
     rv = self.controller.message_send(request)      
     
     logging.info("Verify switch does not generate an error")
     (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,         
                                            timeout=5)
     self.assertTrue(response is None, 
                            'Switch generated ERROR in response to our Hello message')  
Exemple #11
0
    def runTest(self):
        self.controllerSetup(config["controller_host"],
                             config["controller_port"])
        self.controllers[0].connect(self.default_timeout)

        logging.info("TCP Connected " + str(self.controllers[0].switch_addr))
        logging.info("Sending hello")
        self.controllers[0].message_send(message.hello())

        logging.info("Features request not sent, waiting for timeout")

        # wait for controller to die
        self.assertTrue(self.controllers[0].wait_disconnected(timeout=10),
                        "Not notified of controller disconnect")
Exemple #12
0
    def runTest(self):
        logging = get_logger()
        logging.info("Running Grp80No10 HelloWithoutBody Test")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,
                                               timeout=5)
        request = message.hello()
        rv = self.controller.message_send(request)

        logging.info("Verify switch does not generate an error")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
                                               timeout=5)
        self.assertTrue(
            response is None,
            'Switch generated ERROR in response to our Hello message')
Exemple #13
0
    def runTest(self):
        logging = get_logger()
        logging.info("Running Grp80No20 HelloWithBody Test")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,
                                               timeout=5)
        request = message.hello()
        request.data = "Openflow rules the world"
        rv = self.controller.message_send(request)

        logging.info("Verify switch does not generate an error")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
                                               timeout=5)
        self.assertTrue(response is None,
                        'Switch did not ignore the body of the Hello message')
Exemple #14
0
 def runTest(self):
     logging = get_logger()
     logging.info("Running Grp80No20 HelloWithBody Test")            
     (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,         
                                           timeout=5)
     request = message.hello()   
     request.data = "Openflow rules the world"                                            
     rv = self.controller.message_send(request)      
     
     logging.info("Verify switch does not generate an error")
     (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,         
                                            timeout=5)
     self.assertTrue(response is None, 
                            'Switch did not ignore the body of the Hello message')  
Exemple #15
0
    def runTest(self):
        self.controllerSetup(cxn_config["controller_host"], cxn_config["controller_port"])

        cxn_logger.info("TCP Connected " + str(self.controller.switch_addr))
        cxn_logger.info("Sending hello")
        self.controller.message_send(message.hello())

        cxn_logger.info("Features request not sent, waiting for timeout")

        # wait for controller to die
        count = 0
        while self.controller.active and count < self.test_timeout:
            time.sleep(1)
            count = count + 1
        self.assertTrue(not self.controller.active, "Expected controller disconnect, but still active")
Exemple #16
0
    def runTest(self):
        self.controllerSetup(config["controller_host"],
                             config["controller_port"])
        self.controllers[0].connect(self.default_timeout)

        logging.info("TCP Connected " + 
                     str(self.controllers[0].switch_addr))
        logging.info("Sending hello")
        self.controllers[0].message_send(message.hello())

        logging.info("Features request not sent, waiting for timeout")

        # wait for controller to die
        self.assertTrue(self.controllers[0].wait_disconnected(timeout=10),
                        "Not notified of controller disconnect")
    def runTest(self):

        of_logger.info("Running Hello test")

        of_logger.info("Sending Hello")
        of_logger.info(
            "Expecting a Hello on the control plane with version--1.0.0")

        #Send Hello message
        request = message.hello()
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,
                                               timeout=1)
        self.assertTrue(response is not None,
                        'Switch did not exchange hello message in return')
        self.assertTrue(response.header.version == 0x01,
                        'switch openflow-version field is not 1.0.0')
Exemple #18
0
    def runTest(self):

        logging.info("Running TestNo90 EchoTimeout ") 
       
        request = message.hello()
        timeout = test_param_get('timeout',default = 60)
        rv = self.controller.message_send(request)
        self.assertTrue(rv == 0, "Error sending out message")

        for i in range(timeout): 
            if not self.controller.active:
                raise Exception("Test Passed")  
            sleep(1)

        connection_lost = False
        self.assertTrue(connection_lost != False, "Connection did not drop due to echo-timeout")
Exemple #19
0
    def runTest(self):

        logging.info("Running Grp100No10 HelloFailed Test")

        # Send a hello message with incorrect version
        logging.info("Sending Hello message with incorrect version..")
        request = message.hello()
        logging.info("Change hello message version to 0 and send it to control plane")
        request.header.version = 0
        rv = self.controller.message_send(request)

        logging.info("Waiting for OFPT_ERROR message..")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR, timeout=5)
        self.assertTrue(response is not None, "Switch did not reply with error message")
        self.assertTrue(response.type == ofp.OFPET_HELLO_FAILED, "Error type is not HELLO_FAILED")
        self.assertTrue(response.code == ofp.OFPHFC_INCOMPATIBLE, "Error code is not OFPHFC_INCOMPATIBLE")
Exemple #20
0
    def runTest(self):
        logging = get_logger()

        logging.info("Running TestNo40 VersionNegotiation Test") 
        of_version = test_param_get('version',default = 0x01)               
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,         
                                               timeout=5)
        request = message.hello()                                               
        request.header.version=2
        rv = self.controller.message_send(request)      
          
        logging.info("Verifying switch does not generate an error message for a hello message with different version type")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,         
                                               timeout=5)
        self.assertTrue(response is None, 
                               'Switch did not negotiate on the version')  
Exemple #21
0
    def runTest(self):
        self.controllerSetup(config["controller_host"],
                             config["controller_port"])

        logging.info("TCP Connected " + str(self.controller.switch_addr))
        logging.info("Sending hello")
        self.controller.message_send(message.hello())

        logging.info("Features request not sent, waiting for timeout")

        # wait for controller to die
        count = 0
        while self.controller.active and count < self.test_timeout:
            time.sleep(1)
            count = count + 1
        self.assertTrue(not self.controller.active,
                        "Expected controller disconnect, but still active")
Exemple #22
0
    def runTest(self):

        logging.info("Running TestNo70 VersionNegotiation Test") 
        of_version = test_param_get('version',default = 0x01)               
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,         
                                               timeout=5)
        request = message.hello()                                               
        logging.info("Change hello message version to 2 and send it to control plane")
        request.header.version=2
        rv = self.controller.message_send(request)      
          
        logging.info("Verify switch does not generate an error")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,         
                                               timeout=5)
                
        self.assertTrue(response is None, 
                               'Switch did not negotiate on the version')  
Exemple #23
0
    def runTest(self):
        
        logging.info("Running Hello test")

        #Send Hello message
        logging.info("Sending Hello...")
        request = message.hello()
        request.data = 'OpenFlow Will Rule The World'
        self.controller.message_send(request)

        #Verify Hello message in response 
        logging.info("Waiting for a Hello on the control plane with same xid,version--1.0.0 and data field empty")
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,
                                               timeout=1)
        self.assertTrue(response is not None, 
                               'Switch did not exchange hello message in return') 
        self.assertEqual(len(response.data), 0, 'Response data field non-empty')
        self.assertTrue(response.header.version == 0x01, 'Openflow-version field is not 1.0.0')
Exemple #24
0
    def runTest(self):
        logging = get_logger()

        logging.info("Running TestNo40 VersionNegotiation Test")
        of_version = test_param_get('version', default=0x01)
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_HELLO,
                                               timeout=5)
        request = message.hello()
        request.header.version = 2
        rv = self.controller.message_send(request)

        logging.info(
            "Verifying switch does not generate an error message for a hello message with different version type"
        )
        (response, pkt) = self.controller.poll(exp_msg=ofp.OFPT_ERROR,
                                               timeout=5)
        self.assertTrue(response is None,
                        'Switch did not negotiate on the version')
Exemple #25
0
    def runTest(self):
        self.controllerSetup(cxn_config["controller_host"], cxn_config["controller_port"])

        cxn_logger.info("TCP Connected " + str(self.controller.switch_addr))
        cxn_logger.info("Sending hello")
        self.controller.message_send(message.hello())

        request = message.features_request()
        reply, pkt = self.controller.transact(request, timeout=20)
        self.assertTrue(reply is not None, "Did not complete features_request for handshake")
        cxn_logger.info("Handshake complete with " + str(self.controller.switch_addr))

        self.controller.keep_alive = True

        # keep controller up forever
        while self.controller.active:
            time.sleep(1)

        self.assertTrue(not self.controller.active, "Expected controller disconnect, but still active")
Exemple #26
0
    def runTest(self):
        self.controllerSetup(config["controller_host"],
                             config["controller_port"])

        logging.info("TCP Connected " + str(self.controller.switch_addr))
        logging.info("Sending hello")
        self.controller.message_send(message.hello())

        request = message.features_request()
        reply, pkt = self.controller.transact(request, timeout=20)
        self.assertTrue(reply is not None,
                        "Did not complete features_request for handshake")
        logging.info("Handshake complete with " +
                     str(self.controller.switch_addr))

        self.controller.keep_alive = True

        # keep controller up forever
        while self.controller.active:
            time.sleep(1)

        self.assertTrue(not self.controller.active,
                        "Expected controller disconnect, but still active")
Exemple #27
0
    def runTest(self):
        for conspec in self.controller_list:
            self.controllerSetup(conspec[0], conspec[1])
        for i in range(len(self.controller_list)):
            self.controllers[i].cstate = 0
            self.controllers[i].keep_alive = self.keep_alive
            self.controllers[i].saved_switch_addr = None
        tick = 0.1  # time period in seconds at which controllers are handled

        disconnected_count = 0
        cycle = 0
        while True:
            states = []
            for con in self.controllers:
                condesc = con.host + ":" + str(con.port) + ": "
                logging.debug("Checking " + condesc)

                if con.switch_socket:
                    if con.switch_addr != con.saved_switch_addr:
                        con.saved_switch_addr = con.switch_addr
                        con.cstate = 0

                    if con.cstate == 0:
                        logging.info(condesc + "Sending hello to " +
                                     str(con.switch_addr))
                        con.message_send(message.hello())
                        con.cstate = 1
                        con.count = 0
                    elif con.cstate == 1:
                        reply, pkt = con.poll(exp_msg=ofp.OFPT_HELLO,
                                              timeout=0)
                        if reply is not None:
                            logging.info(condesc + 
                                         "Hello received from " +
                                         str(con.switch_addr))
                            con.cstate = 2
                        else:
                            con.count = con.count + 1
                            # fall back to previous state on timeout
                            if con.count >= self.hello_timeout/tick:
                                logging.info(condesc + 
                                             "Timeout hello from " +
                                             str(con.switch_addr))
                                con.cstate = 0
                    elif con.cstate == 2:
                        logging.info(condesc + "Sending features request to " +
                                     str(con.switch_addr))
                        con.message_send(message.features_request())
                        con.cstate = 3
                        con.count = 0
                    elif con.cstate == 3:
                        reply, pkt = con.poll(exp_msg=ofp.OFPT_FEATURES_REPLY,
                                              timeout=0)
                        if reply is not None:
                            logging.info(condesc + 
                                         "Features request received from " +
                                         str(con.switch_addr))
                            con.cstate = 4
                            con.count = 0
                            cycle = cycle + 1
                            logging.info("Cycle " + str(cycle))
                        else:
                            con.count = con.count + 1
                            # fall back to previous state on timeout
                            if con.count >= self.features_req_timeout/tick:
                                logging.info(condesc +
                                             "Timeout features request from " +
                                             str(con.switch_addr))
                                con.cstate = 2
                    elif con.cstate == 4:
                        if (self.controller_timeout < 0 or
                            con.count < self.controller_timeout/tick):
                            logging.debug(condesc +
                                          "Maintaining connection to " +
                                          str(con.switch_addr))
                            con.count = con.count + 1
                        else:
                            logging.info(condesc + 
                                         "Disconnecting from " +
                                         str(con.switch_addr))
                            con.disconnect()
                            con.cstate = 0
                else:
                    con.cstate = 0
            
                states.append(con.cstate)

            logging.debug("Cycle " + str(cycle) +
                          ", states " + str(states) +
                          ", disconnected_count " + str(disconnected_count))
            if 4 in states:
                disconnected_count = 0
            else:
                disconnected_count = disconnected_count + 1
            if cycle != 0:
                self.assertTrue(disconnected_count < self.disconnected_timeout/tick,
                                "Timeout expired connecting to controller")
            else:
               # on first cycle, allow more time for initial connect
               self.assertTrue(disconnected_count < 2*self.disconnected_timeout/tick,
                               "Timeout expired connecting to controller on init")

            if cycle > self.cxn_cycles:
               break
            time.sleep(tick)