Skip to content

Commit 1d1581a

Browse files
author
Arjun Guha
committed
Merge remote-tracking branch 'origin/port-stats' into compilekat
2 parents e324a24 + 7e53db7 commit 1d1581a

File tree

3 files changed

+155
-7
lines changed

3 files changed

+155
-7
lines changed

lib/OpenFlow0x01.ml

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,11 @@ module StatsRequest = struct
16671667
uint16_t out_port
16681668
} as big_endian
16691669

1670+
cstruct ofp_port_stats_request {
1671+
uint16_t port_no;
1672+
uint8_t pad[6];
1673+
} as big_endian
1674+
16701675
let marshal_flow_stats_request pat port table out =
16711676
let _ = Match.marshal pat out in
16721677
set_ofp_flow_stats_request_table_id out table;
@@ -1680,6 +1685,17 @@ module StatsRequest = struct
16801685
end;
16811686
sizeof_ofp_flow_stats_request
16821687

1688+
let marshal_port_stats_request port out =
1689+
begin match port with
1690+
| Some port ->
1691+
set_ofp_port_stats_request_port_no out (PseudoPort.marshal port)
1692+
| None ->
1693+
let open PseudoPort in
1694+
let port_code = ofp_port_to_int OFPP_NONE in
1695+
set_ofp_port_stats_request_port_no out port_code
1696+
end;
1697+
sizeof_ofp_port_stats_request
1698+
16831699
let to_string msg = match msg with
16841700
| DescriptionRequest ->
16851701
"DescriptionReq"
@@ -1689,6 +1705,8 @@ module StatsRequest = struct
16891705
"IndividualFlowReq "
16901706
| AggregateRequest _ ->
16911707
"AggregateFlowReq "
1708+
| PortRequest _ ->
1709+
"PortRequest "
16921710

16931711
let size_of msg =
16941712
let header_size = sizeof_ofp_stats_request in
@@ -1697,12 +1715,14 @@ module StatsRequest = struct
16971715
| FlowTableStatsRequest -> header_size
16981716
| AggregateRequest _
16991717
| IndividualRequest _ -> header_size + sizeof_ofp_flow_stats_request
1718+
| PortRequest _ -> header_size + sizeof_ofp_port_stats_request
17001719

17011720
let ofp_stats_type_of_request req = match req with
17021721
| DescriptionRequest -> OFPST_DESC
17031722
| FlowTableStatsRequest -> OFPST_TABLE
17041723
| IndividualRequest _ -> OFPST_FLOW
17051724
| AggregateRequest _ -> OFPST_AGGREGATE
1725+
| PortRequest _ -> OFPST_PORT
17061726

17071727
let marshal (msg : request) (out : Cstruct.t) =
17081728
let req_type = ofp_stats_type_of_request msg in
@@ -1716,6 +1736,8 @@ module StatsRequest = struct
17161736
| IndividualRequest stats_req
17171737
| AggregateRequest stats_req ->
17181738
marshal_flow_stats_request stats_req.sr_of_match stats_req.sr_out_port stats_req.sr_table_id out'
1739+
| PortRequest port ->
1740+
marshal_port_stats_request port out'
17191741

17201742
let parse_stats_request bits =
17211743
let sr_of_match = Match.parse (get_ofp_flow_stats_request_of_match bits) in
@@ -1729,6 +1751,13 @@ module StatsRequest = struct
17291751
in
17301752
{ sr_of_match; sr_table_id; sr_out_port }
17311753

1754+
let parse_port_request bits =
1755+
let open PseudoPort in
1756+
if ofp_port_to_int OFPP_NONE = (get_ofp_flow_stats_request_out_port bits) then
1757+
None
1758+
else
1759+
Some (PhysicalPort (get_ofp_flow_stats_request_out_port bits))
1760+
17321761
let parse bits =
17331762
let stats_type_code = get_ofp_stats_request_req_type bits in
17341763
let body = Cstruct.shift bits sizeof_ofp_stats_request in
@@ -1739,7 +1768,7 @@ module StatsRequest = struct
17391768
| Some OFPST_AGGREGATE -> AggregateRequest (parse_stats_request body)
17401769
| Some OFPST_QUEUE -> raise (Unparsable "queue statistics unsupported")
17411770
| Some OFPST_VENDOR -> raise (Unparsable "vendor statistics unsupported")
1742-
| Some OFPST_PORT -> raise (Unparsable "port statistics unsupported")
1771+
| Some OFPST_PORT -> PortRequest (parse_port_request body)
17431772
| None ->
17441773
let msg =
17451774
sprintf "bad ofp_stats_type in stats_request (%d)" stats_type_code in
@@ -1763,7 +1792,7 @@ module StatsReply = struct
17631792
} as big_endian
17641793

17651794
let mkString bits size =
1766-
let new_string = String.create size in
1795+
let new_string = Bytes.create size in
17671796
Cstruct.blit_to_string bits 0 new_string 0 size;
17681797
new_string
17691798

@@ -1872,10 +1901,57 @@ module StatsReply = struct
18721901

18731902
let parse_aggregate_stats bits =
18741903
{ total_packet_count = get_ofp_aggregate_stats_packet_count bits;
1875-
total_byte_count = get_ofp_aggregate_stats_byte_count bits;
1876-
flow_count = get_ofp_aggregate_stats_flow_count bits }
1904+
total_byte_count = get_ofp_aggregate_stats_byte_count bits;
1905+
flow_count = get_ofp_aggregate_stats_flow_count bits }
18771906

