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 PropagationLossCacheTestCase : public TestCase
466
{
467
public:
468
  PropagationLossCacheTestCase ();
469
  virtual ~PropagationLossCacheTestCase ();
470
471
private:
472
  virtual bool DoRun (void);
473
};
474
475
PropagationLossCacheTestCase::PropagationLossCacheTestCase ()
476
  : TestCase ("Test PropagationLossCache")
477
{
478
}
479
480
PropagationLossCacheTestCase::~PropagationLossCacheTestCase ()
481
{
482
}
483
484
bool
485
PropagationLossCacheTestCase::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
  PropagationLossCache 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 PropagationLossCacheTestCase);
479
}
533
}
480
534
481
PropagationLossModelsTestSuite WifiPropagationLossModelsTestSuite;
535
PropagationLossModelsTestSuite WifiPropagationLossModelsTestSuite;
(-)a/src/common/propagation-loss-model.cc (-1 / +93 lines)
 Lines 19-30    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"
25
#include "ns3/log.h"
26
#include "ns3/log.h"
26
#include "ns3/mobility-model.h"
27
#include "ns3/mobility-model.h"
27
#include "ns3/boolean.h"
28
#include "ns3/boolean.h"
29
#include "ns3/pointer.h"
28
#include "ns3/double.h"
30
#include "ns3/double.h"
29
#include <math.h>
31
#include <math.h>
30
32
 Lines 752-757    Link Here 
752
  Ptr<MobilityModel> ma = a->GetObject<MobilityModel> ();
754
  Ptr<MobilityModel> ma = a->GetObject<MobilityModel> ();
753
  Ptr<MobilityModel> mb = b->GetObject<MobilityModel> ();
755
  Ptr<MobilityModel> mb = b->GetObject<MobilityModel> ();
754
  NS_ASSERT (ma != 0 && mb != 0);
756
  NS_ASSERT (ma != 0 && mb != 0);
757
  SetLoss (ma, mb, loss, symmetric);
758
}
759
760
void
761
MatrixPropagationLossModel::SetLoss (Ptr<MobilityModel> ma, Ptr<MobilityModel> mb, double loss, bool symmetric)
762
{
763
  NS_ASSERT (ma != 0 && mb != 0);
755
764
756
  MobilityPair p = std::make_pair(ma, mb);
765
  MobilityPair p = std::make_pair(ma, mb);
757
  std::map<MobilityPair, double>::iterator i = m_loss.find (p);
766
  std::map<MobilityPair, double>::iterator i = m_loss.find (p);
 Lines 767-773    Link Here 
767
776
768
  if (symmetric)
777
  if (symmetric)
769
    {
778
    {
770
      SetLoss (b, a, loss, false);
779
      SetLoss (mb, ma, loss, false);
771
    }
780
    }
772
}
781
}
773
782
 Lines 788-793    Link Here 
788
    }
797
    }
789
}
798
}
790
799
800
bool
801
MatrixPropagationLossModel::IsLossSet (Ptr<MobilityModel> a,
802
                                       Ptr<MobilityModel> b) const
803
{
804
  std::map<MobilityPair, double>::const_iterator i = m_loss.find (std::make_pair (a, b));
805
  
806
  return (i != m_loss.end ());
807
}
808
791
// ------------------------------------------------------------------------- //
809
// ------------------------------------------------------------------------- //
792
810
793
NS_OBJECT_ENSURE_REGISTERED (RangePropagationLossModel);
811
NS_OBJECT_ENSURE_REGISTERED (RangePropagationLossModel);
 Lines 829-832    Link Here 
829
847
830
// ------------------------------------------------------------------------- //
848
// ------------------------------------------------------------------------- //
831
849
850
NS_OBJECT_ENSURE_REGISTERED (PropagationLossCache);
851
852
TypeId 
853
PropagationLossCache::GetTypeId (void)
854
{
855
  static TypeId tid = TypeId ("ns3::PropagationLossCache")
856
    .SetParent<PropagationLossModel> ()
857
    .AddConstructor<PropagationLossCache> ()
858
    .AddAttribute ("Symmetric",
859
                   "Whether propagation loss is symmetric",
860
                   BooleanValue (false),
861
                   MakeBooleanAccessor (&PropagationLossCache::m_symmetric),
862
                   MakeBooleanChecker ())
863
    .AddAttribute ("CachedModels",
864
                   "The list of models to be cached",
865
                   PointerValue (),
866
                   MakePointerAccessor (&PropagationLossCache::m_models),
867
                   MakePointerChecker<PropagationLossModel> ())
868
    ;
869
  return tid;
870
}
871
872
PropagationLossCache::PropagationLossCache (void)
873
  : PropagationLossModel (), m_symmetric (false),
874
    m_cache (CreateObject<MatrixPropagationLossModel> ())
875
{}
876
877
void
878
PropagationLossCache::AddModel (Ptr<PropagationLossModel> next)
879
{
880
  NS_ASSERT (next != 0x0);
881
882
  next->SetNext (m_models);
883
  m_models = next;
884
}
885
886
void
887
PropagationLossCache::SetSymmetric (const bool b)
888
{
889
  m_symmetric = b;
890
}
891
892
bool
893
PropagationLossCache::GetSymmetric (void)
894
{
895
  return m_symmetric;
896
}
897
898
double 
899
PropagationLossCache::DoCalcRxPower (double txPowerDbm,
900
                                           Ptr<MobilityModel> a,
901
                                           Ptr<MobilityModel> b) const
902
{
903
  double rxc = 0.0;
904
905
  if (m_cache->IsLossSet (a, b))
906
    {
907
      NS_LOG_DEBUG ("cache hit.");
908
      rxc = m_cache->CalcRxPower (0, a, b);
909
    }
910
  else
911
    {
912
      NS_LOG_DEBUG ("cache miss.");
913
      rxc = m_models->CalcRxPower (0, a, b); // assumes models independent of power
914
      m_cache->SetLoss (a, b, -rxc, m_symmetric);
915
    }
916
917
  NS_LOG_DEBUG ("attenuation coefficent="<<rxc<<"Db");
918
919
  return txPowerDbm + rxc;
920
}
921
922
// ------------------------------------------------------------------------- //
923
832
} // namespace ns3
924
} // namespace ns3
(-)a/src/common/propagation-loss-model.h (+68 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 IsLossSet (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
 * Typical use:
552
 * <code>
553
 * // ...
554
 * PropagationLossCacheHelper cacheHelper;
555
 * cacheHelper.AddPropagationLoss ("ns3::SomeCachableLossModel",
556
 *        "Attribute", someValue);
557
 * cacheHelper.AddPropagationLoss ("ns3::AnotherCachableLossModel",
558
 *        "Attribute", someValue);
559
 *
560
 * WifiChannelHelper wifiChannel; // initialised elsewhere
561
 * wifiChannel.AddPropagationLoss ("ns3::PropagationLossCache",
562
 *        "CachedModels",
563
 *        PointerValue (cacheHelper.GetCachedModels ()));
564
 * wifiChannel.AddPropagationLoss ("ns3::OtherNonCachedLossModel");
565
 * // ...
566
 * </code>
567
 */
568
class PropagationLossCache : public PropagationLossModel
569
{
570
public:
571
  static TypeId GetTypeId (void);
572
  PropagationLossCache (void);
573
574
  /**
575
   * \brief Add a model to the wrapped chain.
576
   *
577
   * \param next the model to be added.
578
   */
579
  void AddModel (Ptr<PropagationLossModel> next);
580
  void SetSymmetric (const bool sym);
581
  bool GetSymmetric (void);
582
583
private:
584
  PropagationLossCache (const PropagationLossCache&);
585
  PropagationLossCache& operator =
586
    (const PropagationLossCache&);
587
588
  virtual double DoCalcRxPower (double txPowerDbm,
589
                                Ptr<MobilityModel>,
590
                                Ptr<MobilityModel>) const;
591
592
  bool m_symmetric;
593
  Ptr<PropagationLossModel> m_models;
594
  Ptr<MatrixPropagationLossModel> m_cache;
595
};
596
529
} // namespace ns3
597
} // namespace ns3
530
598
531
#endif /* PROPAGATION_LOSS_MODEL_H */
599
#endif /* PROPAGATION_LOSS_MODEL_H */
(-)87c065a7bd8a (+95 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 NICTA
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Quincy Tse <quincy.tse@nicta.com.au>
19
 */
20
21
#include "propagation-loss-cache-helper.h"
22
#include "ns3/propagation-loss-model.h"
23
#include "ns3/log.h"
24
25
NS_LOG_COMPONENT_DEFINE ("PropagationLossCacheHelper");
26
27
namespace ns3 {
28
29
PropagationLossCacheHelper::PropagationLossCacheHelper (void)
30
{}
31
32
void
33
PropagationLossCacheHelper::AddPropagationLoss (std::string type,
34
            std::string n0, const AttributeValue &v0,
35
            std::string n1, const AttributeValue &v1,
36
            std::string n2, const AttributeValue &v2,
37
            std::string n3, const AttributeValue &v3,
38
            std::string n4, const AttributeValue &v4,
39
            std::string n5, const AttributeValue &v5,
40
            std::string n6, const AttributeValue &v6,
41
            std::string n7, const AttributeValue &v7)
42
{
43
  ObjectFactory factory;
44
  factory.SetTypeId (type);
45
  factory.Set (n0, v0);
46
  factory.Set (n1, v1);
47
  factory.Set (n2, v2);
48
  factory.Set (n3, v3);
49
  factory.Set (n4, v4);
50
  factory.Set (n5, v5);
51
  factory.Set (n6, v6);
52
  factory.Set (n7, v7);
53
  m_propagationLoss.push_back (factory);
54
}
55
56
inline void
57
PropagationLossCacheHelper::SetSymmetric (bool symmetric)
58
{
59
  m_symmetric = symmetric;
60
}
61
62
Ptr<PropagationLossCache>
63
PropagationLossCacheHelper::Create (void) const
64
{
65
  Ptr<PropagationLossCache> cache = CreateObject<PropagationLossCache> ();
66
67
  cache->SetSymmetric (m_symmetric);
68
69
  for (std::vector<ObjectFactory>::const_iterator it = m_propagationLoss.begin ();
70
       it != m_propagationLoss.end (); ++it)
71
    {
72
      Ptr<PropagationLossModel> cur = (*it).Create<PropagationLossModel> ();
73
      cache->AddModel (cur);
74
    }
75
76
  return cache;
77
}
78
79
Ptr<PropagationLossModel>
80
PropagationLossCacheHelper::GetCachedModels (void) const
81
{
82
  Ptr<PropagationLossModel> prev = 0;
83
84
  for (std::vector<ObjectFactory>::const_iterator it = m_propagationLoss.begin ();
85
       it != m_propagationLoss.end (); ++it)
86
    {
87
      Ptr<PropagationLossModel> curr = (*it).Create<PropagationLossModel> ();
88
      curr->SetNext (prev);
89
      prev = curr;
90
    }
91
92
  return prev;
93
}
94
95
}
(-)87c065a7bd8a (+100 lines)
Added Link Here 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
 * Copyright (c) 2010 NICTA
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License version 2 as
7
 * published by the Free Software Foundation;
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 * Author: Quincy Tse <quincy.tse@nicta.com.au>
19
 */
20
#ifndef PROPAGATION_LOSS_CACHE_HELPER_H
21
#define PROPAGATION_LOSS_CACHE_HELPER_H
22
23
#include "ns3/propagation-loss-model.h"
24
#include "ns3/object-factory.h"
25
26
namespace ns3 {
27
28
/**
29
 * \brief Manage and create propagation loss cache objects.
30
 *
31
 * The intent of this class is to make it easy to create and confiruge a
32
 * PropagationLossCache object .
33
 */
34
class PropagationLossCacheHelper
35
{
36
public:
37
  /**
38
   * Create a cache helper without any parameter set.
39
   */
40
  PropagationLossCacheHelper (void);
41
42
  /**
43
   * \param name the name of the model to add
44
   * \param n0 the name of the attribute to set
45
   * \param v0 the value of the attribute to set
46
   * \param n1 the name of the attribute to set
47
   * \param v1 the value of the attribute to set
48
   * \param n2 the name of the attribute to set
49
   * \param v2 the value of the attribute to set
50
   * \param n3 the name of the attribute to set
51
   * \param v3 the value of the attribute to set
52
   * \param n4 the name of the attribute to set
53
   * \param v4 the value of the attribute to set
54
   * \param n5 the name of the attribute to set
55
   * \param v5 the value of the attribute to set
56
   * \param n6 the name of the attribute to set
57
   * \param v6 the value of the attribute to set
58
   * \param n7 the name of the attribute to set
59
   * \param v7 the value of the attribute to set
60
   *
61
   * Add a propagation loss model to the set of currently-configured loss models.
62
   * This method is additive to allow you to cache multiple propagation loss
63
   * models.
64
   */
65
  void AddPropagationLoss (std::string name,
66
			   std::string n0 = "", const AttributeValue &v0 = EmptyAttributeValue (),
67
			   std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
68
			   std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
69
			   std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
70
			   std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue (),
71
			   std::string n5 = "", const AttributeValue &v5 = EmptyAttributeValue (),
72
			   std::string n6 = "", const AttributeValue &v6 = EmptyAttributeValue (),
73
			   std::string n7 = "", const AttributeValue &v7 = EmptyAttributeValue ());
74
75
  /**
76
   * Sets whether the cache is symmetrical.
77
   */
78
  void SetSymmetric (bool symmetric);
79
80
  /**
81
   * \returns a new cache
82
   *
83
   * Create a cache based on the configuration parameters set previously.
84
   */
85
  Ptr<PropagationLossCache> Create (void) const;
86
87
  /**
88
   * \returns a Ptr to the head of a PropagationLossModel list
89
   *
90
   * Create the propagation loss models and line them in a chain.
91
   */
92
  Ptr<PropagationLossModel> GetCachedModels (void) const;
93
94
private:
95
  std::vector<ObjectFactory> m_propagationLoss;
96
  bool m_symmetric;
97
};
98
99
}
100
#endif
(-)a/src/helper/wscript (+2 lines)
 Lines 55-60    Link Here 
55
        'topology-reader-helper.cc',
55
        'topology-reader-helper.cc',
56
        'waveform-generator-helper.cc',
56
        'waveform-generator-helper.cc',
57
        'spectrum-analyzer-helper.cc',
57
        'spectrum-analyzer-helper.cc',
58
        'propagation-loss-cache-helper.cc',
58
        ]
59
        ]
59
60
60
    headers = bld.new_task_gen('ns3header')
61
    headers = bld.new_task_gen('ns3header')
 Lines 113-118    Link Here 
113
        'topology-reader-helper.h',
114
        'topology-reader-helper.h',
114
        'waveform-generator-helper.h',
115
        'waveform-generator-helper.h',
115
        'spectrum-analyzer-helper.h',
116
        'spectrum-analyzer-helper.h',
117
        'propagation-loss-cache-helper.h',
116
        ]
118
        ]
117
119
118
    env = bld.env_of_name('default')
120
    env = bld.env_of_name('default')

Return to bug 1003