Skip to content

Commit 823e654

Browse files
committed
Merge pull request #177 from frenetic-lang/flowstats
implement flowstats translation between 0x01 and SDN
2 parents 0a85a40 + b42d096 commit 823e654

File tree

7 files changed

+112
-58
lines changed

7 files changed

+112
-58
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 =

lib/SDN_OpenFlow0x01.ml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,90 @@ let to_packetIn (pktIn : Core.packetIn) : AL.pktIn =
3737
| { input_payload; total_len; port; reason } ->
3838
(to_payload input_payload, total_len, Int32.of_int port, to_reason reason)
3939

40+
let to_pattern (p:Core.pattern) : SDN_Types.Pattern.t =
41+
let open SDN_Types.Pattern in
42+
{ dlSrc = p.Core.dlSrc
43+
; dlDst = p.Core.dlDst
44+
; dlTyp = p.Core.dlTyp
45+
; dlVlan = begin match p.Core.dlVlan with
46+
| None -> None
47+
| Some None -> Some(0xffff)
48+
| Some vlan -> vlan
49+
end
50+
; dlVlanPcp = p.Core.dlVlanPcp
51+
; nwSrc = begin match p.Core.nwSrc with
52+
| None -> None
53+
| Some({ Core.m_value; Core.m_mask = None }) ->
54+
Some(m_value, 0l)
55+
| Some({ Core.m_value; Core.m_mask = Some(m) }) ->
56+
Some(m_value, Int32.sub 32l m)
57+
end
58+
; nwDst = begin match p.Core.nwDst with
59+
| None -> None
60+
| Some({ Core.m_value; Core.m_mask = None }) ->
61+
Some(m_value, 0l)
62+
| Some({ Core.m_value; Core.m_mask = Some(m) }) ->
63+
Some(m_value, Int32.sub 32l m)
64+
end
65+
; nwProto = p.Core.nwProto
66+
; tpSrc = p.Core.tpSrc
67+
; tpDst = p.Core.tpDst
68+
; inPort = match p.Core.inPort with
69+
| None -> None
70+
| Some(n) -> Some(Int32.of_int n)
71+
}
72+
73+
let to_pseudoPort (in_port : Core.portId option) pport =
74+
let open Core in
75+
match pport with
76+
| PhysicalPort port ->
77+
if Some port = in_port
78+
then AL.InPort
79+
else AL.Physical (Int32.of_int port)
80+
| InPort -> AL.InPort
81+
| Table -> AL.Table
82+
| Normal -> AL.Normal
83+
| Flood -> AL.Flood
84+
| AllPorts -> AL.All
85+
| Controller(buf) -> AL.Controller(buf)
86+
| Local -> AL.Local
87+
88+
let to_action (in_port : Core.portId option) (act : Core.action) : AL.action =
89+
let open Core in
90+
match act with
91+
| Output pport -> AL.Output (to_pseudoPort in_port pport)
92+
| SetDlVlan dlVlan -> AL.(Modify(SetVlan dlVlan))
93+
| SetDlVlanPcp dlVlanPcp -> AL.(Modify(SetVlanPcp dlVlanPcp))
94+
| SetDlSrc dlAddr -> AL.(Modify(SetEthSrc dlAddr))
95+
| SetDlDst dlAddr -> AL.(Modify(SetEthDst dlAddr))
96+
| SetNwSrc nwAddr -> AL.(Modify(SetIP4Src nwAddr))
97+
| SetNwDst nwAddr -> AL.(Modify(SetIP4Dst nwAddr))
98+
| SetNwTos nwTos -> AL.(Modify(SetIPProto nwTos))
99+
| SetTpSrc tpPort -> AL.(Modify(SetTCPDstPort tpPort))
100+
| SetTpDst tpPort -> AL.(Modify(SetTCPSrcPort tpPort))
101+
| Enqueue _ -> assert false (* XXX(seliopou) raise an exception. It's not
102+
possible to implement this without changing the types in SDN_Types. *)
103+
104+
let to_flowStats stats : SDN_Types.flowStats =
105+
let open SDN_Types in
106+
let open OpenFlow0x01_Stats in
107+
let pattern = to_pattern stats.of_match in
108+
let inPort = match pattern.Pattern.inPort with
109+
| None -> None
110+
| Some(x) -> Some(from_portId x)
111+
in
112+
{ flow_table_id = stats.table_id
113+
; flow_pattern = pattern
114+
; flow_duration_sec = stats.duration_sec
115+
; flow_duration_nsec = stats.duration_nsec
116+
; flow_priority = stats.priority
117+
; flow_idle_timeout = stats.idle_timeout
118+
; flow_hard_timeout = stats.hard_timeout
119+
; flow_actions = List.map (to_action inPort) stats.actions
120+
; flow_packet_count = stats.packet_count
121+
; flow_byte_count = stats.byte_count
122+
}
123+
40124
let from_pattern (pat : AL.Pattern.t) : Core.pattern =
41125
{ Core.dlSrc = pat.AL.Pattern.dlSrc
42126
; Core.dlDst = pat.AL.Pattern.dlDst

lib/SDN_OpenFlow0x01.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
exception Invalid_port of int32
22

33
val to_payload : OpenFlow0x01_Core.payload -> SDN_Types.payload
4-
val from_payload : SDN_Types.payload -> OpenFlow0x01_Core.payload
54
val to_reason : OpenFlow0x01_Core.packetInReason -> SDN_Types.packetInReason
65
val to_packetIn : OpenFlow0x01_Core.packetIn -> SDN_Types.pktIn
6+
val to_flowStats : OpenFlow0x01_Stats.individualStats -> SDN_Types.flowStats
7+
8+
val from_payload : SDN_Types.payload -> OpenFlow0x01_Core.payload
79
val from_packetOut : SDN_Types.pktOut -> OpenFlow0x01_Core.packetOut
810
val from_pattern : SDN_Types.Pattern.t -> OpenFlow0x01_Core.pattern
911
val from_group : OpenFlow0x01_Core.portId option -> SDN_Types.group -> OpenFlow0x01_Core.action list

lib/SDN_Types.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ type flowStats = {
305305
flow_priority: int16;
306306
flow_idle_timeout: int16;
307307
flow_hard_timeout: int16;
308-
flow_action: action;
308+
flow_actions: action list;
309309
flow_packet_count: int64;
310310
flow_byte_count: int64
311311
}

lib/SDN_Types.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ type flowStats = {
195195
flow_priority: int16;
196196
flow_idle_timeout: int16;
197197
flow_hard_timeout: int16;
198-
flow_action: action;
198+
flow_actions: action list;
199199
flow_packet_count: int64;
200200
flow_byte_count: int64
201201
}

0 commit comments

Comments
 (0)