Skip to content

Commit b42d096

Browse files
committed
flowstats: combine types for indvidual/aggregate stats request
Eliminate code duplication in the representation, parsing, and marshalling of individual and aggregate stats requests. Both requests have the same fields, and the fields behave in the same way
1 parent 027f763 commit b42d096

File tree

3 files changed

+23
-55
lines changed

3 files changed

+23
-55
lines changed

lib/OpenFlow0x01.ml

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,49 +1713,30 @@ module StatsRequest = struct
17131713
match msg with
17141714
| DescriptionRequest -> sizeof_ofp_stats_request
17151715
| FlowTableStatsRequest -> sizeof_ofp_stats_request
1716-
| IndividualRequest flow_req ->
1717-
marshal_flow_stats_request flow_req.is_of_match flow_req.is_out_port flow_req.is_table_id out'
1718-
| AggregateRequest agg_req ->
1719-
marshal_flow_stats_request agg_req.as_of_match agg_req.as_out_port agg_req.as_table_id out'
1716+
| IndividualRequest stats_req
1717+
| AggregateRequest stats_req ->
1718+
marshal_flow_stats_request stats_req.sr_of_match stats_req.sr_out_port stats_req.sr_table_id out'
17201719

1721-
let parse_flow_stats_request bits =
1722-
let is_of_match = Match.parse (get_ofp_flow_stats_request_of_match bits) in
1723-
let is_table_id = get_ofp_flow_stats_request_table_id bits in
1724-
let is_out_port =
1720+
let parse_stats_request bits =
1721+
let sr_of_match = Match.parse (get_ofp_flow_stats_request_of_match bits) in
1722+
let sr_table_id = get_ofp_flow_stats_request_table_id bits in
1723+
let sr_out_port =
17251724
(let open PseudoPort in
17261725
if ofp_port_to_int OFPP_NONE = (get_ofp_flow_stats_request_out_port bits) then
17271726
None
17281727
else
17291728
Some (PhysicalPort (get_ofp_flow_stats_request_out_port bits)))
17301729
in
1731-
{ is_of_match = is_of_match;
1732-
is_table_id = is_table_id;
1733-
is_out_port = is_out_port
1734-
}
1730+
{ sr_of_match; sr_table_id; sr_out_port }
17351731

1736-
let parse_aggregate_stats_request bits =
1737-
let as_of_match = Match.parse (get_ofp_flow_stats_request_of_match bits) in
1738-
let as_table_id = get_ofp_flow_stats_request_table_id bits in
1739-
let as_out_port =
1740-
(let open PseudoPort in
1741-
if ofp_port_to_int OFPP_NONE = (get_ofp_flow_stats_request_out_port bits) then
1742-
None
1743-
else
1744-
Some (PhysicalPort (get_ofp_flow_stats_request_out_port bits)))
1745-
in
1746-
{ as_of_match = as_of_match;
1747-
as_table_id = as_table_id;
1748-
as_out_port = as_out_port
1749-
}
1750-
17511732
let parse bits =
17521733
let stats_type_code = get_ofp_stats_request_req_type bits in
17531734
let body = Cstruct.shift bits sizeof_ofp_stats_request in
17541735
match int_to_ofp_stats_types stats_type_code with
17551736
| Some OFPST_DESC -> DescriptionRequest
17561737
| Some OFPST_TABLE -> FlowTableStatsRequest
1757-
| Some OFPST_FLOW -> IndividualRequest (parse_flow_stats_request body)
1758-
| Some OFPST_AGGREGATE -> AggregateRequest (parse_aggregate_stats_request body)
1738+
| Some OFPST_FLOW -> IndividualRequest (parse_stats_request body)
1739+
| Some OFPST_AGGREGATE -> AggregateRequest (parse_stats_request body)
17591740
| Some OFPST_QUEUE -> raise (Unparsable "queue statistics unsupported")
17601741
| Some OFPST_VENDOR -> raise (Unparsable "vendor statistics unsupported")
17611742
| Some OFPST_PORT -> raise (Unparsable "port statistics unsupported")

lib/OpenFlow0x01_Stats.ml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
open Packet
22
open OpenFlow0x01_Core
33

4-
type individualStatsReq =
5-
{ is_of_match : pattern
6-
; is_table_id : int8
7-
; is_out_port : pseudoPort option
8-
}
9-
10-
type aggregateStatsReq =
11-
{ as_of_match : pattern
12-
; as_table_id : int8
13-
; as_out_port : pseudoPort option
4+
type statsReq =
5+
{ sr_of_match : pattern
6+
; sr_table_id : int8
7+
; sr_out_port : pseudoPort option
148
}
159

1610
type request =
1711
| DescriptionRequest
1812
| FlowTableStatsRequest
19-
| IndividualRequest of individualStatsReq
20-
| AggregateRequest of aggregateStatsReq
13+
| IndividualRequest of statsReq
14+
| AggregateRequest of statsReq
2115

2216
type descriptionStats =
2317
{ manufacturer : string

lib/OpenFlow0x01_Stats.mli

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,18 @@ open OpenFlow0x01_Core
77
entries to have this as an output port. Use table ID [0xFF] to
88
read from all tables. *)
99

10-
(** The body of an individual flow stat request. *)
11-
type individualStatsReq =
12-
{ is_of_match : pattern
13-
; is_table_id : int8
14-
; is_out_port : pseudoPort option
15-
}
16-
17-
(** The body of an aggregate flow stat request. *)
18-
type aggregateStatsReq =
19-
{ as_of_match : pattern
20-
; as_table_id : int8
21-
; as_out_port : pseudoPort option
10+
(** The body of an individual or aggregate flow stat request. *)
11+
type statsReq =
12+
{ sr_of_match : pattern
13+
; sr_table_id : int8
14+
; sr_out_port : pseudoPort option
2215
}
2316

2417
type request =
2518
| DescriptionRequest
2619
| FlowTableStatsRequest
27-
| IndividualRequest of individualStatsReq
28-
| AggregateRequest of aggregateStatsReq
20+
| IndividualRequest of statsReq
21+
| AggregateRequest of statsReq
2922

3023
(** The body of a reply to a description request. *)
3124
type descriptionStats =

0 commit comments

Comments
 (0)