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 | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame^] | 9 | #include "sync-logic-helper.h" |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 10 | |
| 11 | using namespace ns3; |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 12 | using namespace Sync; |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 13 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 14 | NS_LOG_COMPONENT_DEFINE ("SyncExample"); |
| 15 | |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame^] | 16 | void OnUpdate (const std::string &prefix, const SeqNo &newSeq, const SeqNo &/*oldSeq*/) |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 17 | { |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame^] | 18 | NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << Simulator::GetContext () << ", prefix: " << prefix << ", seqNo: " << newSeq); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 19 | } |
| 20 | |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame^] | 21 | void OnRemove (const std::string &prefix) |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 22 | { |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame^] | 23 | NS_LOG_LOGIC (Simulator::Now ().ToDouble (Time::S) <<"s\tNode: " << Simulator::GetContext () << ", prefix: "<< prefix); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 24 | } |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 25 | |
| 26 | int |
| 27 | main (int argc, char *argv[]) |
| 28 | { |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 29 | 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 Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 38 | |
| 39 | CommandLine cmd; |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 40 | cmd.AddValue ("finish", "Finish time", finishTime); |
| 41 | cmd.Parse (argc, argv); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 42 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 43 | // Creating nodes |
| 44 | NodeContainer nodes; |
| 45 | nodes.Create (3); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 46 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 47 | // Connecting nodes using two links |
| 48 | PointToPointHelper p2p; |
| 49 | p2p.Install (nodes.Get (0), nodes.Get (1)); |
| 50 | p2p.Install (nodes.Get (1), nodes.Get (2)); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 51 | |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 52 | Names::Add ("0", nodes.Get (0)); |
| 53 | Names::Add ("1", nodes.Get (1)); |
| 54 | Names::Add ("2", nodes.Get (2)); |
| 55 | |
| 56 | // Install CCNx stack on all nodes |
| 57 | NS_LOG_INFO ("Installing CCNx stack"); |
| 58 | CcnxStackHelper ccnxHelper; |
| 59 | ccnxHelper.SetForwardingStrategy ("ns3::CcnxFloodingStrategy"); |
| 60 | ccnxHelper.SetDefaultRoutes (false); |
| 61 | ccnxHelper.InstallAll (); |
| 62 | |
| 63 | ccnxHelper.AddRoute ("0", "/sync", 0, 0); |
| 64 | ccnxHelper.AddRoute ("1", "/sync", 0, 0); |
| 65 | ccnxHelper.AddRoute ("1", "/sync", 1, 0); |
| 66 | ccnxHelper.AddRoute ("2", "/sync", 0, 0); |
| 67 | |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame^] | 68 | SyncLogicHelper logicHelper; |
| 69 | logicHelper.SetPrefix ("/sync"); |
| 70 | logicHelper.SetCallbacks (OnUpdate, OnRemove); |
| 71 | ApplicationContainer apps = logicHelper.Install (NodeContainer (nodes.Get (0), nodes.Get (1))); |
| 72 | |
Alexander Afanasyev | 9cbebab | 2012-04-09 15:47:19 -0700 | [diff] [blame] | 73 | // one data |
| 74 | Simulator::ScheduleWithContext (0, Seconds (0.5), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (0)), "/0", 1, 1); |
| 75 | |
| 76 | // two producers at the same time |
| 77 | Simulator::ScheduleWithContext (0, Seconds (1.001), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (0)), "/0", 1, 2); |
| 78 | Simulator::ScheduleWithContext (1, Seconds (1.001), &SyncLogic::addLocalNames, DynamicCast<SyncLogic> (apps.Get (1)), "/1", 1, 2); |
Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame^] | 79 | |
| 80 | logicHelper.Install (nodes.Get (2)). |
| 81 | Start (Seconds (2.001)); |
Alexander Afanasyev | b550d6a | 2012-04-09 15:03:16 -0700 | [diff] [blame] | 82 | |
| 83 | Simulator::Stop (finishTime); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 84 | Simulator::Run (); |
| 85 | Simulator::Destroy (); |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | |