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

(-)a/src/routing/olsr/olsr-header.cc (-1 / +1 lines)
 Lines 785-791    Link Here 
785
} g_olsrTestSuite;
785
} g_olsrTestSuite;
786
786
787
OlsrTestSuite::OlsrTestSuite()
787
OlsrTestSuite::OlsrTestSuite()
788
  : TestSuite("olsr-routing", UNIT)
788
  : TestSuite("Routing-OLSR-header", UNIT)
789
{
789
{
790
  AddTestCase(new OlsrHnaTestCase());
790
  AddTestCase(new OlsrHnaTestCase());
791
  AddTestCase(new OlsrTcTestCase());
791
  AddTestCase(new OlsrTcTestCase());
(-)a/src/routing/olsr/olsr-routing-protocol.cc (+122 lines)
 Lines 2832-2837    Link Here 
2832
    }
2839
    }
2833
  return false;
2840
  return false;
2834
}
2841
}
2842
OlsrMprTestCase::OlsrMprTestCase ()
2843
  : TestCase ("Check OLSR MPR computing mechanism")
2844
{
2845
}
2846
OlsrMprTestCase::~OlsrMprTestCase ()
2847
{
2848
}
2849
bool
2850
OlsrMprTestCase::DoRun ()
2851
{
2852
  /*
2853
      * Create a 3x3 grid like the following:
2854
      *      3---6---9
2855
      *      |\ /|\ /|
2856
      *      | X | X |
2857
      *      |/ \|/ \|
2858
      *      2---5---8
2859
      *      |\ /|\ /|
2860
      *      | X | X |
2861
      *      |/ \|/ \|
2862
      *      1---4---7
2863
      * PrepareTopology fills all 2-hop neighbors of station 1 and creates a routing protocol
2864
      * We are the station number 2. Obvious, that an only MPR in this case is 5 
2865
      */
2866
   Ptr<RoutingProtocol> m_protocol = CreateObject<RoutingProtocol> ();
2867
   m_protocol->m_mainAddress = Ipv4Address ("10.0.0.2");
2868
   // we fill all possible 2-hop neighborhood
2869
   TwoHopNeighborTuple tuple;
2870
   tuple.expirationTime = Seconds (3600);
2871
   // All neighbor stations which are seen from station 5
2872
   tuple.neighborMainAddr = Ipv4Address ("10.0.0.5");
2873
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.1");
2874
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2875
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2");
2876
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2877
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.3");
2878
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2879
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4");
2880
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2881
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.6");
2882
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2883
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.7");
2884
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2885
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.8");
2886
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2887
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.9");
2888
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2889
   // All neighbor stations which are seen from station 4
2890
   tuple.neighborMainAddr = Ipv4Address ("10.0.0.4");
2891
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.1");
2892
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2893
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2");
2894
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2895
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5");
2896
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2897
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.8");
2898
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2899
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.7");
2900
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2901
2902
   // All neighbor stations which are seen from station 6
2903
   tuple.neighborMainAddr = Ipv4Address ("10.0.0.6");
2904
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.3");
2905
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2906
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2");
2907
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2908
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5");
2909
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2910
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.8");
2911
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2912
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.9");
2913
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2914
2915
   // All neighbor stations which are seen from station 1
2916
   tuple.neighborMainAddr = Ipv4Address ("10.0.0.1");
2917
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2");
2918
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2919
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5");
2920
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2921
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.4");
2922
2923
   // All neighbor stations which are seen from station 3
2924
   tuple.neighborMainAddr = Ipv4Address ("10.0.0.3");
2925
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.2");
2926
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2927
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.5");
2928
   m_protocol->m_state.InsertTwoHopNeighborTuple (tuple);
2929
   tuple.twoHopNeighborAddr = Ipv4Address ("10.0.0.6");
2930
  // First, we fill all neighbors
2931
  // If neighbors willingness = OLSR_WILL_DEFAULT, an only station number 5 will be an MPR
2932
  NeighborTuple neigbor;
2933
  neigbor.status = NeighborTuple::STATUS_SYM;
2934
  neigbor.willingness = OLSR_WILL_DEFAULT;
2935
  neigbor.neighborMainAddr = Ipv4Address ("10.0.0.3");
2936
  m_protocol->m_state.InsertNeighborTuple (neigbor);
2937
  neigbor.neighborMainAddr = Ipv4Address ("10.0.0.6");
2938
  m_protocol->m_state.InsertNeighborTuple (neigbor);
2939
  neigbor.neighborMainAddr = Ipv4Address ("10.0.0.5");
2940
  m_protocol->m_state.InsertNeighborTuple (neigbor);
2941
  neigbor.neighborMainAddr = Ipv4Address ("10.0.0.4");
2942
  m_protocol->m_state.InsertNeighborTuple (neigbor);
2943
  neigbor.neighborMainAddr = Ipv4Address ("10.0.0.1");
2944
  m_protocol->m_state.InsertNeighborTuple (neigbor);
2945
  //Now, calculateMPR
2946
  m_protocol->MprComputation ();
2947
  //Check results
2948
  NS_TEST_ASSERT_MSG_EQ (m_protocol->m_state.FindMprAddress (Ipv4Address ("10.0.0.5")), true, "MPR is incorrect!");
2949
  NS_TEST_ASSERT_MSG_EQ (m_protocol->m_state.GetMprSet ().size (), 1 , "An only address must be chosen!\n");
2950
  return false;
2951
}
2952
2953
static class OlsrProtocolTestSuite : public TestSuite
2954
{
2955
public:
2956
  OlsrProtocolTestSuite ();
2957
} g_olsrProtocolTestSuite;
2958
2959
OlsrProtocolTestSuite::OlsrProtocolTestSuite()
2960
  : TestSuite("Routing-OLSR", UNIT)
2961
{
2962
  AddTestCase (new OlsrMprTestCase ());
2963
}
2835
2964
2836
}} // namespace olsr, ns3
2965
}} // namespace olsr, ns3
2837
2966
(-)a/src/routing/olsr/olsr-routing-protocol.h (+11 lines)
 Lines 25-30    Link Here 
25
#define __OLSR_AGENT_IMPL_H__
25
#define __OLSR_AGENT_IMPL_H__
26
26
27
#include "olsr-header.h"
27
#include "olsr-header.h"
28
#include "ns3/test.h"
28
#include "olsr-state.h"
29
#include "olsr-state.h"
29
#include "olsr-repositories.h"
30
#include "olsr-repositories.h"
30
31
 Lines 58-68    Link Here 
58
    destAddr (), nextAddr (),
59
    destAddr (), nextAddr (),
59
    interface (0), distance (0) {};
60
    interface (0), distance (0) {};
60
};
61
};
62
class RoutingProtocol;
63
/// Testcase for MPR computation mechanism
64
class OlsrMprTestCase : public TestCase {
65
public:
66
  OlsrMprTestCase ();
67
  ~OlsrMprTestCase ();
68
  virtual bool DoRun (void);
69
  ;
70
};
61
71
62
72
63
class RoutingProtocol : public Ipv4RoutingProtocol
73
class RoutingProtocol : public Ipv4RoutingProtocol
64
{
74
{
65
public:
75
public:
76
  friend class OlsrMprTestCase;
66
  static TypeId GetTypeId (void);
77
  static TypeId GetTypeId (void);
67
78
68
  RoutingProtocol ();
79
  RoutingProtocol ();
(-)a/src/routing/olsr/olsr-state.cc (+5 lines)
 Lines 272-277    Link Here 
272
{
272
{
273
  m_mprSet = mprSet;
273
  m_mprSet = mprSet;
274
}
274
}
275
MprSet
276
OlsrState::GetMprSet () const
277
{
278
  return m_mprSet;
279
}
275
280
276
/********** Duplicate Set Manipulation **********/
281
/********** Duplicate Set Manipulation **********/
277
282
(-)a/src/routing/olsr/olsr-state.h (+1 lines)
 Lines 99-104    Link Here 
99
  // MPR
99
  // MPR
100
  bool FindMprAddress (const Ipv4Address &address);
100
  bool FindMprAddress (const Ipv4Address &address);
101
  void SetMprSet (MprSet mprSet);
101
  void SetMprSet (MprSet mprSet);
102
  MprSet GetMprSet () const;
102
103
103
  // Duplicate
104
  // Duplicate
104
  DuplicateTuple* FindDuplicateTuple (const Ipv4Address &address,
105
  DuplicateTuple* FindDuplicateTuple (const Ipv4Address &address,

Return to bug 740