Class CPLNetwork
Introduction
This class implements a HomePlug AV network as a collection of powerline stations. The network is characterized by interrogating a reference station with a VS_NW_INFO message then interrogating each network neighbor with a VS_SW_VER message. Class properties, methods and operators are used to iterate through the collection and obtain copies of individual station instances. Station instances are implemented using the CPLStation class.
The HomePlug AV Specification assigns special meaning to the term station but this class considers all powerline devices to be stations. The central coordinator and proxy coordinator is merely a special kind of station.
The first station in the collection is always the one specified by the CPLChannel instance used to instantiate the CPLNetwork instance. The remaining stations can appear in any order. Applications must iterate through the network to locate the local device or the central coordinator by examining station LinkType and the RoleType properties.
This class is declared in CPLNetwork.hpp and defined in CPLNetwork.cpp.
Inheritance
None.
Dependence
This class uses class CPLChannel to identifiy the host interface and powerline device to be interrogated.
This class uses class CPLStation to represent individual powerline devices found on the powerline network.
Properties
CPLNetwork::Count
unsigned Countvoid
Return the number of powerline stations detected on the network. This property does not change over the instance lifetime and is the upper bound when iterating through network stations.
CPLNetwork::Empty
bool Emptyvoid
Return logical true if the collection is empty. The collection is empty only if the Count property is 0. An empty collection may indicate that the class was instantiated with an incorrect channel PeerAddress.
CPLNetwork::End
bool Endvoid
Return logical true if the collection is exhausted. The collection is exhausted if the Index property equals or exceeds the Count property.
CPLNetwork::Index
unsigned Indexvoid
Return the index of the selected interface. The index ranges from 0 up to (but excluding) the value the Count property. Class methods and operators may be used to alter the value of this property.
CPLNetwork::Selected
CPLStation & Selectedvoid
Return the selected CPLStation object instance. The selected instance is determined by the Index property. All CPLStation class constants, properties, methods and operators are available to the application through this instance.
CPLNetwork::Station
CPLStation & Stationvoid
Return the selected CPLStation object instance. This property is the same as the Selected property.
Methods
CPLNetwork::Enumerate
CPLNetwork & Enumeratevoid
Enumerate network powerline stations on stdout. This is equivalent to calling the Print method for each station in the collection.
CPNetworkn::Select
CPLNetwork & Selectunsigned index
Select a station by index. This sets the Index property and determines the station that will be returned by the Selected and Station properties.
CPLNetwork::SelectFirst
CPLNetwork & SelectFirstvoid
Set the Index property to 0.
CPLNetwork::SelectFinal
CPLNetwork & SelectFinalvoid
Set the Index property to one less than the Count property.
CPLNetwork::SelectNext
CPLNetwork & SelectNextvoid
Increment the Index property if it is less than the Count property.
CPLNetwork::SelectPrev
CPLNetwork & SelectPrevvoid
Decrement the Index property if it is greater than 0.
Operators
CPLNetwork::operator []
CPLStation & operator []unsigned index
Select a network station by index and return an instance of it. This operator has the same effect as calling the Select method with index then reading either the Selected or the Station property.
CPLNetwork::operator =
CPLNetwork & operator =unsigned index
Select a network station by network index. This operator has the same effect as the Select method with index.
Constructors
CPLNetworkCPLChannel * channel
Instantiate a collection of powerline network stations using the specified channel. The channel PeerAddress property must contain the Ethernet hardware address of a powerline station that is accessible through the channel interface. The reference station is interrogated and the collection is constructed. The collection includes the reference station and all neighbor stations. Class properties and methods are used to iterate through the collection obtain copies of individual stations.
Examples
The following example instantiates the CPLNetwork class and prints information about powerline network stations on stdout using the Enumerate method. Several code variations are shown.
Enumerate Powerline Network Station Details
#if defined (__APPLE__)
CPLChannel channel ("en0");
#elif defined (WINPCAP)
CPLChannel channel (2);
#else
CPLChannel channel ("eth4");
#endif
byte device [] = { 0x00, 0xB0, 0x52, 0xBA, 0xBE, 0x05 }
channel.ImportPeerAddress (device)
CPLNetwork network (&channel);
network.Enumerate ();
This example instantiates a channel using interface "en0" on MAC OSX systems, interface number 2 on Windows or interface "eth4" on other systems. This creates a raw socket on the named interface then gathers information about the interface and the socket. Static interface assignment, such as this, is not recommended because we have no way of knowing if the named or numbered interface will be available on all systems.
The example goes on to define an arbitrary powerline device address and assign it to the channel using method ImportPeerAddress. This defines the default peer address for outgoing Ethernet frames. This address remains the default until it is changed. The channel PeerAddress, together with the channel HostAddress and channel Protocol form a template used by other classes to format Ethernet frame headers.
P/L NET TEI ------ MAC ------ ------ BDA ------ TX RX CHIPSET FIRMWARE
LOC CCO 001 00:B0:52:BE:EF:04 00:50:04:A5:D8:98 000 000 INT6000 INT6000-MAC-4-0-4011-01-3431-20090519-FINAL-B
REM STA 002 00:B0:52:DE:AD:01 FF:FF:FF:FF:FF:FF 145 147 INT6000 INT6000-MAC-4-1-4101-00-3646-20090615-BETA1-B
REM STA 003 00:0B:3B:7F:78:AA FF:FF:FF:FF:FF:FF 000 000 INT6300 INT6000-MAC-4-1-4102-00-3679-20090724-FINAL-B
Assuming the channel interface is available and the peer address references some powerline device on that interface, we will have a complete list of stations associated with device. Method Enumerate merely prints all network station details on stdout so we can see them.
The network and channel will close when these objects go out-of-scope.
Enumerate Powerline Network Station Details
if (network.Count ())
{
network.Select (0).Selected ().Title ();
}
for (network.SelectFirst (); network.Index () < network.Count (); network.SelectNext ())
{
network.Selected ().Print ();
}
This example produces the same output as above by iterating through the powerline network stations. The loop shown is basically the same as that used in the Enumerate method.
First, if the network is not empty then station 0 is arbitratily selected and the station Preface method is called to print a heading. This method is cosmetic and optional.
P/L NET TEI ------ MAC ------ ------ BDA ------ TX RX CHIPSET FIRMWARE
The example then iterates through each network station and calls the station Print method to output station details on stdout.
LOC CCO 001 00:B0:52:BE:EF:04 00:50:04:A5:D8:98 000 000 INT6000 INT6000-MAC-4-0-4011-01-3431-20090519-FINAL-B
REM STA 002 00:B0:52:DE:AD:01 FF:FF:FF:FF:FF:FF 145 147 INT6000 INT6000-MAC-4-1-4101-00-3646-20090615-BETA1-B
REM STA 003 00:0B:3B:7F:78:AA FF:FF:FF:FF:FF:FF 000 000 INT6300 INT6000-MAC-4-1-4102-00-3679-20090724-FINAL-B
If this output is not suitable then you can always access the station properties of interest and either use them or display them as needed.