XSocket API  2.0
XIA Socket Library
Public Member Functions | Static Public Attributes
Graph Class Reference

Build DAGs for use as addresses in XIA. More...

#include <dagaddr.hpp>

Public Member Functions

 Graph ()
 Create an empty graph. More...
 
 Graph (const Node &n)
 Create a graph from a node. More...
 
 Graph (const Graph &r)
 Create a copy of a graph. More...
 
 Graph (std::string dag_string)
 Create a graph from a DAG string. More...
 
 Graph (const sockaddr_x *s)
 Create a graph from a sockaddr_x. More...
 
Graphoperator= (const Graph &r)
 
Graphoperator*= (const Graph &r)
 
Graph operator* (const Graph &r) const
 Append a graph to this one. More...
 
Graphoperator+= (const Graph &r)
 
Graph operator+ (const Graph &r) const
 Merge a graph with this one. More...
 
Graph operator* (const Node &r) const
 Append a node. More...
 
Graph operator+ (const Node &r) const
 Merge with a node. More...
 
bool operator== (const Graph &r) const
 Compare two graphs logically. More...
 
void append_node_str (std::string node_str)
 
void print_graph () const
 Print the graph. More...
 
std::string http_url_string () const
 
std::string dag_string () const
 Return the graph in string form. More...
 
const Nodeintent_AD () const
 
const Nodeintent_HID () const
 
const Nodeintent_SID () const
 
std::string intent_AD_str () const
 Return the AD for the Graph's intent node. More...
 
std::string intent_HID_str () const
 
std::string intent_SID_str () const
 
bool is_valid () const
 Check if this is a valid graph. More...
 
bool is_final_intent (const Node &n)
 Test if a node is the final intent. More...
 
bool is_final_intent (const std::string xid_string)
 Test if a node is the final intent. More...
 
Graph next_hop (const Node &n)
 Get the next "intent unit" in the DAG starting at the supplied node. More...
 
Graph next_hop (const std::string xid_string)
 Get the next "intent unit" in the DAG starting at the supplied XID. More...
 
Graph first_hop ()
 Get the first "intent unit" in the DAG. More...
 
uint8_t num_nodes () const
 Get the number of nodes in the DAG. More...
 
Node get_node (int i) const
 Get a node from the DAG. More...
 
size_t fill_wire_buffer (node_t *buf) const
 Fill a wire buffer with this DAG. More...
 
void fill_sockaddr (sockaddr_x *s) const
 Fill a sockaddr_x with this DAG. More...
 
void from_wire_format (uint8_t num_nodes, const node_t *buf)
 
void from_sockaddr (const sockaddr_x *s)
 Fills an empty graph from a sockaddr_x. More...
 
void replace_final_intent (const Node &new_intent)
 Replace the DAG's final intent with the supplied Node. More...
 
Node get_final_intent () const
 Return the final intent of the DAG. More...
 
bool replace_intent_HID (std::string new_hid_str)
 
bool replace_intent_AD (std::string new_ad_str)
 
size_t unparse_node_size () const
 Number of nodes in this graph. More...
 
bool flatten ()
 Flatten the direct edge from source to intent, if it exists. More...
 
bool first_hop_is_sid () const
 Is the first hop from source node an SID? More...
 
bool remove_intent_sid_node ()
 
bool remove_intent_node ()
 
std::vector< const Node * > get_nodes_of_type (unsigned int type) const
 Get a list of nodes of the specified type. More...
 
std::string xid_str_from_index (std::size_t node) const
 Return XID as a string for node at specified index. More...
 
std::size_t final_intent_index () const
 Get the index of the final intent node. More...
 
int compare_except_intent_AD (Graph other) const
 Compare two graphs while ignoring intent AD. More...
 

Static Public Attributes

static const std::size_t MAX_XIDS_IN_ALL_PATHS = 30
 
static const std::size_t INVALID_GRAPH_INDEX = 255
 

Detailed Description

This class provides the user a simple set of operators to build a DAG for use as address within XIA.

NOTE:

Create Node(s) first and then build Graph from them Node objects are compared by reference. So even if two Nodes have the same XID, they are considered separate. This allows us to build Graphs with the same XID appearing more than once.

Constructor & Destructor Documentation

Graph::Graph ( )

Create an empty graph.

