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

📄 xrl_rib_notifier.cc

📁 OLSR Implementation for XORP
💻 CC
字号:
/* * Department of Systems and Computer Engineering * Carleton University, CANADA * Copyright (c) 2004 Liang Qin, Department of Systems and Computer Engineering, * Carleton University * 1. Porting CRC's OLSR with QoS support to XORP 1.0, this release enable OLSR *    adds and deletes route entries to RIB in XORP, instead of to Linux kernel.  **///added by L.Qin, needed for in6_rtmsg#include <net/route.h>#include <sstream>#include "olsr_module.h"#include "libxorp/debug.h"#include "libxorp/xlog.h"#include "libxorp/eventloop.hh"#include "libxipc/xrl_std_router.hh"#include "xrl/interfaces/rib_xif.hh"#include "xrl_rib_notifier.h"#include "xrl_rib_notifierc.h"static const char* RIBNAME = "rib";extern EventLoop e;extern XrlStdRouter tgt_router;extern string wirelessCard;extern int numberofInterfaces;// get the wireless interface name// XrlRibNotifier implementation// static variable://	EventLoop e;//	XrlStdRouter xsr(e,"olsr");	static XrlRibNotifier* ribNotifier=NULL;// some wrapper functionsextern void init_XrlRibNotifier(){	if(!ribNotifier){	//	EventLoop e;	//	XrlStdRouter xsr(e,"olsr");		ribNotifier=new XrlRibNotifier( );                printf("~~~~RN pointer is initialized\n");        }}extern void clean_up_XrlRibNotifier(){	if(ribNotifier){	  delete ribNotifier;	  printf("~~~~RN pointer is deleted\n");        }}extern int add_route_to_RIB(const in6_rtmsg aRoute, char* ifName){	return (ribNotifier->send_add_route(aRoute, ifName));}extern int delete_route_to_RIB(const in6_rtmsg aRoute){	return ribNotifier->send_delete_route(aRoute);}XrlRibNotifier::XrlRibNotifier( )	:eloop(e),className(tgt_router.class_name()),instanceName(tgt_router.instance_name()), aClient(&tgt_router){    set_status(READY);}/*XrlRibNotifier::XrlRibNotifier( )	:eloop(e),xsender(tgt_router),className(tgt_router.class_name()),instanceName(tgt_router.instance_name()), aClient(&xsender){    set_status(READY);}*/XrlRibNotifier::~XrlRibNotifier(){}boolXrlRibNotifier::startup(){    bool ucast = true;    bool mcast = true;    bool ok=true;//    XorpTimer t;//    EventLoop e;//    bool timeout=false;    //wait until module start//    t = e.set_flag_after_ms(2000, &timeout);//    while (!timeout){//       e.run();//    }            if (aClient.send_add_igp_table6(RIBNAME, "olsr", className,     	instanceName, ucast,mcast,	callback(this, &XrlRibNotifier::add_igp_cb,"add table to RIB\n")) == false) {	XLOG_ERROR("Failed to send table creation request.");	set_status(FAILED);    }    else{        printf(" sent out the request and return\n");    }    set_status(STARTING);	return ok;}voidXrlRibNotifier::add_igp_cb(const XrlError& xe, const char* comment){        if (xe != XrlError::OKAY()) {	XLOG_ERROR("add_igp failed: %s\n", xe.str().c_str());	set_status(FAILED);	return;    }    set_status(RUNNING);    printf("from OLSR startup %s\n",comment);}boolXrlRibNotifier::shutdown(){    set_status(SHUTTING_DOWN);//    XrlRibV0p1Client c(&xsender);    bool ucast = true;    bool mcast = false;    bool ok=true;    if (aClient.send_delete_igp_table6	(RIBNAME, "olsr", className, instanceName, ucast, mcast,	 callback(this, &XrlRibNotifier::delete_igp_cb)) == false) {	XLOG_ERROR("Failed to send table deletion request.");	set_status(FAILED);    }    return ok;}voidXrlRibNotifier::delete_igp_cb(const XrlError& e){    if (e != XrlError::OKAY()) {	set_status(FAILED);	return;    }    set_status(SHUTDOWN);}boolXrlRibNotifier::send_add_route(const in6_rtmsg aRoute, char* theinterface){char str[46];      //change fec0 to fe80     in6_rtmsg routeAdd=aRoute;     int aMetric=aRoute.rtmsg_metric;//      routeAdd.rtmsg_dst.s6_addr16[0]=33022;printf("add routeAdd.rtmsg_dst: %s\n",inet_ntop(AF_INET6,&routeAdd.rtmsg_dst,str,46));    bool ok;string routeIFname=string(theinterface);//if we have more than one interface//string routeIF=wirelessCard;//printf("we have interfaces %d\n",numberofInterfaces);//if(numberofInterfaces!=1){//		string buf1; //have a buffer string//		stringstream ss1(wirelessCard); //insert the string into a stream//		vector<string> tokens1; //creat vector to hold the interface names//		while (ss1 >> buf1){//			tokens1.push_back(buf1);//		}  //       int interfaceIndex=aRoute.rtmsg_ifindex;//	printf("The interface index is %d\n",interfaceIndex);//	routeIF=tokens1[interfaceIndex];	printf (" The interface sent to the RIB %s\n",routeIFname.c_str());//}//int len=routeIFname.length();// printf(" in Notifier the name is %s %d\n",routeIFname.c_str(),len);    IPv6 dst=IPv6(routeAdd.rtmsg_dst);    IPv6 gw=IPv6(routeAdd.rtmsg_gateway);    //constructing a IPv6 subnet address    IPNet<IPv6> subAddr=IPNet<IPv6>(dst,aRoute.rtmsg_dst_len);    printf("############before sending route to RIB\n");    ok = aClient.send_add_interface_route6(RIBNAME, "olsr", true, false,	       subAddr, gw,routeIFname,routeIFname,aMetric,//	       subAddr, gw,"eth1","eth1",aMetric,	       callback(this, &XrlRibNotifier::send_route_cb));    printf("############after sending route to RIB\n"); return ok;}boolXrlRibNotifier::send_delete_route(const in6_rtmsg aRoute){//    XrlRibV0p1Client c(&xsender);    bool ok;char str[46];printf(" \n");printf("----- --- ---- \n");     in6_rtmsg routeAdd=aRoute;printf("delete routeAdd.rtmsg_dst: %s\n",inet_ntop(AF_INET6,&routeAdd.rtmsg_dst,str,46)); //constructing a IPv6 subnet address    IPNet<IPv6> subAddr=IPNet<IPv6>(routeAdd.rtmsg_dst,aRoute.rtmsg_dst_len);ok=aClient.send_delete_route6(RIBNAME, "olsr", true, false, subAddr,	 callback(this, &XrlRibNotifier::send_route_cb)); return ok;}voidXrlRibNotifier::send_route_cb(const XrlError& xe){    printf("!!!!!!!!!callback %s\n",xe.str().c_str());    if (xe != XrlError::OKAY()) {	XLOG_ERROR("olsr send to rib Xrl error %s\n", xe.str().c_str());    }    printf("***---***from OLSR module\n");//    printf("***---***from OLSR module %s\n",comment);}

⌨️ 快捷键说明

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