Link Class

new($\$\$)
This is the constructor for the Link class. It's called with a link name, a reference to a source, and a reference to a destination. The weight function is called with the source and the dest to calculate the weight of the link. In all cases the connect function is called on the source, so it can update its list of connected nodes. The connect function is also called on the destination if it's a host.

existing(\$)
The existing function creates and returns a copy of an existing link. It's called with a reference to a Link object.

obverse (\$)
The obverse function creates and returns a link that has the source and destination of an existing link in the opposite order. It's called with a reference to a Link object.

name
If the name function is called with zero parameters it returns the name of the link. If it's called with a parameter it sets the link's name to that parameter and returns the new name.

endpoints
If the endpoints function is called with zero parameters it returns references to the source and destination objects of the link. If it's called with parameters it attempts to set the source to the first parameter and the destination to the second parameter. If both parameters are Host objects the original link is returned unchanged. Otherwise disconnect is called on the old source so it knows it's losing this link. If the old destination was a host disconnect is called on it as well. The source and destination are then updated to the parameters, and connect is called on the new source. If the new destination is a host connect is called on it as well. The weight function is then called with the new source and destination to update the link's weight. The endpoints function then returns an array containing references to the new source and new destination.

weight
The weight function is called with references to two Host or Router objects. It calculates and returns a weight based on the coordinates of those objects.


Host Class

new
This is the constructor for the Host class. It takes as arguments a name, vertical coordinate, horizontal coordinate, weight, and link number.

existing ($)
The existing function creates and returns a copy of an existing host. It's called with a reference to a Host object.

weight
If the weight function is called with zero parameters it returns the weight of the host. If it's called with a parameter it sets the host's weight to that parameter and returns the new weight.

name
If the name function is called with zero parameters it returns the name of the host. If it's called with a parameter it sets the host's name to that parameter and returns the new name.

v_coord
If the v_coord function is called with zero parameters it returns the v_coord of the host. If it's called with a parameter it sets the host's v_coord to that parameter and returns the new v_coord.

h_coord
If the h_coord function is called with zero parameters it returns the h_coord of the host. If it's called with a parameter it sets the host's h_coord to that parameter and returns the new h_coord.

connected
The connected function returns 1 if the host is connected to a router, else it returns 0.

router
The router function returns a reference to the Host's connected Router, else it returns undef if the Host isn't connected to a Router.

link
The link function returns a reference to the Host's connected Link, else it returns undef if the Host doesn't have a Link.

connect
The connect function is called whenever a link is created involving this Host. It takes references to a Router object and a Link object, and sets them as the Host's connected router and link. It also sets the host's connected status to true.

disconnect
The disconnect function clears this Host's connected router and link, and sets its connected status to false.


Router Class

new
This is the constructor for the Router class. It takes as arguments a name, a horizontal coordinate, a vertical coordinate, a weight, and an array of link names.

existing (\$)
The existing function creates and returns a copy of an existing router. It's called with a reference to a Router object.

nhosts
The nhosts function returns the number of connected hosts.

nrouters
The nrouters function returns the number of connected routers.

nlinks
The nlinks function returns the number of connected links.

weight
If the weight function is called with zero parameters it returns the weight of the router. If it's called with a parameter it sets the router's weight to that parameter and returns the new weight.

name
If the name function is called with zero parameters it returns the name of the router. If it's called with a parameter it sets the router's name to that parameter and returns the new name.

h_coord
If the h_coord function is called with zero parameters it returns the h_coord of the router. If it's called with a parameter it sets the router's h_coord to that parameter and returns the new h_coord.

v_coord
If the v_coord function is called with zero parameters it returns the v_coord of the router. If it's called with a parameter it sets the router's v_coord to that parameter and returns the new v_coord.

hosts
If the hosts function is called with zero parameters it returns the router's list of linked hosts. If it's called with a parameter it sets the router's list of linked hosts to that parameter and returns the new list.

routers
If the routers function is called with zero parameters it returns the router's list of linked routers. If it's called with a parameter it sets the router's list of linked routers to that parameter and returns the new list.

links
If the links function is called with zero parameters it returns the router's list of connected links. If it's called with a parameter it sets the router's list of connected links to that parameter and returns the new list.

link
The link function is called with either a reference to a Link object or the name of a link. It returns a reference to that link if it's found in the Router's list of connected links, else it returns undef.

host
The host function is called with either a reference to a Host object or the name of a host. It returns a reference to that host if it's found in the Router's list of linked hosts, else it returns undef.

router
The router function is called with either a reference to a Router object or the name of a router. It returns a reference to that router if it's found in the Router's list of linked routers, else it returns undef.

connect
The connect function is typically called from a Link constructor with parameters of a reference to a destination and a reference to a Link object. It adds the link to the router's list of connected links, and adds the destination to either the list of linked hosts or routers, depending on what the type of the destination is.

disconnect
The disconnect function is called with a reference to a Link object and a reference to a destination. It removes the Link from the router's list of connected links, and removes the destination from either the list of linked hosts or routers, depending on what the type of the destination is.