@@ -55,28 +55,33 @@ let create ?max_pending_connections
55
55
let listen_of0x01 (t : t ) : Chunk_Controller.h Pipe.Writer.t * e Pipe.Reader.t =
56
56
let module OF = OpenFlow0x01 in
57
57
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
59
69
send, Pipe. filter_map (OF0x01_Controller. listen_pipe t.sub_0x01 recv)
60
70
~f: (function
61
71
| `Connect (sw_id , fs ) ->
62
72
let sdn_fs =
63
73
{ 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 }
65
75
in
66
76
Some (`Connect (sw_id, sdn_fs))
67
77
| `Disconnect (sw_id , exn ) ->
68
78
Some (`Disconnect (sw_id, exn ))
69
79
| `Message (sw_id , (xid , OF.Message. PacketInMsg pi )) ->
70
80
Some (`PacketIn (sw_id, SDN_OpenFlow0x01. to_packetIn pi))
71
81
| `Message (sw_id , (xid , OF.Message. PortStatusMsg ps )) ->
72
- let open OF.PortDescription in
73
82
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
80
85
| ChangeReason. Add , true
81
86
| ChangeReason. Modify , true ->
82
87
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 =
92
97
93
98
let listen_of0x04 (t : t ) : Chunk_Controller.h Pipe.Writer.t * e Pipe.Reader.t =
94
99
let module OF = OpenFlow0x04 in
100
+ let open OpenFlow0x04_Core in
95
101
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
97
112
send, Pipe. filter_map (OF0x04_Controller. listen_pipe t.sub_0x04 recv)
98
113
~f: (function
99
114
| `Connect (sw_id , (fs , ps )) ->
100
115
let sdn_fs =
101
116
{ 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 }
103
118
in
104
119
Some (`Connect (sw_id, sdn_fs))
105
120
| `Disconnect (sw_id , exn ) ->
106
121
Some (`Disconnect (sw_id, exn ))
107
122
| `Message (sw_id , (xid , OF.Message. PacketInMsg pi )) ->
108
123
Some (`PacketIn (sw_id, SDN_OpenFlow0x04. to_packetIn pi))
109
124
| `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
117
126
| PortAdd , true
118
127
| PortModify , true ->
119
128
Some (`PortUp (sw_id, ps.desc.port_no))
0 commit comments