y***@gmail.com
2018-12-05 02:45:57 UTC
Hi!
I am a new user of ns3 and sumo, I want to do a simulation connecting them!
But I have a trouble in it.
According to the ns3's example "ns2-mobility-trace.cc", I write the next
code.
void ReceivePacket (Ptr<Socket> socket)
{
while (socket->Recv ())
{
std::cout << "id: " << socket->GetNode()->GetId() << "receiveTime:
" << Simulator::Now() << std::endl;
NS_LOG_UNCOND ("Received one packet!");
}
}
static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
uint32_t pktCount, Time pktInterval )
{
if (pktCount > 0)
{
std::cout << "send..." << std::endl;
socket->Send (Create<Packet> (pktSize));
Simulator::Schedule (pktInterval, &GenerateTraffic,
socket, pktSize,pktCount - 1, pktInterval);
}
else
{
socket->Close ();
}
}
void main() {
....
for (auto edge : edges) {
for (auto lane : edge->lanes) { // the two "for" means the special
network what I want
NodeContainer nodeContainer;
for (auto vehicle : lane->vehicles) { // this "for" means some
vehicle that the network should have
nodeContainer.Add(NodeContainer::GetGlobal().Get(std::stoi(vehicle->id)));
}
if (nodeContainer.GetN() == 0) {
break;
}
// std::cout << "nodeContainerNum:" << nodeContainer.GetN()
<<std::endl;
std::string phyMode ("OfdmRate6MbpsBW10MHz");
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
Ptr<YansWifiChannel> channel = wifiChannel.Create ();
wifiPhy.SetChannel (channel);
wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11);
NqosWaveMacHelper wifi80211pMac = NqosWaveMacHelper::Default ();
Wifi80211pHelper wifi80211p = Wifi80211pHelper::Default ();
// wifi80211p.EnableLogComponents ();
wifi80211p.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue
(phyMode));
InternetStackHelper internet;
NetDeviceContainer devices = wifi80211p.Install (wifiPhy,
wifi80211pMac, nodeContainer);
wifiPhy.EnablePcap ("wave-simple-80211p", devices);
internet.Install (nodeContainer);
Ipv4AddressHelper ipv4;
std::ostringstream oss;
oss << ip1 << "." << ip2 << "." << "0.0";
const char *base = oss.str().c_str();
std::cout << base << std::endl;
ipv4.SetBase (base, "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (devices);
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
for (unsigned int i =0; i<nodeContainer.GetN();i++) {
PrintIPAddress(nodeContainer.Get(i));
Ptr<Socket> recvSink = Socket::CreateSocket (nodeContainer.Get(i),
tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny(),
80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
}
for (unsigned int i =0; i<nodeContainer.GetN();i++) {
Ptr<Socket> source = Socket::CreateSocket (nodeContainer.Get (i),
tid);
InetSocketAddress remote = InetSocketAddress ("255.255.255.255",
80);
source->SetAllowBroadcast (true);
source->Connect (remote);
Simulator::ScheduleWithContext (source->GetNode()->GetId (),
Seconds (simulationTime),
&GenerateTraffic,
source, 1024, 1, Seconds (0.0));
}
ip2++;
}
ip2 = 1;
ip1++;
}
....
}
In the console, I get
10.1.0.0
1: 10.1.0.1
11.1.0.0
1: 11.1.0.1
12.1.0.0
12.2.0.0
12.3.0.0
1: 12.3.0.1
13.1.0.0
1: 13.1.0.1
1: 13.1.0.2
1: 13.1.0.3
1: 13.1.0.4
1: 13.1.0.5
13.2.0.0
1: 13.2.0.1
1: 13.2.0.2
1: 13.2.0.3
1: 13.2.0.4
1: 13.2.0.5
1: 13.2.0.6
13.3.0.0
1: 13.3.0.1
1: 13.3.0.2
1: 13.3.0.3
1: 13.3.0.4
1: 13.3.0.5
1: 13.3.0.6
1: 13.3.0.7
1: 13.3.0.8
1: 13.3.0.9
1: 13.3.0.10
1: 13.3.0.11
1: 13.3.0.12
1: 13.3.0.13
1: 13.3.0.14
1: 13.3.0.15
1: 13.3.0.16
1: 13.3.0.17
14.1.0.0
1: 14.1.0.1
1: 14.1.0.2
1: 14.1.0.3
14.2.0.0
14.3.0.0
15.1.0.0
15.2.0.0
15.3.0.0
1: 15.3.0.1
16.1.0.0
1: 16.1.0.1
1: 16.1.0.2
1: 16.1.0.3
16.2.0.0
16.3.0.0
1: 16.3.0.1
1: 16.3.0.2
1: 16.3.0.3
1: 16.3.0.4
1: 16.3.0.5
1: 16.3.0.6
1: 16.3.0.7
1: 16.3.0.8
1: 16.3.0.9
1: 16.3.0.10
1: 16.3.0.11
1: 16.3.0.12
1: 16.3.0.13
1: 16.3.0.14
1: 16.3.0.15
1: 16.3.0.16
1: 16.3.0.17
1: 16.3.0.18
1: 16.3.0.19
1: 16.3.0.20
1: 16.3.0.21
1: 16.3.0.22
1: 16.3.0.23
1: 16.3.0.24
1: 16.3.0.25
1: 16.3.0.26
1: 16.3.0.27
1: 16.3.0.28
1: 16.3.0.29
1: 16.3.0.30
1: 16.3.0.31
1: 16.3.0.32
1: 16.3.0.33
1: 16.3.0.34
1: 16.3.0.35
17.1.0.0
17.2.0.0
17.3.0.0
1: 17.3.0.1
1: 17.3.0.2
1: 17.3.0.3
1: 17.3.0.4
18.1.0.0
1: 18.1.0.1
1: 18.1.0.2
1: 18.1.0.3
1: 18.1.0.4
1: 18.1.0.5
1: 18.1.0.6
18.2.0.0
18.3.0.0
1: 18.3.0.1
1: 18.3.0.2
1: 18.3.0.3
1: 18.3.0.4
1: 18.3.0.5
1: 18.3.0.6
1: 18.3.0.7
19.1.0.0
19.2.0.0
19.3.0.0
1: 19.3.0.1
1: 19.3.0.2
1: 19.3.0.3
1: 19.3.0.4
1: 19.3.0.5
1: 19.3.0.6
1: 19.3.0.7
1: 19.3.0.8
1: 19.3.0.9
1: 19.3.0.10
1: 19.3.0.11
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
But it don't get a receive.
and I open the NetAnim to find the problem, I get
[image: 49b8cd618e8edb32cb047fb25a50648.png]
Can anybody could tell me why the network don't move with the node?
I am a new user of ns3 and sumo, I want to do a simulation connecting them!
But I have a trouble in it.
According to the ns3's example "ns2-mobility-trace.cc", I write the next
code.
void ReceivePacket (Ptr<Socket> socket)
{
while (socket->Recv ())
{
std::cout << "id: " << socket->GetNode()->GetId() << "receiveTime:
" << Simulator::Now() << std::endl;
NS_LOG_UNCOND ("Received one packet!");
}
}
static void GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize,
uint32_t pktCount, Time pktInterval )
{
if (pktCount > 0)
{
std::cout << "send..." << std::endl;
socket->Send (Create<Packet> (pktSize));
Simulator::Schedule (pktInterval, &GenerateTraffic,
socket, pktSize,pktCount - 1, pktInterval);
}
else
{
socket->Close ();
}
}
void main() {
....
for (auto edge : edges) {
for (auto lane : edge->lanes) { // the two "for" means the special
network what I want
NodeContainer nodeContainer;
for (auto vehicle : lane->vehicles) { // this "for" means some
vehicle that the network should have
nodeContainer.Add(NodeContainer::GetGlobal().Get(std::stoi(vehicle->id)));
}
if (nodeContainer.GetN() == 0) {
break;
}
// std::cout << "nodeContainerNum:" << nodeContainer.GetN()
<<std::endl;
std::string phyMode ("OfdmRate6MbpsBW10MHz");
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
Ptr<YansWifiChannel> channel = wifiChannel.Create ();
wifiPhy.SetChannel (channel);
wifiPhy.SetPcapDataLinkType (WifiPhyHelper::DLT_IEEE802_11);
NqosWaveMacHelper wifi80211pMac = NqosWaveMacHelper::Default ();
Wifi80211pHelper wifi80211p = Wifi80211pHelper::Default ();
// wifi80211p.EnableLogComponents ();
wifi80211p.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue (phyMode),
"ControlMode",StringValue
(phyMode));
InternetStackHelper internet;
NetDeviceContainer devices = wifi80211p.Install (wifiPhy,
wifi80211pMac, nodeContainer);
wifiPhy.EnablePcap ("wave-simple-80211p", devices);
internet.Install (nodeContainer);
Ipv4AddressHelper ipv4;
std::ostringstream oss;
oss << ip1 << "." << ip2 << "." << "0.0";
const char *base = oss.str().c_str();
std::cout << base << std::endl;
ipv4.SetBase (base, "255.255.255.0");
Ipv4InterfaceContainer i = ipv4.Assign (devices);
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
for (unsigned int i =0; i<nodeContainer.GetN();i++) {
PrintIPAddress(nodeContainer.Get(i));
Ptr<Socket> recvSink = Socket::CreateSocket (nodeContainer.Get(i),
tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny(),
80);
recvSink->Bind (local);
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
}
for (unsigned int i =0; i<nodeContainer.GetN();i++) {
Ptr<Socket> source = Socket::CreateSocket (nodeContainer.Get (i),
tid);
InetSocketAddress remote = InetSocketAddress ("255.255.255.255",
80);
source->SetAllowBroadcast (true);
source->Connect (remote);
Simulator::ScheduleWithContext (source->GetNode()->GetId (),
Seconds (simulationTime),
&GenerateTraffic,
source, 1024, 1, Seconds (0.0));
}
ip2++;
}
ip2 = 1;
ip1++;
}
....
}
In the console, I get
10.1.0.0
1: 10.1.0.1
11.1.0.0
1: 11.1.0.1
12.1.0.0
12.2.0.0
12.3.0.0
1: 12.3.0.1
13.1.0.0
1: 13.1.0.1
1: 13.1.0.2
1: 13.1.0.3
1: 13.1.0.4
1: 13.1.0.5
13.2.0.0
1: 13.2.0.1
1: 13.2.0.2
1: 13.2.0.3
1: 13.2.0.4
1: 13.2.0.5
1: 13.2.0.6
13.3.0.0
1: 13.3.0.1
1: 13.3.0.2
1: 13.3.0.3
1: 13.3.0.4
1: 13.3.0.5
1: 13.3.0.6
1: 13.3.0.7
1: 13.3.0.8
1: 13.3.0.9
1: 13.3.0.10
1: 13.3.0.11
1: 13.3.0.12
1: 13.3.0.13
1: 13.3.0.14
1: 13.3.0.15
1: 13.3.0.16
1: 13.3.0.17
14.1.0.0
1: 14.1.0.1
1: 14.1.0.2
1: 14.1.0.3
14.2.0.0
14.3.0.0
15.1.0.0
15.2.0.0
15.3.0.0
1: 15.3.0.1
16.1.0.0
1: 16.1.0.1
1: 16.1.0.2
1: 16.1.0.3
16.2.0.0
16.3.0.0
1: 16.3.0.1
1: 16.3.0.2
1: 16.3.0.3
1: 16.3.0.4
1: 16.3.0.5
1: 16.3.0.6
1: 16.3.0.7
1: 16.3.0.8
1: 16.3.0.9
1: 16.3.0.10
1: 16.3.0.11
1: 16.3.0.12
1: 16.3.0.13
1: 16.3.0.14
1: 16.3.0.15
1: 16.3.0.16
1: 16.3.0.17
1: 16.3.0.18
1: 16.3.0.19
1: 16.3.0.20
1: 16.3.0.21
1: 16.3.0.22
1: 16.3.0.23
1: 16.3.0.24
1: 16.3.0.25
1: 16.3.0.26
1: 16.3.0.27
1: 16.3.0.28
1: 16.3.0.29
1: 16.3.0.30
1: 16.3.0.31
1: 16.3.0.32
1: 16.3.0.33
1: 16.3.0.34
1: 16.3.0.35
17.1.0.0
17.2.0.0
17.3.0.0
1: 17.3.0.1
1: 17.3.0.2
1: 17.3.0.3
1: 17.3.0.4
18.1.0.0
1: 18.1.0.1
1: 18.1.0.2
1: 18.1.0.3
1: 18.1.0.4
1: 18.1.0.5
1: 18.1.0.6
18.2.0.0
18.3.0.0
1: 18.3.0.1
1: 18.3.0.2
1: 18.3.0.3
1: 18.3.0.4
1: 18.3.0.5
1: 18.3.0.6
1: 18.3.0.7
19.1.0.0
19.2.0.0
19.3.0.0
1: 19.3.0.1
1: 19.3.0.2
1: 19.3.0.3
1: 19.3.0.4
1: 19.3.0.5
1: 19.3.0.6
1: 19.3.0.7
1: 19.3.0.8
1: 19.3.0.9
1: 19.3.0.10
1: 19.3.0.11
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
send...
But it don't get a receive.
and I open the NetAnim to find the problem, I get
[image: 49b8cd618e8edb32cb047fb25a50648.png]
Can anybody could tell me why the network don't move with the node?
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+***@googlegroups.com.
To post to this group, send email to ns-3-***@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+***@googlegroups.com.
To post to this group, send email to ns-3-***@googlegroups.com.
Visit this group at https://groups.google.com/group/ns-3-users.
For more options, visit https://groups.google.com/d/optout.