RealworldConnector.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
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, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00024 #ifndef _REALWORLDCONNECTOR_H_
00025 #define _REALWORLDCONNECTOR_H_
00026 
00027 #include <omnetpp.h>
00028 #include "INETDefs.h"
00029 #include "realtimescheduler.h"
00030 #include "PacketParser.h"
00031 
00039 inline u_short cksum(uint16_t *buf, int nbytes)
00040 {
00041     register unsigned long  sum;
00042     u_short                 oddbyte;
00043 
00044     sum = 0;
00045     while (nbytes > 1) {
00046         sum += *buf++;
00047         nbytes -= 2;
00048     }
00049 
00050     if (nbytes == 1) {
00051         oddbyte = 0;
00052         *((u_char *) &oddbyte) = *(u_char *) buf;
00053         sum += oddbyte;
00054     }
00055 
00056     sum = (sum >> 16) + (sum & 0xffff);
00057     sum += (sum >> 16);
00058 
00059     return ~sum;
00060 }
00061 
00066 class INET_API RealworldConnector : public cSimpleModule
00067 {
00068 protected:
00069 
00070     int gateIndexNetwOut;
00071     unsigned int mtu;
00072 #define BUFFERZITE mtu + 4 // 4 bytes for packet information
00073 
00074     // statistics
00075     long numSent;
00076     long numSendError;
00077     long numRcvdOK;
00078     long numRcvError;
00079 
00080     cMessage* packetNotification; // used by TunOutScheduler to notify about new packets
00081     RealtimeScheduler::PacketBuffer packetBuffer; // received packets are stored here
00082     RealtimeScheduler* scheduler;
00083     PacketParser* parser;
00084 
00089     virtual void transmitToNetwork(cPacket *msg);
00090     virtual void updateDisplayString();
00091 
00101     virtual char* encapsulate(cPacket *msg,
00102                               unsigned int* length,
00103                               sockaddr** addr,
00104                               socklen_t* addrlen) = 0;
00105 
00115     virtual cPacket *decapsulate(char* buf,
00116                                   uint32_t length,
00117                                   sockaddr* addr,
00118                                   socklen_t addrlen) = 0;
00119 
00124     virtual bool isApp() {return false;}
00125 
00126 public:
00127     RealworldConnector();
00128     virtual ~RealworldConnector();
00129 
00130     virtual int numInitStages() const
00131     {
00132         return 4;
00133     }
00134 
00139     virtual void initialize(int stage);
00140 
00144     virtual void handleMessage(cMessage *msg);
00145 };
00146 
00147 #endif
00148 
00149 
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3