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

📄 monitor.c

📁 BCAST Implementation for NS2
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *   OSPFD routing daemon *   Copyright (C) 1998 by John T. Moy *    *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. *    *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. *    *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "ospfinc.h"#include "monitor.h"#include "system.h"#include "ifcfsm.h"/* If necessary, allocate an area in which to construct * a monitor response. */MonMsg *OSPF::get_monbuf(int size){    if (size > mon_size) {	mon_size = size;	delete [] mon_buff;	mon_buff = new byte[size];    }    return((MonMsg *)mon_buff);}/* Get global OSPF statistics. */void OSPF::global_stats(MonMsg *req, int conn_id){    int mlen;    MonMsg *msg;    printf("----\nglobal_stats\n");    mlen = sizeof(MonHdr) + sizeof(StatRsp);    msg = get_monbuf(mlen);    msg->hdr.version = OSPF_MON_VERSION;    msg->hdr.retcode = 0;    msg->hdr.exact = 0;    msg->hdr.id = req->hdr.id;    msg->body.statrsp.router_id = hton32(myid);    msg->body.statrsp.n_aselsas = hton32(extLSAs.size());    msg->body.statrsp.asexsum = hton32(ase_xsum);    msg->body.statrsp.n_ase_import = hton32(n_extImports);    msg->body.statrsp.extdb_limit = hton32(ExtLsdbLimit);    msg->body.statrsp.n_dijkstra = hton32(n_dijkstras);    msg->body.statrsp.n_area = hton16(n_area);    msg->body.statrsp.n_dbx_nbrs = hton16(n_dbx_nbrs);    msg->body.statrsp.mospf = g_mospf_enabled ? 1 : 0;    msg->body.statrsp.inter_area_mc = inter_area_mc ? 1 : 0;    msg->body.statrsp.inter_AS_mc = inter_AS_mc;    msg->body.statrsp.overflow_state = OverflowState ? 1 : 0;    msg->body.statrsp.vmajor = vmajor;    msg->body.statrsp.vminor = vminor;    msg->body.statrsp.fill1 = 0;    msg->body.statrsp.n_orig_allocs = hton32(n_orig_allocs);    sys->monitor_response(msg, Stat_Response, mlen, conn_id);}/* Get area statistics. */void OSPF::area_stats(class MonMsg *req, int conn_id){    MonRqArea *areq;    aid_t a_id;    SpfArea *ap;    int mlen;    MonMsg *msg;    areq = &req->body.arearq;    a_id = ntoh32(areq->area_id);    if (req->hdr.exact != 0)        ap = FindArea(a_id);    else	ap = NextArea(a_id);    mlen = sizeof(MonHdr) + sizeof(AreaRsp);    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 (ap) {        AreaRsp *arsp;	IfcIterator iter(ap);	int i;	msg->hdr.retcode = 0;	arsp = &msg->body.arearsp;	arsp->area_id = hton32(ap->a_id);	arsp->n_ifcs = hton16(ap->n_active_if);	for (i = 0; iter.get_next(); )	    i++;	arsp->n_cfgifcs = hton16(i);	arsp->n_routers = hton16(ap->n_routers);	arsp->n_rtrlsas = hton16(ap->rtrLSAs.size());	arsp->n_netlsas = hton16(ap->netLSAs.size());	arsp->n_summlsas = hton16(ap->summLSAs.size());	arsp->n_asbrlsas = hton16(ap->asbrLSAs.size());	arsp->n_grplsas = hton16(ap->grpLSAs.size());	arsp->dbxsum = hton32(ap->db_xsum);	arsp->transit = ap->a_transit ? 1 : 0;	arsp->demand = ap->donotage() ? 1 : 0;	arsp->stub = ap->a_stub ? 1 : 0;	arsp->import_summ = ap->a_import ? 1 : 0;	arsp->n_ranges = hton32(ap->ranges.size());    }    sys->monitor_response(msg, Area_Response, mlen, conn_id);}/* Respond to a query for an interface's statistics. */void OSPF::interface_stats(class MonMsg *req, int conn_id){    MonRqIfc *ireq;    int phyint;    InAddr addr;    int mlen;    MonMsg *msg;    SpfIfc *ip;    printf("----\ninterface_stats\n");    ireq = &req->body.ifcrq;    phyint = ntoh32(ireq->phyint);    printf("phyint = %d\n", phyint);    addr = ntoh32(ireq->if_addr);    printf("addr = %x, exact=%d\n", addr, req->hdr.exact);    if (req->hdr.exact != 0)        ip = find_ifc(addr, phyint);    else	ip = next_ifc(addr, phyint);    mlen = sizeof(MonHdr) + sizeof(IfcRsp);    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 (ip) {        IfcRsp *irsp;	msg->hdr.retcode = 0;	irsp = &msg->body.ifcrsp;	ip->dump_stats(irsp);    }    sys->monitor_response(msg, Ifc_Response, mlen, conn_id);}/* Dump an interface's statistics in a form that can be * sent to other computers for analysis. */void SpfIfc::dump_stats(IfcRsp *irsp){    char *ifstates(int);    char *iftypes(int);    char *phyname;    printf("----\ndump_stats\n");    irsp->if_addr = transit_area() ? hton32(*vl_endpt()) : hton32(if_addr);    irsp->if_phyint = hton32(if_phyint);    irsp->if_mask = hton32(if_mask);    irsp->area_id = hton32(if_area->id());    irsp->transit_id = transit_area() ? hton32(transit_area()->id()) : 0;    irsp->endpt_id = vl_endpt() ? hton32(*vl_endpt()) : 0;    irsp->if_IfIndex = hton32(if_IfIndex);    irsp->if_dint = hton32(if_dint);    irsp->if_pint = hton32(if_pint);    irsp->if_dr = hton32(if_dr);    irsp->if_bdr = hton32(if_bdr);    irsp->mtu = hton16(if_mtu);    irsp->if_cost = hton16(cost());    irsp->if_hint = hton16(if_hint);    irsp->if_autype = hton16(if_autype);    irsp->if_rxmt = if_rxmt;    irsp->if_xdelay = if_xdelay;    irsp->if_drpri = if_drpri;    irsp->if_demand = (if_demand ? 1 : 0);    irsp->if_mcfwd = if_mcfwd;    irsp->if_nnbrs = if_nnbrs;    irsp->if_nfull = if_nfull;    irsp->pad1 = 0;    strncpy(irsp->if_state, ifstates(if_state), MON_STATELEN);    strncpy(irsp->type, iftypes(type()), MON_ITYPELEN);    if (!transit_area()) {	phyname = sys->phyname(if_phyint);	strncpy(irsp->phyname, phyname, MON_PHYLEN);    }    else {        InAddr area_id;	char *p;	area_id = hton32(transit_area()->id());	p = (char *) &area_id;	sprintf(irsp->phyname, "%d.%d.%d.%d",		(int)p[0], (int)p[1], (int)p[2], (int)p[3]);    }}/* Respond to a query for a virtual link's statistics. */void OSPF::vl_stats(class MonMsg *req, int conn_id){    MonRqVL *vlreq;    InAddr taid;    InAddr endpt;    int mlen;    MonMsg *msg;    SpfIfc *ip;    vlreq = &req->body.vlrq;    taid = ntoh32(vlreq->transit_area);    endpt = ntoh32(vlreq->endpoint_id);    if (req->hdr.exact != 0)        ip = find_vl(taid, endpt);    else	ip = next_vl(taid, endpt);    mlen = sizeof(MonHdr) + sizeof(IfcRsp);    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 (ip) {        IfcRsp *irsp;	msg->hdr.retcode = 0;	irsp = &msg->body.ifcrsp;	ip->dump_stats(irsp);    }    sys->monitor_response(msg, Ifc_Response, mlen, conn_id);}/* Respond to a query for a neighbor's statistics. */void OSPF::neighbor_stats(class MonMsg *req, int conn_id){    MonRqNbr *nreq;    int phyint;    InAddr addr;    int mlen;    MonMsg *msg;    SpfNbr *np;    nreq = &req->body.nbrrq;    phyint = ntoh32(nreq->phyint);    addr = ntoh32(nreq->nbr_addr);    if (req->hdr.exact != 0)        np = find_nbr(addr, phyint);    else	np = next_nbr(addr, phyint);    mlen = sizeof(MonHdr) + sizeof(NbrRsp);    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 (np) {        NbrRsp *nrsp;	msg->hdr.retcode = 0;	nrsp = &msg->body.nbrsp;	np->dump_stats(nrsp);    }    sys->monitor_response(msg, Nbr_Response, mlen, conn_id);}/* Dump the neighbor's statistics into a form suitable * for shipment to another program. Used for both real * neighbors and virtual neighbors. */void SpfNbr::dump_stats(NbrRsp *nrsp){    char *nbrstates(int);    char *phyname;    nrsp->n_addr = hton32(addr());    nrsp->n_id = hton32(id());    nrsp->phyint = hton32(n_ifp->if_phyint);    nrsp->transit_id = n_ifp->transit_area() 		       ? hton32(n_ifp->transit_area()->id()) : 0;    nrsp->endpt_id = n_ifp->vl_endpt() ? hton32(*n_ifp->vl_endpt()) : 0;    nrsp->n_ddlst = hton32(n_ddlst.count());    nrsp->n_rqlst = hton32(n_rqlst.count());    nrsp->rxmt_count = hton32(rxmt_count);    nrsp->n_rxmt_window = hton32(n_rxmt_window);    nrsp->n_dr = hton32(n_dr);    nrsp->n_bdr = hton32(n_bdr);    nrsp->n_opts= n_opts;    nrsp->n_imms= n_imms;    nrsp->n_adj_pend = n_adj_pend;    nrsp->n_pri = n_pri;    strncpy(nrsp->n_state, nbrstates(n_state), MON_STATELEN);    if (!n_ifp->transit_area()) {	phyname = sys->phyname(n_ifp->if_phyint);	strncpy(nrsp->phyname, phyname, MON_PHYLEN);    }    else {        InAddr area_id;	char *p;	area_id = hton32(n_ifp->transit_area()->id());	p = (char *) &area_id;	sprintf(nrsp->phyname, "%d.%d.%d.%d",		(int)p[0], (int)p[1], (int)p[2], (int)p[3]);    }}/* Respond to a query for a virtual neighbor's statistics. */void OSPF::vlnbr_stats(class MonMsg *req, int conn_id){    MonRqVL *vlreq;    InAddr taid;    InAddr endpt;    int mlen;    MonMsg *msg;    SpfIfc *ip;    vlreq = &req->body.vlrq;    taid = ntoh32(vlreq->transit_area);    endpt = ntoh32(vlreq->endpoint_id);    if (req->hdr.exact != 0)        ip = find_vl(taid, endpt);    else	ip = next_vl(taid, endpt);    mlen = sizeof(MonHdr) + sizeof(NbrRsp);    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 (ip && ip->if_nlst) {        NbrRsp *nrsp;	msg->hdr.retcode = 0;	nrsp = &msg->body.nbrsp;	ip->if_nlst->dump_stats(nrsp);    }    sys->monitor_response(msg, Nbr_Response, mlen, conn_id);}/* Respond to a query to access an OSPF LSA. */void OSPF::lsa_stats(class MonMsg *req, int conn_id){    MonRqLsa *lsareq;    aid_t a_id;

⌨️ 快捷键说明

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