JaiaBot 3.0.0
JaiaBot micro-AUV software
Loading...
Searching...
No Matches
ip.h
Go to the documentation of this file.
1// Copyright 2025:
2// JaiaRobotics LLC
3// File authors:
4// Toby Schneider <toby@gobysoft.org>
5//
6//
7// This file is part of the JaiaBot Project Binaries
8// ("The Jaia Binaries").
9//
10// The Jaia Binaries are free software: you can redistribute them and/or modify
11// them under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 2 of the License, or
13// (at your option) any later version.
14//
15// The Jaia Binaries are distributed in the hope that they will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with the Jaia Binaries. If not, see <http://www.gnu.org/licenses/>.
22
23#ifndef JAIABOT_UTILS_IP_H
24#define JAIABOT_UTILS_IP_H
25
26#include <climits>
27#include <cstdlib>
28#include <stdexcept>
29#include <string>
30#include <utility>
31
32#include <unistd.h>
33
34#include <boost/asio/ip/address_v4.hpp>
35#include <boost/asio/ip/address_v6.hpp>
36#include <boost/system/error_code.hpp>
37
38namespace jaiabot
39{
40namespace ip
41{
42
43// Node types - limited by IPv4 addresses and definitions in jaiabot/src/lib/comms/comms.h
52
53// Network types
65
66// IP versions a network can be addressed with
67enum class IPVersion
68{
71};
72
73// Node ID valid ranges
74constexpr int bot_id_min = 0, bot_id_max = 150;
75constexpr int hub_id_min = 0, hub_id_max = 30;
76constexpr int desktop_id_min = 1, desktop_id_max = 9;
77constexpr int gateway_id_min = 0, gateway_id_max = 0;
78constexpr int rpicam_id_min = 0, rpicam_id_max = 49;
79constexpr int fleet_id_min = 0, fleet_id_max = 4000;
80
81// The fleet WLAN and fleet VPN carry the fleet id in a single IPv4 octet, which is why fleets
82// above this are addressed with IPv6 on every network. 10.23.254.0/24 and 10.23.255.0/24 are the
83// VirtualFleet and CloudHub subnets of a VPC, so the octet runs out a little before 255 does.
84constexpr int fleet_id_ipv4_max = 250;
85static_assert(fleet_id_ipv4_max <= fleet_id_max, "IPv4 fleets must be a subset of all fleets");
86
87// A VirtualFleet mirrors its fleet's WLAN addressing, which a fleet above fleet_id_ipv4_max cannot
88// do: its nodes are EC2 instances, and EC2 assigns IPv6 from the block Amazon gives the VPC rather
89// than from a ULA of ours. Those VirtualFleets stay IPv4 on this octet instead, which cannot
90// collide with anything because the network it belongs to is private to one fleet's VPC.
91constexpr int vfleet_wlan_ipv4_octet = 253;
93 "the VirtualFleet WLAN octet must not be one an IPv4 fleet uses");
94
95// The CloudHub is always this hub id, on every fleet
96constexpr int cloudhub_id = 30;
97static_assert(cloudhub_id >= hub_id_min && cloudhub_id <= hub_id_max,
98 "cloudhub_id must be a valid hub id");
99
100// iridium.jaia.tech, which relays every fleet's Iridium messages, is this hub id on each
101// fleet's CloudHub VPN; it is not one of the fleet's own hubs
102constexpr int iridium_id = 25;
104 "iridium_id must be a valid hub id other than the CloudHub's");
105
106inline std::string node_type_to_string(NodeType node)
107{
108 switch (node)
109 {
110 case NodeType::bot: return "bot";
111 case NodeType::hub: return "hub";
112 case NodeType::desktop: return "desktop";
113 case NodeType::gateway: return "gateway";
114 case NodeType::rpicam: return "rpicam";
115 }
116 throw std::invalid_argument("Unknown node type");
117}
118
119inline NodeType node_type_from_string(const std::string& s)
120{
121 if (s == "bot")
122 return NodeType::bot;
123 if (s == "hub")
124 return NodeType::hub;
125 if (s == "desktop")
126 return NodeType::desktop;
127 if (s == "gateway")
128 return NodeType::gateway;
129 if (s == "rpicam")
130 return NodeType::rpicam;
131 throw std::invalid_argument("Unknown node type: " + s);
132}
133
134inline std::string network_to_string(Network net)
135{
136 switch (net)
137 {
138 case Network::wlan: return "wlan";
139 case Network::fleet_vpn: return "fleet_vpn";
140 case Network::vfleet_vpn: return "vfleet_vpn";
141 case Network::cloudhub_vpn: return "cloudhub_vpn";
142 case Network::cloudhub_eth: return "cloudhub_eth";
143 case Network::vfleet_eth: return "vfleet_eth";
144 case Network::vfleet_wlan: return "vfleet_wlan";
145 case Network::vpc: return "vpc";
146 }
147 throw std::invalid_argument("Unknown network");
148}
149
150inline Network network_from_string(const std::string& s)
151{
152 if (s == "wlan")
153 return Network::wlan;
154 if (s == "fleet_vpn")
155 return Network::fleet_vpn;
156 if (s == "vfleet_vpn")
157 return Network::vfleet_vpn;
158 if (s == "cloudhub_vpn")
160 if (s == "cloudhub_eth")
162 if (s == "vfleet_eth")
163 return Network::vfleet_eth;
164 if (s == "vfleet_wlan")
166 if (s == "vpc")
167 return Network::vpc;
168 throw std::invalid_argument("Unknown network: " + s);
169}
170
171// Valid [min, max] node id range for a given node type
172inline std::pair<int, int> node_id_range(NodeType node)
173{
174 switch (node)
175 {
176 case NodeType::bot: return {bot_id_min, bot_id_max};
177 case NodeType::hub: return {hub_id_min, hub_id_max};
181 }
182 throw std::invalid_argument("Unknown node type");
183}
184
185inline void validate_fleet_id(int fleet_id)
186{
187 if (fleet_id < fleet_id_min || fleet_id > fleet_id_max)
188 throw std::invalid_argument("fleet_id " + std::to_string(fleet_id) +
189 " is not in range: " + std::to_string(fleet_id_min) + " to " +
190 std::to_string(fleet_id_max));
191}
192
193inline void validate_node_id(NodeType node, int node_id)
194{
195 auto range = node_id_range(node);
196 if (node_id < range.first || node_id > range.second)
197 throw std::invalid_argument("node_id " + std::to_string(node_id) + " for " +
198 node_type_to_string(node) +
199 " is not in range: " + std::to_string(range.first) + " to " +
200 std::to_string(range.second));
201}
202
203// True for fleets that keep the original IPv4 addressing on the fleet WLAN and fleet VPN
204inline bool is_ipv4_fleet(int fleet_id)
205{
206 validate_fleet_id(fleet_id);
207 return fleet_id <= fleet_id_ipv4_max;
208}
209
210// The IP version a given fleet is addressed with on a given network. The VirtualFleet and CloudHub
211// VPNs are IPv6 for every fleet; the VPC networks are dual stack, and IPv4 here because their IPv6
212// side is the block EC2 assigned to the VPC rather than anything derived from the fleet id.
213inline IPVersion ip_version(int fleet_id, Network net)
214{
215 switch (net)
216 {
217 case Network::wlan:
219
222
223 // the VirtualFleet WLAN stays IPv4 for every fleet: see vfleet_wlan_ipv4_octet
227 case Network::vpc: validate_fleet_id(fleet_id); return IPVersion::ipv4;
228 }
229 throw std::invalid_argument("Unknown network");
230}
231
232namespace detail
233{
234
235inline boost::asio::ip::address_v4 ipv4_base(int fleet_id, Network net)
236{
237 using namespace boost::asio::ip;
238
239 // without this a fleet that does not fit in the octet would silently alias onto another one
240 auto fleet_octet = [&]()
241 {
242 if (!is_ipv4_fleet(fleet_id))
243 throw std::invalid_argument("fleet_id " + std::to_string(fleet_id) + " has no IPv4 " +
244 network_to_string(net) + " address: fleets above " +
245 std::to_string(fleet_id_ipv4_max) + " are IPv6 only");
246 return static_cast<uint8_t>(fleet_id);
247 };
248
249 switch (net)
250 {
251 case Network::wlan:
252 // 10.23.{fleet_id}.0
253 return make_address_v4(address_v4::bytes_type{10, 23, fleet_octet(), 0});
255 // 10.23.{fleet_id}.0, or 10.23.253.0 for a fleet whose id does not fit the octet
256 return make_address_v4(address_v4::bytes_type{
257 10, 23,
258 is_ipv4_fleet(fleet_id) ? static_cast<uint8_t>(fleet_id)
259 : static_cast<uint8_t>(vfleet_wlan_ipv4_octet),
260 0});
262 // 172.23.{fleet_id}.0
263 return make_address_v4(address_v4::bytes_type{172, 23, fleet_octet(), 0});
265 // 10.23.255.0
266 return make_address_v4(address_v4::bytes_type{10, 23, 255, 0});
268 // 10.23.254.0
269 return make_address_v4(address_v4::bytes_type{10, 23, 254, 0});
270 case Network::vpc:
271 // 10.23.0.0
272 return make_address_v4(address_v4::bytes_type{10, 23, 0, 0});
273 default: throw std::invalid_argument("No IPv4 base for network: " + network_to_string(net));
274 }
275}
276
278{
279 switch (net)
280 {
281 case Network::wlan:
285 case Network::vfleet_wlan: return 24;
286 case Network::vpc: return 16;
287 default:
288 throw std::invalid_argument("No IPv4 prefix for network: " + network_to_string(net));
289 }
290}
291
292inline uint32_t ipv4_node_offset(NodeType node, int node_id)
293{
294 switch (node)
295 {
296 case NodeType::hub: return static_cast<uint32_t>(10 + node_id);
297 case NodeType::bot: return static_cast<uint32_t>(100 + node_id);
298 case NodeType::rpicam: return static_cast<uint32_t>(50 + node_id);
299 case NodeType::gateway: return 1; // node_id is ignored for gateway
301 throw std::invalid_argument("desktop node is not supported for ipv4");
302 }
303 throw std::invalid_argument("Unknown node type for IPv4");
304}
305
306// Add a 64-bit offset to an IPv6 address (full 128-bit arithmetic via carry)
307inline boost::asio::ip::address_v6 ipv6_add_offset(boost::asio::ip::address_v6 addr,
308 uint64_t offset)
309{
310 auto bytes = addr.to_bytes();
311 uint64_t carry = offset;
312 for (int i = 15; i >= 0 && carry > 0; --i)
313 {
314 uint64_t sum = static_cast<uint64_t>(bytes[i]) + (carry & 0xFF);
315 bytes[i] = static_cast<uint8_t>(sum & 0xFF);
316 carry = (carry >> 8) + (sum >> 8);
317 }
318 return boost::asio::ip::address_v6(bytes);
319}
320
321// Add offset*2^64 to an IPv6 address, that is, add offset to the upper 64 bits. Byte index 7 is
322// the least significant byte of the upper 64 bits.
323inline boost::asio::ip::address_v6 ipv6_add_subnet_offset(boost::asio::ip::address_v6 addr,
324 uint64_t offset)
325{
326 auto bytes = addr.to_bytes();
327 uint64_t carry = offset;
328 for (int i = 7; i >= 0 && carry > 0; --i)
329 {
330 uint64_t sum = static_cast<uint64_t>(bytes[i]) + (carry & 0xFF);
331 bytes[i] = static_cast<uint8_t>(sum & 0xFF);
332 carry = (carry >> 8) + (sum >> 8);
333 }
334 return boost::asio::ip::address_v6(bytes);
335}
336
337// Zero out the lower 64 bits (host portion of a /64 network)
338inline boost::asio::ip::address_v6 ipv6_mask64(boost::asio::ip::address_v6 addr)
339{
340 auto bytes = addr.to_bytes();
341 for (int i = 8; i < 16; ++i) bytes[i] = 0;
342 return boost::asio::ip::address_v6(bytes);
343}
344
345inline boost::asio::ip::address_v6 parse_ipv6(const std::string& s)
346{
347 // accept either a bare address ("2001:db8::") or a CIDR block ("2001:db8::/56"), in which
348 // case the network address (first address in the block) is used
349 std::string addr_str = s.substr(0, s.find('/'));
350 boost::system::error_code ec;
351 auto addr = boost::asio::ip::make_address_v6(addr_str, ec);
352 if (ec)
353 throw std::invalid_argument("Invalid IPv6 address: " + s + " (" + ec.message() + ")");
354 return addr;
355}
356
357// Build the IPv6 base address for a given network/fleet
358// ipv6_base_str is required only for cloudhub_eth, vfleet_eth, vfleet_wlan
359inline boost::asio::ip::address_v6 ipv6_base(int fleet_id, Network net,
360 const std::string& ipv6_base_str = "")
361{
362 auto make_prefix_addr = [&](const char* prefix)
363 {
364 // format fleet_id as lowercase hex without <sstream>, e.g. "fddd:7f2e:3258:" + "ff" + "::"
365 char hex[5];
366 int n = 0;
367 for (int shift = 12; shift >= 0; shift -= 4)
368 {
369 int nibble = (fleet_id >> shift) & 0xF;
370 if (nibble != 0 || n != 0)
371 hex[n++] = "0123456789abcdef"[nibble];
372 }
373 if (n == 0)
374 hex[n++] = '0';
375 hex[n] = '\0';
376 return parse_ipv6(std::string(prefix) + hex + "::");
377 };
378
379 auto get_base_from_arg = [&]()
380 {
381 if (ipv6_base_str.empty())
382 throw std::invalid_argument("--ipv6_base is required for network: " +
383 network_to_string(net));
384 return parse_ipv6(ipv6_base_str);
385 };
386
387 switch (net)
388 {
389 case Network::wlan: return make_prefix_addr("fddd:7f2e:3258:");
390 case Network::fleet_vpn: return make_prefix_addr("fd91:5457:1e5c:");
391 case Network::vfleet_vpn: return make_prefix_addr("fd6e:cf0d:aefa:");
392 case Network::cloudhub_vpn: return make_prefix_addr("fd0f:77ac:4fdf:");
393
395 // ipv6_base + 0*2^64 = no shift
396 return get_base_from_arg();
397
399 // ipv6_base + 1*2^64
400 return ipv6_add_subnet_offset(get_base_from_arg(), 1);
401
403 // ipv6_base + 2*2^64
404 return ipv6_add_subnet_offset(get_base_from_arg(), 2);
405
406 default: throw std::invalid_argument("No IPv6 base for network: " + network_to_string(net));
407 }
408}
409
410// Group 0 is reserved: it holds the subnet-router anycast address (::) and ::1, which routers on
411// the segment conventionally claim -- a node given either one fails DAD and is unreachable.
412inline uint64_t ipv6_node_offset(NodeType node, int node_id)
413{
414 switch (node)
415 {
416 case NodeType::hub: return static_cast<uint64_t>(1 * 65536 + node_id); // 1*2^16 + node_id
417 case NodeType::bot: return static_cast<uint64_t>(2 * 65536 + node_id); // 2*2^16 + node_id
419 return static_cast<uint64_t>(3 * 65536 + node_id); // 3*2^16 + node_id
420 case NodeType::rpicam:
421 return static_cast<uint64_t>(4 * 65536 + node_id); // 4*2^16 + node_id
422 case NodeType::gateway: return 5 * 65536; // node_id ignored
423 }
424 throw std::invalid_argument("Unknown node type for IPv6");
425}
426
427// Reads a run of one or more decimal digits from s starting at pos, advancing pos. Returns false
428// if there are no digits or if the value would exceed max_value (which keeps the accumulation
429// well within the range of int).
430inline bool read_digits(const std::string& s, std::size_t& pos, int& out, int max_value = 1000000)
431{
432 std::size_t start = pos;
433 int value = 0;
434 while (pos < s.size() && s[pos] >= '0' && s[pos] <= '9')
435 {
436 value = value * 10 + (s[pos] - '0');
437 if (value > max_value)
438 return false;
439 ++pos;
440 }
441 if (pos == start)
442 return false;
443 out = value;
444 return true;
445}
446
447// Fleet ID of the machine this is running on, for host codes given without an
448// 'fN' suffix (e.g. "b4"). 'jaia_fleet_id' is set in the generated systemd
449// units and, for login shells, by /etc/profile.d/jaia.sh. The hostname is the
450// fallback where neither applies (cron, 'ssh host command'); postinst sets it
451// from the same debconf answers as "<type><id>-fleet<fleet_id>".
452inline int local_fleet_id()
453{
454 const char* env_fleet_id = std::getenv("jaia_fleet_id");
455 if (env_fleet_id != nullptr && *env_fleet_id != '\0')
456 {
457 std::string env_str(env_fleet_id);
458 std::size_t env_pos = 0;
459 int env_value = 0;
460 if (!read_digits(env_str, env_pos, env_value) || env_pos != env_str.size())
461 throw std::invalid_argument("Invalid 'jaia_fleet_id' environmental variable: " +
462 env_str);
463 return env_value;
464 }
465
466 char hostname[HOST_NAME_MAX + 1] = {0};
467 if (gethostname(hostname, sizeof(hostname) - 1) == 0)
468 {
469 std::string host(hostname);
470 const std::string marker("-fleet");
471 std::size_t marker_pos = host.find(marker);
472 if (marker_pos != std::string::npos)
473 {
474 std::size_t host_pos = marker_pos + marker.size();
475 int host_value = 0;
476 if (read_digits(host, host_pos, host_value) && host_pos == host.size())
477 return host_value;
478 }
479 }
480
481 throw std::invalid_argument(
482 "Could not find fleet ID. Either specify as 'fN' suffix (e.g., b1f3), or provide via the "
483 "'jaia_fleet_id' environmental variable (set for login shells by /etc/profile.d/jaia.sh), "
484 "or run on a host named '<type><id>-fleet<fleet_id>'");
485}
486
487} // namespace detail
488
489// Returns IPv4 address string for a node (e.g. "10.23.1.110" for bot 10 on fleet 1 wlan)
490inline std::string ipv4_addr(int fleet_id, Network net, NodeType node, int node_id)
491{
492 validate_fleet_id(fleet_id);
493 validate_node_id(node, node_id);
494 auto base = detail::ipv4_base(fleet_id, net);
495 uint32_t offset = detail::ipv4_node_offset(node, node_id);
496 auto result = boost::asio::ip::make_address_v4(base.to_uint() + offset);
497 return result.to_string();
498}
499
500// Returns IPv4 network CIDR string (e.g. "10.23.1.0/24")
501inline std::string ipv4_net(int fleet_id, Network net)
502{
503 validate_fleet_id(fleet_id);
504 auto base = detail::ipv4_base(fleet_id, net);
505 int prefix = detail::ipv4_prefix_len(net);
506 return base.to_string() + "/" + std::to_string(prefix);
507}
508
509// Returns IPv6 address string for a node
510// ipv6_base_str is required for cloudhub_eth, vfleet_eth, vfleet_wlan networks
511inline std::string ipv6_addr(int fleet_id, Network net, NodeType node, int node_id,
512 const std::string& ipv6_base_str = "")
513{
514 validate_fleet_id(fleet_id);
515 validate_node_id(node, node_id);
516 auto base = detail::ipv6_base(fleet_id, net, ipv6_base_str);
517 uint64_t offset = detail::ipv6_node_offset(node, node_id);
518 auto result = detail::ipv6_add_offset(base, offset);
519 return result.to_string();
520}
521
522// Returns IPv6 network CIDR string (e.g. "fddd:7f2e:3258:1::/64")
523inline std::string ipv6_net(int fleet_id, Network net, const std::string& ipv6_base_str = "")
524{
525 validate_fleet_id(fleet_id);
526 auto base = detail::ipv6_mask64(detail::ipv6_base(fleet_id, net, ipv6_base_str));
527 return base.to_string() + "/64";
528}
529
530// Returns the address for a node in whichever IP version the fleet uses on the given network
531inline std::string addr(int fleet_id, Network net, NodeType node, int node_id)
532{
533 if (ip_version(fleet_id, net) == IPVersion::ipv4)
534 return ipv4_addr(fleet_id, net, node, node_id);
535 else
536 return ipv6_addr(fleet_id, net, node, node_id);
537}
538
539constexpr const char* host_code_format_msg =
540 "It must be b<bot_id>[svc]f<fleet_id> or h<hub_id>[svc]f<fleet_id> or chf<fleet_id> "
541 "(for cloudhub)";
542
543// Result of parsing a host shorthand code (e.g. "b4f2", "h1cf3", "chf4")
545{
546 // if true, the host code is not a Jaia shorthand and 'literal' should be used as-is
547 bool is_literal{false};
548 std::string literal;
549
551 int node_id{0};
552 int fleet_id{0};
554};
555
556// Parses a host shorthand code without using std::regex (which is comparatively expensive to
557// construct). Codes without an 'fN' suffix use default_fleet_id, or the local fleet ID if that is
558// negative. Throws std::invalid_argument on malformed input.
559inline HostCode parse_host_code(const std::string& host_code, int default_fleet_id = -1)
560{
561 HostCode result;
562
563 if (host_code == "self")
564 {
565 result.is_literal = true;
566 result.literal = "::1";
567 return result;
568 }
569
570 // pass through anything ending in .jaia.tech
571 const std::string jaia_tech_domain = ".jaia.tech";
572 if (host_code.size() > jaia_tech_domain.size() &&
573 host_code.compare(host_code.size() - jaia_tech_domain.size(), jaia_tech_domain.size(),
574 jaia_tech_domain) == 0)
575 {
576 result.is_literal = true;
577 result.literal = host_code;
578 return result;
579 }
580
581 auto invalid = [&]()
582 {
583 return std::invalid_argument("Host string is invalid: " + host_code + ". " +
584 std::string(host_code_format_msg));
585 };
586
587 auto read_int = [&](std::size_t& pos, int& out)
588 {
589 if (!detail::read_digits(host_code, pos, out))
590 throw invalid();
591 return true;
592 };
593
594 if (host_code.empty())
595 throw invalid();
596
597 std::size_t pos = 0;
598
599 if (host_code.compare(0, 2, "ch") == 0)
600 {
601 // chf<fleet_id>: the CloudHub, always over the cloudhub VPN
602 result.node_type = NodeType::hub;
603 result.node_id = cloudhub_id;
604 result.net = Network::cloudhub_vpn;
605 pos = 2;
606 }
607 else if (host_code[0] == 'b' || host_code[0] == 'h')
608 {
609 result.node_type = host_code[0] == 'b' ? NodeType::bot : NodeType::hub;
610 pos = 1;
611 if (!read_int(pos, result.node_id))
612 throw invalid();
613
614 if (pos < host_code.size())
615 {
616 switch (host_code[pos])
617 {
618 case 's':
619 result.net = Network::fleet_vpn;
620 ++pos;
621 break;
622 case 'v':
623 result.net = Network::vfleet_vpn;
624 ++pos;
625 break;
626 case 'c':
627 result.net = Network::cloudhub_vpn;
628 ++pos;
629 break;
630 default: break;
631 }
632 }
633 }
634 else
635 {
636 throw invalid();
637 }
638
639 bool have_fleet_id = false;
640 if (pos < host_code.size())
641 {
642 if (host_code[pos] != 'f')
643 throw invalid();
644 ++pos;
645 if (!read_int(pos, result.fleet_id))
646 throw invalid();
647 have_fleet_id = true;
648 }
649
650 if (pos != host_code.size())
651 throw invalid();
652
653 if (!have_fleet_id)
654 result.fleet_id = default_fleet_id >= 0 ? default_fleet_id : detail::local_fleet_id();
655
656 return result;
657}
658
659// Returns the IP address for a parsed host code in the given IP version, which the fleet need not
660// be the one that uses on that network (e.g. the IPv6 address of an IPv4 fleet)
661inline std::string host_code_addr(const HostCode& host, IPVersion version)
662{
663 if (host.is_literal)
664 return host.literal;
665
666 if (version == IPVersion::ipv4)
667 return ipv4_addr(host.fleet_id, host.net, host.node_type, host.node_id);
668 else
669 return ipv6_addr(host.fleet_id, host.net, host.node_type, host.node_id);
670}
671
672// Returns the IP address for a parsed host code, in whichever IP version the fleet uses on the
673// network the code names
674inline std::string host_code_addr(const HostCode& host)
675{
676 if (host.is_literal)
677 return host.literal;
678
679 return addr(host.fleet_id, host.net, host.node_type, host.node_id);
680}
681
682// Returns the IP address for a host shorthand code (e.g. "b4f2" -> "10.23.2.104")
683inline std::string host_code_to_addr(const std::string& host_code, HostCode* parsed = nullptr)
684{
685 HostCode host = parse_host_code(host_code);
686 if (parsed != nullptr)
687 *parsed = host;
688
689 return host_code_addr(host);
690}
691
692} // namespace ip
693} // namespace jaiabot
694
695#endif
bool read_digits(const std::string &s, std::size_t &pos, int &out, int max_value=1000000)
Definition ip.h:430
boost::asio::ip::address_v6 ipv6_base(int fleet_id, Network net, const std::string &ipv6_base_str="")
Definition ip.h:359
int ipv4_prefix_len(Network net)
Definition ip.h:277
boost::asio::ip::address_v6 ipv6_add_subnet_offset(boost::asio::ip::address_v6 addr, uint64_t offset)
Definition ip.h:323
int local_fleet_id()
Definition ip.h:452
uint64_t ipv6_node_offset(NodeType node, int node_id)
Definition ip.h:412
boost::asio::ip::address_v6 ipv6_add_offset(boost::asio::ip::address_v6 addr, uint64_t offset)
Definition ip.h:307
boost::asio::ip::address_v4 ipv4_base(int fleet_id, Network net)
Definition ip.h:235
uint32_t ipv4_node_offset(NodeType node, int node_id)
Definition ip.h:292
boost::asio::ip::address_v6 ipv6_mask64(boost::asio::ip::address_v6 addr)
Definition ip.h:338
boost::asio::ip::address_v6 parse_ipv6(const std::string &s)
Definition ip.h:345
std::string addr(int fleet_id, Network net, NodeType node, int node_id)
Definition ip.h:531
constexpr int iridium_id
Definition ip.h:102
constexpr int rpicam_id_max
Definition ip.h:78
constexpr int desktop_id_max
Definition ip.h:76
std::string host_code_to_addr(const std::string &host_code, HostCode *parsed=nullptr)
Definition ip.h:683
Network
Definition ip.h:55
void validate_fleet_id(int fleet_id)
Definition ip.h:185
std::string ipv4_addr(int fleet_id, Network net, NodeType node, int node_id)
Definition ip.h:490
void validate_node_id(NodeType node, int node_id)
Definition ip.h:193
std::pair< int, int > node_id_range(NodeType node)
Definition ip.h:172
NodeType
Definition ip.h:45
constexpr int fleet_id_ipv4_max
Definition ip.h:84
bool is_ipv4_fleet(int fleet_id)
Definition ip.h:204
IPVersion ip_version(int fleet_id, Network net)
Definition ip.h:213
constexpr int vfleet_wlan_ipv4_octet
Definition ip.h:91
NodeType node_type_from_string(const std::string &s)
Definition ip.h:119
std::string node_type_to_string(NodeType node)
Definition ip.h:106
std::string network_to_string(Network net)
Definition ip.h:134
constexpr const char * host_code_format_msg
Definition ip.h:539
Network network_from_string(const std::string &s)
Definition ip.h:150
constexpr int rpicam_id_min
Definition ip.h:78
HostCode parse_host_code(const std::string &host_code, int default_fleet_id=-1)
Definition ip.h:559
constexpr int cloudhub_id
Definition ip.h:96
std::string host_code_addr(const HostCode &host, IPVersion version)
Definition ip.h:661
constexpr int gateway_id_min
Definition ip.h:77
constexpr int bot_id_min
Definition ip.h:74
constexpr int desktop_id_min
Definition ip.h:76
constexpr int fleet_id_min
Definition ip.h:79
constexpr int hub_id_min
Definition ip.h:75
std::string ipv4_net(int fleet_id, Network net)
Definition ip.h:501
constexpr int bot_id_max
Definition ip.h:74
IPVersion
Definition ip.h:68
std::string ipv6_addr(int fleet_id, Network net, NodeType node, int node_id, const std::string &ipv6_base_str="")
Definition ip.h:511
constexpr int fleet_id_max
Definition ip.h:79
constexpr int hub_id_max
Definition ip.h:75
constexpr int gateway_id_max
Definition ip.h:77
std::string ipv6_net(int fleet_id, Network net, const std::string &ipv6_base_str="")
Definition ip.h:523
std::string literal
Definition ip.h:548
NodeType node_type
Definition ip.h:550