void CheckGap::send(Node& node, int start, int end) { LitterNode& lnode = dynamic_cast<LitterNode&>(_node); LitterNode& dnode = dynamic_cast<LitterNode&>(node); lnode.stats.gapfound++; if (dnode.getOnline() == true) { Action* pr_event = new GapRcv(node, _node, _sched, _net, start, end, node); LitterNetwork& lnet = dynamic_cast<LitterNetwork&>(_net); lnet.send(lnode, dnode, *pr_event, _sched); lnode.stats.gaptx++; } else { NodeIterator* ni = lnode.getNeighborIT(); while (ni->moveNext()) { Node* neighbor = ni->current(); LitterNode& dest = dynamic_cast<LitterNode&>(*neighbor); if (dest.getOnline() == true) { LitterNetwork& lnet = dynamic_cast<LitterNetwork&>(_net); if ( lnet.isNeighbor(dnode, dest)) { Action* pr_event = new GapRcv(*neighbor, _node, _sched, _net, start, end, node); lnet.send(lnode, dest, *pr_event, _sched); lnode.stats.gaptx++; break; } } } } }
void PullSend::Execute() { if (_resched) { Action* ps_event = new PullSend(_node, _sched, _net, _resched); _sched.after(ps_rate, ps_event); } LitterNode& lnode = dynamic_cast<LitterNode&>(_node); if (lnode.getOnline() == false) return; int end = _sched.getCurrentTime(); int start = lnode.getLastPull(); lnode.setLastPull(_sched.getCurrentTime()); int delay = 0; NodeIterator* ni = lnode.getNeighborIT(); while (ni->moveNext()) { Node* neighbor = ni->current(); LitterNode& dest = dynamic_cast<LitterNode&>(*neighbor); if (dest.getOnline() == true) { Action* pr_event = new PullRcv(*neighbor, _node, _sched, _net, start, end); LitterNetwork& lnet = dynamic_cast<LitterNetwork&>(_net); lnet.send(lnode, dest, *pr_event, _sched, delay++); lnode.stats.pulltx++; } } }
bool LitterNetwork::isNeighbor(LitterNode& source, LitterNode& dest) { NodeIterator* ni = source.getNeighborIT(); while (ni->moveNext()) { if (ni->current() == &dest) { return true; } } return false; }
void PFLCFG::ResetValid(void) { NodeIterator i = FirstNode(); for (; i != LastNode(); i++) { BBType *bb = i.current()->NodeInfo; bb->Valid = false; } }
void PFLCFG::RemoveDeadNodes(void) { bool changed = true; //uint32 round = 0; while (changed) { NodeIterator i = FirstNode(); changed = false; for (; i != LastNode(); i++) { BBType *bb = i.current()->NodeInfo; if (bb->Kind != BB_CFG_ENTRY && bb->Valid) { if (i.current()->GetPredecessors().empty()) { changed = true; bb->Valid = false; } } } if (changed) { NodeIterator i = FirstNode(); for(; i != LastNode(); i++) { BBType *bb = i.current()->NodeInfo; if (!bb->Valid) { list<node_t*> &succ = bb->getNode()->GetSuccessors(); list<node_t*>::iterator k = succ.begin(); for (; k != succ.end(); k++) DeleteEdge(*(*k), *bb->getNode()); //delete bb; //Graph.DeleteNode(*i.current()); } } } } }
void PostSend::Execute() { LitterNode& lnode = dynamic_cast<LitterNode&>(_node); if (lnode.getOnline() == false) return; NodeIterator* ni = lnode.getNeighborIT(); PostMsg* msg = new PostMsg(_node, _sched.getCurrentTime()); assert(lnode.addPost(msg)); lnode.stats.lpostcount++; while (ni->moveNext()) { Node* neighbor = ni->current(); LitterNode& dest = dynamic_cast<LitterNode&>(*neighbor); if (dest.getOnline() == true) { Action* pr_event = new PostRcv(*neighbor, *msg, _sched, _net, 1); LitterNetwork& lnet = dynamic_cast<LitterNetwork&>(_net); lnet.send(lnode, dest, *pr_event, _sched); lnode.stats.posttx++; } } }
int main(int argc, char* argv[]) { if (argc < 6) { cout << " usage: ./litter exp_on exp_off droprate days genrate" << " < graphfile\n"; return 0; } double churn_on = atof(argv[1]); double churn_off = atof(argv[2]); double drop_rate = double(1) - atof(argv[3]); int days = atoi(argv[4]) + 1; GDays = days; int runtime = days * 24 * 3600; int genrate = atoi(argv[5]); int seed = -1; if (argc >= 8) { ps_rate = atoi(argv[6]); cg_rate = atoi(argv[7]); } Random* rnd = new Ran1Random(seed); EventScheduler* sched = new EventScheduler(); Network* net = new LitterNetwork(std::cin, *rnd, drop_rate); ExpDRV* expon = new ExpDRV(*rnd, churn_on); ExpDRV* expoff = new ExpDRV(*rnd, churn_off); UniformNodeSelector* ns = new UniformNodeSelector(*rnd); ns->selectFrom(net); NodeIterator* ni = net->getNodeIterator(); int time = 0; // Schedule a churn event for each node while (ni->moveNext()) { Node* node = ni->current(); time = rnd->getInt(3600); sched->at(time, new ChurnEvent(*node, *sched, *net, *expoff, *expon)); } // Schedule a pull request at each node ni->reset(); while (ni->moveNext()) { Node* node = ni->current(); time = rnd->getInt(3600); sched->at(time, new PullSend(*node, *sched, *net, true)); } // Schedule a checkgap at each node ni->reset(); while (ni->moveNext()) { Node* node = ni->current(); time = rnd->getInt(3600); sched->at(time, new CheckGap(*node, *sched, *net)); } // Periodically generates posts sched->at(1800, new PostGen(*sched, *net, *rnd, *ns, genrate)); // Stops the scheduler sched->at(runtime, new StopAction(*sched)); sched->start(); StatsPrint(*net, *sched); // clean up global objects delete rnd; delete sched; delete expon; delete expoff; delete net; delete ni; delete ns; return 0; }