Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 3 | #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 Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 9 | |
| 10 | using namespace ns3; |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 11 | using namespace Sync; |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 12 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 13 | NS_LOG_COMPONENT_DEFINE ("SyncExample"); |
| 14 | |
| 15 | void OnUpdate (Ptr<Node> node, const std::string &prefix, const SeqNo &newSeq, const SeqNo &/*oldSeq*/) |
| 16 | { |
Alexander Afanasyev | 9cbebab | 2012-04-09 15:47:19 -0700 | [diff] [blame^] | 17 | NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << node->GetId () << ", prefix: " << prefix << ", seqNo: " << newSeq); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | void OnRemove (Ptr<Node> node, const std::string &prefix) |
| 21 | { |
Alexander Afanasyev | 9cbebab | 2012-04-09 15:47:19 -0700 | [diff] [blame^] | 22 | NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << node->GetId () << ", prefix: "<< prefix); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 23 | } |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 24 | |
| 25 | int |
| 26 | main (int argc, char *argv[]) |
| 27 | { |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 28 | 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 Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 37 | |
| 38 | CommandLine cmd; |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 39 | cmd.AddValue ("finish", "Finish time", finishTime); |
| 40 | cmd.Parse (argc, argv); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 41 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 42 | // Creating nodes |
| 43 | NodeContainer nodes; |
| 44 | nodes.Create (3); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 46 | // 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 Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 50 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 51 | 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 Afanasyev | 9cbebab | 2012-04-09 15:47:19 -0700 | [diff] [blame^] | 82 | |
| 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 Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 89 | |
| 90 | Simulator::Stop (finishTime); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 91 | Simulator::Run (); |
| 92 | Simulator::Destroy (); |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | |