ExtInterface Class Reference

#include <ExtInterface.h>

List of all members.

Public Member Functions

virtual int32 numInitStages () const
virtual void initialize (int stage)
virtual void handleMessage (cMessage *msg)
virtual void finish ()

Protected Member Functions

InterfaceEntryregisterInterface ()
void displayBusy ()
void displayIdle ()
void updateDisplayString ()

Protected Attributes

bool connected
uint8 buffer [1<< 16]
const char * device
InterfaceEntryinterfaceEntry
uint64 numSent
uint64 numRcvd
uint64 numDropped
cSocketRTSchedulerrtScheduler

Private Attributes

const char * tag_color
const char * tag_width


Member Function Documentation

InterfaceEntry * ExtInterface::registerInterface (  )  [protected]

Referenced by initialize().

00084 {
00085         InterfaceEntry *e = new InterfaceEntry();
00086 
00087         // interface name: our module name without special characters ([])
00088         char *interfaceName = new char[strlen(getFullName())+1];
00089         char *d=interfaceName;
00090         for (const char *s=getFullName(); *s; s++)
00091         if (isalnum(*s))
00092                 *d++ = *s;
00093         *d = '\0';
00094         e->setName(interfaceName);
00095         delete [] interfaceName;
00096 
00097         e->setMtu(par("mtu"));
00098         e->setMulticast(true);
00099         e->setPointToPoint(true);
00100         IInterfaceTable *ift = InterfaceTableAccess().get();
00101         ift->addInterface(e, this);
00102         return e;
00103 }

void ExtInterface::displayBusy (  )  [protected]

00177 {
00178         getDisplayString().setTagArg("i",1, "yellow");
00179         gate("physOut")->getDisplayString().setTagArg("o",0,"yellow");
00180         gate("physOut")->getDisplayString().setTagArg("o",1,"3");
00181 }

void ExtInterface::displayIdle (  )  [protected]

00184 {
00185         getDisplayString().setTagArg("i",1,"");
00186         gate("physOut")->getDisplayString().setTagArg("o",0,"black");
00187         gate("physOut")->getDisplayString().setTagArg("o",1,"1");
00188 }

void ExtInterface::updateDisplayString (  )  [protected]

Referenced by handleMessage(), and initialize().

00191 {
00192         char buf[80];
00193         if (ev.disable_tracing)
00194                 getDisplayString().setTagArg("t",0,"");
00195         if(connected)
00196                 sprintf(buf, "pcap device: %s\nrcv:%llu snt:%llu", device, numRcvd, numSent);
00197         else
00198                 sprintf(buf, "not connected");
00199         getDisplayString().setTagArg("t", 0, buf);
00200 }

virtual int32 ExtInterface::numInitStages (  )  const [inline, virtual]

00068 {return 4;}

void ExtInterface::initialize ( int  stage  )  [virtual]

00035 {
00036         // subscribe at scheduler for external messages
00037         if(stage == 0)
00038         {
00039                 if(dynamic_cast<cSocketRTScheduler *>(simulation.getScheduler()) != NULL)
00040                 {
00041                         rtScheduler = check_and_cast<cSocketRTScheduler *>(simulation.getScheduler());
00042                         //device = ev.config()->getAsString("Capture", "device", "lo0");
00043                         device = par("device");
00044                         //const char *filter = ev.config()->getAsString("Capture", "filter-string", "ip");
00045                         const char *filter = par("filterString");
00046                         rtScheduler->setInterfaceModule(this, device, filter);
00047                         connected = true;
00048                 }
00049                 else
00050                 {
00051                         // this simulation run works without external interface..
00052                         connected = false;
00053                 }
00054         }
00055 
00056         if (stage == 3)
00057         {
00058                 // update display string when addresses have been autoconfigured etc.
00059                 updateDisplayString();
00060                 return;
00061         }
00062 
00063         // all initialization is done in the first stage
00064         if (stage != 0)
00065                 return;
00066 
00067         numSent = numRcvd = numDropped = 0;
00068         WATCH(numSent);
00069         WATCH(numRcvd);
00070         WATCH(numDropped);
00071 
00072     // register our interface entry in RoutingTable
00073         interfaceEntry = registerInterface();
00074 
00075         // if not connected, make it gray
00076         if (ev.isGUI() && !connected)
00077         {
00078                 getDisplayString().setTagArg("i",1,"#707070");
00079                 getDisplayString().setTagArg("i",2,"100");
00080         }
00081 }

void ExtInterface::handleMessage ( cMessage *  msg  )  [virtual]

00106 {
00107 
00108         if(dynamic_cast<ExtFrame *>(msg) != NULL)
00109         {
00110                 // incoming real packet from wire (captured by pcap)
00111                 uint32 packetLength;
00112                 ExtFrame *rawPacket = check_and_cast<ExtFrame *>(msg);
00113 
00114                 packetLength = rawPacket->getDataArraySize();
00115                 for(uint32 i=0; i < packetLength; i++)
00116                         buffer[i] = rawPacket->getData(i);
00117 
00118                 IPDatagram *ipPacket = new IPDatagram("ip-from-wire");
00119                 IPSerializer().parse(buffer, packetLength, (IPDatagram *)ipPacket);
00120                 EV << "Delivering an IP packet from "
00121                    << ipPacket->getSrcAddress()
00122                    << " to "
00123                    << ipPacket->getDestAddress()
00124                    << " and length of"
00125                    << ipPacket->getByteLength()
00126                    << " bytes to IP layer.\n";
00127                 send(ipPacket, "netwOut");
00128                 numRcvd++;
00129         }
00130         else
00131         {
00132                 memset(buffer, 0, 1<<16);
00133                 IPDatagram *ipPacket = check_and_cast<IPDatagram *>(msg);
00134 
00135                 if ((ipPacket->getTransportProtocol() != IP_PROT_ICMP) &&
00136                     (ipPacket->getTransportProtocol() != IPPROTO_SCTP) &&
00137                     (ipPacket->getTransportProtocol() != IPPROTO_UDP))
00138                 {
00139                         EV << "Can not send packet. Protocol " << ipPacket->getTransportProtocol() << " is not supported.\n";
00140                         numDropped++;
00141                         delete(msg);
00142                         return;
00143                 }
00144 
00145                 if(connected)
00146                 {
00147                         struct sockaddr_in addr;
00148                         addr.sin_family      = AF_INET;
00149 #if !defined(linux) && !defined(_WIN32)
00150                         addr.sin_len         = sizeof(struct sockaddr_in);
00151 #endif
00152                         addr.sin_port        = 0;
00153                         addr.sin_addr.s_addr = htonl(ipPacket->getDestAddress().getInt());
00154                         int32 packetLength = IPSerializer().serialize(ipPacket,buffer, sizeof(buffer));
00155                         EV << "Delivering an IP packet from "
00156                            << ipPacket->getSrcAddress()
00157                            << " to "
00158                            << ipPacket->getDestAddress()
00159                            << " and length of "
00160                            << ipPacket->getByteLength()
00161                            << " bytes to link layer.\n";
00162                         rtScheduler->sendBytes(buffer, packetLength, (struct sockaddr *) &addr, sizeof(struct sockaddr_in));
00163                         numSent++;
00164                 }
00165                 else
00166                 {
00167                         EV << "Interface is not connected, dropping packet " << msg << endl;
00168                         numDropped++;
00169                 }
00170         }
00171         delete(msg);
00172         if (ev.isGUI())
00173                 updateDisplayString();
00174 }

void ExtInterface::finish (  )  [virtual]

00203 {
00204         std::cout<<getFullPath()<<": "<<numSent<<" bytes sent, "<<numRcvd<<" bytes received, "<<numDropped <<" bytes dropped.\n";
00205 }


Member Data Documentation

bool ExtInterface::connected [protected]

uint8 ExtInterface::buffer[1<< 16] [protected]

Referenced by handleMessage().

const char* ExtInterface::device [protected]

Referenced by initialize(), and updateDisplayString().

Referenced by initialize().

uint64 ExtInterface::numSent [protected]

uint64 ExtInterface::numRcvd [protected]

uint64 ExtInterface::numDropped [protected]

Referenced by finish(), handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

const char* ExtInterface::tag_color [private]

const char* ExtInterface::tag_width [private]


The documentation for this class was generated from the following files:

Generated on Fri Mar 20 18:51:19 2009 for INET Framework for OMNeT++/OMNEST by  doxygen 1.5.5