blob: 38edf4f1c6a97f4ee26553220fc72ba3c59639c6 [file] [log] [blame]
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -07003#include <ns3/core-module.h>
4#include <ns3/network-module.h>
5#include <ns3/NDNabstraction-module.h>
6#include <ns3/point-to-point-module.h>
7
8#include "sync-logic.h"
Alexander Afanasyev09e8d752012-04-10 16:05:55 -07009#include "sync-logic-helper.h"
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080010
11using namespace ns3;
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070012using namespace Sync;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080013
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070014NS_LOG_COMPONENT_DEFINE ("SyncExample");
15
Alexander Afanasyev09e8d752012-04-10 16:05:55 -070016void OnUpdate (const std::string &prefix, const SeqNo &newSeq, const SeqNo &/*oldSeq*/)
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070017{
Alexander Afanasyev09e8d752012-04-10 16:05:55 -070018 NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << Simulator::GetContext () << ", prefix: " << prefix << ", seqNo: " << newSeq);
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070019}
20
Alexander Afanasyev09e8d752012-04-10 16:05:55 -070021void OnRemove (const std::string &prefix)
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070022{
Alexander Afanasyev09e8d752012-04-10 16:05:55 -070023 NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << Simulator::GetContext () << ", prefix: "<< prefix);
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070024}
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080025
26int
27main (int argc, char *argv[])
28{
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070029 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
30 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
31 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
32
33 Config::SetDefault ("ns3::CcnxFloodingStrategy::SmartFlooding", StringValue ("false"));
34
35 LogComponentEnable ("SyncExample", LOG_ALL);
36
37 Time finishTime = Seconds (3.0);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080038
39 CommandLine cmd;
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070040 cmd.AddValue ("finish", "Finish time", finishTime);
41 cmd.Parse (argc, argv);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080042
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070043 // Creating nodes
44 NodeContainer nodes;
Chaoyi Bian17e746b2012-04-13 16:57:19 -070045 nodes.Create (11);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080046
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070047 // Connecting nodes using two links
48 PointToPointHelper p2p;
Chaoyi Bian17e746b2012-04-13 16:57:19 -070049 p2p.Install (nodes.Get (0), nodes.Get (4));
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070050 p2p.Install (nodes.Get (1), nodes.Get (2));
Chaoyi Bian17e746b2012-04-13 16:57:19 -070051 p2p.Install (nodes.Get (1), nodes.Get (4));
52 p2p.Install (nodes.Get (1), nodes.Get (5));
53 p2p.Install (nodes.Get (2), nodes.Get (6));
54 p2p.Install (nodes.Get (2), nodes.Get (7));
55 p2p.Install (nodes.Get (3), nodes.Get (4));
56 p2p.Install (nodes.Get (3), nodes.Get (8));
57 p2p.Install (nodes.Get (4), nodes.Get (5));
58 p2p.Install (nodes.Get (4), nodes.Get (8));
59 p2p.Install (nodes.Get (5), nodes.Get (6));
60 p2p.Install (nodes.Get (5), nodes.Get (9));
61 p2p.Install (nodes.Get (5), nodes.Get (10));
62 p2p.Install (nodes.Get (6), nodes.Get (10));
63 p2p.Install (nodes.Get (7), nodes.Get (10));
64 p2p.Install (nodes.Get (8), nodes.Get (9));
65 p2p.Install (nodes.Get (9), nodes.Get (10));
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080066
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070067 Names::Add ("0", nodes.Get (0));
68 Names::Add ("1", nodes.Get (1));
69 Names::Add ("2", nodes.Get (2));
Chaoyi Bian17e746b2012-04-13 16:57:19 -070070 Names::Add ("3", nodes.Get(3));
71 Names::Add ("4", nodes.Get(4));
72 Names::Add ("5", nodes.Get(5));
73 Names::Add ("6", nodes.Get(6));
74 Names::Add ("7", nodes.Get(7));
75 Names::Add ("8", nodes.Get(8));
76 Names::Add ("9", nodes.Get(9));
77 Names::Add ("10", nodes.Get(10));
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070078
79 // Install CCNx stack on all nodes
80 NS_LOG_INFO ("Installing CCNx stack");
81 CcnxStackHelper ccnxHelper;
82 ccnxHelper.SetForwardingStrategy ("ns3::CcnxFloodingStrategy");
83 ccnxHelper.SetDefaultRoutes (false);
84 ccnxHelper.InstallAll ();
85
86 ccnxHelper.AddRoute ("0", "/sync", 0, 0);
87 ccnxHelper.AddRoute ("1", "/sync", 0, 0);
88 ccnxHelper.AddRoute ("1", "/sync", 1, 0);
Chaoyi Bian17e746b2012-04-13 16:57:19 -070089 ccnxHelper.AddRoute ("1", "/sync", 2, 0);
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070090 ccnxHelper.AddRoute ("2", "/sync", 0, 0);
Chaoyi Bian17e746b2012-04-13 16:57:19 -070091 ccnxHelper.AddRoute ("2", "/sync", 1, 0);
92 ccnxHelper.AddRoute ("2", "/sync", 2, 0);
93 ccnxHelper.AddRoute ("3", "/sync", 0, 0);
94 ccnxHelper.AddRoute ("3", "/sync", 1, 0);
95 ccnxHelper.AddRoute ("4", "/sync", 0, 0);
96 ccnxHelper.AddRoute ("4", "/sync", 1, 0);
97 ccnxHelper.AddRoute ("4", "/sync", 2, 0);
98 ccnxHelper.AddRoute ("4", "/sync", 3, 0);
99 ccnxHelper.AddRoute ("4", "/sync", 4, 0);
100 ccnxHelper.AddRoute ("5", "/sync", 0, 0);
101 ccnxHelper.AddRoute ("5", "/sync", 1, 0);
102 ccnxHelper.AddRoute ("5", "/sync", 2, 0);
103 ccnxHelper.AddRoute ("5", "/sync", 3, 0);
104 ccnxHelper.AddRoute ("5", "/sync", 4, 0);
105 ccnxHelper.AddRoute ("6", "/sync", 0, 0);
106 ccnxHelper.AddRoute ("6", "/sync", 1, 0);
107 ccnxHelper.AddRoute ("6", "/sync", 2, 0);
108 ccnxHelper.AddRoute ("7", "/sync", 0, 0);
109 ccnxHelper.AddRoute ("7", "/sync", 1, 0);
110 ccnxHelper.AddRoute ("8", "/sync", 0, 0);
111 ccnxHelper.AddRoute ("8", "/sync", 1, 0);
112 ccnxHelper.AddRoute ("8", "/sync", 2, 0);
113 ccnxHelper.AddRoute ("9", "/sync", 0, 0);
114 ccnxHelper.AddRoute ("9", "/sync", 1, 0);
115 ccnxHelper.AddRoute ("9", "/sync", 2, 0);
116 ccnxHelper.AddRoute ("10", "/sync", 0, 0);
117 ccnxHelper.AddRoute ("10", "/sync", 1, 0);
118 ccnxHelper.AddRoute ("10", "/sync", 2, 0);
119 ccnxHelper.AddRoute ("10", "/sync", 3, 0);
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -0700120
Alexander Afanasyev09e8d752012-04-10 16:05:55 -0700121 SyncLogicHelper logicHelper;
122 logicHelper.SetPrefix ("/sync");
123 logicHelper.SetCallbacks (OnUpdate, OnRemove);
124 ApplicationContainer apps = logicHelper.Install (NodeContainer (nodes.Get (0), nodes.Get (1)));
125
Alexander Afanasyev9cbebab2012-04-09 15:47:19 -0700126 // one data
127 Simulator::ScheduleWithContext (0, Seconds (0.5), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (0)), "/0", 1, 1);
128
129 // two producers at the same time
130 Simulator::ScheduleWithContext (0, Seconds (1.001), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (0)), "/0", 1, 2);
131 Simulator::ScheduleWithContext (1, Seconds (1.001), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (1)), "/1", 1, 2);
Alexander Afanasyev09e8d752012-04-10 16:05:55 -0700132
133 logicHelper.Install (nodes.Get (2)).
134 Start (Seconds (2.001));
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -0700135
136 Simulator::Stop (finishTime);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -0800137 Simulator::Run ();
138 Simulator::Destroy ();
139 return 0;
140}
141
142