Implement Openflow Protocol and Callback system
This commit is contained in:
parent
fc02a678de
commit
e52fe31b79
48 changed files with 937 additions and 244 deletions
|
|
@ -14,15 +14,12 @@ defmodule Openflow.Action.NxBundle do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
hash_field = Keyword.get(options, :hash_field, :eth_src)
|
||||
basis = Keyword.get(options, :basis, 0)
|
||||
alg = Keyword.get(options, :algorithm, :active_backup)
|
||||
slaves = Keyword.get(options, :slaves, [])
|
||||
%NxBundle{algorithm: alg,
|
||||
hash_field: hash_field,
|
||||
basis: basis,
|
||||
n_slaves: length(slaves),
|
||||
slaves: slaves}
|
||||
slaves = options[:slaves] || []
|
||||
%NxBundle{algorithm: options[:algorithm] || :active_backup,
|
||||
hash_field: options[:hash_field] || :eth_src,
|
||||
basis: options[:basis] || 0,
|
||||
n_slaves: length(slaves),
|
||||
slaves: slaves}
|
||||
end
|
||||
|
||||
def to_binary(%NxBundle{algorithm: alg,
|
||||
|
|
|
|||
|
|
@ -19,22 +19,17 @@ defmodule Openflow.Action.NxBundleLoad do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
hash_field = Keyword.get(options, :hash_field, :eth_src)
|
||||
basis = Keyword.get(options, :basis, 0)
|
||||
alg = Keyword.get(options, :algorithm, :active_backup)
|
||||
slaves = Keyword.get(options, :slaves, [])
|
||||
dst_field = Keyword.get(options, :dst_field)
|
||||
dst_field = options[:dst_field]
|
||||
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)
|
||||
%NxBundleLoad{algorithm: alg,
|
||||
hash_field: hash_field,
|
||||
basis: basis,
|
||||
n_slaves: length(slaves),
|
||||
slaves: slaves,
|
||||
offset: ofs,
|
||||
n_bits: n_bits,
|
||||
dst_field: dst_field}
|
||||
slaves = options[:slaves] || []
|
||||
%NxBundleLoad{algorithm: options[:algorithm] || :active_backup,
|
||||
hash_field: options[:hash_field] || :eth_src,
|
||||
basis: options[:basis] || 0,
|
||||
n_slaves: length(slaves),
|
||||
slaves: slaves,
|
||||
offset: options[:offset] || 0,
|
||||
n_bits: options[:n_bits] || default_n_bits,
|
||||
dst_field: options[:dst_field]}
|
||||
end
|
||||
|
||||
def to_binary(%NxBundleLoad{algorithm: alg,
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@ defmodule Openflow.Action.NxConjunction do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
clause = Keyword.get(options, :clause, 0)
|
||||
n_clauses = Keyword.get(options, :n_clauses, 0)
|
||||
id = Keyword.get(options, :id, 0)
|
||||
%NxConjunction{clause: clause, n_clauses: n_clauses, id: id}
|
||||
%NxConjunction{clause: options[:clause] || 0,
|
||||
n_clauses: options[:n_clauses] || 0,
|
||||
id: options[:id] || 0}
|
||||
end
|
||||
|
||||
def to_binary(%NxConjunction{clause: clause, n_clauses: n_clauses, id: id}) do
|
||||
|
|
|
|||
|
|
@ -18,24 +18,14 @@ defmodule Openflow.Action.NxConntrack do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options \\ []) do
|
||||
flags = Keyword.get(options, :flags, [])
|
||||
zone_src = Keyword.get(options, :zone_src)
|
||||
zone_ofs = Keyword.get(options, :zone_offset)
|
||||
zone_n_bits = Keyword.get(options, :zone_n_bits)
|
||||
zone_imm = Keyword.get(options, :zone_imm, 0)
|
||||
recirc_table = Keyword.get(options, :recirc_table, 255)
|
||||
alg = Keyword.get(options, :alg, 0)
|
||||
exec = Keyword.get(options, :exec, [])
|
||||
%NxConntrack{
|
||||
flags: flags,
|
||||
zone_src: zone_src,
|
||||
zone_imm: zone_imm,
|
||||
zone_offset: zone_ofs,
|
||||
zone_n_bits: zone_n_bits,
|
||||
recirc_table: recirc_table,
|
||||
alg: alg,
|
||||
exec: exec
|
||||
}
|
||||
%NxConntrack{flags: options[:flags] || [],
|
||||
zone_src: options[:zone_src],
|
||||
zone_imm: options[:zone_imm] || 0,
|
||||
zone_offset: options[:zone_offset],
|
||||
zone_n_bits: options[:zone_n_bits],
|
||||
recirc_table: options[:recirc_table] || 255,
|
||||
alg: options[:alg] || 0,
|
||||
exec: options[:exec] || []}
|
||||
end
|
||||
|
||||
def to_binary(%NxConntrack{
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@ defmodule Openflow.Action.NxController do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
max_len = Keyword.get(options, :max_len, :no_buffer)
|
||||
controller_id = Keyword.get(options, :id, 0)
|
||||
reason = Keyword.get(options, :reason, :action)
|
||||
%NxController{max_len: max_len, id: controller_id, reason: reason}
|
||||
%NxController{max_len: options[:max_len] || :no_buffer,
|
||||
id: options[:id] || 0,
|
||||
reason: options[:reason] || :action}
|
||||
end
|
||||
|
||||
def to_binary(%NxController{max_len: max_len, id: controller_id, reason: reason}) do
|
||||
|
|
|
|||
|
|
@ -21,16 +21,11 @@ defmodule Openflow.Action.NxController2 do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
max_len = Keyword.get(options, :max_len, :no_buffer)
|
||||
controller_id = Keyword.get(options, :id, 0)
|
||||
reason = Keyword.get(options, :reason, :action)
|
||||
userdata = Keyword.get(options, :userdata)
|
||||
pause = Keyword.get(options, :pause, false)
|
||||
%NxController2{max_len: max_len,
|
||||
id: controller_id,
|
||||
reason: reason,
|
||||
userdata: userdata,
|
||||
pause: pause}
|
||||
%NxController2{max_len: options[:max_len] || :no_buffer,
|
||||
id: options[:id] || 0,
|
||||
reason: options[:reason] || :action,
|
||||
userdata: options[:userdata],
|
||||
pause: options[:pause] || false}
|
||||
end
|
||||
|
||||
def to_binary(%NxController2{} = ctl) do
|
||||
|
|
|
|||
|
|
@ -10,9 +10,8 @@ defmodule Openflow.Action.NxFinTimeout do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
fin_idle = Keyword.get(options, :idle_timeout, 0)
|
||||
fin_hard = Keyword.get(options, :hard_timeout, 0)
|
||||
%NxFinTimeout{idle_timeout: fin_idle, hard_timeout: fin_hard}
|
||||
%NxFinTimeout{idle_timeout: options[:idle_timeout] || 0,
|
||||
hard_timeout: options[:hard_timeout] || 0}
|
||||
end
|
||||
|
||||
def to_binary(%NxFinTimeout{idle_timeout: fin_idle, hard_timeout: fin_hard}) do
|
||||
|
|
|
|||
|
|
@ -14,17 +14,13 @@ defmodule Openflow.Action.NxFlowSpecLoad do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
src = Keyword.get(options, :src)
|
||||
dst = Keyword.get(options, :dst)
|
||||
src_ofs = Keyword.get(options, :src_offset, 0)
|
||||
dst_ofs = Keyword.get(options, :dst_offset, 0)
|
||||
default_n_bits = Openflow.Match.Field.n_bits_of(dst)
|
||||
n_bits = Keyword.get(options, :n_bits, default_n_bits)
|
||||
%NxFlowSpecLoad{src: src,
|
||||
dst: dst,
|
||||
n_bits: n_bits,
|
||||
src_offset: src_ofs,
|
||||
dst_offset: dst_ofs}
|
||||
dst = options[:dst]
|
||||
n_bits = options[:n_bits] || Openflow.Match.Field.n_bits_of(dst)
|
||||
%NxFlowSpecLoad{src: options[:src],
|
||||
dst: dst,
|
||||
n_bits: n_bits,
|
||||
src_offset: options[:src_offset] || 0,
|
||||
dst_offset: options[:dst_offset] || 0}
|
||||
end
|
||||
|
||||
def to_binary(%NxFlowSpecLoad{} = fsm) do
|
||||
|
|
|
|||
|
|
@ -14,17 +14,13 @@ defmodule Openflow.Action.NxFlowSpecMatch do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
src = Keyword.get(options, :src)
|
||||
dst = Keyword.get(options, :dst)
|
||||
default_n_bits = Openflow.Match.Field.n_bits_of(dst)
|
||||
n_bits = Keyword.get(options, :n_bits, default_n_bits)
|
||||
src_ofs = Keyword.get(options, :src_offset, 0)
|
||||
dst_ofs = Keyword.get(options, :dst_offset, 0)
|
||||
%NxFlowSpecMatch{src: src,
|
||||
dst: dst,
|
||||
n_bits: n_bits,
|
||||
src_offset: src_ofs,
|
||||
dst_offset: dst_ofs}
|
||||
dst = options[:dst]
|
||||
n_bits = options[:n_bits] || Openflow.Match.Field.n_bits_of(dst)
|
||||
%NxFlowSpecMatch{src: options[:src],
|
||||
dst: dst,
|
||||
n_bits: n_bits,
|
||||
src_offset: options[:src_offset] || 0,
|
||||
dst_offset: options[:dst_offset] || 0}
|
||||
end
|
||||
|
||||
def to_binary(%NxFlowSpecMatch{} = fsm) do
|
||||
|
|
|
|||
|
|
@ -11,13 +11,11 @@ defmodule Openflow.Action.NxFlowSpecOutput do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
src = Keyword.get(options, :src)
|
||||
src_ofs = Keyword.get(options, :src_offset, 0)
|
||||
default_n_bits = Openflow.Match.Field.n_bits_of(src)
|
||||
n_bits = Keyword.get(options, :n_bits, default_n_bits)
|
||||
%NxFlowSpecOutput{n_bits: n_bits,
|
||||
src: src,
|
||||
src_offset: src_ofs}
|
||||
src = options[:src]
|
||||
n_bits = options[:n_bits] || Openflow.Match.Field.n_bits_of(src)
|
||||
%NxFlowSpecOutput{n_bits: n_bits,
|
||||
src: src,
|
||||
src_offset: options[:src_offset] || 0}
|
||||
end
|
||||
|
||||
def to_binary(%NxFlowSpecOutput{n_bits: n_bits,
|
||||
|
|
|
|||
|
|
@ -17,24 +17,15 @@ defmodule Openflow.Action.NxLearn do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
idle = Keyword.get(options, :idle_timeout, 0)
|
||||
hard = Keyword.get(options, :hard_timeout, 0)
|
||||
prio = Keyword.get(options, :priority, 0)
|
||||
cookie = Keyword.get(options, :cookie, 0)
|
||||
flags = Keyword.get(options, :flags, [])
|
||||
table_id = Keyword.get(options, :table_id, 0)
|
||||
fin_idle = Keyword.get(options, :fin_idle_timeout, 0)
|
||||
fin_hard = Keyword.get(options, :fin_hard_timeout, 0)
|
||||
flow_specs = Keyword.get(options, :flow_specs, [])
|
||||
%NxLearn{idle_timeout: idle,
|
||||
hard_timeout: hard,
|
||||
priority: prio,
|
||||
cookie: cookie,
|
||||
flags: flags,
|
||||
table_id: table_id,
|
||||
fin_idle_timeout: fin_idle,
|
||||
fin_hard_timeout: fin_hard,
|
||||
flow_specs: flow_specs}
|
||||
%NxLearn{idle_timeout: options[:idle_timeout] || 0,
|
||||
hard_timeout: options[:hard_timeout] || 0,
|
||||
priority: options[:priority] || 0,
|
||||
cookie: options[:cookie] || 0,
|
||||
flags: options[:flags] || [],
|
||||
table_id: options[:table_id] || 0xff,
|
||||
fin_idle_timeout: options[:fin_idle_timeout] || 0,
|
||||
fin_hard_timeout: options[:fin_hard_timeout] || 0,
|
||||
flow_specs: options[:flow_specs] || []}
|
||||
end
|
||||
|
||||
def to_binary(%NxLearn{idle_timeout: idle,
|
||||
|
|
@ -52,7 +43,7 @@ defmodule Openflow.Action.NxLearn do
|
|||
prio::16, cookie::64, flags_int::16, table_id::8,
|
||||
0::size(1)-unit(8), fin_idle::16, fin_hard::16,
|
||||
flow_specs_bin::bitstring>>
|
||||
exp_body_size = byte_size(exp_body)
|
||||
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)>>
|
||||
|
|
|
|||
|
|
@ -20,30 +20,18 @@ defmodule Openflow.Action.NxLearn2 do
|
|||
alias __MODULE__
|
||||
|
||||
def new(options) do
|
||||
idle = Keyword.get(options, :idle_timeout, 0)
|
||||
hard = Keyword.get(options, :hard_timeout, 0)
|
||||
prio = Keyword.get(options, :priority, 0)
|
||||
cookie = Keyword.get(options, :cookie, 0)
|
||||
flags = Keyword.get(options, :flags, [])
|
||||
table_id = Keyword.get(options, :table_id, 0)
|
||||
fin_idle = Keyword.get(options, :fin_idle_timeout, 0)
|
||||
fin_hard = Keyword.get(options, :fin_hard_timeout, 0)
|
||||
flow_specs = Keyword.get(options, :flow_specs, [])
|
||||
limit = Keyword.get(options, :limit, 0)
|
||||
result_dst_offset = Keyword.get(options, :result_dst_offset, 0)
|
||||
result_dst = Keyword.get(options, :result_dst)
|
||||
%NxLearn2{idle_timeout: idle,
|
||||
hard_timeout: hard,
|
||||
priority: prio,
|
||||
cookie: cookie,
|
||||
flags: flags,
|
||||
table_id: table_id,
|
||||
fin_idle_timeout: fin_idle,
|
||||
fin_hard_timeout: fin_hard,
|
||||
limit: limit,
|
||||
result_dst_offset: result_dst_offset,
|
||||
result_dst: result_dst,
|
||||
flow_specs: flow_specs}
|
||||
%NxLearn2{idle_timeout: options[:idle_timeout] || 0,
|
||||
hard_timeout: options[:hard_timeout] || 0,
|
||||
priority: options[:priority] || 0,
|
||||
cookie: options[:cookie] || 0,
|
||||
flags: options[:flags] || [],
|
||||
table_id: options[:table_id] || 0xff,
|
||||
fin_idle_timeout: options[:fin_idle_timeout] || 0,
|
||||
fin_hard_timeout: options[:fin_hard_timeout] || 0,
|
||||
limit: options[:limit] || 0,
|
||||
result_dst_offset: options[:result_dst_offset] || 0,
|
||||
result_dst: options[:result_dst],
|
||||
flow_specs: options[:flow_specs] || []}
|
||||
end
|
||||
|
||||
def to_binary(%NxLearn2{idle_timeout: idle,
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ defmodule Openflow.Action.SetField do
|
|||
end
|
||||
|
||||
def read(<<25::16, _length::16, match_field_bin::bytes>>) do
|
||||
<<_class::16, _field::7, _hm::1, flen::8, _rest::bytes>>= match_field_bin
|
||||
<<_class::16, _field::7, _hm::1, flen::8, _rest::bytes>> = match_field_bin
|
||||
match_len = 4 + 4 + flen
|
||||
match_bin = <<1::16, match_len::16, match_field_bin::bytes>>
|
||||
{[field|_], _rest} = Openflow.Match.read(match_bin)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue