OverSim
RealworldConnector.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #ifndef _REALWORLDCONNECTOR_H_
25 #define _REALWORLDCONNECTOR_H_
26 
27 #include "realtimescheduler.h"
28 #include <omnetpp.h>
29 #include "INETDefs.h"
30 #include "PacketParser.h"
31 
39 inline u_short cksum(uint16_t *buf, int nbytes)
40 {
41  register unsigned long sum;
42  u_short oddbyte;
43 
44  sum = 0;
45  while (nbytes > 1) {
46  sum += *buf++;
47  nbytes -= 2;
48  }
49 
50  if (nbytes == 1) {
51  oddbyte = 0;
52  *((u_char *) &oddbyte) = *(u_char *) buf;
53  sum += oddbyte;
54  }
55 
56  sum = (sum >> 16) + (sum & 0xffff);
57  sum += (sum >> 16);
58 
59  return ~sum;
60 }
61 
66 class INET_API RealworldConnector : public cSimpleModule
67 {
68 protected:
69 
71  unsigned int mtu;
72 #define BUFFERZITE mtu + 4 // 4 bytes for packet information
73 
74  // statistics
75  long numSent;
77  long numRcvdOK;
79 
80  cMessage* packetNotification; // used by TunOutScheduler to notify about new packets
81  PacketBuffer packetBuffer; // received packets are stored here
84 
89  virtual void transmitToNetwork(cPacket *msg);
90  virtual void updateDisplayString();
91 
101  virtual char* encapsulate(cPacket *msg,
102  unsigned int* length,
103  sockaddr** addr,
104  socklen_t* addrlen) = 0;
105 
115  virtual cPacket *decapsulate(char* buf,
116  uint32_t length,
117  sockaddr* addr,
118  socklen_t addrlen) = 0;
119 
124  virtual bool isApp() {return false;}
125 
126 public:
128  virtual ~RealworldConnector();
129 
130  virtual int numInitStages() const
131  {
132  return 4;
133  }
134 
139  virtual void initialize(int stage);
140 
144  virtual void handleMessage(cMessage *msg);
145 };
146 
147 #endif
148 
149