atm_switches.h

Two types are switches are being implemented in our model of the atm-layer. The output Buffer switch and the Shared memory switch.

class ATMOutputBuffer

The output buffer switch inherits from the main ATMSwitch class. It is just a simple switch but the buffer limits have been set differently. The traffic from different connections gets queued up in different buffers at the output port.

class ATMSharedBuffer

The shared memory switch also inherits from the main ATMSwitch, but it implements logical queues which share the same buffer space. When a particular connection is closed its queue vanishes from the memory of the queue.

atm_switches.cc

This class is used for identifying the switches. It operates on swwing the following sort of commands at the test-suite.tcl file. The above commands are used in the input file when creating the specifics for the atmnetwork. This command

set n1 [ns node atm-switch output early]
     set n2 [ns node atm-switch shared simple]

The set n1 command creates an output buffer switch, which implements early packet discard. On the other hand the set n2 command sets the node with the at-switch which is shared memory and implements the simple packet discard algorithm. Upon finding the atm-switch keyword, it matches whether the type of the switch is there or not, then it returns the particular switch with the specified packet discard algorithm implemented at the buffer.

void ATMOutputBuffer::set_buffer_limit

The buffer_size is equally divided accross both the atmlinks and the dummy external links.

void ATMOutputBuffer::set_buffer_limit

The buffer size is the queue limit. The buffer limit in the shared memory switch is the size of the buffer since the buffer is shared by all the connections.

atmaal.h

In real life the AAL layer needs to keep record of all the cells in a particular packet from a connection. In our design we only need the last cell received. This is valid since the aal layer is separate for every source. So from one source cells from two different packets will arrive in the same sequence i.e. the cells from the two packets would not overlap. Thus only looking at the next cell, if it is our of sequence we can empty the aal buffer.

Class ATMAal

Class Variables.

int flag_ This is the buffer that is used to indicate the state of the buffer. It shows a 0 if the buffer is empty and a 1 if the buffer is full.

int seq_no_ This is the private variable that shows the sequence number of the cell, and keeps record of it in the ATM Adaptation layer.

int tcp_seq_ TCP packet sequence number

int tcp_port_ . The sequence number of the packet and its port number identify whether the cells belong to the same packet and connection or not. Since the port number is unique to a particular connection. We need the port number to identify the cells of the packet because two packets from different agents i.e. ( different port numbers ) can have the same sequence number.

int tcp_addr The address of the particular node with respect to the topology of the network. This is necessary alongwith the tcp_port_ number of two cells for them to be in sequence.

Functions

ATMAal::ATMAal()

This is the constructor, which initializes all the above mentioned attributes of the ATM adaptation layer.

int ATMAal::Receive_Cell(ATMCell* cell)

This is the main function of the ATM Adaptation layer to reassemble the cells coming in and converting them into TCP/IP packets. This function receives a cell and returns whether a packet is received or not, if it is then it returns a 0 else it returns a 1. The function checks if the cell received has sequence number 1, if it is so it means it is the first cell of any pacekt, so it inserts the cell into the buffer and marks the buffer full. If it is theonly cell of the pacekt then return full. Else wait for other sequence numbers of the same packet.

If the bufferis empty i.e. the flag is = 0, and the packet is not of sequence number 1 then it is supposed to be discarded, since the AAL layer is not supposed to recover the pacekt it is just supposed to mark it and discard it.

Now if the cell that comes is the next one in sequence then it is inserted. If again this is the last sequence number of the cell then return full and the buffer is marked empty. Else the expected sequence number is advanced and the buffer is marked full.

atmcmd.cc

User input command is translated into the command function by identifying the keyword "connect".

static class ATMCommand:public TclObject

This class inherits from the TclObject class and returns an atm_cmd object.

int ATMCommand::command(int argc, const char*const* argv)

This handles the command for connecting a tcp node to an atmnode e.g, it responds to user input of the following sort in the test-suite.tcl file.

ns connect $tcpnode $atmnetwork $atmnode

atmdiscard.h

This file includes the atmswitch.h which follows logically as well since all the packet discard algorithms are supposed to be implemented at the buffer at the switch.

The set of classes included in this file are meant for switches of various types and their discard algorithms. Given the current buffer, current port, current cell they return whether to discard the cell or not.

The simple output and shared buffer swtich classes inherit from the DiscardAlgorithm class. These implement the Simple discard algorithm on the output and shared memory switches.

