Refactored nicira extended actions
This commit is contained in:
parent
efd08cf6dd
commit
ffcba91395
51 changed files with 1015 additions and 819 deletions
|
|
@ -16,54 +16,43 @@ defmodule Openflow.Action.NxMultipath do
|
|||
@nxast 10
|
||||
|
||||
alias __MODULE__
|
||||
alias Openflow.Action.Experimenter
|
||||
|
||||
def new(options) do
|
||||
hash_field = Keyword.get(options, :hash_field, :eth_src)
|
||||
basis = Keyword.get(options, :basis, 0)
|
||||
alg = Keyword.get(options, :algorithm, :modulo_n)
|
||||
max_link = Keyword.get(options, :max_link, 0)
|
||||
arg = Keyword.get(options, :argument, 0)
|
||||
dst_field = Keyword.get(options, :dst_field)
|
||||
def new(options \\ []) do
|
||||
dst_field = options[:dst_field] || raise "dst_field must be specified"
|
||||
default_n_bits = Openflow.Match.Field.n_bits_of(dst_field)
|
||||
n_bits = Keyword.get(options, :n_bits, default_n_bits)
|
||||
ofs = Keyword.get(options, :offset, 0)
|
||||
|
||||
%NxMultipath{
|
||||
hash_field: hash_field,
|
||||
basis: basis,
|
||||
algorithm: alg,
|
||||
max_link: max_link,
|
||||
offset: ofs,
|
||||
n_bits: n_bits,
|
||||
argument: arg,
|
||||
hash_field: options[:hash_field] || :eth_src,
|
||||
basis: options[:basis] || 0,
|
||||
algorithm: options[:algorithm] || :modulo_n,
|
||||
max_link: options[:max_link] || 0,
|
||||
offset: options[:offset] || 0,
|
||||
n_bits: options[:n_bits] || default_n_bits,
|
||||
argument: options[:argument] || 0,
|
||||
dst_field: dst_field
|
||||
}
|
||||
end
|
||||
|
||||
def to_binary(%NxMultipath{
|
||||
hash_field: hash_field,
|
||||
basis: basis,
|
||||
algorithm: alg,
|
||||
max_link: max_link,
|
||||
argument: arg,
|
||||
offset: ofs,
|
||||
n_bits: n_bits,
|
||||
dst_field: dst_field
|
||||
}) do
|
||||
hash_field_int = Openflow.Enums.to_int(hash_field, :nx_hash_fields)
|
||||
alg_int = Openflow.Enums.to_int(alg, :nx_mp_algorithm)
|
||||
dst_field_bin = Openflow.Match.codec_header(dst_field)
|
||||
ofs_nbits = ofs <<< 6 ||| n_bits - 1
|
||||
def to_binary(%NxMultipath{} = multipath) do
|
||||
hash_field_int = Openflow.Enums.to_int(multipath.hash_field, :nx_hash_fields)
|
||||
alg_int = Openflow.Enums.to_int(multipath.algorithm, :nx_mp_algorithm)
|
||||
dst_field_bin = Openflow.Match.codec_header(multipath.dst_field)
|
||||
ofs_nbits = multipath.offset <<< 6 ||| multipath.n_bits - 1
|
||||
|
||||
body =
|
||||
<<hash_field_int::16, basis::16, 0::size(2)-unit(8), alg_int::16, max_link::16, arg::32,
|
||||
0::size(2)-unit(8), ofs_nbits::16, dst_field_bin::4-bytes>>
|
||||
|
||||
exp_body = <<@experimenter::32, @nxast::16, body::bytes>>
|
||||
exp_body_size = byte_size(exp_body)
|
||||
padding_length = Openflow.Utils.padding(4 + exp_body_size, 8)
|
||||
length = 4 + exp_body_size + padding_length
|
||||
<<0xFFFF::16, length::16, exp_body::bytes, 0::size(padding_length)-unit(8)>>
|
||||
Experimenter.pack_exp_header(<<
|
||||
@experimenter::32,
|
||||
@nxast::16,
|
||||
hash_field_int::16,
|
||||
multipath.basis::16,
|
||||
0::size(2)-unit(8),
|
||||
alg_int::16,
|
||||
multipath.max_link::16,
|
||||
multipath.argument::32,
|
||||
0::size(2)-unit(8),
|
||||
ofs_nbits::16,
|
||||
dst_field_bin::4-bytes
|
||||
>>)
|
||||
end
|
||||
|
||||
def read(<<@experimenter::32, @nxast::16, body::bytes>>) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue