srm-state.h
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:5k
源码类别:

通讯编程

开发平台:

Visual C++

  1. /*
  2.  * srm-state.h
  3.  * Copyright (C) 1997 by the University of Southern California
  4.  * $Id: srm-state.h,v 1.8 2005/08/25 18:58:08 johnh Exp $
  5.  *
  6.  * This program is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU General Public License,
  8.  * version 2, as published by the Free Software Foundation.
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  * GNU General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License along
  16.  * with this program; if not, write to the Free Software Foundation, Inc.,
  17.  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  18.  *
  19.  *
  20.  * The copyright of this module includes the following
  21.  * linking-with-specific-other-licenses addition:
  22.  *
  23.  * In addition, as a special exception, the copyright holders of
  24.  * this module give you permission to combine (via static or
  25.  * dynamic linking) this module with free software programs or
  26.  * libraries that are released under the GNU LGPL and with code
  27.  * included in the standard release of ns-2 under the Apache 2.0
  28.  * license or under otherwise-compatible licenses with advertising
  29.  * requirements (or modified versions of such code, with unchanged
  30.  * license).  You may copy and distribute such a system following the
  31.  * terms of the GNU GPL for this module and the licenses of the
  32.  * other code concerned, provided that you include the source code of
  33.  * that other code when and as the GNU GPL requires distribution of
  34.  * source code.
  35.  *
  36.  * Note that people who make modified versions of this module
  37.  * are not obligated to grant this special exception for their
  38.  * modified versions; it is their choice whether to do so.  The GNU
  39.  * General Public License gives permission to release a modified
  40.  * version without this exception; this exception also makes it
  41.  * possible to release a modified version which carries forward this
  42.  * exception.
  43.  *
  44.  */
  45. //
  46. // Author: Kannan Varadhan <kannan@isi.edu>
  47. // Version Date: Mon Jun 30 15:51:33 PDT 1997
  48. //
  49. // @(#) $Header: /cvsroot/nsnam/ns-2/mcast/srm-state.h,v 1.8 2005/08/25 18:58:08 johnh Exp $ (USC/ISI)
  50. //
  51. #ifndef ns_srm_state_h
  52. #define ns_srm_state_h
  53. #include <assert.h>
  54. class SRMinfo {
  55. public:
  56. SRMinfo* next_;
  57. int sender_;
  58. /* Session messages */
  59. int lsess_;   /* # of last session msg received */
  60. int sendTime_;   /* Time sess. msg. # sent */
  61. int recvTime_;   /* Time sess. msg. # received */
  62. double distance_;
  63.         /* Added for ssm, later check if can do for a derived class */
  64.         /* Can do better with space for these flags */
  65.         int     lglbsess_;
  66.         int     llocsess_;
  67.         int     lrepsess_;
  68.         int     repid_;
  69.         int     senderFlag_;
  70.         int     scopeFlag_;
  71. #define ACTIVE 1
  72. #define INACTIVE 0
  73.         int     activeFlag_;
  74. #define SELF_DISTANCE   1
  75. #define REP_DISTANCE    2       
  76. #define NO_DISTANCE     0
  77.         int     distanceFlag_;
  78. /* Data messages */
  79. int ldata_;   /* # of last data msg sent */
  80. protected:
  81. char *received_;   /* Bit vector of msgs received */
  82. int recvmax_;
  83. #define BITVEC_SIZE_DEFAULT 256   // for (256 * 8) = 2K messages
  84. void resize(int id) {
  85. if (! received_) {
  86. received_ = new char[BITVEC_SIZE_DEFAULT];
  87. recvmax_ = BITVEC_SIZE_DEFAULT * sizeof(char);
  88. (void) memset(received_, '', BITVEC_SIZE_DEFAULT);
  89. }
  90. if (recvmax_ <= id) {
  91. int osize, nsize;
  92. nsize = osize = recvmax_;
  93. while (nsize <= id)
  94. nsize *= 2;
  95. osize /= sizeof(char);
  96. nsize /= sizeof(char);
  97. char* nvec = new char[nsize];
  98. (void) memcpy(nvec, received_, osize);
  99. (void) memset(nvec + osize, '', osize);
  100. delete[] received_;
  101. received_ = nvec;
  102. recvmax_ = nsize;
  103. }
  104. }
  105. public:
  106. SRMinfo(int sender) : next_(0), sender_(sender),
  107. lsess_(-1), sendTime_(0), recvTime_(0), distance_(1.0),
  108. senderFlag_(0), activeFlag_(ACTIVE), distanceFlag_(NO_DISTANCE),
  109. ldata_(-1), received_(0), recvmax_(-1) { 
  110.                     lglbsess_ = -1;
  111.                     llocsess_ = -1;
  112.                     lrepsess_ = -1;
  113.                    }
  114. ~SRMinfo() { delete[] received_; }
  115. char ifReceived(int id) {
  116. assert(id >= 0);
  117. if (id >= recvmax_)
  118. resize(id);
  119. return (received_[id / 8] & (1 << (id % 8)));
  120. }
  121. char setReceived(int id) {
  122. int obit = ifReceived(id);
  123. received_[id / 8] |= (1 << (id % 8));
  124. return obit;
  125. }
  126. char resetReceived(int id) {
  127. int obit = ifReceived(id);
  128. received_[id / 8] &= ~(1 << (id % 8));
  129. return obit;
  130. }
  131. };
  132. #endif /* ns_srm_state_h */