blob: cb38f7d72659150825697de6343f6ff256c55ad3 [file] [log] [blame]
Jie Jiang81c84db2020-09-29 17:40:16 +09001// Copyright 2020 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 PATCHPANEL_DBUS_FAKE_CLIENT_H_
6#define PATCHPANEL_DBUS_FAKE_CLIENT_H_
7
8#include <memory>
9#include <set>
10#include <string>
11#include <utility>
12#include <vector>
13
14#include "patchpanel/dbus/client.h"
15
16namespace patchpanel {
17
18// Fake implementation of patchpanel::ClientInterface which can be used in
19// tests.
20class BRILLO_EXPORT FakeClient : public Client {
21 public:
22 FakeClient() = default;
23 ~FakeClient() = default;
24
25 // Client overrides.
Garrick Evansd0a646e2020-11-25 21:08:32 +090026 void RegisterOnAvailableCallback(
27 base::RepeatingCallback<void(bool)> callback) override;
Garrick Evans6a062012021-02-15 09:25:44 +090028 void RegisterProcessChangedCallback(
29 base::RepeatingCallback<void(bool)> callback) override;
Garrick Evansd0a646e2020-11-25 21:08:32 +090030
Jie Jiang81c84db2020-09-29 17:40:16 +090031 bool NotifyArcStartup(pid_t pid) override;
32 bool NotifyArcShutdown() override;
33
34 std::vector<NetworkDevice> NotifyArcVmStartup(uint32_t cid) override;
35 bool NotifyArcVmShutdown(uint32_t cid) override;
36
37 bool NotifyTerminaVmStartup(uint32_t cid,
38 NetworkDevice* device,
39 IPv4Subnet* container_subnet) override;
40 bool NotifyTerminaVmShutdown(uint32_t cid) override;
41
42 bool NotifyPluginVmStartup(uint64_t vm_id,
43 int subnet_index,
44 NetworkDevice* device) override;
45 bool NotifyPluginVmShutdown(uint64_t vm_id) override;
46
47 bool DefaultVpnRouting(int socket) override;
48
49 bool RouteOnVpn(int socket) override;
50
51 bool BypassVpn(int socket) override;
52
53 std::pair<base::ScopedFD, patchpanel::ConnectNamespaceResponse>
54 ConnectNamespace(pid_t pid,
55 const std::string& outbound_ifname,
Garrick Evans58697022020-12-03 12:41:13 +090056 bool forward_user_traffic,
57 bool route_on_vpn,
58 TrafficCounter::Source traffic_source) override;
Jie Jiang81c84db2020-09-29 17:40:16 +090059
60 void GetTrafficCounters(const std::set<std::string>& devices,
61 GetTrafficCountersCallback callback) override;
62
63 bool ModifyPortRule(patchpanel::ModifyPortRuleRequest::Operation op,
64 patchpanel::ModifyPortRuleRequest::RuleType type,
65 patchpanel::ModifyPortRuleRequest::Protocol proto,
66 const std::string& input_ifname,
67 const std::string& input_dst_ip,
68 uint32_t input_dst_port,
69 const std::string& dst_ip,
70 uint32_t dst_port) override;
71
Hugo Benichi007abcc2021-05-14 10:44:45 +090072 bool SetVpnLockdown(bool enable) override;
73
Garrick Evans9e637982020-11-30 11:59:27 +090074 std::vector<NetworkDevice> GetDevices() override;
75
Garrick Evansf04f0442020-12-01 12:36:44 +090076 void RegisterNetworkDeviceChangedSignalHandler(
77 NetworkDeviceChangedSignalHandler handler) override;
78
Jie Jiang25c1b972020-11-12 15:42:53 +090079 void RegisterNeighborReachabilityEventHandler(
80 NeighborReachabilityEventHandler handler) override;
Jie Jiang81c84db2020-09-29 17:40:16 +090081
Jie Jiang25c1b972020-11-12 15:42:53 +090082 // Triggers registered handlers for NeighborReachabilityEventSignal.
83 void TriggerNeighborReachabilityEvent(
84 const NeighborReachabilityEventSignal& signal);
Jie Jiang81c84db2020-09-29 17:40:16 +090085
86 void set_stored_traffic_counters(
87 const std::vector<TrafficCounter>& counters) {
88 stored_traffic_counters_ = counters;
89 }
90
91 private:
92 std::vector<TrafficCounter> stored_traffic_counters_;
Jie Jiang25c1b972020-11-12 15:42:53 +090093 std::vector<NeighborReachabilityEventHandler> neighbor_handlers_;
Garrick Evansf04f0442020-12-01 12:36:44 +090094 NetworkDeviceChangedSignalHandler network_device_changed_handler_;
Jie Jiang81c84db2020-09-29 17:40:16 +090095};
96
97} // namespace patchpanel
98
99#endif // PATCHPANEL_DBUS_FAKE_CLIENT_H_