refixed previous commitprintf
[charm.git] / examples / pose / HiSim / Main / Channel.C
1 #include "BgSim_sim.h"
2 #include "TCsim_sim.h"
3
4 #include<math.h>
5
6
7 Channel::Channel(ChannelMsg *m) {
8    id = m->id;  portid = m->portid;  nodeid = m->nodeid; numP = m->numP;
9    prevIntervalStart = 0; counter = 0;
10 }
11
12 // Send packet to switch or node. Also doubles as the reception channel in direct network
13 void Channel::recvPacket(Packet *copyP) {
14         Packet *p; p = new Packet; *p = *copyP;
15
16         CkAssert(p->hdr.src >= 0);
17         if(portid == numP) { // For direct networks only
18         POSE_invoke(recvPacket(p),NetInterface,config.nicStart+nodeid,(POSE_TimeType)(p->hdr.routeInfo.datalen/config.switchC_BW));
19         if(!config.receptionSerial)
20         elapse((POSE_TimeType)(p->hdr.routeInfo.datalen/config.switchC_BW));
21         return;
22         }
23
24        POSE_TimeType curInterval,tmp=prevIntervalStart,nextId;
25         if(config.linkstats_on) {
26         curInterval = ovt/config.collection_interval;
27         if(curInterval > prevIntervalStart) {
28         prevIntervalStart = curInterval;
29         parent->CommitPrintf("%d->%d %lld %f\n",nodeid,portid,prevIntervalStart,(float)counter/config.collection_interval);
30         counter=0;
31         }
32         }
33
34
35         if((p->hdr.nextId >= config.nicStart)  && (p->hdr.nextId < (config.nicStart+config.numNodes)))
36                 POSE_invoke(recvPacket(p),NetInterface,p->hdr.nextId,(POSE_TimeType)(p->hdr.routeInfo.datalen/config.switchC_BW));
37         else {
38                 CkAssert(p->hdr.nextId >= config.switchStart);
39                 POSE_invoke(recvPacket(p),Switch,p->hdr.nextId,config.switchC_Delay);
40         }
41         counter+= ((POSE_TimeType)(config.switchC_Delay+copyP->hdr.routeInfo.datalen/config.switchC_BW));
42         elapse((POSE_TimeType)(copyP->hdr.routeInfo.datalen/config.switchC_BW));  // Same buffer , we have already elapsed, so no need.
43 }