'Establish a Connection object.
Determines the correct options to use when creating any
connections needed by this Transport, and create a
:class:`Connection` object which saves those values for
connections generated as they are needed. The options are a
mixture of what is passed in through the creator of the
Transport, and the defaults provided by
:meth:`default_connection_params`. Options cover broker network
settings, timeout behaviors, authentication, and identity
verification settings.
This method also creates and stores a
:class:`~qpid.messaging.endpoints.Session` using the
:class:`~qpid.messaging.endpoints.Connection` created by this
method. The Session is stored on self.
:return: The created :class:`Connection` object is returned.
:rtype: :class:`Connection`'

def establish_connection(self):

    conninfo = self.client
    for (name, default_value) in items(self.default_connection_params):
        if (not getattr(conninfo, name, None)):
            setattr(conninfo, name, default_value)
    if conninfo.ssl:
        conninfo.qpid_transport = u'ssl'
        conninfo.transport_options[u'ssl_keyfile'] = conninfo.ssl[u'keyfile']
        conninfo.transport_options[u'ssl_certfile'] = conninfo.ssl[u'certfile']
        conninfo.transport_options[u'ssl_trustfile'] = conninfo.ssl[u'ca_certs']
        if (conninfo.ssl[u'cert_reqs'] == ssl.CERT_REQUIRED):
            conninfo.transport_options[u'ssl_skip_hostname_check'] = False
        else:
            conninfo.transport_options[u'ssl_skip_hostname_check'] = True
    else:
        conninfo.qpid_transport = u'tcp'
    credentials = {}
    if (conninfo.login_method is None):
        if ((conninfo.userid is not None) and (conninfo.password is not None)):
            sasl_mech = u'PLAIN'
            credentials[u'username'] = conninfo.userid
            credentials[u'password'] = conninfo.password
        elif ((conninfo.userid is None) and (conninfo.password is not None)):
            raise Exception(u'Password    configured    but    no    username.    SASL    PLAIN    requires    a    username    when    using    a    password.')
        elif ((conninfo.userid is not None) and (conninfo.password is None)):
            raise Exception(u'Username    configured    but    no    password.    SASL    PLAIN    requires    a    password    when    using    a    username.')
        else:
            sasl_mech = u'ANONYMOUS'
    else:
        sasl_mech = conninfo.login_method
        if (conninfo.userid is not None):
            credentials[u'username'] = conninfo.userid
    opts = {u'host': conninfo.hostname, u'port': conninfo.port, u'sasl_mechanisms': sasl_mech, u'timeout': conninfo.connect_timeout, u'transport': conninfo.qpid_transport}
    opts.update(credentials)
    opts.update(conninfo.transport_options)
    conn = self.Connection(**opts)
    conn.client = self.client
    self.session = conn.get_qpid_connection().session()
    self.session.set_message_received_notify_handler(self._qpid_message_ready_handler)
    conn.get_qpid_connection().set_async_exception_notify_handler(self._qpid_async_exception_notify_handler)
    self.session.set_async_exception_notify_handler(self._qpid_async_exception_notify_handler)
    return conn
