|
INET Framework for OMNeT++/OMNEST
|
#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 |
| void ExtInterface::displayBusy | ( | ) | [protected] |
{
getDisplayString().setTagArg("i",1, "yellow");
gate("physOut")->getDisplayString().setTagArg("ls",0,"yellow");
gate("physOut")->getDisplayString().setTagArg("ls",1,"3");
}
| void ExtInterface::displayIdle | ( | ) | [protected] |
{
getDisplayString().setTagArg("i",1,"");
gate("physOut")->getDisplayString().setTagArg("ls",0,"black");
gate("physOut")->getDisplayString().setTagArg("ls",1,"1");
}
| void ExtInterface::finish | ( | ) | [virtual] |
{
std::cout << getFullPath() << ": " << numSent << " packets sent, " <<
numRcvd << " packets received, " << numDropped <<" packets dropped.\n";
}
| void ExtInterface::handleMessage | ( | cMessage * | msg | ) | [virtual] |
{
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] |
{
// 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] |
{return 4;}
| InterfaceEntry * ExtInterface::registerInterface | ( | ) | [protected] |
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] |
Referenced by handleMessage(), and initialize().
uint8 ExtInterface::buffer[1<< 16] [protected] |
Referenced by handleMessage().
bool ExtInterface::connected [protected] |
Referenced by handleMessage(), initialize(), and updateDisplayString().
const char* ExtInterface::device [protected] |
Referenced by initialize(), and updateDisplayString().
InterfaceEntry* ExtInterface::interfaceEntry [protected] |
Referenced by initialize().
int ExtInterface::numDropped [protected] |
Referenced by finish(), handleMessage(), and initialize().
int ExtInterface::numRcvd [protected] |
Referenced by finish(), handleMessage(), initialize(), and updateDisplayString().
int ExtInterface::numSent [protected] |
Referenced by finish(), handleMessage(), initialize(), and updateDisplayString().
cSocketRTScheduler* ExtInterface::rtScheduler [protected] |
Referenced by handleMessage(), and initialize().
const char* ExtInterface::tag_color [private] |
const char* ExtInterface::tag_width [private] |