#include<string>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<limits>

#include "nlsr.hpp"
#include "nlsr_lsa.hpp"
#include "nlsr_npl.hpp"
#include "nlsr_adjacent.hpp"
#include "utility/nlsr_tokenizer.hpp"


namespace nlsr
{

    using namespace std;


    string
    NameLsa::getNameLsaKey()
    {
        string key;
        key=origRouter + "/" + boost::lexical_cast<std::string>(1);
        return key;
    }

    NameLsa::NameLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt, Npl npl)
    {
        origRouter=origR;
        lsType=lst;
        lsSeqNo=lsn;
        lifeTime=lt;
        std::list<string> nl=npl.getNameList();
        for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++)
        {
            addNameToLsa((*it));
        }
    }

    string
    NameLsa::getNameLsaData()
    {
        string nameLsaData;
        nameLsaData=origRouter + "|" + boost::lexical_cast<std::string>(1) + "|"
                    + boost::lexical_cast<std::string>(lsSeqNo) + "|"
                    + boost::lexical_cast<std::string>(lifeTime);
        nameLsaData+="|";
        nameLsaData+=boost::lexical_cast<std::string>(npl.getNplSize());
        std::list<string> nl=npl.getNameList();
        for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++)
        {
            nameLsaData+="|";
            nameLsaData+=(*it);
        }
        return nameLsaData+"|";
    }

    bool
    NameLsa::initNameLsaFromContent(string content)
    {
        uint32_t numName=0;
        nlsrTokenizer nt(content, "|");
        origRouter=nt.getNextToken();
        if(origRouter.empty())
        {
            return false;
        }
        try
        {
            lsType=boost::lexical_cast<uint8_t>(nt.getNextToken());
            lsSeqNo=boost::lexical_cast<uint32_t>(nt.getNextToken());
            lifeTime=boost::lexical_cast<uint32_t>(nt.getNextToken());
            numName=boost::lexical_cast<uint32_t>(nt.getNextToken());
        }
        catch(std::exception &e)
        {
            return false;
        }
        for(int i=0; i<numName; i++)
        {
            string name=nt.getNextToken();
            addNameToLsa(name);
        }
        return true;
    }

    std::ostream&
    operator<<(std::ostream& os, NameLsa& nLsa)
    {
        os<<"Name Lsa: "<<endl;
        os<<"  Origination Router: "<<nLsa.getOrigRouter()<<endl;
        os<<"  Ls Type: "<<(unsigned short)nLsa.getLsType()<<endl;
        os<<"  Ls Seq No: "<<(unsigned int)nLsa.getLsSeqNo()<<endl;
        os<<"  Ls Lifetime: "<<(unsigned int)nLsa.getLifeTime()<<endl;
        os<<"  Names: "<<endl;
        int i=1;
        std::list<string> nl=nLsa.getNpl().getNameList();
        for( std::list<string>::iterator it=nl.begin(); it != nl.end(); it++)
        {
            os<<"    Name "<<i<<": "<<(*it)<<endl;
        }
        return os;
    }



    CorLsa::CorLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt
                   , double r, double theta)
    {
        origRouter=origR;
        lsType=lst;
        lsSeqNo=lsn;
        lifeTime=lt;
        corRad=r;
        corTheta=theta;
    }

    string
    CorLsa::getCorLsaKey()
    {
        string key;
        key=origRouter + "/" + boost::lexical_cast<std::string>(3);
        return key;
    }

    bool
    CorLsa::isLsaContentEqual(CorLsa& clsa)
    {
        return (std::abs(corRad - clsa.getCorRadius()) <
                std::numeric_limits<double>::epsilon()) &&
               (std::abs(corTheta - clsa.getCorTheta()) <
                std::numeric_limits<double>::epsilon());
    }

    string
    CorLsa::getCorLsaData()
    {
        string corLsaData;
        corLsaData=origRouter + "|";
        corLsaData+=(boost::lexical_cast<std::string>(3) + "|");
        corLsaData+=(boost::lexical_cast<std::string>(lsSeqNo) + "|");
        corLsaData+=(boost::lexical_cast<std::string>(lifeTime) + "|");
        corLsaData+=(boost::lexical_cast<std::string>(corRad) + "|");
        corLsaData+=(boost::lexical_cast<std::string>(corTheta) + "|");
        return corLsaData;
    }

    bool
    CorLsa::initCorLsaFromContent(string content)
    {
        nlsrTokenizer nt(content, "|");
        origRouter=nt.getNextToken();
        if(origRouter.empty())
        {
            return false;
        }
        try
        {
            lsType=boost::lexical_cast<uint8_t>(nt.getNextToken());
            lsSeqNo=boost::lexical_cast<uint32_t>(nt.getNextToken());
            lifeTime=boost::lexical_cast<uint32_t>(nt.getNextToken());
            corRad=boost::lexical_cast<double>(nt.getNextToken());
            corTheta=boost::lexical_cast<double>(nt.getNextToken());
        }
        catch(std::exception &e)
        {
            return false;
        }
        return true;
    }

    std::ostream&
    operator<<(std::ostream& os, CorLsa& cLsa)
    {
        os<<"Cor Lsa: "<<endl;
        os<<"  Origination Router: "<<cLsa.getOrigRouter()<<endl;
        os<<"  Ls Type: "<<(unsigned short)cLsa.getLsType()<<endl;
        os<<"  Ls Seq No: "<<(unsigned int)cLsa.getLsSeqNo()<<endl;
        os<<"  Ls Lifetime: "<<(unsigned int)cLsa.getLifeTime()<<endl;
        os<<"    Hyperbolic Radius: "<<cLsa.getCorRadius()<<endl;
        os<<"    Hyperbolic Theta: "<<cLsa.getCorTheta()<<endl;
        return os;
    }


    AdjLsa::AdjLsa(string origR, uint8_t lst, uint32_t lsn, uint32_t lt,
                   uint32_t nl ,Adl padl)
    {
        origRouter=origR;
        lsType=lst;
        lsSeqNo=lsn;
        lifeTime=lt;
        noLink=nl;
        std::list<Adjacent> al=padl.getAdjList();
        for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++)
        {
            if((*it).getStatus()==1)
            {
                addAdjacentToLsa((*it));
            }
        }
    }

    string
    AdjLsa::getAdjLsaKey()
    {
        string key;
        key=origRouter + "/" + boost::lexical_cast<std::string>(2);
        return key;
    }

    bool
    AdjLsa::isLsaContentEqual(AdjLsa& alsa)
    {
        return adl.isAdlEqual(alsa.getAdl());
    }


    string
    AdjLsa::getAdjLsaData()
    {
        string adjLsaData;
        adjLsaData=origRouter + "|" + boost::lexical_cast<std::string>(2) + "|"
                   + boost::lexical_cast<std::string>(lsSeqNo) + "|"
                   + boost::lexical_cast<std::string>(lifeTime);
        adjLsaData+="|";
        adjLsaData+=boost::lexical_cast<std::string>(adl.getAdlSize());
        std::list<Adjacent> al=adl.getAdjList();
        for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++)
        {
            adjLsaData+="|";
            adjLsaData+=(*it).getAdjacentName();
            adjLsaData+="|";
            adjLsaData+=boost::lexical_cast<std::string>((*it).getConnectingFace());
            adjLsaData+="|";
            adjLsaData+=boost::lexical_cast<std::string>((*it).getLinkCost());
        }
        return adjLsaData+"|";
    }

    bool
    AdjLsa::initAdjLsaFromContent(string content)
    {
        uint32_t numLink=0;
        nlsrTokenizer nt(content, "|");
        origRouter=nt.getNextToken();
        if(origRouter.empty())
        {
            return false;
        }
        try
        {
            lsType=boost::lexical_cast<uint8_t>(nt.getNextToken());
            lsSeqNo=boost::lexical_cast<uint32_t>(nt.getNextToken());
            lifeTime=boost::lexical_cast<uint32_t>(nt.getNextToken());
            numLink=boost::lexical_cast<uint32_t>(nt.getNextToken());
        }
        catch(std::exception &e)
        {
            return false;
        }
        for(int i=0; i< numLink; i++)
        {
            try
            {
                string adjName=nt.getNextToken();
                int connectingFace=boost::lexical_cast<int>(nt.getNextToken());
                double linkCost=boost::lexical_cast<double>(nt.getNextToken());
                Adjacent adjacent(adjName, connectingFace, linkCost, 0, 0);
                addAdjacentToLsa(adjacent);
            }
            catch( std::exception &e )
            {
                return false;
            }
        }
        return true;
    }


    void
    AdjLsa::addNptEntriesForAdjLsa(Nlsr& pnlsr)
    {
        if ( getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
        {
            pnlsr.getNpt().addNpte(getOrigRouter(), getOrigRouter(),pnlsr);
        }
    }


    void
    AdjLsa::removeNptEntriesForAdjLsa(Nlsr& pnlsr)
    {
        if ( getOrigRouter() !=pnlsr.getConfParameter().getRouterPrefix() )
        {
            pnlsr.getNpt().removeNpte(getOrigRouter(), getOrigRouter(),pnlsr);
        }
    }



    std::ostream&
    operator<<(std::ostream& os, AdjLsa& aLsa)
    {
        os<<"Adj Lsa: "<<endl;
        os<<"  Origination Router: "<<aLsa.getOrigRouter()<<endl;
        os<<"  Ls Type: "<<(unsigned short)aLsa.getLsType()<<endl;
        os<<"  Ls Seq No: "<<(unsigned int)aLsa.getLsSeqNo()<<endl;
        os<<"  Ls Lifetime: "<<(unsigned int)aLsa.getLifeTime()<<endl;
        os<<"  No Link: "<<(unsigned int)aLsa.getNoLink()<<endl;
        os<<"  Adjacents: "<<endl;
        int i=1;
        std::list<Adjacent> al=aLsa.getAdl().getAdjList();
        for( std::list<Adjacent>::iterator it=al.begin(); it != al.end(); it++)
        {
            os<<"    Adjacent "<<i<<": "<<endl;
            os<<"      Adjacent Name: "<<(*it).getAdjacentName()<<endl;
            os<<"      Connecting Face: "<<(*it).getConnectingFace()<<endl;
            os<<"      Link Cost: "<<(*it).getLinkCost()<<endl;
        }
        return os;
    }

}//namespace nlsr
