inet-3.6.4/src/inet/linklayer/xmac/XMacLayer.cc
/**
 * Encapsulates the received network-layer packet into a MacPkt and set all
 * needed header fields.
 */
Encapsulates the received network-layer packet into a MacPkt and set all
needed header fields.
Encapsulates the received network - layer packet into a MacPkt and set all needed header fields .
bool XMacLayer::addToQueue(cMessage *msg)
{
	if (macQueue.size() >= queueLength) {
		EV_DEBUG << "New packet arrived, but queue is FULL, so new packet is"
				  " deleted\n";
		emit(packetFromUpperDroppedSignal, msg);
		delete msg;
		nbDroppedDataPackets++;
		return false;
	}
	XMacFrame *macPkt = new XMacFrame(msg->getName());
    macPkt->setBitLength(headerLength);
    IMACProtocolControlInfo *const cInfo = check_and_cast<IMACProtocolControlInfo *>(msg->removeControlInfo());
    EV_DETAIL << "CSMA received a message from upper layer, name is " << msg->getName() << ", CInfo removed, mac addr=" << cInfo->getDestinationAddress() << endl;
    MACAddress dest = cInfo->getDestinationAddress();
    macPkt->setDest(dest);
    delete cInfo;
    macPkt->setSrc(address);
	assert(static_cast<cPacket*>(msg));
	macPkt->encapsulate(static_cast<cPacket*>(msg));
    EV_DETAIL << "pkt encapsulated, length: " << macPkt->getBitLength() << "\n";
	macQueue.push_back(macPkt);
	EV_DEBUG << "Max queue length: " << queueLength << ", packet put in queue"
			  "\n  queue size: " << macQueue.size() << " macState: "
			  << macState << endl;
	return true;
}
bool XMacLayer :: addToQueue ( cMessage * msg ) { if ( macQueue . size ( ) >= queueLength ) { EV_DEBUG << " " " \n " ; emit ( packetFromUpperDroppedSignal , msg ) ; delete msg ; nbDroppedDataPackets ++ ; return false ; } XMacFrame * macPkt = new XMacFrame ( msg -> getName ( ) ) ; macPkt -> setBitLength ( headerLength ) ; IMACProtocolControlInfo * const cInfo = check_and_cast < IMACProtocolControlInfo * > ( msg -> removeControlInfo ( ) ) ; EV_DETAIL << " " << msg -> getName ( ) << " " << cInfo -> getDestinationAddress ( ) << endl ; MACAddress dest = cInfo -> getDestinationAddress ( ) ; macPkt -> setDest ( dest ) ; delete cInfo ; macPkt -> setSrc ( address ) ; assert ( static_cast < cPacket * > ( msg ) ) ; macPkt -> encapsulate ( static_cast < cPacket * > ( msg ) ) ; EV_DETAIL << " " << macPkt -> getBitLength ( ) << " \n " ; macQueue . push_back ( macPkt ) ; EV_DEBUG << " " << queueLength << " " " \n " << macQueue . size ( ) << " " << macState << endl ; return true ; }
Encapsulates the received network-layer packet into a MacPkt and set all
 needed header fields.
Encapsulates the received network - layer packet into a MacPkt and set all needed header fields .
// queue is full, message has to be deleted
