|
|
| 25 |
#include "ns3/trace-source-accessor.h" |
25 |
#include "ns3/trace-source-accessor.h" |
| 26 |
#include "ns3/uinteger.h" |
26 |
#include "ns3/uinteger.h" |
| 27 |
#include "ns3/pointer.h" |
27 |
#include "ns3/pointer.h" |
|
|
28 |
#include "ns3/ipv4-header.h" |
| 28 |
#include "point-to-point-net-device.h" |
29 |
#include "point-to-point-net-device.h" |
| 29 |
#include "point-to-point-channel.h" |
30 |
#include "point-to-point-channel.h" |
| 30 |
#include "ppp-header.h" |
31 |
#include "ppp-header.h" |
|
|
32 |
#include "etherip-header.h" |
| 31 |
|
33 |
|
| 32 |
NS_LOG_COMPONENT_DEFINE ("PointToPointNetDevice"); |
34 |
NS_LOG_COMPONENT_DEFINE ("PointToPointNetDevice"); |
| 33 |
|
35 |
|
|
|
| 158 |
NS_LOG_FUNCTION_NOARGS (); |
160 |
NS_LOG_FUNCTION_NOARGS (); |
| 159 |
} |
161 |
} |
| 160 |
|
162 |
|
| 161 |
void |
163 |
void |
| 162 |
PointToPointNetDevice::AddHeader(Ptr<Packet> p, uint16_t protocolNumber) |
164 |
PointToPointNetDevice::AddHeader(Ptr<Packet> p, uint16_t protocolNumber, Mac48Address dest) |
| 163 |
{ |
165 |
{ |
| 164 |
NS_LOG_FUNCTION_NOARGS (); |
166 |
NS_LOG_FUNCTION_NOARGS (); |
|
|
167 |
EthernetHeader eth; |
| 168 |
eth.SetSource (m_address); |
| 169 |
eth.SetDestination (dest); |
| 170 |
eth.SetLengthType (protocolNumber); |
| 171 |
p->AddHeader (eth); |
| 172 |
EtheripHeader ethIp; |
| 173 |
p->AddHeader (ethIp); |
| 174 |
Ipv4Header ipv4; |
| 175 |
ipv4.SetSource (Ipv4Address::GetZero ()); |
| 176 |
ipv4.SetDestination (Ipv4Address::GetZero ()); |
| 177 |
ipv4.SetPayloadSize (p->GetSize ()); |
| 178 |
ipv4.SetProtocol (0x61); // ETHERip over IPV4 |
| 179 |
p->AddHeader (ipv4); |
| 165 |
PppHeader ppp; |
180 |
PppHeader ppp; |
| 166 |
ppp.SetProtocol(EtherToPpp(protocolNumber)); |
181 |
ppp.SetProtocol(0x0021); // ipv4 |
| 167 |
p->AddHeader (ppp); |
182 |
p->AddHeader (ppp); |
| 168 |
} |
183 |
} |
| 169 |
|
184 |
|
| 170 |
bool |
185 |
EthernetHeader |
| 171 |
PointToPointNetDevice::ProcessHeader(Ptr<Packet> p, uint16_t& param) |
186 |
PointToPointNetDevice::ProcessHeader(Ptr<Packet> p) |
| 172 |
{ |
187 |
{ |
| 173 |
NS_LOG_FUNCTION_NOARGS (); |
188 |
NS_LOG_FUNCTION_NOARGS (); |
| 174 |
PppHeader ppp; |
189 |
PppHeader ppp; |
| 175 |
p->RemoveHeader (ppp); |
190 |
p->RemoveHeader (ppp); |
| 176 |
param = PppToEther(ppp.GetProtocol()); |
191 |
Ipv4Header ipv4; |
| 177 |
return true; |
192 |
p->RemoveHeader (ipv4); |
|
|
193 |
EtheripHeader ethIp; |
| 194 |
p->RemoveHeader (ethIp); |
| 195 |
EthernetHeader eth; |
| 196 |
p->RemoveHeader (eth); |
| 197 |
return eth; |
| 178 |
} |
198 |
} |
| 179 |
|
199 |
|
| 180 |
void |
200 |
void |
|
|
| 304 |
PointToPointNetDevice::Receive (Ptr<Packet> packet) |
324 |
PointToPointNetDevice::Receive (Ptr<Packet> packet) |
| 305 |
{ |
325 |
{ |
| 306 |
NS_LOG_FUNCTION (this << packet); |
326 |
NS_LOG_FUNCTION (this << packet); |
| 307 |
uint16_t protocol = 0; |
|
|
| 308 |
|
| 309 |
if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) ) |
327 |
if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) ) |
| 310 |
{ |
328 |
{ |
| 311 |
// |
329 |
// |
|
|
| 331 |
// there is no difference in what the promisc callback sees and what the |
349 |
// there is no difference in what the promisc callback sees and what the |
| 332 |
// normal receive callback sees. |
350 |
// normal receive callback sees. |
| 333 |
// |
351 |
// |
| 334 |
ProcessHeader(packet, protocol); |
352 |
EthernetHeader eth = ProcessHeader(packet); |
| 335 |
|
353 |
|
| 336 |
if (!m_promiscCallback.IsNull ()) |
354 |
if (!m_promiscCallback.IsNull ()) |
| 337 |
{ |
355 |
{ |
| 338 |
m_macPromiscRxTrace (packet); |
356 |
m_macPromiscRxTrace (packet); |
| 339 |
m_promiscCallback (this, packet, protocol, GetRemote (), GetAddress (), NetDevice::PACKET_HOST); |
357 |
m_promiscCallback (this, packet, eth.GetLengthType (), |
|
|
358 |
eth.GetSource (), eth.GetDestination (), |
| 359 |
NetDevice::PACKET_HOST); |
| 340 |
} |
360 |
} |
| 341 |
|
361 |
|
| 342 |
m_macRxTrace (packet); |
362 |
m_macRxTrace (packet); |
| 343 |
m_rxCallback (this, packet, protocol, GetRemote ()); |
363 |
m_rxCallback (this, packet, eth.GetLengthType (), eth.GetSource ()); |
| 344 |
} |
364 |
} |
| 345 |
} |
365 |
} |
| 346 |
|
366 |
|
|
|
| 471 |
NS_LOG_FUNCTION_NOARGS (); |
491 |
NS_LOG_FUNCTION_NOARGS (); |
| 472 |
NS_LOG_LOGIC ("p=" << packet << ", dest=" << &dest); |
492 |
NS_LOG_LOGIC ("p=" << packet << ", dest=" << &dest); |
| 473 |
NS_LOG_LOGIC ("UID is " << packet->GetUid ()); |
493 |
NS_LOG_LOGIC ("UID is " << packet->GetUid ()); |
|
|
494 |
Mac48Address realDest = Mac48Address::ConvertFrom (dest); |
| 474 |
|
495 |
|
| 475 |
// |
496 |
// |
| 476 |
// If IsLinkUp() is false it means there is no channel to send any packet |
497 |
// If IsLinkUp() is false it means there is no channel to send any packet |
|
|
| 486 |
// Stick a point to point protocol header on the packet in preparation for |
507 |
// Stick a point to point protocol header on the packet in preparation for |
| 487 |
// shoving it out the door. |
508 |
// shoving it out the door. |
| 488 |
// |
509 |
// |
| 489 |
AddHeader(packet, protocolNumber); |
510 |
AddHeader(packet, protocolNumber, realDest); |
| 490 |
|
511 |
|
| 491 |
m_macTxTrace (packet); |
512 |
m_macTxTrace (packet); |
| 492 |
|
513 |
|