Support disconnecting nodes.

We have a case where message bridge client failed to connect on only one
of the nodes.  This resulted in an unreadable log file.  Add the ability
for simulated event loop to recreate this situation.

Change-Id: If471f1690fad45d905c6299324f514ab86355805
diff --git a/aos/events/simulated_network_bridge.cc b/aos/events/simulated_network_bridge.cc
index 45bc6e7..0b79504 100644
--- a/aos/events/simulated_network_bridge.cc
+++ b/aos/events/simulated_network_bridge.cc
@@ -63,6 +63,14 @@
       if (sent_) {
         break;
       }
+
+      if (server_connection_->state() != State::CONNECTED) {
+        sent_ = true;
+        server_connection_->mutate_dropped_packets(
+            server_connection_->dropped_packets() + 1);
+        continue;
+      }
+
       if (fetcher_->context().monotonic_event_time +
               send_node_factory_->network_delay() +
               send_node_factory_->send_delay() >
@@ -109,6 +117,11 @@
  private:
   // Acutally sends the message, and reschedules.
   void Send() {
+    if (server_connection_->state() != State::CONNECTED) {
+      sent_ = true;
+      Schedule();
+      return;
+    }
     // Fill out the send times.
     sender_->Send(fetcher_->context().data, fetcher_->context().size,
                   fetcher_->context().monotonic_event_time,
@@ -379,6 +392,38 @@
   }
 }
 
+void SimulatedMessageBridge::Disconnect(const Node *source,
+                                        const Node *destination) {
+  SetState(source, destination, message_bridge::State::DISCONNECTED);
+}
+
+void SimulatedMessageBridge::Connect(const Node *source,
+                                     const Node *destination) {
+  SetState(source, destination, message_bridge::State::CONNECTED);
+}
+void SimulatedMessageBridge::SetState(const Node *source,
+                                      const Node *destination,
+                                      message_bridge::State state) {
+  auto source_state = event_loop_map_.find(source);
+  CHECK(source_state != event_loop_map_.end());
+
+  ServerConnection *server_connection =
+      source_state->second.server_status.FindServerConnection(destination);
+  if (!server_connection) {
+    return;
+  }
+  server_connection->mutate_state(state);
+
+  auto destination_state = event_loop_map_.find(destination);
+  CHECK(destination_state != event_loop_map_.end());
+  ClientConnection *client_connection =
+      destination_state->second.client_status.GetClientConnection(source);
+  if (!client_connection) {
+    return;
+  }
+  client_connection->mutate_state(state);
+}
+
 void SimulatedMessageBridge::DisableStatistics() {
   for (std::pair<const Node *const, State> &state : event_loop_map_) {
     state.second.server_status.DisableStatistics();