Use proper ethernet header

This commit is contained in:
Tim Schubert 2020-07-21 13:35:00 +02:00
parent 97de8c9d24
commit 1917223a5e
3 changed files with 61 additions and 41 deletions

View file

@ -59,26 +59,43 @@ LeoMockChannel::TransmitStart (Ptr<const Packet> p,
DeviceIndex *dests;
if (fromGround)
{
NS_LOG_LOGIC ("ground to space: " << srcDev->GetAddress () << " to " << dst);
dests = &m_satelliteDevices;
}
else if (fromSpace)
{
NS_LOG_LOGIC ("space to ground: " << srcDev->GetAddress () << " to " << dst);
dests = &m_groundDevices;
}
else
{
NS_LOG_ERROR ("unable to find satellite with address " << dst);
NS_LOG_ERROR ("unable to find source interface " << srcDev);
return false;
}
if (dst == srcDev->GetBroadcast () || dst == srcDev->GetMulticast (Ipv4Address ())) // mcast group ignored
{
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);
}
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
LeoMockChannel::Attach (Ptr<MockNetDevice> device)

View file

@ -26,7 +26,7 @@
#include "ns3/uinteger.h"
#include "ns3/pointer.h"
#include "ns3/net-device-queue-interface.h"
#include "ns3/ppp-header.h"
#include "ns3/ethernet-header.h"
#include "mock-channel.h"
#include "mock-net-device.h"
@ -154,8 +154,6 @@ MockNetDevice::GetTypeId (void)
//
// 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",
"Trace source simulating a non-promiscuous packet sniffer "
@ -187,22 +185,16 @@ MockNetDevice::~MockNetDevice ()
}
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);
PppHeader ppp;
ppp.SetProtocol (EtherToPpp (protocolNumber));
p->AddHeader (ppp);
}
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;
EthernetHeader ethernet;
ethernet.SetSource (Mac48Address::ConvertFrom (src));
ethernet.SetDestination (Mac48Address::ConvertFrom (dst));
p->AddHeader (ethernet);
}
void
@ -285,7 +277,7 @@ MockNetDevice::TransmitStart (Ptr<Packet> p, const Address &dest)
Time txTime = m_bps.CalculateBytesTxTime (p->GetSize ());
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);
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_DEBUG (GetAddress () << " receiving packet from " << senderDevice->GetAddress ());
uint16_t protocol = 0;
if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) )
@ -396,14 +386,27 @@ MockNetDevice::Receive (Ptr<Packet> packet, Ptr<MockNetDevice> senderDevice)
//
Ptr<Packet> originalPacket = packet->Copy ();
//
// Strip off the point-to-point protocol header and forward this packet
// up the protocol stack. Since this is a simple point-to-point link,
// there is no difference in what the promisc callback sees and what the
// normal receive callback sees.
//
ProcessHeader (packet, protocol);
EthernetHeader header;
packet->RemoveHeader (header);
PacketType packetType;
if (header.GetDestination ().IsBroadcast ())
{
packetType = PACKET_BROADCAST;
}
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);
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);
}
if (packetType != PACKET_OTHERHOST) {
m_macRxTrace (originalPacket);
m_rxCallback (this, packet, protocol, remote);
}
}
}
Ptr<Queue<Packet> >
MockNetDevice::GetQueue (void) const
@ -569,11 +574,7 @@ MockNetDevice::Send (
return false;
}
//
// Stick a point to point protocol header on the packet in preparation for
// shoving it out the door.
//
AddHeader (packet, protocolNumber);
AddHeader (packet, m_address, dest, protocolNumber);
m_macTxTrace (packet);

View file

@ -246,9 +246,11 @@ private:
* Adds the necessary headers and trailers to a packet of data in order to
* respect the protocol implemented by the agent.
* \param p packet
* \param src source
* \param dst destination
* \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