Esempio n. 1
0
    def __init__(
            self,
            log_levels=opendnp3.levels.NORMAL | opendnp3.levels.ALL_APP_COMMS,
            host_ip="127.0.0.1",  # presumably outstation
            local_ip="0.0.0.0",
            port=20000,
            log_handler=asiodnp3.ConsoleLogger().Create(),
            channel_listener=asiodnp3.PrintingChannelListener().Create(),
            soe_handler=asiodnp3.PrintingSOEHandler().Create(),
            master_application=asiodnp3.DefaultMasterApplication().Create(),
            stack_config=None):

        self.log_levels = log_levels
        self.host_ip = host_ip
        self.local_ip = local_ip
        self.port = port
        self.log_handler = log_handler
        self.channel_listener = channel_listener
        self.soe_handler = soe_handler
        self.master_application = master_application

        self.stackConfig = stack_config
        if not self.stackConfig:
            # The master config object for a master.
            self.stackConfig = asiodnp3.MasterStackConfig()
            self.stackConfig.master.responseTimeout = openpal.TimeDuration(
            ).Seconds(2)
            self.stackConfig.link.RemoteAddr = 10

        self.manager = None
        self.channel = None
        self.master = None
Esempio n. 2
0
def run_master(hang=False):
    """Demonstrate hanging when channel and master are not deleted prior to manager.Shutdown()
    """
    logger = asiodnp3.ConsoleLogger().Create()
    manager = asiodnp3.DNP3Manager(1, asiodnp3.ConsoleLogger().Create())
    #printing_channel_listener = asiodnp3.PrintingChannelListener().Create()
    channel = manager.AddTCPClient("tcpclient", FILTERS,
                                   asiopal.ChannelRetry(), HOST, LOCAL, PORT,
                                   asiodnp3.PrintingChannelListener().Create())
    stack_config = asiodnp3.MasterStackConfig()
    stack_config.master.responseTimeout = openpal.TimeDuration().Seconds(2)
    stack_config.link.RemoteAddr = 10
    soe_handler = asiodnp3.PrintingSOEHandler().Create()
    default_master_app = asiodnp3.DefaultMasterApplication().Create()
    master = channel.AddMaster("master", soe_handler, default_master_app,
                               stack_config)
    master.Enable()
    time.sleep(2)
    if not hang:
        #del logger
        #del printing_channel_listener
        del channel
        #del stack_config
        #del soe_handler
        #del default_master_app
        del master
    print("Shutdown, Hang = {}".format(hang))
    manager.Shutdown()
Esempio n. 3
0
def run_master():
    # Root DNP3 object used to create channels and sessions
    manager = asiodnp3.DNP3Manager(1, asiodnp3.ConsoleLogger().Create())

    # Connect via a TCPClient socket to an outstation
    channel = manager.AddTCPClient("tcpclient",
                                   FILTERS,
                                   asiopal.ChannelRetry(),
                                   HOST,
                                   LOCAL,
                                   PORT,
                                   asiodnp3.PrintingChannelListener().Create())

    # Master config object for a master
    stack_config = asiodnp3.MasterStackConfig()
    stack_config.master.responseTimeout = openpal.TimeDuration().Seconds(2)
    stack_config.link.RemoteAddr = 10

    # Add a master to a communication channel
    master = channel.AddMaster("master",
                               asiodnp3.PrintingSOEHandler().Create(),
                               asiodnp3.DefaultMasterApplication().Create(),
                               stack_config)

    # Enable the master. This will start communications.
    master.Enable()

    return manager
Esempio n. 4
0
def run_outstation():
    # Root DNP3 object used to create channels and sessions
    manager = asiodnp3.DNP3Manager(1, asiodnp3.ConsoleLogger().Create())

    # Connect via a TCPServer socket to a server
    channel = manager.AddTCPServer("server",
                                   FILTERS,
                                   asiopal.ChannelRetry().Default(),
                                   LOCAL,
                                   PORT,
                                   asiodnp3.PrintingChannelListener().Create())

    # A composite configuration struct that contains all the config information for a dnp3 outstation stack
    config = asiodnp3.OutstationStackConfig(opendnp3.DatabaseSizes.AllTypes(10))
    config.outstation.eventBufferConfig = opendnp3.EventBufferConfig().AllTypes(10)
    config.outstation.params.allowUnsolicited = True
    config.link.LocalAddr = 10
    config.link.KeepAliveTimeout = openpal.TimeDuration().Max()

    # Add an outstation to a communication channel
    outstation = channel.AddOutstation("outstation",
                                       opendnp3.SuccessCommandHandler().Create(),
                                       opendnp3.DefaultOutstationApplication().Create(),
                                       config)
    outstation.Enable()

    return manager
