21 #include "ns3/simulator.h" |
21 #include "ns3/simulator.h" |
22 #include "ns3/mac48-address.h" |
22 #include "ns3/mac48-address.h" |
23 #include "ns3/llc-snap-header.h" |
23 #include "ns3/llc-snap-header.h" |
24 #include "ns3/error-model.h" |
24 #include "ns3/error-model.h" |
25 #include "ns3/trace-source-accessor.h" |
25 #include "ns3/trace-source-accessor.h" |
|
26 #include "ns3/uinteger.h" |
26 #include "ns3/pointer.h" |
27 #include "ns3/pointer.h" |
27 #include "point-to-point-net-device.h" |
28 #include "point-to-point-net-device.h" |
28 #include "point-to-point-channel.h" |
29 #include "point-to-point-channel.h" |
29 #include "ppp-header.h" |
30 #include "ppp-header.h" |
30 |
31 |
43 .AddAttribute ("Address", |
44 .AddAttribute ("Address", |
44 "The MAC address of this device.", |
45 "The MAC address of this device.", |
45 Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")), |
46 Mac48AddressValue (Mac48Address ("ff:ff:ff:ff:ff:ff")), |
46 MakeMac48AddressAccessor (&PointToPointNetDevice::m_address), |
47 MakeMac48AddressAccessor (&PointToPointNetDevice::m_address), |
47 MakeMac48AddressChecker ()) |
48 MakeMac48AddressChecker ()) |
|
49 .AddAttribute ("FrameSize", |
|
50 "The maximum size of a packet sent over this device.", |
|
51 UintegerValue (DEFAULT_FRAME_SIZE), |
|
52 MakeUintegerAccessor (&PointToPointNetDevice::SetFrameSize, |
|
53 &PointToPointNetDevice::GetFrameSize), |
|
54 MakeUintegerChecker<uint16_t> ()) |
48 .AddAttribute ("DataRate", |
55 .AddAttribute ("DataRate", |
49 "The default data rate for point to point links", |
56 "The default data rate for point to point links", |
50 DataRateValue (DataRate ("32768b/s")), |
57 DataRateValue (DataRate ("32768b/s")), |
51 MakeDataRateAccessor (&PointToPointNetDevice::m_bps), |
58 MakeDataRateAccessor (&PointToPointNetDevice::m_bps), |
52 MakeDataRateChecker ()) |
59 MakeDataRateChecker ()) |
81 PointToPointNetDevice::PointToPointNetDevice () |
88 PointToPointNetDevice::PointToPointNetDevice () |
82 : |
89 : |
83 m_txMachineState (READY), |
90 m_txMachineState (READY), |
84 m_channel (0), |
91 m_channel (0), |
85 m_name (""), |
92 m_name (""), |
86 m_linkUp (false), |
93 m_linkUp (false) |
87 m_mtu (0xffff) |
|
88 { |
94 { |
89 NS_LOG_FUNCTION (this); |
95 NS_LOG_FUNCTION (this); |
|
96 |
|
97 // |
|
98 // A quick sanity check to ensure consistent constants. |
|
99 // |
|
100 PppHeader ppp; |
|
101 NS_ASSERT_MSG (PPP_OVERHEAD == ppp.GetSerializedSize (), |
|
102 "PointToPointNetDevice::PointToPointNetDevice(): PPP_OVERHEAD inconsistent"); |
|
103 |
|
104 m_frameSize = DEFAULT_FRAME_SIZE; |
|
105 m_mtu = MtuFromFrameSize (m_frameSize); |
90 } |
106 } |
91 |
107 |
92 PointToPointNetDevice::~PointToPointNetDevice () |
108 PointToPointNetDevice::~PointToPointNetDevice () |
93 { |
109 { |
94 } |
110 } |
499 NS_ASSERT (false); |
502 NS_ASSERT (false); |
500 // quiet compiler. |
503 // quiet compiler. |
501 return Address (); |
504 return Address (); |
502 } |
505 } |
503 |
506 |
|
507 uint16_t |
|
508 PointToPointNetDevice::MtuFromFrameSize (uint16_t frameSize) |
|
509 { |
|
510 NS_LOG_FUNCTION (frameSize); |
|
511 |
|
512 PppHeader ppp; |
|
513 |
|
514 NS_ASSERT_MSG ((uint32_t)frameSize >= ppp.GetSerializedSize (), |
|
515 "PointToPointNetDevice::MtuFromFrameSize(): Given frame size too small to support PPP"); |
|
516 return frameSize - ppp.GetSerializedSize (); |
|
517 } |
|
518 |
|
519 uint16_t |
|
520 PointToPointNetDevice::FrameSizeFromMtu (uint16_t mtu) |
|
521 { |
|
522 NS_LOG_FUNCTION (mtu); |
|
523 |
|
524 PppHeader ppp; |
|
525 return mtu + ppp.GetSerializedSize (); |
|
526 } |
|
527 |
|
528 void |
|
529 PointToPointNetDevice::SetFrameSize (uint16_t frameSize) |
|
530 { |
|
531 NS_LOG_FUNCTION (frameSize); |
|
532 |
|
533 m_frameSize = frameSize; |
|
534 m_mtu = MtuFromFrameSize (frameSize); |
|
535 |
|
536 NS_LOG_LOGIC ("m_frameSize = " << m_frameSize); |
|
537 NS_LOG_LOGIC ("m_mtu = " << m_mtu); |
|
538 } |
|
539 |
|
540 uint16_t |
|
541 PointToPointNetDevice::GetFrameSize (void) const |
|
542 { |
|
543 return m_frameSize; |
|
544 } |
|
545 |
|
546 bool |
|
547 PointToPointNetDevice::SetMtu (uint16_t mtu) |
|
548 { |
|
549 NS_LOG_FUNCTION (mtu); |
|
550 |
|
551 m_frameSize = FrameSizeFromMtu (mtu); |
|
552 m_mtu = mtu; |
|
553 |
|
554 NS_LOG_LOGIC ("m_frameSize = " << m_frameSize); |
|
555 NS_LOG_LOGIC ("m_mtu = " << m_mtu); |
|
556 |
|
557 return true; |
|
558 } |
|
559 |
|
560 uint16_t |
|
561 PointToPointNetDevice::GetMtu (void) const |
|
562 { |
|
563 NS_LOG_FUNCTION_NOARGS (); |
|
564 return m_mtu; |
|
565 } |
|
566 |
|
567 |
504 } // namespace ns3 |
568 } // namespace ns3 |