Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cover.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{incl_app, dobby_oflib, details}.
33 changes: 26 additions & 7 deletions src/dofl_identifier.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,37 @@ flow_mod(Dpid, OFVersion, FlowMod) ->
flow_table(DatapahtId, {_Matches, _Actions, Opts}) ->
TableNo = proplists:get_value(table_id, Opts),
TableIdFun =
fun(Dpid, _, undefined, []) ->
{continue, Dpid};
(Identifier, IdMetadata, _LinkMetadata, Dpid) ->
case [maps:get(P, IdMetadata) || P <- [type, table_no]] of
[of_flow_table, TableNo] ->
fun(Dpid, _, [], _) when Dpid =:= DatapahtId ->
{continue, []};
(Identifier, IdMetadataInfo, _, _) ->
case table_found(IdMetadataInfo, TableNo) of
true ->
{stop, Identifier};
_ ->
{skip, Dpid}
{skip, []}
end
end,
dby:search(TableIdFun, [], DatapahtId, [breadth,{max_depth, 1}]).
dby:search(TableIdFun, [], [], [breadth,{max_depth, 1}]).

%%%=============================================================================
%%% Internal functions
%%%=============================================================================

table_found(IdMetadataInfo, TableNo) ->
case get_metadata_value(type, IdMetadataInfo) of
of_flow_table ->
TN = get_metadata_value(table_no, IdMetadataInfo),
TN =:= TableNo;
_ ->
false
end.

get_metadata_value(Key, Metadatainfo) ->
KeyMap = maps:get(atom_to_binary(Key, utf8), Metadatainfo),
Value = maps:get(<<"value">>, KeyMap),
case is_binary(Value) of
true ->
binary_to_atom(Value, utf8);
_ ->
Value
end.
28 changes: 22 additions & 6 deletions test/dofl_identifier_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,29 @@ unmock_dobby() ->
ok = meck:unload(dby).

assert_dobby_search_fun_correct(Dpid, TableNo) ->
SearchFun = meck:capture(first, dby, search, ['_', '_', Dpid, '_'],
_ArgNo = 1),
NullLink = {Dpid, null, undefined},
SearchFun = meck:capture(first, dby, search, 4, _ArgNo = 1),
Path = [{Dpid,
internal_metadata([{type, of_switch}]),
internal_metadata([{type, of_resource}])}],
SearchResult = SearchFun(?TABLE_IDENTIFIER,
#{type => of_flow_table, table_no => TableNo},
#{type => of_resource},
[NullLink]),
internal_metadata([{type, of_flow_table},
{table_no, TableNo}]),
Path,
[]),
?assertEqual({stop, ?TABLE_IDENTIFIER}, SearchResult).

internal_metadata(Proplist) ->
Fun = fun({K, V}, AccMap) ->
InnerMap = #{<<"value">> => case is_atom(V) of
true ->
atom_to_binary(V, utf8);
false ->
V
end,
<<"publisher_id">> => <<"ID">>,
<<"timestamp">> => <<"TSTM">>},
maps:put(atom_to_binary(K, utf8), InnerMap, AccMap)
end,
lists:foldl(Fun, #{}, Proplist).


5 changes: 4 additions & 1 deletion test/dofl_with_server_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ init_per_suite(Config) ->
Config
end.

end_per_suite(_Config) ->
meck:unload().

all() ->
[should_publish_net_flow].

Expand Down Expand Up @@ -104,7 +107,7 @@ transition(PrevIdMetadataInfo, IdMetadataInfo) ->
TypeMap = maps:get(<<"type">>, MetadataInfo),
maps:get(<<"value">>, TypeMap)
end || MetadataInfo <- [PrevIdMetadataInfo, IdMetadataInfo]],
{atom_to_binary(PrevT, utf8), atom_to_binary(T, utf8)}.
{binary_to_atom(PrevT, utf8), binary_to_atom(T, utf8)}.

is_transition_allowed(Transition, AllowedTransitions) ->
lists:member(Transition, AllowedTransitions).
Expand Down