blob: 54f715f3e97dfdb653c682cb27d27dc63750f870 [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 Afanasyev7a696fb2012-03-01 17:17:22 -08009
10using namespace ns3;
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070011using namespace Sync;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080012
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070013NS_LOG_COMPONENT_DEFINE ("SyncExample");
14
15void OnUpdate (Ptr<Node> node, const std::string &prefix, const SeqNo &newSeq, const SeqNo &/*oldSeq*/)
16{
Alexander Afanasyev9cbebab2012-04-09 15:47:19 -070017 NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << node->GetId () << ", prefix: " << prefix << ", seqNo: " << newSeq);
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070018}
19
20void OnRemove (Ptr<Node> node, const std::string &prefix)
21{
Alexander Afanasyev9cbebab2012-04-09 15:47:19 -070022 NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << node->GetId () << ", prefix: "<< prefix);
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070023}
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080024
25int
26main (int argc, char *argv[])
27{
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070028 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
29 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
30 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
31
32 Config::SetDefault ("ns3::CcnxFloodingStrategy::SmartFlooding", StringValue ("false"));
33
34 LogComponentEnable ("SyncExample", LOG_ALL);
35
36 Time finishTime = Seconds (3.0);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080037
38 CommandLine cmd;
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070039 cmd.AddValue ("finish", "Finish time", finishTime);
40 cmd.Parse (argc, argv);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080041
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070042 // Creating nodes
43 NodeContainer nodes;
44 nodes.Create (3);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080045
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070046 // Connecting nodes using two links
47 PointToPointHelper p2p;
48 p2p.Install (nodes.Get (0), nodes.Get (1));
49 p2p.Install (nodes.Get (1), nodes.Get (2));
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080050
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070051 Names::Add ("0", nodes.Get (0));
52 Names::Add ("1", nodes.Get (1));
53 Names::Add ("2", nodes.Get (2));
54
55 // Install CCNx stack on all nodes
56 NS_LOG_INFO ("Installing CCNx stack");
57 CcnxStackHelper ccnxHelper;
58 ccnxHelper.SetForwardingStrategy ("ns3::CcnxFloodingStrategy");
59 ccnxHelper.SetDefaultRoutes (false);
60 ccnxHelper.InstallAll ();
61
62 ccnxHelper.AddRoute ("0", "/sync", 0, 0);
63 ccnxHelper.AddRoute ("1", "/sync", 0, 0);
64 ccnxHelper.AddRoute ("1", "/sync", 1, 0);
65 ccnxHelper.AddRoute ("2", "/sync", 0, 0);
66
67 ApplicationContainer apps;
68 Ptr<Application> app;
69 app = Create<SyncLogic> ("/sync",
70 boost::bind (OnUpdate, nodes.Get (0), _1, _2, _3),
71 boost::bind (OnRemove, nodes.Get (0), _1));
72
73 nodes.Get (0)->AddApplication (app);
74 apps.Add (app);
75
76 app = Create<SyncLogic> ("/sync",
77 boost::bind (OnUpdate, nodes.Get (1), _1, _2, _3),
78 boost::bind (OnRemove, nodes.Get (1), _1));
79
80 nodes.Get (1)->AddApplication (app);
81 apps.Add (app);
Alexander Afanasyev9cbebab2012-04-09 15:47:19 -070082
83 // one data
84 Simulator::ScheduleWithContext (0, Seconds (0.5), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (0)), "/0", 1, 1);
85
86 // two producers at the same time
87 Simulator::ScheduleWithContext (0, Seconds (1.001), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (0)), "/0", 1, 2);
88 Simulator::ScheduleWithContext (1, Seconds (1.001), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (1)), "/1", 1, 2);
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070089
90 Simulator::Stop (finishTime);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080091 Simulator::Run ();
92 Simulator::Destroy ();
93 return 0;
94}
95
96