OLD | NEW |
(Empty) | |
| 1 #include "ns3/log.h" |
| 2 #include "ns3/command-line.h" |
| 3 #include "ns3/logical-lora-channel-helper.h" |
| 4 #include <cstdlib> |
| 5 |
| 6 using namespace ns3; |
| 7 |
| 8 NS_LOG_COMPONENT_DEFINE ("ChannelTest"); |
| 9 |
| 10 int main (int argc, char *argv[]) |
| 11 { |
| 12 |
| 13 CommandLine cmd; |
| 14 cmd.Parse (argc, argv); |
| 15 |
| 16 LogComponentEnable ("ChannelTest", LOG_LEVEL_ALL); |
| 17 LogComponentEnable ("LogicalLoraChannel", LOG_LEVEL_ALL); |
| 18 LogComponentEnable ("LogicalLoraChannelHelper", LOG_LEVEL_ALL); |
| 19 LogComponentEnable ("SubBand", LOG_LEVEL_ALL); |
| 20 |
| 21 ///////////////////////////// |
| 22 // Test LogicalLoraChannel // |
| 23 ///////////////////////////// |
| 24 |
| 25 // Setup |
| 26 Ptr<LogicalLoraChannel> channel1 = CreateObject<LogicalLoraChannel> (868); |
| 27 Ptr<LogicalLoraChannel> channel2 = CreateObject<LogicalLoraChannel> (868); |
| 28 Ptr<LogicalLoraChannel> channel3 = CreateObject<LogicalLoraChannel> (868.1); |
| 29 Ptr<LogicalLoraChannel> channel4 = CreateObject<LogicalLoraChannel> (868.001); |
| 30 |
| 31 // Equality between channels |
| 32 // Test the == and != operators |
| 33 NS_ASSERT (channel1 == channel2); |
| 34 NS_ASSERT (channel1 != channel3); |
| 35 NS_ASSERT (channel1 != channel4); |
| 36 |
| 37 ////////////////// |
| 38 // Test SubBand // |
| 39 ////////////////// |
| 40 |
| 41 // Setup |
| 42 SubBand subBand (868, 868.7, 0.01, 14); |
| 43 Ptr<LogicalLoraChannel> channel5 = CreateObject<LogicalLoraChannel> (870); |
| 44 |
| 45 // Test BelongsToSubBand |
| 46 NS_ASSERT (subBand.BelongsToSubBand (channel3)); |
| 47 NS_ASSERT (subBand.BelongsToSubBand (channel3->GetFrequency ())); |
| 48 NS_ASSERT (!subBand.BelongsToSubBand (channel5)); |
| 49 |
| 50 /////////////////////////////////// |
| 51 // Test LogicalLoraChannelHelper // |
| 52 /////////////////////////////////// |
| 53 |
| 54 // Setup |
| 55 Ptr<LogicalLoraChannelHelper> channelHelper = CreateObject<LogicalLoraChannelH
elper> (); |
| 56 SubBand subBand1 (869, 869.4, 0.1, 27); |
| 57 channel1 = CreateObject<LogicalLoraChannel> (868.1); |
| 58 channel2 = CreateObject<LogicalLoraChannel> (868.3); |
| 59 channel3 = CreateObject<LogicalLoraChannel> (868.5); |
| 60 channel4 = CreateObject<LogicalLoraChannel> (869.1); |
| 61 channel5 = CreateObject<LogicalLoraChannel> (869.3); |
| 62 |
| 63 // Channel diagram |
| 64 // |
| 65 // Channels 1 2 3 4 5 |
| 66 // SubBands 868 ----- 0.1% ----- 868.7 869 ----- 1% ----- 869.4 |
| 67 |
| 68 // Add SubBands and LogicalLoraChannels to the helper |
| 69 channelHelper->AddSubBand (&subBand); |
| 70 channelHelper->AddSubBand (&subBand1); |
| 71 channelHelper->AddChannel (channel1); |
| 72 channelHelper->AddChannel (channel2); |
| 73 channelHelper->AddChannel (channel3); |
| 74 channelHelper->AddChannel (channel4); |
| 75 channelHelper->AddChannel (channel5); |
| 76 |
| 77 // Duty Cycle tests |
| 78 // (high level duty cycle behavior) |
| 79 /////////////////////////////////// |
| 80 |
| 81 // Waiting time is computed correctly |
| 82 channelHelper->AddEvent (Seconds (2), channel1); |
| 83 Time expectedTimeOff = Seconds (2/0.01 - 2); |
| 84 NS_ASSERT (channelHelper->GetWaitingTime (channel1) == expectedTimeOff); |
| 85 |
| 86 // Duty Cycle involves the whole SubBand, not just a channel |
| 87 NS_ASSERT (channelHelper->GetWaitingTime (channel2) == expectedTimeOff); |
| 88 NS_ASSERT (channelHelper->GetWaitingTime (channel3) == expectedTimeOff); |
| 89 |
| 90 // Other bands are not affected by this transmission |
| 91 NS_ASSERT (channelHelper->GetWaitingTime (channel4) == 0); |
| 92 NS_ASSERT (channelHelper->GetWaitingTime (channel5) == 0); |
| 93 |
| 94 return 0; |
| 95 } |
OLD | NEW |