2023-09-04 12:21:37 +02:00
|
|
|
/* Interface related functions.
|
2020-09-13 11:01:20 +02:00
|
|
|
*
|
|
|
|
* These functions are used to manage a network interface.
|
|
|
|
* Most of them make use of Linux-specific APIs.
|
|
|
|
*
|
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
|
2020-09-13 11:01:20 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <sys/types.h>
|
2020-09-13 11:01:20 +02:00
|
|
|
|
|
|
|
#include <villas/log.hpp>
|
|
|
|
|
|
|
|
#ifndef SO_MARK
|
2023-09-07 11:46:39 +02:00
|
|
|
#define SO_MARK \
|
|
|
|
36 // Workaround: add missing constant for OPAL-RT Redhawk target
|
2020-09-13 11:01:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
struct nl_addr;
|
|
|
|
struct rtnl_link;
|
|
|
|
struct rtnl_qdisc;
|
|
|
|
|
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
|
|
|
// Forward declarations
|
2021-08-10 10:12:48 -04:00
|
|
|
class Node;
|
2020-09-13 11:01:20 +02:00
|
|
|
class SuperNode;
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
} // namespace node
|
2020-09-13 11:01:20 +02:00
|
|
|
|
|
|
|
namespace kernel {
|
|
|
|
|
|
|
|
// Interface data structure
|
|
|
|
class Interface {
|
|
|
|
|
|
|
|
public:
|
2023-09-07 11:46:39 +02:00
|
|
|
struct rtnl_link *nl_link; // libnl3: Handle of interface.
|
|
|
|
struct rtnl_qdisc
|
|
|
|
*tc_qdisc; // libnl3: Root priority queuing discipline (qdisc).
|
2020-09-13 11:01:20 +02:00
|
|
|
|
|
|
|
protected:
|
2023-09-07 11:46:39 +02:00
|
|
|
int affinity; // IRQ / Core Affinity of this interface.
|
2020-09-13 11:01:20 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
std::list<int> irqs; // List of IRQs of the NIC.
|
|
|
|
std::list<node::Node *> nodes; // List of nodes which use this interface.
|
2020-09-13 11:01:20 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
Logger logger;
|
2020-09-13 11:01:20 +02:00
|
|
|
|
|
|
|
public:
|
2023-09-07 11:46:39 +02:00
|
|
|
// Add a new interface to the global list and lookup name, irqs...
|
|
|
|
Interface(struct rtnl_link *link, int affinity = 0);
|
|
|
|
~Interface();
|
2020-09-13 11:01:20 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Start interface.
|
2024-02-29 21:47:13 +01:00
|
|
|
*
|
|
|
|
* This setups traffic controls queue discs, network emulation and
|
|
|
|
* maps interface IRQs according to affinity.
|
|
|
|
*
|
|
|
|
* @param i A pointer to the interface structure.
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
int start();
|
2020-09-13 11:01:20 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Stop interface
|
2024-02-29 21:47:13 +01:00
|
|
|
*
|
|
|
|
* This resets traffic qdiscs ant network emulation
|
|
|
|
* and maps interface IRQs to all CPUs.
|
|
|
|
*
|
|
|
|
* @param i A pointer to the interface structure.
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
int stop();
|
2020-09-13 11:01:20 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Find existing or create new interface instance on which packets for a certain destination
|
2024-02-29 21:47:13 +01:00
|
|
|
* will leave the system.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
static Interface *getEgress(struct sockaddr *sa, node::SuperNode *sn);
|
2020-09-13 11:01:20 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Get all IRQs for this interface.
|
2024-02-29 21:47:13 +01:00
|
|
|
*
|
|
|
|
* Only MSI IRQs are determined by looking at:
|
|
|
|
* /sys/class/net/{ifname}/device/msi_irqs/
|
|
|
|
*
|
|
|
|
* @param i A pointer to the interface structure
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
int getIRQs();
|
2020-09-13 11:01:20 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
/* Change the SMP affinity of NIC interrupts.
|
2024-02-29 21:47:13 +01:00
|
|
|
*
|
|
|
|
* @param i A pointer to the interface structure
|
|
|
|
* @param affinity A mask specifying which cores should handle this interrupt.
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2023-09-07 11:46:39 +02:00
|
|
|
int setAffinity(int affinity);
|
2020-09-13 11:01:20 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
std::string getName() const;
|
2020-09-13 11:01:20 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void addNode(node::Node *n) { nodes.push_back(n); }
|
2020-09-13 11:01:20 +02:00
|
|
|
};
|
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace kernel
|
|
|
|
} // namespace villas
|