WSF
WsfCommReservedAddressing.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2018 Infoscitex, a DCS Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFCOMMRESERVEDADDRESSING_HPP
13#define WSFCOMMRESERVEDADDRESSING_HPP
14
15#include <memory>
16#include <unordered_map>
17#include <unordered_set>
18#include <vector>
19
20#include "WsfCommAddress.hpp"
21
22namespace wsf
23{
24namespace comm
25{
34
40namespace reserved
41{
42constexpr const char* const cBROADCAST_LOCAL = "BROADCAST_LOCAL";
43constexpr const char* const cMULTICAST_INITIAL = "MULTICAST_INITIAL";
44constexpr const char* const cMULTICAST_LAST = "MULTICAST_LAST";
45constexpr const char* const cDEFAULT_INITIAL = "DEFAULT_INITIAL";
46constexpr const char* const cDEFAULT_LAST = "DEFAULT_LAST";
47constexpr const char* const cMULTICAST_ALL_HOSTS = "MULTICAST_ALL_HOSTS"; // All multicast hosts
48constexpr const char* const cMULTICAST_ALL_ROUTERS = "MULTICAST_ALL_ROUTERS"; // All multicast routers
49constexpr const char* const cRIPv2_MULTICAST = "RIPv2_MULTICAST"; // Local Network Only
50constexpr const char* const cOSPF_MULTICAST_ALL = "OSPF_MULTICAST_ALL"; // Hello and Protocol Usage
51constexpr const char* const cOSPF_MULTICAST_DRBR = "OSPF_MULTICAST_DRBR"; // DR/BR Usage Only
52} // namespace reserved
53
59{
60public:
63
67 virtual void Initialize() = 0;
68
70 virtual bool IsReserved(const Address& aAddress) const;
71 virtual Address QueryAddressByType(const std::string& aReservedType) const;
72
73protected:
75 virtual bool IsReservedSimple(const Address& aAddress) const;
76
82 {
83 std::size_t operator()(const std::pair<Address, Address>& aKey) const
84 {
85 auto hash1 = std::hash<Address>{}(aKey.first);
86 auto hash2 = std::hash<Address>{}(aKey.second);
87 auto combineHash1 = hash1 ^ (hash2 << 1);
88 auto combineHash2 = hash2 ^ (hash1 << 1);
89
90 return std::min(combineHash1, combineHash2);
91 }
92 };
93
94 using ReservedSet = std::unordered_set<Address>;
95 using ReservedPairSet = std::unordered_set<std::pair<Address, Address>, AddressPairHash>;
96 using ReservedTypeMap = std::unordered_map<std::string, Address>;
97
101};
102
109{
110public:
111 using UniqueReserved = std::unique_ptr<ReservedAddressingImplementation>;
112
116
117 virtual ~ReservedAddressing() = default;
118 void Register(UniqueReserved aImplementation);
119 void Initialize();
120
121 bool IsReserved(const Address& aAddress) const;
122 Address QueryAddressByType(const std::string& aReservedType) const;
123
124private:
125 std::vector<UniqueReserved> mImplementations;
126};
127
131{
132public:
133 void Initialize() override;
134};
135
136} // namespace comm
137} // namespace wsf
138
139#endif
Definition WsfCommAddress.hpp:57
Definition WsfCommReservedAddressing.hpp:131
void Initialize() override
Definition WsfCommReservedAddressing.cpp:137
virtual Address QueryAddressByType(const std::string &aReservedType) const
Definition WsfCommReservedAddressing.cpp:79
std::unordered_set< std::pair< Address, Address >, AddressPairHash > ReservedPairSet
Definition WsfCommReservedAddressing.hpp:95
virtual bool IsReservedSimple(const Address &aAddress) const
Checks the simple case of an address/32 collision.
Definition WsfCommReservedAddressing.cpp:56
virtual bool IsReserved(const Address &aAddress) const
Checks if the address/32 value is reserved.
Definition WsfCommReservedAddressing.cpp:20
std::unordered_map< std::string, Address > ReservedTypeMap
Definition WsfCommReservedAddressing.hpp:96
ReservedPairSet mReservedAddressRangeSet
Definition WsfCommReservedAddressing.hpp:99
ReservedTypeMap mReservedTypeToAddressMap
Definition WsfCommReservedAddressing.hpp:100
ReservedSet mReservedAddressSet
Definition WsfCommReservedAddressing.hpp:98
std::unordered_set< Address > ReservedSet
Definition WsfCommReservedAddressing.hpp:94
void Register(UniqueReserved aImplementation)
Definition WsfCommReservedAddressing.cpp:122
Address QueryAddressByType(const std::string &aReservedType) const
Definition WsfCommReservedAddressing.cpp:106
ReservedAddressing & operator=(const ReservedAddressing &aSrc)=delete
void Initialize()
Definition WsfCommReservedAddressing.cpp:128
std::unique_ptr< ReservedAddressingImplementation > UniqueReserved
Definition WsfCommReservedAddressing.hpp:111
virtual ~ReservedAddressing()=default
ReservedAddressing(const ReservedAddressing &aSrc)=delete
bool IsReserved(const Address &aAddress) const
Definition WsfCommReservedAddressing.cpp:92
Definition WsfCommReservedAddressing.hpp:41
constexpr const char *const cMULTICAST_LAST
Definition WsfCommReservedAddressing.hpp:44
constexpr const char *const cDEFAULT_LAST
Definition WsfCommReservedAddressing.hpp:46
constexpr const char *const cMULTICAST_INITIAL
Definition WsfCommReservedAddressing.hpp:43
constexpr const char *const cOSPF_MULTICAST_DRBR
Definition WsfCommReservedAddressing.hpp:51
constexpr const char *const cMULTICAST_ALL_ROUTERS
Definition WsfCommReservedAddressing.hpp:48
constexpr const char *const cBROADCAST_LOCAL
Definition WsfCommReservedAddressing.hpp:42
constexpr const char *const cMULTICAST_ALL_HOSTS
Definition WsfCommReservedAddressing.hpp:47
constexpr const char *const cRIPv2_MULTICAST
Definition WsfCommReservedAddressing.hpp:49
constexpr const char *const cDEFAULT_INITIAL
Definition WsfCommReservedAddressing.hpp:45
constexpr const char *const cOSPF_MULTICAST_ALL
Definition WsfCommReservedAddressing.hpp:50
Definition WsfComm.cpp:34
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Definition WsfCommReservedAddressing.hpp:82
std::size_t operator()(const std::pair< Address, Address > &aKey) const
Definition WsfCommReservedAddressing.hpp:83
Copyrights Multiple, All Rights Reserved