From da4a72be376b3f1eb2fde27cad482b491b608f6d Mon Sep 17 00:00:00 2001 From: Szymon Mentel Date: Fri, 6 Mar 2015 16:19:17 +0100 Subject: [PATCH 1/3] Adjust finding flow table identifier to the new API --- src/dofl_identifier.erl | 33 ++++++++++++++++++++++++++------- test/dofl_identifier_SUITE.erl | 28 ++++++++++++++++++++++------ test/dofl_with_server_SUITE.erl | 2 +- 3 files changed, 49 insertions(+), 14 deletions(-) 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..abfb6e3 100644 --- a/test/dofl_with_server_SUITE.erl +++ b/test/dofl_with_server_SUITE.erl @@ -104,7 +104,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). From d87d459e46f94a62f607eda37e91abca8ecf81f6 Mon Sep 17 00:00:00 2001 From: Magnus Henoch Date: Tue, 10 Mar 2015 17:48:58 +0000 Subject: [PATCH 2/3] Unload mocked modules after test This is necessary to get cover reports for modules that have been mocked in the suite, in this case dofl_identifier. --- test/dofl_with_server_SUITE.erl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/dofl_with_server_SUITE.erl b/test/dofl_with_server_SUITE.erl index abfb6e3..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]. From 087bc9211402336ff5887325534fa46333f70501 Mon Sep 17 00:00:00 2001 From: Magnus Henoch Date: Tue, 10 Mar 2015 17:53:08 +0000 Subject: [PATCH 3/3] Test coverage report for Common Test Add the required cover.spec file to activate cover reports under Common Test. --- cover.spec | 1 + 1 file changed, 1 insertion(+) create mode 100644 cover.spec 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}.