当前位置: 首页>>代码示例>>C++>>正文


C++ Router::addInterface方法代码示例

本文整理汇总了C++中Router::addInterface方法的典型用法代码示例。如果您正苦于以下问题:C++ Router::addInterface方法的具体用法?C++ Router::addInterface怎么用?C++ Router::addInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Router的用法示例。


在下文中一共展示了Router::addInterface方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: inferRouters

void NetworkTreeNode::inferRouters()
{
    if(inferredRouters.size() > 0)
    {
        return;
    }

    list<InetAddress*> interfaces = this->listInterfaces();
    
    // Remove duplicata (possible because ingress interface of neighborhood can be a contra-pivot)
    InetAddress previous(0);
    bool previousAssigned = false;
    for(list<InetAddress*>::iterator i = interfaces.begin(); i != interfaces.end(); ++i)
    {
        InetAddress *current = (*i);
        
        if(current == NULL)
            continue;
        
        if(previousAssigned && (*current) == previous)
            interfaces.erase(i--);
        
        previous = (*current);
        if(!previousAssigned)
            previousAssigned = true;
    }

    // First compute the smallest gap between IP IDs.
    unsigned short smallestGap = 65335;
    bool noHostNames = true;
    for(list<InetAddress*>::iterator i = interfaces.begin(); i != interfaces.end(); ++i)
    {
        for(list<InetAddress*>::iterator j = i; j != interfaces.end(); ++j)
        {
            if((*i) == (*j))
                continue;
            
            if(!(*i)->getStoredHostName().empty() && !(*j)->getStoredHostName().empty())
                noHostNames = false;
            
            if((*i)->hasIPIdentifier() && (*j)->hasIPIdentifier())
            {
                unsigned short thisGap = 0;
                unsigned short IPId1 = (*i)->getIPIdentifier();
                unsigned short IPId2 = (*j)->getIPIdentifier();
                if(IPId1 > IPId2)
                    thisGap = IPId1 - IPId2;
                else
                    thisGap = IPId2 - IPId1;
                
                if(thisGap > (65535 - MAX_IP_ID_DIFFERENCE))
                {
                    if(IPId1 > 60000)
                        thisGap = (65535 - IPId1) + IPId2;
                    else
                        thisGap = (65535 - IPId2) + IPId1;
                }
                
                if(thisGap < smallestGap)
                    smallestGap = thisGap;
            }
        }
    }
    
    // If not enough host names, above a threshold (for the gap), infers a router per interface.
    if(noHostNames && smallestGap > NO_ASSOCIATION_THRESHOLD)
    {
        for(list<InetAddress*>::iterator i = interfaces.begin(); i != interfaces.end(); ++i)
        {
            Router *curRouter = new Router();
            curRouter->addInterface(InetAddress(*(*i)));
            inferredRouters.push_back(curRouter);
        }
        
        /*
         * Some post-processing: removes the routers consisting of a single interface which happens 
         * to be a candidate contra-pivot of an ODD subnet.
         *
         * N.B.: checking the interface appears in the subnet responsive IPs list is enough, as the 
         * pivots were not listed at all in the potential interfaces.
         */
         
        for(list<Router*>::iterator i = inferredRouters.begin(); i != inferredRouters.end(); ++i)
        {
            if((*i)->getNbInterfaces() == 1)
            {
                InetAddress singleInterface = (*i)->getInterfacesList()->front();
                for(list<NetworkTreeNode*>::iterator j = children.begin(); j != children.end(); ++j)
                {
                    if((*j)->getType() == NetworkTreeNode::T_SUBNET)
                    {
                        SubnetSite *ss = (*j)->getAssociatedSubnet();
                        
                        if(ss->getStatus() == SubnetSite::ODD_SUBNET && 
                           ss->hasLiveInterface(singleInterface))
                        {
                            bool isALabel = false;
                            for(list<InetAddress>::iterator k = labels.begin(); 
                                k != labels.end(); 
                                ++k)
//.........这里部分代码省略.........
开发者ID:tartaruszen,项目名称:treenet,代码行数:101,代码来源:NetworkTreeNode.cpp


注:本文中的Router::addInterface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。