예제 #1
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
예제 #2
0
 def configure_stack():
     """Set up the OpenDNP3 configuration."""
     stack_config = asiodnp3.OutstationStackConfig(opendnp3.DatabaseSizes.AllTypes(10))
     stack_config.outstation.eventBufferConfig = opendnp3.EventBufferConfig().AllTypes(10)
     stack_config.outstation.params.allowUnsolicited = True
     stack_config.link.LocalAddr = 10
     stack_config.link.RemoteAddr = 1
     stack_config.link.KeepAliveTimeout = openpal.TimeDuration().Max()
     return stack_config
예제 #3
0
    def run_outstation(self, value=None, index=0):
        # Callback interface for log messages
        self.handler = LogHandler()

        # Root DNP3 object used to create channels and sessions
        self.manager = asiodnp3.DNP3Manager(1, self.handler)

        # Connect via a TCPServer socket to a server
        self.channel_listener = ChannelListener()
        channel = self.manager.AddTCPServer("server",
                                            FILTERS,
                                            asiopal.ChannelRetry().Default(),
                                            LOCAL,
                                            PORT,
                                            self.channel_listener)

        # 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
        self.outstation_application = OutstationApplication()
        outstation = channel.AddOutstation("outstation",
                                           opendnp3.SuccessCommandHandler().Create(),
                                           self.outstation_application,
                                           config)
        outstation.Enable()

        # If the master is running, the channel listener state is OPENING
        assert self.channel_listener.state == opendnp3.ChannelState.OPENING

        if value is not None:
            # reset the logger id server to False before sending the cmd, if the cmd is sent successful,
            # the log handler should catch the logger id "server"
            self.handler.server = False

            builder = asiodnp3.UpdateBuilder()
            builder.Update(value, index)
            outstation.Apply(builder.Build())

            # If the message sent successful, the log handler should catch loggerid "server"
            time.sleep(2)
            assert self.handler.server == True

            # Test outstation application tracking info
            assert self.outstation_application.link_status == opendnp3.LinkStatus.UNRESET

        time.sleep(1)
        self.manager.Shutdown()
