1212 publish_new_flow /3 ]).
1313
1414-include_lib (" dobby_clib/include/dobby.hrl" ).
15-
16- % % -define(MYMAC, "MY").
17-
18- % %------------------------------------------------------------------------------
19- % % Types
20- % %------------------------------------------------------------------------------
21-
22- -type openflow_path () ::
23- [#{DatapathId :: binary () =>
24- list ({OFVersion :: 4 | 5 , [flow_mod ()]})
25- }].
26-
27- -type flow_mod () :: {Matches :: [term ()],
28- Instructions :: [term ()],
29- Opts :: [term ()]}.
15+ -include (" dobby_oflib.hrl" ).
3016
3117% %%=============================================================================
3218% %% External functions
@@ -42,22 +28,22 @@ get_path(SrcEndpoint, DstEndpoint) ->
4228% %
4329% % Publishes a NetFlow identifier between `SrcEndpoint' and `DstEndpoint'
4430% % that are assumed to be present in Dobby database. It also publishes
45- % % `OpenFlowPath ' that is set of links and identifiers representing OpenFlow
31+ % % `FlowPath ' that is set of links and identifiers representing OpenFlow
4632% % entities that provide logical connectivity between the two endpoints.
47- % % The first and the last identifiers of the `OpenFlowPath ' hang off
33+ % % The first and the last identifiers of the `FlowPath ' hang off
4834% % the Net Flow Identifier and their connections to it indicate the beginning
49- % % an the end of the `OpenFlowPath '.
35+ % % an the end of the `FlowPath '.
5036% %
5137% % The function returns Net Flow Identifier: `NetFlowId' that can be
5238% % used for referencing published Net Flow.
53- -spec publish_new_flow (identifier (), identifier (), openflow_path ()) ->
39+ -spec publish_new_flow (identifier (), identifier (), flow_path ()) ->
5440 Result when
5541 Result :: {ok , NetFlowId :: endpoint ()}
5642 | {error , Reason :: term ()}.
5743
58- publish_new_flow (SrcEndpoint , DstEndpoint , OpenFlowPath ) ->
59- NfId = publish_net_flow_identifer (SrcEndpoint , DstEndpoint ),
60- publish_openflow_path (NfId , OpenFlowPath ),
44+ publish_new_flow (SrcEndpoint , DstEndpoint , FlowPath ) ->
45+ NfId = publish_net_flow_identifier (SrcEndpoint , DstEndpoint ),
46+ publish_flow_path (NfId , FlowPath ),
6147 lager :info (" Published NetFlow: ~p between endpoints src: ~p dst: ~p ~n " ,
6248 [NfId , SrcEndpoint , DstEndpoint ]),
6349 NfId .
@@ -66,54 +52,52 @@ publish_new_flow(SrcEndpoint, DstEndpoint, OpenFlowPath) ->
6652% %% Internal functions
6753% %%=============================================================================
6854
69- publish_net_flow_identifer (Src , Dst ) ->
55+ publish_net_flow_identifier (Src , Dst ) ->
7056 % % TODO: In transaction
71- NfNode = {NfId , _NfMetadata } = net_flow_identifier (Src , Dst ),
72- publish (Src , NfNode , link_metadata (ep_to_nf , Src )),
73- publish (NfId , Dst , link_metadata (ep_to_nf , NfId )),
57+ NfNode = {NfId , _NfMetadata } = dofl_identifier :net_flow (Src , Dst ),
58+ publish (Src , NfNode ,
59+ dofl_link_metadata :endpoint_with_net_flow (Src )),
60+ publish (NfId , Dst ,
61+ dofl_link_metadata :endpoint_with_net_flow (NfId )),
7462 NfId .
7563
76- publish_openflow_path (NetFlowId , OpenFlowPath0 ) ->
77- FlowPath1 = flatten_openflow_path ( OpenFlowPath0 ),
78- publish_openflow_path (NetFlowId , FlowPath1 , NetFlowId ).
64+ publish_flow_path (NetFlowId , FlowPath0 ) ->
65+ FlowPath1 = reconstruct_flow_path ( FlowPath0 ),
66+ publish_flow_path (NetFlowId , FlowPath1 , NetFlowId ).
7967
80- publish_openflow_path (NetFlowId , [ExtendedFlowMod | T ], LastId )
68+ publish_flow_path (NetFlowId , [ExtendedFlowMod | T ], LastId )
8169 when LastId =:= NetFlowId ->
8270 publish (NetFlowId ,
8371 {Id , _Md } = flow_mod_identifier (ExtendedFlowMod ),
84- link_metadata (of_path_starts_at , {NetFlowId , NetFlowId })),
85- publish_openflow_path (NetFlowId , T , Id );
86- publish_openflow_path (NetFlowId , [ExtendedFlowMod | T ], LastId ) ->
72+ dofl_link_metadata :net_flow_with_flow_mod (NetFlowId , NetFlowId )),
73+ publish (Id ,
74+ flow_table_identifier (ExtendedFlowMod ),
75+ dofl_link_metadata :flow_mod_with_flow_table ()),
76+ publish_flow_path (NetFlowId , T , Id );
77+ publish_flow_path (NetFlowId , [ExtendedFlowMod | T ], LastId ) ->
8778 publish (LastId ,
8879 {Id , _Md } = flow_mod_identifier (ExtendedFlowMod ),
89- link_metadata (of_path_forwards_to , {NetFlowId , LastId })),
90- publish_openflow_path (NetFlowId , T , Id );
91- publish_openflow_path (NetFlowId , [], LastId ) ->
80+ dofl_link_metadata :between_flow_mods (LastId , NetFlowId )),
81+ publish (Id ,
82+ flow_table_identifier (ExtendedFlowMod ),
83+ dofl_link_metadata :flow_mod_with_flow_table ()),
84+ publish_flow_path (NetFlowId , T , Id );
85+ publish_flow_path (NetFlowId , [], LastId ) ->
9286 publish (LastId , NetFlowId ,
93- link_metadata (of_path_ends_at , {NetFlowId , LastId })).
94-
95- net_flow_identifier (Src , Dst ) ->
96- {<<" NF:" , Src /binary , " :" , Dst /binary >>, #{type => of_net_flow }}.
87+ dofl_link_metadata :net_flow_with_flow_mod (LastId , NetFlowId )).
9788
9889flow_mod_identifier ({Dpid , OFVersion , FlowMod }) ->
99- {_Matches , _Instructions , Opts } = FlowMod ,
100- Cookie = proplists :get_value (cookie , Opts ),
101- {Cookie , #{type => of_flow_mod , dpid => Dpid , of_version => OFVersion }}.
102-
103- link_metadata (Type = ep_to_nf , SrcIdentifier ) ->
104- #{type => Type , src => SrcIdentifier };
105- link_metadata (Type , {NetFlowId , Src })
106- when Type =:= of_path_starts_at ;
107- Type =:= of_path_ends_at ;
108- Type =:= of_path_forwards_to ->
109- #{type => Type , src => Src , net_flow_ids => [NetFlowId ]}.
90+ dofl_identifier :flow_mod (Dpid , OFVersion , FlowMod ).
91+
92+ flow_table_identifier ({Dpid , _OFVersion , FlowMod }) ->
93+ dofl_identifier :flow_table (Dpid , FlowMod ).
11094
11195publish (Src , Dst , LinkMetadata ) ->
11296 dby :publish (Src , Dst , LinkMetadata , [persistent ]).
11397
114- flatten_openflow_path (FlowPath0 ) ->
98+ reconstruct_flow_path (FlowPath0 ) ->
11599 Fun = fun ({Dpid , {OFVersion , FlowMods }}) ->
116- [{Dpid , OFVersion , FlowMod } || FlowMod <- FlowMods ]
100+ [{Dpid , OFVersion , FM } || FM <- FlowMods ]
117101 end ,
118102 FlowPath1 = lists :map (Fun , FlowPath0 ),
119103 lists :flatten (FlowPath1 ).
0 commit comments