blob: aecda793bed08c651cfe1d5d668c7844bd6dbfcd [file] [log] [blame]
Garrick Evansf0ab7132019-06-18 14:50:42 +09001// Copyright 2019 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
Garrick Evans3388a032020-03-24 11:25:55 +09005#ifndef PATCHPANEL_MOCK_DATAPATH_H_
6#define PATCHPANEL_MOCK_DATAPATH_H_
Garrick Evansf0ab7132019-06-18 14:50:42 +09007
8#include <string>
9
10#include <base/macros.h>
11
Garrick Evans3388a032020-03-24 11:25:55 +090012#include "patchpanel/datapath.h"
Jason Jeremy Imana7273a32020-08-04 11:25:31 +090013#include "patchpanel/firewall.h"
Garrick Evans3388a032020-03-24 11:25:55 +090014#include "patchpanel/minijailed_process_runner.h"
Garrick Evansf0ab7132019-06-18 14:50:42 +090015
Garrick Evans3388a032020-03-24 11:25:55 +090016namespace patchpanel {
Garrick Evansf0ab7132019-06-18 14:50:42 +090017
18// ARC networking data path configuration utility.
19class MockDatapath : public Datapath {
20 public:
Jason Jeremy Imana7273a32020-08-04 11:25:31 +090021 explicit MockDatapath(MinijailedProcessRunner* runner, Firewall* firewall)
22 : Datapath(runner, firewall) {}
Qijiang Fan6bc59e12020-11-11 02:51:06 +090023 MockDatapath(const MockDatapath&) = delete;
24 MockDatapath& operator=(const MockDatapath&) = delete;
25
Garrick Evansf0ab7132019-06-18 14:50:42 +090026 ~MockDatapath() = default;
27
Hugo Benichibf811c62020-09-07 17:30:45 +090028 MOCK_METHOD0(Start, void());
29 MOCK_METHOD0(Stop, void());
Hugo Benichi33860d72020-07-09 16:34:01 +090030 MOCK_METHOD2(NetnsAttachName,
31 bool(const std::string& netns_name, pid_t netns_pid));
32 MOCK_METHOD1(NetnsDeleteName, bool(const std::string& netns_name));
33
Garrick Evans7a1a9ee2020-01-28 11:03:57 +090034 MOCK_METHOD3(AddBridge,
35 bool(const std::string& ifname,
36 uint32_t ipv4_addr,
37 uint32_t prefix_len));
Yuichiro Hanadaed427fd2019-09-25 08:41:21 +000038 MOCK_METHOD1(RemoveBridge, void(const std::string& ifname));
Garrick Evansb4eb3892019-11-13 12:07:07 +090039 MOCK_METHOD2(AddToBridge,
40 bool(const std::string& br_ifname, const std::string& ifname));
Hugo Benichi33860d72020-07-09 16:34:01 +090041
Garrick Evansb4eb3892019-11-13 12:07:07 +090042 MOCK_METHOD4(AddTAP,
43 std::string(const std::string& name,
44 const MacAddress* mac_addr,
45 const SubnetAddress* ipv4_addr,
46 const std::string& user));
Hugo Benichi82ed5cf2020-09-08 21:30:22 +090047 MOCK_METHOD8(ConnectVethPair,
48 bool(pid_t pid,
49 const std::string& netns_name,
Hugo Benichi33860d72020-07-09 16:34:01 +090050 const std::string& veth_ifname,
Hugo Benichi82ed5cf2020-09-08 21:30:22 +090051 const std::string& peer_ifname,
52 const MacAddress& remote_mac_addr,
53 uint32_t remote_ipv4_addr,
54 uint32_t remote_ipv4_prefix_len,
55 bool remote_multicast_flag));
Garrick Evans54861622019-07-19 09:05:09 +090056 MOCK_METHOD1(RemoveInterface, void(const std::string& ifname));
Hugo Benichi93306e52020-12-04 16:08:00 +090057 MOCK_METHOD5(StartRoutingDevice,
Hugo Benichi8d622b52020-08-13 15:24:12 +090058 void(const std::string& ext_ifname,
59 const std::string& int_ifname,
60 uint32_t int_ipv4_addr,
Hugo Benichi93306e52020-12-04 16:08:00 +090061 TrafficSource source,
62 bool route_on_vpn));
63 MOCK_METHOD5(StopRoutingDevice,
Hugo Benichi8d622b52020-08-13 15:24:12 +090064 void(const std::string& ext_ifname,
65 const std::string& int_ifname,
66 uint32_t int_ipv4_addr,
Hugo Benichi93306e52020-12-04 16:08:00 +090067 TrafficSource source,
68 bool route_on_vpn));
Garrick Evans664a82f2019-12-17 12:18:05 +090069 MOCK_METHOD3(MaskInterfaceFlags,
70 bool(const std::string& ifname, uint16_t on, uint16_t off));
Taoyu Li90c13912019-11-26 17:56:54 +090071 MOCK_METHOD2(AddIPv6Forwarding,
72 bool(const std::string& ifname1, const std::string& ifname2));
73 MOCK_METHOD2(RemoveIPv6Forwarding,
74 void(const std::string& ifname1, const std::string& ifname2));
Garrick Evans3d97a392020-02-21 15:24:37 +090075 MOCK_METHOD3(AddIPv4Route, bool(uint32_t gw, uint32_t dst, uint32_t netmask));
Garrick Evansf0ab7132019-06-18 14:50:42 +090076};
77
Garrick Evans3388a032020-03-24 11:25:55 +090078} // namespace patchpanel
Garrick Evansf0ab7132019-06-18 14:50:42 +090079
Garrick Evans3388a032020-03-24 11:25:55 +090080#endif // PATCHPANEL_MOCK_DATAPATH_H_