-
Notifications
You must be signed in to change notification settings - Fork 18
Nodes
A node represents a host or a router in the network simulation. It contains a list of links, a set of protocol handlers, and a forwarding table. When the node receives a packet, it uses the destination address to determine if the packet has arrived at its destination. If so, then the node calls the protocol handler specified by the packet's protocol field. Otherwise, it uses the destination address to look up a matching entry in the forwarding table, which specifies a link to forward the packet toward its destination.
add_link(link)
delete_link(link)
Adds or delete link for the node.
add_protocol(protocol,handler)
delete_protocol(protocol):
Add or delete a protocol handler. A protocol is a string identifier and a handler is an object. When a packet arrives at its destination, the protocol field in the packet specifies which handler object should be called. The node calls the handle_packet() method on this object.
add_forwarding_entry(address,link)
delete_forwarding_entry(address,link)
Add or delete a forwarding entry for the node. The forwarding entry is given by an integer address, and specifies which link object should be used to reach that address.
By convention, any object can be given a packet to handle using its handle_packet() method. When the handle_packet() method is called on a node, it compares the packet's destination address to the address for each of its links. If a match is found, the packet belongs to this node, so the corresponding packet handler is called, based on the protocol field in the packet. If no match is found, the node uses the forwarding table to send the packet on the link that leads toward the packet's destination.