View | Details | Raw Unified | Return to bug 1003
Collapse All | Expand All

(-)a/src/common/propagation-loss-model-test-suite.cc (+54 lines)
 Lines 462-467    Link Here 
462
  return GetErrorStatus ();
462
  return GetErrorStatus ();
463
}
463
}
464
464
465
class PropagationLossCachedEvaluatorTestCase : public TestCase
466
{
467
public:
468
  PropagationLossCachedEvaluatorTestCase ();
469
  virtual ~PropagationLossCachedEvaluatorTestCase ();
470
471
private:
472
  virtual bool DoRun (void);
473
};
474
475
PropagationLossCachedEvaluatorTestCase::PropagationLossCachedEvaluatorTestCase ()
476
  : TestCase ("Test PropagationLossCachedEvaluator")
477
{
478
}
479
480
PropagationLossCachedEvaluatorTestCase::~PropagationLossCachedEvaluatorTestCase ()
481
{
482
}
483
484
bool
485
PropagationLossCachedEvaluatorTestCase::DoRun (void)
486
{
487
  Ptr<Node> n[3];
488
  Ptr<MobilityModel> m[3];
489
  for (int i = 0; i < 3; ++i)
490
    {
491
      n[i] = CreateObject<Node> ();
492
      m[i] = CreateObject<ConstantPositionMobilityModel> ();
493
      m[i]->SetPosition (Vector (i, i, i));
494
      n[i]->AggregateObject (m[i]);
495
    }
496
  
497
  Ptr<LogDistancePropagationLossModel> ref =
498
    CreateObject<LogDistancePropagationLossModel> ();
499
  PropagationLossCachedEvaluator cache;
500
  cache.AddModel (ref);
501
502
  NS_TEST_ASSERT_MSG_EQ (cache.CalcRxPower (0, m[0], m[1]), ref->CalcRxPower (0, m[0], m[1]), "cache 0 -> 1 incorrect");
503
  NS_TEST_ASSERT_MSG_EQ (cache.CalcRxPower (0, m[1], m[0]), ref->CalcRxPower (0, m[1], m[0]), "cache 1 -> 0 incorrect");
504
  NS_TEST_ASSERT_MSG_EQ (cache.CalcRxPower (0, m[0], m[2]), ref->CalcRxPower (0, m[0], m[2]), "cache 0 -> 2 incorrect");
505
  NS_TEST_ASSERT_MSG_EQ (cache.CalcRxPower (0, m[2], m[0]), ref->CalcRxPower (0, m[2], m[0]), "cache 2 -> 0 incorrect");
506
  NS_TEST_ASSERT_MSG_EQ (cache.CalcRxPower (0, m[1], m[2]), ref->CalcRxPower (0, m[1], m[2]), "cache 1 -> 2 incorrect");
507
  NS_TEST_ASSERT_MSG_EQ (cache.CalcRxPower (0, m[2], m[1]), ref->CalcRxPower (0, m[2], m[1]), "cache 2 -> 1 incorrect");
508
  NS_TEST_ASSERT_MSG_EQ (cache.CalcRxPower (10, m[2], m[1]), ref->CalcRxPower (10, m[2], m[1]), "attenuation not applied to txPowerDbm");
509
510
  m[0]->SetPosition (Vector (10,10,10));
511
  NS_TEST_EXPECT_MSG_NE (cache.CalcRxPower (0, m[0], m[1]), ref->CalcRxPower (0, m[0], m[1]), "cache not used");
512
513
  Simulator::Destroy ();
514
  
515
  return GetErrorStatus ();
516
}
517
465
class PropagationLossModelsTestSuite : public TestSuite
518
class PropagationLossModelsTestSuite : public TestSuite
466
{
519
{
467
public:
520
public:
 Lines 476-481    Link Here 
476
  AddTestCase (new LogDistancePropagationLossModelTestCase);
529
  AddTestCase (new LogDistancePropagationLossModelTestCase);
477
  AddTestCase (new MatrixPropagationLossModelTestCase);
530
  AddTestCase (new MatrixPropagationLossModelTestCase);
478
  AddTestCase (new RangePropagationLossModelTestCase);
531
  AddTestCase (new RangePropagationLossModelTestCase);
532
  AddTestCase (new PropagationLossCachedEvaluatorTestCase);
479
}
533
}
480
534
481
PropagationLossModelsTestSuite WifiPropagationLossModelsTestSuite;
535
PropagationLossModelsTestSuite WifiPropagationLossModelsTestSuite;
(-)a/src/common/propagation-loss-model.cc (+102 lines)
 Lines 19-24    Link Here 
19
 * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu>
19
 * Contributions: Timo Bingmann <timo.bingmann@student.kit.edu>
20
 * Contributions: Tom Hewer <tomhewer@mac.com> for Two Ray Ground Model
20
 * Contributions: Tom Hewer <tomhewer@mac.com> for Two Ray Ground Model
21
 *                Pavel Boyko <boyko@iitp.ru> for matrix
21
 *                Pavel Boyko <boyko@iitp.ru> for matrix
22
 *                Quincy Tse <quincy.tse@nicta.com.au> for cached
22
 */
23
 */
23
24
24
#include "propagation-loss-model.h"
25
#include "propagation-loss-model.h"
 Lines 771-776    Link Here 
771
    }
772
    }
772
}
773
}
773
774
775
void
776
MatrixPropagationLossModel::SetLoss (Ptr<MobilityModel> ma, Ptr<MobilityModel> mb, double loss, bool symmetric)
777
{
778
  NS_ASSERT (ma != 0 && mb != 0);
779
780
  MobilityPair p = std::make_pair(ma, mb);
781
  std::map<MobilityPair, double>::iterator i = m_loss.find (p);
782
  
783
  if (i == m_loss.end ())
784
    {
785
      m_loss.insert (std::make_pair (p, loss));
786
    }
787
  else
788
    {
789
      i->second = loss;
790
    }
791
792
  if (symmetric)
793
    {
794
      SetLoss (mb, ma, loss, false);
795
    }
796
}
797
774
double 
798
double 
775
MatrixPropagationLossModel::DoCalcRxPower (double txPowerDbm,
799
MatrixPropagationLossModel::DoCalcRxPower (double txPowerDbm,
776
                                           Ptr<MobilityModel> a,
800
                                           Ptr<MobilityModel> a,
 Lines 788-793    Link Here 
788
    }
812
    }
789
}
813
}
790
814
815
bool
816
MatrixPropagationLossModel::ContainsPair (Ptr<MobilityModel> a,
817
                                           Ptr<MobilityModel> b) const
818
{
819
  std::map<MobilityPair, double>::const_iterator i = m_loss.find (std::make_pair (a, b));
820
  
821
  return (i != m_loss.end ());
822
}
823
791
// ------------------------------------------------------------------------- //
824
// ------------------------------------------------------------------------- //
792
825
793
NS_OBJECT_ENSURE_REGISTERED (RangePropagationLossModel);
826
NS_OBJECT_ENSURE_REGISTERED (RangePropagationLossModel);
 Lines 829-832    Link Here 
829
862
830
// ------------------------------------------------------------------------- //
863
// ------------------------------------------------------------------------- //
831
864
865
NS_OBJECT_ENSURE_REGISTERED (PropagationLossCachedEvaluator);
866
867
TypeId 
868
PropagationLossCachedEvaluator::GetTypeId (void)
869
{
870
  static TypeId tid = TypeId ("ns3::PropagationLossCachedEvaluator")
871
    .SetParent<PropagationLossModel> ()
872
    .AddConstructor<PropagationLossCachedEvaluator> ()
873
    .AddAttribute ("Symmetric",
874
                   "Whether propagation loss is symmetric",
875
                   BooleanValue (false),
876
                   MakeBooleanAccessor (&PropagationLossCachedEvaluator::m_symmetric),
877
                   MakeBooleanChecker ())
878
    ;
879
  return tid;
880
}
881
882
PropagationLossCachedEvaluator::PropagationLossCachedEvaluator (void)
883
  : PropagationLossModel (), m_symmetric (false),
884
    m_cache (CreateObject<MatrixPropagationLossModel> ())
885
{}
886
887
void
888
PropagationLossCachedEvaluator::AddModel (Ptr<PropagationLossModel> next)
889
{
890
  NS_ASSERT (next != 0x0);
891
892
  next->SetNext (m_models);
893
  m_models = next;
894
}
895
896
void
897
PropagationLossCachedEvaluator::SetSymmetric (const bool b)
898
{
899
  m_symmetric = b;
900
}
901
902
bool
903
PropagationLossCachedEvaluator::GetSymmetric (void)
904
{
905
  return m_symmetric;
906
}
907
908
double 
909
PropagationLossCachedEvaluator::DoCalcRxPower (double txPowerDbm,
910
                                           Ptr<MobilityModel> a,
911
                                           Ptr<MobilityModel> b) const