예제 #4
0
 def test_passing_args(self):
     """
         Create the class object with defined arguments and test if the object is not empty.
     """
     assert asiodnp3.ConsoleLogger(True) is not None
     assert asiodnp3.DatabaseConfig(opendnp3.DatabaseSizes()) is not None
     assert asiodnp3.DNP3Manager(1) is not None
     assert asiodnp3.DNP3Manager(
         1,
         asiodnp3.ConsoleLogger().Create()) is not None
     assert asiodnp3.OutstationStackConfig(
         opendnp3.DatabaseSizes()) is not None
     assert asiodnp3.X509Info(1, openpal.RSlice(), "test") is not None
     assert asiopal.ChannelRetry(openpal.TimeDuration(),
                                 openpal.TimeDuration()) is not None
     assert asiopal.ChannelRetry(openpal.TimeDuration(),
                                 openpal.TimeDuration(),
                                 asiopal.IOpenDelayStrategy()) is not None
     assert asiopal.Executor(asiopal.IO()) is not None
     assert asiopal.IPEndpoint("127.0.0.1", 502) is not None
     assert asiopal.LoggingConnectionCondition(openpal.Logger()) is not None
     assert asiopal.SerialChannel(asiopal.Executor(
         asiopal.IO())) is not None
     assert asiopal.TCPClient(openpal.Logger(),
                              asiopal.Executor(asiopal.IO()),
                              asiopal.IPEndpoint("127.0.0.1", 502),
                              "adapter") is not None
     assert asiopal.ThreadPool(openpal.Logger(), asiopal.IO(),
                               1) is not None
     assert asiopal.TLSConfig("~/files/peerCert", "~/files/localCert",
                              "~/files/privateKey") is not None
     assert opendnp3.AnalogOutputInt16(
         1, opendnp3.CommandStatus.TIMEOUT) is not None
     assert opendnp3.AnalogOutputInt32(
         1, opendnp3.CommandStatus.FORMAT_ERROR) is not None
     assert opendnp3.AnalogOutputFloat32(
         1, opendnp3.CommandStatus.ALREADY_ACTIVE) is not None
     assert opendnp3.AnalogOutputDouble64(
         1, opendnp3.CommandStatus.LOCAL) is not None
     assert opendnp3.BinaryCommandEvent(opendnp3.Flags()) is not None
     assert opendnp3.BinaryCommandEvent(opendnp3.Flags(),
                                        opendnp3.DNPTime()) is not None
     assert opendnp3.BinaryCommandEvent(
         True, opendnp3.CommandStatus.TOO_MANY_OPS) is not None
     assert opendnp3.BinaryCommandEvent(
         False, opendnp3.CommandStatus.NOT_AUTHORIZED,
         opendnp3.DNPTime()) is not None
     assert opendnp3.ClassField(opendnp3.PointClass.Class0) is not None
     assert opendnp3.ClassField(1) is not None
     assert opendnp3.ClassField(True, False, True, False) is not None
     assert opendnp3.ControlRelayOutputBlock(
         opendnp3.ControlCode.LATCH_ON, 1, 100, 100,
         opendnp3.CommandStatus.AUTOMATION_INHIBIT) is not None
     assert opendnp3.ControlRelayOutputBlock(
         0x1, 1, 100, 100,
         opendnp3.CommandStatus.AUTOMATION_INHIBIT) is not None
     assert opendnp3.GroupVariationID(0x10, 0x1) is not None
     assert opendnp3.IINField(opendnp3.IINBit.ALL_STATIONS) is not None
     assert opendnp3.IndexedBinary(opendnp3.Binary(), 1) is not None
     assert opendnp3.IndexedDoubleBitBinary(opendnp3.DoubleBitBinary(),
                                            1) is not None
     assert opendnp3.IndexedAnalog(opendnp3.Analog(), 1) is not None
     assert opendnp3.IndexedCounter(opendnp3.Counter(), 1) is not None
     assert opendnp3.IndexedFrozenCounter(opendnp3.FrozenCounter(),
                                          1) is not None
     assert opendnp3.IndexedBinaryOutputStatus(
         opendnp3.BinaryOutputStatus(), 1) is not None
     assert opendnp3.IndexedAnalogOutputStatus(
         opendnp3.AnalogOutputStatus(), 1) is not None
     assert opendnp3.IndexedOctetString(opendnp3.OctetString(),
                                        1) is not None
     assert opendnp3.IndexedTimeAndInterval(opendnp3.TimeAndInterval(),
                                            1) is not None
     assert opendnp3.IndexedBinaryCommandEvent(
         opendnp3.BinaryCommandEvent(), 1) is not None
     assert opendnp3.IndexedAnalogCommandEvent(
         opendnp3.AnalogCommandEvent(), 1) is not None
     assert opendnp3.IndexedSecurityStat(opendnp3.SecurityStat(),
                                         1) is not None
     assert opendnp3.IndexedControlRelayOutputBlock(
         opendnp3.ControlRelayOutputBlock(), 1) is not None
     assert opendnp3.IndexedAnalogOutputInt16(opendnp3.AnalogOutputInt16(),
                                              1) is not None
     assert opendnp3.IndexedAnalogOutputInt32(opendnp3.AnalogOutputInt32(),
                                              1) is not None
     assert opendnp3.IndexedAnalogOutputFloat32(
         opendnp3.AnalogOutputFloat32(), 1) is not None
     assert opendnp3.IndexedAnalogOutputDouble64(
         opendnp3.AnalogOutputDouble64(), 1) is not None
     assert opendnp3.Binary(True) is not None
     assert opendnp3.Binary(opendnp3.Flags()) is not None
     assert opendnp3.Binary(opendnp3.Flags(),
                            opendnp3.DNPTime()) is not None
     assert opendnp3.Binary(False, opendnp3.Flags()) is not None
     assert opendnp3.Binary(True, opendnp3.Flags(),
                            opendnp3.DNPTime()) is not None
     assert opendnp3.DoubleBitBinary(opendnp3.DoubleBit(1),
                                     opendnp3.Flags(),
                                     opendnp3.DNPTime()) is not None
     assert opendnp3.BinaryOutputStatus(False, opendnp3.Flags(),
                                        opendnp3.DNPTime()) is not None
     assert opendnp3.Analog(1.2, opendnp3.Flags(),
                            opendnp3.DNPTime()) is not None
     assert opendnp3.Counter(100, opendnp3.Flags(),
                             opendnp3.DNPTime()) is not None
     assert opendnp3.FrozenCounter(2000, opendnp3.Flags(),
                                   opendnp3.DNPTime()) is not None
     assert opendnp3.AnalogOutputStatus(109.68, opendnp3.Flags(),
                                        opendnp3.DNPTime()) is not None
     assert opendnp3.TimeAndInterval(opendnp3.DNPTime(), 10,
                                     0x1) is not None
     assert opendnp3.TimeAndInterval(
         opendnp3.DNPTime(), 10, opendnp3.IntervalUnits.Seconds) is not None
     assert opendnp3.OctetData(openpal.RSlice()) is not None
     assert opendnp3.OctetString(openpal.RSlice()) is not None
     assert opendnp3.SecurityStat(opendnp3.SecurityStatValue(), 0x1,
                                  opendnp3.DNPTime()) is not None
     assert opendnp3.SecurityStat(0x1, 10, 100) is not None
     assert opendnp3.SecurityStat(0x1, 10, 100,
                                  opendnp3.DNPTime()) is not None
     assert opendnp3.LinkConfig(True, True) is not None
     assert opendnp3.LinkConfig(True, False, 100, 10, 10,
                                openpal.TimeDuration(),
                                openpal.TimeDuration()) is not None
     assert opendnp3.LinkHeaderFields(opendnp3.LinkFunction.INVALID, False,
                                      True, False, 10, 10) is not None
     assert opendnp3.LinkStatistics(
         opendnp3.LinkStatisticsChannel(),
         opendnp3.LinkStatisticsParser()) is not None
     assert opendnp3.CommandPointResult(
         100, 10, opendnp3.CommandPointState.INIT,
         opendnp3.CommandStatus.PROCESSING_LIMITED) is not None
     assert opendnp3.HeaderInfo(opendnp3.GroupVariation.Group10Var0,
                                opendnp3.QualifierCode.UINT8_CNT,
                                opendnp3.TimestampMode.SYNCHRONIZED,
                                100) is not None
     assert opendnp3.RestartOperationResult(
         opendnp3.TaskCompletion.SUCCESS,
         openpal.TimeDuration()) is not None
     assert opendnp3.DatabaseSizes(0, 1, 2, 3, 4, 5, 6, 7) is not None
     assert opendnp3.EventBufferConfig(0, 1, 2, 3, 4, 5, 6, 7) is not None
     assert opendnp3.OutstationConfig(
         opendnp3.OutstationParams(),
         opendnp3.EventBufferConfig()) is not None
     assert opendnp3.OutstationParams(opendnp3.IndexMode.Contiguous, 0x3,
                                      openpal.TimeDuration(),
                                      openpal.TimeDuration(),
                                      openpal.TimeDuration(),
                                      openpal.TimeDuration(), 10, 20, True,
                                      opendnp3.StaticTypeBitField(),
                                      opendnp3.ClassField()) is not None
     assert opendnp3.SimpleCommandHandler(
         opendnp3.CommandStatus.SUCCESS) is not None
     assert opendnp3.StaticTypeBitField(1) is not None
     assert opendnp3.StackStatistics(
         opendnp3.StackStatisticsLink(),
         opendnp3.StackStatisticsTransport()) is not None
     assert openpal.ArrayBinaryConfig(1) is not None
     assert openpal.ArrayDoubleBitBinaryConfig(1) is not None
     assert openpal.ArrayAnalogConfig(1) is not None
     assert openpal.ArrayCounterConfig(1) is not None
     assert openpal.ArrayFrozenCounterConfig(1) is not None
     assert openpal.ArrayBOStatusConfig(1) is not None
     assert openpal.ArrayAOStatusConfig(1) is not None
     assert openpal.ArrayTimeAndIntervalConfig(1) is not None
     assert openpal.ArrayBuffer(10) is not None
     assert openpal.Buffer(27) is not None
     assert openpal.Buffer(openpal.RSlice()) is not None
     assert openpal.LinkedListInt(5) is not None
     assert openpal.PairInt(5, 10) is not None
     assert openpal.RSlice(0xFF, 100) is not None
     assert openpal.SecureBuffer(10) is not None
     assert openpal.SecureBuffer(openpal.RSlice()) is not None
     assert openpal.WSlice(0x30, 20) is not None
     assert openpal.MonotonicTimestamp(100) is not None
     assert openpal.UTCTimestamp(900) is not None
     assert openpal.LogEntry("123", openpal.LogFilters(), "location 1",
                             "test") is not None
     assert openpal.LogFilters(20) is not None
     assert openpal.LoggerSettings("234", openpal.LogFilters())
