OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /*· |
| 3 * Copyright (c) 2012 Michal Paszta |
| 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: Michal Paszta· |
| 19 */ |
| 20 |
| 21 #include <ns3/test.h> |
| 22 #include <ns3/rns-module.h> |
| 23 #include <iostream> |
| 24 #include <ns3/log.h> |
| 25 #include <ns3/ipv4.h> |
| 26 #include <ns3/packet.h> |
| 27 |
| 28 namespace ns3 { |
| 29 |
| 30 /* *********************** RNS Simple Test Case ******************************/ |
| 31 class SimpleTestCase : public TestCase |
| 32 { |
| 33 public: |
| 34 SimpleTestCase(); |
| 35 ~SimpleTestCase(); |
| 36 void DoRun(void); |
| 37 }; |
| 38 |
| 39 SimpleTestCase::SimpleTestCase() |
| 40 : TestCase("RNS Algorithm Simple Test") |
| 41 {} |
| 42 |
| 43 SimpleTestCase::~SimpleTestCase() |
| 44 {} |
| 45 |
| 46 void SimpleTestCase::DoRun(void) |
| 47 { |
| 48 //Situation 0 |
| 49 Ptr<rns::Rns<uint32_t> > rns1 = CreateObject<rns::Rns<uint32_t> >(0,0.0,0.0,5.
0); |
| 50 rns1->SetAttribute("Test", BooleanValue(true)); |
| 51 rns1->Start(NULL); |
| 52 NS_TEST_EXPECT_MSG_EQ(rns1->AmIRedundant(),false,"0: Non-redundant node recogn
ized as redundant."); |
| 53 |
| 54 //Situation 1 |
| 55 rns::Neighbor<uint32_t> n1(1,5.0,5.0,5.0); |
| 56 rns1->UpdateNeighbor(n1,true); |
| 57 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"1: Non-redundant node recogni
zed as redundant."); |
| 58 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),false,"1: RRN not recognized."); |
| 59 |
| 60 //Situation 2 |
| 61 n1.SetX(2.0);n1.SetY(2.0); |
| 62 rns1->UpdateNeighbor(n1,true); |
| 63 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"2: Non-redundant node recogni
zed as redundant."); |
| 64 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),false,"2: RRN not recognized."); |
| 65 |
| 66 //Situation 3 |
| 67 rns::Neighbor<uint32_t> n2(2,-1.0,-1.0,5.0); |
| 68 rns1->UpdateNeighbor(n2,true); |
| 69 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"3: Non-redundant node recogni
zed as redundant."); |
| 70 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),false,"3: RRN not recognized."); |
| 71 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),false,"3: RRN not recognized."); |
| 72 |
| 73 //Situation 4 |
| 74 n1.SetR(8.0); |
| 75 rns::RnsHeader<uint32_t> header(0x02,n1.GetR(),n1.GetId()); |
| 76 rns1->ReceiveRnsMessage(header,n1.GetId()); |
| 77 rns1->UpdateNeighbor(n1,true); |
| 78 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"4: Redundant node not recogniz
ed."); |
| 79 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),true,"4: RRN not recognized."); |
| 80 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),false,"4: RRN not recognized."); |
| 81 |
| 82 //Situation 5 |
| 83 n1.SetR(7.0); |
| 84 header.SetNewStatus(0x02);header.SetRange(n1.GetR());header.SetId(n1.GetId()); |
| 85 rns1->ReceiveRnsMessage(header,n1.GetId()); |
| 86 rns1->UpdateNeighbor(n1,true); |
| 87 NS_TEST_EXPECT_MSG_EQ(rns1->AmIRedundant(),true,"5: Redundant node not recogni
zed."); |
| 88 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),true,"5: RRN not recognized."); |
| 89 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),true,"5: RRN not recognized."); |
| 90 |
| 91 //Situation 6 |
| 92 n1.SetX(1.0);n1.SetY(1.0);n1.SetR(5.0); |
| 93 n2.SetX(-1.0);n2.SetY(1.0); |
| 94 rns::Neighbor<uint32_t> n3(3,-1.0,-1.0,5.0); |
| 95 header.SetNewStatus(0x02);header.SetRange(n1.GetR());header.SetId(n1.GetId()); |
| 96 rns1->ReceiveRnsMessage(header,n1.GetId()); |
| 97 rns1->UpdateNeighbor(n1,true); |
| 98 rns1->UpdateNeighbor(n2,true); |
| 99 rns1->UpdateNeighbor(n3,true); |
| 100 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"6: Non-redundant node recogni
zed as redundant."); |
| 101 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),false,"6: RRN not recognized."); |
| 102 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),false,"6: RRN not recognized."); |
| 103 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n3),false,"6: RRN not recognized."); |
| 104 |
| 105 //Situation 7 |
| 106 n1.SetX(1.0);n1.SetY(0.0); |
| 107 rns1->UpdateNeighbor(n1,true); |
| 108 NS_TEST_EXPECT_MSG_EQ(rns1->AmIRedundant(),true,"7: Redundant node not recogni
zed."); |
| 109 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),true,"7: RRN not recognized."); |
| 110 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),true,"7: RRN not recognized."); |
| 111 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n3),true,"7: RRN not recognized."); |
| 112 |
| 113 |
| 114 //Situation 8 |
| 115 rns::Neighbor<uint32_t> n4(4,1.0,-1.0,5.0); |
| 116 rns1->UpdateNeighbor(n4,true); |
| 117 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"8: Redundant node not recogniz
ed."); |
| 118 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),true,"8: RRN not recognized."); |
| 119 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),true,"8: RRN not recognized."); |
| 120 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n3),true,"8: RRN not recognized."); |
| 121 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n4),false,"8: RRN not recognized."); |
| 122 |
| 123 //Situation 9 |
| 124 n1.SetX(4.0);n1.SetY(2.0);n1.SetR(4.0); |
| 125 header.SetNewStatus(0x02);header.SetRange(n1.GetR());header.SetId(n1.GetId()); |
| 126 rns1->ReceiveRnsMessage(header,n1.GetId()); |
| 127 rns1->UpdateNeighbor(n1,true); |
| 128 n2.SetX(-4.0);n2.SetY(4.0); |
| 129 rns1->UpdateNeighbor(n2,true); |
| 130 n3.SetX(-4.0);n3.SetY(-4.0); |
| 131 rns1->UpdateNeighbor(n3,true); |
| 132 n2.SetX(-4.0);n2.SetY(-4.0); |
| 133 rns1->UpdateNeighbor(n4,true); |
| 134 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"9: Redundant node not recogni
zed."); |
| 135 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),false,"9: RRN not recognized."); |
| 136 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),false,"9: RRN not recognized."); |
| 137 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n3),false,"9: RRN not recognized."); |
| 138 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n4),false,"9: RRN not recognized."); |
| 139 |
| 140 |
| 141 /* Repeat all tests with the central node in point (1.5,1.5) */ |
| 142 //Situation 0 |
| 143 Ptr<rns::Rns<uint32_t> > rns2 = CreateObject<rns::Rns<uint32_t> >(0,1.5,1.5,5.
0); |
| 144 rns2->SetAttribute("Test", BooleanValue(true)); |
| 145 rns2->Start(NULL); |
| 146 NS_TEST_EXPECT_MSG_EQ(rns2->AmIRedundant(),false,"0r: Non-redundant node recog
nized as redundant."); |
| 147 |
| 148 //Situation 1 |
| 149 n1.SetX(6.5);n1.SetY(6.5);n1.SetR(5.0); |
| 150 rns2->UpdateNeighbor(n1,true); |
| 151 header.SetNewStatus(0x02);header.SetRange(n1.GetR());header.SetId(n1.GetId()); |
| 152 rns2->ReceiveRnsMessage(header,n1.GetId()); |
| 153 NS_TEST_EXPECT_MSG_EQ(rns2->IsRedundant(),false,"1r: Non-redundant node recogn
ized as redundant."); |
| 154 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n1),false,"1r: RRN not recognized."); |
| 155 |
| 156 //Situation 2 |
| 157 n1.SetX(3.5);n1.SetY(3.5); |
| 158 rns2->UpdateNeighbor(n1,true); |
| 159 NS_TEST_EXPECT_MSG_EQ(rns2->IsRedundant(),false,"2r: Non-redundant node recogn
ized as redundant."); |
| 160 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n1),false,"2r: RRN not recognized."); |
| 161 |
| 162 //Situation 3 |
| 163 n2.SetX(0.5);n2.SetY(0.5); |
| 164 rns2->UpdateNeighbor(n2,true); |
| 165 NS_TEST_EXPECT_MSG_EQ(rns2->IsRedundant(),false,"3r: Non-redundant node recogn
ized as redundant."); |
| 166 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n1),false,"3r: RRN not recognized."); |
| 167 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n2),false,"3r: RRN not recognized."); |
| 168 |
| 169 //Situation 4 |
| 170 n1.SetR(8.0); |
| 171 header.SetNewStatus(0x02);header.SetRange(n1.GetR());header.SetId(n1.GetId()); |
| 172 rns2->ReceiveRnsMessage(header,n1.GetId()); |
| 173 rns2->UpdateNeighbor(n1,true); |
| 174 NS_TEST_EXPECT_MSG_EQ(rns2->IsRedundant(),true,"4r: Redundant node not recogni
zed."); |
| 175 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n1),true,"4r: RRN not recognized."); |
| 176 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n2),false,"4r: RRN not recognized."); |
| 177 |
| 178 //Situation 5 |
| 179 n1.SetR(7.0); |
| 180 header.SetNewStatus(0x02);header.SetRange(n1.GetR());header.SetId(n1.GetId()); |
| 181 rns2->ReceiveRnsMessage(header,n1.GetId()); |
| 182 rns2->UpdateNeighbor(n1,true); |
| 183 NS_TEST_EXPECT_MSG_EQ(rns2->IsRedundant(),true,"5r: Redundant node not recogni
zed."); |
| 184 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n1),true,"5r: RRN not recognized."); |
| 185 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n2),true,"5r: RRN not recognized."); |
| 186 |
| 187 //Situation 6 |
| 188 n1.SetX(2.5);n1.SetY(2.5);n1.SetR(5.0); |
| 189 n2.SetX(0.5);n2.SetY(2.5); |
| 190 n3.SetX(0.5);n3.SetY(0.5); |
| 191 header.SetNewStatus(0x02);header.SetRange(n1.GetR());header.SetId(n1.GetId()); |
| 192 rns2->ReceiveRnsMessage(header,n1.GetId()); |
| 193 rns2->UpdateNeighbor(n1,true); |
| 194 rns2->UpdateNeighbor(n2,true); |
| 195 rns2->UpdateNeighbor(n3,true); |
| 196 NS_TEST_EXPECT_MSG_EQ(rns2->IsRedundant(),false,"6r: Non-redundant node recogn
ized as redundant."); |
| 197 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n1),false,"6r: RRN not recognized."); |
| 198 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n2),false,"6r: RRN not recognized."); |
| 199 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n3),false,"6r: RRN not recognized."); |
| 200 |
| 201 //Situation 7 |
| 202 n1.SetX(2.5);n1.SetY(1.5); |
| 203 rns2->UpdateNeighbor(n1,true); |
| 204 NS_TEST_EXPECT_MSG_EQ(rns2->AmIRedundant(),true,"7r: Redundant node not recogn
ized."); |
| 205 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n1),true,"7r: RRN not recognized."); |
| 206 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n2),true,"7r: RRN not recognized."); |
| 207 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n3),true,"7r: RRN not recognized."); |
| 208 |
| 209 |
| 210 //Situation 8 |
| 211 n4.SetX(2.5);n4.SetY(0.5); |
| 212 rns2->UpdateNeighbor(n4,true); |
| 213 NS_TEST_EXPECT_MSG_EQ(rns2->IsRedundant(),true,"8r: Redundant node not recogni
zed."); |
| 214 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n1),true,"8r: RRN not recognized."); |
| 215 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n2),true,"8r: RRN not recognized."); |
| 216 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n3),true,"8r: RRN not recognized."); |
| 217 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n4),false,"8r: RRN not recognized."); |
| 218 |
| 219 //Situation 9 |
| 220 n1.SetX(5.5);n1.SetY(3.5);n1.SetR(4.0); |
| 221 header.SetNewStatus(0x02);header.SetRange(n1.GetR());header.SetId(n1.GetId()); |
| 222 rns2->ReceiveRnsMessage(header,n1.GetId()); |
| 223 rns2->UpdateNeighbor(n1,true); |
| 224 n2.SetX(-2.5);n2.SetY(5.5); |
| 225 rns2->UpdateNeighbor(n2,true); |
| 226 n3.SetX(-2.5);n3.SetY(-2.5); |
| 227 rns2->UpdateNeighbor(n3,true); |
| 228 n2.SetX(-2.5);n2.SetY(-2.5); |
| 229 rns2->UpdateNeighbor(n4,true); |
| 230 NS_TEST_EXPECT_MSG_EQ(rns2->IsRedundant(),false,"9r: Redundant node not recogn
ized."); |
| 231 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n1),false,"9r: RRN not recognized."); |
| 232 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n2),false,"9r: RRN not recognized."); |
| 233 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n3),false,"9r: RRN not recognized."); |
| 234 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n4),false,"9r: RRN not recognized."); |
| 235 } |
| 236 |
| 237 |
| 238 |
| 239 |
| 240 /* ********************* RNS Redundancy Test Case ****************************/ |
| 241 class RedundancyTestCase : public TestCase |
| 242 { |
| 243 public: |
| 244 RedundancyTestCase(); |
| 245 ~RedundancyTestCase(); |
| 246 void DoRun(void); |
| 247 }; |
| 248 |
| 249 RedundancyTestCase::RedundancyTestCase() |
| 250 : TestCase("RNS Algorithm Redundancy Test") |
| 251 {} |
| 252 |
| 253 RedundancyTestCase::~RedundancyTestCase() |
| 254 {} |
| 255 |
| 256 void RedundancyTestCase::DoRun(void) |
| 257 { |
| 258 Ptr<rns::Rns<uint32_t> > rns1 = CreateObject<rns::Rns<uint32_t> >(0,0.0,0.0,5.
0); |
| 259 rns1->SetAttribute("Test", BooleanValue(true)); |
| 260 rns1->Start(NULL); |
| 261 |
| 262 //Situation 1 |
| 263 rns::Neighbor<uint32_t> n1(1,3.0,3.0,5.0); |
| 264 rns::Neighbor<uint32_t> n2(2,-3.0,3.0,5.0); |
| 265 rns::Neighbor<uint32_t> n3(3,-6.0,-3.0,5.0); |
| 266 rns::Neighbor<uint32_t> n4(4,3.0,-3.0,5.0); |
| 267 rns1->UpdateNeighbor(n1,true); |
| 268 rns1->UpdateNeighbor(n2,true); |
| 269 rns1->UpdateNeighbor(n3,true); |
| 270 rns1->UpdateNeighbor(n4,true); |
| 271 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"1: Redundant node not recogniz
ed."); |
| 272 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),true,"1: RRN not recognized."); |
| 273 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),true,"1: RRN not recognized."); |
| 274 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n3),true,"1: RRN not recognized."); |
| 275 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n4),true,"1: RRN not recognized."); |
| 276 |
| 277 //Situation 2 |
| 278 n1.SetX(5.0);n1.SetY(5.0); |
| 279 n2.SetX(-3.0);n2.SetY(3.0); |
| 280 n3.SetX(-5.0);n3.SetY(-5.0); |
| 281 n4.SetX(3.0);n4.SetY(-1.0); |
| 282 rns1->UpdateNeighbor(n1,true); |
| 283 rns1->UpdateNeighbor(n2,true); |
| 284 rns1->UpdateNeighbor(n3,true); |
| 285 rns1->UpdateNeighbor(n4,true); |
| 286 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"2: Redundant node not recogniz
ed."); |
| 287 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),true,"2: RRN not recognized."); |
| 288 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),true,"2: RRN not recognized."); |
| 289 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n3),true,"2: RRN not recognized."); |
| 290 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n4),true,"2: RRN not recognized."); |
| 291 |
| 292 //Situation 3 |
| 293 n1.SetX(1.0);n1.SetY(-5.0); |
| 294 n2.SetX(4.0);n2.SetY(0.0); |
| 295 n3.SetX(3.0);n3.SetY(2.0); |
| 296 n4.SetX(1.0);n4.SetY(3.0); |
| 297 rns1->UpdateNeighbor(n1,true); |
| 298 rns1->UpdateNeighbor(n2,true); |
| 299 rns1->UpdateNeighbor(n3,true); |
| 300 rns1->UpdateNeighbor(n4,true); |
| 301 rns::Neighbor<uint32_t> n5(5,-2.0,2.0,5.0); |
| 302 rns1->UpdateNeighbor(n5,true); |
| 303 rns::Neighbor<uint32_t> n6(6,-6.0,-2.0,5.0); |
| 304 rns1->UpdateNeighbor(n6,true); |
| 305 rns::Neighbor<uint32_t> n7(7,-5.0,-3.0,5.0); |
| 306 rns1->UpdateNeighbor(n7,true); |
| 307 rns::Neighbor<uint32_t> n8(8,-4.0,-4.0,5.0); |
| 308 rns1->SetRedundant(false); //otherwise, the node will not run the RNS algorith
m |
| 309 rns1->UpdateNeighbor(n8,true); |
| 310 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"3: Redundant node not recogniz
ed."); |
| 311 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),true,"3: RRN not recognized."); |
| 312 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n3),true,"3: RRN not recognized."); |
| 313 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n5),true,"3: RRN not recognized."); |
| 314 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n8),true,"3: RRN not recognized."); |
| 315 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),false,"3: RRN recognized incorrectly."); |
| 316 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n4),false,"3: RRN recognized incorrectly."); |
| 317 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n6),false,"3: RRN recognized incorrectly."); |
| 318 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n7),false,"3: RRN recognized incorrectly."); |
| 319 |
| 320 //Situation 4 |
| 321 //Turn 8 off with a fake rns message |
| 322 rns::RnsHeader<uint32_t> header(0x00,n8.GetR(),n8.GetId()); |
| 323 rns1->ReceiveRnsMessage(header,n8.GetId()); |
| 324 NS_TEST_EXPECT_MSG_EQ(rns1->AmIRedundant(),true,"3: Redundant node not recogni
zed."); |
| 325 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),true,"3: RRN not recognized."); |
| 326 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n3),true,"3: RRN not recognized."); |
| 327 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n5),true,"3: RRN not recognized."); |
| 328 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n8),false,"3: RRN not recognized."); |
| 329 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),false,"3: RRN recognized incorrectly."); |
| 330 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n4),false,"3: RRN recognized incorrectly."); |
| 331 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n6),false,"3: RRN recognized incorrectly."); |
| 332 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n7),true,"3: RRN recognized incorrectly."); |
| 333 |
| 334 //Situation 5 |
| 335 Ptr<rns::Rns<uint32_t> > rns2 = CreateObject<rns::Rns<uint32_t> >(0,0.0,0.0,5.
0); |
| 336 rns2->SetAttribute("Test", BooleanValue(true)); |
| 337 rns2->Start(NULL); |
| 338 header.SetNewStatus(0x02); |
| 339 |
| 340 n1.SetX(3.0);n1.SetY(3.0);n1.SetR(2.0); |
| 341 rns2->UpdateNeighbor(n1,true); |
| 342 header.SetRange(n1.GetR()); |
| 343 rns2->ReceiveRnsMessage(header,n1.GetId()); |
| 344 |
| 345 n2.SetX(-2.0);n2.SetY(2.0);n2.SetR(4.0); |
| 346 rns2->UpdateNeighbor(n2,true); |
| 347 header.SetRange(n2.GetR()); |
| 348 rns2->ReceiveRnsMessage(header,n2.GetId()); |
| 349 |
| 350 n3.SetX(-4.0);n3.SetY(-2.0);n3.SetR(3.0); |
| 351 header.SetRange(n3.GetR()); |
| 352 rns2->ReceiveRnsMessage(header,n3.GetId()); |
| 353 rns2->UpdateNeighbor(n3,true); |
| 354 |
| 355 n4.SetX(3.0);n4.SetY(-1.0);n4.SetR(5.0); |
| 356 rns2->UpdateNeighbor(n4,true); |
| 357 header.SetRange(n4.GetR()); |
| 358 rns2->ReceiveRnsMessage(header,n4.GetId()); |
| 359 |
| 360 n5.SetX(-6.0);n5.SetY(1.0);n5.SetR(2.0); |
| 361 rns2->UpdateNeighbor(n5,true); |
| 362 header.SetRange(n5.GetR()); |
| 363 rns2->ReceiveRnsMessage(header,n5.GetId()); |
| 364 |
| 365 n6.SetX(-1.0);n6.SetY(-6.0);n6.SetR(2.0); |
| 366 rns2->UpdateNeighbor(n6,true); |
| 367 header.SetRange(n6.GetR()); |
| 368 rns2->ReceiveRnsMessage(header,n6.GetId()); |
| 369 NS_TEST_EXPECT_MSG_EQ(rns2->IsRedundant(),false,"5: Redundant node not recogni
zed."); |
| 370 |
| 371 n7.SetX(-2.0);n7.SetY(-4.0);n7.SetR(1.5); |
| 372 rns2->UpdateNeighbor(n7,true); |
| 373 header.SetRange(n7.GetR()); |
| 374 rns2->ReceiveRnsMessage(header,n7.GetId()); |
| 375 NS_TEST_EXPECT_MSG_EQ(rns2->IsRedundant(),false,"5: Redundant node not recogni
zed."); |
| 376 |
| 377 n8.SetX(1.0);n8.SetY(5.0);n8.SetR(1.0); |
| 378 rns2->UpdateNeighbor(n8,true); |
| 379 header.SetRange(n8.GetR()); |
| 380 rns2->ReceiveRnsMessage(header,n8.GetId()); |
| 381 rns2->UpdateNeighbor(n8,true); |
| 382 |
| 383 NS_TEST_EXPECT_MSG_EQ(rns2->IsRedundant(),true,"5: Redundant node not recogniz
ed."); |
| 384 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n1),true,"5: RRN not recognized."); |
| 385 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n2),true,"5: RRN not recognized."); |
| 386 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n3),true,"5: RRN not recognized."); |
| 387 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n4),true,"5: RRN not recognized."); |
| 388 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n5),false,"5: RRN recognized incorrectly."); |
| 389 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n6),true,"5: RRN not recognized."); |
| 390 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n7),true,"5: RRN not recognized."); |
| 391 NS_TEST_EXPECT_MSG_EQ(rns2->IsRrn(n8),true,"5: RRN not recognized."); |
| 392 |
| 393 } |
| 394 |
| 395 |
| 396 |
| 397 |
| 398 /* ********************* NonRedundancy Test Case *****************************/ |
| 399 class NonRedundancyTestCase : public TestCase |
| 400 { |
| 401 public: |
| 402 NonRedundancyTestCase(); |
| 403 ~NonRedundancyTestCase(); |
| 404 void DoRun(void); |
| 405 }; |
| 406 |
| 407 NonRedundancyTestCase::NonRedundancyTestCase() |
| 408 : TestCase("RNS Algorithm NonRedundancy Test") |
| 409 {} |
| 410 |
| 411 NonRedundancyTestCase::~NonRedundancyTestCase() |
| 412 {} |
| 413 |
| 414 void NonRedundancyTestCase::DoRun(void) |
| 415 { |
| 416 Ptr<rns::Rns<uint32_t> > rns1 = CreateObject<rns::Rns<uint32_t> >(0,0.0,0.0,5.
0); |
| 417 rns1->SetAttribute("Test", BooleanValue(true)); |
| 418 rns1->Start(NULL); |
| 419 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"1: Non-redundant node not rec
ognized."); |
| 420 //Situation 1 |
| 421 rns::Neighbor<uint32_t> n1(1,1.0,1.0,5.0); |
| 422 rns::Neighbor<uint32_t> n2(2,-1.0,4.0,5.0); |
| 423 rns::Neighbor<uint32_t> n3(3,-1.0,-4.0,5.0); |
| 424 rns::Neighbor<uint32_t> n4(4,4.0,-3.0,5.0); |
| 425 rns1->UpdateNeighbor(n1,true); |
| 426 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"1: Non-redundant node not rec
ognized."); |
| 427 rns1->UpdateNeighbor(n2,true); |
| 428 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"1: Non-redundant node not rec
ognized."); |
| 429 rns1->UpdateNeighbor(n3,true); |
| 430 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"1: Non-redundant node not rec
ognized."); |
| 431 rns1->UpdateNeighbor(n4,true); |
| 432 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"1: Non-redundant node not rec
ognized."); |
| 433 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),false,"1: RRN not recognized."); |
| 434 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),false,"1: RRN not recognized."); |
| 435 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n3),false,"1: RRN not recognized."); |
| 436 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n4),false,"1: RRN not recognized."); |
| 437 |
| 438 //Situation 2 |
| 439 n1.SetX(4);n1.SetY(3);n1.SetR(5); |
| 440 rns1->UpdateNeighbor(n1,true); |
| 441 n2.SetX(-2);n2.SetY(7);n2.SetR(4); |
| 442 rns1->UpdateNeighbor(n2,true); |
| 443 rns::RnsHeader<uint32_t> header(0x02,n2.GetR(),n2.GetId()); |
| 444 rns1->ReceiveRnsMessage(header,n2.GetId()); |
| 445 n3.SetX(-1);n3.SetY(-4); |
| 446 rns1->UpdateNeighbor(n3,true); |
| 447 n4.SetX(4);n4.SetY(-3); |
| 448 rns1->UpdateNeighbor(n4,true); |
| 449 rns::Neighbor<uint32_t> n5(5,-6.0,2.0,4.0); |
| 450 rns1->UpdateNeighbor(n5,true); |
| 451 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"2: Non-redundant node not rec
ognized."); |
| 452 } |
| 453 |
| 454 |
| 455 |
| 456 |
| 457 /* *********************** Mobile Test Case **********************************/ |
| 458 class MobileTestCase : public TestCase |
| 459 { |
| 460 public: |
| 461 MobileTestCase(); |
| 462 ~MobileTestCase(); |
| 463 void DoRun(void); |
| 464 }; |
| 465 |
| 466 MobileTestCase::MobileTestCase() |
| 467 : TestCase("RNS Algorithm Mobile Test") |
| 468 {} |
| 469 |
| 470 MobileTestCase::~MobileTestCase() |
| 471 {} |
| 472 |
| 473 void MobileTestCase::DoRun(void) |
| 474 { |
| 475 //Situation 5 |
| 476 //rns::RnsHeader<uint32_t> header(0x00,n8.GetR(),n8.GetId()); |
| 477 |
| 478 Ptr<rns::Rns<uint32_t> > rns1 = CreateObject<rns::Rns<uint32_t> >(0,0.0,0.0,5.
0); |
| 479 rns1->SetAttribute("Test", BooleanValue(true)); |
| 480 rns1->Start(NULL); |
| 481 //header.SetNewStatus(0x02); |
| 482 |
| 483 rns::Neighbor<uint32_t> n1(1,3.0,3.0,2.0); |
| 484 rns1->UpdateNeighbor(n1,true); |
| 485 rns::Neighbor<uint32_t> n2(2,-2.0,2.0,4.0); |
| 486 rns1->UpdateNeighbor(n2,true); |
| 487 rns::Neighbor<uint32_t> n3(3,-4.0,-2.0,3.0); |
| 488 rns1->UpdateNeighbor(n3,true); |
| 489 rns::Neighbor<uint32_t> n4(4,3.0,-1.0,5.0); |
| 490 rns1->UpdateNeighbor(n4,true); |
| 491 rns::Neighbor<uint32_t> n5(5,-6.0,1.0,2.0); |
| 492 rns1->UpdateNeighbor(n5,true); |
| 493 rns::Neighbor<uint32_t> n6(6,-1.0,-6.0,2.0); |
| 494 rns1->UpdateNeighbor(n6,true); |
| 495 rns::Neighbor<uint32_t> n7(7,-2.0,-4.0,1.5); |
| 496 rns1->UpdateNeighbor(n7,true); |
| 497 rns::Neighbor<uint32_t> n8(8,1.0,5.0,1.0); |
| 498 rns1->UpdateNeighbor(n8,true); |
| 499 |
| 500 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"0: Redundant node not recogniz
ed."); |
| 501 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),true,"0: RRN not recognized."); |
| 502 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),true,"0: RRN not recognized."); |
| 503 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n3),true,"0: RRN not recognized."); |
| 504 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n4),true,"0: RRN not recognized."); |
| 505 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n5),false,"0: RRN recognized incorrectly."); |
| 506 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n6),true,"0: RRN not recognized."); |
| 507 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n7),true,"0: RRN not recognized."); |
| 508 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n8),true,"0: RRN not recognized."); |
| 509 |
| 510 //Move node 5 around |
| 511 n5.SetX(7.0);n5.SetY(-1.0); |
| 512 rns1->UpdateNeighbor(n5,true); |
| 513 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"0: Moving N5 around changes th
e status."); |
| 514 |
| 515 n5.SetX(1.0);n5.SetY(1.0); |
| 516 rns1->UpdateNeighbor(n5,true); |
| 517 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"0: Moving N5 around changes t
he status."); |
| 518 |
| 519 //Move node 5 back to its origin |
| 520 n5.SetX(-6.0);n5.SetY(1.0); |
| 521 rns1->UpdateNeighbor(n5,true); |
| 522 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"0: Moving N5 around changes th
e status."); |
| 523 |
| 524 //Situation 1 |
| 525 n8.SetX(2.0);n8.SetY(6.0); |
| 526 rns1->UpdateNeighbor(n8,true); |
| 527 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"1: Moving N8 away doesn't cha
nge the status."); |
| 528 |
| 529 n8.SetX(1.0);n8.SetY(5.0); |
| 530 rns1->UpdateNeighbor(n8,true); |
| 531 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"1: Moving N8 back doesn't chan
ge the status."); |
| 532 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n8),true,"1: RRN not recognized."); |
| 533 |
| 534 n8.SetX(2.0);n8.SetY(6.0); |
| 535 rns1->UpdateNeighbor(n8,true); |
| 536 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"1: Moving N8 away doesn't cha
nge the status."); |
| 537 |
| 538 //Situation 2 |
| 539 n1.SetX(2.0);n1.SetY(4.0); |
| 540 rns1->UpdateNeighbor(n1,true); |
| 541 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"2: Moving N1 doesn't change th
e status."); |
| 542 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),true,"2: RRN not recognized."); |
| 543 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n8),false,"2: Node recoginzed as RRN."); |
| 544 |
| 545 n1.SetX(3.0);n1.SetY(3.0); |
| 546 rns1->UpdateNeighbor(n1,true); |
| 547 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"2: Moving N1 doesn't change t
he status."); |
| 548 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),false,"2: RRN not recognized."); |
| 549 |
| 550 //Situation 3 |
| 551 n5.SetX(2.0);n5.SetY(4.0); |
| 552 rns1->UpdateNeighbor(n5,true); |
| 553 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"3: Moving N5 changes the statu
s."); |
| 554 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n5),true,"3: RRN not recognized."); |
| 555 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),false,"3: RRN not recognized."); |
| 556 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n8),false,"3: Node recoginzed as RRN"); |
| 557 |
| 558 //Situation 4 |
| 559 n8.SetX(1.0);n8.SetY(-6.0); |
| 560 rns1->UpdateNeighbor(n8,true); |
| 561 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),true,"4: Moving N8 changes the statu
s."); |
| 562 rns1->SetX(0.5);rns1->SetY(-0.5); |
| 563 NS_TEST_EXPECT_MSG_EQ(rns1->AmIRedundant(),true,"4: Moving the central node do
esn't change the status."); |
| 564 |
| 565 //Situation 5 |
| 566 rns1->SetX(2.0);rns1->SetY(-2.0); |
| 567 n4.SetX(2.999); //Fake n4 movement because No mobility is aggreg
ated... |
| 568 rns1->UpdateNeighbor(n4,true); //...and we need to force the algorithm to
run. |
| 569 NS_TEST_EXPECT_MSG_EQ(rns1->IsRedundant(),false,"5: Moving the central node ch
anges the status."); |
| 570 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n1),false,"0: RRN not recognized."); |
| 571 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n2),false,"0: RRN not recognized."); |
| 572 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n3),false,"0: RRN not recognized."); |
| 573 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n4),false,"0: RRN not recognized."); |
| 574 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n5),false,"0: RRN recognized incorrectly."); |
| 575 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n6),false,"0: RRN not recognized."); |
| 576 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n7),false,"0: RRN not recognized."); |
| 577 NS_TEST_EXPECT_MSG_EQ(rns1->IsRrn(n8),false,"0: RRN not recognized."); |
| 578 } |
| 579 |
| 580 |
| 581 |
| 582 |
| 583 |
| 584 class RnsAlgorithmTestSuite : public TestSuite |
| 585 { |
| 586 public: |
| 587 RnsAlgorithmTestSuite () : TestSuite ("rns-algorithm-tests", UNIT) |
| 588 { |
| 589 AddTestCase (new SimpleTestCase); |
| 590 AddTestCase (new RedundancyTestCase); |
| 591 AddTestCase (new NonRedundancyTestCase); |
| 592 AddTestCase (new MobileTestCase); |
| 593 } |
| 594 } g_rnsAlgorithmTestSuite; |
| 595 |
| 596 } // namespace ns3 |
OLD | NEW |