Darius Malysiak
unread,Apr 3, 2012, 11:26:16 AM4/3/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ns-3-users
Hello,
i am currently trying to send packets over a packet socket, i already
succeded in receiving packets via a packet socket. Yet, i had no
success in sending them. Each time i receive the following output /
error:
0
assert failed. cond="m_current + delta <= m_dataEnd", file=./ns3/
buffer.h, line=678
Here is my code:
void startFlowPacketSocket(Ptr<Socket> localSocket, uint32_t nBytes)
{
Ptr<ns3::Packet> packet = Create<Packet>(nBytes);
int accepted_bytes = localSocket->Send(packet);
printf("%d\n", accepted_bytes);
}
Ptr<Socket> initPacketSocket(Ptr<Node> c0, unsigned int ifIndex,
Address target)
{
Ptr<Socket> localSocket = Socket::CreateSocket(c0,
PacketSocketFactory::GetTypeId());
//only for packetsockets
ns3::PacketSocketAddress sinkAddress;
sinkAddress.SetSingleDevice (ifIndex); // set outgoing interface
for outgoing packets
sinkAddress.SetPhysicalAddress(target); // set destination address
for outgoing packets
sinkAddress.SetProtocol(2); // set arbitrary protocol for
outgoing packets
if(localSocket->Bind() ==-1)
{
printf("error during binding on source\n");
}
//only for packet sockets
if(localSocket->Connect(sinkAddress) ==-1)
{
printf("error during connect on source\n");
}
return localSocket;
}
int main (int argc, char *argv[])
{
//create a node container
NodeContainer c0;
//create two nodes inside the container
c0.Create (2);
//create csma channel and configure attributes
CsmaHelper csma;
csma.SetChannelAttribute("DataRate", StringValue ("10Mbps"));
csma.SetChannelAttribute("Delay", TimeValue (MicroSeconds(500)));
NetDeviceContainer devices = csma.Install (c0);
//add internet stack to nodes
InternetStackHelper internet;
internet.Install (c0);
//add ip addresses to csma devices
Ipv4AddressHelper ipv4;
ipv4.SetBase("192.168.0.0", "255.255.255.0");
Ipv4InterfaceContainer ipInterfaces = ipv4.Assign(devices);
Ptr<Socket> localSocket = initPacketSocket(c0,devices.Get(0)-
>GetIfIndex(),devices.Get(1)->GetAddress());
Simulator::ScheduleNow(&startFlowPacketSocket, localSocket,
1);
Simulator::Stop (Seconds(15));
Simulator::Run ();
Simulator::Destroy ();
}