Sockets
The socket node-type is the most comprehensive and complex one. It allows to send and receive simulation data over the network. Internally it uses the well known BSD socket API.
Please note that only datagram / packet, connection-less based network protocols are supported. This means that there's currently no support for TCP!
The implementation supports multiple protocols / OSI layers:
- Data-Link Layer 2: Raw Ethernet Frames (no routing!)
- Network Layer 3: Raw IP (internet / VPN routing possible)
- Transport Layer 4: UDP encapsulation, TCP client or server
Prerequisites
This node-type does not have any special library dependencies. It is always available.
Optionally, libnl3 is used to setup network emulation as described in page Netem Emulation.
Implementation
The source code of the node-type is available here: https://github.com/VILLASframework/node/blob/master/lib/nodes/socket.cpp
Configuration
For TCP connection, the node can only be either server or client which is specified by "tcp-server" or "tcp-client" in the layer section.
Format Object (object) or Format Name (string) (format_spec) | |
| layer | string Default: "udp" Enum: "udp" "ip" "eth" "tcp-client" "tcp-server" Select the network layer which should be used for the socket. Please note that |
| verify_source | boolean Default: false Check if source address of incoming packets matches the remote address. |
object (Input configuration (received by VILLASnode)) | |
object (Output configuration (sent out by VILLASnode)) | |
| vectorize | integer Default: 1 This setting allows to send multiple samples in a single message to the destination nodes. The value of this setting determines how many samples will be combined into one packet. |
Array of Hook Object (object) or Hook Name (string) (hook_list) | |
| builtin | boolean (Builtin hook functions) Default: true By default, each node and paths has a couple of default hooks attached to them. With this setting the attachment of built-in hooks can be disabled. |
{- "format": "villas.human",
- "layer": "udp",
- "verify_source": false,
- "in": {
- "address": "string",
- "signals": [
- {
- "name": "tap_position",
- "type": "integer",
- "init": 0
}, - {
- "name": "voltage",
- "type": "float",
- "unit": "V",
- "init": 230
}
], - "vectorize": 1,
- "hooks": [
- "print",
- {
- "type": "limit_rate",
- "rate": 1000
}
]
}, - "out": {
- "address": "string",
- "netem": {
- "enabled": true,
- "delay": 0,
- "jitter": 0,
- "distribution": "uniform",
- "loss": 0,
- "duplicate": 0,
- "corrupt": 0
}, - "multicast": {
- "enabled": true,
- "group": "string",
- "ttl": 0,
- "loop": true
}, - "vectorize": 0,
- "hooks": [
- "print",
- {
- "type": "limit_rate",
- "rate": 1000
}
]
}, - "vectorize": 1,
- "hooks": [
- "print",
- {
- "type": "limit_rate",
- "rate": 1000
}
], - "builtin": true
}Example
nodes = {
udp_node = {
type = "socket"
# Receive and sent 30 samples per message (combining)
vectorize = 30
# The maximum number of samples this node can receive
samplelen = 10
# By default, all nodes will have a few builtin hooks attached to them
# When collecting statistics or measurements these are undesired
builtin = false
# Layer can be one of:
# - udp Send / receive L4 UDP packets
# - ip Send / receive L3 IP packets
# - eth Send / receive L2 Ethernet frames (IEEE802.3)
layer = "udp"
format = "gtnet"
in = {
# This node only received messages on this IP:Port pair
address = "127.0.0.1:12001"
# Check if source address of incoming packets matches the remote address
verify_source = true
}
out = {
# This node sends outgoing messages to this IP:Port pair
address = "127.0.0.1:12000"
}
}
# Raw Ethernet frames
ethernet_node = {
type = "socket"
layer = "eth"
in = {
address = "12:34:56:78:90:AB%lo:12002"
}
out = {
address = "12:34:56:78:90:AB%lo:12002"
}
}
# Datagram UNIX domain sockets require two endpoints
unix_domain_node = {
type = "socket"
layer = "unix"
in = {
address = "/var/run/villas-node/node.sock"
}
out = {
address = "/var/run/villas-node/client.sock"
}
}
udp_multicast_node = {
type = "socket"
in = {
# This node only received messages on this IP:Port pair
address = "127.0.0.1:12001"
# IGMP multicast is only support for layer = (ip|udp)
multicast = {
enabled = true
# The multicast group. Must be within 224.0.0.0/4
group = "224.1.2.3"
# The IP address of the interface which should receive multicast packets
interface = "1.2.3.4"
# The time to live for outgoing multicast packets
ttl = 128
# Whether or not to loopback outgoing multicast packets to the local host
loop = false
}
}
out = {
# This node sends outgoing messages to this IP:Port pair
address = "127.0.0.1:12000"
}
}
}