summaryrefslogtreecommitdiff
path: root/connection_info_reader.h
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2013-04-12 17:15:43 -0700
committerChromeBot <chrome-bot@google.com>2013-04-16 16:03:44 -0700
commitbac5bc8cc9debc8f55decbeab64df6c79c60d3ba (patch)
tree74bd3c4f7432138273987cfd38ac94591ae179fb /connection_info_reader.h
parent0364fb6b844aca8265f240ccb3693edb0e365edf (diff)
downloadshill-bac5bc8cc9debc8f55decbeab64df6c79c60d3ba.tar.gz
shill: Add ConnectionInfoReader class to read connection information.
BUG=chromium:230938 TEST=Build and run unit tests. Change-Id: Ie1f8d01e5c1b6d604e7bea9964a8c26af229528a Reviewed-on: https://gerrit.chromium.org/gerrit/48064 Reviewed-by: Thieu Le <thieule@chromium.org> Commit-Queue: Ben Chan <benchan@chromium.org> Tested-by: Ben Chan <benchan@chromium.org>
Diffstat (limited to 'connection_info_reader.h')
-rw-r--r--connection_info_reader.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/connection_info_reader.h b/connection_info_reader.h
new file mode 100644
index 00000000..a82b29bd
--- /dev/null
+++ b/connection_info_reader.h
@@ -0,0 +1,56 @@
+// Copyright (c) 2013 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_INFO_READER_H_
+#define SHILL_CONNECTION_INFO_READER_H_
+
+#include <string>
+#include <vector>
+
+#include <base/basictypes.h>
+#include <base/file_path.h>
+#include <gtest/gtest_prod.h>
+
+#include "shill/connection_info.h"
+
+namespace shill {
+
+class ConnectionInfoReader {
+ public:
+ ConnectionInfoReader();
+ virtual ~ConnectionInfoReader();
+
+ // Returns the file path (/proc/net/ip_conntrack by default) from where
+ // IP connection tracking information are read. Overloadded by unit tests
+ // to return a different file path.
+ virtual base::FilePath GetConnectionInfoFilePath() const;
+
+ // Loads IP connection tracking information from the file path returned by
+ // GetConnectionInfoFilePath(). Existing entries in |info_list| are always
+ // discarded. Returns true on success.
+ virtual bool LoadConnectionInfo(std::vector<ConnectionInfo> *info_list);
+
+ private:
+ FRIEND_TEST(ConnectionInfoReaderTest, ParseConnectionInfo);
+ FRIEND_TEST(ConnectionInfoReaderTest, ParseIPAddress);
+ FRIEND_TEST(ConnectionInfoReaderTest, ParseIsUnreplied);
+ FRIEND_TEST(ConnectionInfoReaderTest, ParsePort);
+ FRIEND_TEST(ConnectionInfoReaderTest, ParseProtocol);
+ FRIEND_TEST(ConnectionInfoReaderTest, ParseTimeToExpireSeconds);
+
+ bool ParseConnectionInfo(const std::string &input, ConnectionInfo *info);
+ bool ParseProtocol(const std::string &input, int *protocol);
+ bool ParseTimeToExpireSeconds(const std::string &input,
+ int64 *time_to_expire_seconds);
+ bool ParseIsUnreplied(const std::string &input, bool *is_unreplied);
+ bool ParseIPAddress(const std::string &input,
+ IPAddress *ip_address, bool *is_source);
+ bool ParsePort(const std::string &input, uint16 *port, bool *is_source);
+
+ DISALLOW_COPY_AND_ASSIGN(ConnectionInfoReader);
+};
+
+} // namespace shill
+
+#endif // SHILL_CONNECTION_INFO_READER_H_