Node utilities
API reference for various utilities in diameter.node
.
SequenceGenerator ¶
SequenceGenerator(include_now: int = None)
A sequence generator base class.
By default, is just a non-persistent counter that loops back to 1 when max sequence is reached. Can be overwritten by implementing parties, if any kind of persistence over reboots is required.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_now
|
int
|
An optional unix timestamp. If provided, sets the high order bits of the initial sequence value to the provided time, as suggested by rfc6733. The remaining bits are always initialised to a random value. |
None
|
SessionGenerator ¶
SessionGenerator(node_name: str)
A sequential session generator that guarantees uniqueness.
This generator produces diameter session IDs that conform to rfc6733 8.8 by producing "globally and eternally unique" IDs, by creating session IDs that begin with the diameter entity and have ";"-separated sections of hexadecimal values that guarantee uniqueness. Optional implementation specific values may be appended to each session.
The rfc-suggested method of producing uniqueness is not used. Instead, the generator sets a base initial value on generator creation that equals the current time. This value remains unchanged for the lifetime of the generator. The generator also creates a random 64-bit integer on startup and will increase it by one for every new session ID. The integer values are encoded in hexacecimal. The format is:
<DiameterIdentity>;<startup timestamp>;<high 32 bits>;<low 32 bits>[;<optional values>]
The generator holds a threading lock while session IDs are generated, ensuring that no duplicate IDs may be produced. If the internal 64-bit sequence reaches maximum value of 0xffffffffffffffff, it overflows back to 1.
Examples:
>>> g = SessionGenerator("test2.gy.local.realm")
>>> g.next_id()
test2.gy.local.realm;6571a525;5bd295f2;6c76d6b6
>>> g.next_id()
test2.gy.local.realm;6571a525;5bd295f2;6c76d6b7
>>> # note how the base timestamp changes when generator restarts:
g = SessionGenerator("test2.gy.local.realm")
>>> g.next_id()
test2.gy.local.realm;6571a525;1967cbd0;8e9e3a16
>>> # passing optional values:
>>> g.next_id("user@host", "hello")
test2.gy.local.realm;6571a525;1967cbd0;8e9e3a17;user@host;hello
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_name
|
str
|
Diameter identity of the node, will be embedded in the generated session IDs. |
required |
next_id ¶
next_id(*optional: str) -> str
Generate the next session ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*optional
|
str
|
Any string values to append as optional fields at the end of the generated session IDs. The values will be separated by ";" |
()
|
parse_diameter_uri ¶
parse_diameter_uri(uri: str) -> DiameterUri
Parses a diameter URI.
Follows the rfc6733 4.3.1 specification for a DiameterURI value and parses URIs such as:
- aaa://host.example.com;transport=tcp
- aaa://host.example.com:5959;transport=tcp;protocol=diameter
- aaas://host.example.com;transport=sctp
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
A string that contains at least "://" |
required |
Returns:
Type | Description |
---|---|
DiameterUri
|
A |
DiameterUri ¶
validate_message_avps ¶
validate_message_avps(msg: _AnyMessageType) -> list[Avp]
Validate that a message has all the mandatory AVPs set.
The validation works only for the commands that have a python
implementation, containing an avp_def
attribute, listing the mandatory
AVPs. This is true for every message.commands.*
subclass. For any other
message type will return an empty list.
Returns:
Type | Description |
---|---|
list[Avp]
|
A list of |