@@ -60,32 +60,41 @@ module Controller = struct
60
60
let close t = ChunkController. close t.sub
61
61
let has_client_id t = ChunkController. has_client_id t.sub
62
62
let send t s_id msg = ChunkController. send t.sub s_id (Message. marshal' msg)
63
+ let send_ignore_errors t s_id msg = ChunkController. send_ignore_errors t.sub s_id (Message. marshal' msg)
63
64
let send_to_all t msg = ChunkController. send_to_all t.sub (Message. marshal' msg)
64
65
let client_addr_port t = ChunkController. client_addr_port t.sub
65
66
let listening_port t = ChunkController. listening_port t.sub
66
67
67
68
(* XXX(seliopou): Raises `Not_found` if the client is no longer connected. *)
68
- let switch_id_of_client t c_id = ClientMap. find_exn t.switches c_id
69
- let client_id_of_switch t sw_id = SwitchMap. find_exn t.clients sw_id
69
+ let switch_id_of_client_exn t c_id = ClientMap. find_exn t.switches c_id
70
+ let client_id_of_switch_exn t sw_id = SwitchMap. find_exn t.clients sw_id
71
+
72
+ let switch_id_of_client t c_id = ClientMap. find t.switches c_id
73
+ let client_id_of_switch t sw_id = SwitchMap. find t.clients sw_id
74
+
75
+ let set_monitor_interval (t :t ) (s :Time.Span.t ) : unit =
76
+ ChunkController. set_monitor_interval t.sub s
77
+
78
+ let set_idle_wait (t :t ) (s :Time.Span.t ) : unit =
79
+ ChunkController. set_idle_wait t.sub s
80
+
81
+ let set_kill_wait (t :t ) (s :Time.Span.t ) : unit =
82
+ ChunkController. set_kill_wait t.sub s
70
83
71
84
let create ?max_pending_connections
72
85
?verbose
73
86
?log_disconnects
74
- ?buffer_age_limit ~port () =
87
+ ?buffer_age_limit
88
+ ?monitor_connections ~port () =
75
89
ChunkController. create ?max_pending_connections ?verbose ?log_disconnects
76
- ?buffer_age_limit ~port ()
90
+ ?buffer_age_limit ?monitor_connections ~port ()
77
91
>> | function t ->
78
92
{ sub = t
79
93
; shakes = ClientSet. empty
80
94
; switches = ClientMap. empty
81
95
; clients = SwitchMap. empty
82
96
}
83
97
84
- let _send t c_id m =
85
- send t c_id (0l , m) >> | function
86
- | `Drop exn -> raise exn
87
- | `Sent _ -> ()
88
-
89
98
let openflow0x01 t evt =
90
99
match evt with
91
100
| `Connect (c_id , version ) ->
@@ -104,15 +113,24 @@ module Controller = struct
104
113
let features t evt =
105
114
match evt with
106
115
| `Connect (c_id ) ->
116
+ assert (not (ClientSet. mem t.shakes c_id));
107
117
t.shakes < - ClientSet. add t.shakes c_id;
108
- send t c_id (0l , M. SwitchFeaturesRequest ) >> | ChunkController. ensure
118
+ send t c_id (0l , M. SwitchFeaturesRequest )
119
+ (* XXX(seliopou): This swallows any errors that might have occurred
120
+ * while attemping the handshake. Any such error should not be raised,
121
+ * since as far as the user is concerned the connection never existed.
122
+ * At the very least, the exception should be logged, which it will be
123
+ * as long as the log_disconnects option is not disabled when creating
124
+ * the controller.
125
+ * *)
126
+ >> | (function _ -> [] )
109
127
| `Message (c_id , (xid , msg )) when ClientSet. mem t.shakes c_id ->
110
128
begin match msg with
111
129
| M. SwitchFeaturesReply fs ->
112
130
let switch_id = fs.OpenFlow0x01.SwitchFeatures. switch_id in
113
131
t.switches < - ClientMap. add t.switches c_id switch_id;
114
- t.clients < - SwitchMap. add t.clients switch_id c_id;
115
- t.shakes < - ClientSet. remove t.shakes c_id;
132
+ t.clients < - SwitchMap. add t.clients switch_id c_id;
133
+ t.shakes < - ClientSet. remove t.shakes c_id;
116
134
return [`Connect (c_id, fs)]
117
135
| _ ->
118
136
Log. of_lazy ~tags ~level: `Debug (lazy
@@ -126,11 +144,12 @@ module Controller = struct
126
144
let m_sw_id = ClientMap. find t.switches c_id in
127
145
match m_sw_id with
128
146
| None -> (* features request did not complete *)
147
+ assert (ClientSet. mem t.shakes c_id);
129
148
t.shakes < - ClientSet. remove t.shakes c_id;
130
149
return []
131
150
| Some (sw_id ) -> (* features request did complete *)
132
- t.clients < - SwitchMap. remove t.clients sw_id;
133
151
t.switches < - ClientMap. remove t.switches c_id;
152
+ t.clients < - SwitchMap. remove t.clients sw_id;
134
153
return [`Disconnect (c_id, sw_id, exn )]
135
154
136
155
let listen t =
0 commit comments