Вы находитесь на странице: 1из 8

TP0. Package.

ned simple Source gates: out: sortie; in: entree; endsimple simple Destination gates: in: entree; out: sortie; endsimple module reseau submodules: s1:Source; d1:Destination; connections: s1.sortie-->d1.entree; d1.sortie-->s1.entree; end module network r1:reseau end network Destination.CC #include "Destination.h" Define_Module(Source); void Source::initialize() { //codes (rien a faire) } void Source::handleMessage(cMesssage *msg) { ev<< "Received message" <<msg->getFullname() <<"'"<<endl; send (msg,"sortie"); //delete msg; } Destination.h #ifndef DESTINATION_H_ #define DESTINATION_H_ #include <string.h> #include <omnetpp.h> class Destination : public cSimpleModule {protected: virtual void initialize(); virtual void handleMessage(cMessage *msg);}; #endif /* DESTINATION_H_ */

Source.CC #include "Source.h" Define_Module(Source); void Source::initialize() { //codes cMessage *msg= new cMessage("paquet");//creation de msg send(msg1,"sortie");//sur le port de sortie appelle "sortie" } void Source::handleMessage(cMesssage *msg) { //codes ev<< "Received message" <<msg->getFullname() <<"'"<<endl;//ev comme print endline a la fin //getFullname methode de la classe cMessage pour afficher le nom du msg qui est "paquet" send(msg,"sortie");// envoyer de nouveau } Source.h #ifndef SOURCE_H_ #define SOURCE_H_ #include <string.h> #include <omnetpp.h> class Source : public cSimpleModule {protected: virtual void initialize();//decrit ce que doit etre effectue quand le module sera cree virtual void handleMessage(cMessage *msg);//decrit quelle action doit etre effectueee a la reception d'un message }; #endif /* SOURCE_H_ */
TP1. TICTOC.NED network Tictoc { submodules: noeud[5]: Txc { @display("i=device/laptop"); } connections: noeud[0].out --> { delay = 100ms; } --> noeud[1].in; noeud[1].out --> { delay = 100ms; } --> noeud[2].in; noeud[2].out --> { delay = 100ms; } --> noeud[3].in; noeud[3].out --> { delay = 100ms; } --> noeud[4].in; noeud[4].out --> { delay = 100ms; } --> noeud[0].in; } TXC.NED simple Txc {parameters: bool sendInitialMessage = default(false); gates: input in; output out;}

TXC.CC #include "Txc.h" Define_Module(Txc); void Txc::initialize() { if (getIndex()==1) { cMessage *msg = new cMessage("TICTOC",kind); int kind = intuniform(1,10); send(msg, "out"); }} void Txc::handleMessage(cMessage *msg) { if (getIndex()==1) { ev<<"c'est parti pour"<< msg->getKind()<<"messages"<<endl; delete msg; } else { int k = msg -> getKind(); ev<<"c'est parti pour"<< k<<"messages"<<endl; int j = intuniform(1,10); for (int i=1; i<=k;i++) { cMessage *cpy=msg->dup(); send(cpy,"out"); }}} TXC.H #ifndef __TIC_TCX_H #define __TIC_TCX_H #include <omnetpp.h> class Txc : public cSimpleModule { protected: virtual void initialize(); virtual void handleMessage(cMessage *msg); };#endif TP2. Reseau.ned network reseau { submodules: noeud[4]:terminal; rout:routeur; connections: noeud[0].in++ <--{delay = 100ms;} <--rout.out++; noeud[0].out++ --> {delay = 100ms;}--> rout.in++; noeud[1].in++ <-- {delay = 100ms;}<-- rout.out++; noeud[1].out++ --> {delay = 100ms;}--> rout.in++; noeud[2].in++ <-- {delay = 100ms;}<-- rout.out++; noeud[2].out++ --> {delay = 100ms;}--> rout.in++; noeud[3].in++ <-- {delay = 100ms;}<-- rout.out++; noeud[3].out++ --> {delay = 100ms;} --> rout.in++; }

Routeur.ned simple routeur {parameters: @display("i=abstract/router"); gates: input in[]; output out[]; } Terminal.ned simple terminal { parameters: @display("i=device/pc4"); gates: input in[]; output out[]; } Terminal.h #ifndef __TERMINAL_H__ #define __TERMINAL_H__ #include <omnetpp.h> class terminal : public cSimpleModule { protected: virtual void initialize(); virtual void handleMessage(cMessage *msg); }; #endif Routeur.h #ifndef __ROUTEUR_H__ #define __ROUTEUR_H__ #include <omnetpp.h> class routeur : public cSimpleModule { protected: virtual void initialize(); virtual void handleMessage(cMessage *msg); }; #endif

Routeur.cc #include "routeur.h" Define_Module(routeur); void routeur::initialize() { } void routeur::handleMessage(cMessage *msg) { simtime_t arrivalT=msg->getArrivalTime(); EV<<"Message Arrival Time: "<<arrivalT; EV<<""<<endl; simtime_t time=msg->getCreationTime(); EV<<"Message Creation Time: "<<time; EV<<""<<endl; int k = msg->getKind(); send(msg,"out",k); }

