summaryrefslogtreecommitdiffstats
path: root/src/bin/perfdhcp/avalanche_scen.h
blob: b745efe69cfb8197f581c1c032e4ff3c8b612dc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (C) 2012-2019,2021 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef AVALANCHE_SCEN_H
#define AVALANCHE_SCEN_H

#include <config.h>

#include <perfdhcp/abstract_scen.h>


namespace isc {
namespace perfdhcp {

// This class fixes an issue in older compilers
// that cannot handle enum class as key in std::unordered_map.
// See: https://stackoverflow.com/questions/18837857/cant-use-enum-class-as-unordered-map-key
struct EnumClassHash
{
    template <typename T>
    std::size_t operator()(T t) const
    {
        return static_cast<std::size_t>(t);
    }
};

/// \brief Avalanche Scenario class.
///
/// This class is used to run the performance test where DHCP server
/// is first loaded with indicated buffer of Discover or Solicit messages
/// and then the class is waiting till receiving all required responses.
/// Full DORA and SARR message sequences are expected.
class AvalancheScen : public AbstractScen {
public:
    /// \brief Default and the only constructor of AvalancheScen.
    ///
    /// \param options reference to command options,
    /// \param socket reference to a socket.
    AvalancheScen(CommandOptions& options, BasePerfSocket &socket):
        AbstractScen(options, socket),
        socket_(socket),
        total_resent_(0) {};

    /// brief\ Run performance test.
    ///
    /// Method runs whole performance test.
    ///
    /// \return execution status.
    int run() override;

protected:

    // A reference to socket;
    BasePerfSocket &socket_;

    /// A map xchg type -> (a map of trans id -> retransmissions count.
    std::unordered_map<ExchangeType, std::unordered_map<uint32_t, int>, EnumClassHash> retransmissions_;
    /// A map xchg type -> (a map of trans id -> time of sending first packet.
    std::unordered_map<ExchangeType, std::unordered_map<uint32_t, boost::posix_time::ptime>, EnumClassHash> start_times_;

    /// Total number of resent packets.
    int total_resent_;

    /// \\brief Resend packets.
    ///
    /// It resends packets for given exchange type that did not receive
    /// a response yet.
    ///
    /// \param xchg_type exchange type that should be looked for.
    /// \return number of packets still waiting for resending.
    int resendPackets(ExchangeType xchg_type);

};

}
}

#endif // AVALANCHE_SCEN_H