signetlabdei / lorawan

An ns-3 module for simulation of LoRaWAN networks
GNU General Public License v2.0
182 stars 130 forks source link

How to integrate a new model #162

Open Vidushi0001 opened 4 months ago

Vidushi0001 commented 4 months ago

I have worked on drafting a code for classBEndDeviceLorawanMac and an example script to test that, but I need certain instructions on how to integrate it with the module and run it, can someone please guide?

Specifications

non-det-alle commented 4 months ago

From the top of my head, here are some of the things you will probably need to do:

Please be more specific with your question.

Vidushi0001 commented 4 months ago

@non-det-alle I plan to extend the functionality of this module to classBLorawanEndDevice also, for the same I need to know the steps and places where I need to make changes to integrate the classBLorawanEndDevice class in the module.

The steps I think of using are:

adding the file for class-b-lorawan-end-device.cc and .h file in models folder adding the files to the CMakeLists.txt file specifying the build rule for implementation:

 cmake_minimum_required(VERSION 3.10)

set(CLASSB_END_DEVICE_SRCS
  class-b-end-device.cc
)

set(CLASSB_END_DEVICE_HEADERS
  class-b-end-device.h
)

ns3module_add_to_build(ClassBEndDevice
  ${CLASSB_END_DEVICE_SRCS}
  ${CLASSB_END_DEVICE_HEADERS}
)

target_include_directories(ClassBEndDevice
  PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
)

Modify lorawan-mac-helper.h and .cc file to include classBLorawanEndDevice using

void Install(LoraPhyHelper& phyHelper, NodeContainer& nodes, const ClassBEndDeviceLorawanMacParameters& parameters = ClassBEndDeviceLorawanMacParameters());

Implementing a new install method in lorawan-mac-helper.cc

void
LorawanMacHelper::Install(LoraPhyHelper& phyHelper, NodeContainer& nodes, const ClassBEndDeviceLorawanMacParameters& parameters)
{
  for (NodeContainer::Iterator i = nodes.Begin(); i != nodes.End(); ++i)
    {
      Ptr<Node> node = *i;
      Ptr<LoraDeviceMac> mac = CreateObject<ClassBEndDeviceLorawanMac> (parameters);
      phyHelper.SetDeviceType(LoraPhyHelper::ED);
      phyHelper.Install(mac, node);
    }
}

Add a line to lorawan-phy-helper.h for supporting the new class

void SetDeviceType(LoraPhyHelper::DeviceType deviceType, Ptr<LoraDeviceMac> mac);

implement new setDeviceType in lorawan-phy-helper.cc

void
LoraPhyHelper::SetDeviceType(DeviceType deviceType, Ptr<LoraDeviceMac> mac)
{
  if (deviceType == DeviceType::ED)
    {
      m_deviceType = DeviceType::ED;
      m_phy->SetDeviceType(LoraPhy::ED, mac);
    }
  else if (deviceType == DeviceType::GW)
    {
      m_deviceType = DeviceType::GW;
      m_phy->SetDeviceType(LoraPhy::GW, mac);
    }
  else
    {
      NS_ABORT_MSG("Invaliddevice type.");
    }
}

build the project and run the simulation scenario created for testing the new class.

Please help me and correct the steps which you feel are wrong and where you feel I am doing it incorreclty and suggest the correct way