public class Router extends NetworkElement
The bottleneck resource that we study using this router is the memory space, which determines the maximum possible queue length (the queuing capacity). If more packets arrive than the queue (buffer) can hold, the excess packets are discarded.
The router needs help from the simulator environment to
know about the progression of time. The simulation clock ticking
is signaled by invocation of the method send(NetworkElement, Packet)
.
Every time this method is called, the router performs
the work allowed within the elapsed time.
Currently, this means that the router will hand over the queued
packets in packetBuffer
to their outgoing links (outputPorts
).
Note that this class defines an inner class for output ports
(see Router.OutputPort
).
Simulator
Modifier and Type | Class and Description |
---|---|
protected class |
Router.OutputPort
Inner class for router's output ports.
|
Modifier and Type | Field and Description |
---|---|
private int |
bufferCapacity
The router buffer capacity, in bytes.
|
private int |
currentBufferOccupancy
Current occupancy of the router memory is obtained as
a sum of the packet lengths for all packets currently
queued in the router memory
packetBuffer . |
protected java.util.HashMap<NetworkElement,Link> |
forwardingTable
Router's forwarding table maps the destination node
(found in the Packet header) to the outgoing link.
|
protected java.util.HashMap<Link,Router.OutputPort> |
outputPorts
Output ports associated with the router's links.
|
private java.util.ArrayList<Packet> |
packetBuffer
Router memory for buffered/queued packets.
|
lastTimeProcessCalled, name, simulator
Constructor and Description |
---|
Router(Simulator simulator_,
java.lang.String name_,
int bufferSize_)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addForwardingTableEntry(NetworkElement node_,
Link outgoingLink_)
Adds another entry into the router's forwarding table.
|
int |
getMaxBufferSize()
Accessor for retrieving the packet buffering capacity
of this router.
|
void |
handle(NetworkElement source_,
Packet receivedPacket_)
Buffers the incoming packet in the router memory.
|
void |
process(int mode_)
When this method is called, it is a signal to the router
to transmit packets on their corresponding outgoing links,
if there are any packets buffered in the router memory.
Only the caller knows when sufficient amount of time has elapsed and when it should call this method. |
void |
send(NetworkElement dummySource_,
Packet dummyPacket_)
Currently does nothing.
|
getName, getSimulator
private int bufferCapacity
currentBufferOccupancy
),
the excess packets will be discarded.private int currentBufferOccupancy
packetBuffer
.protected java.util.HashMap<NetworkElement,Link> forwardingTable
protected java.util.HashMap<Link,Router.OutputPort> outputPorts
private java.util.ArrayList<Packet> packetBuffer
bufferCapacity
.
Current memory occupancy is represented by currentBufferOccupancy
.public Router(Simulator simulator_, java.lang.String name_, int bufferSize_)
simulator_
- the runtime environmentname_
- the name given to this routerbufferSize_
- the given buffer size for the router's memory (in bytes).public void addForwardingTableEntry(NetworkElement node_, Link outgoingLink_)
node_
- the network node (hash-table key) with which the specified outgoing link is to be associatedoutgoingLink_
- the outgoing link to be associated with the specified network nodepublic int getMaxBufferSize()
public void handle(NetworkElement source_, Packet receivedPacket_)
bufferCapacity
memory capacity is exceeded,
the input packet will be discarded.handle
in class NetworkElement
source_
- the immediate source of the arrived packetreceivedPacket_
- the packet that arrived on an incoming linkRouter.OutputPort.handleIncomingPacket(NetworkElement, Packet)
,
NetworkElement.handle(NetworkElement, sime.Packet)
public void process(int mode_)
process
in class NetworkElement
mode_
- the processing mode, currently not used and ignoredRouter.OutputPort.transmitPackets()
,
Simulator.run(java.nio.ByteBuffer, int)
public void send(NetworkElement dummySource_, Packet dummyPacket_)
send
in class NetworkElement
dummySource_
- [ignored]dummyPacket_
- [ignored]NetworkElement.send(NetworkElement, Packet)