2023-09-04 12:21:37 +02:00
|
|
|
/* Setup network emulation.
|
2017-12-20 11:23:55 +01:00
|
|
|
*
|
|
|
|
* We use the firewall mark to apply individual netem qdiscs
|
|
|
|
* per node. Every node uses an own BSD socket.
|
|
|
|
* By using so SO_MARK socket option (see socket(7))
|
|
|
|
* we can classify traffic originating from a node seperately.
|
|
|
|
*
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2017-12-20 11:23:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-06-23 16:57:00 +02:00
|
|
|
#include <cstdint>
|
2017-12-20 11:23:55 +01:00
|
|
|
|
|
|
|
#include <netlink/route/classifier.h>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <netlink/route/qdisc.h>
|
2017-12-20 11:23:55 +01:00
|
|
|
|
|
|
|
#include <jansson.h>
|
|
|
|
|
2020-09-13 11:01:20 +02:00
|
|
|
namespace villas {
|
|
|
|
namespace kernel {
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
class Interface;
|
2017-12-20 11:23:55 +01:00
|
|
|
|
2020-09-13 11:01:20 +02:00
|
|
|
namespace tc {
|
|
|
|
|
|
|
|
typedef uint32_t tc_hdl_t;
|
2017-12-20 11:23:55 +01:00
|
|
|
|
|
|
|
/* Parse network emulator (netem) settings.
|
|
|
|
*
|
2021-02-16 14:15:14 +01:00
|
|
|
* @param json A jansson object containing the settings.
|
2017-12-20 11:23:55 +01:00
|
|
|
* @param[out] ne A pointer to a libnl3 qdisc object where setting will be written to.
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2021-02-16 14:15:14 +01:00
|
|
|
int netem_parse(struct rtnl_qdisc **ne, json_t *json);
|
2017-12-20 11:23:55 +01:00
|
|
|
|
|
|
|
/* Print network emulator (netem) setting into buffer.
|
|
|
|
*
|
|
|
|
* @param tc A pointer to the libnl3 qdisc object where settings will be read from.
|
|
|
|
* @return A pointer to a string which must be freed() by the caller.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
char *netem_print(struct rtnl_qdisc *ne);
|
2017-12-20 11:23:55 +01:00
|
|
|
|
|
|
|
/* Add a new network emulator (netem) discipline.
|
|
|
|
*
|
|
|
|
* @param i[in] The interface to which this qdisc will be added.
|
|
|
|
* @param qd[in,out] The libnl3 object of the new prio qdisc.
|
|
|
|
* @param handle[in] The handle of the new qdisc.
|
|
|
|
* @param parent[in] Make this qdisc a child of this class
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
int netem(Interface *i, struct rtnl_qdisc **qd, tc_hdl_t handle,
|
|
|
|
tc_hdl_t parent);
|
2020-09-13 11:01:20 +02:00
|
|
|
|
|
|
|
int netem_set_delay_distribution(struct rtnl_qdisc *qdisc, json_t *json);
|
2017-12-20 11:23:55 +01:00
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace tc
|
|
|
|
} // namespace kernel
|
|
|
|
} // namespace villas
|