summaryrefslogtreecommitdiffstats
path: root/src/lib/yang/adaptor_subnet.h
blob: f357eb9c707d3c090bbf266f1682e9548090c48f (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
// Copyright (C) 2018-2022 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 ISC_ADAPTOR_SUBNET_H
#define ISC_ADAPTOR_SUBNET_H 1

#include <dhcpsrv/subnet_id.h>
#include <yang/adaptor.h>

namespace isc {
namespace yang {

/// @brief JSON adaptor for subnets adding IDs and canonizes relays.
///
/// Adding IDs is done in two passes walking through subnets.
///  -1- Add in the set used values and return false when there is no ID
///      so the caller can decide if the second pass is needed.
///  -2- For a subnet without an ID, assigned the next unused ID.
///
/// For relays an old syntax ip-address is translated into a new syntax
/// ip-addresses. Note as all canonization adaptor it is optional, i.e.,
/// code should work without it.
class AdaptorSubnet {
public:
    /// @brief Destructor.
    virtual ~AdaptorSubnet() = default;

    /// @brief Collect a subnet ID.
    ///
    /// @param subnet The subnet.
    /// @param set The reference to the set of assigned IDs.
    /// @return True if the subnet has an ID, false otherwise.
    static bool collectID(isc::data::ConstElementPtr subnet,
                          isc::dhcp::SubnetIDSet& set);

    /// @brief Assign subnet ID.
    ///
    /// @param subnet The subnet.
    /// @param set The reference to the set of assigned IDs.
    /// @param next The next ID.
    static void assignID(isc::data::ElementPtr subnet,
                         isc::dhcp::SubnetIDSet& set,
                         isc::dhcp::SubnetID& next);

    /// @brief Update relay.
    ///
    /// Force the use of ip-addresses when it finds an ip-address entry.
    /// Can be used for shared networks too.
    ///
    /// @param subnet The subnet.
    static void updateRelay(isc::data::ElementPtr subnet);
};  // AdaptorSubnet

}  // namespace yang
}  // namespace isc

#endif  // ISC_ADAPTOR_SUBNET_H