@@ -1667,6 +1667,11 @@ module StatsRequest = struct
1667
1667
uint16_t out_port
1668
1668
} as big_endian
1669
1669
1670
+ cstruct ofp_port_stats_request {
1671
+ uint16_t port_no;
1672
+ uint8_t pad[6 ];
1673
+ } as big_endian
1674
+
1670
1675
let marshal_flow_stats_request pat port table out =
1671
1676
let _ = Match. marshal pat out in
1672
1677
set_ofp_flow_stats_request_table_id out table;
@@ -1680,6 +1685,17 @@ module StatsRequest = struct
1680
1685
end ;
1681
1686
sizeof_ofp_flow_stats_request
1682
1687
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
+
1683
1699
let to_string msg = match msg with
1684
1700
| DescriptionRequest ->
1685
1701
" DescriptionReq"
@@ -1689,6 +1705,8 @@ module StatsRequest = struct
1689
1705
" IndividualFlowReq "
1690
1706
| AggregateRequest _ ->
1691
1707
" AggregateFlowReq "
1708
+ | PortRequest _ ->
1709
+ " PortRequest "
1692
1710
1693
1711
let size_of msg =
1694
1712
let header_size = sizeof_ofp_stats_request in
@@ -1697,12 +1715,14 @@ module StatsRequest = struct
1697
1715
| FlowTableStatsRequest -> header_size
1698
1716
| AggregateRequest _
1699
1717
| IndividualRequest _ -> header_size + sizeof_ofp_flow_stats_request
1718
+ | PortRequest _ -> header_size + sizeof_ofp_port_stats_request
1700
1719
1701
1720
let ofp_stats_type_of_request req = match req with
1702
1721
| DescriptionRequest -> OFPST_DESC
1703
1722
| FlowTableStatsRequest -> OFPST_TABLE
1704
1723
| IndividualRequest _ -> OFPST_FLOW
1705
1724
| AggregateRequest _ -> OFPST_AGGREGATE
1725
+ | PortRequest _ -> OFPST_PORT
1706
1726
1707
1727
let marshal (msg : request ) (out : Cstruct.t ) =
1708
1728
let req_type = ofp_stats_type_of_request msg in
@@ -1716,6 +1736,8 @@ module StatsRequest = struct
1716
1736
| IndividualRequest stats_req
1717
1737
| AggregateRequest stats_req ->
1718
1738
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'
1719
1741
1720
1742
let parse_stats_request bits =
1721
1743
let sr_of_match = Match. parse (get_ofp_flow_stats_request_of_match bits) in
@@ -1729,6 +1751,13 @@ module StatsRequest = struct
1729
1751
in
1730
1752
{ sr_of_match; sr_table_id; sr_out_port }
1731
1753
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
+
1732
1761
let parse bits =
1733
1762
let stats_type_code = get_ofp_stats_request_req_type bits in
1734
1763
let body = Cstruct. shift bits sizeof_ofp_stats_request in
@@ -1739,7 +1768,7 @@ module StatsRequest = struct
1739
1768
| Some OFPST_AGGREGATE -> AggregateRequest (parse_stats_request body)
1740
1769
| Some OFPST_QUEUE -> raise (Unparsable " queue statistics unsupported" )
1741
1770
| 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 )
1743
1772
| None ->
1744
1773
let msg =
1745
1774
sprintf " bad ofp_stats_type in stats_request (%d)" stats_type_code in
@@ -1763,7 +1792,7 @@ module StatsReply = struct
1763
1792
} as big_endian
1764
1793
1765
1794
let mkString bits size =
1766
- let new_string = String . create size in
1795
+ let new_string = Bytes . create size in
1767
1796
Cstruct. blit_to_string bits 0 new_string 0 size;
1768
1797
new_string
1769
1798
@@ -1872,10 +1901,57 @@ module StatsReply = struct
1872
1901
1873
1902
let parse_aggregate_stats bits =
1874
1903
{ 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 }
1877
1906
1878
1907
(* * 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
+
1879
1955
cstruct ofp_stats_reply {
1880
1956
uint16_t stats_type;
1881
1957
uint16_t flags
@@ -1893,7 +1969,7 @@ module StatsReply = struct
1893
1969
| Some OFPST_TABLE -> raise (Unparsable " table statistics unsupported" )
1894
1970
| Some OFPST_QUEUE -> raise (Unparsable " queue statistics unsupported" )
1895
1971
| 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 )
1897
1973
| None ->
1898
1974
let msg =
1899
1975
sprintf " bad ofp_stats_type in stats_reply (%d)" stats_type_code in
@@ -1939,6 +2015,24 @@ module StatsReply = struct
1939
2015
end ;
1940
2016
(* * TODO: Support the marshaling of multiple action and multiple flows *)
1941
2017
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
1942
2036
end
1943
2037
1944
2038
let to_string (t : t ) =
@@ -1948,7 +2042,7 @@ module StatsReply = struct
1948
2042
| DescriptionRep _ -> sizeof_ofp_stats_reply + sizeof_ofp_desc_stats
1949
2043
| IndividualFlowRep _ -> sizeof_ofp_stats_reply + sizeof_ofp_flow_stats
1950
2044
| AggregateFlowRep _ -> sizeof_ofp_stats_reply + sizeof_ofp_aggregate_stats
1951
-
2045
+ | PortRep _ -> sizeof_ofp_stats_reply + sizeof_ofp_port_stats
1952
2046
end
1953
2047
1954
2048
(* See Section 5.4.4 of the OpenFlow 1.0 specification *)
0 commit comments