PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/OmnetInetManet/inetmanet-baseuco/src/undertest/hip/base/RvsHIP.cc

https://gitlab.com/Cased93/ConNetFull
C++ | 126 lines | 81 code | 9 blank | 36 comment | 9 complexity | 6ec00ad384fd43cbdc194a1b1238a114 MD5 | raw file
  1. //*********************************************************************************
  2. // File: RvsHIP.cc
  3. //
  4. // Authors: Laszlo Tamas Zeke, Levente Mihalyi, Laszlo Bokor
  5. //
  6. // Copyright: (C) 2008-2009 BME-HT (Department of Telecommunications,
  7. // Budapest University of Technology and Economics), Budapest, Hungary
  8. //
  9. // This program is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU General Public License
  11. // as published by the Free Software Foundation; either version 2
  12. // of the License, or (at your option) any later version.
  13. //
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. // GNU General Public License for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License
  20. // along with this program; if not, write to the Free Software
  21. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. //
  23. //**********************************************************************************
  24. // Part of: HIPSim++ Host Identity Protocol Simulation Framework developed by BME-HT
  25. //**********************************************************************************
  26. #include "RvsHIP.h"
  27. #include "IPv6ControlInfo.h"
  28. #include "HipMessages_m.h"
  29. #include "IPv6Datagram.h"
  30. Define_Module(RvsHIP)
  31. ;
  32. RvsHIP::RvsHIP()
  33. {
  34. }
  35. RvsHIP::~RvsHIP()
  36. {
  37. }
  38. void RvsHIP::specInitialize()
  39. {
  40. _isRvs = true;
  41. ownHIT.set(this->par("OWN_HIT"));
  42. }
  43. // Handles incoming I1 messages
  44. void RvsHIP::handleMsgFromNetwork(cMessage *msg)
  45. {
  46. if (dynamic_cast<HIPHeaderMessage *>(msg) != NULL)
  47. {
  48. HIPHeaderMessage *hipHeader = check_and_cast<HIPHeaderMessage *>(msg);
  49. //HIP msg
  50. if (hipHeader != NULL)
  51. {
  52. IPv6ControlInfo *networkControlInfo = check_and_cast<IPv6ControlInfo*>(msg->removeControlInfo());
  53. //dest is RVS's HIT, it's a registration
  54. ev<< "destHIT ? ownHIT " << hipHeader->getDestHIT() << " ? " << ownHIT << endl;
  55. if (hipHeader->getDestHIT() == ownHIT)
  56. {
  57. ev<< "true" << endl;
  58. int fsmId = -1;
  59. if(hitToIpMap.find(hipHeader->getSrcHIT()) != hitToIpMap.end())
  60. fsmId = hitToIpMap.find(hipHeader->getSrcHIT())->second->fsmId;
  61. if(fsmId < 0)
  62. {
  63. //create new daemon and fw to it
  64. ev << "RVS received I1" << endl;
  65. msg->setControlInfo(networkControlInfo);
  66. sendDirect(msg, createStateMachine(networkControlInfo->getSrcAddr(), hipHeader->getSrcHIT()), "remoteIn");
  67. }
  68. else
  69. {
  70. //spi is known, find daemon and fw to it
  71. ev << "RVS received SPI (possible UPDATE, BE) " << hipHeader->getLocator(1).locatorESP_SPI << endl;
  72. msg->setControlInfo(networkControlInfo);
  73. sendDirect(msg, findStateMachine(fsmId),"remoteIn");
  74. }
  75. }
  76. //not registration, somebody's trying to reach destHIT, fw I1 to it
  77. else
  78. {
  79. hitToIpMapIt = hitToIpMap.find(hipHeader->getDestHIT());
  80. alterHipPacketAndSend(hipHeader, networkControlInfo->getDestAddr(), hitToIpMapIt->second->addr.front(), networkControlInfo->getSrcAddr());
  81. }
  82. }
  83. else
  84. {
  85. delete msg;
  86. }
  87. }
  88. }
  89. // Forwards I1 messages to the registered host's IP address
  90. void RvsHIP::alterHipPacketAndSend(HIPHeaderMessage* hipHead, IPv6Address &rvsIP, IPv6Address &destIP,
  91. IPv6Address &fromIP)
  92. {
  93. //create new dest locator
  94. HipLocator *destLoc = new HipLocator();
  95. destLoc->locatorESP_SPI = -1;
  96. destLoc->locatorIPv6addr = destIP;
  97. hipHead->setLocator(1, *destLoc);
  98. //set HIPHeader's FROM field
  99. hipHead->setFrom_i(fromIP);
  100. hipHead->setRvs_mac(1);
  101. IPv6ControlInfo *networkControlInfo = new IPv6ControlInfo();
  102. networkControlInfo->setDestAddr(destIP);
  103. networkControlInfo->setSrcAddr(rvsIP);
  104. networkControlInfo->setProtocol(6);
  105. hipHead->setControlInfo(networkControlInfo);
  106. send(hipHead, "tcp6Out");
  107. }
  108. // Overridden, RVS doesn't functions as a host
  109. void RvsHIP::handleMsgFromTransport(cMessage *msg)
  110. {
  111. delete msg;
  112. }
  113. // And hopefully doesn't changes IP addresses either
  114. void RvsHIP::handleAddressChange()
  115. {
  116. return;
  117. }