4#include "Stroika/Frameworks/StroikaPreComp.h"
10#include "Stroika/Foundation/Containers/Collection.h"
13#include "Stroika/Foundation/IO/Network/Listener.h"
18#include "Traceroute.h"
23using namespace Stroika::Foundation::Debug;
25using namespace Stroika::Foundation::Memory;
26using namespace Stroika::Foundation::IO;
28using namespace Stroika::Foundation::IO::Network::InternetProtocol;
29using namespace Stroika::Foundation::Traversal;
31using namespace Stroika::Frameworks;
32using namespace Stroika::Frameworks::NetworkMonitor;
47 sb <<
"Interval: "sv << fInterval;
48 sb <<
", Count: "sv << fSampleCount;
58String Traceroute::Options::ToString ()
const
63 sb <<
"Max-Hops: "sv << *fMaxHops;
66 sb <<
", Timeout: "sv << *fTimeout;
68 if (fPacketPayloadSize) {
69 sb <<
", Packet-Payload-Size: "sv << *fPacketPayloadSize;
72 sb <<
", Sample: "sv << *fSampleInfo;
83String Hop::ToString ()
const
87 sb <<
"Time: "sv << fTime;
88 sb <<
", Address: "sv << fAddress;
101 Run (addr, [&results] (
const Hop& h) { results += h; }, options);
105void NetworkMonitor::Traceroute::Run (
const InternetAddress& addr, function<
void (Hop)> perHopCallback,
const Options& options)
108 unsigned int maxTTL = options.fMaxHops.value_or (Options::kDefaultMaxHops);
110 Ping::Options pingOptions{};
111 pingOptions.fPacketPayloadSize = options.fPacketPayloadSize;
114 for (
unsigned int ttl = 1; ttl <= maxTTL; ++ttl) {
116 if (options.fSampleInfo) {
117 pingOptions.fSampleInfo = Ping::Options::SampleInfo{options.fSampleInfo->fInterval, options.fSampleInfo->fSampleCount};
122 Ping::Pinger::ResultType r = pinger.RunOnce (ttl);
123 perHopCallback (Hop{r.fPingTime, addr});
127#if USE_NOISY_TRACE_IN_THIS_MODULE_
128 DbgTrace (
"exception {} - ipaddr = {}"_f, ttlExpiredException, ttlExpiredException.GetReachedIP ());
131 perHopCallback (Hop{
Duration{Time::GetTickCount () - startOfPingRequest}, ttlExpiredException.GetUnreachedIP ()});
134#if USE_NOISY_TRACE_IN_THIS_MODULE_
135 DbgTrace (
"exception {} - ipaddr = {}"_f, destinationUnreachableException, destinationUnreachableException.GetReachedIP ());
138 perHopCallback (Hop{
Duration{Time::GetTickCount () - startOfPingRequest}, destinationUnreachableException.GetUnreachedIP ()});
141#if USE_NOISY_TRACE_IN_THIS_MODULE_
142 DbgTrace (L
"exception {}"_f, current_exception ());
144 perHopCallback (Hop{});
Results< FLOAT_TYPE > Run(const TargetFunction< FLOAT_TYPE > &function2Minimize, const Sequence< FLOAT_TYPE > &initialValues, const Options< FLOAT_TYPE > &options=Options< FLOAT_TYPE >{})
Downhill Simplex Minimization, AKA Nelder-Mead algorithm, to compute minimization.
time_point< RealtimeClock, DurationSeconds > TimePointSeconds
TimePointSeconds is a simpler approach to chrono::time_point, which doesn't require using templates e...
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
String is like std::u32string, except it is much easier to use, often much more space efficient,...
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Duration is a chrono::duration<double> (=.