Initial commit
diff --git a/examples/sync-example.cc b/examples/sync-example.cc
new file mode 100644
index 0000000..57bf8b4
--- /dev/null
+++ b/examples/sync-example.cc
@@ -0,0 +1,26 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+
+#include "ns3/core-module.h"
+#include "ns3/sync-helper.h"
+
+using namespace ns3;
+
+
+int 
+main (int argc, char *argv[])
+{
+  bool verbose = true;
+
+  CommandLine cmd;
+  cmd.AddValue ("verbose", "Tell application to log if true", verbose);
+
+  cmd.Parse (argc,argv);
+
+  /* ... */
+
+  Simulator::Run ();
+  Simulator::Destroy ();
+  return 0;
+}
+
+
diff --git a/examples/wscript b/examples/wscript
new file mode 100644
index 0000000..3b46e2d
--- /dev/null
+++ b/examples/wscript
@@ -0,0 +1,6 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+def build(bld):
+    obj = bld.create_ns3_program('sync-example', ['sync'])
+    obj.source = 'sync-example.cc'
+
diff --git a/model/sync-app.cc b/model/sync-app.cc
new file mode 100644
index 0000000..2680859
--- /dev/null
+++ b/model/sync-app.cc
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
diff --git a/model/sync-app.h b/model/sync-app.h
new file mode 100644
index 0000000..a0310a3
--- /dev/null
+++ b/model/sync-app.h
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_APP_H
+#define SYNC_APP_H
+
+namespace ns3
+{
+
+namespace Sync
+{
+
+class App
+{
+public:
+private:
+};
+
+} // Sync
+
+} // ns3
+
+#endif // SYNC_APP_H
diff --git a/model/sync-ccnx-name-info.cc b/model/sync-ccnx-name-info.cc
new file mode 100644
index 0000000..f0a5473
--- /dev/null
+++ b/model/sync-ccnx-name-info.cc
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "sync-ccnx-name-info.h"
+#include "ns3/ccnx-name-components.h"
+
+#include <boost/lexical_cast.hpp>
+
+namespace ns3 {
+namespace Sync {
+
+
+CcnxNameInfo::CcnxNameInfo (Ptr<const CcnxNameComponents> name)
+  : m_name (name)
+{
+}
+
+CcnxNameInfo::~CcnxNameInfo ()
+{
+}
+
+std::string
+CcnxNameInfo::toString () const
+{
+  return boost::lexical_cast<std::string> (*m_name);
+}
+
+
+} // Sync
+} // ns3
diff --git a/model/sync-ccnx-name-info.h b/model/sync-ccnx-name-info.h
new file mode 100644
index 0000000..89ea006
--- /dev/null
+++ b/model/sync-ccnx-name-info.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_CCNX_NAME_INFO_H
+#define SYNC_CCNX_NAME_INFO_H
+
+#include "sync-name-info.h"
+#include "ns3/ptr.h"
+
+namespace ns3 {
+
+class CcnxNameComponents;
+
+namespace Sync {
+
+class CcnxNameInfo : public NameInfo
+{
+public:
+  /**
+   * @brief Constructor
+   * @param name full (routable) name for the participant
+   */
+  CcnxNameInfo (Ptr<const CcnxNameComponents> name);
+  virtual ~CcnxNameInfo ();
+  
+  // from NameInfo
+  virtual std::string
+  toString () const;
+  
+private:
+  Ptr<const CcnxNameCompnents> m_name;
+};
+
+} // Sync
+} // ns3
+
+#endif // SYNC_CCNX_NAME_INFO_H
diff --git a/model/sync-diff-leaf.cc b/model/sync-diff-leaf.cc
new file mode 100644
index 0000000..2680859
--- /dev/null
+++ b/model/sync-diff-leaf.cc
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
diff --git a/model/sync-diff-leaf.h b/model/sync-diff-leaf.h
new file mode 100644
index 0000000..d857690
--- /dev/null
+++ b/model/sync-diff-leaf.h
@@ -0,0 +1,89 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_DIFF_LEAF_H
+#define SYNC_DIFF_LEAF_H
+
+#include "sync-leaf.h"
+
+namespace ns3 {
+namespace Sync {
+
+/**
+ * @ingroup sync
+ * @brief Annotation for SYNC leaf
+ */
+enum Operation
+  {
+    UPDATE, ///< @brief Leaf was added or updated
+    REMOVE  ///< @brief Leaf was removed
+  };
+
+/**
+ * @ingroup sync
+ * @brief Annotated SYNC leaf 
+ */
+class DiffLeaf : public Leaf
+{
+public:
+  /**
+   * @brief Constructor to create an UPDATE diff leaf
+   * @param info Smart pointer to leaf's name
+   * @param seq  Initial sequence number of the pointer
+   */
+  DiffLeaf (boost::shared_ptr<const NameInfo> info, const SeqNo &seq)
+    : Leaf (info, seq)
+    , m_op (Operation::UPDATE)
+  {
+  }
+
+  /**
+   * @brief Constructor to create an REMOVE diff leaf
+   * @param info Smart pointer to leaf's name
+   *
+   * This constructor creates a leaf with phony sequence number
+   * with 0 session ID and 0 sequence number
+   */
+  DiffLeaf (boost::shared_ptr<const NameInfo> info)
+    : Leaf (info, SeqNo (0,0))
+    , m_op (Operation::REMOVE)
+  {
+  }
+
+  virtual ~DiffLeaf ()
+  {
+  }
+
+  Operation
+  getOperation () const
+  {
+    return m_op;
+  }
+  
+private:
+  Operation m_op;
+};
+
+} // Sync
+} // ns3
+
+#endif // SYNC_DIFF_LEAF_H
diff --git a/model/sync-diff-state.cc b/model/sync-diff-state.cc
new file mode 100644
index 0000000..b26a756
--- /dev/null
+++ b/model/sync-diff-state.cc
@@ -0,0 +1,85 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "sync-diff-state.h"
+
+#include <boost/make_shared.hpp>
+
+using namespace boost;
+
+namespace ns3 {
+namespace Sync {
+
+DiffState::DiffState ()
+  : m_next (0)
+{
+}
+
+DiffState::~DiffState ()
+{
+}
+
+DiffStatePtr
+DiffState::diff () const
+{
+  DiffStatePtr ret = make_shared<DiffState> ();
+
+  DiffState *state = m_next;
+  while (state != 0)
+    {
+      *ret += *state;
+      state = state->m_next;
+    }
+
+  return ret;
+}
+
+DiffState &
+DiffState::operator += (const DiffState &state)
+{
+  return *this;
+}
+  
+// from State
+virtual void
+DiffState::update (NameInfoConstPtr info, const SeqNo &seq)
+{
+  LeafContainer::iterator item = m_leafs.find (info);
+  if (item != m_leafs.end ())
+    m_leafs.remove (item);
+  
+  m_leafs.insert (make_shared<DiffLeaf> (info, cref (seq)));
+}
+
+virtual void
+DiffState::remove (NameInfoConstPtr info)
+{
+  LeafContainer::iterator item = m_leafs.find (info);
+  if (item != m_leafs.end ())
+    m_leafs.remove (item);
+
+  m_leafs.insert (make_shared<DiffLeaf> (info));
+}
+
+
+} // ns3
+} // Sync
diff --git a/model/sync-diff-state.h b/model/sync-diff-state.h
new file mode 100644
index 0000000..49f61ae
--- /dev/null
+++ b/model/sync-diff-state.h
@@ -0,0 +1,96 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_DIFF_STATE_H
+#define SYNC_DIFF_STATE_H
+
+#include "sync-state.h"
+
+namespace ns3 {
+namespace Sync {
+
+class DiffState;
+typedef boost::shared_ptr<DiffState> DiffStatePtr;
+typedef boost::shared_ptr<DiffState> DiffStateConstPtr;
+
+/**
+ * @ingroup ccnx
+ * @brief Differential SYNC state
+ */
+class DiffState : public State
+{
+public:
+  /**
+   * @see Default constructor
+   */
+  DiffState ();
+  virtual ~DiffState ();
+
+  /**
+   * @brief Set successor for the diff state
+   * @param next successor state
+   */
+  void
+  setNext (DiffStatePtr next)
+  {
+    m_next = next;
+  }
+
+  // void
+  // setDigest (Hash digest);
+
+  // Hash
+  // getDigest () const;
+
+  /**
+   * @brief Accumulate differences from `this' state to the most current state
+   * @returns Accumulated differences from `this' state to the most current state
+   */
+  DiffStatePtr
+  diff () const;
+
+  /**
+   * @brief Combine differences from `this' and `state'
+   * @param state Differential state to combine with
+   * @return Combined differences
+   *
+   * In case of collisions, `this' leaf will be replaced with the leaf of `state'
+   */
+  DiffState&
+  operator += (const DiffState &state);
+  
+  // from State
+  virtual void
+  update (NameInfoConstPtr info, const SeqNo &seq);
+
+  virtual void
+  remove (NameInfoConstPtr info);
+  
+private:
+  DiffStatePtr m_next;
+  // Hash m_digest;
+};
+
+} // Sync
+} // ns3
+
+#endif // SYNC_DIFF_STATE_H
diff --git a/model/sync-full-state.cc b/model/sync-full-state.cc
new file mode 100644
index 0000000..696ac3c
--- /dev/null
+++ b/model/sync-full-state.cc
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "sync-full-state.h"
+
+#include "ns3/simulator.h"
+
+#include <boost/make_shared.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+
+using namespace boost;
+namespace ll = boost::lambda;
+
+namespace ns3 {
+namespace Sync {
+
+
+FullState::FullState ()
+  : m_lastUpdated (0)
+{
+}
+
+FullState::~FullState ()
+{
+}
+
+Time
+FullState::getTimeFromLastUpdate () const
+{
+  return Simulator::Now () - m_lastUpdated;
+}
+  
+// from State
+void
+FullState::update (NameInfoConstPtr info, const SeqNo &seq)
+{
+  m_lastUpdated = Simulator::Now ();
+
+  LeafContainer::iterator item = m_leafs.find (*info);
+  if (item == m_leafs.end ())
+    {
+      m_leafs.insert (make_shared<Leaf> (info, cref (seq)));
+    }
+  else
+    {
+      m_leafs.modify (item, ll::bind (&Leaf::setSeq, ll::_1, cref (seq)));
+    }
+}
+
+void
+FullState::remove (NameInfoConstPtr info)
+{
+  m_lastUpdated = Simulator::Now ();
+
+  m_leafs.remove (info);
+}
+
+
+} // Sync
+} // ns3
diff --git a/model/sync-full-state.h b/model/sync-full-state.h
new file mode 100644
index 0000000..56d7f0d
--- /dev/null
+++ b/model/sync-full-state.h
@@ -0,0 +1,67 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_FULL_STATE_H
+#define SYNC_FULL_STATE_H
+
+#include "sync-state.h"
+
+namespace ns3 {
+namespace Sync {
+
+/**
+ * \ingroup sync
+ * @brief Cumulative SYNC state
+ */
+class FullState : public State
+{
+public:
+  /**
+   * @brief Default constructor
+   */
+  FullState ();
+  virtual ~FullState ();
+
+  /**
+   * @brief Get time period since last state update
+   *
+   * This value can be used to randomize reconciliation waiting time in SyncApp
+   */
+  Time
+  getTimeFromLastUpdate () const;
+  
+  // from State
+  virtual void
+  update (NameInfoConstPtr info, const SeqNo &seq);
+
+  virtual void
+  remove (NameInfoConstPtr info);
+  
+private:
+  Time m_lastUpdated; ///< @brief Time when state was updated last time
+};
+
+
+} // Sync
+} // ns3
+
+#endif // SYNC_STATE_H
diff --git a/model/sync-leaf.cc b/model/sync-leaf.cc
new file mode 100644
index 0000000..2680859
--- /dev/null
+++ b/model/sync-leaf.cc
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
diff --git a/model/sync-leaf.h b/model/sync-leaf.h
new file mode 100644
index 0000000..151f2c6
--- /dev/null
+++ b/model/sync-leaf.h
@@ -0,0 +1,95 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_LEAF_H
+#define SYNC_LEAF_H
+
+#include "sync-seq-no.h"
+#include <boost/shared_ptr.hpp>
+
+namespace ns3 {
+namespace Sync {
+
+class NameInfo;
+
+/**
+ * \ingroup sync
+ * @brief Sync tree leaf
+ */
+class Leaf
+{
+public:
+  /**
+   * @brief Constructor
+   * @param info Smart pointer to leaf's name
+   * @param seq  Initial sequence number of the pointer
+   */
+  Leaf (boost::shared_ptr<const NameInfo> info, const SeqNo &seq)
+    : m_info (info)
+    , m_seq (seq)
+  { }
+
+  virtual ~Leaf ()
+  {
+  }
+  
+  /**
+   * @brief Get name of the leaf
+   */
+  const NameInfo &
+  getInfo () const
+  {
+    return *m_info;
+  }
+
+  /**
+   * @brief Get sequence number of the leaf
+   */
+  const SeqNo&
+  getSeq () const
+  {
+    return m_seq;
+  }
+
+  /**
+   * @brief Update sequence number of the leaf
+   * @param seq Sequence number
+   *
+   * Sequence number is updated to the largest value among this->m_seq and seq
+   */
+  void
+  setSeq (const SeqNo &seq)
+  {
+    m_seq = std::max (m_seq, seq);
+  }
+  
+private:
+  NameInfoConstPtr m_info;
+  SeqNo m_seq;
+};
+
+typedef boost::shared_ptr<Leaf> LeafPtr;
+
+} // Sync
+} // ns3
+
+#endif // SYNC_LEAF_H
diff --git a/model/sync-name-info.cc b/model/sync-name-info.cc
new file mode 100644
index 0000000..2680859
--- /dev/null
+++ b/model/sync-name-info.cc
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
diff --git a/model/sync-name-info.h b/model/sync-name-info.h
new file mode 100644
index 0000000..d0ec575
--- /dev/null
+++ b/model/sync-name-info.h
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_NAME_INFO_H
+#define SYNC_NAME_INFO_H
+
+namespace ns3 {
+namespace Sync {
+
+/**
+ * @brief Abstraction of the leaf name
+ */
+class NameInfo
+{
+public:
+  virtual ~NameInfo () = 0;
+  /**
+   * @brief Calculates digest of the name
+   */
+  // Digest
+  // getDigest () const;
+
+  virtual std::string
+  toString () const = 0;
+};
+
+typedef boost::shared_ptr<NameInfo> NameInfoPtr;
+typedef boost::shared_ptr<const NameInfo> NameInfoConstPtr;
+
+} // Sync
+} // ns3
+
+#endif // SYNC_NAME_INFO_H
diff --git a/model/sync-name-manager.cc b/model/sync-name-manager.cc
new file mode 100644
index 0000000..2680859
--- /dev/null
+++ b/model/sync-name-manager.cc
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
diff --git a/model/sync-name-manager.h b/model/sync-name-manager.h
new file mode 100644
index 0000000..90c71e0
--- /dev/null
+++ b/model/sync-name-manager.h
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_NAME_MANAGER_H
+#define SYNC_NAME_MANAGER_H
+
+namespace ns3
+{
+
+namespace Sync
+{
+
+class NameManager
+{
+public:
+private:
+};
+
+} // Sync
+
+} // ns3
+
+#endif // SYNC_NAME_MANAGER_H
diff --git a/model/sync-seq-no.h b/model/sync-seq-no.h
new file mode 100644
index 0000000..1461acb
--- /dev/null
+++ b/model/sync-seq-no.h
@@ -0,0 +1,105 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_SEQ_NO_H
+#define SYNC_SEQ_NO_H
+
+namespace ns3
+{
+
+namespace Sync
+{
+
+/**
+ * @brief Sequence number abstraction
+ *
+ * 
+ */
+struct SeqNo
+{
+public:
+  /**
+   * @brief Constructor with just sequence number. Session assumed to be zero
+   * @param seq Sequence number
+   */
+  SeqNo (uint32_t seq)
+    : m_session (0)
+    , m_seq (seq)
+  { }
+
+  /**
+   * @brief Constructor with session and sequence id
+   * @param session Session ID
+   * @param seq Sequence number
+   */
+  SeqNo (uint32_t session, uint32_t seq)
+    : m_session (session)
+    , m_seq (seq)
+  { }
+  
+  /**
+   * @brief Session ID (e.g., after crash, application will choose new session ID.
+   *
+   * Note that session IDs for the same name should always increase. So, the good choice
+   * for the session ID is client's timestamp
+   */
+  uint32_t m_session;
+
+  /**
+   * @brief Sequence number
+   *
+   * Sequence number for a session always starts with 0 and goes to max value.
+   *
+   * For now, wrapping sequence number after max to zero is not supported
+   */
+  uint32_t m_seq;
+
+  /**
+   * @brief Compare if one sequence number is lower
+   * @param seq Another sequence number to compare with
+   *
+   * tuple (session1, seq1) is less than (session2, seq2) in two cases:
+   * 1. session1 < session2
+   * 2. session1 == session2 and seq1 < seq2
+   */
+  bool
+  operator < (const SeqNo &seq) const
+  {
+    return m_session < seq.m_session || (m_session == seq.m_session && m_seq < seq.m_seq);
+  }
+
+  /**
+   * @brief Compare if two sequence numbers are equal
+   * @param seq Another sequence number to compare with
+   */
+  bool
+  operator == (const SeqNo &seq) const
+  {
+    return m_session == seq.m_session && m_seq == seq.m_seq;
+  }
+};
+
+} // Sync
+
+} // ns3
+
+#endif // SYNC_SEQ_NO_H
diff --git a/model/sync-state-leaf-container.h b/model/sync-state-leaf-container.h
new file mode 100644
index 0000000..f66c966
--- /dev/null
+++ b/model/sync-state-leaf-container.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_STATE_LEAF_CONTAINER
+#define SYNC_STATE_LEAF_CONTAINER
+
+#include <boost/multi_index_container.hpp>
+// #include <boost/multi_index/tag.hpp>
+// #include <boost/multi_index/ordered_index.hpp>
+// #include <boost/multi_index/composite_key.hpp>
+#include <boost/multi_index/hashed_index.hpp>
+// #include <boost/multi_index/random_access_index.hpp>
+// #include <boost/multi_index/member.hpp>
+#include <boost/multi_index/mem_fun.hpp>
+
+namespace mi = boost::multi_index;
+
+namespace ns3 {
+namespace Sync {
+
+/**
+ * \ingroup sync
+ * @brief Container for SYNC leaves
+ */
+struct LeafContainer : public mi::multi_index_container<
+    LeafPtr,
+    mi::indexed_by<
+      // For fast access to elements using NameInfo
+      mi::hashed_unique<
+        mi::const_mem_fun<Leaf, const NameInfo&, &Leaf::getInfo>,
+        LeafHash (),
+        LeafEqual () 
+      >
+    >
+   >
+{
+};
+
+} // Sync
+} // ns3
+
+#endif // SYNC_STATE_LEAF_CONTAINER
diff --git a/model/sync-state-manager.cc b/model/sync-state-manager.cc
new file mode 100644
index 0000000..2680859
--- /dev/null
+++ b/model/sync-state-manager.cc
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
diff --git a/model/sync-state-manager.h b/model/sync-state-manager.h
new file mode 100644
index 0000000..2d05055
--- /dev/null
+++ b/model/sync-state-manager.h
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_STATE_MANAGER_H
+#define SYNC_STATE_MANAGER_H
+
+namespace ns3
+{
+
+namespace Sync
+{
+
+class StateManager
+{
+public:
+private:
+};
+
+} // Sync
+
+} // ns3
+
+#endif // SYNC_STATE_MANAGER_H
diff --git a/model/sync-state.cc b/model/sync-state.cc
new file mode 100644
index 0000000..2680859
--- /dev/null
+++ b/model/sync-state.cc
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
diff --git a/model/sync-state.h b/model/sync-state.h
new file mode 100644
index 0000000..c6511e5
--- /dev/null
+++ b/model/sync-state.h
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
+ *         卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
+ *	   Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef SYNC_STATE_H
+#define SYNC_STATE_H
+
+#include "sync-state-leaf-container.h"
+
+namespace ns3 {
+
+/**
+ * \defgroup sync SYNC protocol
+ *
+ * Implementation of SYNC protocol
+ */
+namespace Sync {
+
+/**
+ * \ingroup sync
+ * @brief Container for state leaves and definition of the abstract interface to work with State objects
+ */
+class State
+{
+public:
+  virtual ~State () = 0;
+  
+  /**
+   * @brief Add or update leaf to the state tree
+   *
+   * @param info name of the leaf
+   * @param seq  sequence number of the leaf
+   */
+  virtual void
+  update (NameInfoConstPtr info, const SeqNo &seq) = 0;
+
+  /**
+   * @brief Remove leaf from the state tree
+   *
+   * @param info name of the leaf
+   */
+  virtual void
+  remove (NameInfoConstPtr info) = 0;
+
+protected:
+  LeafContainer m_leaves;
+};
+
+} // Sync
+} // ns3
+
+#endif // SYNC_STATE_H
diff --git a/wscript b/wscript
new file mode 100644
index 0000000..4120c88
--- /dev/null
+++ b/wscript
@@ -0,0 +1,39 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+# def options(opt):
+#     pass
+
+# def configure(conf):
+#     conf.check_nonfatal(header_name='stdint.h', define_name='HAVE_STDINT_H')
+
+def build (bld):
+    deps = ['core', 'network', 'NDNabstraction']
+    if bld.env['ENABLE_PYTHON_BINDINGS']:
+        deps.append ('visualizer')
+
+    module = bld.create_ns3_module ('sync', deps)
+    module.uselib = 'BOOST BOOST_IOSTREAMS'
+
+    # tests = bld.create_ns3_module_test_library('sync')
+    # tests.source = [
+    #     'test/sync-test-suite.cc',
+    #     ]
+
+    headers = bld.new_task_gen(features=['ns3header'])
+    headers.module = 'sync'
+    headers.source = [
+        'model/sync-app.h',
+        ]
+
+    # if not bld.env['ENABLE_NDN_ABSTRACT']:
+    #     bld.env['MODULES_NOT_BUILT'].append('NDNabstraction')
+    #     return
+   
+    module.source = bld.path.ant_glob(['model/*.cc',
+                                       'helper/*.cc'])
+
+    # if bld.env.ENABLE_EXAMPLES:
+    #     bld.add_subdirs('examples')
+
+    # bld.ns3_python_bindings()
+