MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
FabricAddress.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#pragma once
6
7#include <cstdint>
8#include <string>
9#include <variant>
10#include <netinet/in.h>
11#include "FabricInfo.hpp"
12#include "Provider.hpp"
13
15{
16 enum class FabricAddressFormat : std::uint32_t
17 {
18 Unspec = static_cast<std::uint32_t>(FI_ADDR_UNSPEC), // Unspecified
19 Sockaddr = FI_SOCKADDR, // Any socket address, including infiniband
20 SockaddrIp = FI_SOCKADDR_IP, // Any socket address, but infiniband is not valid
21 SockaddrIn = FI_SOCKADDR_IN, // AF_INET socket address
22 SockaddrIn6 = FI_SOCKADDR_IN6, // AF_INET6 socket address
23 SockaddrIb = FI_SOCKADDR_IB, // AF_IB socket address
24 Efa = FI_ADDR_EFA, // EFA specific proprietary address format
25 String = FI_ADDR_STR, // String address in the form of scheme://addr, example: fi_ns://<node>:<service>
26 };
27
30 [[nodiscard]]
31 FabricAddressFormat convertAddressFormat(std::uint32_t fiAddrFormat);
32
36 [[nodiscard]]
37 FabricAddressFormat mustConvertAddressFormat(std::uint32_t fiAddrFormat);
38
46 {
47 unsigned short sib_family; // AF_IB
48 std::uint16_t sib_pkey;
49 std::uint32_t sib_flowinfo;
50 std::uint8_t sib_addr[16];
51 std::uint64_t sib_sid;
52 std::uint64_t sib_sid_mask;
53 std::uint64_t sib_scope_id;
54 };
55
62 {
63 std::uint8_t gid[16];
64 std::uint16_t qpn;
65 std::uint32_t qkey;
66 };
67
77 {
78 public:
79 using Native = std::variant<std::monostate, // unknown / null / unsupported
80 ::sockaddr_in, // FI_SOCKADDR_IN, FI_SOCKADDR(_IP) with AF_INET
81 ::sockaddr_in6, // FI_SOCKADDR_IN6, FI_SOCKADDR(_IP) with AF_INET6
82 OfiSockaddrIb, // FI_SOCKADDR_IB
83 EfaAddress, // FI_ADDR_EFA
84 std::string>; // FI_ADDR_STR
85
87 [[nodiscard]]
88 static FabricAddress fromSource(FabricInfoView info) noexcept;
89
91 [[nodiscard]]
92 static FabricAddress fromDestination(FabricInfoView info) noexcept;
93
100 [[nodiscard]]
101 static FabricAddress decode(FabricAddressFormat addrFormat, void const* addr, std::size_t len);
102
103 FabricAddress() noexcept;
104
106 [[nodiscard]]
107 Native const& native() const noexcept
108 {
109 return _native;
110 }
111
113 [[nodiscard]]
114 bool empty() const noexcept
115 {
116 return std::holds_alternative<std::monostate>(_native);
117 }
118
124 [[nodiscard]]
125 std::string toString() const;
126
133 [[nodiscard]]
134 std::optional<std::string> node() const;
135
137 [[nodiscard]]
138 std::optional<std::string> service() const;
139
141 [[nodiscard]]
142 FabricAddressFormat addressFormat() const noexcept;
143
145 [[nodiscard]]
146 static FabricAddress parse(Provider provider, std::optional<std::string> node, std::optional<std::string> service);
147
148 private:
149 explicit FabricAddress(Native native) noexcept;
150
151 private:
153 };
154}
Owning, type-safe representation of a libfabric address.
static FabricAddress parse(Provider provider, std::optional< std::string > node, std::optional< std::string > service)
Parse a node/service pair into a typed address for the given provider.
bool empty() const noexcept
True if the address could not be decoded (holds std::monostate).
Native const & native() const noexcept
Access the underlying variant.
std::optional< std::string > node() const
Return the host portion of the address as a string.
FabricAddressFormat addressFormat() const noexcept
Return the libfabric address format constant (FI_SOCKADDR_IN, etc.).
static FabricAddress fromSource(FabricInfoView info) noexcept
Build a FabricAddress from the source address of info.
static FabricAddress decode(FabricAddressFormat addrFormat, void const *addr, std::size_t len)
Decode a raw libfabric address buffer of the given addr_format.
static FabricAddress fromDestination(FabricInfoView info) noexcept
Build a FabricAddress from the destination address of info.
std::optional< std::string > service() const
Return the service/port portion of the address as a string.
std::string toString() const
Format the address exactly as libfabric's internal ofi_straddr.
std::variant< std::monostate, ::sockaddr_in, ::sockaddr_in6, OfiSockaddrIb, EfaAddress, std::string > Native
Non-owning view of a FabricInfo. Returned when iterating over a FabricInfoList.
FabricAddressFormat convertAddressFormat(std::uint32_t fiAddrFormat)
Convert from libfabric address format value to FabricAddressFormat.
Provider
Internal representation of supported libfabric providers.
Definition Provider.hpp:17
FabricAddressFormat mustConvertAddressFormat(std::uint32_t fiAddrFormat)
Convert from libfabric address format value to FabricAddressFormat Never returns FabricAddressFormat:...
Decoded representation of an FI_ADDR_EFA address.
Local declaration of libfabric's internal struct ofi_sockaddr_ib.