Skip to content

Commit 53e51e5

Browse files
committed
Merge pull request #172 from frenetic-lang/mask-more-bugfix
Fix bug in IP wildcarding.
2 parents 4ebd865 + 64a1818 commit 53e51e5

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

lib/SDN_OpenFlow0x01.ml

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module AL = SDN_Types
22
module Core = OpenFlow0x01_Core
33
module Msg = OpenFlow0x01.Message
44

5-
65
exception Invalid_port of int32
76

87
let from_portId (pport_id : AL.portId) : Core.portId =
@@ -48,13 +47,23 @@ let from_pattern (pat : AL.Pattern.t) : Core.pattern =
4847
| None -> None)
4948
; Core.dlVlanPcp = pat.AL.Pattern.dlVlanPcp
5049
; Core.nwSrc = (match pat.AL.Pattern.nwSrc with
51-
| None -> None
52-
| Some (p,m) -> let mo = if m = 32l then None else Some m in
53-
Some { Core.m_value = p; Core.m_mask = mo })
50+
| None -> None
51+
| Some (p,m) ->
52+
let mo =
53+
if m = 32l then
54+
None
55+
else
56+
Some (Int32.sub 32l m) in
57+
Some { Core.m_value = p; Core.m_mask = mo })
5458
; Core.nwDst = (match pat.AL.Pattern.nwDst with
55-
| None -> None
56-
| Some (p,m) -> let mo = if m = 32l then None else Some m in
57-
Some { Core.m_value = p; Core.m_mask = mo })
59+
| None -> None
60+
| Some (p,m) ->
61+
let mo =
62+
if m = 32l then
63+
None
64+
else
65+
Some (Int32.sub 32l m) in
66+
Some { Core.m_value = p; Core.m_mask = mo })
5867
; Core.nwProto = pat.AL.Pattern.nwProto
5968
; Core.nwTos = None
6069
; Core.tpSrc = pat.AL.Pattern.tpSrc
@@ -82,11 +91,11 @@ module Common = HighLevelSwitch_common.Make (struct
8291
| AL.All ->
8392
(Mod.none, Output AllPorts)
8493
| AL.Physical pport_id ->
85-
let pport_id = from_portId pport_id in
86-
if Some pport_id = inPort then
87-
(Mod.none, Output InPort)
88-
else
89-
(Mod.none, Output (PhysicalPort pport_id))
94+
let pport_id = from_portId pport_id in
95+
if Some pport_id = inPort then
96+
(Mod.none, Output InPort)
97+
else
98+
(Mod.none, Output (PhysicalPort pport_id))
9099
| AL.Controller n ->
91100
(Mod.none, Output (Controller n))
92101
| AL.Local ->
@@ -119,30 +128,34 @@ module Common = HighLevelSwitch_common.Make (struct
119128
end
120129
| AL.Modify (AL.SetVlanPcp pcp) ->
121130
(Mod.dlVlanPcp, SetDlVlanPcp(VInt.(get_int4 (Int4 pcp))))
122-
| AL.Modify (AL.SetEthTyp _) -> raise (Invalid_argument "cannot set Ethernet type")
123-
| AL.Modify (AL.SetIPProto _) -> raise (Invalid_argument "cannot set IP protocol")
131+
| AL.Modify (AL.SetEthTyp _) ->
132+
raise (Invalid_argument "cannot set Ethernet type")
133+
| AL.Modify (AL.SetIPProto _) ->
134+
raise (Invalid_argument "cannot set IP protocol")
124135
| AL.Modify (AL.SetIP4Src nwAddr) ->
125136
(Mod.nwSrc, SetNwSrc nwAddr)
126137
| AL.Modify (AL.SetIP4Dst nwAddr) ->
127138
(Mod.nwDst, SetNwDst nwAddr)
128139
| AL.Modify (AL.SetTCPSrcPort tp) ->
129-
(Mod.tpSrc, SetTpSrc VInt.(get_int16 (Int16 tp)))
140+
(Mod.tpSrc, SetTpSrc VInt.(get_int16 (Int16 tp)))
130141
| AL.Modify (AL.SetTCPDstPort tp) ->
131142
(Mod.tpDst, SetTpDst VInt.(get_int16 (Int16 tp)))
132143
end)
133144

134-
let from_group (inPort : Core.portId option) (group : AL.group) : Core.action list =
145+
let from_group (inPort : Core.portId option) (group : AL.group)
146+
: Core.action list =
135147
match group with
136148
| [] -> []
137149
| [par] -> Common.flatten_par inPort par
138-
| _ -> raise (SDN_Types.Unsupported "OpenFlow 1.0 does not support fast-failover")
150+
| _ ->
151+
raise (SDN_Types.Unsupported "OpenFlow 1.0 does not support fast-failover")
139152

140153
let from_timeout (timeout : AL.timeout) : Core.timeout =
141154
match timeout with
142155
| AL.Permanent -> Core.Permanent
143156
| AL.ExpiresAfter n -> Core.ExpiresAfter n
144157

145-
let from_flow (priority : int) (flow : AL.flow) : Core.flowMod =
158+
let from_flow (priority : int) (flow : AL.flow) : Core.flowMod =
146159
let open AL in
147160
match flow with
148161
| { pattern; action; cookie; idle_timeout; hard_timeout } ->

0 commit comments

Comments
 (0)