Esempio n. 5
0
    def __init__(
            self,
            log_handler=asiodnp3.ConsoleLogger().Create(),
            listener=asiodnp3.PrintingChannelListener().Create(),
            soe_handler=asiodnp3.PrintingSOEHandler().Create(),
            master_application=asiodnp3.DefaultMasterApplication().Create(),
            stack_config=None):

        _log.debug('Creating a DNP3Manager.')
        self.log_handler = log_handler
        self.manager = asiodnp3.DNP3Manager(1, self.log_handler)

        _log.debug('Creating the DNP3 channel, a TCP client.')
        self.retry = asiopal.ChannelRetry().Default()
        self.listener = listener
        self.channel = self.manager.AddTCPClient("tcpclient", FILTERS,
                                                 self.retry, HOST, LOCAL, PORT,
                                                 self.listener)

        _log.debug('Configuring the DNP3 stack.')
        self.stack_config = stack_config
        if not self.stack_config:
            self.stack_config = asiodnp3.MasterStackConfig()
            self.stack_config.master.responseTimeout = openpal.TimeDuration(
            ).Seconds(2)
            self.stack_config.link.RemoteAddr = 10

        _log.debug('Adding the master to the channel.')
        self.soe_handler = soe_handler
        self.master_application = master_application
        self.master = self.channel.AddMaster(
            "master",
            asiodnp3.PrintingSOEHandler().Create(), self.master_application,
            self.stack_config)

        _log.debug('Configuring some scans (periodic reads).')
        # Set up a "slow scan", an infrequent integrity poll that requests events and static data for all classes.
        self.slow_scan = self.master.AddClassScan(
            opendnp3.ClassField().AllClasses(),
            openpal.TimeDuration().Minutes(30),
            opendnp3.TaskConfig().Default())
        # Set up a "fast scan", a relatively-frequent exception poll that requests events and class 1 static data.
        self.fast_scan = self.master.AddClassScan(
            opendnp3.ClassField(opendnp3.ClassField.CLASS_1),
            openpal.TimeDuration().Minutes(1),
            opendnp3.TaskConfig().Default())

        self.channel.SetLogFilters(
            openpal.LogFilters(opendnp3.levels.ALL_COMMS))
        self.master.SetLogFilters(openpal.LogFilters(
            opendnp3.levels.ALL_COMMS))

        _log.debug(
            'Enabling the master. At this point, traffic will start to flow between the Master and Outstations.'
        )
        self.master.Enable()
        time.sleep(5)
Esempio n. 6
0
    def __init__(self,outstation_ip, outstation_id):
        
        self._soe_handler = SOEHandler()
        self._soe_handler.values = self.values

        log_handler = asiodnp3.ConsoleLogger().Create()

        self._manager = asiodnp3.DNP3Manager(1, log_handler)
        retry = asiopal.ChannelRetry().Default()
        listener = asiodnp3.PrintingChannelListener().Create()
        channel = self._manager.AddTCPClient('client', opendnp3.levels.NOTHING, retry, outstation_ip, '0.0.0.0', 20000, listener)
        master_application = asiodnp3.DefaultMasterApplication().Create()
        stack_config = asiodnp3.MasterStackConfig()
        stack_config.master.responseTimeout = openpal.TimeDuration().Seconds(2)
        stack_config.link.RemoteAddr = outstation_id

        self._master = channel.AddMaster('master', self._soe_handler, master_application, stack_config)
Esempio n. 7
0
    def End(self):
        # This is implementing an interface, so this function
        # must be declared.
        pass


values = {'analog': [], 'binary': []}

print("Starting")

# Create the manager for DNP3. This is always the first thing you
# need to do for OpenDNP3.
log_handler = asiodnp3.ConsoleLogger().Create()
manager = asiodnp3.DNP3Manager(1, log_handler)
retry = asiopal.ChannelRetry().Default()
listener = asiodnp3.PrintingChannelListener().Create()
channel = manager.AddTCPClient('client', opendnp3.levels.NOTHING, retry,
                               '192.168.69.166', '0.0.0.0', 20000, listener)

soe_handler = SOEHandler()
soe_handler.values = values

master_application = asiodnp3.DefaultMasterApplication().Create()
stack_config = asiodnp3.MasterStackConfig()
stack_config.master.responseTimeout = openpal.TimeDuration().Seconds(2)
stack_config.link.RemoteAddr = 10
master = channel.AddMaster('master', soe_handler, master_application,
                           stack_config)
master.Enable()

time.sleep(SLEEP_SECONDS)