14.5.3 Mac Class in C++

In C++, the Mac class derives from Connector. When the recv() method gets a packet, it identifies the direction of the packet based on the presence of a callback handler. If there is a callback handler, the packet is outgoing, otherwise, it is incoming.

   class Mac : public Connector {
   public:
        Mac();
        virtual void recv(Packet* p, Handler* h);
        virtual void send(Packet* p);
        virtual void resume(Packet* p = 0);
                . . .
    };

When a Mac object receives a packet via its recv() method, it checks whether the packet is outgoing or incoming. For an outgoing packet, it assumes that the link-layer of the sender has obtained the destination MAC address and filled in the macDA
_
field of the MAC header, hdr_mac. The Mac object fills in the rest of the MAC header with the source MAC address and the frame type. It then passes the packet to its send() method, which carries out the medium access protocol. For the basic Mac object, the send method calls txtime() to compute the transmission time, then invokes Channel::send to transmit the packet. Finally, it schedules itself to resume after the transmission time has elapsed.

For an incoming packet, the MAC object does its protocol processing and passes the packet to the link-layer.

Tom Henderson 2011-11-05