15.3.3 Channel Class in C++
In C++, the class Channel extends the Connector object
with several new methods to
support a variety of MAC protocols. The class is defined as follow in
~ns/channel.h:
class Channel : public Connector {
public:
Channel();
void recv(Packet* p, Handler*);
virtual int send(Packet* p, double txtime);
virtual void contention(Packet*, Handler*);
int hold(double txtime);
virtual int collision() { return numtx_ \> 1; }
virtual double txstop() { return txstop_; }
. . .
};
The important methods of the class Channel are:
- txstop() method returns the time when the channel will become
idle, which can be used by the MAC to implement carrier sense.
- contention() method allows the MAC to contend for the channel
before sending a packet. The channel then use this packet to signal the
corresponding Mac object at the end of each contention period.
- collision() method indicates whether a collision occurs
during the contention period. When the Channel signal the end of
the contention period, the MAC can use the collision() method to
detect collision.
- send() method allows the MAC object to transmit a packet on the
channel for a specified duration of time.
- hold() method allows the MAC object to hold the channel for a
specified duration of time without actually transmitting any packets.
This is useful in simulating the jamming mechanism of some MAC
protocols.
Tom Henderson
2014-12-17