Terminal.cc #include "terminal.h" Define_Module(terminal); void terminal::initialize() { int dest = intuniform(1,3); if(getIndex() == 0){ cMessage *msg= new cMessage("DS_MSG", dest); send(msg, "out", 0); }} void terminal::handleMessage(cMessage *msg) { simtime_t arrivalT=msg->getArrivalTime(); EV<<"Message Arrival Time: "<<arrivalT; EV<<""<<endl; simtime_t time=msg->getCreationTime(); EV<<"Message Creation Time: "<<time; EV<<""<<endl; int dest = intuniform(0,3); msg->setKind(dest); send(msg, "out", 0); } TP3. TICTOC.NED (SOURCE) network Tictoc { parameters: double n; //int n @prompt("number of nodes"); @display("i=device/pc2"); submodules: node[n]: Txc { @display("i=device/lan"); } connections: for i=0..n-1, for j=1..n-1 { node[i].out++ --> { delay = 100ms; } --> node[j].in++ if i!=j; } } TXC.NED (SOURCE) simple Txc { parameters: bool sendInitialMessage = default(false); @display("i=device/lan"); gates: input in[]; output out[]; }

TXC.H #ifndef __TP3_TCX_H #define __TP3_TCX_H #include <omnetpp.h> /** * Implements the Txc simple module. See the NED file for more information. */ class Txc : public cSimpleModule { protected: virtual void initialize(); virtual void handleMessage(cMessage *msg); }; #endif TXC.CC #include "Txc.h" Define_Module(Txc); void Txc::initialize() { // if (par("sendInitialMessage").boolValue()) int k = 0; if(getIndex() == 0){ int Num = gateSize("out"); cMessage *msg = new cMessage("My MSG", k); for(int i = 0; i < Num; i++){ k = k+1; msg->setKind(k); cMessage *cpy = msg->dup(); send(cpy, "out", i); }}} void Txc::handleMessage(cMessage *msg) { int Hosts = getAncestorPar("n"); int HostsNum = msg->getKind(); if(getIndex() == Hosts-1){ EV<<"Le msg est recu:"<<endl; delete(msg); } else { int NbGates = gateSize("out"); HostsNum++; for(int i = 0; i < NbGates; i++){ cMessage* cpy = msg->dup(); cpy->setKind(HostsNum); send(cpy, "out", i); EV<<"Le nombre de de sauts est:"<<HostsNum<<endl; }}}

TP4. #include "Txc.h" Define_Module(Txc); void Txc::initialize() { //if (par("sendInitialMessage").boolValue()) int HopCount = 0; int NumGate=gateSize("out"); cMessage *msg = new cMessage("My MSG", HopCount); if(getIndex() == 0){ for(int i = 0; i < NumGate; i++){ msg->setKind(HopCount); cMessage *cpy = msg->dup(); send(cpy, "out", i); } } } void Txc::handleMessage(cMessage *msg) { int Hosts = getAncestorPar("n"); int HostsNum = msg->getKind(); cGate *ps = msg->getArrivalGate()->getPreviousGate(); int previous=ps->getOwnerModule()->getIndex(); int Gatenumb=gateSize("out"); if(getIndex() == Hosts-1){ EV<<"Le msg est recu:"<<endl; bubble("Le msg est recu"); delete(msg); } else { for(int i = 0; i < Gatenumb; i++){ cGate *m=gate("out",i); int h=m->getNextGate()->getIndex; if(previous != h) { cMessage* cpy1 = msg->dup(); cpy->setKind(HostsNum); send(cpy1, "out", i); EV<<"Le nombre de de sauts est:"<<HostsNum<<endl; } HostNum++; } } }

TP5. TXC.CC #include "Txc.h" Define_Module(Txc); void Txc::initialize() { if ( getIndex()==0) { int kind =0; cPacket *pak = new cPacket("le packet"); pak->setBytetLength(64); cMessage *msg = check_and_cast<cMessage *> (pak); msg->setKind(kind); int N = gateSize("out"); for (int i=0; i<N ; i++){ cMessage *cpy = msg->dup; send (cpy,"out",i); } } } void Txc::handleMessage(cMessage *msg) { int Hops = getAncestorPar("n"); int t=msg->getKind(); cPacket *pak = check_and_cast<cPacket *>(msg); int size = pak-> getByteLength(); if(getIndex()==1){ if (t==0) { kind =1; cPacket *newpak = new cPacket("le packet"); newpak->setBytetLength(64); pak->encapsulate(newpak); cMessage *msg = check_and_cast<cMessage *> (pak); int S = gateSize("out"); for (int i=0; i<S ; i++){ cMessage *cpy = msg->dup; send (cpy,"out",i); } } } else if (getIndex()==Hops-1){ if (t==1){ EV<< "le message reu est modifie" ; } else { EV<< " le message reu est initiale" ; } } else{ cMessage *msg = check_and_cast<cMessage *> (pak); int P = gateSize("out"); for (int i=0; i<P ; i++){ cMessage *cpy = msg->dup; send (cpy,"out",i); } }}

Вам также может понравиться