WSF
WsfObserver::Address Class Reference

#include <WsfCommAddress.hpp>

Inherits UtScriptAccessible.

Public Member Functions

 Address ()=default
 Address (const std::string &aAddress, size_t aSubnetMaskBitLength=IPv4::cDEFAULT_CIDR)
 Address (size_t aSubnetMaskBitLength)
virtual ~Address ()=default
const char * GetScriptClassName () const override
void SetAddress (const std::string &aAddress, size_t aSubnetBitLength=IPv4::cDEFAULT_CIDR)

Static Public Member Functions

static Address ProcessInput (UtInput &aInput)
static Address ProcessInput (std::string aInput)
static bool IsValidAddress (const std::string &aPossibleAddress)
static size_t GetCIDR_ValueFromString (std::string &aPossibleAddress)

Address++ and ++Address Overloads

Increments the address by one. Useful when assigning new addresses, in that the highest existing address in a subnet can be copied and then simply incremented to provide a new address.

Note
These do NOT check if the increment will result in a new address that changes the routing prefix of the address (essentially moving the address out of a current subnet). Any calling object should ensure that the resulting address is still viable by comparing the routing prefix.
Addressoperator++ ()
Address operator++ (int)
template<typename T>
void Serialize (T &aBuff)
 For XIO usage.
std::string GetGenerationToken () const
std::string GetBroadcastAddress () const
 Returns the broadcast address of this address.
static size_t GetStringValue (const std::string &aString)
static bool CheckInAddressRange (const Address &aNetworkAddress, const Address &aCheckAddress)
WSF_EXPORT std::ostream & operator<< (std::ostream &aOut, const Address &aAddress)

GenerateAddress Method

This method populates the address object with an IP address generated from a provided string token. This token can be any string, of which a procedurally generated IP address will be generated that will consistently provide the same address given a particular string. Useful for assigning initial address values, especially for named networks when no address is provided.

void GenerateAddress (const std::string &aGenerationToken, size_t aSubnetBitLength=IPv4::cDEFAULT_CIDR)
const std::string & GetAddress () const
size_t GetSubnetMaskBitLength () const
const std::string & GetRoutingPrefix () const
const std::string & GetSubnet () const
size_t GetNumHostAddresses () const
bool IsNull () const
size_t GetBinaryInteger () const
bool operator== (const Address &aRhs) const
bool operator!= (const Address &aRhs) const
bool operator< (const Address &aRhs) const

Detailed Description

WsfCommAddress represents a typical IP address, for usage within the context of addressing within the Comm domain. Even though some networks are not formal Internet Protocol networks and would not be subject to this standard of addressing, this method is a standard that provides Comm with a internally consistent means of handling addressing of all comm-capable objects within AFSIM. The addressing here is consistent with the CIDR variable subnet bit masking instead of the deprecated class A,B, and C domain usages. Note that this class now differs from the original instantiation in that platforms are not directly associated with an address within the scope of this class.

Constructor & Destructor Documentation

◆ Address() [1/3]

◆ Address() [2/3]

wsf::comm::Address::Address ( const std::string & aAddress,
size_t aSubnetMaskBitLength = IPv4::cDEFAULT_CIDR )

◆ Address() [3/3]

wsf::comm::Address::Address ( size_t aSubnetMaskBitLength)
explicit

Note: This constructor supplies an uninitialized address, but with a specified bit mask length. This allows the conveyance of a required bit length mask for an address that is to be generated at a time beyond construction, typically using GenerateAddress().

◆ ~Address()

virtual wsf::comm::Address::~Address ( )
virtualdefault

Member Function Documentation

◆ CheckInAddressRange()

bool wsf::comm::Address::CheckInAddressRange ( const Address & aNetworkAddress,
const Address & aCheckAddress )
static

A static method for checking whether or not a provided address falls within the range of addresses of a network address using CIDR notation. Be mindful of the order of addresses provided, as the CIDR value of the network address and its subnet mask is used without checking for consistency with the comparing address.

◆ GenerateAddress()

void wsf::comm::Address::GenerateAddress ( const std::string & aGenerationToken,
size_t aSubnetBitLength = IPv4::cDEFAULT_CIDR )

Generate an integer value for the token string.

We always add the above integer value to the integer representation of the existing address. Typically, this will be 0.0.0.0 for previously unused address objects, but this call may have been made previously and resulted in an unsuitable address (due to a collision with an existing address, or range limitations of usage). Thus, we have a predictable and reproducible way of getting new addresses given the same token and subsequent calls to this method, yet get different results from each iteration of the call.

Convert the integer value into an IPV4 format address.

◆ GetAddress()

const std::string & wsf::comm::Address::GetAddress ( ) const
inline

◆ GetBinaryInteger()

size_t wsf::comm::Address::GetBinaryInteger ( ) const
inline

◆ GetBroadcastAddress()

Returns the broadcast address of this address.

◆ GetCIDR_ValueFromString()

size_t wsf::comm::Address::GetCIDR_ValueFromString ( std::string & aPossibleAddress)
static

Given a possible address string, find the CIDR notation value and return it.

Note
CIDR notation is denoted by a valid string address format followed by a "/" and an unsigned integer value between 0 and 32. e.g 192.168.1.1/24
This takes a reference to the possible string address. It is modified during this call to consume the CIDR mask reference value to leave the bare address.
If no CIDR value is found, the default CIDR value of 24 will be returned.

◆ GetGenerationToken()

std::string wsf::comm::Address::GetGenerationToken ( ) const
inline

If the address was generated using a user supplied string token, then that value is saved within the address for later retrieval, as the user may identify an address based on this value.

◆ GetNumHostAddresses()

Note: Typically, we would subtract two available hosts from an IPV4 host range, as the highest and lowest available host addresses are used for broadcasting. We don't make the distinction in this implementation. Therefore, if checking with external references, this value is likely two hosts higher.

◆ GetRoutingPrefix()

const std::string & wsf::comm::Address::GetRoutingPrefix ( ) const
inline

◆ GetScriptClassName()

const char * wsf::comm::Address::GetScriptClassName ( ) const
override

◆ GetStringValue()

size_t wsf::comm::Address::GetStringValue ( const std::string & aString)
static

A static method that provides an unsigned integer value from a string. Uses the same value assignment methodology as UtDictionary, and produces a consistent and repeatable value given a specific string.

◆ GetSubnet()

const std::string & wsf::comm::Address::GetSubnet ( ) const
inline

◆ GetSubnetMaskBitLength()

◆ IsNull()

bool wsf::comm::Address::IsNull ( ) const
inline

◆ IsValidAddress()

bool wsf::comm::Address::IsValidAddress ( const std::string & aPossibleAddress)
static

Allows the checking of a string to determine if it is a valid IPV4 format address.

◆ operator!=()

bool wsf::comm::Address::operator!= ( const Address & aRhs) const

◆ operator++() [1/2]

Address & wsf::comm::Address::operator++ ( )

Increment the lowest order byte, carrying the value if we are at the max value for this byte (255).

Reset the other member variables to account for the address change.

◆ operator++() [2/2]

Address wsf::comm::Address::operator++ ( int )

◆ operator<()

bool wsf::comm::Address::operator< ( const Address & aRhs) const

Iterate from most significant to least significant bytes. Values may be equal for some higher order bytes, but we're guaranteed to differ somewhere due to the previous equivalence check.

We should never reach this point.

◆ operator==()

bool wsf::comm::Address::operator== ( const Address & aRhs) const

◆ ProcessInput() [1/2]

Address wsf::comm::Address::ProcessInput ( std::string aInput)
static

Same as the ProcessInput command, expect acts on the raw string input already retrieved from a source such as a input stream.

◆ ProcessInput() [2/2]

Address wsf::comm::Address::ProcessInput ( UtInput & aInput)
static

Allows parsing of addresses from the input stream using a defined standard.

Note
Entry into this method may use various commands. It is assumed this is called only after confirming an address is next in the stream. This will handle any possible CIDR subnet usage subsequent in the stream.

◆ Serialize()

template<typename T>
void wsf::comm::Address::Serialize ( T & aBuff)
inline

For XIO usage.

◆ SetAddress()

void wsf::comm::Address::SetAddress ( const std::string & aAddress,
size_t aSubnetBitLength = IPv4::cDEFAULT_CIDR )

Ensure the bit mask length is valid

Parse out the strings associated with each subfield in the address e.g. 123.2.1.33 -> 123, 2, 1, 33

Convert each field value to a integer representing the binary value for each field

Store each field as a byte representation

Store the integer value of the address for possible later comparisons

Get the CIDR mask

Get the vector of integer values for the routing/network address

Get the vector of integer value of the subnet mask

Translate the subnet into an integer value for easy comparisons between addresses

Convert the two values above to strings with delimiters, and save them.

◆ operator<<

WSF_EXPORT std::ostream & operator<< ( std::ostream & aOut,
const Address & aAddress )
friend

The documentation for this class was generated from the following files:
Copyrights Multiple, All Rights Reserved