|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2008 Irene Ruengeler 00003 // Copyright (C) 2010 Thomas Dreibholz 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 00020 #include "SCTPMessage.h" 00021 #include "SCTPAssociation.h" 00022 00023 00024 Register_Class(SCTPMessage); 00025 00026 SCTPMessage& SCTPMessage::operator=(const SCTPMessage& other) 00027 { 00028 SCTPMessage_Base::operator=(other); 00029 00030 this->setBitLength(SCTP_COMMON_HEADER*8); 00031 this->setTag(other.getTag()); 00032 for (std::list<cPacket*>::const_iterator i=other.chunkList.begin(); i!=other.chunkList.end(); ++i) 00033 addChunk((cPacket *)(*i)->dup()); 00034 00035 return *this; 00036 } 00037 00038 SCTPMessage::~SCTPMessage() 00039 { 00040 SCTPChunk* chunk; 00041 if (this->getChunksArraySize()>0) 00042 for (uint32 i=0; i < this->getChunksArraySize(); i++) 00043 { 00044 chunk = (SCTPChunk*)this->getChunks(i); 00045 drop(chunk); 00046 delete chunk; 00047 } 00048 } 00049 00050 void SCTPMessage::setChunksArraySize(uint32 size) 00051 { 00052 throw new cException(this, "setChunkArraySize() not supported, use addChunk()"); 00053 } 00054 00055 uint32 SCTPMessage::getChunksArraySize() const 00056 { 00057 return chunkList.size(); 00058 } 00059 00060 cPacketPtr& SCTPMessage::getChunks(uint32 k) 00061 { 00062 std::list<cPacket*>::iterator i = chunkList.begin(); 00063 while (k>0 && i!=chunkList.end()) 00064 (++i, --k); 00065 return *i; 00066 } 00067 00068 void SCTPMessage::setChunks(uint32 k, const cPacketPtr& chunks_var) 00069 { 00070 throw new cException(this, "setChunks() not supported, use addChunk()"); 00071 } 00072 00073 00074 void SCTPMessage::addChunk(cPacket* msg) 00075 { 00076 char str[256]; 00077 take(msg); 00078 if (this->chunkList.size()<9) 00079 { 00080 strcpy(str, this->getName()); 00081 snprintf(str, sizeof(str), "%s %s",this->getName(), msg->getName()); 00082 this->setName(str); 00083 } 00084 this->setBitLength(this->getBitLength()+ADD_PADDING(msg->getBitLength()/8)*8); 00085 chunkList.push_back(msg); 00086 } 00087 00088 cPacket *SCTPMessage::removeChunk() 00089 { 00090 if (chunkList.empty()) 00091 return NULL; 00092 00093 cPacket *msg = chunkList.front(); 00094 chunkList.pop_front(); 00095 drop(msg); 00096 this->setBitLength(this->getBitLength()-ADD_PADDING(msg->getBitLength()/8)*8); 00097 return msg; 00098 } 00099 00100 cPacket *SCTPMessage::removeLastChunk() 00101 { 00102 if (chunkList.empty()) 00103 return NULL; 00104 00105 cPacket *msg = chunkList.back(); 00106 chunkList.pop_back(); 00107 drop(msg); 00108 this->setBitLength(this->getBitLength()-ADD_PADDING(msg->getBitLength()/8)*8); 00109 return msg; 00110 } 00111 00112 cPacket *SCTPMessage::peekFirstChunk() 00113 { 00114 if (chunkList.empty()) 00115 return NULL; 00116 00117 cPacket *msg = chunkList.front(); 00118 return msg; 00119 } 00120 00121 cPacket *SCTPMessage::peekLastChunk() 00122 { 00123 if (chunkList.empty()) 00124 return NULL; 00125 00126 cPacket *msg = chunkList.back(); 00127 return msg; 00128 } 00129 00130 00131 00132 00133 Register_Class(SCTPErrorChunk); 00134 00135 SCTPErrorChunk& SCTPErrorChunk::operator=(const SCTPErrorChunk& other) 00136 { 00137 SCTPErrorChunk_Base::operator=(other); 00138 00139 this->setBitLength(4*8); 00140 for (std::list<cPacket*>::const_iterator i=other.parameterList.begin(); i!=other.parameterList.end(); ++i) 00141 addParameters((cPacket *)(*i)->dup()); 00142 00143 return *this; 00144 } 00145 00146 void SCTPErrorChunk::setParametersArraySize(uint32 size) 00147 { 00148 throw new cException(this, "setParametersArraySize() not supported, use addParameter()"); 00149 } 00150 00151 uint32 SCTPErrorChunk::getParametersArraySize() const 00152 { 00153 return parameterList.size(); 00154 } 00155 00156 cPacketPtr& SCTPErrorChunk::getParameters(uint32 k) 00157 { 00158 std::list<cPacket*>::iterator i = parameterList.begin(); 00159 while (k>0 && i!=parameterList.end()) 00160 (++i, --k); 00161 return *i; 00162 } 00163 00164 void SCTPErrorChunk::setParameters(uint32 k, const cPacketPtr& chunks_var) 00165 { 00166 throw new cException(this, "setParameter() not supported, use addParameter()"); 00167 } 00168 00169 void SCTPErrorChunk::addParameters(cPacket* msg) 00170 { 00171 take(msg); 00172 00173 this->setBitLength(this->getBitLength()+ADD_PADDING(msg->getBitLength())); 00174 parameterList.push_back(msg); 00175 } 00176 00177 cPacket *SCTPErrorChunk::removeParameter() 00178 { 00179 if (parameterList.empty()) 00180 return NULL; 00181 00182 cPacket *msg = parameterList.front(); 00183 parameterList.pop_front(); 00184 drop(msg); 00185 this->setBitLength(this->getBitLength()-ADD_PADDING(msg->getBitLength()/8)*8); 00186 return msg; 00187 }