912
{
913
  double rxc = 0.0;
914
915
  if (m_cache->ContainsPair (a, b))
916
    {
917
      NS_LOG_DEBUG ("cache hit.");
918
      rxc = m_cache->CalcRxPower (0, a, b);
919
    }
920
  else
921
    {
922
      NS_LOG_DEBUG ("cache miss.");
923
      rxc = m_models->CalcRxPower (0, a, b); // assumes models independent of power
924
      m_cache->SetLoss (a, b, -rxc, m_symmetric);
925
    }
926
927
  NS_LOG_DEBUG ("attenuation coefficent="<<rxc<<"Db");
928
929
  return txPowerDbm + rxc;
930
}
931
932
// ------------------------------------------------------------------------- //
933
832
} // namespace ns3
934
} // namespace ns3
(-)a/src/common/propagation-loss-model.h (+51 lines)
 Lines 20-25    Link Here 
20
 * Contributions: Gary Pei <guangyu.pei@boeing.com> for fixed RSS
20
 * Contributions: Gary Pei <guangyu.pei@boeing.com> for fixed RSS
21
 * Contributions: Tom Hewer <tomhewer@mac.com> for two ray ground model
21
 * Contributions: Tom Hewer <tomhewer@mac.com> for two ray ground model
22
 *                Pavel Boyko <boyko@iitp.ru> for matrix
22
 *                Pavel Boyko <boyko@iitp.ru> for matrix
23
 *                Quincy Tse <quincy.tse@nicta.com.au> for buffered
23
 */
24
 */
24
25
25
#ifndef PROPAGATION_LOSS_MODEL_H
26
#ifndef PROPAGATION_LOSS_MODEL_H
 Lines 487-494    Link Here 
487
   * \param symmetric   If true (default), both a->b and b->a paths will be affected
488
   * \param symmetric   If true (default), both a->b and b->a paths will be affected
488
   */ 
489
   */ 
489
  void SetLoss (Ptr<Node> a, Ptr<Node> b, double loss, bool symmetric = true);
490
  void SetLoss (Ptr<Node> a, Ptr<Node> b, double loss, bool symmetric = true);
491
  /**
492
   * \brief Set loss (in dB, positive) between pair of nodes.
493
   * 
494
   * \param a           Source node's MobilityModel
495
   * \param b           Destination node's MobilityModel
496
   * \param loss        a -> b path loss, positive in dB
497
   * \param symmetric   If true (default), both a->b and b->a paths will be affected
498
   */ 
499
  void SetLoss (Ptr<MobilityModel> a, Ptr<MobilityModel> b, double loss, bool symmetric = true);
490
  /// Set default loss (in dB, positive) to be used, infinity if not set
500
  /// Set default loss (in dB, positive) to be used, infinity if not set
491
  void SetDefaultLoss (double);
501
  void SetDefaultLoss (double);
502
  /// Whether matrix contains the node-pair
503
  bool ContainsPair (Ptr<MobilityModel> a, Ptr<MobilityModel> b) const;
492
  
504
  
493
private:
505
private:
494
  virtual double DoCalcRxPower (double txPowerDbm,
506
  virtual double DoCalcRxPower (double txPowerDbm,
 Lines 526-531    Link Here 
526
  double m_range;
538
  double m_range;
527
};
539
};
528
540
541
/**
542
 * \brief A cached evaluator for propagation loss models.
543
 *
544
 * This model calculates the reception power only as required and caches
545
 * the results for later use. It wraps around models whose values do not
546
 * change throughout the simulation (eg. log-distance pathloss, given
547
 * nodes are stationary. Results from the wrapped model chain are cached
548
 * in a MatrixPropagationLossModel. The wrapped models MUST be independent
549
 * of the input signal strength.
550
 */
551
class PropagationLossCachedEvaluator : public PropagationLossModel
552
{
553
public:
554
  static TypeId GetTypeId (void);
555
  PropagationLossCachedEvaluator (void);
556
557
  /**
558
   * \brief Add a model to the wrapped chain.
559
   *
560
   * \param next the model to be added.
561
   */
562
  void AddModel (Ptr<PropagationLossModel> next);
563
  void SetSymmetric (const bool sym);
564
  bool GetSymmetric (void);
565
566
private:
567
  PropagationLossCachedEvaluator (const PropagationLossCachedEvaluator&);
568
  PropagationLossCachedEvaluator& operator =
569
    (const PropagationLossCachedEvaluator&);
570
571
  virtual double DoCalcRxPower (double txPowerDbm,
572
                                Ptr<MobilityModel>,
573
                                Ptr<MobilityModel>) const;
574
575
  bool m_symmetric;
576
  Ptr<PropagationLossModel> m_models;
577
  Ptr<MatrixPropagationLossModel> m_cache;
578
};
579
529
} // namespace ns3
580
} // namespace ns3
530
581
531
#endif /* PROPAGATION_LOSS_MODEL_H */
582
#endif /* PROPAGATION_LOSS_MODEL_H */

Return to bug 1003