diff --git a/cover.spec b/cover.spec new file mode 100644 index 0000000..08c7e9c --- /dev/null +++ b/cover.spec @@ -0,0 +1 @@ +{incl_app, dobby_oflib, details}. diff --git a/src/dofl_identifier.erl b/src/dofl_identifier.erl index a1796f2..bb4166a 100644 --- a/src/dofl_identifier.erl +++ b/src/dofl_identifier.erl @@ -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. diff --git a/test/dofl_identifier_SUITE.erl b/test/dofl_identifier_SUITE.erl index dea0158..0d705cf 100644 --- a/test/dofl_identifier_SUITE.erl +++ b/test/dofl_identifier_SUITE.erl @@ -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). + diff --git a/test/dofl_with_server_SUITE.erl b/test/dofl_with_server_SUITE.erl index d325993..2eb81b9 100644 --- a/test/dofl_with_server_SUITE.erl +++ b/test/dofl_with_server_SUITE.erl @@ -35,6 +35,9 @@ init_per_suite(Config) -> Config end. +end_per_suite(_Config) -> + meck:unload(). + all() -> [should_publish_net_flow]. @@ -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).