Graph::Graph ( const Node n)

Create a graph containing a single node.

Parameters
nThe node the new graph should contain.
Graph::Graph ( const Graph r)

Create a new graph that is a copy of the supplied graph.

Parameters
rThe graph to be copied.
Graph::Graph ( std::string  dag_string)

Create a new graph from a DAG string. It is generally recommended not to write DAG strings from scratch, but to obtain them by creating Graphs with other constructors and calling Graph::dag_string(). This constructor is also useful for creating a DAG from a DAG string obtained from the XSocket API (from the XrecvFrom() call, for example).

Parameters
dag_stringThe DAG in the string format used by the XSocket API. Example 1:
DAG 2 0 -
AD:4349445f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f 2 1 -
HID:4849445f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f 2 -
SID:534944305f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f
Example 2:
RE ( AD:1000000000000000000000000000000000000000 HID:0000000000000000000000000000000000000000 ) SID:1110000000000000000000000000000000001113
Graph::Graph ( const sockaddr_x *  s)

Create a new graph from a sockaddr_x. This constructor is useful for creating a DAG from from a sockaddr_x obtained from the XSocket API (from the XrecvFrom() call, for example).

Parameters
sThe sockaddr_x

Member Function Documentation

void Graph::append_node_str ( std::string  node_str)
int Graph::compare_except_intent_AD ( Graph  other) const
Returns
0 if the graphs are same except intent AD, -1 otherwise
std::string Graph::dag_string ( ) const

Get the DAG string representation of the graph. This string is suitable for use with the XSocket API.

Returns
The graph in DAG string form.
void Graph::fill_sockaddr ( sockaddr_x *  s) const

Fill the provided sockaddr_x with this DAG

Parameters
sThe sockaddr_x struct to be filled in (allocated by caller)
size_t Graph::fill_wire_buffer ( node_t *  buf) const

Fill the provided buffer with this DAG

Parameters
sThe wire buffer struct to be filled in (allocated by caller)
std::size_t Graph::final_intent_index ( ) const

Get the index of the final intent node. This method returns the index of the first sink node it finds.

Returns
The index of the DAG's final intent node.
Graph Graph::first_hop ( )

Get the first "intent unit" in the DAG. Calling this method is equivalent to calling g.next_hope(Node()).

Returns
The DAG's first intent unit (as a Graph)
bool Graph::first_hop_is_sid ( ) const
Returns
True if first hop from source node is SID
bool Graph::flatten ( )

Try to flatten a graph with a direct edge between the source and intent by removing that edge.

Returns
result of flattening the direct edge from source to intent node.
void Graph::from_sockaddr ( const sockaddr_x *  s)

Fills an empty graph from a sockaddr_x. Behavior is undefined if the graph contains nodes or edges prior to this call.

Parameters
sThe sockaddr_x.
void Graph::from_wire_format ( uint8_t  num_nodes,
const node_t *  buf 
)

@ Fills an empty graph from our binary wire format

Fills an empty graph from a memory buffer containing the graph in serialized wire form.

Parameters
num_nodesThe number of nodes in the graph
bufThe memory buffer containing graph in serialized wire format
Node Graph::get_final_intent ( ) const

Returns the DAG's final intent (as a Node).

Returns
the DAG's final intent
Node Graph::get_node ( int  i) const

Get a Node from the graph at the specified index. The sink node will always be returned last (that is, it has index num_nodes()-1).

Note
This function skips the starting node
Parameters
iThe index of the node to return
Returns
The node at index i
std::vector< const Node * > Graph::get_nodes_of_type ( unsigned int  type) const

Return a list of the nodes in the DAG of the specified XID type. The vector returned contains pointers to the node objects in the DAG, not copies.

Parameters
xid_typeThe XID type of interest. Must be one of:
Node::XID_TYPE_AD (Administrative Domain)
Node::XID_TYPE_HID (Host)
Node::XID_TYPE_CID (Content)
Node::XID_TYPE_SID (Service)
Node::XID_TYPE_FID (Flood)
Node::XID_TYPE_IP (IPv4 / 4ID)
Returns
List of pointers to nodes of the specified type.
std::string Graph::http_url_string ( ) const
const Node & Graph::intent_AD ( ) const
std::string Graph::intent_AD_str ( ) const

