|
|
| 190 |
m_txMachineState = READY; |
190 |
m_txMachineState = READY; |
| 191 |
m_tInterframeGap = Seconds (0); |
191 |
m_tInterframeGap = Seconds (0); |
| 192 |
m_channel = 0; |
192 |
m_channel = 0; |
|
|
193 |
m_queue = 0; |
| 194 |
m_queueInterface = 0; |
| 193 |
|
195 |
|
| 194 |
// |
196 |
// |
| 195 |
// We would like to let the attribute system take care of initializing the |
197 |
// We would like to let the attribute system take care of initializing the |
|
|
| 217 |
NS_LOG_FUNCTION_NOARGS (); |
219 |
NS_LOG_FUNCTION_NOARGS (); |
| 218 |
m_channel = 0; |
220 |
m_channel = 0; |
| 219 |
m_node = 0; |
221 |
m_node = 0; |
|
|
222 |
m_queueInterface = 0; |
| 220 |
NetDevice::DoDispose (); |
223 |
NetDevice::DoDispose (); |
| 221 |
} |
224 |
} |
| 222 |
|
225 |
|
| 223 |
void |
226 |
void |
|
|
227 |
CsmaNetDevice::NotifyNewAggregate (void) |
| 228 |
{ |
| 229 |
NS_LOG_FUNCTION (this); |
| 230 |
if (m_queueInterface == 0) |
| 231 |
{ |
| 232 |
// Verify if this is a valid netdevice queue interface and if the |
| 233 |
// netdevice queue interface was not set before. |
| 234 |
Ptr<NetDeviceQueueInterface> ndqi = GetObject<NetDeviceQueueInterface> (); |
| 235 |
if (ndqi != 0) |
| 236 |
{ |
| 237 |
m_queueInterface = ndqi; |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
NetDevice::NotifyNewAggregate (); |
| 242 |
} |
| 243 |
|
| 244 |
void |
| 224 |
CsmaNetDevice::SetEncapsulationMode (enum EncapsulationMode mode) |
245 |
CsmaNetDevice::SetEncapsulationMode (enum EncapsulationMode mode) |
| 225 |
{ |
246 |
{ |
| 226 |
NS_LOG_FUNCTION (mode); |
247 |
NS_LOG_FUNCTION (mode); |
|
|
| 553 |
m_backoff.ResetBackoffTime (); |
574 |
m_backoff.ResetBackoffTime (); |
| 554 |
m_txMachineState = READY; |
575 |
m_txMachineState = READY; |
| 555 |
|
576 |
|
|
|
577 |
Ptr<NetDeviceQueue> txq; |
| 578 |
if (m_queueInterface) |
| 579 |
{ |
| 580 |
txq = m_queueInterface->GetTxQueue (0); |
| 581 |
} |
| 582 |
|
| 556 |
// |
583 |
// |
| 557 |
// If there is another packet on the input queue, we need to start trying to |
584 |
// If there is another packet on the input queue, we need to start trying to |
| 558 |
// get that out. If the queue is empty we just wait until someone puts one |
585 |
// get that out. If the queue is empty, wake the queue disc. |
| 559 |
// in. |
|
|
| 560 |
// |
586 |
// |
| 561 |
if (m_queue->IsEmpty ()) |
587 |
if (m_queue->IsEmpty ()) |
| 562 |
{ |
588 |
{ |
|
|
589 |
if (txq) |
| 590 |
{ |
| 591 |
NS_LOG_DEBUG ("The device queue is being woken up (" << |
| 592 |
m_queue->GetNPackets () << " packets and " << |
| 593 |
m_queue->GetNBytes () << " bytes inside)"); |
| 594 |
txq->Wake (); |
| 595 |
} |
| 563 |
return; |
596 |
return; |
| 564 |
} |
597 |
} |
| 565 |
else |
598 |
else |
|
|
| 570 |
m_snifferTrace (m_currentPkt); |
603 |
m_snifferTrace (m_currentPkt); |
| 571 |
m_promiscSnifferTrace (m_currentPkt); |
604 |
m_promiscSnifferTrace (m_currentPkt); |
| 572 |
TransmitStart (); |
605 |
TransmitStart (); |
|
|
606 |
|
| 607 |
// We have dequeued a packet, inform BQL and start the queue if there is |
| 608 |
// room for another packet. |
| 609 |
if (txq) |
| 610 |
{ |
| 611 |
txq->NotifyTransmittedBytes (m_currentPkt->GetSize ()); |
| 612 |
|
| 613 |
if ((m_queue->GetMode () == Queue::QUEUE_MODE_PACKETS |
| 614 |
&& m_queue->GetNPackets () < m_queue->GetMaxPackets ()) |
| 615 |
|| (m_queue->GetMode () == Queue::QUEUE_MODE_BYTES |
| 616 |
&& m_queue->GetNBytes () + m_mtu <= m_queue->GetMaxBytes ())) |
| 617 |
{ |
| 618 |
NS_LOG_DEBUG ("The device queue is being started (" << |
| 619 |
m_queue->GetNPackets () << " packets and " << |
| 620 |
m_queue->GetNBytes () << " bytes inside)"); |
| 621 |
txq->Start (); |
| 622 |
} |
| 623 |
} |
| 573 |
} |
624 |
} |
| 574 |
} |
625 |
} |
| 575 |
|
626 |
|
|
|
| 624 |
// |
675 |
// |
| 625 |
NS_ASSERT_MSG (m_currentPkt == 0, "CsmaNetDevice::TransmitReadyEvent(): m_currentPkt nonzero"); |
676 |
NS_ASSERT_MSG (m_currentPkt == 0, "CsmaNetDevice::TransmitReadyEvent(): m_currentPkt nonzero"); |
| 626 |
|
677 |
|
|
|
678 |
Ptr<NetDeviceQueue> txq; |
| 679 |
if (m_queueInterface) |
| 680 |
{ |
| 681 |
txq = m_queueInterface->GetTxQueue (0); |
| 682 |
} |
| 683 |
|
| 627 |
// |
684 |
// |
| 628 |
// Get the next packet from the queue for transmitting |
685 |
// Get the next packet from the queue for transmitting. If the queue is |
|
|
686 |
// empty, wake the queue disc. |
| 629 |
// |
687 |
// |
| 630 |
if (m_queue->IsEmpty ()) |
688 |
if (m_queue->IsEmpty ()) |
| 631 |
{ |
689 |
{ |
|
|
690 |
if (txq) |
| 691 |
{ |
| 692 |
NS_LOG_DEBUG ("The device queue is being woken up (" << |
| 693 |
m_queue->GetNPackets () << " packets and " << |
| 694 |
m_queue->GetNBytes () << " bytes inside)"); |
| 695 |
txq->Wake (); |
| 696 |
} |
| 632 |
return; |
697 |
return; |
| 633 |
} |
698 |
} |
| 634 |
else |
699 |
else |
|
|
| 639 |
m_snifferTrace (m_currentPkt); |
704 |
m_snifferTrace (m_currentPkt); |
| 640 |
m_promiscSnifferTrace (m_currentPkt); |
705 |
m_promiscSnifferTrace (m_currentPkt); |
| 641 |
TransmitStart (); |
706 |
TransmitStart (); |
|
|
707 |
|
| 708 |
// We have dequeued a packet, inform BQL and start the queue if there is |
| 709 |
// room for another packet. |
| 710 |
if (txq) |
| 711 |
{ |
| 712 |
txq->NotifyTransmittedBytes (m_currentPkt->GetSize ()); |
| 713 |
|
| 714 |
if ((m_queue->GetMode () == Queue::QUEUE_MODE_PACKETS |
| 715 |
&& m_queue->GetNPackets () < m_queue->GetMaxPackets ()) |
| 716 |
|| (m_queue->GetMode () == Queue::QUEUE_MODE_BYTES |
| 717 |
&& m_queue->GetNBytes () + m_mtu <= m_queue->GetMaxBytes ())) |
| 718 |
{ |
| 719 |
NS_LOG_DEBUG ("The device queue is being started (" << |
| 720 |
m_queue->GetNPackets () << " packets and " << |
| 721 |
m_queue->GetNBytes () << " bytes inside)"); |
| 722 |
txq->Start (); |
| 723 |
} |
| 724 |
} |
| 642 |
} |
725 |
} |
| 643 |
} |
726 |
} |
| 644 |
|
727 |
|
|
|
| 960 |
return false; |
1043 |
return false; |
| 961 |
} |
1044 |
} |
| 962 |
|
1045 |
|
|
|
1046 |
Ptr<NetDeviceQueue> txq; |
| 1047 |
if (m_queueInterface) |
| 1048 |
{ |
| 1049 |
txq = m_queueInterface->GetTxQueue (0); |
| 1050 |
} |
| 1051 |
|
| 963 |
Mac48Address destination = Mac48Address::ConvertFrom (dest); |
1052 |
Mac48Address destination = Mac48Address::ConvertFrom (dest); |
| 964 |
Mac48Address source = Mac48Address::ConvertFrom (src); |
1053 |
Mac48Address source = Mac48Address::ConvertFrom (src); |
| 965 |
AddHeader (packet, source, destination, protocolNumber); |
1054 |
AddHeader (packet, source, destination, protocolNumber); |
|
|
| 972 |
// |
1061 |
// |
| 973 |
if (m_queue->Enqueue (Create<QueueItem> (packet)) == false) |
1062 |
if (m_queue->Enqueue (Create<QueueItem> (packet)) == false) |
| 974 |
{ |
1063 |
{ |
|
|
1064 |
// Enqueue may fail (overflow). This should not happen if the traffic |
| 1065 |
// control module has been installed. Anyway, stop the tx queue, so that |
| 1066 |
// the upper layers do not send packets until there is room in the queue |
| 1067 |
// again. |
| 975 |
m_macTxDropTrace (packet); |
1068 |
m_macTxDropTrace (packet); |
|
|
1069 |
if (txq) |
| 1070 |
{ |
| 1071 |
NS_LOG_ERROR ("Device queue full when the queue is not stopped! (" << |
| 1072 |
m_queue->GetNPackets () << " packets and " << |
| 1073 |
m_queue->GetNBytes () << " bytes inside)"); |
| 1074 |
txq->Stop (); |
| 1075 |
} |
| 976 |
return false; |
1076 |
return false; |
| 977 |
} |
1077 |
} |
| 978 |
|
1078 |
|
|
|
1079 |
// The packet has been enqueued, inform BQL and stop the queue disc if full. |
| 1080 |
if (txq) |
| 1081 |
{ |
| 1082 |
txq->NotifyQueuedBytes (packet->GetSize ()); |
| 1083 |
|
| 1084 |
if ((m_queue->GetMode () == Queue::QUEUE_MODE_PACKETS |
| 1085 |
&& m_queue->GetNPackets () >= m_queue->GetMaxPackets ()) |
| 1086 |
|| (m_queue->GetMode () == Queue::QUEUE_MODE_BYTES |
| 1087 |
&& m_queue->GetNBytes () + m_mtu > m_queue->GetMaxBytes ())) |
| 1088 |
{ |
| 1089 |
NS_LOG_DEBUG ("The device queue is being stopped (" << |
| 1090 |
m_queue->GetNPackets () << " packets and " << |
| 1091 |
m_queue->GetNBytes () << " bytes inside)"); |
| 1092 |
txq->Stop (); |
| 1093 |
} |
| 1094 |
} |
| 1095 |
|
| 979 |
// |
1096 |
// |
| 980 |
// If the device is idle, we need to start a transmission. Otherwise, |
1097 |
// If the device is idle, we need to start a transmission. Otherwise, |
| 981 |
// the transmission will be started when the current packet finished |
1098 |
// the transmission will be started when the current packet finished |
|
|
| 991 |
m_promiscSnifferTrace (m_currentPkt); |
1108 |
m_promiscSnifferTrace (m_currentPkt); |
| 992 |
m_snifferTrace (m_currentPkt); |
1109 |
m_snifferTrace (m_currentPkt); |
| 993 |
TransmitStart (); |
1110 |
TransmitStart (); |
|
|
1111 |
|
| 1112 |
// We have dequeued a packet, inform BQL and start the queue if there |
| 1113 |
// is room for another packet. |
| 1114 |
if (txq) |
| 1115 |
{ |
| 1116 |
txq->NotifyTransmittedBytes (m_currentPkt->GetSize ()); |
| 1117 |
|
| 1118 |
if ((m_queue->GetMode () == Queue::QUEUE_MODE_PACKETS && |
| 1119 |
m_queue->GetNPackets () < m_queue->GetMaxPackets ()) || |
| 1120 |
(m_queue->GetMode () == Queue::QUEUE_MODE_BYTES && |
| 1121 |
m_queue->GetNBytes () + m_mtu <= m_queue->GetMaxBytes ())) |
| 1122 |
{ |
| 1123 |
NS_LOG_DEBUG ("The device queue is being started (" << |
| 1124 |
m_queue->GetNPackets () << " packets and " << |
| 1125 |
m_queue->GetNBytes () << " bytes inside)"); |
| 1126 |
txq->Start (); |
| 1127 |
} |
| 1128 |
} |
| 994 |
} |
1129 |
} |
| 995 |
} |
1130 |
} |
| 996 |
return true; |
1131 |
return true; |