예제 #1
0
    def createSessionConfig(self, mode):
        """
        Creates an instance of SessionConfig with the given transport mode and
        sets the reconnect timer to one minute. All other attributes are set to
        their default values.

        When connecting to a network element, the caller may optionally provide a
        SessionConfig that contains the desired configuration for the resulting
        session. When creating the SessionConfig, the only required attribute is
        the transport mode. TLS is the transport mode used for the end node
        hosting model. TIPC (sometimes referred to as LOCAL) may be used in
        process and blade hosting models. All other attributes are optional,
        and will take on their default values if not explicitly set. To
        demonstrate reconnecting to the session, the reconnect timer will be set
        to one minute.

        @param mode The transport mode used by the connection.
        @return a SessionConfig instance.
        """

        #  START SNIPPET: create_session_config
        #  Construct a SessionConfig instance with the given transport mode.
        config = SessionConfig(mode)
        #  Set the reconnect timer to one minute.
        config.reconnectTimer = 60
        #  The session attributes below this point are set to their default
        #  values.
        #
        #  Set the port to connect to on the network element.
        #  TLS      15002
        #  TIPC     N/A
        #
        if mode.lower() == "tls":
            config.port = config.DEFAULT_PORT
            config.transportMode = SessionConfig.SessionTransportMode.TLS
            config.ca_certs = tutorial.root_cert_path
            config.keyfile = tutorial.client_key_path
            config.certfile = tutorial.client_cert_path
        else:
            #  Not required for TIPC.
            pass
        #  Set the event queue size of the session.
        config.eventQueueSize = config.DEFAULT_EVENT_QUEUE_SIZE
        #  Set the event thread pool size of the session.
        config.eventThreadPool = config.DEFAULT_THREADPOOL_SIZE
        #  Set the event drop mode of the session.
        config.eventDropMode = config.DEFAULT_EVENT_DROP_MODE
        #  Set the keepalive attributes of the session.
        #  Idle time in seconds
        config.keepAliveIdleTime = config.DEFAULT_KEEPALIVE_IDLE_TIME
        #  Interval between keepalives in seconds
        config.keepAliveInterval = config.DEFAULT_KEEPALIVE_INTERVAL
        #  Number of keepalives
        config.keepAliveRetryCount = config.DEFAULT_KEEPALIVE_RETRY_COUNT
        #  END SNIPPET: create_session_config
        config.set_tls_pinning(tutorial.tls_pinning_file,
                               PinningHandler(tutorial.tls_pinning_file))
        return config