|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * @author Richard Plny <[email protected]> |
| 4 | + * @brief IP prefix classifier interface |
| 5 | + * |
| 6 | + * SPDX-License-Identifier: BSD-3-Clause |
| 7 | + */ |
| 8 | + |
| 9 | +#pragma once |
| 10 | + |
| 11 | +#include "wif/classifiers/classifier.hpp" |
| 12 | +#include "wif/utils/ipPrefix.hpp" |
| 13 | + |
| 14 | +#include <algorithm> |
| 15 | +#include <memory> |
| 16 | +#include <vector> |
| 17 | + |
| 18 | +namespace WIF { |
| 19 | + |
| 20 | +/** |
| 21 | + * @brief Classifier performing blocklist detection |
| 22 | + */ |
| 23 | +class IpPrefixClassifier : public Classifier { |
| 24 | +public: |
| 25 | + /** |
| 26 | + * @brief Construct an IP Prefix Classifier object with empty blocklist |
| 27 | + */ |
| 28 | + IpPrefixClassifier() = default; |
| 29 | + |
| 30 | + /** |
| 31 | + * @brief Construct a new IP Prefix Classifier object |
| 32 | + * @param blocklist std::vector of blocklisted IP prefixes |
| 33 | + */ |
| 34 | + IpPrefixClassifier(const std::vector<IpPrefix>& blocklist); |
| 35 | + |
| 36 | + /** |
| 37 | + * @brief Getter for current IP prefix blocklist |
| 38 | + * @return const std::vector<IpPrefix>& current blocklist |
| 39 | + */ |
| 40 | + const std::vector<IpPrefix>& getBlocklist() const noexcept { return m_blocklist; } |
| 41 | + |
| 42 | + /** |
| 43 | + * @brief Update blocklist |
| 44 | + * Old blocklist is destructed and replaced by new one |
| 45 | + * @param blocklist std::vector of new IP prefixes on blocklist |
| 46 | + */ |
| 47 | + void updateBlocklist(const std::vector<IpPrefix>& blocklist); |
| 48 | + |
| 49 | + /** |
| 50 | + * @brief Classify single flowFeature object |
| 51 | + * ClfResult contains non-zero double value if flowFeatures contained a field with IP from |
| 52 | + * blocklist, otherwise the double value is set to zero |
| 53 | + * |
| 54 | + * @param flowFeatures flow features to classify |
| 55 | + * @return ClfResult result of the classification |
| 56 | + */ |
| 57 | + ClfResult classify(const FlowFeatures& flowFeatures) override; |
| 58 | + |
| 59 | + /** |
| 60 | + * @brief Classify a burst of flow features |
| 61 | + * |
| 62 | + * @param burstOfFlowsFeatures the burst of flow features to classify |
| 63 | + * @return std::vector<ClfResult> std::vector<ClfResult> the results of the classification |
| 64 | + */ |
| 65 | + std::vector<ClfResult> classify(const std::vector<FlowFeatures>& burstOfFlowsFeatures) override; |
| 66 | + |
| 67 | +private: |
| 68 | + bool findIpAddress(const IpAddress& ipAddress); |
| 69 | + |
| 70 | + std::vector<IpPrefix> m_blocklist; |
| 71 | +}; |
| 72 | + |
| 73 | +} // namespace WIF |
0 commit comments