Skip to content

Commit 24b2872

Browse files
Szymon Mentelmentels
authored andcommitted
Adjust finding flow table identifier to the new API
1 parent 57ac719 commit 24b2872

3 files changed

Lines changed: 55 additions & 17 deletions

File tree

src/dofl_identifier.erl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,36 @@ flow_mod(Dpid, OFVersion, FlowMod) ->
3939
flow_table(DatapahtId, {_Matches, _Actions, Opts}) ->
4040
TableNo = proplists:get_value(table_id, Opts),
4141
TableIdFun =
42-
fun(Dpid, _, undefined, []) ->
43-
{continue, Dpid};
44-
(Identifier, IdMetadata, _LinkMetadata, Dpid) ->
45-
case [maps:get(P, IdMetadata) || P <- [type, table_no]] of
46-
[of_flow_table, TableNo] ->
42+
fun(Dpid, _, [], _) when Dpid =:= DatapahtId ->
43+
{continue, []};
44+
(Identifier, IdMetadataInfo, _, _) ->
45+
case table_found(IdMetadataInfo, TableNo) of
46+
true ->
4747
{stop, Identifier};
4848
_ ->
49-
{skip, Dpid}
49+
{skip, []}
5050
end
5151
end,
52-
dby:search(TableIdFun, [], DatapahtId, [breadth,{max_depth, 1}]).
52+
dby:search(TableIdFun, [], [], [breadth, {max_depth, 1}]).
5353

5454
%%%=============================================================================
5555
%%% Internal functions
5656
%%%=============================================================================
57+
58+
table_found(IdMetadataInfo, TableNo) ->
59+
case get_metadata_value(type, IdMetadataInfo) of
60+
of_flow_table ->
61+
TableNo =:= get_metadata_value(table_no, IdMetadataInfo);
62+
_ ->
63+
false
64+
end.
65+
66+
get_metadata_value(Key, Metadatainfo) ->
67+
KeyMap = maps:get(atom_to_binary(Key, utf8), Metadatainfo),
68+
Value = maps:get(value, KeyMap),
69+
case is_binary(Value) of
70+
true ->
71+
binary_to_atom(Value, utf8);
72+
_ ->
73+
Value
74+
end.

test/dofl_identifier_SUITE.erl

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ should_query_flow_table_id(_Config) ->
4949
%% THEN
5050
assert_dobby_search_fun_correct(?DPID, TableNo).
5151

52+
%%%=============================================================================
53+
%%% Assertions
54+
%%%=============================================================================
55+
56+
assert_dobby_search_fun_correct(Dpid, TableNo) ->
57+
SearchFun = meck:capture(first, dby, search, 4, _ArgNo = 1),
58+
Path = switch_to_flow_table_path(Dpid),
59+
SearchResult = SearchFun(_FlowTableId = ?TABLE_IDENTIFIER,
60+
flow_table_metadata_info(TableNo),
61+
Path,
62+
[]),
63+
?assertEqual({stop, ?TABLE_IDENTIFIER}, SearchResult).
64+
5265
%%%=============================================================================
5366
%%% Internal functions
5467
%%%=============================================================================
@@ -58,14 +71,21 @@ mock_dobby() ->
5871
unmock_dobby() ->
5972
ok = meck:unload(dby).
6073

61-
assert_dobby_search_fun_correct(Dpid, TableNo) ->
62-
SearchFun = meck:capture(first, dby, search, ['_', '_', Dpid, '_'],
63-
_ArgNo = 1),
64-
NullLink = {Dpid, null, undefined},
65-
SearchResult = SearchFun(?TABLE_IDENTIFIER,
66-
#{type => of_flow_table, table_no => TableNo},
67-
#{type => of_resource},
68-
[NullLink]),
69-
?assertEqual({stop, ?TABLE_IDENTIFIER}, SearchResult).
74+
switch_to_flow_table_path(Dpid) ->
75+
[{_SwIdentifier = Dpid,
76+
_SwIdMetadataInfo = metadata([{type, of_switch}]),
77+
_SwToFlowTableMetadataInfo = metadata([{type, of_resource}])}].
78+
79+
flow_table_metadata_info(TableNo) ->
80+
metadata([{type, of_flow_table}, {table_no, TableNo}]).
7081

82+
metadata(Proplist) ->
83+
lists:foldl(fun({K, V}, AccMap) ->
84+
IM = inner_metadata(V),
85+
maps:put(atom_to_binary(K, utf8), IM, AccMap)
86+
end, #{}, Proplist).
7187

88+
inner_metadata(V) when is_atom(V) ->
89+
inner_metadata(atom_to_binary(V, utf8));
90+
inner_metadata(V) ->
91+
#{value => V, publisher_id => <<"ID">>, timestamp => <<"TSTM">>}.

test/dofl_with_server_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ transition(PrevIdMetadataInfo, IdMetadataInfo) ->
104104
TypeMap = maps:get(<<"type">>, MetadataInfo),
105105
maps:get(<<"value">>, TypeMap)
106106
end || MetadataInfo <- [PrevIdMetadataInfo, IdMetadataInfo]],
107-
{atom_to_binary(PrevT, utf8), atom_to_binary(T, utf8)}.
107+
{binary_to_atom(PrevT, utf8), binary_to_atom(T, utf8)}.
108108

109109
is_transition_allowed(Transition, AllowedTransitions) ->
110110
lists:member(Transition, AllowedTransitions).

0 commit comments

Comments
 (0)