udp socket

148 views
Skip to first unread message

derar

unread,
Dec 12, 2009, 11:08:31 PM12/12/09
to ns-3-users
hi all
i am building a content addressable network application. i have some
problem with the udp socket.
in my application i want to forward a packet from one node to another.
Can i create two sockets one for listening to incoming connection
request and another socket to forward a packet to any nodes? And how
to do that…?
Any suggestion please..

Mathieu Lacage

unread,
Dec 15, 2009, 6:37:12 AM12/15/09
to ns-3-...@googlegroups.com
On Sun, Dec 13, 2009 at 5:08 AM, derar <odera...@gmail.com> wrote:
hi all
i am building a content addressable network application. i have some
problem with the udp socket.
in my application i want to forward a packet from one node to another.
Can i create two sockets one for listening to incoming connection
request and another socket to forward a packet to any nodes?  And how

yes.
 
to do that…?

Ptr<Node> node = ...;
Ptr<SocketFactory> factory = node->GetObject<UdpSocketFactory> ();
Ptr<Socket> send = factory->CreateSocket();
Ptr<Socket> recv = factory->CreateSocket();

send->Bind (..);
recv->Bind (...);

// setup rx and tx callbacks, call Socket::Send from receive callback.


Mathieu
--
Mathieu Lacage <mathieu...@gmail.com>

derar

unread,
Dec 15, 2009, 8:26:20 PM12/15/09
to ns-3-users
Hi
it is not working.... let me explain the problem i have...
suppose i have three nodes A(10.1.1.1), B(10.1.1.2), and C(10.1.1.4).
Initially, all nodes create a socket for listening to incoming
connection request using the following code

CanNode::StartApplication (void)

{

NS_LOG_FUNCTION_NOARGS ();



if (m_socket == 0)

{

TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");

m_socket = Socket::CreateSocket (GetNode(), tid);

InetSocketAddress local = InetSocketAddress
(Ipv4Address::GetAny (),9);

m_socket->Bind (local);




}

m_socket->SetRecvCallback(MakeCallback(&CanNode::HandleRead, this));

m_socket->SetAcceptCallback ( MakeNullCallback<bool, Ptr<Socket>,
const Address &> (),

MakeCallback(&CanNode::HandleAccept, this));


ScheduleTransmit (Seconds(0.));


}



Node C sends a packet to node B using the following socket code
if (m_socket1 == 0)

{

TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");

m_socket1 = Socket::CreateSocket (GetNode(), tid);

m_socket1->Bind ();

m_socket1->Connect (InetSocketAddress ("10.1.1.2", 9));
}



m_socket1->SetRecvCallback(MakeCallback(&CanNode::HandleRead,
this));

m_socket1->SetAcceptCallback ( MakeNullCallback<bool, Ptr<Socket>,
const Address &> (),

MakeCallback(&CanNode::HandleAccept, this));



m_socket1->Send (p);


B receives the packet correctly...no problem

but when B wants to forward the same packet to node A using the
following code:

Ptr<Socket> outSocket = Socket::CreateSocket(GetNode(),
TypeId::LookupByName ("ns3::UdpSocketFactory"));

NS_ASSERT(outSocket != 0);

NS_ASSERT(outSocket->Bind() == 0);

NS_ASSERT(outSocket->Connect(InetSocketAddress("10.1.1.1",9)) ==
0);

outSocket->SetRecvCallback(MakeCallback
(&InitialCanNode::HandleRead, this));

outSocket->SetAcceptCallback ( MakeNullCallback<bool, Ptr<Socket>,
const Address &> (),

MakeCallback(&InitialCanNode::HandleAccept, this));

outSocket->Send(packet);




the simulator gives me the following error:

assert failed. file=../src/common/packet-tag-list.cc, line=139,
cond="cur->tid != tag.GetInstanceTypeId ()"

Command ['/home/Derar/ns-allinone-3.5/ns-3.5/build/debug/scratch/
firstcan'] exited with code -11




if i change the port number from 9 to any number the packet is sent
but ICMP is sent from C to B because the port is unreachable.

The same socket code is working when node c send a packet to node B,
but it is not working when node B forward the same packet to node A.


any suggestion please...i need a help



On Dec 15, 5:37 am, Mathieu Lacage <mathieu.lac...@gmail.com> wrote:
> Mathieu Lacage <mathieu.lac...@gmail.com>

Mathieu Lacage

unread,
Dec 17, 2009, 3:22:54 AM12/17/09
to ns-3-...@googlegroups.com
On Wed, Dec 16, 2009 at 2:26 AM, derar <odera...@gmail.com> wrote:
assert failed. file=../src/common/packet-tag-list.cc, line=139,
cond="cur->tid != tag.GetInstanceTypeId ()"

It's hard to really know what is going on in your code  without more details but this assert is telling you that some piece of code (a backtrace would help to pinpoint which piece of code) is adding a tag in a packet which already contains that tag (in case you wonder, I figured this out from the comment on line 136 in packet-tag-list.cc).

Again, without more information, I am shooting in the dark but I would bet that your packet reception callback in the socket is taking the received packet pointer and pushing it back into the send socket directly which, unfortunately, does not work. See UdpEchoServer::HandleRead in applications/udp-echo/udp-echo-server.cc for a workaround.

Mathieu
--
Mathieu Lacage <mathieu...@gmail.com>
Reply all
Reply to author
Forward
0 new messages