#include <ExtInterface.h>
Public Member Functions | |
virtual int32 | numInitStages () const |
virtual void | initialize (int stage) |
virtual void | handleMessage (cMessage *msg) |
virtual void | finish () |
Protected Member Functions | |
InterfaceEntry * | registerInterface () |
void | displayBusy () |
void | displayIdle () |
void | updateDisplayString () |
Protected Attributes | |
bool | connected |
uint8 | buffer [1<< 16] |
const char * | device |
InterfaceEntry * | interfaceEntry |
int | numSent |
int | numRcvd |
int | numDropped |
cSocketRTScheduler * | rtScheduler |
Private Attributes | |
const char * | tag_color |
const char * | tag_width |
Definition at line 39 of file ExtInterface.h.
void ExtInterface::displayBusy | ( | ) | [protected] |
Definition at line 178 of file ExtInterface.cc.
{ getDisplayString().setTagArg("i",1, "yellow"); gate("physOut")->getDisplayString().setTagArg("ls",0,"yellow"); gate("physOut")->getDisplayString().setTagArg("ls",1,"3"); }
void ExtInterface::displayIdle | ( | ) | [protected] |
Definition at line 185 of file ExtInterface.cc.
{ getDisplayString().setTagArg("i",1,""); gate("physOut")->getDisplayString().setTagArg("ls",0,"black"); gate("physOut")->getDisplayString().setTagArg("ls",1,"1"); }
void ExtInterface::finish | ( | ) | [virtual] |
Definition at line 204 of file ExtInterface.cc.
{ std::cout << getFullPath() << ": " << numSent << " packets sent, " << numRcvd << " packets received, " << numDropped <<" packets dropped.\n"; }
void ExtInterface::handleMessage | ( | cMessage * | msg | ) | [virtual] |
Definition at line 106 of file ExtInterface.cc.
{ if(dynamic_cast<ExtFrame *>(msg) != NULL) { // incoming real packet from wire (captured by pcap) uint32 packetLength; ExtFrame *rawPacket = check_and_cast<ExtFrame *>(msg); packetLength = rawPacket->getDataArraySize(); for(uint32 i=0; i < packetLength; i++) buffer[i] = rawPacket->getData(i); IPDatagram *ipPacket = new IPDatagram("ip-from-wire"); IPSerializer().parse(buffer, packetLength, (IPDatagram *)ipPacket); EV << "Delivering an IP packet from " << ipPacket->getSrcAddress() << " to " << ipPacket->getDestAddress() << " and length of" << ipPacket->getByteLength() << " bytes to IP layer.\n"; send(ipPacket, "netwOut"); numRcvd++; } else { memset(buffer, 0, 1<<16); IPDatagram *ipPacket = check_and_cast<IPDatagram *>(msg); if ((ipPacket->getTransportProtocol() != IP_PROT_ICMP) && (ipPacket->getTransportProtocol() != IPPROTO_SCTP) && (ipPacket->getTransportProtocol() != IPPROTO_TCP) && (ipPacket->getTransportProtocol() != IPPROTO_UDP)) { EV << "Can not send packet. Protocol " << ipPacket->getTransportProtocol() << " is not supported.\n"; numDropped++; delete(msg); return; } if(connected) { struct sockaddr_in addr; addr.sin_family = AF_INET; #if !defined(linux) && !defined(_WIN32) addr.sin_len = sizeof(struct sockaddr_in); #endif addr.sin_port = 0; addr.sin_addr.s_addr = htonl(ipPacket->getDestAddress().getInt()); int32 packetLength = IPSerializer().serialize(ipPacket,buffer, sizeof(buffer)); EV << "Delivering an IP packet from " << ipPacket->getSrcAddress() << " to " << ipPacket->getDestAddress() << " and length of " << ipPacket->getByteLength() << " bytes to link layer.\n"; rtScheduler->sendBytes(buffer, packetLength, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)); numSent++; } else { EV << "Interface is not connected, dropping packet " << msg << endl; numDropped++; } } delete(msg); if (ev.isGUI()) updateDisplayString(); }
void ExtInterface::initialize | ( | int | stage | ) | [virtual] |
Definition at line 35 of file ExtInterface.cc.
{ // subscribe at scheduler for external messages if(stage == 0) { if(dynamic_cast<cSocketRTScheduler *>(simulation.getScheduler()) != NULL) { rtScheduler = check_and_cast<cSocketRTScheduler *>(simulation.getScheduler()); //device = ev.config()->getAsString("Capture", "device", "lo0"); device = par("device"); //const char *filter = ev.config()->getAsString("Capture", "filter-string", "ip"); const char *filter = par("filterString"); rtScheduler->setInterfaceModule(this, device, filter); connected = true; } else { // this simulation run works without external interface.. connected = false; } } if (stage == 3) { // update display string when addresses have been autoconfigured etc. updateDisplayString(); return; } // all initialization is done in the first stage if (stage != 0) return; numSent = numRcvd = numDropped = 0; WATCH(numSent); WATCH(numRcvd); WATCH(numDropped); // register our interface entry in RoutingTable interfaceEntry = registerInterface(); // if not connected, make it gray if (ev.isGUI() && !connected) { getDisplayString().setTagArg("i",1,"#707070"); getDisplayString().setTagArg("i",2,"100"); } }
virtual int32 ExtInterface::numInitStages | ( | ) | const [inline, virtual] |
Definition at line 68 of file ExtInterface.h.
{return 4;}
InterfaceEntry * ExtInterface::registerInterface | ( | ) | [protected] |
Definition at line 84 of file ExtInterface.cc.
Referenced by initialize().
{ InterfaceEntry *e = new InterfaceEntry(); // interface name: our module name without special characters ([]) char *interfaceName = new char[strlen(getFullName())+1]; char *d=interfaceName; for (const char *s=getFullName(); *s; s++) if (isalnum(*s)) *d++ = *s; *d = '\0'; e->setName(interfaceName); delete [] interfaceName; e->setMtu(par("mtu")); e->setMulticast(true); e->setPointToPoint(true); IInterfaceTable *ift = InterfaceTableAccess().get(); ift->addInterface(e, this); return e; }
void ExtInterface::updateDisplayString | ( | ) | [protected] |
Definition at line 192 of file ExtInterface.cc.
Referenced by handleMessage(), and initialize().
uint8 ExtInterface::buffer[1<< 16] [protected] |
Definition at line 43 of file ExtInterface.h.
Referenced by handleMessage().
bool ExtInterface::connected [protected] |
Definition at line 42 of file ExtInterface.h.
Referenced by handleMessage(), initialize(), and updateDisplayString().
const char* ExtInterface::device [protected] |
Definition at line 44 of file ExtInterface.h.
Referenced by initialize(), and updateDisplayString().
InterfaceEntry* ExtInterface::interfaceEntry [protected] |
Definition at line 46 of file ExtInterface.h.
Referenced by initialize().
int ExtInterface::numDropped [protected] |
Definition at line 51 of file ExtInterface.h.
Referenced by finish(), handleMessage(), and initialize().
int ExtInterface::numRcvd [protected] |
Definition at line 50 of file ExtInterface.h.
Referenced by finish(), handleMessage(), initialize(), and updateDisplayString().
int ExtInterface::numSent [protected] |
Definition at line 49 of file ExtInterface.h.
Referenced by finish(), handleMessage(), initialize(), and updateDisplayString().
cSocketRTScheduler* ExtInterface::rtScheduler [protected] |
Definition at line 54 of file ExtInterface.h.
Referenced by handleMessage(), and initialize().
const char* ExtInterface::tag_color [private] |
Definition at line 62 of file ExtInterface.h.
const char* ExtInterface::tag_width [private] |
Definition at line 63 of file ExtInterface.h.