Skip to content

Commit 714ba82

Browse files
committed
multi: only report usable ports in switch features
The abstraction layer does not expose any of the data structures necessary for the user to determine whether or not a port is live or not. The abstraciton layer therefore needs to make this determination for the user by filtering ports in the initial feature request, and surfacing events when ports come up or down.
1 parent 5b38fcc commit 714ba82

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

async/Async_SDN.ml

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,33 @@ let create ?max_pending_connections
5555
let listen_of0x01 (t : t) : Chunk_Controller.h Pipe.Writer.t * e Pipe.Reader.t =
5656
let module OF = OpenFlow0x01 in
5757
let recv, send = Pipe.create () in
58-
let get_port pd = Int32.of_int_exn pd.OF.PortDescription.port_no in
58+
let port_useable pd =
59+
let open OF.PortDescription in
60+
if pd.config.PortConfig.down
61+
then false
62+
else not (pd.state.PortState.down)
63+
in
64+
let get_port pd =
65+
if port_useable pd
66+
then Some(Int32.of_int_exn pd.OF.PortDescription.port_no)
67+
else None
68+
in
5969
send, Pipe.filter_map (OF0x01_Controller.listen_pipe t.sub_0x01 recv)
6070
~f:(function
6171
| `Connect(sw_id, fs) ->
6272
let sdn_fs =
6373
{ SDN.switch_id = sw_id
64-
; SDN.switch_ports = List.map fs.OF.SwitchFeatures.ports ~f:get_port }
74+
; SDN.switch_ports = List.filter_map fs.OF.SwitchFeatures.ports ~f:get_port }
6575
in
6676
Some(`Connect(sw_id, sdn_fs))
6777
| `Disconnect(sw_id, exn) ->
6878
Some(`Disconnect(sw_id, exn))
6979
| `Message(sw_id, (xid, OF.Message.PacketInMsg pi)) ->
7080
Some(`PacketIn(sw_id, SDN_OpenFlow0x01.to_packetIn pi))
7181
| `Message (sw_id, (xid, OF.Message.PortStatusMsg ps)) ->
72-
let open OF.PortDescription in
7382
let open OF.PortStatus in
74-
let useable =
75-
if ps.desc.config.PortConfig.down
76-
then false
77-
else not (ps.desc.state.PortState.down)
78-
in
79-
begin match ps.reason, useable with
83+
let open OF.PortDescription in
84+
begin match ps.reason, port_useable ps.desc with
8085
| ChangeReason.Add, true
8186
| ChangeReason.Modify, true ->
8287
let pt_id = Int32.of_int_exn (ps.desc.port_no) in
@@ -92,28 +97,32 @@ let listen_of0x01 (t : t) : Chunk_Controller.h Pipe.Writer.t * e Pipe.Reader.t =
9297

9398
let listen_of0x04 (t : t) : Chunk_Controller.h Pipe.Writer.t * e Pipe.Reader.t =
9499
let module OF = OpenFlow0x04 in
100+
let open OpenFlow0x04_Core in
95101
let recv, send = Pipe.create () in
96-
let get_port pd = pd.OpenFlow0x04_Core.port_no in
102+
let port_useable (pd : portDesc) =
103+
if pd.config.port_down
104+
then false
105+
else not (pd.state.link_down)
106+
in
107+
let get_port pd =
108+
if port_useable pd
109+
then Some(pd.port_no)
110+
else None
111+
in
97112
send, Pipe.filter_map (OF0x04_Controller.listen_pipe t.sub_0x04 recv)
98113
~f:(function
99114
| `Connect(sw_id, (fs, ps)) ->
100115
let sdn_fs =
101116
{ SDN.switch_id = sw_id
102-
; SDN.switch_ports = List.map ps ~f:get_port }
117+
; SDN.switch_ports = List.filter_map ps ~f:get_port }
103118
in
104119
Some(`Connect(sw_id, sdn_fs))
105120
| `Disconnect(sw_id, exn) ->
106121
Some(`Disconnect(sw_id, exn))
107122
| `Message(sw_id, (xid, OF.Message.PacketInMsg pi)) ->
108123
Some(`PacketIn(sw_id, SDN_OpenFlow0x04.to_packetIn pi))
109124
| `Message (sw_id, (xid, OF.Message.PortStatusMsg ps)) ->
110-
let open OpenFlow0x04_Core in
111-
let useable =
112-
if ps.desc.config.port_down
113-
then false
114-
else not (ps.desc.state.link_down)
115-
in
116-
begin match ps.reason, useable with
125+
begin match ps.reason, port_useable ps.desc with
117126
| PortAdd, true
118127
| PortModify, true ->
119128
Some(`PortUp(sw_id, ps.desc.port_no))

0 commit comments

Comments
 (0)