blob: c400fff9fdc9c4d603f1a6718da8b5e8a0ae78c4 [file] [log] [blame]
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -07001/*
2 * sync-topology-ndnabstraction.cpp
3 * XcodeProject
4 *
5 * Created by Ilya on 7/18/11.
6 * Copyright 2011 __MyCompanyName__. All rights reserved.
7 *
8 */
9#include "ns3/core-module.h"
10#include "ns3/network-module.h"
11#include "ns3/internet-module.h"
12#include "ns3/point-to-point-module.h"
13#include "ns3/applications-module.h"
14
15using namespace ns3;
16
17NS_LOG_COMPONENT_DEFINE ("SyncTopologyNDNabstraction");
18
19int
20main (int argc, char *argv[])
21{
22 // Set up some default values for the simulation. Use the
23
24 Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
25 Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
26
27 // Allow the user to override any of the defaults and the above
28 // DefaultValue::Bind ()s at run-time, via command-line arguments
29 CommandLine cmd;
30 cmd.Parse (argc, argv);
31
32 // Here, we will explicitly create seven nodes.
33 NS_LOG_INFO ("Create nodes.");
34 NodeContainer c;
35 c.Create (7);
36
37
38 NodeContainer n13 = NodeContainer (c.Get (0), c.Get (2));
39 NodeContainer n23 = NodeContainer (c.Get (1), c.Get (3));
40 NodeContainer n35 = NodeContainer (c.Get (2), c.Get (4));
41 NodeContainer n34 = NodeContainer (c.Get (2), c.Get (3));
42 NodeContainer n45 = NodeContainer (c.Get (3), c.Get (4));
43 NodeContainer n56 = NodeContainer (c.Get (4), c.Get (5));
44 NodeContainer n57 = NodeContainer (c.Get (4), c.Get (6));
45
46 Ipv4StaticRoutingHelper staticRouting;
47
48 Ipv4ListRoutingHelper list;
49 list.Add (staticRouting, 1);
50
51 //Add static routing
52 InternetStackHelper internet;
53 internet.SetRoutingHelper (list); // has effect on the next Install ()
54 internet.Install (c);
55
56 // We create the channels first without any IP addressing information
57 NS_LOG_INFO ("Create channels.");
58 PointToPointHelper p2p;
59 p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
60 p2p.SetChannelAttribute ("Delay", StringValue ("1ms"));
61 NetDeviceContainer nd13 = p2p.Install (n13);
62 NetDeviceContainer nd23 = p2p.Install (n23);
63 NetDeviceContainer nd56 = p2p.Install (n56);
64
65 p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
66 p2p.SetChannelAttribute ("Delay", StringValue ("50ms"));
67 NetDeviceContainer nd57 = p2p.Install (n57);
68
69 p2p.SetDeviceAttribute ("DataRate", StringValue ("1Mbps"));
70 p2p.SetChannelAttribute ("Delay", StringValue ("1ms"));
71 NetDeviceContainer nd34 = p2p.Install (n34);
72 NetDeviceContainer nd45 = p2p.Install (n45);
73
74 p2p.SetDeviceAttribute ("DataRate", StringValue ("1Mbps"));
75 p2p.SetChannelAttribute ("Delay", StringValue ("50ms"));
76 NetDeviceContainer nd35 = p2p.Install (n35);
77
78 // Later, we add IP addresses.
79 NS_LOG_INFO ("Assign IP Addresses.");
80 Ipv4AddressHelper ipv4;
81 ipv4.SetBase ("192.168.1.0", "255.255.255.0");
82 Ipv4InterfaceContainer i13 = ipv4.Assign (nd13);
83 Ipv4InterfaceContainer i23 = ipv4.Assign (nd23);
84 Ipv4InterfaceContainer i35 = ipv4.Assign (nd35);
85 Ipv4InterfaceContainer i34 = ipv4.Assign (nd34);
86 Ipv4InterfaceContainer i45 = ipv4.Assign (nd45);
87 Ipv4InterfaceContainer i56 = ipv4.Assign (nd56);
88 Ipv4InterfaceContainer i57 = ipv4.Assign (nd57);
89
90
91 // Create the OnOff application to send UDP datagrams of size
92 // 210 bytes at a rate of 448 Kb/s from n0 to n4
93 NS_LOG_INFO ("Create Applications.");
94 uint16_t port = 9; // Discard port (RFC 863)
95
96 std::string sendsizeattr = "SendSize";
97 //flow2 7-->2
98 BulkSendHelper bulksend0 ("ns3::UdpSocketFactory", InetSocketAddress (i23.GetAddress (0), port));
99 //bulksend0.SetAttribute(sendsizeattr, AttributeValue(ConstantVariable(2560)));
100 bulksend0.SetAttribute("MaxBytes", UintegerValue(2560));
101 ApplicationContainer apps = bulksend0.Install(c.Get(6));
102 apps.Start(Seconds (1.0));
103 apps.Stop(Seconds (10.0));
104
105 // Create a packet sink to receive these packets
106 PacketSinkHelper sink0 ("ns3::UdpSocketFactory", InetSocketAddress(Ipv4Address::GetAny (), port));
107 apps = sink0.Install(c.Get(1));
108 apps.Start(Seconds(0.0));
109 apps.Stop(Seconds(20.0));
110
111 //flow1 1-->6
112 BulkSendHelper bulksend ("ns3::UdpSocketFactory", InetSocketAddress (i56.GetAddress (1), port));
113 //bulksend.SetAttribute(sendsizeattr, AttributeValue( ConstantVariable(2560)));
114 bulksend0.SetAttribute("MaxBytes", UintegerValue(2560));
115 apps = bulksend.Install (c.Get (0));
116 apps.Start (Seconds (6.0));
117 apps.Stop (Seconds (20.0));
118
119 // Create a packet sink to receive these packets
120 PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
121 apps = sink.Install (c.Get (5));
122 apps.Start(Seconds(0.0));
123 apps.Stop(Seconds(20.0));
124
125 AsciiTraceHelper ascii;
126 p2p.EnableAsciiAll (ascii.CreateFileStream ("sync-topology-ndnabstraction.tr"));
127 p2p.EnablePcapAll ("sync-topology-ndnabstraction");
128
129 Simulator::Stop (Seconds (20));
130
131 NS_LOG_INFO ("Run Simulation.");
132 Simulator::Run ();
133 Simulator::Destroy ();
134 NS_LOG_INFO ("Done.");
135
136 return 0;
137}