mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 01:53:58 +02:00
add index for satellite / ground net devices
This commit is contained in:
parent
20ad318cb9
commit
432866d8ca
3 changed files with 79 additions and 36 deletions
|
@ -26,8 +26,7 @@ LeoMockChannel::GetTypeId (void)
|
|||
}
|
||||
|
||||
LeoMockChannel::LeoMockChannel() :
|
||||
MockChannel (),
|
||||
m_channelType (LeoMockChannel::ChannelType::UNKNOWN)
|
||||
MockChannel ()
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
}
|
||||
|
@ -43,25 +42,81 @@ LeoMockChannel::TransmitStart (Ptr<const Packet> p,
|
|||
Time txTime)
|
||||
{
|
||||
// Find devices joined to channel
|
||||
Ptr<LeoMockNetDevice> srcDev = DynamicCast<LeoMockNetDevice> (GetDevice (devId));
|
||||
Ptr<LeoMockNetDevice> dstDev = DynamicCast<LeoMockNetDevice> (GetDevice (dst));
|
||||
Ptr<MockNetDevice> srcDev = DynamicCast<MockNetDevice> (GetDevice (devId));
|
||||
|
||||
bool isBroadcast = (srcDev->GetBroadcast () == dst);
|
||||
if (!isBroadcast && dstDev == nullptr)
|
||||
{
|
||||
NS_LOG_LOGIC (this << "Dropping packet: direct communication between ground stations and satellites not allowed using this channel");
|
||||
return false;
|
||||
}
|
||||
bool toSatellite = m_groundDevices.find (srcDev->GetAddress ()) != m_groundDevices.end ();
|
||||
|
||||
for (uint32_t i = 0; i < GetNDevices (); i++)
|
||||
if (isBroadcast)
|
||||
{
|
||||
if (srcDev->GetDeviceType () != dstDev->GetDeviceType ())
|
||||
// Broadcast hack for ARP and neighbor cache
|
||||
// TODO remove if found a way to fill neighbor cache / ARP by hand
|
||||
for (uint32_t i = 0; i < GetNDevices (); i++)
|
||||
{
|
||||
// TODO deliver only to devices in the same beam
|
||||
Deliver (p, srcDev, DynamicCast<MockNetDevice> (GetDevice (i)), txTime);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (toSatellite)
|
||||
{
|
||||
Deliver (p, srcDev, dstDev, txTime);
|
||||
// Satellites can always directly be addresses
|
||||
// Assume beams are narrow enough to not also receive the signal at other
|
||||
// satellites for performance reasons.
|
||||
DeviceIndex::iterator it = m_satelliteDevices.find (dst);
|
||||
if (it == m_satelliteDevices.end ())
|
||||
{
|
||||
NS_LOG_LOGIC (this << "unable to find satellite with address " << dst);
|
||||
return false;
|
||||
}
|
||||
Deliver (p, srcDev, it->second, txTime);
|
||||
}
|
||||
else
|
||||
// space to ground delivers to everything within the beam
|
||||
{
|
||||
for (DeviceIndex::iterator it = m_groundDevices.begin ();
|
||||
it != m_groundDevices.end ();
|
||||
it++)
|
||||
{
|
||||
// TODO deliver only to devices in the same beam
|
||||
Deliver (p, srcDev, it->second, txTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t
|
||||
LeoMockChannel::Attach (Ptr<MockNetDevice> device)
|
||||
{
|
||||
Ptr<LeoMockNetDevice> leodev = DynamicCast<LeoMockNetDevice> (device);
|
||||
|
||||
// Add to index
|
||||
switch (leodev->GetDeviceType ())
|
||||
{
|
||||
case LeoMockNetDevice::DeviceType::GND:
|
||||
m_groundDevices[leodev->GetAddress ()] = leodev;
|
||||
break;
|
||||
case LeoMockNetDevice::DeviceType::SAT:
|
||||
m_satelliteDevices[leodev->GetAddress ()] = leodev;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return MockChannel::Attach (device);
|
||||
}
|
||||
|
||||
bool
|
||||
LeoMockChannel::Detach (uint32_t deviceId)
|
||||
{
|
||||
Ptr<NetDevice> dev = GetDevice (deviceId);
|
||||
m_groundDevices.erase (dev->GetAddress ());
|
||||
m_satelliteDevices.erase (dev->GetAddress ());
|
||||
|
||||
return MockChannel::Detach (deviceId);
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
|
|
|
@ -30,13 +30,12 @@
|
|||
#include "ns3/mobility-module.h"
|
||||
#include "ns3/propagation-delay-model.h"
|
||||
#include "ns3/propagation-loss-model.h"
|
||||
#include "leo-mock-net-device.h"
|
||||
#include "mock-channel.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/**
|
||||
* \ingroup network
|
||||
* \ingroup leo
|
||||
* \defgroup channel Channel
|
||||
*/
|
||||
/**
|
||||
|
@ -44,8 +43,6 @@ namespace ns3 {
|
|||
* \brief Mocked satellite-gateway, satellite-terminal channel types
|
||||
*
|
||||
*/
|
||||
// TODO make separate clases for ut and gw links
|
||||
// TODO make separate clases for ut and gw devices
|
||||
class LeoMockChannel : public MockChannel
|
||||
{
|
||||
public:
|
||||
|
@ -61,28 +58,19 @@ public:
|
|||
*/
|
||||
virtual bool TransmitStart (Ptr<const Packet> p, uint32_t devId, Address dst, Time txTime);
|
||||
|
||||
protected:
|
||||
enum ChannelType
|
||||
{
|
||||
GW,
|
||||
UT,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
ChannelType GetChannelType () const;
|
||||
virtual int32_t Attach (Ptr<MockNetDevice> device);
|
||||
virtual bool Detach (uint32_t deviceId);
|
||||
|
||||
private:
|
||||
/**
|
||||
* \brief Type of the channel
|
||||
* \brief Ground and satellite devices
|
||||
*
|
||||
* This channel does not allow for communication between devices of the same
|
||||
* type (no sat-sat or ground-ground).
|
||||
*/
|
||||
ChannelType m_channelType;
|
||||
|
||||
bool IsChannel (Ptr<LeoMockNetDevice> dstType, Ptr<LeoMockNetDevice> srcType, bool isBroadcast);
|
||||
|
||||
typedef std::map<Address, Ptr<LeoMockNetDevice> > DeviceIndex;
|
||||
DeviceIndex m_gndDevs;
|
||||
DeviceIndex m_satDevs;
|
||||
|
||||
typedef std::map<Address, Ptr<MockNetDevice> > DeviceIndex;
|
||||
DeviceIndex m_groundDevices;
|
||||
DeviceIndex m_satelliteDevices;
|
||||
}; // class MockChannel
|
||||
|
||||
} // namespace ns3
|
||||
|
|
|
@ -60,14 +60,14 @@ public:
|
|||
* \param device Device to attach to the channel
|
||||
* \return Index of the device inside the devices list
|
||||
*/
|
||||
int32_t Attach (Ptr<MockNetDevice> device);
|
||||
virtual int32_t Attach (Ptr<MockNetDevice> device);
|
||||
|
||||
/**
|
||||
* \brief Detach a given netdevice from this channel
|
||||
* \param device pointer to the netdevice to detach from the channel
|
||||
* \return true on success, false on failure
|
||||
*/
|
||||
bool Detach (uint32_t deviceId);
|
||||
virtual bool Detach (uint32_t deviceId);
|
||||
|
||||
std::size_t GetNDevices (void) const;
|
||||
virtual bool TransmitStart (Ptr<const Packet> p, uint32_t devId, Address dst, Time txTime) = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue