├── model ├── vlcnew.cc ├── vlcnew.h ├── Source.cc ├── vlcNetDevice.cc ├── vlcNetDevice.h ├── VLC_SNR.h ├── vlcMobilityModel.h ├── VlcPropagationLoss.h ├── VLC-error-model.h ├── VlcPropagationLoss.cc ├── vlcNetDeviceTX.h ├── vlcchannel.h ├── vlcNetDeviceTX.cc ├── vlcMobilityModel.cc ├── vlcNetDeviceRX.h ├── vlcchannel.cc ├── vlcNetDeviceRX.cc ├── VLC_SNR.cc └── VLC-error-model.cc ├── helper ├── vlcnew-helper.cc ├── vlcnew-helper.h ├── vlcDeviceHelper.h ├── vlcChannelHelper.h ├── vlcChannelHelper.cc └── vlcDeviceHelper.cc ├── examples ├── wscript └── vlcnew-example.cc ├── .gitignore ├── wscript ├── test └── vlcnew-test-suite.cc ├── README.md ├── doc └── vlcnew.rst ├── VPPMtest.cc └── LICENSE /model/vlcnew.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | 3 | #include "ns3/vlcnew.h" 4 | 5 | namespace vlc { 6 | 7 | /* ... */ 8 | 9 | 10 | } 11 | 12 | -------------------------------------------------------------------------------- /helper/vlcnew-helper.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | 3 | #include "vlcnew-helper.h" 4 | 5 | namespace ns3 { 6 | 7 | /* ... */ 8 | 9 | 10 | } 11 | 12 | -------------------------------------------------------------------------------- /model/vlcnew.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | #ifndef VLCNEW_H 3 | #define VLCNEW_H 4 | 5 | namespace ns3 { 6 | 7 | /* ... */ 8 | 9 | } 10 | 11 | #endif /* VLCNEW_H */ 12 | 13 | -------------------------------------------------------------------------------- /examples/wscript: -------------------------------------------------------------------------------- 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 2 | 3 | def build(bld): 4 | obj = bld.create_ns3_program('vlcnew-example', ['vlcnew']) 5 | obj.source = 'vlcnew-example.cc' 6 | 7 | -------------------------------------------------------------------------------- /helper/vlcnew-helper.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | #ifndef VLCNEW_HELPER_H 3 | #define VLCNEW_HELPER_H 4 | 5 | #include "ns3/vlcnew.h" 6 | 7 | namespace ns3 { 8 | 9 | /* ... */ 10 | 11 | } 12 | 13 | #endif /* VLCNEW_HELPER_H */ 14 | 15 | -------------------------------------------------------------------------------- /model/Source.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Source.cc 3 | * 4 | * Created on: Mar 27, 2016 5 | * Author: adel 6 | */ 7 | #include 8 | //#include "ns3/core/model/*" 9 | 10 | 11 | using namespace std; 12 | int main(){ 13 | 14 | cout<<"main can also start from here \n "; 15 | 16 | return 0; 17 | } 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | -------------------------------------------------------------------------------- /examples/vlcnew-example.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | 3 | #include "ns3/core-module.h" 4 | #include "ns3/vlcnew-helper.h" 5 | 6 | using namespace ns3; 7 | 8 | 9 | int 10 | main (int argc, char *argv[]) 11 | { 12 | bool verbose = true; 13 | 14 | CommandLine cmd; 15 | cmd.AddValue ("verbose", "Tell application to log if true", verbose); 16 | 17 | cmd.Parse (argc,argv); 18 | 19 | /* ... */ 20 | 21 | Simulator::Run (); 22 | Simulator::Destroy (); 23 | return 0; 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /model/vlcNetDevice.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcNetDevice.cc 3 | * 4 | * Created on: Mar 25, 2016 5 | * Author: Adel Aldalbahi 6 | */ 7 | 8 | #include "ns3/vlcNetDevice.h" 9 | 10 | namespace vlc { 11 | 12 | vlc_NetDevice::vlc_NetDevice() { 13 | m_mobilityModel = ns3::CreateObject(); 14 | m_mobilityModel->SetAzimuth(0); 15 | m_mobilityModel->SetElevation(0); 16 | m_mobilityModel->SetPosition(ns3::Vector(0.0,0.0,0.0)); 17 | } 18 | 19 | 20 | double vlc_NetDevice::GetAzmuth(){ 21 | return this->m_mobilityModel->GetAzimuth(); 22 | } 23 | 24 | void vlc_NetDevice::SetAzmuth(double az){ 25 | this->m_mobilityModel->SetAzimuth(az); 26 | } 27 | 28 | ns3::Vector vlc_NetDevice::GetPosition(){ 29 | return this->m_mobilityModel->GetPosition(); 30 | } 31 | 32 | void vlc_NetDevice::SetPosition(ns3::Vector position){ 33 | m_mobilityModel->SetPosition(position); 34 | } 35 | 36 | double vlc_NetDevice::GetElevation(){ 37 | return m_mobilityModel->GetElevation(); 38 | } 39 | 40 | void vlc_NetDevice::SetElevation(double elevation){ 41 | 42 | m_mobilityModel->SetElevation(elevation); 43 | } 44 | 45 | ns3::Ptr vlc_NetDevice::GetMobilityModel(){ 46 | return m_mobilityModel; 47 | } 48 | void vlc_NetDevice::SetMobilityModel(ns3::Ptr model){ 49 | m_mobilityModel = model; 50 | } 51 | 52 | 53 | vlc_NetDevice::~vlc_NetDevice() { 54 | 55 | } 56 | 57 | } /* namespace vlc */ 58 | 59 | -------------------------------------------------------------------------------- /model/vlcNetDevice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcNetDevice.h 3 | * 4 | * Created on: Mar 25, 2016 5 | * Author: Adel Aldalbahi 6 | */ 7 | 8 | #ifndef VLCNETDEVICE_H_ 9 | #define VLCNETDEVICE_H_ 10 | 11 | #include "ns3/point-to-point-net-device.h" 12 | #include "ns3/point-to-point-channel.h" 13 | #include "ns3/vlcMobilityModel.h" 14 | #include "ns3/mobility-model.h" 15 | #include "ns3/pointer.h" 16 | #include "ns3/ptr.h" 17 | #include "ns3/core-module.h" 18 | #include "ns3/object.h" 19 | 20 | namespace vlc { 21 | 22 | class vlc_NetDevice: public ns3::PointToPointNetDevice { 23 | 24 | public: 25 | vlc_NetDevice(); 26 | 27 | virtual ~vlc_NetDevice(); 28 | 29 | //returns the azmuth, i.e. facing of the device 30 | double GetAzmuth(); 31 | //sets the azmuth,i.e. facing of the device 32 | void SetAzmuth(double az); 33 | 34 | //returns the x,y,z co-ordinates of the device 35 | ns3::Vector GetPosition(); 36 | 37 | //sets the position of the device to a particular x,y,z value 38 | void SetPosition(ns3::Vector position); 39 | 40 | //returns the elevation of the device 41 | double GetElevation(); 42 | 43 | //sets the elevation of the device 44 | void SetElevation(double elevation); 45 | 46 | //returns a pointer to the mobility model of the device 47 | ns3::Ptr GetMobilityModel(); 48 | 49 | //sets the mobility model of the device 50 | void SetMobilityModel(ns3::Ptr model); 51 | 52 | 53 | 54 | private: 55 | ns3::Ptr m_mobilityModel; 56 | 57 | }; 58 | 59 | } /* namespace vlc */ 60 | 61 | #endif /* VLCNETDEVICE_H_ */ 62 | -------------------------------------------------------------------------------- /wscript: -------------------------------------------------------------------------------- 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- 2 | 3 | # def options(opt): 4 | # pass 5 | 6 | def configure(conf): 7 | conf.check_nonfatal(header_name='stdint.h', define_name='HAVE_STDINT_H') 8 | 9 | def build(bld): 10 | module = bld.create_ns3_module('vlcnew', ['core','network', 'mpi', 'mobility', 'propagation','point-to-point']) 11 | module.source = [ 12 | 'model/vlcnew.cc', 13 | 'helper/vlcnew-helper.cc', 14 | 'helper/vlcChannelHelper.cc', 15 | 'helper/vlcDeviceHelper.cc', 16 | 'model/vlcNetDevice.cc', 17 | 'model/vlcchannel.cc', 18 | 'model/vlcMobilityModel.cc', 19 | 'model/VlcPropagationLoss.cc', 20 | 'model/vlcNetDeviceRX.cc', 21 | 'model/vlcNetDeviceTX.cc', 22 | 'model/VLC_SNR.cc' , 23 | 'model/VLC-error-model.cc' , 24 | ] 25 | 26 | module_test = bld.create_ns3_module_test_library('vlcnew') 27 | module_test.source = [ 28 | 'test/vlcnew-test-suite.cc', 29 | ] 30 | 31 | headers = bld(features='ns3header') 32 | headers.module = 'vlcnew' 33 | headers.source = [ 34 | 'model/vlcnew.h', 35 | 'helper/vlcnew-helper.h', 36 | 'helper/vlcChannelHelper.h', 37 | 'helper/vlcDeviceHelper.h', 38 | 'model/vlcNetDevice.h', 39 | 'model/vlcchannel.h', 40 | 'model/vlcMobilityModel.h', 41 | 'model/VlcPropagationLoss.h', 42 | 'model/vlcNetDeviceRX.h', 43 | 'model/vlcNetDeviceTX.h', 44 | 'model/VLC_SNR.h' , 45 | 'model/VLC-error-model.h' , 46 | ] 47 | 48 | if bld.env.ENABLE_EXAMPLES: 49 | bld.recurse('examples') 50 | 51 | # bld.ns3_python_bindings() 52 | 53 | -------------------------------------------------------------------------------- /helper/vlcDeviceHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcDeviceHelper.h 3 | * 4 | * Created on: Apr 9, 2016 5 | * Author: adel 6 | */ 7 | 8 | #ifndef VLCDEVICEHELPER_H_ 9 | #define VLCDEVICEHELPER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include "ns3/vlcNetDeviceRX.h" 16 | #include "ns3/vlcNetDeviceTX.h" 17 | #include "ns3/core-module.h" 18 | #include "ns3/VLC-error-model.h" 19 | 20 | 21 | namespace vlc { 22 | 23 | 24 | class vlc_DeviceHelper : public Object{ 25 | public: 26 | vlc_DeviceHelper(); 27 | 28 | ~vlc_DeviceHelper(); 29 | 30 | void CreateTransmitter(std::string TXName); 31 | 32 | void CreateReceiver(std::string RXName); 33 | 34 | ns3::Ptr GetTransmitter(std::string devName); 35 | 36 | ns3::Ptr GetReceiver(std::string devName); 37 | 38 | 39 | std::vector GenerateSignal(int size,double dutyRatio,double bias, double VMax,double VMin); 40 | 41 | void SetTXSignal(std::string devName,int size,double dutyRatio,double bias, double VMax,double VMin); 42 | 43 | void SetTrasmitterParameter(std::string devName, std::string paramName, double value ); 44 | 45 | void SetTrasmitterBoost(std::string devName); 46 | 47 | void SetTrasmitterPosition(std::string devName, double x, double y, double z); 48 | 49 | void SetReceiverPosition(std::string devName, double x, double y, double z); 50 | 51 | void SetReceiverParameter(std::string devName, std::string paramName, double value ); 52 | 53 | double GetReceiverParameter(std::string devName,std::string paramName); 54 | 55 | private: 56 | std::map > m_TXDevices; 57 | std::map > m_RXDevices; 58 | 59 | }; 60 | 61 | } /* namespace vlc */ 62 | 63 | #endif /* VLCDEVICEHELPER_H_ */ 64 | -------------------------------------------------------------------------------- /helper/vlcChannelHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcChannelHelper.h 3 | * 4 | * Created on: Apr 10, 2016 5 | * Author: adel 6 | */ 7 | 8 | #ifndef VLCCHANNELHELPER_H_ 9 | #define VLCCHANNELHELPER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "ns3/core-module.h" 15 | #include "ns3/vlcchannel.h" 16 | #include "ns3/vlcDeviceHelper.h" 17 | #include "ns3/net-device-container.h" 18 | #include "ns3/queue.h" 19 | #include "ns3/vlcNetDevice.h" 20 | #include "ns3/vlcNetDeviceRX.h" 21 | #include "ns3/vlcNetDeviceTX.h" 22 | #include "ns3/object-factory.h" 23 | 24 | 25 | 26 | 27 | namespace vlc { 28 | 29 | class vlcChannelHelper : public Object { 30 | public: 31 | vlcChannelHelper(); 32 | 33 | void CreateChannel(std::string channelName); 34 | 35 | void SetChannelWavelength(std::string channelName, int lower, int upper); 36 | 37 | void SetPropagationLoss(std::string channelName, std::string propagationLossType); 38 | 39 | void SetPropagationDelay(std::string channelName, double value); 40 | 41 | void AttachTransmitter(std::string chName,std::string TXDevName, ns3::Ptr devHelper); 42 | 43 | void AttachReceiver(std::string chName,std::string RXDevName, ns3::Ptr devHelper); 44 | 45 | double GetChannelSNR(std::string chName); 46 | 47 | void SetChannelParameter(std::string chName,std::string paramName, double value); 48 | 49 | ns3::Ptr GetChannel(std::string chName); 50 | 51 | ns3::Ptr< vlc_NetDevice > GetDevice(std::string chName,uint32_t idx); 52 | 53 | ns3::NetDeviceContainer Install(std::string chName,Ptr a, Ptr b); 54 | 55 | virtual ~vlcChannelHelper(); 56 | 57 | private: 58 | 59 | std::map< std::string, ns3::Ptr > m_channel; 60 | 61 | ObjectFactory m_queueFactory; 62 | 63 | }; 64 | 65 | } /* namespace vlc */ 66 | 67 | #endif /* VLCCHANNELHELPER_H_ */ 68 | -------------------------------------------------------------------------------- /model/VLC_SNR.h: -------------------------------------------------------------------------------- 1 | #ifndef VLC_SNR_H 2 | #define VLC_SNR_H 3 | 4 | 5 | #include "ns3/object.h" 6 | 7 | namespace ns3 { 8 | 9 | class VLC_SNR : public Object // This class is a subclass of Object class 10 | { 11 | public: 12 | // Public methods 13 | static TypeId GetTypeId (void); // returns meta-information about PAMErrorModel class 14 | 15 | VLC_SNR (); // constructor 16 | virtual ~VLC_SNR (); //destructor 17 | 18 | void SetWavelength (int lower, int upper); // sets upper and lower bound wavelength [nm] 19 | void SetTemperature (double t); // sets the blackbody temperature of LED 20 | double GetTemperature(); 21 | void SetReceivedPower (double p); // sets the average received optical signal power 22 | void SetElectricNoiseBandWidth (double b); // sets the noise bandwidth 23 | double GetNoiseBandwidth(); //return the noise bandwidth 24 | 25 | void CalculateNoiseVar (double A); //calculates the noise variance 26 | void CalculateSNR (); // caluclates the SNR value 27 | double GetSNR () ; // returns the signal-to-noise ratio (SNR) 28 | 29 | private: 30 | // Private methods called by other methods inside the class 31 | double IntegralPlanck(); 32 | double IntegralRes(); 33 | double SpectralRadiance(int wavelength, double temperature); 34 | 35 | // Private class members 36 | double noise_var; // total noise variance 37 | double Pr; // average received optical signal power 38 | double res; // responsitivity of receiver 39 | double SNR; // signal-to-noise ratio 40 | double B; // B: electric noise bandwidth 41 | 42 | int wavelength_lower; // lower bound WaveLength [nm] 43 | int wavelength_upper; // upper bound Wavelength [nm] 44 | double temp; // Blackbody temp of LED 45 | 46 | static double V_lambda[]; 47 | static double Response[]; 48 | }; 49 | 50 | } // namespace ns3 51 | #endif 52 | -------------------------------------------------------------------------------- /model/vlcMobilityModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcMobilityModel.h 3 | * 4 | * Created on: Mar 26, 2016 5 | * Author: Adel Aldalbahi 6 | */ 7 | 8 | #ifndef VLCMOBILITYMODEL_H_ 9 | #define VLCMOBILITYMODEL_H_ 10 | 11 | #include "ns3/mobility-model.h" 12 | #include "ns3/vector.h" 13 | #include "ns3/enum.h" 14 | #include "ns3/double.h" 15 | #include "ns3/string.h" 16 | #include "ns3/pointer.h" 17 | #include "ns3/simulator.h" 18 | #include "ns3/log.h" 19 | #include 20 | 21 | namespace vlc { 22 | 23 | class VlcMobilityModel : public ns3::MobilityModel { 24 | public: 25 | /** 26 | * Register this type with the TypeId system. 27 | * \return the object TypeId 28 | */ 29 | static ns3::TypeId GetTypeId (void); 30 | /** 31 | * Create position located at coordinates (0,0,0) with 32 | * speed (0,0,0). 33 | */ 34 | VlcMobilityModel (); 35 | virtual ~VlcMobilityModel (); 36 | /** 37 | * Set the model's velocity and acceleration 38 | * \param velocity the velocity (m/s) 39 | * \param acceleration the acceleration (m/s^2) 40 | */ 41 | void SetVelocityAndAcceleration (const ns3::Vector &velocity, const ns3::Vector &acceleration); 42 | 43 | void SetAzimuth(double angle); 44 | double GetAzimuth(void); 45 | 46 | void SetElevation (double angle); 47 | double GetElevation (void); 48 | 49 | private: 50 | virtual ns3::Vector DoGetPosition (void) const; 51 | virtual void DoSetPosition (const ns3::Vector &position); 52 | virtual ns3::Vector DoGetVelocity (void) const; 53 | 54 | ns3::Time m_baseTime; //!< the base time 55 | ns3::Vector m_basePosition; //!< the base position 56 | ns3::Vector m_baseVelocity; //!< the base velocity 57 | ns3::Vector m_acceleration; //!< the acceleration 58 | double m_azimuth; //Rotation (left/;; and Right) 59 | double m_elevation; //Rotation Angle}; 60 | }; 61 | 62 | } /* namespace vlc */ 63 | 64 | 65 | #endif /* VLC_MOBILITY_MODEL_H */ 66 | -------------------------------------------------------------------------------- /test/vlcnew-test-suite.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 | 3 | // Include a header file from your module to test. 4 | #include "ns3/vlcnew.h" 5 | 6 | // An essential include is test.h 7 | #include "ns3/test.h" 8 | 9 | // Do not put your test classes in namespace ns3. You may find it useful 10 | // to use the using directive to access the ns3 namespace directly 11 | using namespace ns3; 12 | 13 | // This is an example TestCase. 14 | class VlcnewTestCase1 : public TestCase 15 | { 16 | public: 17 | VlcnewTestCase1 (); 18 | virtual ~VlcnewTestCase1 (); 19 | 20 | private: 21 | virtual void DoRun (void); 22 | }; 23 | 24 | // Add some help text to this case to describe what it is intended to test 25 | VlcnewTestCase1::VlcnewTestCase1 () 26 | : TestCase ("Vlcnew test case (does nothing)") 27 | { 28 | } 29 | 30 | // This destructor does nothing but we include it as a reminder that 31 | // the test case should clean up after itself 32 | VlcnewTestCase1::~VlcnewTestCase1 () 33 | { 34 | } 35 | 36 | // 37 | // This method is the pure virtual method from class TestCase that every 38 | // TestCase must implement 39 | // 40 | void 41 | VlcnewTestCase1::DoRun (void) 42 | { 43 | // A wide variety of test macros are available in src/core/test.h 44 | NS_TEST_ASSERT_MSG_EQ (true, true, "true doesn't equal true for some reason"); 45 | // Use this one for floating point comparisons 46 | NS_TEST_ASSERT_MSG_EQ_TOL (0.01, 0.01, 0.001, "Numbers are not equal within tolerance"); 47 | } 48 | 49 | // The TestSuite class names the TestSuite, identifies what type of TestSuite, 50 | // and enables the TestCases to be run. Typically, only the constructor for 51 | // this class must be defined 52 | // 53 | class VlcnewTestSuite : public TestSuite 54 | { 55 | public: 56 | VlcnewTestSuite (); 57 | }; 58 | 59 | VlcnewTestSuite::VlcnewTestSuite () 60 | : TestSuite ("vlcnew", UNIT) 61 | { 62 | // TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER 63 | AddTestCase (new VlcnewTestCase1, TestCase::QUICK); 64 | } 65 | 66 | // Do not forget to allocate an instance of this TestSuite 67 | static VlcnewTestSuite vlcnewTestSuite; 68 | 69 | -------------------------------------------------------------------------------- /model/VlcPropagationLoss.h: -------------------------------------------------------------------------------- 1 | /* 2 | * VlcPropagationLoss.h 3 | * 4 | * Created on: Mar 27, 2016 5 | * Author: Adel Aldabahi 6 | */ 7 | 8 | #ifndef VLCPROPAGATIONLOSS_H_ 9 | #define VLCPROPAGATIONLOSS_H_ 10 | 11 | #include "ns3/point-to-point-channel.h" 12 | #include "ns3/propagation-loss-model.h" 13 | #include "ns3/propagation-delay-model.h" 14 | #include "ns3/ptr.h" 15 | #include "ns3/pointer.h" 16 | #include "ns3/mobility-model.h" 17 | #include "ns3/point-to-point-net-device.h" 18 | #include 19 | 20 | 21 | using namespace ns3; 22 | 23 | namespace vlc { 24 | 25 | class VLCPropagationLossModel: public ns3::PropagationLossModel { 26 | 27 | public: 28 | /** 29 | * \breif Get the type ID. 30 | * \return the object TypeId 31 | */ 32 | //static ns3::TypeId GetTypeId(void); 33 | //Constructor 34 | VLCPropagationLossModel(); 35 | void SetTxPower(double watt); 36 | void SetTxPowerMAX(double MAX); 37 | 38 | double GetTxPower(); 39 | double GetTxPowerMAX(); 40 | 41 | 42 | void SetFilterGain(double gain); 43 | double GetFilterGain(); 44 | 45 | void SetConcentratorGain(double cGain); //set concentration gain calculated in RX 46 | double GetConcentratorGain(); 47 | 48 | void SetTXGain(double txgain); 49 | double GetTXGain(); 50 | 51 | void SetRXGain(double rxgain); 52 | double GetRXGain(); 53 | 54 | double GetDistance(ns3::Ptr aTX, ns3::Ptr bRX) const; 55 | 56 | double GetRxPower(); 57 | 58 | void SetRXPower(double wattTX, ns3::Ptr aTX, 59 | ns3::Ptr bRX); 60 | 61 | 62 | 63 | double dotProduct(std::vector v1, std::vector v2) const; 64 | double magnitude(std::vector v) const; 65 | 66 | ~VLCPropagationLossModel(); 67 | private: 68 | /** 69 | * \brief Copy constructor 70 | * 71 | * Defined and unimplemented to avoid misuse 72 | */ 73 | VLCPropagationLossModel(const VLCPropagationLossModel &); 74 | /** 75 | * \brief Copy constructor 76 | * 77 | * Defined and unimplemented to avoid misuse 78 | * \returns 79 | */ 80 | VLCPropagationLossModel & operator =(const VLCPropagationLossModel &); 81 | 82 | virtual double DoCalcRxPower(double txPowerDbm, ns3::Ptr aTX,ns3::Ptr bRX) const; 83 | 84 | virtual int64_t DoAssignStreams(int64_t stream); 85 | 86 | double m_TxPower; 87 | double m_TxPowerMAX; 88 | 89 | double m_FilterGain; 90 | double m_ConcentratorGain; 91 | double m_RxPower; 92 | 93 | double m_TXGain; 94 | double m_RXGain; 95 | 96 | }; 97 | 98 | } /* namespace vlc */ 99 | 100 | #endif /* VLCPROPAGATIONLOSS_H_ */ 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VLC 2 | We provide visible light communication (vlc) module that is implemented using NS3 to simulate large-scale vlc.Please refer to the doc directory for more details. 3 | 4 | If you do not have NS3 installed in your PC, please refer to the following link for installation: 5 | 6 | https://www.nsnam.org/docs/release/3.24/tutorial/singlehtml/index.html 7 | Installation guide: https://www.nsnam.org/wiki/Installation (Follow the instructions for installation depending on which flavor of Linux you prefer) 8 | 9 | Once an example script is made and compiles, to run this script it must be in the scratch directory: 10 | To get to this directory run the cmd: cd repos/ns-3-allinone/ns-3-dev/scratch (path is not fixed also it depends on which ns3 version you install) 11 | 12 | NS-3 file documentation: https://www.nsnam.org/doxygen/index.html (gives an idead of ns3 classes structure) 13 | 14 | Steps to install VLC module into NS3: 15 | 16 | Prerequisites: 17 | 18 | 1-Having the NS3 environment installed and running in your linux environment 19 | 20 | 21 | Installation: 22 | 23 | 1) download .zip file of the vlc module 24 | 25 | 2) open .zip file and you should see a simple folder named vlcnew 26 | 27 | 3) enter that folder and you should see folders that mimic the ones in the repository 28 | 29 | 4) Now, go into the terminal and build a skeleton module by typing "./create-module.py vlcnew" (please follow ns3 guidline on how to build new module) 30 | 31 | 5) Find your NS3 file system and in the "src" folder there should be a "vlcnew" folder, open that and you should see similar folder names to that of the repository. 32 | 33 | 6) you should delete those files as they will be replaced by the files downloaded from the repository 34 | 35 | 7) Look back to where you unziped the downloaded repository files and copy and paste those folders and files into this newly made folder (do not copy the scratch folder) 36 | 37 | 8) Now, start up the terminal and go to the ns-3-dev directory 38 | 39 | 9) While in this directory build all the NS3 modules (if unsure use the installation guide to help, I use ubuntu and my command is ./waf build) 40 | 41 | 10) It is optional to enable tests and examples but it should build regardless ( build will take sometimes! have your coffee ready!) 42 | 43 | 11) now you can use the vlcnew-module in ns3 simulations 44 | 45 | 12) as far as the error model and propagation model are concerned, they can be also put into the model folder of the module but propagation can also be added onto the propagation module that is native to ns3, just be sure to add everything to its respective wscript 46 | 47 | //Running a script 48 | 49 | 1) create a file a .cc file and follow the format that the example scripts use (in terms of laying out the script) 50 | 51 | 2) move the file into the /scratch directory (must run any test from the scratch directory) 52 | 53 | 3) to compile and run use the command "./waf --run scratch/your_file_name_without_.cc 54 | -------------------------------------------------------------------------------- /model/VLC-error-model.h: -------------------------------------------------------------------------------- 1 | #ifndef VLC_ERROR_MODEL_H 2 | #define VLC_ERROR_MODEL_H 3 | 4 | #include 5 | #include "ns3/error-model.h" 6 | #include "ns3/random-variable-stream.h" 7 | #include 8 | #include 9 | 10 | namespace ns3 { 11 | 12 | class Packet; 13 | 14 | class VLC_ErrorModel : public RateErrorModel // This class is a subclass of RateErrorModel class 15 | { 16 | public: 17 | // Public methods 18 | static TypeId GetTypeId (void); // returns meta-information about VLC_ErrorModel class 19 | 20 | VLC_ErrorModel (); // constructor 21 | virtual ~VLC_ErrorModel (); //destructor 22 | 23 | enum ModScheme // enumeration for the two modulation schemes 24 | { 25 | PAM, 26 | OOK, 27 | VPPM 28 | }; 29 | 30 | VLC_ErrorModel::ModScheme GetScheme (void) const; // returns the modulation scheme used 31 | 32 | void SetScheme (ModScheme scheme); // sets the value of the modulation scheme used 33 | 34 | void SetScheme (std::string scheme); // sets the value of the modulation scheme used 35 | 36 | void SetRandomVariable (Ptr ranVar); // assigns a random variable stream to be used by this model 37 | 38 | int64_t AssignStreams (int64_t stream); // assigns a fixed stream number to the random variables used by this model 39 | 40 | double GetSNR (void) const; // returns the signal-to-noise ratio (SNR) 41 | 42 | void SetSNR (double snr); // sets the SNR value 43 | 44 | double CalculateErrorRate (void); // calculates the error rate value according to modulation scheme 45 | 46 | bool IsCorrupt (Ptr pkt); // determines if the packet is corrupted according to the error model 47 | 48 | // methods for PAM 49 | int GetModulationOrder (void) const; // returns the modulation order (M) 50 | void SetModulationOrder (int m_order); // sets the modulation order value 51 | 52 | // methods for VPPM 53 | double GetAlpha(void) const; // returns alpha value 54 | void SetAlpha (double a); // sets alpha value 55 | 56 | double GetBeta(void) const; // returns beta value 57 | void SetBeta (double b); // sets beta value 58 | 59 | private: 60 | // Private methods 61 | virtual void DoReset (void); // overrides DoReset method from RateErrorModel class 62 | double CalculateSER (void); // calculates the SER value (for OOK and PAM) 63 | double CalculateBER (void); // calculates the BER value (for VPPM) 64 | 65 | 66 | // Private class members 67 | int mod_order; // the modulation order (M) of PAM scheme 68 | double alpha; // the duty cycle of the VPPM signal 69 | double beta; // a factor relating noise bandwidth to signal bandwidth in VPPM 70 | double SNR; // signal-to-noise ratio 71 | 72 | Ptr m_ranvar; // random variable stream 73 | VLC_ErrorModel::ModScheme mod_scheme; // the modulation scheme used 74 | }; 75 | 76 | } // namespace ns3 77 | #endif 78 | -------------------------------------------------------------------------------- /model/VlcPropagationLoss.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * VlcPropagationLoss.cc 3 | * 4 | * Created on: Mar 27, 2016 5 | * Author: Adel Aldalbahi 6 | */ 7 | 8 | #include "ns3/VlcPropagationLoss.h" 9 | 10 | namespace vlc { 11 | 12 | 13 | VLCPropagationLossModel::VLCPropagationLossModel() { 14 | m_TxPowerMAX = 0; 15 | m_TxPower = 0; 16 | m_FilterGain = 0; 17 | m_ConcentratorGain = 0; 18 | m_RxPower = 0; 19 | 20 | m_RXGain = 0 ; 21 | m_TXGain = 0; 22 | 23 | } 24 | 25 | void VLCPropagationLossModel::SetTxPower(double watt){ 26 | this->m_TxPower = watt; 27 | } 28 | void VLCPropagationLossModel::SetTxPowerMAX(double MAX){ 29 | this->m_TxPowerMAX = MAX; 30 | } 31 | 32 | double VLCPropagationLossModel::GetTxPower(){ 33 | return this->m_TxPower; 34 | } 35 | 36 | double VLCPropagationLossModel::GetTxPowerMAX(){ 37 | return this->m_TxPowerMAX; 38 | } 39 | 40 | 41 | void VLCPropagationLossModel::SetFilterGain(double gain){ 42 | this->m_FilterGain = gain; 43 | } 44 | 45 | double VLCPropagationLossModel::GetFilterGain(){ 46 | return this->m_FilterGain; 47 | } 48 | 49 | void VLCPropagationLossModel::SetConcentratorGain(double cGain){ 50 | this->m_ConcentratorGain = cGain; 51 | } 52 | 53 | double VLCPropagationLossModel::GetConcentratorGain(){ 54 | return this->m_ConcentratorGain; 55 | } 56 | 57 | double VLCPropagationLossModel::DoCalcRxPower(double txPowerDbm, ns3::Ptr aTX,ns3::Ptr bRX) const{ 58 | double distance = this->GetDistance(aTX,bRX); 59 | double pRX = txPowerDbm*this->m_RXGain*this->m_TXGain*this->m_FilterGain*this->m_ConcentratorGain ; 60 | pRX /= std::pow(distance,2); 61 | 62 | return pRX; 63 | } 64 | 65 | double VLCPropagationLossModel::GetRxPower(){ 66 | return this->m_RxPower; 67 | } 68 | 69 | void VLCPropagationLossModel::SetRXPower(double wattTX, ns3::Ptr aTX, 70 | ns3::Ptr bRX){ 71 | this->m_RxPower = this->DoCalcRxPower(wattTX,aTX,bRX); 72 | } 73 | 74 | int64_t VLCPropagationLossModel::DoAssignStreams(int64_t stream){ 75 | return stream; 76 | } 77 | 78 | double VLCPropagationLossModel::GetDistance(ns3::Ptr aTX, ns3::Ptr bRX) const{ 79 | double dist = 0; 80 | Vector tx = aTX->GetPosition(); 81 | Vector rx = bRX->GetPosition(); 82 | dist = std::pow((tx.x-rx.x),2) + std::pow((tx.y-rx.y),2) + std::pow((tx.z-rx.z),2) ; 83 | dist = std::sqrt(dist); 84 | return dist; 85 | } 86 | 87 | void VLCPropagationLossModel::SetTXGain(double txgain){ 88 | this->m_TXGain = txgain; 89 | } 90 | 91 | double VLCPropagationLossModel::GetTXGain(){ 92 | return this->m_TXGain; 93 | } 94 | 95 | void VLCPropagationLossModel::SetRXGain(double rxgain){ 96 | this->m_RXGain = rxgain; 97 | } 98 | 99 | double VLCPropagationLossModel::GetRXGain(){ 100 | return this->m_RXGain; 101 | } 102 | 103 | VLCPropagationLossModel::~VLCPropagationLossModel() { 104 | 105 | } 106 | 107 | } /* namespace vlc */ 108 | 109 | -------------------------------------------------------------------------------- /model/vlcNetDeviceTX.h: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcNetDeviceTX.h 3 | * 4 | * Created on: Mar 25, 2016 5 | * Author: Adel Aldabahi 6 | */ 7 | 8 | #ifndef VLCNETDEVICETX_H_ 9 | #define VLCNETDEVICETX_H_ 10 | 11 | 12 | 13 | #include "ns3/core-module.h" 14 | #include "ns3/vlcNetDevice.h" 15 | #include "ns3/ptr.h" 16 | #include "ns3/vlcchannel.h" 17 | #include 18 | 19 | 20 | namespace vlc { 21 | 22 | class vlc_NetDeviceTX : public vlc::vlc_NetDevice { 23 | 24 | public: 25 | vlc_NetDeviceTX(); 26 | 27 | virtual ~vlc_NetDeviceTX(); 28 | 29 | //adds a signal instant to the TX optical power signal 30 | void AddTXOpticalPowerSignal(double power); 31 | 32 | //returns the TX Optical power signal in the form of std::vector of doubles 33 | std::vector& GetTXOpticalPowerSignal(); 34 | 35 | //returns the TX power signal at instant time, time has to be lesser than the capacity of std::vector of signal 36 | double GetOpticalPowerSignalAtInstant(int time); 37 | 38 | //sets the TX power signal from a std::vector 39 | void SetTXOpticalPowerSignal(std::vector &powerSignal); 40 | 41 | //reserves the capacity of signal vector 42 | void SetCapacity(int size); 43 | 44 | //returns the semiangle of the TX device 45 | double GetSemiangle(); 46 | 47 | //sets the semianle of the TX device 48 | void SetSemiangle(double angle); 49 | 50 | //sets the angle of radiance of the TX device 51 | void SetAngleOfRadiance(double angle); 52 | 53 | //returns the angle of radiance of the TX device 54 | double GetAngleOfRadiance(); 55 | 56 | //returns the lambertian order of the TX device 57 | double GetLambertianOrder(); 58 | 59 | //computes and then sets the lambertian order of the TX device 60 | void SetLambertainOrder(); 61 | 62 | //returns the gain of the TX device 63 | double GetTXGain(); 64 | //computes and sets the gain of the TX device 65 | void SetTXGain(); 66 | 67 | //adds a signal component to the signal vector 68 | void AddSignal(double signal); 69 | 70 | //returns the signal vector of the TX device 71 | std::vector& GetSignal(); 72 | 73 | //returns the magnitude of the signal at a particular instant 74 | double GetSignalAtInstant(int time); 75 | 76 | //sets the signal vector of the TX device 77 | void SetSignal(std::vector &signal); 78 | 79 | //sets the bias voltage of the TX device 80 | void SetBias(double bias); 81 | 82 | //returns the bias voltage of the TX device 83 | double GetBias(); 84 | 85 | //calculates the optical power signal after biasing it by m_bias 86 | void BoostSignal(); 87 | 88 | //returns the Maximum TX power that can be transmitted 89 | double GetTXPowerMax(); 90 | 91 | //returns the average of TX Power signal 92 | double GetAveragePowerSignalPower(); 93 | 94 | 95 | //returns the average of the TX signal 96 | double GetAverageSignal(); 97 | 98 | 99 | private: 100 | std::vector m_TXOpticalPower; 101 | std::vector m_signal; 102 | const double m_TMAX; 103 | double m_semiangle; 104 | double m_angleOfRadiance; 105 | double m_lOrder; 106 | double m_TXGain; 107 | double m_bias; 108 | 109 | }; 110 | 111 | } /* namespace vlc */ 112 | 113 | #endif /* VLCNETDEVICETX_H_ */ 114 | -------------------------------------------------------------------------------- /model/vlcchannel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcchannel.h 3 | * 4 | * Created on: Mar 23, 2016 5 | * Author: Adel Aldalbahi 6 | */ 7 | 8 | #ifndef SRC_VLCNEW_VLCCHANNEL_H_ 9 | #define SRC_VLCNEW_VLCCHANNEL_H_ 10 | 11 | #include "ns3/point-to-point-channel.h" 12 | #include "ns3/propagation-loss-model.h" 13 | #include "ns3/propagation-delay-model.h" 14 | #include "ns3/pointer.h" 15 | #include "ns3/ptr.h" 16 | #include "ns3/core-module.h" 17 | #include "ns3/mobility-module.h" 18 | #include "ns3/VlcPropagationLoss.h" 19 | #include "ns3/VLC_SNR.h" 20 | #include "ns3/VLC-error-model.h" 21 | #include "ns3/log.h" 22 | 23 | #include "ns3/vlcNetDevice.h" 24 | #include "ns3/vlcNetDeviceTX.h" 25 | #include "ns3/vlcNetDeviceRX.h" 26 | 27 | 28 | namespace vlc { 29 | 30 | class vlc_channel : public ns3::PointToPointChannel { 31 | public: 32 | vlc_channel(); 33 | 34 | virtual ~vlc_channel(); 35 | 36 | void SetPropagationLossModel(ns3::Ptr loss); //sets the propagation loss model for the channel 37 | 38 | ns3::Ptr GetPropagationLossModel(); //returns a pointer to the propagation loss model 39 | 40 | void SetPropagationDelayModel(ns3::Ptr delay); //sets the propagation delay model for the channel 41 | 42 | ns3::Ptr GetPropagationDelayModel(); //returns the propagation delay model of the channel 43 | 44 | void SetPropagationDelay(double delay); 45 | 46 | double GetDistance(); //returns the distance after computing the distance using the mobility models of TX and RX 47 | 48 | void SetDistance(); //sets the distance after computing the distance using the mobility models of TX and RX 49 | 50 | void DoCalcPropagationLoss(); //calculates the optical power signal for the RX using the optical power signal of the TX and loss model 51 | 52 | void SetPorpagationLossParametersFromTX(); //sets the parameters of the loss model from the TX 53 | 54 | void SetPorpagationLossParametersFromRX(); //sets the paraameters of the loss model from the RX 55 | 56 | double DoCalcPropagationLossForSignal(int timeInstant); //computes the optical power signal of RX at a particular instant 57 | 58 | void SetAveragePower(double power); //computes the averaage power of the signals 59 | 60 | double GetAveragePower(); //returns the average power of the signalss 61 | 62 | void SetWavelength (int lower, int upper); // sets upper and lower bound wavelength [nm] 63 | 64 | void SetTemperature (double t); // sets the blackbody temperature of LED 65 | 66 | double GetTemperature(); 67 | 68 | void SetReceivedPower (double p); // sets the average received optical signal power 69 | 70 | void CalculateNoiseVar (); //calculates the noise variance 71 | 72 | void CalculateSNR (); // caluclates the SNR value 73 | 74 | double GetSNR () const; // returns the signal-to-noise ratio (SNR) 75 | 76 | void SetElectricNoiseBandWidth (double b); // sets the noise bandwidth 77 | double GetNoiseBandwidth(); //return the noise bandwidth 78 | 79 | 80 | private: 81 | ns3::Ptr m_loss; 82 | double m_distanceBWTXandRX; 83 | ns3::Ptr m_delay; 84 | double m_AvgPower; 85 | ns3::Ptr m_SNR; 86 | 87 | }; 88 | 89 | } /* namespace vlc */ 90 | 91 | #endif /* SRC_VLCNEW_VLCCHANNEL_H_ */ 92 | -------------------------------------------------------------------------------- /model/vlcNetDeviceTX.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcNetDeviceTX.cc 3 | * 4 | * Created on: Mar 25, 2016 5 | * Author: Adel Aldabahi 6 | */ 7 | 8 | #include "ns3/vlcNetDeviceTX.h" 9 | 10 | namespace vlc { 11 | 12 | vlc_NetDeviceTX::vlc_NetDeviceTX(): m_TMAX(60){ 13 | m_semiangle = 70; 14 | m_angleOfRadiance = 0; 15 | m_lOrder = 1; 16 | m_TXGain = 0; 17 | m_bias = 0; 18 | } 19 | 20 | double vlc_NetDeviceTX::GetLambertianOrder(){ 21 | return this->m_lOrder; 22 | } 23 | 24 | //before setting Lambertian Order make sure the semiangle value is set 25 | //Need to setup error handling when semiangle is not set 26 | void vlc_NetDeviceTX::SetLambertainOrder(){ 27 | this->m_lOrder = (-1*log(2))/(log(cos(this->m_semiangle))); 28 | } 29 | 30 | void vlc_NetDeviceTX::AddTXOpticalPowerSignal(double power){ 31 | this->m_TXOpticalPower.push_back(power); 32 | } 33 | std::vector& vlc_NetDeviceTX::GetTXOpticalPowerSignal(){ 34 | return this->m_TXOpticalPower; 35 | } 36 | double vlc_NetDeviceTX::GetOpticalPowerSignalAtInstant(int time){ 37 | return this->m_TXOpticalPower.at(time); 38 | } 39 | void vlc_NetDeviceTX::SetTXOpticalPowerSignal(std::vector &powerSignal){ 40 | this->m_TXOpticalPower = powerSignal; 41 | } 42 | 43 | 44 | double vlc_NetDeviceTX::GetTXPowerMax(){ 45 | return this->m_TMAX; 46 | } 47 | 48 | void vlc_NetDeviceTX::SetCapacity(int size){ 49 | 50 | m_TXOpticalPower.reserve(size); 51 | m_signal.reserve(size); 52 | } 53 | 54 | double vlc_NetDeviceTX::GetSemiangle(){ 55 | return this->m_semiangle; 56 | } 57 | 58 | void vlc_NetDeviceTX::SetSemiangle(double angle){ 59 | this->m_semiangle = angle*M_PI/180; 60 | this->SetLambertainOrder(); 61 | } 62 | 63 | void vlc_NetDeviceTX::SetAngleOfRadiance(double angle){ 64 | this->m_angleOfRadiance = angle*M_PI/180; 65 | } 66 | 67 | double vlc_NetDeviceTX::GetAngleOfRadiance(){ 68 | return this->m_angleOfRadiance; 69 | } 70 | 71 | double vlc_NetDeviceTX::GetTXGain(){ 72 | return this->m_TXGain; 73 | } 74 | void vlc_NetDeviceTX::SetTXGain(){ 75 | this->m_TXGain = ((this->m_lOrder + 1)/(2*M_PI))*std::pow(std::cos((long double)this->m_angleOfRadiance),2); 76 | } 77 | 78 | 79 | void vlc_NetDeviceTX::AddSignal(double signal){ 80 | this->m_signal.push_back(signal); 81 | } 82 | 83 | std::vector& vlc_NetDeviceTX::GetSignal(){ 84 | return this->m_signal; 85 | } 86 | 87 | double vlc_NetDeviceTX::GetSignalAtInstant(int time){ 88 | return this->m_signal.at(time); 89 | } 90 | 91 | void vlc_NetDeviceTX::SetSignal(std::vector &signal){ 92 | this->m_signal = signal; 93 | } 94 | 95 | void vlc_NetDeviceTX::SetBias(double bias){ 96 | this->m_bias = bias; 97 | } 98 | 99 | double vlc_NetDeviceTX::GetBias(){ 100 | return m_bias; 101 | } 102 | 103 | 104 | void vlc_NetDeviceTX::BoostSignal(){ 105 | 106 | m_TXOpticalPower.clear(); 107 | 108 | for(unsigned int i=0;i< m_signal.size();i++){ 109 | m_TXOpticalPower.push_back( (double)(m_signal.at(i) + m_bias) ); 110 | if(m_TXOpticalPower.at(i) > m_TMAX){ 111 | m_TXOpticalPower.at(i) = m_TMAX; 112 | } 113 | 114 | } 115 | 116 | } 117 | 118 | double vlc_NetDeviceTX::GetAveragePowerSignalPower(){ 119 | double pMax = this->m_TXOpticalPower.at(0); 120 | double pMin = this->m_TXOpticalPower.at(m_TXOpticalPower.size()-1); 121 | return (pMax+pMin)/2; 122 | } 123 | 124 | double vlc_NetDeviceTX::GetAverageSignal(){ 125 | double pMax = m_signal.at(0); 126 | double pMin = m_signal.at(m_signal.size()-1); 127 | return (pMax+pMin)/2; 128 | } 129 | 130 | 131 | vlc_NetDeviceTX::~vlc_NetDeviceTX() { 132 | 133 | } 134 | 135 | } /* namespace vlc */ 136 | -------------------------------------------------------------------------------- /model/vlcMobilityModel.cc: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 4 | * Author: Ryan Ackerman 5 | * 6 | * 7 | */ 8 | #include "ns3/vlcMobilityModel.h" 9 | 10 | using namespace ns3; 11 | 12 | namespace vlc { 13 | 14 | 15 | NS_OBJECT_ENSURE_REGISTERED (VlcMobilityModel); 16 | 17 | 18 | 19 | ns3::TypeId vlc::VlcMobilityModel::GetTypeId (void) 20 | { 21 | static ns3::TypeId tid = ns3::TypeId ("ns3::VlcMobilityModel") 22 | .SetParent () 23 | .SetGroupName ("Mobility") 24 | .AddConstructor () 25 | .AddAttribute("Azimuth", 26 | "The Left and right rotation of the device", 27 | DoubleValue(1.0), 28 | MakeDoubleAccessor (&VlcMobilityModel::m_azimuth), 29 | MakeDoubleChecker ()) 30 | .AddAttribute("Elevation", 31 | "Up and Down rotation of the device", 32 | DoubleValue(1.0), 33 | MakeDoubleAccessor (&VlcMobilityModel::m_elevation), 34 | MakeDoubleChecker ()) 35 | .AddAttribute("Position2", 36 | "Where the Device is", 37 | VectorValue(Vector(0.0,0.0,0.0)), 38 | MakeVectorAccessor (&VlcMobilityModel::m_basePosition), 39 | MakeVectorChecker()); 40 | return tid; 41 | } 42 | 43 | vlc::VlcMobilityModel::VlcMobilityModel () 44 | { 45 | this->m_azimuth = 0; 46 | this->m_elevation = 0; 47 | } 48 | 49 | vlc::VlcMobilityModel::~VlcMobilityModel () 50 | { 51 | 52 | } 53 | 54 | inline Vector 55 | vlc::VlcMobilityModel::DoGetVelocity (void) const 56 | { 57 | double t = (Simulator::Now () - m_baseTime).GetSeconds (); 58 | return Vector (m_baseVelocity.x + m_acceleration.x*t, 59 | m_baseVelocity.y + m_acceleration.y*t, 60 | m_baseVelocity.z + m_acceleration.z*t); // returns a velocity vector of the node that has this mobility model instlled on it 61 | } 62 | 63 | inline Vector 64 | vlc::VlcMobilityModel::DoGetPosition (void) const 65 | { 66 | double t = (Simulator::Now () - m_baseTime).GetSeconds (); 67 | double half_t_square = t*t*0.5; 68 | return Vector (m_basePosition.x + m_baseVelocity.x*t + m_acceleration.x*half_t_square, 69 | m_basePosition.y + m_baseVelocity.y*t + m_acceleration.y*half_t_square, 70 | m_basePosition.z + m_baseVelocity.z*t + m_acceleration.z*half_t_square); // returns a acceleration vector of the node that has this mobility model instlled on it 71 | } 72 | 73 | void 74 | vlc::VlcMobilityModel::DoSetPosition (const Vector &position) //called to set position via vector parameters 75 | { 76 | m_baseVelocity = DoGetVelocity (); 77 | m_baseTime = Simulator::Now (); 78 | m_basePosition = position; 79 | NotifyCourseChange (); 80 | } 81 | 82 | void 83 | vlc::VlcMobilityModel::SetVelocityAndAcceleration (const Vector &velocity, 84 | const Vector &acceleration) // called to set velocity and acceleration via vector parameters 85 | { 86 | m_basePosition = DoGetPosition (); 87 | m_baseTime = Simulator::Now (); 88 | m_baseVelocity = velocity; 89 | m_acceleration = acceleration; 90 | NotifyCourseChange (); 91 | } 92 | 93 | void vlc::VlcMobilityModel::SetAzimuth(double angle) 94 | { 95 | m_azimuth = angle * (M_PI/180); 96 | } 97 | 98 | void vlc::VlcMobilityModel::SetElevation(double angle) 99 | { 100 | m_elevation = angle * (M_PI/180); 101 | } 102 | 103 | double vlc::VlcMobilityModel::GetAzimuth(void) 104 | { 105 | return m_azimuth; 106 | } 107 | double vlc::VlcMobilityModel::GetElevation(void) 108 | { 109 | return m_elevation; 110 | } 111 | 112 | } /* namespace vlc */ 113 | 114 | -------------------------------------------------------------------------------- /helper/vlcChannelHelper.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcChannelHelper.cc 3 | * 4 | * Created on: Apr 10, 2016 5 | * Author: Adel 6 | */ 7 | 8 | #include "vlcChannelHelper.h" 9 | 10 | namespace vlc { 11 | 12 | vlcChannelHelper::vlcChannelHelper() { 13 | //NS_LOG_FUNCTION(this); 14 | } 15 | 16 | void vlcChannelHelper::CreateChannel(std::string channelName){ 17 | //NS_LOG_FUNCTION(this); 18 | this->m_channel[channelName] = CreateObject(); 19 | } 20 | 21 | void vlcChannelHelper::SetChannelParameter(std::string chName,std::string paramName, double value){ 22 | if(paramName=="TEMP"){ 23 | this->m_channel[chName]->SetTemperature(value); 24 | } 25 | else if(paramName=="ElectricNoiseBandWidth"){ 26 | this->m_channel[chName]->SetElectricNoiseBandWidth(value); 27 | } 28 | } 29 | 30 | void vlcChannelHelper::SetPropagationLoss(std::string channelName, std::string propagationLossType){ 31 | //NS_LOG_FUNCTION(this); 32 | if(propagationLossType=="VLCPropagationLoss"){ 33 | this->m_channel[channelName]->SetPropagationLossModel(CreateObject()); 34 | } 35 | } 36 | 37 | void vlcChannelHelper::SetPropagationDelay(std::string channelName, double value){ 38 | //NS_LOG_FUNCTION(this); 39 | this->m_channel[channelName]->SetPropagationDelay(value); 40 | 41 | } 42 | 43 | double vlcChannelHelper::GetChannelSNR(std::string chName){ 44 | ns3::Ptr rx = DynamicCast(m_channel[chName]->GetDevice(1)); 45 | this->m_channel[chName]->DoCalcPropagationLossForSignal(0); 46 | this->m_channel[chName]->CalculateNoiseVar(); 47 | double snr = this->m_channel[chName]->GetSNR(); 48 | rx->SetSNRForErrorModel(snr); 49 | return snr; 50 | } 51 | 52 | void vlcChannelHelper::SetChannelWavelength(std::string channelName, int lower, int upper){ 53 | this->m_channel[channelName]->SetWavelength(lower,upper); 54 | } 55 | 56 | void vlcChannelHelper::AttachTransmitter(std::string chName,std::string TXDevName, ns3::Ptr devHelper){ 57 | //NS_LOG_FUNCTION(this); 58 | this->m_channel[chName]->Attach(devHelper->GetTransmitter(TXDevName)); 59 | this->m_channel[chName]->SetPorpagationLossParametersFromTX(); 60 | } 61 | 62 | void vlcChannelHelper::AttachReceiver(std::string chName,std::string RXDevName, ns3::Ptr devHelper){ 63 | //NS_LOG_FUNCTION(this); 64 | this->m_channel[chName]->Attach(devHelper->GetReceiver(RXDevName)); 65 | this->m_channel[chName]->SetPorpagationLossParametersFromRX(); 66 | } 67 | 68 | ns3::Ptr vlcChannelHelper::GetChannel(std::string chName){ 69 | //NS_LOG_FUNCTION(this); 70 | return m_channel[chName]; 71 | } 72 | 73 | ns3::Ptr< vlc_NetDevice > vlcChannelHelper::GetDevice(std::string chName,uint32_t idx){ 74 | //NS_LOG_FUNCTION(this); 75 | ns3::Ptr ans = DynamicCast(m_channel[chName]->GetDevice(idx)); 76 | 77 | return ans; 78 | } 79 | 80 | NetDeviceContainer vlcChannelHelper::Install(std::string chName,Ptr a, Ptr b){ 81 | 82 | //NS_LOG_FUNCTION(this); 83 | 84 | NetDeviceContainer container; 85 | Ptr ch = this->m_channel[chName]; 86 | 87 | Ptr devTX = DynamicCast(ch->GetDevice(0) ); 88 | Ptr devRX = DynamicCast(ch->GetDevice(1) ); 89 | 90 | 91 | a->AddDevice(devTX); 92 | //Ptr < Queue > queueA = m_queueFactory.Create(); 93 | //Ptr < DropTailQueue > queueA = CreateObject(); 94 | //devTX->SetQueue(queueA); 95 | 96 | b->AddDevice(devRX); 97 | //Ptr < Queue > queueB = m_queueFactory.Create(); 98 | //devRX->SetQueue(queueB); 99 | 100 | /*bool useNormalChannel = true; 101 | ch = 0; 102 | 103 | if (MpiInterface::IsEnabled()) { 104 | uint32_t n1SystemId = a->GetSystemId(); 105 | uint32_t n2SystemId = b->GetSystemId(); 106 | uint32_t currSystemId = MpiInterface::GetSystemId(); 107 | 108 | if (n1SystemId != currSystemId || n2SystemId != currSystemId) { 109 | useNormalChannel = false; 110 | } 111 | }*/ 112 | 113 | 114 | container.Add(devTX); 115 | container.Add(devRX); 116 | 117 | return container; 118 | 119 | } 120 | 121 | vlcChannelHelper::~vlcChannelHelper() { 122 | 123 | } 124 | 125 | } /* namespace vlc */ 126 | -------------------------------------------------------------------------------- /model/vlcNetDeviceRX.h: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcNetDeviceRX.h 3 | * 4 | * Created on: Mar 25, 2016 5 | * Author: Adel Aldalbahi 6 | */ 7 | 8 | #ifndef VLCNETDEVICERX_H_ 9 | #define VLCNETDEVICERX_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "ns3/vlcNetDevice.h" 15 | #include "ns3/ptr.h" 16 | #include "ns3/VLC-error-model.h" 17 | #include "ns3/error-model.h" 18 | #include "ns3/random-variable-stream.h" 19 | #include "ns3/pointer.h" 20 | 21 | namespace vlc { 22 | 23 | 24 | class vlc_NetDeviceRX : public vlc_NetDevice{ 25 | public: 26 | //constructor for the RX device, initializes all private members to zero 27 | vlc_NetDeviceRX(); 28 | 29 | //destructor for the RX device 30 | virtual ~vlc_NetDeviceRX(); 31 | 32 | //adds a signal instant to the RX optical power signal 33 | void AddRXOpticalPowerSignal(double power); 34 | 35 | //returns the RX Optical power signal in the form of std::vector of doubles 36 | std::vector& GetRXOpticalPowerSignal(); 37 | 38 | //returns the RX power signal at instant time, time has to be lesser than the capacity of std::vector of signal 39 | double GetOpticalPowerSignalAtInstant(int time); 40 | 41 | //sets the RX power signal from a std::vector 42 | void SetRXOpticalPowerSignal(std::vector &powerSignal); 43 | 44 | //sets the size of the signal of RX 45 | void SetCapacity(int size); 46 | 47 | //sets the filter gain of the RX device 48 | double GetFilterGain(); 49 | 50 | //returns the filter gain of the RX device 51 | void SetFilterGain(double fgain); 52 | 53 | //returns the photodetector area of the RX device 54 | double GetPhotoDetectorArea(); 55 | 56 | //sets the photo detector area of the RX device 57 | void SetPhotoDectectorArea(double pArea); 58 | 59 | //returns the FOV angle of the RX device 60 | double GetFOVAngle(); 61 | 62 | //sets the FOV angle of the RX device 63 | void SetFOVAngle(double angle); 64 | 65 | //returns the refractive index of the RX device 66 | double GetRefractiveIndex(); 67 | 68 | //sets the refractive index of the RX device 69 | void SetRefractiveIndex(double angle); 70 | 71 | //returns the concentration gain of the RX device 72 | double GetConcentrationGain(); 73 | 74 | //sets the concentration gain of the RX device 75 | void SetConcentrationGain(); 76 | 77 | //returns the total gain of the RX device 78 | double GetRXGain(); 79 | //sets the total gain of the RX device using internal parameters 80 | void SetRXGain(); 81 | 82 | //sets the incidence angle of the RX device 83 | void SetIncidenceAngle(double angle); 84 | 85 | //returns the concentration gain of the RX device 86 | double GetIncidenceAngle(); 87 | 88 | ns3::VLC_ErrorModel::ModScheme GeModulationtScheme (void) const; // returns the modulation scheme used 89 | 90 | void SetScheme (std::string scheme); // sets the value of the modulation scheme used 91 | 92 | void SetRandomVariableForErrorModel (ns3::Ptr ranVar); // assigns a random variable stream to be used by this model 93 | 94 | int64_t AssignStreamsForErrorModel (int64_t stream); // assigns a fixed stream number to the random variables used by this model 95 | 96 | double GetSNRFromErrorModel (void) const; // returns the signal-to-noise ratio (SNR) 97 | 98 | void SetSNRForErrorModel (double snr); // sets the SNR value 99 | 100 | double CalculateErrorRateForErrorModel (void); // calculates the error rate value according to modulation scheme 101 | 102 | bool IsCorrupt (ns3::Ptr pkt); // determines if the packet is corrupted according to the error model 103 | 104 | // methods for PAM 105 | int GetModulationOrder (void) const; // returns the modulation order (M) 106 | void SetModulationOrder (int m_order); // sets the modulation order value 107 | 108 | // methods for VPPM 109 | double GetAlpha(void) const; // returns alpha value 110 | void SetAlpha (double a); // sets alpha value 111 | 112 | double GetBeta(void) const; // returns beta value 113 | void SetBeta (double b); // sets beta value 114 | 115 | 116 | private: 117 | std::vector m_RXOpticalPower; 118 | std::vector m_signal; 119 | double m_filterGain; 120 | double m_photodetectorArea; 121 | double m_FOVangle; 122 | double m_refIndex; 123 | double m_angleOfIncidence; 124 | double m_concentrationGain; 125 | double m_RXGain; 126 | double m_bias; 127 | ns3::Ptr m_error; 128 | 129 | }; 130 | 131 | } /* namespace vlc */ 132 | 133 | 134 | #endif /* VLCNETDEVICERX_H_ */ 135 | -------------------------------------------------------------------------------- /doc/vlcnew.rst: -------------------------------------------------------------------------------- 1 | 2 | ..highlight:: bash 3 | 4 | Visible light communication module Integration (vlcnew) 5 | ************************************************** 6 | visible light communication is the mean of using light intensity for the purpose of communication. Visible light has been around for few years where this technology allows the use of unlimited bandwidth, lower power consumption and immunity to interference when compared to the conventional RF technology. 7 | 8 | Model Description 9 | ************************ 10 | The source code for the new module lives in the directory ``src/vlcnew``. 11 | 12 | Design 13 | ====== 14 | This module can be used to investigate visible light communication at both network and physical layer using different modulation schemes such as OOK, #PAM and VPPM. The module is consists of related classes some of which are inherited from ns3's classes. The main idea of this module is simulate large-scale visible light communication system that can be very costly to implemented in real life. This simulator is built to help researchers who are interested in in studying the signal to noise ratio (SNR), bit error rate (BER) and goodput of visible light under different network topology. At this moment, we implemented two classes one transmitter and the second is receiver in addition different classes for propagation loss, error rate and many more. The transmitter gain is implemented inside the transmitter and the receiver gain is implemented inside the receiver. The channel know both tx and rx gain and is able to compute the loss as the receiver moves away using our mobility model that we inherited form ns3 to crap both devices's orientation. 15 | 16 | Scope and Limitations 17 | ===================== 18 | This module can investigate the channel condition under different modulation schemes. In addition it can help to investigate the network performance under different topology a user can create. At this stage the visible light standard did not implemented. 19 | 20 | 21 | References 22 | ========== 23 | Extending ns3 to simulate visible light communication at network-level (http://ieeexplore.ieee.org/document/7500485/) 24 | 25 | Usage 26 | ***** 27 | 28 | This section is principally concerned with the usage of your model, using 29 | the public API. Focus first on most common usage patterns, then go 30 | into more advanced topics. 31 | 32 | 33 | 34 | Helpers 35 | ======= 36 | the easiest way to vlc node to node communication is by using the following helpers: 37 | 38 | vlcChannelHelper : to create a vlc channel 39 | vlc_DeviceHelper : to set transmitter and the receiver parameters 40 | transmitter parameters: 41 | Our signal is a positive square form signal that is pushed into the transmitter power taking the time as parameter. The signal consists of the following parameters: 42 | 1- size 43 | 2- Duty ratio 44 | 3- bias 45 | 4- Max 46 | 5- Min 47 | 48 | In addition to the above parameter, the transmitter has “Transmitter gain” with the following parameters: 49 | 1- Semiangle 50 | 2-Angle of irradiance 51 | 3- Lambertian Order. 52 | 53 | Also the following parameter from the mobility model : 54 | 1-Position 55 | 2- Azimuth 56 | 3- Elevation 57 | 58 | Others Parameters: 59 | Transmitter Data rate 60 | 61 | Receiver Parameters: 62 | 1-Filter gain 63 | 2-refractive index 64 | 3-filed of view 65 | 4-concentration gain 66 | 5- Incidence Angle 67 | 5-PhotoDetectorArea 68 | 6-duty cycle ( for VPPM error model) 69 | 7-beta 70 | 8-elevation 71 | 9-position 72 | 10-Azimuth 73 | Also from the receiver we can choose the applied Modulation scheme where : 74 | 0 value represent OOK 75 | 1 value represent 4-PAM 76 | 2 value represent VPPM 77 | 78 | 79 | 80 | 81 | Attributes 82 | ========== 83 | 84 | What classes hold attributes, and what are the key ones worth mentioning? // will be gevin in details soon 85 | 86 | Output 87 | ====== 88 | 89 | What kind of data does the model generate? What are the key trace 90 | sources? What kind of logging output can be enabled? // will be gevin in details soon 91 | 92 | Examples 93 | ======== 94 | 95 | Ath this moment one example is implemented to test this module called : "VPPMtest.cc". The example is consist of 4 nodes where vlc is used to generate downlink traffic and WiFi is used as an uplink. A user can also generate traffic for different modulation scheme (mentioned in helper above). 96 | 97 | 98 | Validation 99 | ********** 100 | 101 | Describe how the model has been tested/validated. What tests run in the 102 | test suite? How much API and code is covered by the tests? Again, 103 | references to outside published work may help here. 104 | -------------------------------------------------------------------------------- /helper/vlcDeviceHelper.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcDeviceHelper.cpp 3 | * 4 | * Created on: Apr 9, 2016 5 | * Author: adel 6 | */ 7 | 8 | #include "vlcDeviceHelper.h" 9 | 10 | 11 | 12 | namespace vlc { 13 | 14 | vlc_DeviceHelper::vlc_DeviceHelper() { 15 | 16 | 17 | } 18 | 19 | void vlc_DeviceHelper::CreateTransmitter(std::string TXName){ 20 | m_TXDevices[TXName] = CreateObject(); 21 | } 22 | 23 | void vlc_DeviceHelper::CreateReceiver(std::string RXName){ 24 | m_RXDevices[RXName] = CreateObject(); 25 | } 26 | 27 | void vlc_DeviceHelper::SetTrasmitterParameter(std::string devName, std::string paramName, double value ){ 28 | 29 | if(paramName=="SemiAngle"){ 30 | m_TXDevices[devName]->SetSemiangle(value); 31 | } 32 | else if(paramName=="AngleOfRadiance"){ 33 | m_TXDevices[devName]->SetAngleOfRadiance(value); 34 | } 35 | else if(paramName=="LambertianOrder"){ 36 | m_TXDevices[devName]->SetLambertainOrder(); 37 | } 38 | else if(paramName=="Gain"){ 39 | m_TXDevices[devName]->SetTXGain(); 40 | } 41 | else if(paramName=="Bias"){ 42 | m_TXDevices[devName]->SetBias(value); 43 | } 44 | else if(paramName=="Azimuth"){ 45 | m_TXDevices[devName]->SetAzmuth(value); 46 | } 47 | else if(paramName=="Elevation"){ 48 | m_TXDevices[devName]->SetElevation(value); 49 | } 50 | else if(paramName=="DataRateInMBPS"){ 51 | std::ostringstream strs; 52 | strs << value; 53 | std::string str = strs.str(); 54 | str = str + "Mbps"; 55 | DataRate drate(str); 56 | m_TXDevices[devName]->SetDataRate(drate); 57 | } 58 | 59 | 60 | } 61 | 62 | void vlc_DeviceHelper::SetTrasmitterPosition(std::string devName, double x, double y, double z){ 63 | m_TXDevices[devName]->SetPosition(Vector(x,y,z)); 64 | } 65 | 66 | void vlc_DeviceHelper::SetReceiverPosition(std::string devName, double x, double y, double z){ 67 | m_RXDevices[devName]->SetPosition(Vector(x,y,z)); 68 | } 69 | 70 | void vlc_DeviceHelper::SetTrasmitterBoost(std::string devName){ 71 | m_TXDevices[devName]->BoostSignal(); 72 | } 73 | 74 | void vlc_DeviceHelper::SetReceiverParameter(std::string devName, std::string paramName, double value ){ 75 | if(paramName=="FilterGain"){ 76 | m_RXDevices[devName]->SetFilterGain(value); 77 | } 78 | else if(paramName=="PhotoDetectorArea"){ 79 | m_RXDevices[devName]->SetPhotoDectectorArea(value); 80 | } 81 | else if(paramName=="FOVAngle"){ 82 | m_RXDevices[devName]->SetFOVAngle(value); 83 | } 84 | else if(paramName=="RefractiveIndex"){ 85 | m_RXDevices[devName]->SetRefractiveIndex(value); 86 | } 87 | else if(paramName=="IncidenceAngle"){ 88 | m_RXDevices[devName]->SetIncidenceAngle(value); 89 | } 90 | else if(paramName=="ConcentrationGain"){ 91 | m_RXDevices[devName]->SetConcentrationGain(); 92 | } 93 | else if(paramName=="RXGain"){ 94 | m_RXDevices[devName]->SetRXGain(); 95 | } 96 | else if(paramName=="SetModulationScheme"){ 97 | if(value==0){ 98 | m_RXDevices[devName]->SetScheme( "OOK" ); 99 | } 100 | else if(value==1){ 101 | m_RXDevices[devName]->SetScheme("PAM"); 102 | } 103 | else if(value==2){ 104 | m_RXDevices[devName]->SetScheme("VPPM"); 105 | } 106 | } 107 | else if(paramName=="DutyCycle"){ 108 | m_RXDevices[devName]->SetAlpha(value); 109 | } 110 | else if(paramName=="Beta"){ 111 | m_RXDevices[devName]->SetBeta(value); 112 | } 113 | 114 | 115 | } 116 | 117 | double vlc_DeviceHelper::GetReceiverParameter(std::string devName,std::string paramName){ 118 | if(paramName=="BER"){ 119 | return this->m_RXDevices[devName]->CalculateErrorRateForErrorModel(); 120 | } 121 | else if(paramName=="SER"){ 122 | return this->m_RXDevices[devName]->CalculateErrorRateForErrorModel(); 123 | } 124 | return 0; 125 | } 126 | 127 | std::vector vlc_DeviceHelper::GenerateSignal(int size,double dutyRatio,double bias, double VMax,double VMin){ 128 | 129 | std::vector result; 130 | result.reserve(size); 131 | 132 | for(int i=0;i r = GenerateSignal(size, dutyRatio, bias, VMax, VMin) ; 149 | m_TXDevices[devName]->SetSignal(r); 150 | 151 | } 152 | 153 | ns3::Ptr vlc_DeviceHelper::GetTransmitter(std::string devName){ 154 | 155 | return this->m_TXDevices[devName]; 156 | 157 | } 158 | ns3::Ptr vlc_DeviceHelper::GetReceiver(std::string devName){ 159 | 160 | return this->m_RXDevices[devName]; 161 | } 162 | 163 | 164 | 165 | vlc_DeviceHelper::~vlc_DeviceHelper() { 166 | this->m_RXDevices.clear(); 167 | this->m_TXDevices.clear(); 168 | } 169 | 170 | } /* namespace vlc */ 171 | -------------------------------------------------------------------------------- /model/vlcchannel.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcchannel.cpp 3 | * 4 | * Created on: Mar 23, 2016 5 | * Author: Adel Aldalbahi 6 | */ 7 | 8 | #include "ns3/vlcchannel.h" 9 | #include "ns3/log.h" 10 | 11 | namespace vlc { 12 | 13 | vlc_channel::vlc_channel():m_distanceBWTXandRX(0) { 14 | //NS_LOG_FUNCTION(this); 15 | this->m_loss = CreateObject< vlc::VLCPropagationLossModel > (); 16 | m_AvgPower = 0; 17 | this->m_SNR = CreateObject (); 18 | } 19 | 20 | void vlc_channel::SetPropagationLossModel(ns3::Ptr loss){ 21 | //NS_LOG_FUNCTION(this<m_loss = loss; 23 | } 24 | 25 | ns3::Ptr vlc_channel::GetPropagationLossModel(){ 26 | //NS_LOG_FUNCTION(this); 27 | return this->m_loss; 28 | } 29 | 30 | void vlc_channel::SetPropagationDelayModel(ns3::Ptr delay){ 31 | //NS_LOG_FUNCTION(this<m_delay = delay; 33 | } 34 | ns3::Ptr vlc_channel::GetPropagationDelayModel(){ 35 | //NS_LOG_FUNCTION(this); 36 | return this->m_delay; 37 | } 38 | 39 | double vlc_channel::GetDistance(){ 40 | //NS_LOG_FUNCTION(this); 41 | return this->m_distanceBWTXandRX; 42 | } 43 | 44 | void vlc_channel::SetDistance(){ 45 | //NS_LOG_FUNCTION(this); 46 | ns3::Ptr first = ns3::DynamicCast< vlc_NetDevice >( this->GetDevice(0)); 47 | ns3::Ptr second = ns3::DynamicCast< vlc_NetDevice >( this->GetDevice(1)); 48 | 49 | ns3::Ptr l = ns3::DynamicCast< VLCPropagationLossModel >(this->m_loss); 50 | this->m_distanceBWTXandRX = l->GetDistance(first->GetMobilityModel(),second->GetMobilityModel()); 51 | } 52 | 53 | void vlc_channel::DoCalcPropagationLoss(){ 54 | //NS_LOG_FUNCTION(this); 55 | ns3::Ptr first = ns3::DynamicCast ( this->GetDevice(0) ); 56 | ns3::Ptr second = ns3::DynamicCast( this->GetDevice(1) ); 57 | double loss = 0; 58 | 59 | for(unsigned int i=0; iGetTXOpticalPowerSignal().size();i++){ 60 | loss = m_loss->CalcRxPower(first->GetTXOpticalPowerSignal().at(i) , first->GetMobilityModel(), second->GetMobilityModel()); 61 | second->GetRXOpticalPowerSignal().at(i) = loss ; 62 | } 63 | 64 | } 65 | 66 | void vlc_channel::SetPropagationDelay(double delay){ 67 | //NS_LOG_FUNCTION(this<m_delay->set 69 | } 70 | 71 | double vlc_channel::DoCalcPropagationLossForSignal(int timeInstant){ 72 | //NS_LOG_FUNCTION(this); 73 | ns3::Ptr first = ns3::DynamicCast ( this->GetDevice(0)); 74 | ns3::Ptr second = ns3::DynamicCast( this->GetDevice(1)); 75 | double loss = m_loss->CalcRxPower(first->GetTXOpticalPowerSignal().at(timeInstant), first->GetMobilityModel(), second->GetMobilityModel() ); 76 | m_SNR->SetReceivedPower(loss); 77 | 78 | return loss; 79 | } 80 | 81 | void vlc_channel::SetPorpagationLossParametersFromTX(){ 82 | //NS_LOG_FUNCTION(this); 83 | ns3::Ptr tx = ns3::DynamicCast< vlc_NetDeviceTX >( this->GetDevice(0)); 84 | ns3::Ptr loss = ns3::DynamicCast< vlc::VLCPropagationLossModel >( this->m_loss); 85 | loss->SetTxPowerMAX(tx->GetTXPowerMax()); 86 | loss->SetTXGain(tx->GetTXGain()); 87 | } 88 | 89 | void vlc_channel::SetPorpagationLossParametersFromRX(){ 90 | //NS_LOG_FUNCTION(this); 91 | ns3::Ptr rx = ns3::DynamicCast< vlc_NetDeviceRX >( this->GetDevice(1)); 92 | ns3::Ptr loss = ns3::DynamicCast< vlc::VLCPropagationLossModel >( this->m_loss); 93 | loss->SetFilterGain(rx->GetFilterGain()); 94 | loss->SetConcentratorGain(rx->GetConcentrationGain()); 95 | loss->SetRXGain(rx->GetRXGain()); 96 | 97 | } 98 | 99 | void vlc_channel::SetWavelength (int lower, int upper){ // sets upper and lower bound wavelength [nm] 100 | //NS_LOG_FUNCTION(this); 101 | this->m_SNR->SetWavelength(lower,upper); 102 | } 103 | void vlc_channel::SetTemperature (double t){ // sets the blackbody temperature of LED 104 | //NS_LOG_FUNCTION(this<m_SNR->SetTemperature(t); 106 | } 107 | 108 | double vlc_channel::GetTemperature(){ 109 | return this->m_SNR->GetTemperature(); 110 | } 111 | void vlc_channel::SetReceivedPower (double p){ // sets the average received optical signal power 112 | //NS_LOG_FUNCTION(this<m_SNR->SetReceivedPower(p); 114 | } 115 | void vlc_channel::CalculateNoiseVar (){ //calculates the noise variance 116 | //NS_LOG_FUNCTION(this< rx = DynamicCast(this->GetDevice(1)); 118 | this->m_SNR->CalculateNoiseVar(rx->GetPhotoDetectorArea() ); 119 | 120 | } 121 | void vlc_channel::CalculateSNR (){ // caluclates the SNR value 122 | //NS_LOG_FUNCTION(this); 123 | this->m_SNR->CalculateSNR(); 124 | } 125 | 126 | double vlc_channel::GetSNR () const{ // returns the signal-to-noise ratio (SNR) 127 | //NS_LOG_FUNCTION(this); 128 | ns3::Ptr rx = DynamicCast(this->GetDevice(1)); 129 | this->m_SNR->CalculateNoiseVar(rx->GetPhotoDetectorArea()); 130 | m_SNR->CalculateSNR(); 131 | return this->m_SNR->GetSNR(); 132 | } 133 | 134 | 135 | void vlc_channel::SetAveragePower(double power){ 136 | //NS_LOG_FUNCTION(this<m_SNR->SetElectricNoiseBandWidth(b); 147 | } 148 | 149 | double vlc_channel::GetNoiseBandwidth(){ //return the noise bandwidth 150 | return m_SNR->GetNoiseBandwidth(); 151 | } 152 | 153 | vlc_channel::~vlc_channel() { 154 | 155 | } 156 | 157 | 158 | } /* namespace vlc */ 159 | -------------------------------------------------------------------------------- /model/vlcNetDeviceRX.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * vlcNetDeviceRX.cpp 3 | * 4 | * Created on: Mar 25, 2016 5 | * Author: Adel Aldalbahi 6 | */ 7 | 8 | #include "ns3/vlcNetDeviceRX.h" 9 | 10 | namespace vlc { 11 | 12 | vlc_NetDeviceRX::vlc_NetDeviceRX() { 13 | 14 | //NS_LOG_FUNCTION(this); 15 | 16 | m_filterGain = 0; 17 | m_photodetectorArea = 0; 18 | m_FOVangle = 0; 19 | m_refIndex = 0; 20 | m_angleOfIncidence = 0; 21 | m_concentrationGain = 0; 22 | m_RXGain = 0; 23 | m_bias = 0; 24 | this->m_error = ns3::CreateObject(); 25 | 26 | 27 | } 28 | 29 | 30 | //use this function after setting up FOV and refractive index 31 | void vlc_NetDeviceRX::SetConcentrationGain(){ 32 | //NS_LOG_FUNCTION(this); 33 | this->m_concentrationGain = std::pow(this->m_refIndex,2)/std::pow((float)std::sin((float)m_FOVangle),2); 34 | } 35 | 36 | void vlc_NetDeviceRX::AddRXOpticalPowerSignal(double power){ 37 | //NS_LOG_FUNCTION(this<m_RXOpticalPower.push_back(power); 39 | } 40 | std::vector& vlc_NetDeviceRX::GetRXOpticalPowerSignal(){ 41 | //NS_LOG_FUNCTION(this); 42 | return this->m_RXOpticalPower; 43 | } 44 | double vlc_NetDeviceRX::GetOpticalPowerSignalAtInstant(int time){ 45 | //NS_LOG_FUNCTION(this<m_RXOpticalPower.at(time); 47 | } 48 | void vlc_NetDeviceRX::SetRXOpticalPowerSignal(std::vector &powerSignal){ 49 | //NS_LOG_FUNCTION(this<m_RXOpticalPower = powerSignal; 51 | } 52 | 53 | 54 | 55 | void vlc_NetDeviceRX::SetCapacity(int size){ 56 | //NS_LOG_FUNCTION(this<m_signal.reserve(size); 58 | this->m_RXOpticalPower.reserve(size); 59 | } 60 | 61 | double vlc_NetDeviceRX::GetFilterGain(){ 62 | //NS_LOG_FUNCTION(this); 63 | return this->m_filterGain; 64 | } 65 | void vlc_NetDeviceRX::SetFilterGain(double fgain){ 66 | //NS_LOG_FUNCTION(this<m_filterGain = fgain; 68 | } 69 | 70 | double vlc_NetDeviceRX::GetPhotoDetectorArea(){ 71 | //NS_LOG_FUNCTION(this); 72 | return this->m_photodetectorArea; 73 | } 74 | 75 | void vlc_NetDeviceRX::SetPhotoDectectorArea(double pArea){ 76 | //NS_LOG_FUNCTION(this<m_photodetectorArea = pArea; 78 | } 79 | 80 | double vlc_NetDeviceRX::GetFOVAngle(){ 81 | //NS_LOG_FUNCTION(this); 82 | return this->m_FOVangle; 83 | } 84 | 85 | void vlc_NetDeviceRX::SetFOVAngle(double angle){ 86 | //NS_LOG_FUNCTION(this<m_FOVangle = angle*M_PI/180; 88 | } 89 | 90 | double vlc_NetDeviceRX::GetRefractiveIndex(){ 91 | //NS_LOG_FUNCTION(this); 92 | return this->m_refIndex; 93 | } 94 | void vlc_NetDeviceRX::SetRefractiveIndex(double angle){ 95 | //NS_LOG_FUNCTION(this << angle); 96 | this->m_refIndex = angle; 97 | } 98 | 99 | 100 | double vlc_NetDeviceRX::GetConcentrationGain(){ 101 | //NS_LOG_FUNCTION(this); 102 | return this->m_concentrationGain; 103 | } 104 | 105 | 106 | double vlc_NetDeviceRX::GetRXGain(){ 107 | //NS_LOG_FUNCTION(this); 108 | return this->m_RXGain; 109 | } 110 | void vlc_NetDeviceRX::SetRXGain(){ 111 | //NS_LOG_FUNCTION(this); 112 | this->m_RXGain = std::cos(this->m_angleOfIncidence); 113 | } 114 | 115 | 116 | void vlc_NetDeviceRX::SetIncidenceAngle(double angle){ 117 | //NS_LOG_FUNCTION(this << angle); 118 | this->m_angleOfIncidence = angle*M_PI/180; 119 | } 120 | 121 | ns3::VLC_ErrorModel::ModScheme vlc_NetDeviceRX::GeModulationtScheme (void) const{ // returns the modulation scheme used 122 | //NS_LOG_FUNCTION(this); 123 | return this->m_error->GetScheme(); 124 | } 125 | 126 | void vlc_NetDeviceRX::SetScheme (std::string scheme){ // sets the value of the modulation scheme used 127 | //NS_LOG_FUNCTION(this<m_error->SetScheme(scheme); 129 | 130 | } 131 | 132 | void vlc_NetDeviceRX::SetRandomVariableForErrorModel(ns3::Ptr ranVar){ // assigns a random variable stream to be used by this model 133 | //NS_LOG_FUNCTION(this<m_error->SetRandomVariable(ranVar); 135 | } 136 | 137 | int64_t vlc_NetDeviceRX::AssignStreamsForErrorModel (int64_t stream){ // assigns a fixed stream number to the random variables used by this model 138 | //NS_LOG_FUNCTION(this); 139 | return this->m_error->AssignStreams(stream); 140 | } 141 | 142 | double vlc_NetDeviceRX::GetSNRFromErrorModel (void) const{ // returns the signal-to-noise ratio (SNR) 143 | //NS_LOG_FUNCTION(this); 144 | return this->m_error->GetSNR(); 145 | } 146 | 147 | void vlc_NetDeviceRX::SetSNRForErrorModel (double snr){ // sets the SNR value 148 | //NS_LOG_FUNCTION(this<m_error->SetSNR(snr); 150 | } 151 | 152 | double vlc_NetDeviceRX::CalculateErrorRateForErrorModel (){ // calculates the error rate value according to modulation scheme 153 | //NS_LOG_FUNCTION(this); 154 | return this->m_error->CalculateErrorRate(); 155 | } 156 | 157 | bool vlc_NetDeviceRX::IsCorrupt (ns3::Ptr pkt){ // determines if the packet is corrupted according to the error model 158 | //NS_LOG_FUNCTION(this<m_error->IsCorrupt(pkt); 160 | } 161 | 162 | // methods for PAM 163 | int vlc_NetDeviceRX::GetModulationOrder (void) const{ // returns the modulation order (M) 164 | //NS_LOG_FUNCTION(this); 165 | return this->m_error->GetModulationOrder(); 166 | } 167 | 168 | void vlc_NetDeviceRX::SetModulationOrder (int m_order){ // sets the modulation order value 169 | //NS_LOG_FUNCTION(this<m_error->SetModulationOrder(m_order); 171 | } 172 | 173 | // methods for VPPM 174 | double vlc_NetDeviceRX::GetAlpha(void) const{ // returns alpha value 175 | //NS_LOG_FUNCTION(this); 176 | return this->m_error->GetAlpha(); 177 | } 178 | void vlc_NetDeviceRX::SetAlpha (double a){ // sets alpha value 179 | //NS_LOG_FUNCTION(this); 180 | this->m_error->SetAlpha(a); 181 | } 182 | 183 | double vlc_NetDeviceRX::GetBeta(void) const{ // returns beta value 184 | //NS_LOG_FUNCTION(this); 185 | return this->m_error->GetBeta(); 186 | } 187 | void vlc_NetDeviceRX::SetBeta (double b){ // sets beta value 188 | //NS_LOG_FUNCTION(this<m_error->SetBeta(b); 190 | } 191 | 192 | 193 | double vlc_NetDeviceRX::GetIncidenceAngle(){ 194 | return this->m_angleOfIncidence; 195 | } 196 | 197 | 198 | vlc_NetDeviceRX::~vlc_NetDeviceRX() { 199 | // TODO Auto-generated destructor stub 200 | } 201 | 202 | } /* namespace vlc */ 203 | -------------------------------------------------------------------------------- /model/VLC_SNR.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "VLC_SNR.h" 4 | #include "ns3/double.h" 5 | #include "ns3/integer.h" 6 | #include "ns3/log.h" 7 | 8 | 9 | namespace ns3 { 10 | 11 | NS_LOG_COMPONENT_DEFINE ("VLC_SNR"); // define a log component with the name "VLC_SNR" 12 | 13 | NS_OBJECT_ENSURE_REGISTERED (VLC_SNR); // register VLC_SNR class with the TypeId system 14 | 15 | TypeId VLC_SNR::GetTypeId (void) // returns meta-information about VLC_SNR class 16 | { // including parent class, group name, constructor, and attributes 17 | static TypeId tid = TypeId ("ns3::VLC_SNR") 18 | .SetParent () 19 | .SetGroupName("Network") 20 | .AddConstructor () 21 | .AddAttribute ("PowerReceived", "average received optical signal power", 22 | DoubleValue (0), 23 | MakeDoubleAccessor (&VLC_SNR::Pr), 24 | MakeDoubleChecker ()) 25 | .AddAttribute ("SNR", "signal-to-noise-ratio", 26 | DoubleValue (0), 27 | MakeDoubleAccessor (&VLC_SNR::SNR), 28 | MakeDoubleChecker ()) 29 | .AddAttribute ("LowerWavelength", "lower bound WaveLength", 30 | IntegerValue (0), 31 | MakeIntegerAccessor (&VLC_SNR::wavelength_lower), 32 | MakeIntegerChecker ()) 33 | .AddAttribute ("UpperWavelength", "upper bound WaveLength", 34 | IntegerValue (0), 35 | MakeIntegerAccessor (&VLC_SNR::wavelength_upper), 36 | MakeIntegerChecker ()) 37 | .AddAttribute ("Temperature", "Blackbody temp of LED", 38 | DoubleValue (0), 39 | MakeDoubleAccessor (&VLC_SNR::temp), 40 | MakeDoubleChecker ()) 41 | ; 42 | return tid; 43 | } 44 | 45 | //Values of the Standard Luminocity Functions 46 | double VLC_SNR::V_lambda[] = { 47 | 0.000039, 0.000120, 0.000396, 0.001210, 0.004000, 0.011600, 0.023000, 48 | 0.038000, 0.060000, 0.090980, 0.139020, 0.208020, 0.323000, 0.503000, 49 | 0.710000, 0.862000, 0.954000, 0.994950, 0.995000, 0.952000, 0.870000, 50 | 0.757000, 0.631000, 0.503000, 0.381000, 0.265000, 0.175000, 0.107000, 51 | 0.061000, 0.032000, 0.017000, 0.008210, 0.004102, 0.002091, 0.001047, 52 | 0.000520, 0.000249, 0.000120, 0.000060, 0.000030 }; 53 | 54 | //General values for Respositvity 55 | double VLC_SNR::Response[] = { 56 | 0.150, 0.160, 0.170, 0.190, 0.200, 0.220, 0.230, 0.240, 0.250, 0.260, 57 | 0.270, 0.280, 0.300, 0.320, 0.330, 0.350, 0.360, 0.370, 0.375, 0.380, 58 | 0.390, 0.400, 0.415, 0.420, 0.430, 0.440, 0.450, 0.460, 0.470, 0.475, 59 | 0.480, 0.485, 0.490, 0.495, 0.500, 0.505, 0.510, 0.520, 0.526, 0.532 }; 60 | 61 | // constructor 62 | VLC_SNR::VLC_SNR () 63 | { 64 | NS_LOG_FUNCTION (this); 65 | noise_var = 0; // total noise variance 66 | Pr = 0; // average received optical signal power 67 | res = 0; // responsitivity of receiver 68 | SNR = 0; // signal-to-noise ratio 69 | B = 0; 70 | wavelength_lower = 0; // lower bound WaveLength [nm] 71 | wavelength_upper = 0; // upper bound Wavelength [nm] 72 | temp = 0; // Blackbody temp of LED 73 | } 74 | 75 | // destructor 76 | VLC_SNR::~VLC_SNR () 77 | { 78 | NS_LOG_FUNCTION (this); 79 | } 80 | 81 | // sets upper and lower bound wavelength 82 | void VLC_SNR::SetWavelength (int lower, int upper) 83 | { 84 | NS_LOG_FUNCTION (this << lower << upper); 85 | wavelength_lower = lower; 86 | wavelength_upper = upper; 87 | } 88 | 89 | // sets the blackbody temperature of LED 90 | void VLC_SNR::SetTemperature (double t) 91 | { 92 | NS_LOG_FUNCTION (this << t); 93 | temp = t; 94 | } 95 | 96 | double VLC_SNR::GetTemperature(){ 97 | NS_LOG_FUNCTION (this ); 98 | return this->temp; 99 | } 100 | 101 | // sets the average received optical signal power 102 | void VLC_SNR::SetReceivedPower (double p) 103 | { 104 | NS_LOG_FUNCTION (this << p); 105 | Pr = p; 106 | } 107 | 108 | // CalculateNoiseVar method calculates the noise variance using the following parameters: 109 | // Ib: background current [A] 110 | // I2: noise-bandwidth factor 111 | // I3: 112 | // A: photodetector Area [m^2] 113 | // B: noise bandwidth 114 | // Tk: absolute temperature [K] 115 | // Cpd: fixed capacitance of photodetector per unit area [F/cm^2] 116 | // Gol: open-loop voltage gain 117 | // gamma: FET channel noise factor 118 | // gm: FET transconductance [s] 119 | void VLC_SNR::CalculateNoiseVar ( double A) 120 | { 121 | NS_LOG_FUNCTION (this); 122 | 123 | //res = IntegralRes() / IntegralPlanck(); 124 | res = 0.003; 125 | 126 | static const double q = 1.602176487e-19; //electronic charge [Coulombs] 127 | static const double k = 1.38064852e-23; //Boltzmann constant [m^2 kg s^-2 K^-1] 128 | static const double I2 = 0.5620; //noise bandwidth factor 129 | double I3 = 0.0868; //noise bandwidth factor 130 | double Ib = 5100e-6; //photocurrent due to background radiation [microA] 131 | double Gol = 10; //open-loop voltage gain 132 | double Cpd = 112e-12; //fixed capacitance of photodetector per unit area [pF/cm^2] 133 | double gm = 30e-3; //FET transconductance [mS] 134 | double gamma = 1.5; //FET channel noise factor 135 | 136 | double shot_var, thermal_var; 137 | 138 | // shot noise variance 139 | shot_var = (2 * q * res * Pr * B) + (2 * q * Ib * I2 * B); 140 | 141 | // thermal noise variance 142 | thermal_var = (8 * M_PI * k * temp * Cpd * A * I2 * (std::pow(B, 2)) / Gol) 143 | + (16 * (std::pow(M_PI, 2)) * k * temp * gamma * (std::pow(Cpd, 2)) * (std::pow(A, 2)) * I3 * (std::pow(B, 3)) / gm); 144 | 145 | noise_var = shot_var + thermal_var; 146 | } 147 | 148 | // caluclates the SNR value using received power, responsivity and noise variance 149 | void VLC_SNR::CalculateSNR () 150 | { 151 | NS_LOG_FUNCTION (this); 152 | if (noise_var != 0) 153 | SNR = std::pow((Pr * res), 2) / noise_var; 154 | } 155 | 156 | // returns the signal-to-noise ratio (SNR) 157 | double VLC_SNR::GetSNR () 158 | { 159 | NS_LOG_FUNCTION (this); 160 | CalculateSNR(); 161 | return SNR; 162 | } 163 | 164 | // Definite integral of the Spectral Radiance(wavelength, temperature) d(wavelength) 165 | double VLC_SNR::IntegralPlanck() 166 | { 167 | NS_LOG_FUNCTION (this); 168 | double integral = 0; 169 | 170 | while(wavelength_lower <= wavelength_upper) 171 | { 172 | integral += SpectralRadiance(wavelength_lower, temp) * 10e-9; 173 | wavelength_lower += 10; 174 | } 175 | return integral; 176 | } 177 | 178 | // Definite integral of the Response(wavelength)*Spectral Radiance(wavelength, temperature) d(wavelength) 179 | double VLC_SNR::IntegralRes() 180 | { 181 | NS_LOG_FUNCTION (this); 182 | double integral = 0; 183 | while(wavelength_lower <= wavelength_upper) 184 | { 185 | integral += Response[(wavelength_lower - 380) / 10] * SpectralRadiance(wavelength_lower, temp) * 10e-9; 186 | wavelength_lower += 10; 187 | } 188 | return integral; 189 | } 190 | 191 | void VLC_SNR::SetElectricNoiseBandWidth (double b){ // sets the noise bandwidth 192 | NS_LOG_FUNCTION (this); 193 | B = b; 194 | } 195 | 196 | double VLC_SNR::GetNoiseBandwidth(){ //return the noise bandwidth 197 | NS_LOG_FUNCTION (this); 198 | return B; 199 | } 200 | 201 | // Calculates Spectral Radiance based on wavelength and Blackbody temp of LED 202 | double VLC_SNR::SpectralRadiance(int wavelength, double temperature) 203 | { 204 | NS_LOG_FUNCTION (this); 205 | double spectral_rad; 206 | double h = 6.62607004; //Planck's constant 207 | double c = 299792458; //speed of light 208 | double k = 1.3806488e-23; //Boltzmann constant 209 | double waveLength = wavelength * 1e-9; //nm 210 | spectral_rad = 15 * (std::pow((h * c) / ( M_PI * k * temperature), 4)) 211 | / ((std::pow(waveLength, 5)) * ((std::exp((h * c) / (waveLength * k * temperature))) - 1)); 212 | return spectral_rad; 213 | } 214 | 215 | } // namespace ns3 216 | -------------------------------------------------------------------------------- /model/VLC-error-model.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "VLC-error-model.h" 3 | #include "ns3/packet.h" 4 | #include "ns3/assert.h" 5 | #include "ns3/log.h" 6 | #include "ns3/boolean.h" 7 | #include "ns3/enum.h" 8 | #include "ns3/integer.h" 9 | #include "ns3/double.h" 10 | #include "ns3/string.h" 11 | #include "ns3/pointer.h" 12 | 13 | namespace ns3 { 14 | 15 | NS_LOG_COMPONENT_DEFINE ("VLC_ErrorModel"); // define a log component with the name "VLC_ErrorModel" 16 | 17 | NS_OBJECT_ENSURE_REGISTERED (VLC_ErrorModel); // register VLC_ErrorModel class with the TypeId system 18 | 19 | TypeId VLC_ErrorModel::GetTypeId (void) // returns meta-information about VLC_ErrorModel class 20 | { // including parent class, group name, constructor, and attributes 21 | static TypeId tid = TypeId ("ns3::VLC_ErrorModel") 22 | .SetParent () 23 | .SetGroupName("Network") 24 | .AddConstructor () 25 | .AddAttribute ("ModulationOrder", "The modulation order (M)", 26 | IntegerValue (0), 27 | MakeIntegerAccessor (&VLC_ErrorModel::mod_order), 28 | MakeIntegerChecker ()) 29 | .AddAttribute ("Alpha", "The duty cycle of the VPPM signal", 30 | DoubleValue (0.0), 31 | MakeDoubleAccessor (&VLC_ErrorModel::alpha), 32 | MakeDoubleChecker ()) 33 | .AddAttribute ("Beta", "A factor relating noise bandwidth to signal bandwidth", 34 | DoubleValue (0.0), 35 | MakeDoubleAccessor (&VLC_ErrorModel::beta), 36 | MakeDoubleChecker ()) 37 | .AddAttribute ("SNR", "Signal-to-Noise Ratio", 38 | DoubleValue (0.0), 39 | MakeDoubleAccessor (&VLC_ErrorModel::SNR), 40 | MakeDoubleChecker ()) 41 | .AddAttribute ("RanVar1", "The decision variable attached to this error model.", 42 | StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"), 43 | MakePointerAccessor (&VLC_ErrorModel::m_ranvar), 44 | MakePointerChecker ()) 45 | .AddAttribute ("ModulationScheme", "The modulation scheme used in this model", 46 | EnumValue (PAM), 47 | MakeEnumAccessor (&VLC_ErrorModel::mod_scheme), 48 | MakeEnumChecker (PAM, "PAM", 49 | OOK, "OOK", 50 | VPPM, "VPPM")) 51 | ; 52 | return tid; 53 | } 54 | 55 | // constructor 56 | VLC_ErrorModel::VLC_ErrorModel () 57 | { 58 | 59 | NS_LOG_FUNCTION (this); 60 | 61 | alpha = 0; 62 | beta = 1; 63 | SNR = 0; 64 | mod_order = 0; 65 | mod_scheme = OOK; 66 | 67 | } 68 | 69 | // destructor 70 | VLC_ErrorModel::~VLC_ErrorModel () 71 | { 72 | NS_LOG_FUNCTION (this); 73 | } 74 | 75 | VLC_ErrorModel::ModScheme 76 | VLC_ErrorModel::GetScheme (void) const // returns the modulation scheme used 77 | { 78 | NS_LOG_FUNCTION (this); 79 | return mod_scheme; 80 | } 81 | 82 | void 83 | VLC_ErrorModel::SetScheme (ModScheme scheme) // sets the value of the modulation scheme used 84 | { 85 | NS_LOG_FUNCTION (this << scheme); 86 | mod_scheme = scheme; 87 | if (scheme == OOK) 88 | mod_order = 2; 89 | } 90 | 91 | 92 | void VLC_ErrorModel::SetScheme (std::string scheme){ // sets the value of the modulation scheme used 93 | NS_LOG_FUNCTION (this << scheme); 94 | if(scheme=="PAM"){ 95 | SetScheme(VLC_ErrorModel::PAM); 96 | } 97 | else if(scheme=="OOK"){ 98 | SetScheme(VLC_ErrorModel::OOK); 99 | } 100 | else if(scheme=="VPPM"){ 101 | SetScheme(VLC_ErrorModel::VPPM); 102 | } 103 | 104 | } 105 | // SetRandomVariable method assigns a random variable stream to be used by this model 106 | void 107 | VLC_ErrorModel::SetRandomVariable (Ptr ranvar) 108 | { 109 | NS_LOG_FUNCTION (this << ranvar); 110 | m_ranvar = ranvar; 111 | } 112 | 113 | //AssignStreams method assigns a fixed stream number to the random variables used by this model 114 | int64_t 115 | VLC_ErrorModel::AssignStreams (int64_t stream) 116 | { 117 | NS_LOG_FUNCTION (this << stream); 118 | m_ranvar->SetStream (stream); 119 | return 1; 120 | } 121 | 122 | // GetModulationOrder method returns the modulation order (M) 123 | int 124 | VLC_ErrorModel::GetModulationOrder (void) const 125 | { 126 | NS_LOG_FUNCTION (this); 127 | return mod_order; 128 | } 129 | 130 | // SetModulationOrder method sets the modulation order value 131 | void 132 | VLC_ErrorModel::SetModulationOrder (int m_order) 133 | { 134 | NS_LOG_FUNCTION (this << m_order); 135 | mod_order = m_order; 136 | } 137 | 138 | // GetAlpha method returns alpha value 139 | double 140 | VLC_ErrorModel::GetAlpha (void) const 141 | { 142 | NS_LOG_FUNCTION (this); 143 | return alpha; 144 | } 145 | 146 | // SetAlpha method sets alpha value 147 | void 148 | VLC_ErrorModel::SetAlpha (double a) 149 | { 150 | NS_LOG_FUNCTION (this << a); 151 | alpha = a; 152 | } 153 | 154 | // GetBeta method returns beta value 155 | double 156 | VLC_ErrorModel::GetBeta (void) const 157 | { 158 | NS_LOG_FUNCTION (this); 159 | return beta; 160 | } 161 | 162 | // SetBeta method sets beta value 163 | void 164 | VLC_ErrorModel::SetBeta (double b) 165 | { 166 | NS_LOG_FUNCTION (this << b); 167 | beta = b; 168 | } 169 | 170 | // GetSNR method returns the signal-to-noise ratio (SNR) value 171 | double 172 | VLC_ErrorModel::GetSNR (void) const 173 | { 174 | NS_LOG_FUNCTION (this); 175 | return SNR; 176 | } 177 | 178 | // SetSNR method sets the SNR value 179 | void 180 | VLC_ErrorModel::SetSNR (double snr) 181 | { 182 | NS_LOG_FUNCTION (this << snr); 183 | SNR = snr; 184 | } 185 | 186 | // CalculateErrorRate calculates SER or BER value according to modulation scheme 187 | double 188 | VLC_ErrorModel::CalculateErrorRate (void) 189 | { 190 | NS_LOG_FUNCTION (this); 191 | if (mod_scheme == VPPM) 192 | return CalculateBER(); 193 | else if (mod_scheme == PAM || mod_scheme == OOK) 194 | return CalculateSER(); 195 | return 0; 196 | } 197 | 198 | // CalculateSER method calculates the SER value of OOK and PAM models 199 | // using modulation order(M) and SNR 200 | double VLC_ErrorModel::CalculateSER (void) 201 | { 202 | NS_LOG_FUNCTION (this); 203 | // Calculate Q(sqrt(SNR) / (M-1)) 204 | // Q-function is the tail probability of the standard normal distribution 205 | double Q = 0.5 * erfc( (std::sqrt(SNR) / (mod_order-1) ) / std::sqrt(2)); 206 | double SER = (2 * (mod_order-1) / mod_order) * Q; 207 | SetRate(SER); 208 | if (mod_scheme == OOK) 209 | SetUnit(ERROR_UNIT_BIT); 210 | return SER; 211 | } 212 | 213 | // CalculateBER method calculates the BER of VPPM model using alpha, beta and SNR 214 | double VLC_ErrorModel::CalculateBER (void) 215 | { 216 | NS_LOG_FUNCTION (this); 217 | double x; // the vaue to calculate Q(x) 218 | if (alpha <= 0.5) 219 | x = std::sqrt(SNR / (2 * beta * alpha)); 220 | else 221 | x = std::sqrt(SNR * (1 - alpha) / (2 * beta * std::pow(alpha, 2))); 222 | // Calculate BER = Q(x) 223 | // Q-function is the tail probability of the standard normal distribution 224 | double Q = 0.5 * erfc(x / std::sqrt(2)); 225 | SetRate(Q); // call SetRate method in parent class RateErrorModel to set m_rate to BER value 226 | SetUnit(ERROR_UNIT_BIT); 227 | return Q; 228 | } 229 | 230 | // DoCorrupt method determines if the packet is corrupted according to the error model used 231 | bool VLC_ErrorModel::IsCorrupt (Ptr p) 232 | { 233 | NS_LOG_FUNCTION (this << p); 234 | 235 | if (mod_scheme == PAM || mod_scheme == OOK) 236 | { 237 | // check if the model is enabled 238 | if (!IsEnabled ()) 239 | { 240 | return false; 241 | } 242 | 243 | // computes pkt error rate from symbol error rate 244 | double symbol_size = log2(mod_order); // symbol size in bits 245 | double symbols_per_pkt = static_cast(8 * p->GetSize ()) / symbol_size; // no. of symbols per packet 246 | // Compute pkt error rate by finding the complement of the probablility 247 | // that a packets is not corrupted 248 | // = (1 - the probability that all symbols in pkt are not corrupted) 249 | double per = 1 - std::pow (1.0 - GetRate(), symbols_per_pkt); 250 | // the pkt is corrupted according to PER 251 | // using random variable m_ranvar 252 | return (m_ranvar->GetValue () < per); 253 | } 254 | 255 | // for VPPM scheme, call the method defined in parent class RateErrorModel 256 | else 257 | { 258 | RateErrorModel::SetRandomVariable(m_ranvar); 259 | return RateErrorModel::IsCorrupt(p); 260 | } 261 | } 262 | 263 | 264 | // DoReset method does nothing 265 | void VLC_ErrorModel::DoReset (void) 266 | { 267 | NS_LOG_FUNCTION (this); 268 | /* re-initialize any state; no-op for now */ 269 | } 270 | 271 | } // namespace ns3 272 | -------------------------------------------------------------------------------- /VPPMtest.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * MyFirst.cc 3 | * 4 | * Created on: Mar 27, 2016 5 | * Author: adel 6 | */ 7 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 8 | /* 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License version 2 as 11 | * published by the Free Software Foundation; 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | */ 22 | 23 | #include "ns3/core-module.h" 24 | #include "ns3/network-module.h" 25 | #include "ns3/internet-module.h" 26 | #include "ns3/point-to-point-module.h" 27 | #include "ns3/applications-module.h" 28 | #include "ns3/vlcnew-module.h" 29 | #include "ns3/vlcnew.h" 30 | #include "ns3/pointer.h" 31 | #include "ns3/ptr.h" 32 | #include "ns3/object.h" 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include "ns3/vlcChannelHelper.h" 41 | #include "ns3/vlcDeviceHelper.h" 42 | #include "ns3/network-module.h" 43 | #include "ns3/internet-module.h" 44 | #include "ns3/ipv4-static-routing-helper.h" 45 | #include "ns3/ipv4-list-routing-helper.h" 46 | #include "ns3/netanim-module.h" 47 | #include 48 | #include "ns3/applications-module.h" 49 | 50 | #include "ns3/packet-sink.h" 51 | #include "ns3/gnuplot.h" 52 | #include "ns3/mobility-module.h" 53 | #include "ns3/wifi-module.h" 54 | #include "ns3/drop-tail-queue.h" 55 | 56 | 57 | using namespace ns3; 58 | using namespace std; 59 | using namespace vlc; 60 | 61 | std::vector& GenerateSignal(int size,double dutyRatio); 62 | void StartFlow(Ptr, Ipv4Address, uint16_t); //send data 63 | void WriteUntilBufferFull(Ptr, uint32_t); 64 | void SendStuff(Ptr sock, Ipv4Address dstaddr, uint16_t port); 65 | void BindSock(Ptr sock, Ptr netdev); 66 | //void srcSocketRecv(Ptr Socket); 67 | //void dstSocketRecv(Ptr Socket); 68 | 69 | std::vector Received(1, 0); 70 | std::vector theTime(1, 0); 71 | 72 | static void RxEnd(Ptr p) { // used for tracing and calculating throughput 73 | 74 | Received.push_back(Received.back() + p->GetSize()); // appends on the received packet to the received data up until that packet and adds that total to the end of the vector 75 | theTime.push_back(Simulator::Now().GetSeconds()); // keeps track of the time during simulation that a packet is received 76 | } 77 | 78 | static void TxEnd(Ptr p) { // also used as a trace and for calculating throughput 79 | 80 | Received.push_back(Received.back() + p->GetSize()); // same as for the RxEnd trace 81 | theTime.push_back(Simulator::Now().GetSeconds()); // 82 | } 83 | 84 | static const uint32_t totalTxBytes = 100000; //The simulation with send 1000 bytes in data packets (not including overhead) 85 | static uint32_t currentTxBytes = 0; 86 | static const uint32_t writeSize = 1040; // How big each packet will be, default for TCP is 536 w/out headers 87 | uint8_t data[writeSize]; 88 | 89 | 90 | NS_LOG_COMPONENT_DEFINE ("MyFirst"); 91 | 92 | int main (int argc, char *argv[]) 93 | { 94 | 95 | // #################################################VPPM TESTING################################################# 96 | 97 | //VPPM Variables 98 | 99 | /*double transmit_power = (48.573); // used to set the transmitted power 100 | double LambertianOrder = (70.0); // to set lambertianorder semiangle 101 | double FilterGain = (1); // to set the filter gain*/ 102 | double PhotoDetectorArea = (1.0e-4); // to set the photo dectror area 103 | /* 104 | double fov = (70.0); // to set field of view 105 | double refracIndex = (1.5); // to set refractive index 106 | */ 107 | 108 | /* double transmitter_Azimuth = (0.0); 109 | double receiver_Azimuth = (0.0); 110 | double transmitter_elevation = (180.0); 111 | double receiver_elevation = (0.0);*/ 112 | 113 | // noise setup: 114 | // double DutyCycle = (0.85); 115 | double Band_factor_Noise_Signal = (10.0); 116 | /* int lower_freq = (380); 117 | int upper_freq = (380); 118 | int temp = (5000); 119 | double elec_filter_bandwidth = (5 * 1e6); 120 | 121 | uint8_t data[writeSize];*/ 122 | 123 | 124 | Ptr sink1; 125 | std::vector Received(1, 0); 126 | std::vector theTime(1, 0); 127 | 128 | //OUTPUT FILES TO CAPTURE PARAMETERS 129 | 130 | std::ofstream myfile; 131 | myfile.open("VPPMBER.dat"); 132 | 133 | std::ofstream myfile2; 134 | myfile2.open("VPPMSNR.dat"); 135 | 136 | std::ofstream myfile3; 137 | myfile3.open("VPPMGOODPUT.dat"); 138 | 139 | std::ofstream myfile4; 140 | myfile4.open("GvS_VPPM.dat"); 141 | 142 | std::ofstream myfile5; 143 | myfile5.open("BvS_VPPM.dat"); 144 | for(double dist = 50; dist > 0; dist -= .5){ 145 | 146 | //creating each node object 147 | 148 | Ptr < Node > wifiAp = CreateObject(); 149 | Ptr < Node > relayAp = CreateObject(); 150 | Ptr < Node > relayMt = CreateObject(); 151 | Ptr < Node > wifiMt = CreateObject(); 152 | 153 | //puts all the nodes into one place 154 | 155 | NodeContainer c = NodeContainer(wifiAp, relayAp, relayMt, wifiMt); 156 | InternetStackHelper internet; //This helper handles making all the components of the internet stack that will be layered on top on the already exsisting network 157 | internet.Install(c); 158 | 159 | //This helper sets up the P2P connections that we will be using 160 | PointToPointHelper p2p; 161 | p2p.SetDeviceAttribute("DataRate", StringValue("200Mbps")); 162 | p2p.SetChannelAttribute("Delay", StringValue("2ms")); 163 | NetDeviceContainer ndAp_Relay = p2p.Install(wifiAp, relayAp); 164 | 165 | // #################################################VLC-NETWORK-CONFIG################################################# 166 | vlc_DeviceHelper devHelperVPPM; 167 | 168 | devHelperVPPM.CreateTransmitter("THE_TRANSMITTER"); 169 | devHelperVPPM.SetTXSignal("THE_TRANSMITTER",1000,0.5,0.2e-3,4.5e-3,0.5e-3); 170 | devHelperVPPM.SetTrasmitterParameter("THE_TRANSMITTER","Bias",0.5e-3); 171 | devHelperVPPM.SetTrasmitterBoost("THE_TRANSMITTER"); 172 | devHelperVPPM.SetTrasmitterParameter("THE_TRANSMITTER","SemiAngle",70); 173 | devHelperVPPM.SetTrasmitterParameter("THE_TRANSMITTER","Azimuth",0); 174 | devHelperVPPM.SetTrasmitterParameter("THE_TRANSMITTER","Elevation",180.0); 175 | devHelperVPPM.SetTrasmitterPosition("THE_TRANSMITTER",0.0,0.0,52.0); 176 | devHelperVPPM.SetTrasmitterParameter("THE_TRANSMITTER","Gain",70); 177 | devHelperVPPM.SetTrasmitterParameter("THE_TRANSMITTER","DataRateInMBPS",5); 178 | 179 | 180 | 181 | devHelperVPPM.CreateReceiver("THE_RECEIVER"); 182 | devHelperVPPM.SetReceiverParameter("THE_RECEIVER","FilterGain",1); 183 | devHelperVPPM.SetReceiverParameter("THE_RECEIVER","RefractiveIndex",1.5); 184 | devHelperVPPM.SetReceiverParameter("THE_RECEIVER","FOVAngle",70); 185 | devHelperVPPM.SetReceiverParameter("THE_RECEIVER","ConcentrationGain",0); 186 | devHelperVPPM.SetReceiverParameter("THE_RECEIVER","PhotoDetectorArea",1.0e-4); 187 | devHelperVPPM.SetReceiverParameter("THE_RECEIVER","RXGain",0); 188 | devHelperVPPM.SetReceiverPosition("THE_RECEIVER",0.0,0.0,dist); 189 | devHelperVPPM.SetReceiverParameter("THE_RECEIVER","DutyCycle",0.85); 190 | devHelperVPPM.SetReceiverParameter("THE_RECEIVER","PhotoDetectorArea", PhotoDetectorArea); 191 | devHelperVPPM.SetReceiverParameter("THE_RECEIVER","Beta", 1); 192 | devHelperVPPM.SetReceiverParameter("THE_RECEIVER","SetModulationScheme", 2); 193 | 194 | 195 | 196 | 197 | vlcChannelHelper chHelperVPPM; 198 | 199 | chHelperVPPM.CreateChannel("THE_CHANNEL"); 200 | chHelperVPPM.SetPropagationLoss("THE_CHANNEL","VLCPropagationLoss"); 201 | chHelperVPPM.SetPropagationDelay("THE_CHANNEL",2); 202 | chHelperVPPM.AttachTransmitter("THE_CHANNEL","THE_TRANSMITTER",&devHelperVPPM); 203 | chHelperVPPM.AttachReceiver("THE_CHANNEL","THE_RECEIVER",&devHelperVPPM); 204 | chHelperVPPM.SetChannelParameter("THE_CHANNEL","TEMP",295); 205 | chHelperVPPM.SetChannelParameter("THE_CHANNEL","BAND_FACTOR_NOISE_SIGNAL",Band_factor_Noise_Signal); 206 | chHelperVPPM.SetChannelWavelength("THE_CHANNEL",380,780); 207 | chHelperVPPM.SetChannelParameter("THE_CHANNEL","ElectricNoiseBandWidth",5 * 1e6); 208 | 209 | 210 | NetDeviceContainer ndRelayAp_RelayMt2 = chHelperVPPM.Install("THE_CHANNEL",relayAp,relayMt); 211 | 212 | //------------------------------------------------------------ 213 | //Wifi-------------------------------------------------------- 214 | std::string phyMode("DsssRate11Mbps"); 215 | double rss = -80; // -dBm 216 | NodeContainer cont = NodeContainer(relayMt, relayAp); 217 | 218 | // The below set of helpers will help us to put together the wifi NICs we want 219 | WifiHelper wifi; 220 | wifi.SetStandard(WIFI_PHY_STANDARD_80211b); 221 | YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default(); 222 | 223 | // This is one parameter that matters when using FixedRssLossModel 224 | // set it to zero; otherwise, gain will be added 225 | wifiPhy.Set("RxGain", DoubleValue(0)); 226 | 227 | // ns-3 supports RadioTap and Prism tracing extensions for 802.11b 228 | wifiPhy.SetPcapDataLinkType(YansWifiPhyHelper::DLT_IEEE802_11_RADIO); 229 | YansWifiChannelHelper wifiChannel; 230 | wifiChannel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel"); 231 | 232 | // The below FixedRssLossModel will cause the rss to be fixed regardless 233 | // of the distance between the two stations, and the transmit power 234 | wifiChannel.AddPropagationLoss("ns3::FixedRssLossModel", "Rss",DoubleValue(rss)); 235 | wifiPhy.SetChannel(wifiChannel.Create()); 236 | 237 | // Add a non-QoS upper mac, and disable rate control 238 | NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default(); 239 | wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "DataMode", 240 | StringValue(phyMode), "ControlMode", StringValue(phyMode)); 241 | 242 | // Set it to adhoc mode 243 | wifiMac.SetType("ns3::AdhocWifiMac"); 244 | NetDeviceContainer ndRelayAp_RelayMt3 = wifi.Install(wifiPhy, wifiMac,cont); 245 | 246 | // Note that with FixedRssLossModel, the positions below are not 247 | // used for received signal strength. 248 | MobilityHelper mobility; 249 | Ptr < ListPositionAllocator > positionAlloc = CreateObject(); 250 | positionAlloc->Add(Vector(0.0, 0.0, 52.0)); 251 | positionAlloc->Add(Vector(0.0, 0.0, dist )); 252 | mobility.SetPositionAllocator(positionAlloc); 253 | mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); 254 | mobility.Install(cont); 255 | 256 | //NetDeviceContainer ndRelayAp_RelayMt3 = p2p.Install(relayMt,relayAp); 257 | //------------------------------------------------------------- 258 | NetDeviceContainer ndRelay_Mt = p2p.Install(relayMt, wifiMt); 259 | 260 | //The following sets up address bases for out net devices on the nodes so as to identify them on a routing table as we do 261 | Ipv4AddressHelper ipv4; 262 | ipv4.SetBase("10.1.1.0", "255.255.255.0"); // used for the WIFI AP ------- Relay AP point to point 263 | Ipv4InterfaceContainer iAp = ipv4.Assign(ndAp_Relay); 264 | ipv4.SetBase("10.1.2.0", "255.255.255.0"); // used for the Relay AP --------- Relay MT VLC 265 | Ipv4InterfaceContainer iRelayApMt = ipv4.Assign(ndRelayAp_RelayMt2); 266 | ipv4.SetBase("10.1.3.0", "255.255.255.0"); // used for the Relay MT ------- Relay AP WIFI 267 | Ipv4InterfaceContainer iRelayMtAp = ipv4.Assign(ndRelayAp_RelayMt3); 268 | ipv4.SetBase("10.1.4.0", "255.255.255.0"); // used for Relay MT -------- MT point to point 269 | Ipv4InterfaceContainer iMt = ipv4.Assign(ndRelay_Mt); 270 | 271 | //The following sets up each nodes routing table that will be statically added to 272 | Ptr < Ipv4 > ipv4Ap = wifiAp->GetObject(); 273 | Ptr < Ipv4 > ipv4RelayAp = relayAp->GetObject(); 274 | Ptr < Ipv4 > ipv4RelayMt = relayMt->GetObject(); 275 | Ptr < Ipv4 > ipv4Mt = wifiMt->GetObject(); 276 | Ipv4StaticRoutingHelper ipv4RoutingHelper; 277 | Ptr < Ipv4StaticRouting > staticRoutingAp = 278 | ipv4RoutingHelper.GetStaticRouting(ipv4Ap); 279 | 280 | Ptr < Ipv4StaticRouting > staticRoutingRelayAp = 281 | ipv4RoutingHelper.GetStaticRouting(ipv4RelayAp); 282 | 283 | Ptr < Ipv4StaticRouting > staticRoutingRelayMt = 284 | ipv4RoutingHelper.GetStaticRouting(ipv4RelayMt); 285 | 286 | Ptr < Ipv4StaticRouting > staticRoutingMt = 287 | ipv4RoutingHelper.GetStaticRouting(ipv4Mt); 288 | 289 | //The following are the specific routes added to various routing tables and this current scheme is modeing a VLC downlink and a WIFI uplink 290 | staticRoutingAp->AddHostRouteTo(Ipv4Address("10.1.4.2"), 291 | Ipv4Address("10.1.1.2"), 1, 1); /// 292 | 293 | staticRoutingRelayAp->AddHostRouteTo(Ipv4Address("10.1.4.2"), 294 | Ipv4Address("10.1.2.2"), 2, 1); // This block is for sending from WIFI AP to the MT 295 | 296 | staticRoutingRelayMt->AddHostRouteTo(Ipv4Address("10.1.4.2"), 297 | Ipv4Address("10.1.4.2"), 3, 1); // 298 | 299 | staticRoutingMt->AddHostRouteTo(Ipv4Address("10.1.1.1"), 300 | Ipv4Address("10.1.4.1"), 1, 1); /// 301 | 302 | staticRoutingRelayMt->AddHostRouteTo(Ipv4Address("10.1.1.1"), 303 | Ipv4Address("10.1.3.2"), 2, 1); // This block is for sending back information from MT to WIFI AP 304 | 305 | staticRoutingRelayAp->AddHostRouteTo(Ipv4Address("10.1.1.1"), 306 | Ipv4Address("10.1.1.1"), 1, 1); // 307 | 308 | //This sets up various sockets on the same node as to allow multiple TCP connections to be made as to pass information through the net devices 309 | Ptr < Socket > srcSocket1 = Socket::CreateSocket(wifiAp, 310 | TypeId::LookupByName("ns3::TcpSocketFactory")); 311 | Ptr < Socket > srcSocket2 = Socket::CreateSocket(wifiAp, TypeId::LookupByName("ns3::TcpSocketFactory")); 312 | Ptr < Socket > srcSocket3 = Socket::CreateSocket(wifiAp, TypeId::LookupByName("ns3::TcpSocketFactory")); 313 | Ptr < Socket > srcSocket4 = Socket::CreateSocket(wifiAp, TypeId::LookupByName("ns3::TcpSocketFactory")); 314 | uint16_t dstport = 12345; 315 | Ipv4Address dstaddr("10.1.4.2"); //destination 316 | PacketSinkHelper sink("ns3::TcpSocketFactory", 317 | InetSocketAddress(Ipv4Address::GetAny(), dstport)); //setting a sink on a node 318 | ApplicationContainer apps = sink.Install(wifiMt); 319 | sink1 = DynamicCast < PacketSink > (apps.Get(0)); 320 | apps.Start(Seconds(0.0)); 321 | apps.Stop(Seconds(10.0)); 322 | 323 | //the following is used for logging and various debugging purposes 324 | AsciiTraceHelper ascii; 325 | p2p.EnableAsciiAll(ascii.CreateFileStream("RoutingTestCase.tr")); 326 | p2p.EnablePcapAll("RoutingTestCase"); 327 | // LogComponentEnableAll (LOG_PREFIX_TIME); 328 | // LogComponentEnable("RoutingTestCase", LOG_LEVEL_INFO); 329 | Ptr < OutputStreamWrapper > stream1 = Create < OutputStreamWrapper> ("Table3", std::ios::out); 330 | ipv4RoutingHelper.PrintRoutingTableAllAt(Seconds(2.0), stream1); 331 | ndRelay_Mt.Get(1)->TraceConnectWithoutContext("PhyRxEnd", MakeCallback(&RxEnd)); //traces to allow us to see what and when data is sent through the network 332 | ndRelay_Mt.Get(1)->TraceConnectWithoutContext("PhyTxEnd", MakeCallback(&TxEnd)); //traces to allow us to see what and when data is received through the network 333 | 334 | // Simulator schedules 335 | Simulator::Schedule(Seconds(0.1), &StartFlow, srcSocket1, dstaddr,dstport); 336 | Simulator::Run(); 337 | 338 | double throughput = ((Received.back() * 8)) / theTime.back(); //goodput calculation 339 | std::cout << "-------------------------" << std::endl; 340 | std::cout << "Distance : " << dist << std::endl; 341 | myfile2 << 52 - dist << "\t" << chHelperVPPM.GetChannelSNR("THE_CHANNEL") << std::endl; 342 | myfile << 52 - dist << "\t" << devHelperVPPM.GetReceiverParameter("THE_RECEIVER","BER") << std::endl; 343 | myfile3 << 52 - dist << "\t" << throughput << std::endl; 344 | myfile4 << chHelperVPPM.GetChannelSNR("THE_CHANNEL") << "\t" << throughput << std::endl; 345 | std::cout << chHelperVPPM.GetChannelSNR("THE_CHANNEL") << "\t" << throughput << std::endl; 346 | myfile5 << devHelperVPPM.GetReceiverParameter("THE_RECEIVER","BER") << "\t" << std::endl; 347 | 348 | Received.clear(); // clears the data received vector so as to avoid calculation errors from old and irrelevant values 349 | Simulator::Destroy(); 350 | 351 | } 352 | 353 | 354 | Simulator::Destroy (); 355 | return 0; 356 | } 357 | 358 | std::vector& GenerateSignal(int size,double dutyRatio){ 359 | std::vector *result = new std::vector(); 360 | result->reserve(size); 361 | 362 | double bias = 0; 363 | double Vmax = 4.5; 364 | double Vmin = 0.5; 365 | 366 | 367 | 368 | for(int i=0;ipush_back(Vmax+bias); 371 | } 372 | else{ 373 | result->push_back(Vmin+bias); 374 | } 375 | } 376 | 377 | return *result; 378 | } 379 | 380 | void BindSock(Ptr sock, Ptr netdev) { 381 | sock->BindToNetDevice(netdev); 382 | return; 383 | } 384 | 385 | void StartFlow(Ptr localSocket, Ipv4Address servAddress,uint16_t servPort) { 386 | // NS_LOG_INFO ("Starting flow at time " << Simulator::Now ().GetSeconds ()); 387 | currentTxBytes = 0; 388 | localSocket->Bind(); 389 | localSocket->Connect(InetSocketAddress(servAddress, servPort)); //connect 390 | 391 | // tell the tcp implementation to call WriteUntilBufferFull again 392 | // if we blocked and new tx buffer space becomes available 393 | localSocket->SetSendCallback(MakeCallback(&WriteUntilBufferFull)); 394 | WriteUntilBufferFull(localSocket, localSocket->GetTxAvailable()); 395 | } 396 | 397 | void WriteUntilBufferFull(Ptr localSocket, uint32_t txSpace) { 398 | while (currentTxBytes < totalTxBytes && localSocket->GetTxAvailable() > 0) { 399 | uint32_t left = totalTxBytes - currentTxBytes; 400 | uint32_t dataOffset = currentTxBytes % writeSize; 401 | uint32_t toWrite = writeSize - dataOffset; 402 | toWrite = std::min(toWrite, left); 403 | toWrite = std::min(toWrite, localSocket->GetTxAvailable()); 404 | int amountSent = localSocket->Send(&data[dataOffset], toWrite, 0); 405 | if (amountSent < 0) { 406 | // we will be called again when new tx space becomes available. 407 | return; 408 | } 409 | currentTxBytes += amountSent; 410 | } 411 | localSocket->Close(); 412 | } 413 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------