Skip to content

Commit 23c5542

Browse files
committed
flowstats: implement translation btwn 0x01 and SDN
1 parent de8229a commit 23c5542

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ val to_payload : OpenFlow0x01_Core.payload -> SDN_Types.payload
44
val from_payload : SDN_Types.payload -> OpenFlow0x01_Core.payload
55
val to_reason : OpenFlow0x01_Core.packetInReason -> SDN_Types.packetInReason
66
val to_packetIn : OpenFlow0x01_Core.packetIn -> SDN_Types.pktIn
7+
val to_flowStats : OpenFlow0x01_Stats.individualStats -> SDN_Types.flowStats
78
val from_packetOut : SDN_Types.pktOut -> OpenFlow0x01_Core.packetOut
89
val from_pattern : SDN_Types.Pattern.t -> OpenFlow0x01_Core.pattern
910
val from_group : OpenFlow0x01_Core.portId option -> SDN_Types.group -> OpenFlow0x01_Core.action list

0 commit comments

Comments
 (0)