I have a question: using new libs (loom, ofs_handler, of_driver) I need to send settings message to switch. I have to create record like this:
-record(ofp_field, {
class = openflow_basic :: ofp_field_class(),
name :: ofp_field_type(),
has_mask = false :: boolean(),
value :: bitstring(),
mask :: bitstring()
}).
But 'value' must be a bitstring, and I don't know how to correctly convert a port number (e.g. 8080, 6633) to a bitstring, because I can make <<Port>>, <<Port:32/integer>>
and get different results.
Does anyone have an idea how make it right?
Or do I have to use binary:encode_unsigned
?
In the OpenFlow protocol, TCP and UDP port numbers are represented as 16-bit integers (see table 12 in the 1.4.0 specification). Thus you should write <<Port:16>>
.
OpenFlow uses big-endian integers (i.e. network byte order) throughout, which is what Erlang generates if you don't specify another endianness, so that code will work correctly on any platform. (In C, you would have to convert between host and network byte order.) See "Bit Syntax Expressions in the Erlang Reference Manual" for how to use a different endianness, should you need it for some other protocol.