shill: Add connection class

The connection class represents the snapshot of connectivity
state, including routing, address information and addressing.
It is able to apply itself as the "default" connection, by
setting routing table metrics and DNS resolver files.

BUG=chromium-os:19095
TEST=New unittest

Change-Id: I7021867ed8a8559db0e84f58a72692abaf105cad
Reviewed-on: http://gerrit.chromium.org/gerrit/5938
Reviewed-by: Chris Masone <cmasone@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/connection.h b/connection.h
new file mode 100644
index 0000000..d3d7310
--- /dev/null
+++ b/connection.h
@@ -0,0 +1,64 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_CONNECTION_
+#define SHILL_CONNECTION_
+
+#include <string>
+#include <vector>
+
+#include <base/memory/ref_counted.h>
+#include <gtest/gtest_prod.h>  // for FRIEND_TEST
+
+#include "shill/refptr_types.h"
+
+namespace shill {
+
+class Resolver;
+class RoutingTable;
+class RTNLHandler;
+
+// The Conneciton maintains the implemented state of an IPConfig, e.g,
+// the IP address, routing table and DNS table entries.
+class Connection : public base::RefCounted<Connection> {
+ public:
+  Connection(int interface_index, const std::string& interface_name);
+  virtual ~Connection();
+
+  // Add the contents of an IPConfig reference to the list of managed state.
+  // This will replace all previous state for this address family.
+  void UpdateFromIPConfig(const IPConfigRefPtr &config);
+
+  // Sets the current connection as "default", i.e., routes and DNS entries
+  // should be used by all system components that don't select explicitly.
+  bool is_default() const { return is_default_; }
+  void SetDefault(bool is_default);
+
+ private:
+  friend class ConnectionTest;
+  FRIEND_TEST(ConnectionTest, InitState);
+  FRIEND_TEST(ConnectionTest, AddConfig);
+  FRIEND_TEST(ConnectionTest, AddConfigReverse);
+  FRIEND_TEST(ConnectionTest, Destructor);
+
+  static const uint32 kDefaultMetric;
+  static const uint32 kNonDefaultMetric;
+
+  bool is_default_;
+  int interface_index_;
+  const std::string interface_name_;
+  std::vector<std::string> dns_servers_;
+  std::vector<std::string> dns_domain_search_;
+
+  // Store cached copies of singletons for speed/ease of testing
+  Resolver *resolver_;
+  RoutingTable *routing_table_;
+  RTNLHandler *rtnl_handler_;
+
+  DISALLOW_COPY_AND_ASSIGN(Connection);
+};
+
+}  // namespace shill
+
+#endif  // SHILL_CONNECTION_