18781907
(** Reply to an ofp_stats_request of type OFPST_AGGREGATE *)
1908+
1909+
cstruct ofp_port_stats {
1910+
uint16_t port_no;
1911+
uint8_t pad[6];
1912+
uint64_t rx_packets;
1913+
uint64_t tx_packets;
1914+
uint64_t rx_bytes;
1915+
uint64_t tx_bytes;
1916+
uint64_t rx_dropped;
1917+
uint64_t tx_dropped;
1918+
uint64_t rx_errors;
1919+
uint64_t tx_errors;
1920+
uint64_t rx_frame_err;
1921+
uint64_t rx_over_err;
1922+
uint64_t rx_crc_err;
1923+
uint64_t collisions;
1924+
} as big_endian
1925+
1926+
let parse_port_stats bits =
1927+
let port_no = get_ofp_port_stats_port_no bits in
1928+
let rx_packets = get_ofp_port_stats_rx_packets bits in
1929+
let tx_packets = get_ofp_port_stats_tx_packets bits in
1930+
let rx_bytes = get_ofp_port_stats_rx_bytes bits in
1931+
let tx_bytes = get_ofp_port_stats_tx_bytes bits in
1932+
let rx_dropped = get_ofp_port_stats_rx_dropped bits in
1933+
let tx_dropped = get_ofp_port_stats_tx_dropped bits in
1934+
let rx_errors = get_ofp_port_stats_rx_errors bits in
1935+
let tx_errors = get_ofp_port_stats_tx_errors bits in
1936+
let rx_frame_err = get_ofp_port_stats_rx_frame_err bits in
1937+
let rx_over_err = get_ofp_port_stats_rx_over_err bits in
1938+
let rx_crc_err = get_ofp_port_stats_rx_crc_err bits in
1939+
let collisions = get_ofp_port_stats_collisions bits in
1940+
{ port_no = port_no
1941+
; rx_packets = rx_packets
1942+
; tx_packets = tx_packets
1943+
; rx_bytes = rx_bytes
1944+
; tx_bytes = tx_bytes
1945+
; rx_dropped = rx_dropped
1946+
; tx_dropped = tx_dropped
1947+
; rx_errors = rx_errors
1948+
; tx_errors = tx_errors
1949+
; rx_frame_err = rx_frame_err
1950+
; rx_over_err = rx_over_err
1951+
; rx_crc_err = rx_crc_err
1952+
; collisions = collisions
1953+
}
1954+
18791955
cstruct ofp_stats_reply {
18801956
uint16_t stats_type;
18811957
uint16_t flags
@@ -1893,7 +1969,7 @@ module StatsReply = struct
18931969
| Some OFPST_TABLE -> raise (Unparsable "table statistics unsupported")
18941970
| Some OFPST_QUEUE -> raise (Unparsable "queue statistics unsupported")
18951971
| Some OFPST_VENDOR -> raise (Unparsable "vendor statistics unsupported")
1896-
| Some OFPST_PORT -> raise (Unparsable "port statistics unsupported")
1972+
| Some OFPST_PORT -> PortRep (parse_port_stats body)
18971973
| None ->
18981974
let msg =
18991975
sprintf "bad ofp_stats_type in stats_reply (%d)" stats_type_code in
@@ -1939,6 +2015,24 @@ module StatsReply = struct
19392015
end;
19402016
(** TODO: Support the marshaling of multiple action and multiple flows *)
19412017
sizeof_ofp_stats_reply + sizeof_ofp_flow_stats
2018+
| PortRep rep ->
2019+
set_ofp_stats_reply_stats_type out (ofp_stats_types_to_int OFPST_PORT);
2020+
begin let out = Cstruct.shift out sizeof_ofp_stats_reply in
2021+
set_ofp_port_stats_port_no out (rep.port_no);
2022+
set_ofp_port_stats_rx_packets out (rep.rx_packets);
2023+
set_ofp_port_stats_tx_packets out (rep.tx_packets);
2024+
set_ofp_port_stats_rx_bytes out (rep.rx_bytes);
2025+
set_ofp_port_stats_tx_bytes out (rep.tx_bytes);
2026+
set_ofp_port_stats_rx_dropped out (rep.rx_dropped);
2027+
set_ofp_port_stats_tx_dropped out (rep.tx_dropped);
2028+
set_ofp_port_stats_rx_errors out (rep.rx_errors);
2029+
set_ofp_port_stats_tx_errors out (rep.tx_errors);
2030+
set_ofp_port_stats_rx_frame_err out (rep.rx_frame_err);
2031+
set_ofp_port_stats_rx_over_err out (rep.rx_over_err);
2032+
set_ofp_port_stats_rx_crc_err out (rep.rx_crc_err);
2033+
set_ofp_port_stats_collisions out (rep.collisions);
2034+
end;
2035+
sizeof_ofp_stats_reply + sizeof_ofp_port_stats
19422036
end
19432037

19442038
let to_string (t : t) =
@@ -1948,7 +2042,7 @@ module StatsReply = struct
19482042
| DescriptionRep _ -> sizeof_ofp_stats_reply + sizeof_ofp_desc_stats
19492043
| IndividualFlowRep _ -> sizeof_ofp_stats_reply + sizeof_ofp_flow_stats
19502044
| AggregateFlowRep _ -> sizeof_ofp_stats_reply + sizeof_ofp_aggregate_stats
1951-
2045+
| PortRep _ -> sizeof_ofp_stats_reply + sizeof_ofp_port_stats
19522046
end
19532047

19542048
(* See Section 5.4.4 of the OpenFlow 1.0 specification *)

lib/OpenFlow0x01_Stats.ml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type request =
1212
| FlowTableStatsRequest
1313
| IndividualRequest of statsReq
1414
| AggregateRequest of statsReq
15+
| PortRequest of pseudoPort option
1516

1617
type descriptionStats =
1718
{ manufacturer : string
@@ -41,10 +42,27 @@ type aggregateStats =
4142
; flow_count : int32
4243
}
4344

45+
type portStats =
46+
{ port_no : int16
47+
; rx_packets : int64
48+
; tx_packets : int64
49+
; rx_bytes : int64
50+
; tx_bytes : int64
51+
; rx_dropped : int64
52+
; tx_dropped : int64
53+
; rx_errors : int64
54+
; tx_errors : int64
55+
; rx_frame_err : int64
56+
; rx_over_err : int64
57+
; rx_crc_err : int64
58+
; collisions : int64
59+
}
60+
4461
type reply =
4562
| DescriptionRep of descriptionStats
4663
| IndividualFlowRep of individualStats list
4764
| AggregateFlowRep of aggregateStats
65+
| PortRep of portStats
4866

4967
module Format = struct
5068

@@ -56,16 +74,34 @@ module Format = struct
5674
v.manufacturer v.hardware v.software v.serial_number v.datapath
5775

5876
(* TODO(arjun): must fill *)
59-
let individualStats fmt v = fprintf fmt "individualStats"
77+
let individualStats fmt v =
78+
fprintf fmt "individualStats"
6079

6180
let aggregateStats fmt v =
6281
fprintf fmt "@[{@[@[packets=%Ld;@]@ @[bytes=%Ld;@]@ @[flows=%ld@]@]}@]"
6382
v.total_packet_count v.total_byte_count v.flow_count
6483

84+
let portStats fmt v =
85+
fprintf fmt "@[{@[port_no=%d@ \
86+
rx_packets=%Ld@ tx_packets=%Ld@ \
87+
rx_bytes=%Ld@ tx_bytes=%Ld@ \
88+
rx_dropped=%Ld@ tx_dropped=%Ld@ \
89+
rx_errors=%Ld@ tx_errors=%Ld@ \
90+
rx_frame_err=%Ld@ rx_over_err=%Ld@ rx_crc_err=%Ld@ \
91+
collisions=%Ld@]}@]"
92+
v.port_no
93+
v.rx_packets v.tx_packets
94+
v.rx_bytes v.tx_bytes
95+
v.rx_dropped v.tx_dropped
96+
v.rx_errors v.tx_errors
97+
v.rx_frame_err v.rx_over_err v.rx_crc_err
98+
v.collisions
99+
65100
let reply fmt v = match v with
66101
| DescriptionRep st -> descriptionStats fmt st
67102
| IndividualFlowRep st -> individualStats fmt st
68103
| AggregateFlowRep st -> aggregateStats fmt st
104+
| PortRep st -> portStats fmt st
69105

