|
INET Framework for OMNeT++/OMNEST
|
00001 /* 00002 * pim.cc 00003 * 00004 * Created on: 3.12.2011 00005 * Author: Haczek 00006 */ 00007 00008 #include "pimSplitter.h" 00009 00010 using namespace std; 00011 00012 Define_Module(pimSplitter); 00013 00014 void pimSplitter::handleMessage(cMessage *msg) 00015 { 00016 EV << "PIM::handleMessage" << endl; 00017 00018 // vlastni zprava, tj. nektery z casovacu 00019 if (msg->isSelfMessage()) 00020 { 00021 PIMTimer *timer = check_and_cast <PIMTimer *> (msg); 00022 } 00023 else if (dynamic_cast<PIMPacket *>(msg)) 00024 { 00025 PIMPacket *pkt = check_and_cast<PIMPacket *>(msg); 00026 EV << "Verze: " << pkt->getVersion() << ", typ: " << pkt->getType() << endl; 00027 } 00028 else 00029 EV << "PIM: spatna zprava" << endl; 00030 } 00031 00032 void pimSplitter::initialize(int stage) 00033 { 00034 // v stage 2 se registruji interfacy 00035 if (stage == 3) 00036 { 00037 EV << "PIM::sendPacket" << endl; 00038 00039 rt = RoutingTableAccess().get(); 00040 ift = InterfaceTableAccess().get(); 00041 00042 EV << "Posilam zpravu na adresu: 224.0.0.13" << endl; 00043 00044 PIMPacket *msg = new PIMPacket(); 00045 msg->setVersion(2); 00046 msg->setType(Hello); 00047 msg->setName("PIMmessage"); 00048 00049 int intID; 00050 IInterfaceTable *ift; 00051 ift = InterfaceTableAccess().get(); 00052 for (int i = 0; i < ift->getNumInterfaces(); i++) 00053 { 00054 if (!ift->getInterface(i)->isLoopback()) 00055 { 00056 intID = ift->getInterface(i)->getInterfaceId(); 00057 break; 00058 } 00059 } 00060 00061 IPControlInfo *ctrl = new IPControlInfo(); 00062 IPAddress ga1("224.0.0.13"); 00063 ctrl->setDestAddr(ga1); 00064 ctrl->setProtocol(IP_PROT_PIM); 00065 ctrl->setTimeToLive(1); 00066 ctrl->setInterfaceId(intID); 00067 msg->setControlInfo(ctrl); 00068 00069 send(msg, "transportOut"); 00070 } 00071 }