LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2007 Emmanuelle Laprise | 3 * Copyright (c) 2007 Emmanuelle Laprise |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software | 15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca> | 18 * Author: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca> |
19 */ | 19 */ |
20 | 20 |
21 #include "ns3/log.h" | 21 #include "ns3/log.h" |
| 22 #include "ns3/queue.h" |
22 #include "ns3/simulator.h" | 23 #include "ns3/simulator.h" |
23 #include "ns3/ethernet-header.h" | 24 #include "ns3/ethernet-header.h" |
24 #include "ns3/ethernet-trailer.h" | 25 #include "ns3/ethernet-trailer.h" |
25 #include "ns3/llc-snap-header.h" | 26 #include "ns3/llc-snap-header.h" |
26 #include "ns3/error-model.h" | 27 #include "ns3/error-model.h" |
27 #include "ns3/enum.h" | 28 #include "ns3/enum.h" |
28 #include "ns3/boolean.h" | 29 #include "ns3/boolean.h" |
29 #include "ns3/uinteger.h" | 30 #include "ns3/uinteger.h" |
30 #include "ns3/pointer.h" | 31 #include "ns3/pointer.h" |
31 #include "ns3/trace-source-accessor.h" | 32 #include "ns3/trace-source-accessor.h" |
32 #include "csma-net-device.h" | 33 #include "csma-net-device.h" |
33 #include "csma-channel.h" | 34 #include "csma-channel.h" |
| 35 #include "ns3/net-device-queue-interface.h" |
34 | 36 |
35 namespace ns3 { | 37 namespace ns3 { |
36 | 38 |
37 NS_LOG_COMPONENT_DEFINE ("CsmaNetDevice"); | 39 NS_LOG_COMPONENT_DEFINE ("CsmaNetDevice"); |
38 | 40 |
39 NS_OBJECT_ENSURE_REGISTERED (CsmaNetDevice); | 41 NS_OBJECT_ENSURE_REGISTERED (CsmaNetDevice); |
40 | 42 |
41 TypeId | 43 TypeId |
42 CsmaNetDevice::GetTypeId (void) | 44 CsmaNetDevice::GetTypeId (void) |
43 { | 45 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 MakePointerChecker<ErrorModel> ()) | 80 MakePointerChecker<ErrorModel> ()) |
79 | 81 |
80 // | 82 // |
81 // Transmit queueing discipline for the device which includes its own set | 83 // Transmit queueing discipline for the device which includes its own set |
82 // of trace hooks. | 84 // of trace hooks. |
83 // | 85 // |
84 .AddAttribute ("TxQueue",· | 86 .AddAttribute ("TxQueue",· |
85 "A queue to use as the transmit queue in the device.", | 87 "A queue to use as the transmit queue in the device.", |
86 PointerValue (), | 88 PointerValue (), |
87 MakePointerAccessor (&CsmaNetDevice::m_queue), | 89 MakePointerAccessor (&CsmaNetDevice::m_queue), |
88 MakePointerChecker<PacketQueue> ()) | 90 MakePointerChecker<Queue<Packet> > ()) |
89 | 91 |
90 // | 92 // |
91 // Trace sources at the "top" of the net device, where packets transition | 93 // Trace sources at the "top" of the net device, where packets transition |
92 // to/from higher layers. | 94 // to/from higher layers. |
93 // | 95 // |
94 .AddTraceSource ("MacTx",· | 96 .AddTraceSource ("MacTx",· |
95 "Trace source indicating a packet has " | 97 "Trace source indicating a packet has " |
96 "arrived for transmission by this device", | 98 "arrived for transmission by this device", |
97 MakeTraceSourceAccessor (&CsmaNetDevice::m_macTxTrace), | 99 MakeTraceSourceAccessor (&CsmaNetDevice::m_macTxTrace), |
98 "ns3::Packet::TracedCallback") | 100 "ns3::Packet::TracedCallback") |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 m_queue = 0; | 221 m_queue = 0; |
220 m_queueInterface = 0; | 222 m_queueInterface = 0; |
221 NetDevice::DoDispose (); | 223 NetDevice::DoDispose (); |
222 } | 224 } |
223 | 225 |
224 void | 226 void |
225 CsmaNetDevice::DoInitialize (void) | 227 CsmaNetDevice::DoInitialize (void) |
226 { | 228 { |
227 if (m_queueInterface) | 229 if (m_queueInterface) |
228 { | 230 { |
229 // create the transmission queue in case it has not been already created (
by | 231 // create the transmission queue in case it has not been created yet (by |
230 // TrafficControlLayer::SetupDevice -- this might be the case of some test
s) | 232 // TrafficControlLayer::DoInitialize) |
231 if (m_queueInterface->GetNTxQueues () == 0) | 233 if (m_queueInterface->GetNTxQueues () == 0) |
232 { | 234 { |
233 m_queueInterface->CreateTxQueues (); | 235 m_queueInterface->CreateTxQueues (); |
234 } | 236 } |
235 | 237 |
236 NS_ASSERT_MSG (m_queue != 0, "A Queue object has not been attached to the
device"); | 238 NS_ASSERT_MSG (m_queue != 0, "A Queue object has not been attached to the
device"); |
237 | 239 |
238 // ensure in order packet dequeues | |
239 m_queue->SetInOrderDequeue (true); | |
240 | |
241 // connect the traced callbacks of m_queue to the static methods provided
by | 240 // connect the traced callbacks of m_queue to the static methods provided
by |
242 // the NetDeviceQueue class to support flow control and dynamic queue limi
ts. | 241 // the NetDeviceQueue class to support flow control and dynamic queue limi
ts. |
243 // This could not be done in NotifyNewAggregate because at that time we ar
e | 242 // This could not be done in NotifyNewAggregate because at that time we ar
e |
244 // not guaranteed that a queue has been attached to the netdevice | 243 // not guaranteed that a queue has been attached to the netdevice |
245 m_queue->TraceConnectWithoutContext ("Enqueue", | 244 m_queueInterface->ConnectQueueTraces (m_queue, 0); |
246 MakeBoundCallback (&NetDeviceQueue::P
acketEnqueued<Packet>, | |
247 m_queue, m_queueIn
terface, 0)); | |
248 | |
249 m_queue->TraceConnectWithoutContext ("Dequeue", | |
250 MakeBoundCallback (&NetDeviceQueue::P
acketDequeued<Packet>, | |
251 m_queue, m_queueIn
terface, 0)); | |
252 | |
253 m_queue->TraceConnectWithoutContext ("DropAfterDequeue", | |
254 MakeBoundCallback (&NetDeviceQueue::P
acketDequeued<Packet>, | |
255 m_queue, m_queueIn
terface, 0)); | |
256 | |
257 m_queue->TraceConnectWithoutContext ("DropBeforeEnqueue", | |
258 MakeBoundCallback (&NetDeviceQueue::P
acketDiscarded<Packet>, | |
259 m_queue, m_queueIn
terface, 0)); | |
260 } | 245 } |
261 | 246 |
262 NetDevice::DoInitialize (); | 247 NetDevice::DoInitialize (); |
263 } | 248 } |
264 | 249 |
265 void | 250 void |
266 CsmaNetDevice::NotifyNewAggregate (void) | 251 CsmaNetDevice::NotifyNewAggregate (void) |
267 { | 252 { |
268 NS_LOG_FUNCTION (this); | 253 NS_LOG_FUNCTION (this); |
269 if (m_queueInterface == 0) | 254 if (m_queueInterface == 0) |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 // transmit state machine. | 595 // transmit state machine. |
611 // | 596 // |
612 m_backoff.ResetBackoffTime (); | 597 m_backoff.ResetBackoffTime (); |
613 m_txMachineState = READY; | 598 m_txMachineState = READY; |
614 | 599 |
615 // | 600 // |
616 // If there is another packet on the input queue, we need to start trying to· | 601 // If there is another packet on the input queue, we need to start trying to· |
617 // get that out. If the queue is empty we just wait until someone puts one | 602 // get that out. If the queue is empty we just wait until someone puts one |
618 // in. | 603 // in. |
619 // | 604 // |
620 Ptr<Packet> packet = m_queue->Dequeue (); | 605 if (m_queue->IsEmpty ()) |
621 if (packet == 0) | |
622 { | 606 { |
623 return; | 607 return; |
624 } | 608 } |
625 else | 609 else |
626 { | 610 { |
| 611 Ptr<Packet> packet = m_queue->Dequeue (); |
| 612 NS_ASSERT_MSG (packet != 0, "CsmaNetDevice::TransmitAbort(): IsEmpty false
but no Packet on queue?"); |
627 m_currentPkt = packet; | 613 m_currentPkt = packet; |
628 m_snifferTrace (m_currentPkt); | 614 m_snifferTrace (m_currentPkt); |
629 m_promiscSnifferTrace (m_currentPkt); | 615 m_promiscSnifferTrace (m_currentPkt); |
630 TransmitStart (); | 616 TransmitStart (); |
631 } | 617 } |
632 } | 618 } |
633 | 619 |
634 void | 620 void |
635 CsmaNetDevice::TransmitCompleteEvent (void) | 621 CsmaNetDevice::TransmitCompleteEvent (void) |
636 { | 622 { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 | 664 |
679 // | 665 // |
680 // We expect that the packet we had been transmitting was cleared when the· | 666 // We expect that the packet we had been transmitting was cleared when the· |
681 // TransmitCompleteEvent() was executed. | 667 // TransmitCompleteEvent() was executed. |
682 // | 668 // |
683 NS_ASSERT_MSG (m_currentPkt == 0, "CsmaNetDevice::TransmitReadyEvent(): m_curr
entPkt nonzero"); | 669 NS_ASSERT_MSG (m_currentPkt == 0, "CsmaNetDevice::TransmitReadyEvent(): m_curr
entPkt nonzero"); |
684 | 670 |
685 // | 671 // |
686 // Get the next packet from the queue for transmitting | 672 // Get the next packet from the queue for transmitting |
687 // | 673 // |
688 Ptr<Packet> packet = m_queue->Dequeue (); | 674 if (m_queue->IsEmpty ()) |
689 if (packet == 0) | |
690 { | 675 { |
691 return; | 676 return; |
692 } | 677 } |
693 else | 678 else |
694 { | 679 { |
| 680 Ptr<Packet> packet = m_queue->Dequeue (); |
| 681 NS_ASSERT_MSG (packet != 0, "CsmaNetDevice::TransmitReadyEvent(): IsEmpty
false but no Packet on queue?"); |
695 m_currentPkt = packet; | 682 m_currentPkt = packet; |
696 m_snifferTrace (m_currentPkt); | 683 m_snifferTrace (m_currentPkt); |
697 m_promiscSnifferTrace (m_currentPkt); | 684 m_promiscSnifferTrace (m_currentPkt); |
698 TransmitStart (); | 685 TransmitStart (); |
699 } | 686 } |
700 } | 687 } |
701 | 688 |
702 bool | 689 bool |
703 CsmaNetDevice::Attach (Ptr<CsmaChannel> ch) | 690 CsmaNetDevice::Attach (Ptr<CsmaChannel> ch) |
704 { | 691 { |
(...skipping 14 matching lines...) Expand all Loading... |
719 m_tInterframeGap = m_bps.CalculateBytesTxTime (96/8); | 706 m_tInterframeGap = m_bps.CalculateBytesTxTime (96/8); |
720 | 707 |
721 // | 708 // |
722 // This device is up whenever a channel is attached to it. | 709 // This device is up whenever a channel is attached to it. |
723 // | 710 // |
724 NotifyLinkUp (); | 711 NotifyLinkUp (); |
725 return true; | 712 return true; |
726 } | 713 } |
727 | 714 |
728 void | 715 void |
729 CsmaNetDevice::SetQueue (Ptr<PacketQueue> q) | 716 CsmaNetDevice::SetQueue (Ptr<Queue<Packet> > q) |
730 { | 717 { |
731 NS_LOG_FUNCTION (q); | 718 NS_LOG_FUNCTION (q); |
732 m_queue = q; | 719 m_queue = q; |
733 } | 720 } |
734 | 721 |
735 void | 722 void |
736 CsmaNetDevice::SetReceiveErrorModel (Ptr<ErrorModel> em) | 723 CsmaNetDevice::SetReceiveErrorModel (Ptr<ErrorModel> em) |
737 { | 724 { |
738 NS_LOG_FUNCTION (em); | 725 NS_LOG_FUNCTION (em); |
739 m_receiveErrorModel = em;· | 726 m_receiveErrorModel = em;· |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 // packet received trace hook and forward the packet up the stack. | 856 // packet received trace hook and forward the packet up the stack. |
870 // | 857 // |
871 if (packetType != PACKET_OTHERHOST) | 858 if (packetType != PACKET_OTHERHOST) |
872 { | 859 { |
873 m_snifferTrace (originalPacket); | 860 m_snifferTrace (originalPacket); |
874 m_macRxTrace (originalPacket); | 861 m_macRxTrace (originalPacket); |
875 m_rxCallback (this, packet, protocol, header.GetSource ()); | 862 m_rxCallback (this, packet, protocol, header.GetSource ()); |
876 } | 863 } |
877 } | 864 } |
878 | 865 |
879 Ptr<PacketQueue> | 866 Ptr<Queue<Packet> > |
880 CsmaNetDevice::GetQueue (void) const· | 867 CsmaNetDevice::GetQueue (void) const· |
881 {· | 868 {· |
882 NS_LOG_FUNCTION_NOARGS (); | 869 NS_LOG_FUNCTION_NOARGS (); |
883 return m_queue; | 870 return m_queue; |
884 } | 871 } |
885 | 872 |
886 void | 873 void |
887 CsmaNetDevice::NotifyLinkUp (void) | 874 CsmaNetDevice::NotifyLinkUp (void) |
888 { | 875 { |
889 NS_LOG_FUNCTION_NOARGS (); | 876 NS_LOG_FUNCTION_NOARGS (); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 return false; | 1020 return false; |
1034 } | 1021 } |
1035 | 1022 |
1036 // | 1023 // |
1037 // If the device is idle, we need to start a transmission. Otherwise, | 1024 // If the device is idle, we need to start a transmission. Otherwise, |
1038 // the transmission will be started when the current packet finished | 1025 // the transmission will be started when the current packet finished |
1039 // transmission (see TransmitCompleteEvent) | 1026 // transmission (see TransmitCompleteEvent) |
1040 // | 1027 // |
1041 if (m_txMachineState == READY)· | 1028 if (m_txMachineState == READY)· |
1042 { | 1029 { |
1043 Ptr<Packet> packet = m_queue->Dequeue (); | 1030 if (m_queue->IsEmpty () == false) |
1044 if (packet != 0) | |
1045 { | 1031 { |
| 1032 Ptr<Packet> packet = m_queue->Dequeue (); |
| 1033 NS_ASSERT_MSG (packet != 0, "CsmaNetDevice::SendFrom(): IsEmpty false
but no Packet on queue?"); |
1046 m_currentPkt = packet; | 1034 m_currentPkt = packet; |
1047 m_promiscSnifferTrace (m_currentPkt); | 1035 m_promiscSnifferTrace (m_currentPkt); |
1048 m_snifferTrace (m_currentPkt); | 1036 m_snifferTrace (m_currentPkt); |
1049 TransmitStart (); | 1037 TransmitStart (); |
1050 } | 1038 } |
1051 } | 1039 } |
1052 return true; | 1040 return true; |
1053 } | 1041 } |
1054 | 1042 |
1055 Ptr<Node> | 1043 Ptr<Node> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 return true; | 1091 return true; |
1104 } | 1092 } |
1105 | 1093 |
1106 int64_t | 1094 int64_t |
1107 CsmaNetDevice::AssignStreams (int64_t stream) | 1095 CsmaNetDevice::AssignStreams (int64_t stream) |
1108 { | 1096 { |
1109 return m_backoff.AssignStreams (stream); | 1097 return m_backoff.AssignStreams (stream); |
1110 } | 1098 } |
1111 | 1099 |
1112 } // namespace ns3 | 1100 } // namespace ns3 |
LEFT | RIGHT |