70106
let string_of_mk formatter x =
71107
let buf = Buffer.create 100 in

lib/OpenFlow0x01_Stats.mli

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type request =
1919
| FlowTableStatsRequest
2020
| IndividualRequest of statsReq
2121
| AggregateRequest of statsReq
22+
| PortRequest of pseudoPort option
2223

2324
(** The body of a reply to a description request. *)
2425
type descriptionStats =
@@ -52,12 +53,29 @@ type aggregateStats =
5253
; flow_count : int32 (** Number of flows. *)
5354
}
5455

56+
type portStats =
57+
{ port_no : int16
58+
; rx_packets : int64
59+
; tx_packets : int64
60+
; rx_bytes : int64
61+
; tx_bytes : int64
62+
; rx_dropped : int64
63+
; tx_dropped : int64
64+
; rx_errors : int64
65+
; tx_errors : int64
66+
; rx_frame_err : int64
67+
; rx_over_err : int64
68+
; rx_crc_err : int64
69+
; collisions : int64
70+
}
71+
5572
(** A statistics reply message. See Section 5.3.5 of the OpenFlow 1.0
5673
specification. *)
5774

5875
type reply =
5976
| DescriptionRep of descriptionStats
6077
| IndividualFlowRep of individualStats list
6178
| AggregateFlowRep of aggregateStats
79+
| PortRep of portStats
6280

6381
val reply_to_string : reply -> string

0 commit comments

Comments
 (0)