diff --git a/model/leo-mock-channel.cc b/model/leo-mock-channel.cc index 1edfd3d..51dfb83 100644 --- a/model/leo-mock-channel.cc +++ b/model/leo-mock-channel.cc @@ -4,6 +4,8 @@ #include "ns3/ptr.h" #include "ns3/log.h" #include "ns3/enum.h" + +#include "leo-mock-net-device.h" #include "leo-mock-channel.h" namespace ns3 { @@ -24,24 +26,15 @@ LeoMockChannel::GetTypeId (void) EnumValue (), MakeEnumAccessor (&LeoMockChannel::m_channelType), MakeEnumChecker ( - ChannelType::GW_FORWARD, "ns3::LeoMockChannel::ChannelType::GW_FORWARD", - ChannelType::GW_RETURN, "ns3::LeoMockChannel::ChannelType::GW_RETURN", - ChannelType::UT_FORWARD, "ns3::LeoMockChannel::ChannelType::UT_FORWARD", - ChannelType::UT_RETURN, "ns3::LeoMockChannel::ChannelType::UT_RETURN")) - .AddTraceSource ("TxRxLeoMockChannel", - "Trace source indicating transmission of packet " - "from the LeoMockChannel, used by the Animation " - "interface.", - MakeTraceSourceAccessor (&LeoMockChannel::m_txrxMock), - "ns3::LeoMockChannel::TxRxAnimationCallback") + ChannelType::GW, "ns3::LeoMockChannel::ChannelType::GW", + ChannelType::UT, "ns3::LeoMockChannel::ChannelType::UT")) ; return tid; } -// -// By default, you get a channel that -// has an "infitely" fast transmission speed and zero processing delay. -LeoMockChannel::LeoMockChannel() : MockChannel (), m_channelType (LeoMockChannel::ChannelType::UNKNOWN) +LeoMockChannel::LeoMockChannel() : + MockChannel (), + m_channelType (LeoMockChannel::ChannelType::UNKNOWN) { NS_LOG_FUNCTION_NOARGS (); } @@ -51,10 +44,69 @@ LeoMockChannel::~LeoMockChannel() } bool -TransmitStart (Ptr p, - uint32_t devId, - Address dst, Time txTime) +LeoMockChannel::TransmitStart (Ptr p, + uint32_t devId, + Address dst, + Time txTime) { + // Find devices joined to channel + Ptr srcDev = DynamicCast (GetDevice (devId)); + + if (srcDev == nullptr) + { + NS_LOG_ERROR ("Dropping packet: invalid source device"); + return false; + } + + Ptr dstDev = DynamicCast (GetDevice (dst)); + bool isBroadcast = (srcDev->GetBroadcast () == dst); + if (dstDev == nullptr && !isBroadcast) + { + NS_LOG_ERROR ("Dropping packet: invalid destination device"); + return false; + } + + LeoMockNetDevice::DeviceType srcType = srcDev->GetDeviceType (); + + switch (m_channelType) + { + case LeoMockChannel::ChannelType::GW: + if (srcType == LeoMockNetDevice::GW) + { + // Get device from SAT_GW set + return true; + } + else if (srcType == LeoMockNetDevice::SAT_GW) + { + // Get device from GW set + return true; + } + break; + case LeoMockChannel::ChannelType::UT: + if (srcType == LeoMockNetDevice::UT) + { + // Get device from SAT_UT set + return true; + } + else if (srcType == LeoMockNetDevice::SAT_UT) + { + // Get device from UT set + return true; + } + break; + // Other kinds of transmissions are not allowed + default: + NS_LOG_ERROR ("Dropping packet: invalid channel type"); + return false; + } + + // Apply propagation loss and schedule transmission + + + // Get propagation delay + Time delay = GetDelay (srcDev, dstDev, txTime); + + // Make compiler happy return false; } diff --git a/model/leo-mock-channel.h b/model/leo-mock-channel.h index 1dc8151..1d036cc 100644 --- a/model/leo-mock-channel.h +++ b/model/leo-mock-channel.h @@ -30,7 +30,7 @@ #include "ns3/mobility-module.h" #include "ns3/propagation-delay-model.h" #include "ns3/propagation-loss-model.h" -#include "mock-net-device.h" +#include "leo-mock-net-device.h" #include "mock-channel.h" namespace ns3 { @@ -63,10 +63,8 @@ protected: enum ChannelType { - GW_FORWARD, - GW_RETURN, - UT_FORWARD, - UT_RETURN, + GW, + UT, UNKNOWN }; @@ -78,6 +76,8 @@ private: */ ChannelType m_channelType; + bool IsChannel (Ptr dstType, Ptr srcType, bool isBroadcast); + }; // class MockChannel } // namespace ns3 diff --git a/model/leo-mock-net-device.cc b/model/leo-mock-net-device.cc new file mode 100644 index 0000000..ad1379b --- /dev/null +++ b/model/leo-mock-net-device.cc @@ -0,0 +1,50 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#include "ns3/log.h" +#include "ns3/enum.h" + +#include "leo-mock-net-device.h" + +namespace ns3 +{ + +NS_LOG_COMPONENT_DEFINE ("LeoMockNetDevice"); + +NS_OBJECT_ENSURE_REGISTERED (LeoMockNetDevice); + +TypeId +LeoMockNetDevice::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::LeoMockNetDevice") + .SetParent () + .SetGroupName ("Leo") + .AddConstructor () + .AddAttribute ("DeviceType", "The type of the mocked device", + EnumValue (), + MakeEnumAccessor (&LeoMockNetDevice::m_deviceType), + MakeEnumChecker ( + DeviceType::GW, "ns3::LeoMockNetDevice::NetDeviceType::GW_FORWARD", + DeviceType::UT, "ns3::LeoMockNetDevice::NetDeviceType::GW_RETURN", + DeviceType::SAT_GW, "ns3::LeoMockNetDevice::NetDeviceType::UT_FORWARD", + DeviceType::SAT_UT, "ns3::LeoMockNetDevice::NetDeviceType::UT_RETURN")) + ; + return tid; +}; + +LeoMockNetDevice::LeoMockNetDevice () +{ +} + +LeoMockNetDevice::DeviceType +LeoMockNetDevice::GetDeviceType () const +{ + return m_deviceType; +} + +void +LeoMockNetDevice::SetDeviceType (LeoMockNetDevice::DeviceType deviceType) +{ + m_deviceType = deviceType; +} + +}; /* namspace ns3 */ diff --git a/model/leo-mock-net-device.h b/model/leo-mock-net-device.h new file mode 100644 index 0000000..0182b0d --- /dev/null +++ b/model/leo-mock-net-device.h @@ -0,0 +1,41 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#ifndef LEO_MOCK_NET_DEVICE_H_ +#define LEO_MOCK_NET_DEVICE_H_ + +#include "mock-net-device.h" + +namespace ns3 +{ + /** + * \brief A mocked satellite-ground link communication device with a type + */ +class LeoMockNetDevice : public MockNetDevice +{ +public: + enum DeviceType + { + GW, + UT, + SAT_UT, + SAT_GW + }; + + static TypeId GetTypeId (void); + + LeoMockNetDevice (); + + virtual ~LeoMockNetDevice () + { + } + + DeviceType GetDeviceType () const; + void SetDeviceType (DeviceType deviceType); + +private: + DeviceType m_deviceType; +}; + +}; + +#endif /* LEO_MOCK_NET_DEVICE_H_ */ diff --git a/wscript b/wscript index cf0311c..38227c8 100644 --- a/wscript +++ b/wscript @@ -9,14 +9,16 @@ def build(bld): module = bld.create_ns3_module('leo', ['core','internet', 'propagation', 'stats', 'traffic', 'flow-monitor', 'applications']) module.source = [ - 'model/leo.cc', - 'model/mock-net-device.cc', - 'model/mock-channel.cc', 'model/isl-mock-channel.cc', 'model/isl-propagation-loss-model.cc', - 'model/leo-mobility-model.cc', - 'helper/leo-helper.cc', 'helper/isl-helper.cc', + 'model/leo.cc', + 'model/leo-mobility-model.cc', + 'model/leo-mock-channel.cc', + 'model/leo-mock-net-device.cc', + 'helper/leo-helper.cc', + 'model/mock-net-device.cc', + 'model/mock-channel.cc', ] module_test = bld.create_ns3_module_test_library('leo') @@ -27,14 +29,16 @@ def build(bld): headers = bld(features='ns3header') headers.module = 'leo' headers.source = [ - 'model/leo.h', - 'model/mock-net-device.h', - 'model/mock-channel.h', 'model/isl-mock-channel.h', 'model/isl-propagation-loss-model.h', - 'model/leo-mobility-model.h', - 'helper/leo-helper.h', 'helper/isl-helper.h', + 'model/leo.h', + 'model/leo-mobility-model.h', + 'model/leo-mock-channel.h', + 'model/leo-mock-net-device.h', + 'helper/leo-helper.h', + 'model/mock-net-device.h', + 'model/mock-channel.h', ] if bld.env.ENABLE_EXAMPLES: