OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2016 NITK Surathkal |
| 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 * Authors: Ankit Deepak <adadeepak8@gmail.com> |
| 19 * Shravya Ks <shravya.ks0@gmail.com>, |
| 20 * Mohit P. Tahiliani <tahiliani@nitk.edu.in> |
| 21 */ |
| 22 |
| 23 /* |
| 24 * PORT NOTE: This code was ported from ns-3 IPv4 implementation (src/olsr). A
lmost all |
| 25 * comments have also been ported from the same |
| 26 */ |
| 27 |
| 28 |
| 29 #include "ns3/test.h" |
| 30 #include "ns3/olsr6-routing-protocol.h" |
| 31 #include "ns3/ipv6-header.h" |
| 32 |
| 33 /********** Willingness **********/ |
| 34 |
| 35 /// Willingness for forwarding packets from other nodes: never. |
| 36 #define OLSR6_WILL_NEVER 0 |
| 37 /// Willingness for forwarding packets from other nodes: low. |
| 38 #define OLSR6_WILL_LOW 1 |
| 39 /// Willingness for forwarding packets from other nodes: medium. |
| 40 #define OLSR6_WILL_DEFAULT 3 |
| 41 /// Willingness for forwarding packets from other nodes: high. |
| 42 #define OLSR6_WILL_HIGH 6 |
| 43 /// Willingness for forwarding packets from other nodes: always. |
| 44 #define OLSR6_WILL_ALWAYS 7 |
| 45 |
| 46 using namespace ns3; |
| 47 using namespace olsr6; |
| 48 |
| 49 /// Testcase for MPR computation mechanism |
| 50 class Olsr6MprTestCase : public TestCase |
| 51 { |
| 52 public: |
| 53 Olsr6MprTestCase (); |
| 54 ~Olsr6MprTestCase (); |
| 55 /// \brief Run test case |
| 56 virtual void DoRun (void); |
| 57 }; |
| 58 |
| 59 |
| 60 Olsr6MprTestCase::Olsr6MprTestCase () |
| 61 : TestCase ("Check OLSR6 MPR computing mechanism") |
| 62 { |
| 63 } |
| 64 Olsr6MprTestCase::~Olsr6MprTestCase () |
| 65 { |
| 66 } |
| 67 void |
| 68 Olsr6MprTestCase::DoRun () |
| 69 { |
| 70 Ptr<RoutingProtocol> protocol = CreateObject<RoutingProtocol> (); |
| 71 protocol->m_mainAddress = Ipv6Address ("2001:1::1"); |
| 72 Olsr6State & state = protocol->m_state; |
| 73 |
| 74 /* |
| 75 * 1 -- 2 |
| 76 * | | |
| 77 * 3 -- 4 |
| 78 * |
| 79 * Node 1 must select only one MPR (2 or 3, doesn't matter) |
| 80 */ |
| 81 NeighborTuple neigbor; |
| 82 neigbor.status = NeighborTuple::STATUS_SYM; |
| 83 neigbor.willingness = OLSR6_WILL_DEFAULT; |
| 84 neigbor.neighborMainAddr = Ipv6Address ("2001:1::2"); |
| 85 protocol->m_state.InsertNeighborTuple (neigbor); |
| 86 neigbor.neighborMainAddr = Ipv6Address ("2001:1::3"); |
| 87 protocol->m_state.InsertNeighborTuple (neigbor); |
| 88 TwoHopNeighborTuple tuple; |
| 89 tuple.expirationTime = Seconds (3600); |
| 90 tuple.neighborMainAddr = Ipv6Address ("2001:1::2"); |
| 91 tuple.twoHopNeighborAddr = Ipv6Address ("2001:1::4"); |
| 92 protocol->m_state.InsertTwoHopNeighborTuple (tuple); |
| 93 tuple.neighborMainAddr = Ipv6Address ("2001:1::3"); |
| 94 tuple.twoHopNeighborAddr = Ipv6Address ("2001:1::4"); |
| 95 protocol->m_state.InsertTwoHopNeighborTuple (tuple); |
| 96 |
| 97 protocol->MprComputation (); |
| 98 NS_TEST_EXPECT_MSG_EQ (state.GetMprSet ().size (), 1, "An only address must be
chosen."); |
| 99 /* |
| 100 * 1 -- 2 -- 5 |
| 101 * | | |
| 102 * 3 -- 4 |
| 103 * |
| 104 * Node 1 must select node 2 as MPR. |
| 105 */ |
| 106 tuple.neighborMainAddr = Ipv6Address ("2001:1::2"); |
| 107 tuple.twoHopNeighborAddr = Ipv6Address ("2001:1::5"); |
| 108 protocol->m_state.InsertTwoHopNeighborTuple (tuple); |
| 109 |
| 110 protocol->MprComputation (); |
| 111 MprSet mpr = state.GetMprSet (); |
| 112 NS_TEST_EXPECT_MSG_EQ (mpr.size (), 1, "An only address must be chosen."); |
| 113 NS_TEST_EXPECT_MSG_EQ ((mpr.find ("2001:1::2") != mpr.end ()), true, "Node 1 m
ust select node 2 as MPR"); |
| 114 /* |
| 115 * 1 -- 2 -- 5 |
| 116 * | | |
| 117 * 3 -- 4 |
| 118 * | |
| 119 * 6 |
| 120 * |
| 121 * Node 1 must select nodes 2 and 3 as MPRs. |
| 122 */ |
| 123 tuple.neighborMainAddr = Ipv6Address ("2001:1::3"); |
| 124 tuple.twoHopNeighborAddr = Ipv6Address ("2001:1::6"); |
| 125 protocol->m_state.InsertTwoHopNeighborTuple (tuple); |
| 126 |
| 127 protocol->MprComputation (); |
| 128 mpr = state.GetMprSet (); |
| 129 NS_TEST_EXPECT_MSG_EQ (mpr.size (), 2, "An only address must be chosen."); |
| 130 NS_TEST_EXPECT_MSG_EQ ((mpr.find ("2001:1::2") != mpr.end ()), true, "Node 1 m
ust select node 2 as MPR"); |
| 131 NS_TEST_EXPECT_MSG_EQ ((mpr.find ("2001:1::3") != mpr.end ()), true, "Node 1 m
ust select node 3 as MPR"); |
| 132 /* |
| 133 * 7 (OLSR6_WILL_ALWAYS) |
| 134 * | |
| 135 * 1 -- 2 -- 5 |
| 136 * | | |
| 137 * 3 -- 4 |
| 138 * | |
| 139 * 6 |
| 140 * |
| 141 * Node 1 must select nodes 2, 3 and 7 (since it is WILL_ALWAYS) as MPRs. |
| 142 */ |
| 143 neigbor.willingness = OLSR6_WILL_ALWAYS; |
| 144 neigbor.neighborMainAddr = Ipv6Address ("2001:1::7"); |
| 145 protocol->m_state.InsertNeighborTuple (neigbor); |
| 146 |
| 147 protocol->MprComputation (); |
| 148 mpr = state.GetMprSet (); |
| 149 NS_TEST_EXPECT_MSG_EQ (mpr.size (), 3, "An only address must be chosen."); |
| 150 NS_TEST_EXPECT_MSG_EQ ((mpr.find ("2001:1::7") != mpr.end ()), true, "Node 1 m
ust select node 7 as MPR"); |
| 151 /* |
| 152 * 7 <- WILL_ALWAYS |
| 153 * | |
| 154 * 9 -- 8 -- 1 -- 2 -- 5 |
| 155 * | | |
| 156 * ^ 3 -- 4 |
| 157 * | | |
| 158 * WILL_NEVER 6 |
| 159 * |
| 160 * Node 1 must select nodes 2, 3 and 7 (since it is WILL_ALWAYS) as MPRs. |
| 161 * Node 1 must NOT select node 8 as MPR since it is WILL_NEVER |
| 162 */ |
| 163 neigbor.willingness = OLSR6_WILL_NEVER; |
| 164 neigbor.neighborMainAddr = Ipv6Address ("2001:1::8"); |
| 165 protocol->m_state.InsertNeighborTuple (neigbor); |
| 166 tuple.neighborMainAddr = Ipv6Address ("2001:1::8"); |
| 167 tuple.twoHopNeighborAddr = Ipv6Address ("2001:1::9"); |
| 168 protocol->m_state.InsertTwoHopNeighborTuple (tuple); |
| 169 |
| 170 protocol->MprComputation (); |
| 171 mpr = state.GetMprSet (); |
| 172 NS_TEST_EXPECT_MSG_EQ (mpr.size (), 3, "An only address must be chosen."); |
| 173 NS_TEST_EXPECT_MSG_EQ ((mpr.find ("2001:1::9") == mpr.end ()), true, "Node 1 m
ust NOT select node 8 as MPR"); |
| 174 } |
| 175 |
| 176 static class Olsr6ProtocolTestSuite : public TestSuite |
| 177 { |
| 178 public: |
| 179 Olsr6ProtocolTestSuite (); |
| 180 } g_olsr6ProtocolTestSuite; |
| 181 |
| 182 Olsr6ProtocolTestSuite::Olsr6ProtocolTestSuite () |
| 183 : TestSuite ("routing-olsr6", UNIT) |
| 184 { |
| 185 AddTestCase (new Olsr6MprTestCase (), TestCase::QUICK); |
| 186 } |
OLD | NEW |