session

package
v0.0.0-...-26ed527 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2022 License: CC0-1.0 Imports: 7 Imported by: 0

Documentation

Overview

Package session provides the OSI transport and session layers.

Index

Constants

View Source
const (
	// TCPPort is the IANA registered port number for unsecure connection.
	TCPPort = 2404

	// TCPPortSecure is the IANA registered port number for secure connection.
	TCPPortSecure = 19998
)

Variables

View Source
var (
	// ErrConnLost signals unknown reception status.
	ErrConnLost = errors.New("part5: connection lost")

	// ErrNoConn signals unable to perform.
	ErrNoConn = errors.New("part5: no connection")
)
View Source
var Trace = false

Trace activates wire logging.

Functions

func Pipe

func Pipe(timeout time.Duration) (*Transport, *Transport)

Pipe creates a synchronous, in-memory, full duplex session. Reads on one end are matched with writes on the other, copying data directly between the two; there is no internal buffering. The timeout sets the upper limit for an Outbound block.

Types

type Level

type Level uint

Level is the availability status.

const (
	Exit Level = iota // no connection
	Down              // not operational
	Up                // operational
)

func (Level) String

func (l Level) String() string

String returns a name.

type Outbound

type Outbound struct {
	Payload []byte // datagram

	// In case of failure exactly one error is send.
	// It is safe to wait for the channel to close once
	// the submission (either class Ⅰ or Ⅱ) is accepted.
	Done <-chan error
	// contains filtered or unexported fields
}

Outbound is a single-use data submission handle.

func NewOutbound

func NewOutbound(payload []byte) *Outbound

NewOutbound returns a new Outbound ready to use [once].

type Station

type Station struct {
	Transport

	Addr net.Addr // remote address

	// Level propagates status changes and must be read or
	// operation blocks and may behave in an unexpected way.
	Level <-chan Level

	// Launch targets a level.
	// Any failure to do so terminates the connection.
	Launch chan<- Level
}

Station is an RTU (remote terminal unit) or SCADA (Supervisory Control And Data Acquisition) system.

func TCP

func TCP(conf *TCPConf, conn net.Conn) *Station

TCP returns a session with status Down.

type TCPConf

type TCPConf struct {
	// Maximum amount of time for TCP connection establishment. The standard
	// specifies "t₀" in [1, 255] seconds with a default of 30.
	ConnectTimeout time.Duration

	// Upper limit for the number of I-frames send without reception of a
	// confiramation. Transmission stops once this number has been reached.
	// The standard specifies "k" in [1, 32767] with a default of 12.
	// See IEC 60870-5-104, subclause 5.5.
	SendUnackMax uint

	// Maximum amount of time for frame reception confirmation. On expiry
	// the connection is closed immediately. The standard specifies "t₁" in
	// [1, 255] seconds with a default of 15.
	// See IEC 60870-5-104, figure 18.
	SendUnackTimeout time.Duration

	// Upper limit for the number of I-frames received without sending a
	// receival confirmation. It is recommended that RecvUnackMax should not
	// exceed two thirds of SendUnackMax. The standard specifies "w" in [1,
	// 32767] with a default of 8.
	// See IEC 60870-5-104, subclause 5.5.
	RecvUnackMax uint

	// Maximum amount of time allowed for sending a receival confirmation.
	// In practice this framework will send such acknowledgement within a
	// second. The standard specifies "t₂" in [1, 255] seconds with a
	// default of 10.
	// See IEC 60870-5-104, figure 10.
	RecvUnackTimeout time.Duration

	// Amount of idle time needed to trigger "TESTFR" keep-alives. The
	// standard recommends "t₃" in [1 second, 48 hours] and the default is
	// set to 20 seconds.
	// See IEC 60870-5-104, subclause 5.2.
	IdleTimeout time.Duration
}

TCPConf defines an IEC 60870-5-104 configuration. The default is applied for each unspecified value.

type Transport

type Transport struct {
	// In captures inbound datagrams in order of appearance.
	In <-chan []byte

	// Class1 blocks until the payload is accepted
	// and sealed with timeout protection mechanisms.
	// Class Ⅰ data transmission is typically used for
	// events or for messages with high priority.
	Class1 chan<- *Outbound

	// Class2 blocks until the payload is accepted
	// and sealed with timeout protection mechanisms.
	// Class Ⅱ data transmission is typically used for
	// cyclic transmission or for low priority messages.
	Class2 chan<- *Outbound

	// Err captures all protocol failures which are not
	// directly related to an Outbound submission.
	Err <-chan error
}

Transport layer as datagram channels. Channel In and Err MUST be read continuously or operation may block and behave in an unexpected way. On Exit, In is closed first follewed by Err. Both Class1 and Class2 MUST be closed by the user and doing so ensures an Exit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL