@@ -75,6 +75,11 @@ const (
7575 dirDelete = "delete"
7676)
7777
78+ // Interface names option
79+ const (
80+ interfaceNamesOption = "--names"
81+ )
82+
7883// Add pushes zero or more Flows on to the transaction, to be added by
7984// Open vSwitch. If any of the flows are invalid, Add becomes a no-op
8085// and the error will be surfaced when Commit is called.
@@ -267,7 +272,7 @@ func (o *OpenFlowService) DumpTables(bridge string) ([]*Table, error) {
267272 return tables , err
268273}
269274
270- // DumpFlowsWithFlowArgs retrieves statistics about all flows for the specified bridge,
275+ // DumpFlowsWithFlowArgs retrieves details about all flows for the specified bridge,
271276// filtering on the specified flow(s), if provided.
272277// If a table has no active flows and has not been used for a lookup or matched
273278// by an incoming packet, it is filtered from the output.
@@ -306,13 +311,64 @@ func (o *OpenFlowService) DumpFlowsWithFlowArgs(bridge string, flow *MatchFlow)
306311 return flows , err
307312}
308313
309- // DumpFlows retrieves statistics about all flows for the specified bridge.
314+ // DumpFlows retrieves details about all flows for the specified bridge.
310315// If a table has no active flows and has not been used for a lookup or matched
311316// by an incoming packet, it is filtered from the output.
312317func (o * OpenFlowService ) DumpFlows (bridge string ) ([]* Flow , error ) {
313318 return o .DumpFlowsWithFlowArgs (bridge , nil )
314319}
315320
321+ // DumpFlowStatsWithFlowArgs retrieves statistics about all flows for the specified bridge,
322+ // filtering on the specified flow(s), if provided.
323+ // If a table has no active flows and has not been used for a lookup or matched
324+ // by an incoming packet, it is filtered from the output.
325+ // We neeed to add a Matchflow to filter the dumpflow results. For example filter based on table, cookie.
326+ // Report with interface names if useInterfaceNames is set. Port numbers otherwise
327+ func (o * OpenFlowService ) DumpFlowStatsWithFlowArgs (bridge string , flow * MatchFlow , useInterfaceNames bool ) ([]* PerFlowStats , error ) {
328+ args := []string {"dump-flows" , bridge }
329+ if useInterfaceNames {
330+ args = append (args , interfaceNamesOption )
331+ }
332+ args = append (args , o .c .ofctlFlags ... )
333+ if flow != nil {
334+ fb , err := flow .MarshalText ()
335+ if err != nil {
336+ return nil , err
337+ }
338+ args = append (args , string (fb ))
339+ }
340+ out , err := o .exec (args ... )
341+ if err != nil {
342+ return nil , err
343+ }
344+
345+ var flows []* PerFlowStats
346+ err = parseEachLine (out , dumpFlowsPrefix , func (b []byte ) error {
347+ // Do not attempt to parse ST_FLOW messages.
348+ if bytes .Contains (b , dumpFlowsPrefix ) {
349+ return nil
350+ }
351+
352+ f := new (PerFlowStats )
353+ if err := f .UnmarshalText (b ); err != nil {
354+ return err
355+ }
356+
357+ flows = append (flows , f )
358+ return nil
359+ })
360+
361+ return flows , err
362+ }
363+
364+ // DumpFlowStats retrieves statistics about all matching flows for the specified bridge.
365+ // If a table has no active flows and has not been used for a lookup or matched
366+ // by an incoming packet, it is filtered from the output.
367+ // Use nil MatchFlow if no filtering is desired.
368+ func (o * OpenFlowService ) DumpFlowStats (bridge string , flow * MatchFlow , useInterfaceNames bool ) ([]* PerFlowStats , error ) {
369+ return o .DumpFlowStatsWithFlowArgs (bridge , flow , useInterfaceNames )
370+ }
371+
316372// DumpAggregate retrieves statistics about the specified flow attached to the
317373// specified bridge.
318374func (o * OpenFlowService ) DumpAggregate (bridge string , flow * MatchFlow ) (* FlowStats , error ) {
0 commit comments