예제 #5
0
    def start(self):
        _log.debug('Configuring the DNP3 stack.')
        self.stack_config = asiodnp3.OutstationStackConfig(
            opendnp3.DatabaseSizes.AllTypes(
                self.outstation_config.get('database_sizes', 10000)))
        self.stack_config.outstation.eventBufferConfig = opendnp3.EventBufferConfig.AllTypes(
            self.outstation_config.get('event_buffers', 10))
        self.stack_config.outstation.params.allowUnsolicited = self.outstation_config.get(
            'allow_unsolicited', True)
        self.stack_config.link.LocalAddr = self.outstation_config.get(
            'link_local_addr', 10)
        self.stack_config.link.RemoteAddr = self.outstation_config.get(
            'link_remote_addr', 1)
        self.stack_config.link.KeepAliveTimeout = openpal.TimeDuration().Max()

        # Configure the outstation database of points based on the contents of the data dictionary.
        _log.debug('Configuring the DNP3 Outstation database.')
        db_config = self.stack_config.dbConfig
        for point in self.get_agent().point_definitions.all_points():
            if point.point_type == 'Analog Input':
                cfg = db_config.analog[int(point.index)]
            elif point.point_type == 'Binary Input':
                cfg = db_config.binary[int(point.index)]
            else:
                # This database's point configuration is limited to Binary and Analog data types.
                cfg = None
            if cfg:
                cfg.clazz = point.eclass
                cfg.svariation = point.svariation
                cfg.evariation = point.evariation

        _log.debug('Creating a DNP3Manager.')
        threads_to_allocate = self.outstation_config.get(
            'threads_to_allocate', 1)
        # self.log_handler = asiodnp3.ConsoleLogger().Create()              # (or use this during regression testing)
        # self.log_handler = MyLogger().Create()
        self.log_handler = MyLogger()
        self.manager = asiodnp3.DNP3Manager(threads_to_allocate,
                                            self.log_handler)

        _log.debug('Creating the DNP3 channel, a TCP server.')
        self.retry_parameters = asiopal.ChannelRetry().Default()
        # self.listener = asiodnp3.PrintingChannelListener().Create()       # (or use this during regression testing)
        self.listener = AppChannelListener()
        self.channel = self.manager.AddTCPServer("server",
                                                 self.dnp3_log_level(),
                                                 self.retry_parameters,
                                                 self.local_ip, self.port,
                                                 self.listener)

        _log.debug('Adding the DNP3 Outstation to the channel.')
        # self.command_handler =  opendnp3.SuccessCommandHandler().Create() # (or use this during regression testing)
        self.command_handler = OutstationCommandHandler()
        self.outstation = self.channel.AddOutstation("outstation",
                                                     self.command_handler,
                                                     self, self.stack_config)

        # Set the singleton instance that communicates with the Master.
        self.set_outstation(self.outstation)

        _log.info(
            'Enabling the DNP3 Outstation. Traffic can now start to flow.')
        self.outstation.Enable()