?? netmodel.cc
字號:
/* * Copyright (c) 1991,1993 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the Computer Systems * Engineering Group at Lawrence Berkeley Laboratory. * 4. Neither the name of the University nor of the Laboratory may be used * to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#) $Header: /cvsroot/nsnam/nam-1/netmodel.cc,v 1.113 2006/11/19 00:12:29 tom_henderson Exp $ (LBL) */#include <stdlib.h>#ifdef WIN32#include <windows.h>#endif#include <stdio.h>#include <ctype.h>#include <math.h>#include <tcl.h>#include <tclcl.h>#include "config.h"#include "netview.h"#include "psview.h"#include "testview.h"#include "animation.h"#include "group.h"#include "tag.h"#include "queue.h"#include "drop.h"#include "packet.h"#include "edge.h"#include "lan.h"#include "node.h"#include "agent.h"#include "feature.h"#include "route.h"#include "netmodel.h"#include "monitor.h"#include "trace.h"#include "paint.h"#include "sincos.h"#include "state.h"#include "editview.h"#include "address.h"#include "animator.h"#include <float.h>extern int lineno;// not used//static int next_pat;class NetworkModelClass : public TclClass {public: NetworkModelClass() : TclClass("NetworkModel") {} TclObject* create(int argc, const char*const* argv) { if (argc < 5) return 0; return (new NetModel(argv[4])); }} networkmodel_class;//----------------------------------------------------------------------//----------------------------------------------------------------------NetModel::NetModel(const char *animator) : TraceHandler(animator), drawables_(0), animations_(0), queues_(0), views_(0), nodes_(0), lans_(0), node_sizefac_(NODE_EDGE_RATIO), mon_count_(0), monitors_(NULL), wireless_(0), resetf_(0), selectedSrc_(-1), selectedDst_(-1), selectedFid_(-1), hideSrc_(-1), hideDst_(-1), hideFid_(-1), colorSrc_(-1), colorDst_(-1), colorFid_(-1), showData_(1), showRouting_(1), showMac_(1), selectedColor_(-1), nGroup_(0), nTag_(0), parsetable_(&traceevent_) { int i; for (i = 0; i < EDGE_HASH_SIZE; ++i) { hashtab_[i] = 0; } for (i = 0; i < PTYPELEN; ++i) { selectedTraffic_[i] = '\0' ; colorTraffic_[i] = '\0' ; hideTraffic_[i] = '\0' ; } // Default node size is 10.0 so a default packet will be 25% of that (2.5) // This value is modified whenever a node is added. It will be based on // the running average of the size of the last 5 nodes. Look at // NetModel::addNode(const TraceEvent &e) for more details packet_size_ = 2.5; /*XXX*/ nymin_ = 1e6; nymax_ = -1e6; Paint *paint = Paint::instance(); int p = paint->thin(); // Initially 256 colors. Can be extended later. // See handling of otcl binding "color" nclass_ = 256; paintMask_ = 0xff; paint_ = new int[nclass_]; oldpaint_ = new int[nclass_]; for (i = 0; i < nclass_; ++i) { paint_[i] = p; oldpaint_[i] = p; } addrHash_ = new Tcl_HashTable; Tcl_InitHashTable(addrHash_, TCL_ONE_WORD_KEYS); grpHash_ = new Tcl_HashTable; Tcl_InitHashTable(grpHash_, TCL_ONE_WORD_KEYS); tagHash_ = new Tcl_HashTable; Tcl_InitHashTable(tagHash_, TCL_STRING_KEYS); objnameHash_ = new Tcl_HashTable; Tcl_InitHashTable(objnameHash_, TCL_STRING_KEYS); registerObjName("ALL", ClassAllID); registerObjName("ANIMATION", ClassAnimationID); registerObjName("NODE", ClassNodeID); registerObjName("PACKET", ClassPacketID); registerObjName("EDGE", ClassEdgeID); registerObjName("QUEUEITEM", ClassQueueItemID); registerObjName("LAN", ClassLanID); registerObjName("TAG", ClassTagID); registerObjName("AGENT", ClassAgentID); bind("bcast_duration_", &bcast_duration_); bind("bcast_radius_", &bcast_radius_);}NetModel::~NetModel(){ // We should delete everything here, if we want deletable netmodel... delete paint_; Animation *a, *n; for (a = animations_; a != 0; a = n) { n = a->next(); delete a; } for (a = drawables_; a != 0; a = n) { n = a->next(); delete a; } Tcl_DeleteHashTable(grpHash_); delete grpHash_; Tcl_DeleteHashTable(tagHash_); delete tagHash_; Tcl_DeleteHashTable(objnameHash_); delete objnameHash_;}void NetModel::update(double now){ Animation *a, *n; for (a = animations_; a != 0; a = n) { n = a->next(); a->update(now); } /* * Draw all animations and drawables on display to reflect * current time. */ now_ = now; for (View* p = views_; p != 0; p = p->next_) { // Calls View::draw() which calls NetView::render() // which calls NetModel::render(View*) p->draw(); }}void NetModel::update(double now, Animation* a) { a->update(now); for (View* p = views_; p != 0; p = p->next_) a->draw(p, now);}//----------------------------------------------------------------------// void// NetModel::reset(double now)// - Reset all animations and queues to time 'now'.//----------------------------------------------------------------------voidNetModel::reset(double now) { Animation* a; for (a = animations_; a != 0; a = a->next()) a->reset(now); for (a = drawables_; a != 0; a = a->next()) a->reset(now); for (Queue* q = queues_; q != 0; q = q->next_) q->reset(now);}//----------------------------------------------------------------------// void// NetModel::render(View * view)// - Draw this NetModel's drawables, animations, and monitors.// (tags, nodes, edges, packets, queues, etc.)//----------------------------------------------------------------------voidNetModel::render(View* view) { Animation *a; Monitor *m; for (a = drawables_; a != 0; a = a->next()) a->draw(view, now_); for (a = animations_; a != 0; a = a->next()) a->draw(view, now_); for ( m = monitors_; m != NULL; m = m->next()) m->draw_monitor(view, nymin_, nymax_);}void NetModel::render(PSView* view) { Animation *a; for (a = drawables_; a != 0; a = a->next()) a->draw(view, now_); for (a = animations_; a != 0; a = a->next()) a->draw(view, now_);}void NetModel::render(TestView* view) { Animation *a; for (a = drawables_; a != 0; a = a->next()) a->draw(view, now_); for (a = animations_; a != 0; a = a->next()) a->draw(view, now_);}//----------------------------------------------------------------------// NetModel::EdgeHashNode *// NetModel::lookupEdgeHashNode(int src, int dst) const// - Return a pointer to the edge between 'src' and 'dst'. //----------------------------------------------------------------------NetModel::EdgeHashNode *NetModel::lookupEdgeHashNode(int source, int destination) const{ EdgeHashNode* h; for (h = hashtab_[ehash(source, destination)]; h != 0; h = h->next) if (h->src == source && h->dst == destination) break; return (h);}int NetModel::addAddress(int id, int addr) const{ int newEntry = 1; Tcl_HashEntry *he = Tcl_CreateHashEntry(addrHash_, (const char *)addr, &newEntry); if (he == NULL) return -1; if (newEntry) { Tcl_SetHashValue(he, (ClientData)id); } return 0;}int NetModel::addr2id(int addr) const { Tcl_HashEntry *he = Tcl_FindHashEntry(addrHash_, (const char *)addr); if (he == NULL) return -1; return *(int*)Tcl_GetHashValue(he);}//----------------------------------------------------------------------// Adds an edge to a hash table?//----------------------------------------------------------------------void NetModel::enterEdge(Edge* e) { int src = e->src(); int dst = e->dst(); EdgeHashNode *h = lookupEdgeHashNode(src, dst); if (h != 0) { /* XXX */ fprintf(stderr, "nam: duplicate edge (%d,%d)\n", src, dst); //exit(1); return; } h = new EdgeHashNode; h->src = src; h->dst = dst; h->queue = 0; h->edge = e; int k = ehash(src, dst); h->next = hashtab_[k]; hashtab_[k] = h;}//----------------------------------------------------------------------// void// NetModel::removeEdge(Edge* e)// - Remove an edge from the network model and delete it//----------------------------------------------------------------------voidNetModel::removeEdge(Edge* e) { int k; int src = e->src(); int dst = e->dst(); EdgeHashNode * h = lookupEdgeHashNode(src, dst); EdgeHashNode * f, * g; if (h == 0) { fprintf(stderr, "nam: trying to delete nonesisting edge (%d,%d)\n", src, dst); exit(1); } //XXX do we need to process queue ? leave it to the future 10/01/98 k = ehash(src, dst); for (f = hashtab_[k]; f != 0; f = f->next) { if (h->src == f->src && h->dst == f->dst) { if (f == hashtab_[k]) { hashtab_[k] = f->next; break; } else { g->next = f->next; break; } } g = f; } delete h;}//----------------------------------------------------------------------// void // NetModel::BoundingBox(BBox& bb) {// XXX Make this cheaper (i.e. cache it)//----------------------------------------------------------------------void NetModel::BoundingBox(BBox& bb) { /* ANSI C limits, from float.h */ bb.xmin = bb.ymin = FLT_MAX; bb.xmax = bb.ymax = -FLT_MAX; for (Animation* a = drawables_; a != 0; a = a->next()) a->merge(bb);}/* Animation* NetModel::inside(double now, float px, float py) const { for (Animation* a = animations_; a != 0; a = a->next()) if (a->inside(now, px, py)) return (a); for (Animation* d = drawables_; d != 0; d = d->next()) if (d->inside(now, px, py)) return (d); return (0); }*/// Used exclusively for start_info() in nam.tcl. It ignores all tag objects// and therefore should *not* be used for editing.Animation* NetModel::inside(float px, float py) const{ for (Animation* a = animations_; a != 0; a = a->next()) { if (a->type() == BPACKET) { BPacket* b = (BPacket* ) a ; if ((b->inside(px, py)) && (a->classid() != ClassTagID)) return (a); } else { if ((a->inside(px, py)) && (a->classid() != ClassTagID)) return (a); } } for (Animation* d = drawables_; d != 0; d = d->next()) { if ((d->inside(px, py) && (d->classid() != ClassTagID))) return (d); } return (0);}int NetModel::add_monitor(Animation *a){ Monitor *m = new Monitor(mon_count_, a, node_size_); m->next(monitors_); monitors_=m; return mon_count_++;}int NetModel::monitor(double now, int monitor, char *result, int len){ /*XXX should get rid of this search*/ for(Monitor *m=monitors_; m!=NULL; m=m->next()) { if (m->monitor_number()==monitor) { m->update(now, result, len); if (strlen(result)==0) delete_monitor(m); return 0; } } result[0]='\0'; return -1;}//----------------------------------------------------------------------// void NetModel::check_monitors(Animation *a)// - A new animation just got created. Check to see if we should // already have a monitor on it.//----------------------------------------------------------------------void NetModel::check_monitors(Animation *a) { MonState * ms; Monitor * m;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -