tres/lib/openflow/actions/pop_mpls.ex
2019-03-20 11:02:26 +09:00

43 lines
926 B
Elixir

defmodule Openflow.Action.PopMpls do
@moduledoc """
Pop the out MPLS label
note: The one of ETH__P_MPLS_* is needed to be specified to eth_type field
send_flow_mod_add(
datapath_id,
match: Match.new(0x8847),
instructions: ApplyActions.new(PopMpls.new())
)
"""
defstruct(ethertype: 0x8847)
alias __MODULE__
@type t :: %PopMpls{}
@eth_p_mpls_uc 0x8847
@spec ofpat() :: 20
def ofpat, do: 20
@doc """
Create a new pop_mpls action struct
0x8847(ETH_P_MPLS_UC) as default value.
"""
@spec new() :: t()
@spec new(ethertype :: 0..0xFFFF) :: t()
def new(ethertype \\ @eth_p_mpls_uc) do
%PopMpls{ethertype: ethertype}
end
def to_binary(%PopMpls{ethertype: ethertype}) do
<<20::16, 8::16, ethertype::16, 0::size(2)-unit(8)>>
end
def read(<<20::16, 8::16, ethertype::16, 0::size(2)-unit(8)>>) do
%PopMpls{ethertype: ethertype}
end
end