otupy.core.producer.Producer

class Producer(producer: str, encoder: Encoder = None, transfer: Transfer = None)

Bases: object

OpenC2 Producer

An OpenC2 Producer sends Commands and receives Responses. The Producer is an intermediary to deal with OpenC2-related issues, but does not implement any control logic. A Producer instance is used to create an OpenC2 stack with an Encoder and a Transfer protocol. The Producer is associated to an identifier to distinguish its messages.

Note that the actuator instance is only known to the consumer, which runs it. The producer

knows the profile of the actuator, which embeds the an identifier for the actual actuator run by the consumer.

Methods

sendcmd

Send an OpenC2 message

__init__(producer: str, encoder: Encoder = None, transfer: Transfer = None)

Initialize an OpenC2 stack

Creates a Producer communication stack made of an identifier, an Encoding format, and a Transfer protocol. This will be used as the “default” stack if no otherwise overwritten when sending the message. Both the Encoding and Transfer class must be derived from the base Encoder and Transfer definition.

Parameters:
  • producer – A string that identifies the Producer.

  • encoder – An instance of an Encoding class derived from base Encoder.

  • transfer – An instnace of a Transfer protocol derived from base Transfer.

sendcmd(cmd: Command, encoder: Encoder = None, transfer: Transfer = None, consumers: [] = None)

Send an OpenC2 message

Sends an otupy Command. The default communication stack is used, if a different one is not specified. This method internally creates the Message metadata that will be encoded and traferred.

The option to create a different stack is given to manage the presence of multiple Consumer with different stacks. However, it is recommended to create different Producer`s in this case. Note that the `consumer argument is meant for internal use of a Consumer only, because the endpoint of the message is always identified by the Transfer definition.

Parameters:
  • cmd – The Command to be sent.

  • encoder – An instance of an Encoding class derived from base Encoder.

  • transfer – An instnace of a Transfer protocol derived from base Transfer.

  • consumers – An optional list of strings that identify multiple intended recipients of the message.

Returns:

The Response to the Command.