SDN Controller Programming Guide
24
All OpenFlow messages will be fully creatable/encodable/decodable, making the library
completely symmetrical in this respect.
The controller (or app) would never create certain messages (such as PortStatus,
FlowRemoved, MultipartReply, etc.) as these are only ever generated by the switch.
Technically, we would only need to decode those messages, never encode them.
However, providing a complete solution allows us to emulate OpenFlow switches in Java
code. This will facilitate the writing of automated tests to verify switch/controller
interactions in a deterministic manner.
Message instances, for the most part, will be immutable.
This means a single instance may be shared safely across multiple applications (and
multiple threads) without synchronization.
This implies that the structures that make up the message (ports, instructions, actions, etc.)
must also be immutable.
Where possible, “Cacheable Data Types” will be used to encourage API type-safety –
see the Javadocs for com.hp.util.ip and com.hp.of.lib.dt.
Where bitmasks are defined in the protocol, Java enumerations will be defined with a
constant for each bit.
A specific bitmask value will be represented by a Set of the appropriate enumeration
constants.
For example: Set<PortConfig>
A message instance will be mutable only while the message is under construction (for
example, an application composing a FlowMod message). To be sent through the system is
must be converted to its immutable form first.
To create and send a message, an application will:
Use the Message Factory to create a mutable message of the required type
Set the state (payload) of the message
Make the message immutable
Send the message via the ControllerService API.
The Core Controller will use the Message Factory to encode the message into its byte-stream
form, for transmitting to the switch.
The Core Controller will use the Message Factory to decode incoming messages from their
byte-stream form into their (immutable) rich data type form.