//------------------------------------------------------------- // File: HcubeRte.cc // // Implementation of simple module types // // Authors: Andras Varga (TU Budapest) //------------------------------------------------------------- #include #include #include "hc_rte.h" #include "hcpacket_m.h" #define TRACE_MSG #define SLOT_TIME 1.0 #define PROPDEL (0.99*SLOT_TIME) // Module registration: Define_Module( HCRouter ) void deflectionRouting(int my_address,int dim, int *rte_dest, int num_rte, int *rte_port, int *usr_dest, int num_usr, int *usr_port); // // Activity of the simple module // void HCRouter::activity() { int my_address = par("address"); int dim = par("dim"); int fromUserGateId = gate("from_gen")->id(); long total_usr = 0, discarded_usr = 0; cMessage *endOfSlot = new cMessage("endOfSlot"); for(;;) { int i; // buffers for transit cells (rte) and for cells from local user (usr) HCPacket *rte_cell[32]; int num_rte = 0; HCPacket *usr_cell[32]; int num_usr = 0; // collect cells; user cells go into separate buffer scheduleAt( simTime()+SLOT_TIME, endOfSlot ); cMessage *msg; while ((msg=receive())!=endOfSlot) { HCPacket *pkt = check_and_cast(msg); if (pkt->arrivalGateId()!=fromUserGateId) { if (pkt->getDestAddress()!=my_address) rte_cell[num_rte++] = pkt; else send(pkt,"to_sink"); } else { total_usr++; if (num_usr<32) usr_cell[num_usr++] = pkt; else {discarded_usr++; delete pkt;} } } // prepare arrays used in routing int rte_dest[32], rte_port[32]; // destinations, output ports int usr_dest[32], usr_port[32]; for (i=0;igetDestAddress(); for (i=0;igetDestAddress(); // make routing decision (function fills rte_port[] and usr_port[]) deflectionRouting(my_address, dim, rte_dest, num_rte, rte_port, usr_dest, num_usr, usr_port); // send out transit cells for (i=0; isetHops(rte_cell[i]->getHops()+1); sendDelayed(rte_cell[i], PROPDEL, "out", rte_port[i]); } // send out user cells for (i=0; isetHops(usr_cell[i]->getHops()+1); sendDelayed(usr_cell[i], PROPDEL, "out", usr_port[i]); } } ev.printf("rte[%d]: Discarded %ld out of %ld\n", my_address, discarded_usr, total_usr); } } void deflectionRouting(int my_address,int dim, int *rte_dest, int num_rte, int *rte_port, int *usr_dest, int num_usr, int *usr_port) { // This function implements a simple, fast, but very suboptimal, unfair, // unbalanced etc. deflection scheme. int i; unsigned port_mask = (1<