|
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 |
|