How to set Destination on ns3

84 views
Skip to first unread message

non

unread,
Nov 13, 2018, 9:28:18 AM11/13/18
to ns-3-users
Hello mate

I have a question for routing.

Now I'm try to modify destination on aodv.
So I add "SetDestination".
But it isn's work.
Could you help me?

If it is wrong, is there any other way to change the destination?


Thank you.


-----------code(aodv-routing-protocol.cc)-----------
bool
RoutingProtocol::RouteInput (Ptr<const Packet> p, const Ipv4Header &header,
                             Ptr<const NetDevice> idev, UnicastForwardCallback ucb,
                             MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
{
  NS_LOG_FUNCTION (this << p->GetUid () << header.GetDestination () << idev->GetAddress ());
  if (m_socketAddresses.empty ())
    {
      NS_LOG_LOGIC ("No aodv interfaces");
      return false;
    }
  NS_ASSERT (m_ipv4 != 0);
  NS_ASSERT (p != 0);
  // Check if input device supports IP
  NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0);
  int32_t iif = m_ipv4->GetInterfaceForDevice (idev);
  Ipv4Address dst = header.GetDestination ();
  Ipv4Address origin = header.GetSource ();

  // Deferred route request 
  if (idev == m_lo)
    {
      DeferredRouteOutputTag tag;
      if (p->PeekPacketTag (tag))
        {

        //Add
        header.SetDestination ("10.1.1.4");

          DeferredRouteOutput (p, header, ucb, ecb);
          return true;
        }
    }


-----error-------

../src/aodv/model/aodv-routing-protocol.cc:471:9: error: 'this' argument to member function 'SetDestination' has type 'const ns3::Ipv4Header', but function is not marked const

        header.SetDestination ("10.1.1.4");

        ^~~~~~

./ns3/ipv4-header.h:160:8: note: 'SetDestination' declared here

  void SetDestination (Ipv4Address destination);

       ^

1 warning and 1 error generated.

pdbarnes

unread,
Nov 14, 2018, 10:14:15 AM11/14/18
to ns-3-users
The header argument is const, so you can’t modify it. You’ll have to copy it and modify the copy.

Peter

non

unread,
Nov 15, 2018, 7:18:54 PM11/15/18
to ns-3-users

Ok, I understood.
Thank you very much Peter.

And I implemented it as follows.


------source(aodv-routing-protocol.cc)-------

          //Add
          Ipv4Header header2 = header;
          header2.SetSource (origin);
          header2.SetDestination ("10.1.1.17");

          DeferredRouteOutput (p, header2, ucb, ecb);


2018年11月15日木曜日 0時14分15秒 UTC+9 pdbarnes:
Reply all
Reply to author
Forward
0 new messages