⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monitor.c

📁 BCAST Implementation for NS2
💻 C
📖 第 1 页 / 共 2 页
字号:
    byte ls_type;    lsid_t id;    rtid_t advrtr;    LSA *lsap;    int mlen;    MonMsg *msg;    lsareq = &req->body.lsarq;    a_id = ntoh32(lsareq->area_id);    ls_type = ntoh32(lsareq->ls_type);    id = ntoh32(lsareq->ls_id);    advrtr = ntoh32(lsareq->adv_rtr);    lsap = 0;    if (req->hdr.exact != 0) {	SpfArea *ap;	if ((ap = FindArea(a_id)) || flooding_scope(ls_type) == GlobalScope)	    lsap = FindLSA(0, ap, ls_type, id, advrtr);    } else        lsap = NextLSA(a_id, ls_type, id, advrtr);    mlen = sizeof(MonHdr) + sizeof(MonRqLsa);    if (lsap)        mlen += lsap->ls_length();    msg = get_monbuf(mlen);    msg->hdr.version = OSPF_MON_VERSION;    msg->hdr.retcode = 1;    msg->hdr.exact = req->hdr.exact;    msg->hdr.id = req->hdr.id;    if (lsap) {        MonRqLsa *lsarsp;	LShdr *hdr;	msg->hdr.retcode = 0;	lsarsp = &msg->body.lsarq;	lsarsp->area_id = lsap->lsa_ap ? hton32(lsap->lsa_ap->a_id) : 0;	lsarsp->ls_type = hton32(lsap->lsa_type);	lsarsp->ls_id = hton32(lsap->ls_id());	lsarsp->adv_rtr = hton32(lsap->adv_rtr());	hdr = BuildLSA(lsap);	memcpy((lsarsp + 1), hdr, lsap->ls_length());    }    sys->monitor_response(msg, LSA_Response, mlen, conn_id);}/* Respond to a query to access a Link-local LSA. */void OSPF::lllsa_stats(class MonMsg *req, int conn_id){    MonRqLLLsa *llreq;    InAddr if_addr;    int phyint;    aid_t taid;    byte ls_type;    lsid_t id;    rtid_t advrtr;    LSA *lsap;    int mlen;    MonMsg *msg;    char *phyname;    llreq = &req->body.lllsarq;    if_addr = ntoh32(llreq->if_addr);    phyint = ntoh32(llreq->phyint);    taid = ntoh32(llreq->taid);    ls_type = ntoh32(llreq->ls_type);    id = ntoh32(llreq->ls_id);    advrtr = ntoh32(llreq->adv_rtr);    lsap = 0;    if (req->hdr.exact != 0) {	SpfIfc *ip;	if (taid != 0)	    ip = find_vl(taid, if_addr);	else	    ip = find_ifc(if_addr, phyint);	if (ip)	    lsap = FindLSA(ip, 0, ls_type, id, advrtr);    } else        lsap = NextLSA(if_addr, phyint, taid, ls_type, id, advrtr);    mlen = sizeof(MonHdr) + sizeof(MonRqLLLsa);    if (lsap)        mlen += lsap->ls_length();    msg = get_monbuf(mlen);    msg->hdr.version = OSPF_MON_VERSION;    msg->hdr.retcode = 1;    msg->hdr.exact = req->hdr.exact;    msg->hdr.id = req->hdr.id;    if (lsap) {        MonRqLLLsa *llrsp;	LShdr *hdr;	SpfIfc *ip;	ip = lsap->lsa_ifp;	msg->hdr.retcode = 0;	llrsp = &msg->body.lllsarq;	if (!ip->is_virtual()) {	    llrsp->if_addr = hton32(ip->if_addr);	    llrsp->taid = 0;	    phyname = sys->phyname(ip->if_phyint);	    strncpy(llrsp->phyname, phyname, MON_PHYLEN);	}	else {	    char *p;	    llrsp->taid = hton32(ip->transit_area()->id());	    llrsp->if_addr = hton32(*ip->vl_endpt());	    p = (char *) &llrsp->taid;	    sprintf(llrsp->phyname, "%d.%d.%d.%d",		    (int)p[0], (int)p[1], (int)p[2], (int)p[3]);	}	llrsp->phyint = hton32(ip->if_phyint);	llrsp->a_id = hton32(ip->area()->id());	llrsp->ls_type = hton32(lsap->lsa_type);	llrsp->ls_id = hton32(lsap->ls_id());	llrsp->adv_rtr = hton32(lsap->adv_rtr());	hdr = BuildLSA(lsap);	memcpy((llrsp + 1), hdr, lsap->ls_length());    }    sys->monitor_response(msg, LLLSA_Response, mlen, conn_id);}/* Get information concerning a routing table entry. */void OSPF::rte_stats(class MonMsg *req, int conn_id){    MonRqRte *rtereq;    InAddr net;    InMask mask;    INrte *rte;    int mlen;    MonMsg *msg;    rtereq = &req->body.rtrq;    net = ntoh32(rtereq->net);    mask = ntoh32(rtereq->mask);    if (req->hdr.exact != 0)        rte = inrttbl->find(net, mask);    else {        INiterator iter(inrttbl);	iter.seek(net, mask);	do {	    rte = iter.nextrte();	} while (rte && !rte->valid());    }    mlen = sizeof(MonHdr) + sizeof(RteRsp);    msg = get_monbuf(mlen);    msg->hdr.version = OSPF_MON_VERSION;    msg->hdr.retcode = 1;    msg->hdr.exact = req->hdr.exact;    msg->hdr.id = req->hdr.id;    if (rte && rte->valid()) {        RteRsp *rtersp;	int n;	extern char *rtt_ascii[];	msg->hdr.retcode = 0;	rtersp = &msg->body.rtersp;	rtersp->net = hton32(rte->net());	rtersp->mask = hton32(rte->mask());	strncpy(rtersp->type, rtt_ascii[rte->type()], MON_RTYPELEN);	if (rte->intra_AS() || rte->t2cost == Infinity) {	    rtersp->cost = hton32(rte->cost);	    rtersp->o_cost = 0;	}	else {	    rtersp->cost = hton32(rte->t2cost);	    rtersp->o_cost = hton32(rte->cost);	}	rtersp->tag = hton32(rte->tag);	n = rte->r_mpath ? rte->r_mpath->npaths : 0;	rtersp->npaths = hton32(n);	for (int i = 0; i < n; i++) {	    char *phyname;	    phyname = sys->phyname(rte->r_mpath->NHs[i].phyint);	    rtersp->hops[i].phyname[0] = '\0';	    if (phyname)	        strncpy(rtersp->hops[i].phyname, phyname, MON_PHYLEN);	    rtersp->hops[i].gw = hton32(rte->r_mpath->NHs[i].gw);	}    }    sys->monitor_response(msg, Rte_Response, mlen, conn_id);}/* Respond to a query to get the next Opaque-LSA. */void OSPF::opq_stats(class MonMsg *req, int conn_id){    aid_t a_id;    int phyint;    InAddr if_addr;    LShdr *hdr;    int mlen;    MonMsg *msg;    bool success;    success = get_next_opq(conn_id, phyint, if_addr, a_id, hdr);    mlen = sizeof(MonHdr) + sizeof(OpqRsp);    if (success)        mlen += ntoh16(hdr->ls_length);    msg = get_monbuf(mlen);    msg->hdr.version = OSPF_MON_VERSION;    msg->hdr.retcode = 1;    msg->hdr.exact = 1;    msg->hdr.id = req->hdr.id;    if (success) {        OpqRsp *opqrsp;	msg->hdr.retcode = 0;	opqrsp = &msg->body.opqrsp;	opqrsp->phyint = hton32(phyint);	opqrsp->if_addr = hton32(if_addr);	opqrsp->a_id = hton32(a_id);	memcpy((opqrsp + 1), hdr, ntoh16(hdr->ls_length));    }    sys->monitor_response(msg, OpqLSA_Response, mlen, conn_id);}/* Utility routines used to "get" and "get-next". *//* Find the next interface data structure given the * previous IP address and its physical interface. * Only used for real interfaces, and not virtual links. */SpfIfc  *OSPF::next_ifc(uns32 xaddr, int phy){    IfcIterator iter(this);    SpfIfc *ip;    SpfIfc *best;    printf("ifcs = %p\n", ifcs);    best = 0;    while ((ip = iter.get_next())) {	printf("next_ifc, ip=%p\n", ip);	if (ip->is_virtual())	    continue;	if (phy > ip->if_phyint)	    continue;	if (phy == ip->if_phyint && xaddr >= ip->if_addr)	    continue;	if (best) {	    if (best->if_phyint < ip->if_phyint)	        continue;	    if (best->if_phyint == ip->if_phyint &&		best->if_addr <  ip->if_addr)	        continue;	}	// New best	best = ip;    }    return(best);}/* Find a virtual link based on its transit area and * endpoint. */SpfIfc *OSPF::find_vl(aid_t transit_id, rtid_t endpt){    SpfArea *tap;    RTRrte *rte;    if (!(tap = FindArea(transit_id)))	return(0);    if (!(rte = tap->find_abr(endpt)))	return(0);    return(rte->VL);}/* Find the next virtual link based on the previous virtual * link's transit area and endpoint. */SpfIfc *OSPF::next_vl(aid_t transit_id, rtid_t endpt){    AreaIterator aiter(this);    SpfArea *tap;    RTRrte *rte;    VLIfc *vl;    VLIfc *best;    best = 0;    while ((tap = aiter.get_next())) {        AVLsearch avls(&tap->abr_tbl);        if (transit_id > tap->a_id)	    continue;	while ((rte = (RTRrte *)avls.next())) {	    if (!(vl = rte->VL))	        continue;	    if (transit_id == tap->a_id && endpt >= vl->if_nbrid)		continue;	    if (best) {	        if (best->if_tap->a_id < vl->if_tap->a_id)	            continue;		if (best->if_tap->a_id == vl->if_tap->a_id &&		    best->if_nbrid <  vl->if_nbrid)		    continue;	    }	    // New best	    best = vl;	}    }       return(best);}/* Find a neighbor based on its physical interface and * IP address. * Used for monitoring purposes only, and only for * non-virtual neighbors. */SpfNbr *OSPF::find_nbr(InAddr nbr_addr, int phy){    IfcIterator iter(this);    SpfIfc *ip;    SpfNbr *np;    while ((ip = iter.get_next())) {	NbrIterator niter(ip);	if (ip->is_virtual())	    continue;	if (phy != ip->if_phyint)	    continue;	while ((np = niter.get_next())) {	    if (np->n_addr == nbr_addr)	        return(np);	}    }    return(0);}/* Find the next neighbor based on the previous neighbor's * physical interface and IP address. * Used for monitoring purposes only, and only for * non-virtual neighbors. */SpfNbr *OSPF::next_nbr(InAddr nbr_addr, int phy){    IfcIterator iter(this);    SpfIfc *ip;    SpfNbr *np;    SpfNbr *best;    best = 0;    while ((ip = iter.get_next())) {	NbrIterator niter(ip);	if (ip->is_virtual())	    continue;	if (phy > ip->if_phyint)	    continue;	while ((np = niter.get_next())) {	    if (phy == ip->if_phyint && nbr_addr >= np->n_addr)	        continue;	    if (best) {	        if (best->n_ifp->if_phyint < ip->if_phyint)	            continue;	        if (best->n_ifp->if_phyint == ip->if_phyint &&		    best->n_addr < np->n_addr)	            continue;	    } 	    // New best	    best = np;	}    }    return(best);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -