Public Types | Public Member Functions | Private Attributes

FlowStat Class Reference

Flow statistics telling how much flow should be sent along a link. More...

#include <station_base.h>

Public Types

typedef std::map< uint32,
StationID > 
SharesMap

Public Member Functions

 FlowStat ()
 Invalid constructor.
 FlowStat (StationID st, uint flow)
 Create a FlowStat with an initial entry.
void AppendShare (StationID st, uint flow)
 Add some flow to the end of the shares map.
uint GetShare (StationID st) const
 Get flow for a station.
void ChangeShare (StationID st, int flow)
 Change share for specified station.
const SharesMap * GetShares () const
 Get the actual shares as a const pointer so that they can be iterated over.
StationID GetVia () const
 Get a station a package can be routed to.
StationID GetVia (StationID excluded, StationID excluded2=INVALID_STATION) const
 Get a station a package can be routed to, but exclude the given one.

Private Attributes

SharesMap shares
 Shares of flow to be sent via specified station (or consumed locally).

Detailed Description

Flow statistics telling how much flow should be sent along a link.

This is done by creating "flow shares" and using std::map's upper_bound() method to look them up with a random number. A flow share is the difference between a key in a map and the previous key. So one key in the map doesn't actually mean anything by itself.

Definition at line 36 of file station_base.h.


Constructor & Destructor Documentation

FlowStat::FlowStat (  )  [inline]

Invalid constructor.

This can't be called as a FlowStat must not be empty. However, the constructor must be defined and reachable for FlwoStat to be used in a std::map.

Definition at line 45 of file station_base.h.

FlowStat::FlowStat ( StationID  st,
uint  flow 
) [inline]

Create a FlowStat with an initial entry.

Parameters:
st Station the initial entry refers to.
flow Amount of flow for the initial entry.

Definition at line 52 of file station_base.h.

References shares.


Member Function Documentation

void FlowStat::AppendShare ( StationID  st,
uint  flow 
) [inline]

Add some flow to the end of the shares map.

Only do that if you know that the station isn't in the map yet. Anything else may lead to inconsistencies.

Parameters:
st Remote station.
flow Amount of flow to be added.

Definition at line 65 of file station_base.h.

References shares.

Referenced by FlowStatMap::PassOnFlow().

void FlowStat::ChangeShare ( StationID  st,
int  flow 
)

Change share for specified station.

By specifing INT_MIN as parameter you can erase a share.

Parameters:
st Next Hop to be removed.
flow Share to be added or removed.

Definition at line 4130 of file station_cmd.cpp.

References shares.

Referenced by FlowStatMap::DeleteFlows(), and FlowStatMap::FinalizeLocalConsumption().

uint FlowStat::GetShare ( StationID  st  )  const

Get flow for a station.

Parameters:
st Station to get flow for.
Returns:
Flow for st.

Definition at line 4057 of file station_cmd.cpp.

References shares.

Referenced by FlowStatMap::FinalizeLocalConsumption().

const SharesMap* FlowStat::GetShares (  )  const [inline]

Get the actual shares as a const pointer so that they can be iterated over.

Returns:
Actual shares.

Definition at line 80 of file station_base.h.

References shares.

Referenced by FlowStatMap::DeleteFlows(), and FlowStatMap::FinalizeLocalConsumption().

StationID FlowStat::GetVia ( StationID  excluded,
StationID  excluded2 = INVALID_STATION 
) const

Get a station a package can be routed to, but exclude the given one.

Parameters:
excluded StationID not to be selected.
Returns:
A station ID from the shares map.

Definition at line 4075 of file station_cmd.cpp.

References max(), shares, and Swap().

StationID FlowStat::GetVia (  )  const [inline]

Get a station a package can be routed to.

This done by drawing a random number between 0 and sum_shares and then looking that up in the map with lower_bound. So each share gets selected with a probability dependent on its flow.

Returns:
A station ID from the shares map.

Definition at line 89 of file station_base.h.

References shares.


The documentation for this class was generated from the following files: