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

📄 show_routes.cc

📁 xorp源码hg
💻 CC
📖 第 1 页 / 共 2 页
字号:
    string proto = rib_table_name(_opts.protocol, _opts.ribin);    XrlRibV0p1Client::RedistDisable4CB cb;    cb = callback(this, &ShowRoutesProcessor::request_cease_cb);    XrlRibV0p1Client rib(_rtr);    bool sent = false;    if (_opts.ipv4) {	sent = rib.send_redist_disable4(_opts.xrl_target.c_str(),					_rtr->instance_name(),					proto, _opts.unicast, !_opts.unicast,					_cookie, cb);    } else {	sent = rib.send_redist_disable6(_opts.xrl_target.c_str(),					_rtr->instance_name(),					proto, _opts.unicast, !_opts.unicast,					_cookie, cb);    }    if (sent == false) {	set_status(SERVICE_FAILED, "Failed to request redistribution end.");	return;    }    set_status(SERVICE_SHUTTING_DOWN);}voidShowRoutesProcessor::request_cease_cb(const XrlError& /* xe */){    set_status(SERVICE_SHUTDOWN);    return;}boolShowRoutesProcessor::check_cookie(const string& cookie){    if (cookie != _cookie) {	cerr << "Bug detected cookie mismatch \"" << cookie << "\" != \""	     << _cookie << "\"" << endl;    }    return true;}XrlCmdErrorShowRoutesProcessor::common_0_1_get_target_name(string& name){    name = this->name();    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::common_0_1_get_version(string& version){    version = this->version();    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::common_0_1_get_status(uint32_t&	status,					   string&	/* reason */){    switch (this->status()) {    case SERVICE_READY:		status = PROC_NULL;		break;    case SERVICE_STARTING:	status = PROC_STARTUP;		break;    case SERVICE_RUNNING:	status = PROC_READY;		break;    case SERVICE_PAUSED:					/* FALLTHRU */    case SERVICE_PAUSING:					/* FALLTHRU */    case SERVICE_RESUMING:	status = PROC_NOT_READY;	break;    case SERVICE_SHUTTING_DOWN:	status = PROC_SHUTDOWN;		break;    case SERVICE_SHUTDOWN:	status = PROC_DONE;		break;    case SERVICE_FAILED:	status = PROC_FAILED;		break;    case SERVICE_ALL:						break;    }    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::common_0_1_shutdown(){    this->shutdown();    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::finder_event_observer_0_1_xrl_target_birth(						const string& /* cls */,						const string& /* ins */						){    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::finder_event_observer_0_1_xrl_target_death(						const string& cls,						const string& /* ins */){    if (cls == _opts.xrl_target)	this->shutdown();    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::redist4_0_1_starting_route_dump(const string& cookie){    _cookie = cookie;    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::redist4_0_1_finishing_route_dump(const string& cookie){    check_cookie(cookie);    this->shutdown();    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::redist4_0_1_add_route(const IPv4Net&	dst,					   const IPv4&		nexthop,					   const string&	ifname,					   const string&	vifname,					   const uint32_t&	metric,					   const uint32_t&	admin_distance,					   const string&	cookie,					   const string&	protocol_origin){    if (this->status() != SERVICE_RUNNING || check_cookie(cookie) == false) {	return XrlCmdError::OKAY();    }    switch (this->_opts.print_style) {    case PRINT_STYLE_BRIEF:	display_route_brief(dst, nexthop, ifname, vifname, metric,			    admin_distance, protocol_origin);	break;    case PRINT_STYLE_DETAIL:	display_route_detail(dst, nexthop, ifname, vifname, metric,			     admin_distance, protocol_origin);	break;    case PRINT_STYLE_TERSE:	display_route_terse(dst, nexthop, ifname, vifname, metric,			    admin_distance, protocol_origin);	break;    }    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::redist4_0_1_delete_route(const IPv4Net&	dst,					      const IPv4&	nexthop,					      const string&	ifname,					      const string&	vifname,					      const uint32_t&	metric,					      const uint32_t&	admin_distance,					      const string&	cookie,					      const string&	protocol_origin){    // TODO: XXX: For now we ignore deletions that occur during route dump    UNUSED(dst);    UNUSED(nexthop);    UNUSED(ifname);    UNUSED(vifname);    UNUSED(metric);    UNUSED(admin_distance);    UNUSED(cookie);    UNUSED(protocol_origin);    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::redist6_0_1_starting_route_dump(const string& cookie){    check_cookie(cookie);    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::redist6_0_1_finishing_route_dump(const string& cookie){    check_cookie(cookie);    this->shutdown();    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::redist6_0_1_add_route(const IPv6Net&	dst,					   const IPv6&		nexthop,					   const string&	ifname,					   const string&	vifname,					   const uint32_t&	metric,					   const uint32_t&	admin_distance,					   const string&	cookie,					   const string&	protocol_origin){    if (this->status() != SERVICE_RUNNING || check_cookie(cookie) == false) {	return XrlCmdError::OKAY();    }    switch (this->_opts.print_style) {    case PRINT_STYLE_BRIEF:	display_route_brief(dst, nexthop, ifname, vifname, metric,			    admin_distance, protocol_origin);	break;    case PRINT_STYLE_DETAIL:	display_route_detail(dst, nexthop, ifname, vifname, metric,			     admin_distance, protocol_origin);	break;    case PRINT_STYLE_TERSE:	display_route_terse(dst, nexthop, ifname, vifname, metric,			    admin_distance, protocol_origin);	break;    }    return XrlCmdError::OKAY();}XrlCmdErrorShowRoutesProcessor::redist6_0_1_delete_route(const IPv6Net&	dst,					      const IPv6&	nexthop,					      const string&	ifname,					      const string&	vifname,					      const uint32_t&	metric,					      const uint32_t&	admin_distance,					      const string&	cookie,					      const string&	protocol_origin){    // TODO: XXX: For now we ignore deletions that occur during route dump    UNUSED(dst);    UNUSED(nexthop);    UNUSED(ifname);    UNUSED(vifname);    UNUSED(metric);    UNUSED(admin_distance);    UNUSED(cookie);    UNUSED(protocol_origin);    return XrlCmdError::OKAY();}// ----------------------------------------------------------------------------// Utility methodsstatic voidusage(){    fprintf(stderr,	    "Usage: %s [options] (ribin|ribout) (ipv4|ipv6) (unicast|multicast) <protocol>\n",	    xlog_process_name());    fprintf(stderr, "Options:\n");    fprintf(stderr, "\t -F <finder_host>:<finder_port> "	    "Specify Finder host and port to use.\n");    fprintf(stderr, "\t -T <targetname>                "	    "Specify XrlTarget to query.\n\n");    fprintf(stderr, "\t -b                             "	    "Brief output.\n");    fprintf(stderr, "\t -d                             "	    "Detailed output.\n");    fprintf(stderr, "\t -t                             "	    "Terse output.\n");    exit(-1);}static boolparse_finder_args(const string& host_colon_port, string& host, uint16_t& port){    string::size_type sp = host_colon_port.find(":");    if (sp == string::npos) {        host = host_colon_port;        // Do not set port, by design it has default finder port value.    } else {        host = string(host_colon_port, 0, sp);        string s_port = string(host_colon_port, sp + 1, 14);        uint32_t t_port = atoi(s_port.c_str());        if (t_port == 0 || t_port > 65535) {            XLOG_ERROR("Finder port %u is not in range 1--65535.\n",		       XORP_UINT_CAST(t_port));            return false;        }        port = (uint16_t)t_port;    }    return true;}static intfind_option(const char* s, const char* opts[], size_t n_opts){    for (size_t i = 0; i < n_opts; i++) {	if (strcmp(s, opts[i]) == 0) {	    return (int)i;	}    }    fprintf(stderr, "Invalid option \"%s\", expected one of:", s);    for (size_t i = 0; i < n_opts; i++) {	fprintf(stderr, "%s\"%s\"", (i == 0) ? " " : ", ", opts[i]);    }    fprintf(stderr, "\n");    return -1;}static inline boolmatch_binary_option(const char* input,		    const char* option1,		    const char* option2,		    bool&	matches_first){    const char* argv[2] = { option1, option2 };    int i = find_option(input, argv, 2);    if (i < 0)	return false;    matches_first = (i == 0) ? true : false;    return true;}// ----------------------------------------------------------------------------// Mainintmain(int argc, char* const argv[]){    //    // Initialize and start xlog    //    xlog_init(argv[0], NULL);    xlog_set_verbose(XLOG_VERBOSE_LOW);         // Least verbose messages    xlog_level_set_verbose(XLOG_LEVEL_ERROR, XLOG_VERBOSE_HIGH);    xlog_add_default_output();    xlog_start();    try {	bool		do_run 	    = true;	ShowRoutesOptions sr_opts;	sr_opts.finder_host = FinderConstants::FINDER_DEFAULT_HOST().str();        sr_opts.finder_port = FinderConstants::FINDER_DEFAULT_PORT();	sr_opts.xrl_target  = "rib";	int ch;	while ((ch = getopt(argc, argv, "bdtF:T:")) != -1) {	    switch (ch) {	    case 'b':		sr_opts.print_style = PRINT_STYLE_BRIEF;		break;	    case 'd':		sr_opts.print_style = PRINT_STYLE_DETAIL;		break;	    case 't':		sr_opts.print_style = PRINT_STYLE_TERSE;		break;	    case 'F':		do_run = parse_finder_args(optarg,					   sr_opts.finder_host,					   sr_opts.finder_port);		break;	    case 'T':		sr_opts.xrl_target = optarg;		break;	    default:		usage();		do_run = false;	    }	}	argc -= optind;	argv += optind;	if (argc != 4) {	    usage();	}	if (match_binary_option(argv[0], "ribin", "ribout", sr_opts.ribin)	    == false) {	    usage();	}	if (match_binary_option(argv[1], "ipv4", "ipv6", sr_opts.ipv4)	    == false) {	    usage();	}	if (match_binary_option(argv[2], "unicast", "multicast",				sr_opts.unicast) == false) {	    usage();	}	sr_opts.protocol = argv[3];	EventLoop e;	ShowRoutesProcessor srp(e, sr_opts);	srp.startup();	//	// Print the headers	//	switch (sr_opts.print_style) {	case PRINT_STYLE_BRIEF:	    // XXX: no header	    break;	case PRINT_STYLE_DETAIL:	    // XXX: no header	    break;	case PRINT_STYLE_TERSE:	    cout << "Destination        P Prf  Metric 1  Next hop          ";	    // XXX: Will we have all this info in the RIB - Metric2, AS path?	    // cout << "A Destination        P Prf  Metric 1  Metric 2  "	    // "Next hop          AS path";	    cout << endl;	    break;	}	while ((srp.status() != SERVICE_FAILED)	       && (srp.status() != SERVICE_SHUTDOWN)) {	    e.run();	}	if (srp.status() == SERVICE_FAILED) {	    srp.shutdown();	    if (srp.status_note().empty() == false) {		cout << srp.status_note() << endl;	    } else {		cout << "Failed" << endl;	    }	    cout << endl;	}    } catch (...) {	xorp_print_standard_exceptions();    }    //    // Gracefully stop and exit xlog    //    xlog_stop();    xlog_exit();    return 0;}

⌨️ 快捷键说明

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