The early output and shared memory switch classes ineherit from the Discard Algorithm class. These implement the Early Packet discard algorithm on the Shared memory and output buffer switches.

atmdiscard.cc

static class ATMOutputDiscardMatcher

This matcher class inherits from the base Matcher class. It is used to match the user input. These are particularly used to identify the discard algorithm. "output" specifies that it is for output buffer and "simple" and "early" identify the discard algorithm.

static class ATMSharedDiscardMatcher

This does the same thing as the previous function but for the Shared Memory switch instead of the Output buffer switch.

int SimpleOutputBuffer::check_discard

This function implements the Simple discard algorithm at the Output Buffer switch. When the individual queue of a port ( connection ) is full, it starts discarding the packets of that particular connection. The function returns a 1 if the packet is supposed to be discarded and a 0 if it is not to be discarded.

int SimpleSharedBuffer::check_discard

This function implements the Simple discard algorithm at the Shared Memory switch. When the combined total of the port queues is full. The function returns a 1 if the packet is supposed to be discarded and a 0 if it is not to be discarded.

EarlyOutputBuffer

Set weight to the default weight value.

int EarlyOutputBuffer::check_discard

If the percentage weight of the queue is full then the incoming UBR cells are discarded. But if all the queue is full then all the cells from all the connections are discarded. But the queue is examined at the specified port given as argument.

int EarlySharedBuffer::check_discard

If a percentage ( weight ) of the queue is full then discard the incoming UBR cells. ELse if all the queue is full then discard all the cells. The difference between this type of discard and that implemented on the Output Buffer is that in this type of switch the whole buffer is examined rather than a part of the buffer as in the previous one. This function returns a 0 or a 1 depending on whether the cell is to be discarded or not.

atmlink.h

class ATMLink

The atmlink inherits from the base link class. The difference between this class and all the other classes is that the end nodes in this case are the atm nodes, and also the transmission time of the cells from end to end is fixed. The transmission time is fixed due to the standard characteristic that the cell size of the ATM cell is fixed i.e. it is 53 bytes. The atmlinks are slotted in nature they are synchronized and start at the same time i.e. 0.0, so a cell can only get on a link if its time is a multiple of the size of the slot.

The link is identified by the end nodes, so the attribute ATMNode* neighbour identifies the end node for the particular link.

double start This attribute gives the start time at which a cell can get on a particular link. If teh time at which teh cell is supposed to get on the link is not a multiple of the slot size, it is adjusted so that it becomes one and meets the criterion.

atmlink.cc

static class ATMLinkMatcher

This class inherits from the base matcher class. It is used for identifying the ATMLink. The type "atm" identifies it to be an ATMLink. It matches with the input and creates a matcher_atm_link;

ATMLink::ATMLink()
This is the constructor for the ATMLink class. It initializes the private members of the ATMLink class the neighbour and the starting time of the links to 0.0.

inline void ATMLink::neighbour(ATMNode* p)

This constructor sets the neighbouring to the ATMNode p passed to it as a argument. It also initializes the destination address to the address of the node given to it as an argument. This too is a sort of a constructor.

void ATMLink::handle(Event* e)

This is the handle function for the ATMLink class. It handles teh event that is passed to it. Its main function is to find the slot size. Then it schedules the time at which the cell is supposed to get off the link and reach the other end. Since there is a restriction on slotted ATMLinks that cells can only get on and off the links on a given slot. The slotsize is calculated by dividing the total number of bits in a cell i.e. ( 53* 8 = 424 ) by the bandwidth of the link which is in bytes per second so this gives the slot size in seconds. Then an instance of the Scheduler is created. The current time cur_time is set equal to the time of the scheduler. If this curr_time is less than the start time of the link, then current time is assigned equal to the start time. Then the slot size is added to the current time. If time lies between two slots it is upgraded so that it falls on the next slot. Then the neigbour, the cell itself, the next slot time and the delay is passed to the schedule function of the newly created scheduler object. The slotsize is added to the time for which the link will remain busy.

int ATMLink::command(int argc, const char*const* argv)

This function is used to override the "install" command to be between two ATMNodes.  It checks that both the ends are atmnodes, if the source and destination are the same then there is an error. If not then the destination is made the neighbour. The link is then added to the source. Otherwise the command is returned to the command function in the above hierarchy.

atmnetwork.h

This class represents a complete ATM Network. It is derived from the Node class so that the current TCP remains unaffected while it can internally handle packets the way it wants to. The reason for not making the atm-node inherit from the node because it would have interfered with the functioning of normal nodes. it would also have added redundancy to the structures.

ATMNode** nodes This is a list of all switches and sources counted as ATMNodes in the ATMNetwork.

int* map This is used to identify the external TCP connections corresponding to the ATMNetwork connections. The map variable, when given a TCP node address returns an ATM Node index. map[tcpnode address]->ATMNode index

double* earliest_start The earliest time a packet a packet can arrive from any link.

int curr_nodes This gives the total number of nodes in the network at that particular moment.

int max_nodes This give the total number of nodes that can possibly be in the network, or the maximum number of nodes that can be declared. This is arranged such that whenever the current number of nodes is equal to the max_nodes, it is doubled, so that the network is not constrained by it. Hence the only limitation on increasing the total number of the nodes in the network is that of the memory.

ATMLink *** link_table This is a table of ATMLinks contained in the network. The links are stored in the form of the source and destination in the table. Hence each link has a unique source and destination. So given a destination and a source number it returns the corresponding link. link_table[src][dest]-> the link.

ATMRouteLogic* routelogic This is gives the routing logic that is supposed to be followed by the ATM network. Route logic knows the topology of the whole network , it is atatched to the network, and the routing logic is implemented to the whole network.

atmnetwork.cc

static class ATMNetworkMatcher:public Matcher

This is the matcher function of the ATMNwork class. It inherits from the main Matcher class. This class identifies that "ns node atm-network $route" is actually creating an object of type ATMNetwork.

int ATMNetwork::lookup_id(const char * id)

It is a function which when given the name of the object returns the index of the object with reference to the whole network. It looks up the name is located by using the name() function and comparing with all the values in the list of nodes. If it is found then the index of the object in the list of nodes is returned.

int ATMNetwork::attach(Node * t, ATMNode* a)

This function records that which TCP Node is attached to which ATM Node. It uses the TclObject::name() function to identify objects. IF the function is successful in recording the name of the function it returns 1 else it returns a 0. The function actually looks in the map function ( it gives it the address of the node ) and it returns an index . The function then add the dummy link to the node and then returns.

int ATMNetwork::command(int argc, const char*const* argv)

This function is called from the Tcl input and by matching the user command performs the actions associated with it. Upon coming accross the "route" keyword it calls the routelogic object to Associate a routing logic with the network. If it is unable to find the object it returns false, otherwise it returns ok.

Upon the "add-node" command it looks up the node and adds it to the network. As a last alternative if the ATMNetwork is unable to handle this command it passes it over to the class previous in hierarchy (i.e. one above it ), in this case (Node::command(argc, argv)).

void ATMNetwork::add_node(ATMNode * node)

This function is called through the command function upon seeing the add_node keyword. It actually adds the ATMNode to the network. If the nodes reach their maximum then simply double the array. i.e If teh current number of nodes becomes equal to teh maximum number of nodes, the maximum number of nodes is doubled.and all the nodes are initialized.

Then the ATM adaptation layer corresponding to that particular report is initialized. Then the address of the node is set to be the current sequence number. The node is made to point to the network so that it knows the network to which it is associated with. At the same time the node is added to the list of nodes at the index of the current number of nodes. The route logic object is also initialized. It is made to the current number of nodes, the links and the routing table.

void ATMNetwork::handle(Event * e)

This function is responsible for handling the functions particularly generated for this network. If a packet comes it is broken and passed on to the appropriate ATM Node. When a packet is recovered the outgoing packet is handed over to the TCP network. When a packet enters the network for the first time its destination is pointing to its node. It is broken into 47 bytes but it is transmitted at a rate of 53 bytes to the atmnode ( this is after the header is attatched. At the same time the destination is changed to some other destination rather than the current node which is initally the case. When this packet arrive again its destination is changed and it is treated like just another TCP packet. If the destination address of the packet is not equal to the current node it means this is a recovered packet which is about to leave the ATMNetwork. If this is the case then its original destination is restored it is signalled to the TCP network. If the destination address is the address of the current node then the packet is a new packet entering the packet for the first time. It is handled as follows.

Its local destination is changed to one more than the current address. This packet is broken into cells and its source and destination are altered as compared. The map function called for the source of the ATMCell gives the ATMNode from which this particular packet should be sent. The outgoing TCP node gives the ATM destination. The cell priority is set to 0 since all TCP traffic is considered to be of UBR ( Unspecified bit rate ). The flag of the cell that indicates whether the cell is queued or not is also set to 0. A new link which is the input ATM link is also created. The transmission time of the cell is calculated on the basis of 53 bytes ( 47 + the headers attatched ). Routing tables are determined based on the routing strategy established. This also returns any delay associated with the establishing of the routes. If there are multiple packets arriving on the same link ( i.e. implying queuing ) the earliest_start function gives the time for which the packet must wait before it can be handled. The packet is broken into the number of cells it is supposed to be broken into then the next earliest start time is also calculated. After this the packet is handled as a normal TCP packet, using Multicast or unicast forward routing algorithms.

void ATMNetwork::add_link(ATMLink* link, int src, int dst )

This function adds teh link to the list o fall links in a network. A link can only have a unique pair of ends, i.e. there cannot be multiple links between two nodes. The link_table function returns the particular link if given a source and a destination.

atmnode.h

ATMNetwork

This is the parent class for all the nodes in the network. This includes the ATM traffic sources and the switches. It is derived from the NsObject and Handler classes so that they ca handle packets and also accept tcl commands.

ATMAal* aal This is conceptually how the ATM Adaptation layer is implemented.

int total_nodes This gives the total number of nodes in the network.

int no_links_ This gives the total number of links connected in the network.

int addr_ This gives the address of the node.

ATMNetwork *network_ This serves two purposes. Firstly the node should know which network it is pointing to. Since after a packet is complete it is handed over to this network. This network handles the packet. Also the node is supposed to refer to the network when it is in need for resources.

ATMLink ** links_ The list of outgoing links from the node. These are all the atm links emerging from the node, this does not include any other links

struct Dummy Links

This is a component of the linked list which contains the dummy lists. It has two attributes to it. One is the address of the external node, and the other is the port number of the switch. Each individual component also contains a pointer to the next link.

DummyLinks* dummy_ This is a list of all the dummy links ( external links ).

int dummy_count This gives the total number of dummy nodes attatched to the node.

int * port_table The list of ports in this switch.

atmnode.cc

ATMNode::ATMNode()

This is the ATMNode constructor. The number of ATMLinks is initially 16 and doubles whenever the capacity reaches its maximum. The port table is also created for 16 entries corresponding to the number of ATMLinks.

ATMNode::ATMNode(int tn)

This is another constructor which changes the default value of the total number of nodes equal to the number given to it as argument.

void ATMNode::init_aal(int tn)

This function initializes the aal layer. This function is invoked by the ATMNetwork whenever there is a change in the total number of nodes in the network. This function initializes the total_nodes equal to the number given as argument. Then creates an object of type ATMAal of size equal to the total number of nodes.

void ATMNode::add_dummy_link(int ad)

This function adds a dummy link to this node for the specified address given to it as an argument. This function is invoked by the network when it connects a tcpnode to an atmnode.

void ATMNode::get_dummy_port(int ad)

This function searches for the address in the list of dummy ports and returns the port number of the queue. This function gets the address of the node to be searched. It them compares and searches for it in teh list of nodes. It returns a -1 if it does not find the required port not. if it does then it returns the port number of the queue.

void ATMNode::add_link(int ad)

This function adds a link to the particular node for which it is invoked. If the total number of nodes in the atm network reaches the maximum number that there can be, the maximum number in the network is doubled. It updates the network since a new node is being added to the network. It also makes a new entry into the list of links. Apart from this the port_table is also increased. The total number of links is also incremented.

atmroute.h

class ATMRouteLogic: public TclObject

This is the class that inherits from the main TclObject class. This class establishes the route from all sources to all destinations. The routing logic can be used any which way it is required as.

ATMNode** nodes_ This gives the total number of nodes in the network.

int curr_nodes_ This gives the total number of nodes currently there in the network.

ATMLink *** lnk_tbl_ This is a link_table which when given a source and a destination, returns a link.

atmroute.cc

class ATMMinHop: public ATMRotueLogic

This clas uses the minimum hop algorithm between all sources and all destinations. At the very first invokation the algorithm tries to establish paths from every node to every other node i.e. all to all paths. If a node is added subsequently i.e. after adding the routes are computed, the done is set to 0 and the routes are established once again.

class ATMMinHopRouteLogicMatcher: pubic Matcher

This class inherits from the matcher clss. This class class identifies the match with the identification "min-hop". It matches this keyword at the ns_default.tcl file and matches it appropriately.

int ATMMinHop::command(int argc, const char*const* argv )

This matches the command at the user input and invokes the appropriate function. In this case, if it comes accross a "compute-routes" keyword it invokes compute_routes() function.

The other keyword that it matches is "insert" it inserts the node that is added to the network topology.

int ATMMinHop::establish_route(int src, int dst)

This function creates an all to all shortest paths and returns 0 as the delay for time taken in establishing the routing tables.

atmsrc.h

class ATMSource:public ATMNode

The class ATMSource inherits from the main ATMNode class.

static class ATMSourceMatcher:public Matcher

This is the matcher class for the ATM source. It simply matches the object atm-source declared by the tcl input. Upon matching the keyword it returns the object ATMSource.

void ATMSource::handle(Event* x)

This function is supposed to handle the events meant for the ATMSource to handle. If the node for which the function gets invoked is the destination node as well then the event is handed over to the appropriate AALLayer. If the packet is complete ( i.e. all the cells pertaining to the packet have been received ) then an intermediate event is generated. This intermediate event is handled by the atm network to return the packet. If the node for which the function is invoked is the source then the packet is routed.

atmswitch.h

class ATMSwitchBuffer

This class is used to implement the buffer for the switch. Different switching architectures can be implemented by making them inherit from the main buffer class. We are not required to store the actual cells, only the total count of the cells is fine since it serves the purpose, and saves the memory requirements as well.

int * qsize gives the current size of the queue

int total_q gives the sum of all the queues

int ports This gives the total number of ports.

int qlimit_ This is the limit assigned to the queue which is used to compare against in deciding which packet to discard and which one to let go.

class DiscardAlgorithm: public NsObject

This class inherits from the NsObject class. This is the generic DiscardAlgorithm class. All the discard algorithms can be implemented by inheriting from this generic class. The only difference between the generic DiscardAlgorithm class and those inheriting from it is that the only functions that determine ( by looking at the buffer and the cell ) whether the cell is to be discarded or not. which is the check_discard( const ATMSwitchBuffer* , const ATMCell*, int).

class ATMSwitch: public ATMNode

This is the generic ( base ) class for all ATMSwitches. All the subsequent classes of switches i.e. the output buffer and shared memory switches inherit from this class after slight variation in the functions.

int buffer_size_ This gives the buffer size of the switch in terms of number of cells.

int qlimit This gives the threshold value against which the discard decision is taken or ruled out.

long int no_of_cells_lost This gives the total number of cells lost in the buffer of the switch.

long int no_of_cells_passed This gives the total number of cells passed through the switch buffer.

atmswitch.cc

ATMSwitch::ATMSwitch()
This is the constructor for the ATMSwitch class. It declares a new buffer of the type ATMSwitchBuffer. It also initialises the link_int with the name of the switch ns_switch, the buffer-size, and

ATMSwitch::add_link(ATMLink* link)

This function adds a link to the switch. It also updates the buffer size allocated to each port on the addition of the new link. This also sets the buffer limit which is used in implementing discard decisions.

ATMSwitch::command(ATMLink* link)

This function interprets the user input from the ns_default.tcl file and interprets it and takes appropriate action. This command function reacts to one of the following commands in the ns_default.tcl files. e.g

$switch discard-algo $discard

On getting the keyword discard-algo, looks up the name in the list of algorithms and sets the appropriate discard algorithm. The return value of the function is assigned to the discard variable.

$switch buffer-size $size

This line is interpreted so as to set the buffer size. If none of the options are matching, then this function returns to the command function in the class one step above in object hierarchy.i.e. the command function of the NsObject::command.

ATMSwitch::handle(Event* x)

The main purpose of this function is to handle the event passed to it as an argument. If the node for which this function is invoked is the destination and the cell is currently queued up then the event is passed on to the appropriate ATM adaptation layer. If the current node is the destination but the cell is not queued the teh cell is to be queued with teh appropriate port.

If the packet is complete then an intermediate event is generated in the atm network which handles the packet. If the current node is the destination as well as the source then the packet is returned.