Get the AD string on first path to intent node Note: This function is essentially identical to intent_HID_str()

Returns
The AD if found, empty string otherwise
const Node & Graph::intent_HID ( ) const
std::string Graph::intent_HID_str ( ) const
const Node & Graph::intent_SID ( ) const
std::string Graph::intent_SID_str ( ) const
bool Graph::is_final_intent ( const Node n)

Check whether or not the supplied Node is the final intent of the DAG

Parameters
nThe node to check
Returns
true if n is the final intent, false otherwise
bool Graph::is_final_intent ( const std::string  xid_string)

Check whether or not the supplied XID is the final intent of the DAG

Parameters
xid_stringThe XID to check
Returns
true if the XID is the final intent, false otherwise
bool Graph::is_valid ( ) const

Make sure this Graph represents a valid XIA DAG. For now we just do a bunch of simple checks like making sure there's at least one node and that the intent node has a valid XID type.

Returns
true if the graph is valid, false otherwise
Graph Graph::next_hop ( const Node n)

Get the next "intent unit" in the DAG starting at the supplied node. An intent node is a node that can be reached by following the highest priority out edge of each node beginning with the source. An intent unit is an intent node along with its fallbacks. In the new DAG, the previous intent unit becomes the source node.

Parameters
nThe node from which to find the next intent unit. n must be an intent node.
Returns
The next intent unit (as a Graph)
Graph Graph::next_hop ( const std::string  xid_string)

This method is the same as Graph::next_hop(const Node& n) except it takes an XID string instead of a Node object.

Parameters
xid_stringThe XID of the intent node from which to find the next intent unit.
Returns
The next intent unit (as a Graph)
uint8_t Graph::num_nodes ( ) const

Get the number of nodes in the DAG.

Note
This does not include the starting node
Returns
The number of nodes in the DAG
Graph Graph::operator* ( const Graph r) const

Append the supplied graph to the end of this one and return the resulting graph.

Parameters
rThe graph to be appended
Returns
The resulting graph
Graph Graph::operator* ( const Node r) const
inline

Append a node to the end of this graph and return the result.

Parameters
rThe node to append
Returns
The resulting graph
Graph & Graph::operator*= ( const Graph r)
Graph Graph::operator+ ( const Graph r) const

Merge the supplied graph with this one and return the resulting graph. If both graphs share the same source and sink, one graph will become a fallback path.

Parameters
rThe graph to be merged with this one
Returns
The resulting graph
Graph Graph::operator+ ( const Node r) const
inline

Merge the supplied node with this graph. If the node is already present in this graph, the resulting graph will be the same. If the node is different, the new node will be added to the graph but will not be connected by any edges.

Parameters
rThe node with which to merge
Returns
The resulting graph
Graph & Graph::operator+= ( const Graph r)
Graph & Graph::operator= ( const Graph r)
bool Graph::operator== ( const Graph g) const

Two graphs can be represented differently in memory or as a string We compare them logically by walking all possible paths from source to sink and comparing the order of nodes on each path with those in the other graph.

Parameters
gThe other graph to compare against
Returns
are the graphs logically equal?
void Graph::print_graph ( ) const

Print the graph. Useful for debugging.

Warning
The format in which this function prints a graph is not the same as the DAG string format used by the XSocket API. To obtain a string version of the DAG for use with the XSocket API, use Graph::dag_string() instead.
bool Graph::remove_intent_node ( )
bool Graph::remove_intent_sid_node ( )
void Graph::replace_final_intent ( const Node new_intent)

Replace the DAG's final intent with the supplied node.

Parameters
new_intentThe Node to become the DAG's new final intent.
bool Graph::replace_intent_AD ( std::string  new_ad_str)
bool Graph::replace_intent_HID ( std::string  new_hid_str)
size_t Graph::unparse_node_size ( ) const

Get the number of nodes in this graph or 0 if there are no nodes Note: we may return 0 on failure

Returns
number of nodes in graph minus source node
std::string Graph::xid_str_from_index ( std::size_t  node) const

Get the XID in string format from nodes_ at specified index.

Returns
XID string

Field Documentation

const std::size_t Graph::INVALID_GRAPH_INDEX = 255
static
const std::size_t Graph::MAX_XIDS_IN_ALL_PATHS = 30
static

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