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