unable to call a method of a routing protocol from the simulation script !!

81 views
Skip to first unread message

Abdelbasset KABOU

unread,
Nov 23, 2014, 4:02:08 AM11/23/14
to ns-3-...@googlegroups.com

Hello all,

i am working on a new routing protocol (named "bp"), i try to call a function,  from my simulation script, executing some output stuff and printing the results in a csv file (forwarded packets, number of packet on MAC queue ...):

void MeshScenario::ScenarioReport()
{
    std::ofstream out (m_CSVReportFileName.c_str ());
    out << "NodeIndex, IPAddress, ForwardedPackets, VirtualPackets" << std::endl;
    for ( int i=0 ; i <  m_xSize * m_ySize ; i++)
        {
            out << i << ",";
            Ptr<ns3::bp::RoutingProtocol> RoutingLayer = meshRouters.Get(i) -> GetObject<Ipv4> ()
                                                        -> GetRoutingProtocol();
            NS_ASSERT(RoutingLayer);
            RoutingLayer-> nodeReport (out);
            out << std::endl;
        }
    out.close();
}


So i try to execute a method (nodeReport) in each node,  the problem is that i am not able to access to it :

./ns3/ptr.h:447:27: erreur: invalid conversion from ‘ns3::Ipv4RoutingProtocol*’ to ‘ns3::bp::RoutingProtocol*’ [-fpermissive]

 Any suggestion please?
 

Tommaso Pecorella

unread,
Nov 23, 2014, 9:06:59 AM11/23/14
to ns-3-...@googlegroups.com
I could suggest to read a good C++ manual, indeed.

Cheers,

T.
Message has been deleted

Abdelbasset KABOU

unread,
Nov 23, 2014, 9:59:30 AM11/23/14
to ns-3-...@googlegroups.com


Well, the problem was in using GetRoutingProtocol(), i should use GetObject<ns3::bp::RoutingProtocol>()  instead.

Ptr<ns3::bp::RoutingProtocol> RoutingLayer = meshRouters.Get(i) -> GetObject<Ipv4> ()
                                                                    -> GetObject<ns3::bp::RoutingProtocol> ();
RoutingLayer-> nodeReport (Stream);



Its compiling now but i still don't see the difference between GetRoutingProtocol(), and  GetObject<ns3::bp::RoutingProtocol> ()

Thanks a lot Mr @Pecorella :)

Tommaso Pecorella

unread,
Nov 24, 2014, 12:37:28 AM11/24/14
to ns-3-...@googlegroups.com
Hi,

the mistake was to use a generic RoutingProtocol pointer as a specific bp::RoutingProtocol pointer. I.e., to use the parent class pointer instead of the derived class pointer. C++ forbids to have an implicit cast of that kind, so you have to use an explicit cast (e.g., dynamic cast). An alternative is what you did, as is to ask the node for the aggregate object of the right kind.
An even cleaner alternative is to use this function:

Cheers,

T.

Abdelbasset KABOU

unread,
Nov 24, 2014, 3:04:12 AM11/24/14
to ns-3-...@googlegroups.com

Thanks a lot sir
Reply all
Reply to author
Forward
0 new messages