|
INET Framework for OMNeT++/OMNEST
|
00001 // 00002 // Copyright (C) 2008 Irene Ruengeler 00003 // 00004 // This program is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU General Public License 00006 // as published by the Free Software Foundation; either version 2 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 00019 #ifndef __SCTPSOCKET_H 00020 #define __SCTPSOCKET_H 00021 00022 00023 #include <omnetpp.h> 00024 #include "SCTPCommand_m.h" 00025 #include "IPvXAddress.h" 00026 #include "RoutingTable.h" 00027 00028 00029 class SCTPStatusInfo; 00030 class SCTP; 00031 00032 00033 00034 00035 class INET_API SCTPSocket 00036 { 00037 public: 00046 class CallbackInterface 00047 { 00048 public: 00049 virtual ~CallbackInterface() {} 00050 virtual void socketDataArrived(int assocId, void *yourPtr, cPacket *msg, bool urgent) = 0; 00051 virtual void socketDataNotificationArrived(int assocId, void *yourPtr, cPacket *msg) = 0; 00052 virtual void socketEstablished(int assocId, void *yourPtr, uint64 buffer) {} 00053 virtual void socketPeerClosed(int assocId, void *yourPtr) {} 00054 virtual void socketClosed(int assocId, void *yourPtr) {} 00055 virtual void socketFailure(int assocId, void *yourPtr, int code) {} 00056 virtual void socketStatusArrived(int assocId, void *yourPtr, SCTPStatusInfo *status){}// {delete status;} 00057 virtual void sendRequestArrived() {} 00058 virtual void shutdownReceivedArrived(int connId) {} 00059 virtual void sendqueueFullArrived(int connId) {} 00060 virtual void sendqueueAbatedArrived(int connId, uint64 buffer) {} 00061 virtual void addressAddedArrived(int assocId, IPvXAddress localAddr, IPvXAddress remoteAddr) {} 00062 }; 00063 00064 enum State {NOT_BOUND, CLOSED, LISTENING, CONNECTING, CONNECTED, PEER_CLOSED, LOCALLY_CLOSED, SOCKERROR}; 00065 00066 protected: 00067 int assocId; 00068 int sockId; 00069 int sockstate; 00070 bool oneToOne; 00071 00072 IPvXAddress localAddr; 00073 AddressVector localAddresses; 00074 00075 int localPrt; 00076 IPvXAddress remoteAddr; 00077 AddressVector remoteAddresses; 00078 int remotePrt; 00079 int fsmStatus; 00080 int inboundStreams; 00081 int outboundStreams; 00082 int lastStream; 00083 00084 00085 CallbackInterface *cb; 00086 void *yourPtr; 00087 00088 protected: 00089 void sendToSCTP(cPacket *msg); 00090 00091 public: 00092 cGate *gateToSctp; 00097 // SCTPSocket(); 00098 SCTPSocket(bool type = true); 00099 00105 SCTPSocket(cPacket *msg); 00106 00110 ~SCTPSocket(); 00111 00117 int getConnectionId() const {return assocId;} 00118 00124 int getState() {return sockstate;} 00125 00129 static const char *stateName(int state); 00130 00133 // IPvXAddress localAddress() {return localAddr;} 00134 AddressVector getLocalAddresses() {return localAddresses;} 00135 int getLocalPort() {return localPrt;} 00136 // IPvXAddress remoteAddress() {return remoteAddr;} 00137 AddressVector getRemoteAddresses() {return remoteAddresses;} 00138 int getRemotePort() {return remotePrt;} 00139 IPvXAddress getRemoteAddr() {return remoteAddr;} 00141 00144 00149 void setOutputGate(cGate *toSctp) {gateToSctp = toSctp;}; 00150 void setOutboundStreams(int streams) {outboundStreams = streams;}; 00151 void setInboundStreams(int streams) {inboundStreams = streams;}; 00152 int getOutboundStreams() {return outboundStreams;}; 00153 int getLastStream() {return lastStream;}; 00157 void bind(int localPort); 00158 00163 void bind(IPvXAddress localAddr, int localPort); 00164 00165 void bindx(AddressVector localAddr, int localPort); 00166 00167 void addAddress(IPvXAddress addr); 00168 // 00169 // TBD add support for these options too! 00170 // string sendQueueClass; 00171 // string receiveQueueClass; 00172 // string sctpAlgorithmClass; 00173 // 00174 00182 void listen(bool fork=false, uint32 requests=0, uint32 messagesToPush=0); 00186 void connect(IPvXAddress remoteAddress, int32 remotePort, uint32 numRequests); 00187 00188 void connectx(AddressVector remoteAddresses, int32 remotePort, uint32 numRequests=0); 00192 void send(cPacket *msg, bool last=true, bool primary=true); 00193 00194 void sendNotification(cPacket *msg); 00195 void sendRequest(cPacket *msg); 00202 void close(); 00203 00207 void abort(); 00208 void shutdown(); 00216 void requestStatus(); 00218 00226 bool belongsToSocket(cPacket *msg); 00227 00233 static bool belongsToAnySCTPSocket(cPacket *msg); 00234 00256 void setCallbackObject(CallbackInterface *cb, void *yourPtr=NULL); 00257 00274 void processMessage(cPacket *msg); 00276 00277 00278 void setState(int state) {sockstate = state; }; 00279 }; 00280 00281 #endif 00282 00283