mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 18:13:57 +02:00
Use proper ethernet header
This commit is contained in:
parent
97de8c9d24
commit
1917223a5e
3 changed files with 61 additions and 41 deletions
|
@ -59,26 +59,43 @@ LeoMockChannel::TransmitStart (Ptr<const Packet> p,
|
||||||
DeviceIndex *dests;
|
DeviceIndex *dests;
|
||||||
if (fromGround)
|
if (fromGround)
|
||||||
{
|
{
|
||||||
|
NS_LOG_LOGIC ("ground to space: " << srcDev->GetAddress () << " to " << dst);
|
||||||
dests = &m_satelliteDevices;
|
dests = &m_satelliteDevices;
|
||||||
}
|
}
|
||||||
else if (fromSpace)
|
else if (fromSpace)
|
||||||
{
|
{
|
||||||
|
NS_LOG_LOGIC ("space to ground: " << srcDev->GetAddress () << " to " << dst);
|
||||||
dests = &m_groundDevices;
|
dests = &m_groundDevices;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NS_LOG_ERROR ("unable to find satellite with address " << dst);
|
NS_LOG_ERROR ("unable to find source interface " << srcDev);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dst == srcDev->GetBroadcast () || dst == srcDev->GetMulticast (Ipv4Address ())) // mcast group ignored
|
||||||
|
{
|
||||||
for (DeviceIndex::iterator it = dests->begin (); it != dests->end(); it ++)
|
for (DeviceIndex::iterator it = dests->begin (); it != dests->end(); it ++)
|
||||||
{
|
{
|
||||||
// TODO deliver only to devices in the same beam
|
|
||||||
Deliver (p, srcDev, it->second, txTime);
|
Deliver (p, srcDev, it->second, txTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DeviceIndex::iterator it = dests->find (dst);
|
||||||
|
if (it == dests->end ())
|
||||||
|
{
|
||||||
|
NS_LOG_ERROR ("unable to find destination interface: " << dst);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO deliver only to devices in the same beam
|
||||||
|
return Deliver (p, srcDev, it->second, txTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int32_t
|
int32_t
|
||||||
LeoMockChannel::Attach (Ptr<MockNetDevice> device)
|
LeoMockChannel::Attach (Ptr<MockNetDevice> device)
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "ns3/uinteger.h"
|
#include "ns3/uinteger.h"
|
||||||
#include "ns3/pointer.h"
|
#include "ns3/pointer.h"
|
||||||
#include "ns3/net-device-queue-interface.h"
|
#include "ns3/net-device-queue-interface.h"
|
||||||
#include "ns3/ppp-header.h"
|
#include "ns3/ethernet-header.h"
|
||||||
#include "mock-channel.h"
|
#include "mock-channel.h"
|
||||||
#include "mock-net-device.h"
|
#include "mock-net-device.h"
|
||||||
|
|
||||||
|
@ -154,8 +154,6 @@ MockNetDevice::GetTypeId (void)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Trace sources designed to simulate a packet sniffer facility (tcpdump).
|
// Trace sources designed to simulate a packet sniffer facility (tcpdump).
|
||||||
// Note that there is really no difference between promiscuous and
|
|
||||||
// non-promiscuous traces in a point-to-point link.
|
|
||||||
//
|
//
|
||||||
.AddTraceSource ("Sniffer",
|
.AddTraceSource ("Sniffer",
|
||||||
"Trace source simulating a non-promiscuous packet sniffer "
|
"Trace source simulating a non-promiscuous packet sniffer "
|
||||||
|
@ -187,22 +185,16 @@ MockNetDevice::~MockNetDevice ()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MockNetDevice::AddHeader (Ptr<Packet> p, uint16_t protocolNumber)
|
MockNetDevice::AddHeader (Ptr<Packet> p,
|
||||||
|
Address src,
|
||||||
|
Address dst,
|
||||||
|
uint16_t protocolNumber)
|
||||||
{
|
{
|
||||||
NS_LOG_FUNCTION (this << p << protocolNumber);
|
NS_LOG_FUNCTION (this << p << protocolNumber);
|
||||||
PppHeader ppp;
|
EthernetHeader ethernet;
|
||||||
ppp.SetProtocol (EtherToPpp (protocolNumber));
|
ethernet.SetSource (Mac48Address::ConvertFrom (src));
|
||||||
p->AddHeader (ppp);
|
ethernet.SetDestination (Mac48Address::ConvertFrom (dst));
|
||||||
}
|
p->AddHeader (ethernet);
|
||||||
|
|
||||||
bool
|
|
||||||
MockNetDevice::ProcessHeader (Ptr<Packet> p, uint16_t& param)
|
|
||||||
{
|
|
||||||
NS_LOG_FUNCTION (this << p << param);
|
|
||||||
PppHeader ppp;
|
|
||||||
p->RemoveHeader (ppp);
|
|
||||||
param = PppToEther (ppp.GetProtocol ());
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -285,7 +277,7 @@ MockNetDevice::TransmitStart (Ptr<Packet> p, const Address &dest)
|
||||||
Time txTime = m_bps.CalculateBytesTxTime (p->GetSize ());
|
Time txTime = m_bps.CalculateBytesTxTime (p->GetSize ());
|
||||||
Time txCompleteTime = txTime + m_tInterframeGap;
|
Time txCompleteTime = txTime + m_tInterframeGap;
|
||||||
|
|
||||||
NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << txCompleteTime.GetSeconds () << "sec");
|
NS_LOG_LOGIC ("Schedule TransmitCompleteEvent in " << txCompleteTime.GetNanoSeconds () << " nsec");
|
||||||
Simulator::Schedule (txCompleteTime, &MockNetDevice::TransmitComplete, this, dest);
|
Simulator::Schedule (txCompleteTime, &MockNetDevice::TransmitComplete, this, dest);
|
||||||
|
|
||||||
bool result = m_channel->TransmitStart (p, m_channelDevId, dest, txTime);
|
bool result = m_channel->TransmitStart (p, m_channelDevId, dest, txTime);
|
||||||
|
@ -367,8 +359,6 @@ MockNetDevice::Receive (Ptr<Packet> packet, Ptr<MockNetDevice> senderDevice)
|
||||||
{
|
{
|
||||||
NS_LOG_FUNCTION (this << packet << senderDevice);
|
NS_LOG_FUNCTION (this << packet << senderDevice);
|
||||||
|
|
||||||
NS_LOG_DEBUG (GetAddress () << " receiving packet from " << senderDevice->GetAddress ());
|
|
||||||
|
|
||||||
uint16_t protocol = 0;
|
uint16_t protocol = 0;
|
||||||
|
|
||||||
if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) )
|
if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) )
|
||||||
|
@ -396,14 +386,27 @@ MockNetDevice::Receive (Ptr<Packet> packet, Ptr<MockNetDevice> senderDevice)
|
||||||
//
|
//
|
||||||
Ptr<Packet> originalPacket = packet->Copy ();
|
Ptr<Packet> originalPacket = packet->Copy ();
|
||||||
|
|
||||||
//
|
EthernetHeader header;
|
||||||
// Strip off the point-to-point protocol header and forward this packet
|
packet->RemoveHeader (header);
|
||||||
// up the protocol stack. Since this is a simple point-to-point link,
|
PacketType packetType;
|
||||||
// there is no difference in what the promisc callback sees and what the
|
if (header.GetDestination ().IsBroadcast ())
|
||||||
// normal receive callback sees.
|
{
|
||||||
//
|
packetType = PACKET_BROADCAST;
|
||||||
ProcessHeader (packet, protocol);
|
}
|
||||||
|
else if (header.GetDestination () == m_address)
|
||||||
|
{
|
||||||
|
packetType = PACKET_HOST;
|
||||||
|
}
|
||||||
|
else if (header.GetDestination ().IsGroup ())
|
||||||
|
{
|
||||||
|
packetType = PACKET_MULTICAST;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
packetType = PACKET_OTHERHOST;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO sniffer trace
|
||||||
Address remote = GetRemote (senderDevice);
|
Address remote = GetRemote (senderDevice);
|
||||||
if (!m_promiscCallback.IsNull ())
|
if (!m_promiscCallback.IsNull ())
|
||||||
{
|
{
|
||||||
|
@ -411,10 +414,12 @@ MockNetDevice::Receive (Ptr<Packet> packet, Ptr<MockNetDevice> senderDevice)
|
||||||
m_promiscCallback (this, packet, protocol, remote, GetAddress (), NetDevice::PACKET_HOST);
|
m_promiscCallback (this, packet, protocol, remote, GetAddress (), NetDevice::PACKET_HOST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (packetType != PACKET_OTHERHOST) {
|
||||||
m_macRxTrace (originalPacket);
|
m_macRxTrace (originalPacket);
|
||||||
m_rxCallback (this, packet, protocol, remote);
|
m_rxCallback (this, packet, protocol, remote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ptr<Queue<Packet> >
|
Ptr<Queue<Packet> >
|
||||||
MockNetDevice::GetQueue (void) const
|
MockNetDevice::GetQueue (void) const
|
||||||
|
@ -569,11 +574,7 @@ MockNetDevice::Send (
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
AddHeader (packet, m_address, dest, protocolNumber);
|
||||||
// Stick a point to point protocol header on the packet in preparation for
|
|
||||||
// shoving it out the door.
|
|
||||||
//
|
|
||||||
AddHeader (packet, protocolNumber);
|
|
||||||
|
|
||||||
m_macTxTrace (packet);
|
m_macTxTrace (packet);
|
||||||
|
|
||||||
|
|
|
@ -246,9 +246,11 @@ private:
|
||||||
* Adds the necessary headers and trailers to a packet of data in order to
|
* Adds the necessary headers and trailers to a packet of data in order to
|
||||||
* respect the protocol implemented by the agent.
|
* respect the protocol implemented by the agent.
|
||||||
* \param p packet
|
* \param p packet
|
||||||
|
* \param src source
|
||||||
|
* \param dst destination
|
||||||
* \param protocolNumber protocol number
|
* \param protocolNumber protocol number
|
||||||
*/
|
*/
|
||||||
void AddHeader (Ptr<Packet> p, uint16_t protocolNumber);
|
void AddHeader (Ptr<Packet> p, Address src, Address dst, uint16_t protocolNumber);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes, from a packet of data, all headers and trailers that
|
* Removes, from a packet of data, all headers and trailers that
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue