blob: f99447d70f3026a769b6226c8b3aea89c35f7e21 [file] [log] [blame]
Paul Stewartdd60e452011-08-08 11:38:36 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SHILL_CONNECTION_
6#define SHILL_CONNECTION_
7
8#include <string>
9#include <vector>
10
11#include <base/memory/ref_counted.h>
12#include <gtest/gtest_prod.h> // for FRIEND_TEST
13
14#include "shill/refptr_types.h"
15
16namespace shill {
17
Paul Stewart9a908082011-08-31 12:18:48 -070018class DeviceInfo;
Paul Stewartdd60e452011-08-08 11:38:36 -070019class Resolver;
20class RoutingTable;
21class RTNLHandler;
22
23// The Conneciton maintains the implemented state of an IPConfig, e.g,
24// the IP address, routing table and DNS table entries.
25class Connection : public base::RefCounted<Connection> {
26 public:
Paul Stewart9a908082011-08-31 12:18:48 -070027 Connection(int interface_index,
28 const std::string &interface_name,
29 const DeviceInfo *device_info);
Paul Stewartdd60e452011-08-08 11:38:36 -070030 virtual ~Connection();
31
32 // Add the contents of an IPConfig reference to the list of managed state.
33 // This will replace all previous state for this address family.
Paul Stewartc1dec4d2011-12-08 15:25:28 -080034 virtual void UpdateFromIPConfig(const IPConfigRefPtr &config);
Paul Stewartdd60e452011-08-08 11:38:36 -070035
36 // Sets the current connection as "default", i.e., routes and DNS entries
37 // should be used by all system components that don't select explicitly.
38 bool is_default() const { return is_default_; }
Paul Stewartc1dec4d2011-12-08 15:25:28 -080039 virtual void SetIsDefault(bool is_default);
Paul Stewartdd60e452011-08-08 11:38:36 -070040
Paul Stewartbe5f5b32011-12-07 17:11:11 -080041 const std::string &interface_name() const { return interface_name_; }
42 const std::vector<std::string> &dns_servers() const { return dns_servers_; }
43
Paul Stewartdd60e452011-08-08 11:38:36 -070044 private:
45 friend class ConnectionTest;
46 FRIEND_TEST(ConnectionTest, InitState);
47 FRIEND_TEST(ConnectionTest, AddConfig);
48 FRIEND_TEST(ConnectionTest, AddConfigReverse);
49 FRIEND_TEST(ConnectionTest, Destructor);
50
51 static const uint32 kDefaultMetric;
Paul Stewart7cfca042011-12-08 14:18:17 -080052 static const uint32 kNonDefaultMetricBase;
53
54 uint32 GetMetric(bool is_default);
Paul Stewartdd60e452011-08-08 11:38:36 -070055
56 bool is_default_;
57 int interface_index_;
58 const std::string interface_name_;
59 std::vector<std::string> dns_servers_;
60 std::vector<std::string> dns_domain_search_;
61
62 // Store cached copies of singletons for speed/ease of testing
Paul Stewart9a908082011-08-31 12:18:48 -070063 const DeviceInfo *device_info_;
Paul Stewartdd60e452011-08-08 11:38:36 -070064 Resolver *resolver_;
65 RoutingTable *routing_table_;
66 RTNLHandler *rtnl_handler_;
67
68 DISALLOW_COPY_AND_ASSIGN(Connection);
69};
70
71} // namespace shill
72
73#endif // SHILL_CONNECTION_