?? netmodel.cc
字號:
ehn = lookupEdgeHashNode(e.pe.src, e.pe.dst); if (direction == FORWARDS) { if (ehn != 0 && ehn->queue != 0) { q = ehn->queue->remove(e.pe.pkt); delete q; } } else { if (ehn != 0 && ehn->queue != 0) { QueueItem *qi = new QueueItem(e.pe.pkt, e.time, e.offset); qi->paint(paint_[e.pe.pkt.attr & paintMask_]); ehn->queue->enque(qi,QUEUE_HEAD); qi->insert(&animations_); check_monitors(qi); } } break; case 'E': { // Nothing for now Group *grp = lookupGroup(e.pe.dst); if (grp == NULL) { fprintf(stderr, "Packet destination group %d not found\n", e.pe.dst); return; } int *mbr = new int[grp->size()]; grp->get_members(mbr); for (int i = 0; i < grp->size(); i++) { QueueItem *qi = new QueueItem(e.pe.pkt, e.time, e.offset); qi->paint(paint_[e.pe.pkt.attr & paintMask_]); n = lookupNode(mbr[i]); if (n == 0) { fprintf(stderr, "Group member %d not found\n", mbr[i]); return; } if (direction == FORWARDS) { n->queue()->enque(qi, QUEUE_TAIL); qi->insert(&animations_); check_monitors(qi); } else { qi = n->queue()->remove(e.pe.pkt); delete qi; } } delete mbr; break; } case 'D': { n = lookupNode(e.pe.dst); if (n == NULL) { fprintf(stderr, "Bad node id %d for session deque event\n", e.pe.dst); return; } if (direction == FORWARDS) { q = n->queue()->remove(e.pe.pkt); delete q; } else { QueueItem *qi = new QueueItem(e.pe.pkt, e.time, e.offset); qi->paint(paint_[e.pe.pkt.attr & paintMask_]); n->queue()->enque(qi, QUEUE_HEAD); qi->insert(&animations_); check_monitors(qi); } break; } case 'P': // session drop // Get packet to drop. if (direction == FORWARDS) { // fprintf(stderr, "drop on %d -> %d\n", e.pe.src, e.pe.dst); n = lookupNode(e.pe.dst); if (n == 0) return; q = 0; if (n->queue() != 0) { // Remove packet from session queue q = n->queue()->remove(e.pe.pkt); if (q == 0) { // No such packet in queue??? fprintf(stderr, "No packet drop %id in queue\n", e.pe.pkt.id); return; } q->position(x,y); pno = q->paint(); delete q; } // Compute the point at which the dropped packet disappears. // Let's just make this sufficiently far below the lowest // thing on the screen. // Watch out for topologies that have all their nodes lined // up horizontally. In this case, nymin_ == nymax_ == 0. // Set the bottom to -0.028. This was chosen empirically. // The nam display was set to the maximum size and the lowest // position on the display was around -0.028. float bot; if (nymin_ - nymax_ < 0.01) bot = nymin_ - 10 * n->size() ; else bot = nymin_ - (nymax_ - nymin_); Drop *d = new Drop(x, y, bot, n->size()*0.5, /* This is a hack */ e.time, e.offset, e.pe.pkt); d->paint(pno); d->insert(&animations_); check_monitors(d); break; } else { /*direction is BACKWARDS - need to create the packet*/ //fprintf(stderr, "Packet drop backwards\n"); } case 'G': { /* Group event */ Group *grp = lookupGroup(e.ge.src); if (grp == NULL) { grp = new Group(e.ge.grp.name, e.ge.src); add_group(grp); } if (e.ge.grp.flag == GROUP_EVENT_JOIN) { grp->join(e.ge.grp.mbr); // XXX // Hard-coded queue angle for session queues. :( // Create session queue here because they are not like // traditional queues which are created when nam // started. Group member may dynamically join/leave, // so may session queues. We create them here because // there's a 1-1 relationship between join and creating // session queues. n = lookupNode(e.ge.grp.mbr); if (n == NULL) { fprintf(stderr, "Bad node %d for group event\n", e.ge.grp.mbr); return; } // Need more consideration on the placement of these queues Queue *q = new Queue(0.5); q->next_ = queues_; queues_ = q; n->add_sess_queue(e.ge.src, q); } else if (e.ge.grp.flag == GROUP_EVENT_LEAVE) // No deletion of session queues. grp->leave(e.ge.grp.mbr); break; } case 'l': /*link event*/ // if src or dst = -1 this is a layout link (-t *) // so skip over it if (e.le.src == -1 || e.le.dst == -1) return; ehn = lookupEdgeHashNode(e.le.src, e.le.dst); if (ehn == 0) { // if edge doesn't exist try to create it dynamically ep = addEdge(e.le.src, e.le.dst, e); if (!ep) { fprintf(stderr, "Unable to create edge(%d,%d) dynamically.\n", e.le.src, e.le.dst); return; } ehn = lookupEdgeHashNode(e.le.src, e.le.dst); do_relayout= true; } ehnrev = lookupEdgeHashNode(e.le.dst, e.le.src); if (ehnrev == 0) { // if edge doesn't exist try to create it dynamically ep = addEdge(e.le.dst, e.le.src, e); if (!ep) { fprintf(stderr, "Unable to create reverse edge(%d,%d) dynamically.\n", e.le.dst, e.le.src); return; } ehnrev = lookupEdgeHashNode(e.le.dst, e.le.src); do_relayout = true; } if (do_relayout) { //relayout(); relayoutNode(lookupNode(e.le.src)); relayoutNode(lookupNode(e.le.dst)); do_relayout = false; } /*note: many link events are bidirectional events so be careful to apply them to both a link and the reverse of it*/ if (direction==FORWARDS) { // Always save the color before the last DOWN event if (strncmp(e.le.link.state, "DOWN", 4)==0) { ehn->edge->set_down("red"); ehnrev->edge->set_down("red"); } else if (strncmp(e.le.link.state, "UP", 2)==0) { /* XXX Assume an UP event always follows a DOWN event */ ehn->edge->set_up(); ehnrev->edge->set_up(); } else if (strncmp(e.le.link.state, "COLOR", 5) == 0) { ehn->edge->color((char *)e.le.link.color); ehnrev->edge->color((char *)e.le.link.color); } else if (strncmp(e.le.link.state, "DLABEL", 6) == 0) { ehn->edge->dlabel((char *)e.le.link.dlabel); ehnrev->edge->dlabel((char *)e.le.link.dlabel); } else if (strncmp(e.le.link.state, "DCOLOR", 6) == 0) { ehn->edge->dcolor((char *)e.le.link.dcolor); ehnrev->edge->dcolor((char *)e.le.link.dcolor); } else if (strncmp(e.le.link.state, "DIRECTION", 9) == 0) { ehn->edge->direction((char *)e.le.link.direction); ehnrev->edge->direction((char *)e.le.link.direction); } else if (strncmp(e.le.link.state, "DIRECTION", 9) == 0) { ehn->edge->direction((char *)e.le.link.direction); ehnrev->edge->direction((char *)e.le.link.direction); } } else { if (strncmp(e.le.link.state, "UP", 2)==0) { ehn->edge->set_down("red"); ehnrev->edge->set_down("red"); } else if (strncmp(e.le.link.state, "DOWN", 4)==0) { ehn->edge->set_up(); } else if (strncmp(e.le.link.state, "COLOR", 5) == 0) { ehn->edge->color((char *)e.le.link.oldColor); ehnrev->edge->color((char *)e.le.link.oldColor); } else if (strncmp(e.le.link.state, "DLABEL", 6) == 0) { ehn->edge->dlabel((char *)e.le.link.odlabel); ehnrev->edge->dlabel((char *)e.le.link.odlabel); } else if (strncmp(e.le.link.state, "DCOLOR", 6) == 0) { ehn->edge->dcolor((char *)e.le.link.odcolor); ehnrev->edge->dcolor((char *)e.le.link.odcolor); } else if (strncmp(e.le.link.state, "DIRECTION", 9) == 0) { ehn->edge->direction((char *)e.le.link.odirection); ehnrev->edge->direction((char *)e.le.link.odirection); } else if (strncmp(e.le.link.state, "DIRECTION", 9) == 0) { ehn->edge->direction((char *)e.le.link.odirection); ehnrev->edge->direction((char *)e.le.link.odirection); } } break; case 'n': /* node event */ // Return if node has -t * // Ths node is only used for initial layout if (e.ne.src == -1) return; n = lookupNode(e.ne.src); if (n == 0) { // if node doesn't exist try to create it dynamically n = addNode(e); if (!n) return; } if (direction==FORWARDS) { if (strncmp(e.ne.node.state, "DOWN", 4)==0) { n->set_down("gray"); } else if (strncmp(e.ne.node.state, "UP", 2)==0) { n->set_up(); } else if (strncmp(e.ne.node.state, "COLOR", 5) == 0) { // normal color can be defined by user n->color((char *)e.ne.node.color); n->lcolor((char *)e.ne.node.lcolor); } else if (strncmp(e.ne.node.state, "DLABEL", 6) == 0) { n->dlabel((char *)e.ne.node.dlabel); } else if (strncmp(e.ne.node.state, "DCOLOR", 6) == 0) { n->dcolor((char *)e.ne.node.dcolor); } else if (strncmp(e.ne.node.state, "DIRECTION", 9) == 0) { n->direction((char *)e.ne.node.direction); } } else { if (strncmp(e.ne.node.state, "UP", 4)==0) { n->set_down("gray"); } else if (strncmp(e.ne.node.state, "DOWN", 2)==0) { n->set_up(); } else if (strncmp(e.ne.node.state, "COLOR", 5) == 0) { n->color((char *)e.ne.node.oldColor); n->lcolor((char *)e.ne.node.olcolor); } else if (strncmp(e.ne.node.state, "DLABEL", 6) == 0) { n->dlabel((char *)e.ne.node.odlabel); } else if (strncmp(e.ne.node.state, "DCOLOR", 6) == 0) { n->dcolor((char *)e.ne.node.odcolor); } else if (strncmp(e.ne.node.state, "DIRECTION", 9) == 0) { n->direction((char *)e.ne.node.odirection); } } break; case 'm': /* node mark event */ NodeMark *cm; n = lookupNode(e.me.src); if (n == 0) return; cm = n->find_mark((char *) e.me.mark.name); if (direction == FORWARDS) { if (e.me.mark.expired == 0) { /* once created, a node mark cannot be changed*/ if (cm == NULL) n->add_mark((char *)e.me.mark.name, (char *)e.me.mark.color, (char *)e.me.mark.shape); } else /* expired */ n->delete_mark((char *)e.me.mark.name); } else { /* * backward: * (1) create it if expired == 1 * (2) delete it if expired == 0 */ if (e.me.mark.expired == 0) n->delete_mark((char *)e.me.mark.name); else { /* re-create the circle */ if (cm == NULL) n->add_mark((char *)e.me.mark.name, (char *)e.me.mark.color, (char *)e.me.mark.shape); } } break; case 'R': // route event if (((e.re.route.expired==0)&&(direction==FORWARDS))|| ((e.re.route.expired==1)&&(direction==BACKWARDS))) { // this is a new route n = lookupNode(e.re.src); if (n == 0) return; ehn = lookupEdgeHashNode(e.re.src, e.re.dst); if (ehn == 0) return; int oif=1; if (strncmp(e.re.route.mode, "iif", 3)==0) oif=0; r = new Route(n, ehn->edge, e.re.route.group, e.re.route.pktsrc, e.re.route.neg, oif, e.re.route.timeout, now); n->add_route(r); n->place_route(r); r->insert(&animations_); r->paint(paint_[e.re.route.group & paintMask_]); check_monitors(r); } else { // an old route expired n = lookupNode(e.re.src); if (n == 0) return; // src and dst are node ids ehn = lookupEdgeHashNode(e.re.src, e.re.dst); if (ehn == 0) return; int oif = 1; if (strncmp(e.re.route.mode, "iif", 3) == 0) { oif=0; } r = n->find_route(ehn->edge, e.re.route.group, e.re.route.pktsrc, oif); if (r == 0) { fprintf(stderr, "nam: attempt to delete non-existent route\n"); abort(); } n->delete_route(r); delete r; } break; case 'd': add_drop(e, now, direction); }}//---------------------------------------------------------------------// void// NetModel::add_drop(const TraceEvent &e, double now, int direction)// - This method adds a packet drop animation to the animations_ list// - Packet drops can occur from queues and edges. If the queue is // not being displayed the packet is dropped from the node// position.// - If the animation direction is BACKWARDS a packet should be// created but it appears that this code does not do that.//---------------------------------------------------------------------voidNetModel::add_drop(const TraceEvent &e, double now, int direction) { EdgeHashNode *ehn; QueueItem *q; Packet *p; Lan *lan; float x, y; int pno; // paint number (color with which to draw) // Get packet to drop. if (direction == FORWARDS) { ehn = lookupEdgeHashNode(e.pe.src, e.pe.dst); if (ehn == 0) { return; } q = 0; if (ehn->queue != 0) { // if there's a queue, try removing it from the queue first // queue drops are more common than link drops... q = ehn->queue->remove(e.pe.pkt); } if (q == 0) { // perhaps it's a link packet drop p = lookupPacket(e.pe.src, e.pe.dst, e.pe.pkt.id); if (p != NULL) { // it was a link packet drop p->position(x, y, now); ehn->edge->DeletePacket(p); pno = p->paint(); delete p; } else if ((lan = lookupLan(e.pe.src)) != NULL) { /* * If it's a Lan (selective) packet drop, which means * the packet is only dropped on some of the lan links, * register the packet on the lan and drop it when the * packet is actually transmitted to that lan link. * * When the packet is actually dropped, this function will be * called again, but at that time the packet will be actually * on the link and this code will not be executed. */ lan->register_drop(e); return; } else { // probably it was a queue drop, but we're not displaying // that queue // It's possible that this packet is dropped directly from // the queue, even before the enqT_ module. In this case, // we should still produce a packet drop; we use the position // of the node to generate the drop. Node *s = lookupNode(e.pe.src); if (s == NULL) { fprintf(stderr, "NetModel::add_drop(): cannot find src node for packet drop.\n"); abort(); } x = s->x(); y = s->y(); pno = paint_[e.pe.pkt.attr & paintMask_]; } } else { // packet dropped from queue // get x,y position of queue item q->position(x, y);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -