integration in progress
authorvictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Wed, 7 Oct 2009 11:29:59 +0000 (11:29 +0000)
committervictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Wed, 7 Oct 2009 11:29:59 +0000 (11:29 +0000)
git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@394 e16421f0-f15b-0410-abcd-98678b794739

doc/binmaps-alenex.pdf [new file with mode: 0644]
doc/lancaster.txt [deleted file]
doc/p2tp-lancaster.pdf [new file with mode: 0755]
doc/p2tp-uml-er.pdf [new file with mode: 0644]
file.h [deleted file]
tests/binstest2.cpp [new file with mode: 0755]

diff --git a/doc/binmaps-alenex.pdf b/doc/binmaps-alenex.pdf
new file mode 100644 (file)
index 0000000..d67b8c2
Binary files /dev/null and b/doc/binmaps-alenex.pdf differ
diff --git a/doc/lancaster.txt b/doc/lancaster.txt
deleted file mode 100644 (file)
index d4d79cb..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-* MISSION : <1 min
-    * multiparty transport protocol
-    * diverse usecases (files, VoD, live)
-    * for embedded 24x7 use
-* OBJECTIVES : 1 min
-    * light footprint (embedded)
-    * NAT penetration
-    * non-intrusive congestion control
-    * genericity
-* METHOD : 1 min
-    * UDP
-    * LEDBAT (Mugurel)
-    * common messages 
-    * Merkle hashes
-    * binmaps
-* STATUS : 5 min
-    * state machine: implemented
-    * congestion control: implemented
-    * binmaps: implemented
-    * streaming: in progress
-    * todo: test, integrate, test
-* HELP NEEDED : 4 min
-    * testing
-    * security
-    * robustness
-    * usecases
-
diff --git a/doc/p2tp-lancaster.pdf b/doc/p2tp-lancaster.pdf
new file mode 100755 (executable)
index 0000000..4bed32b
Binary files /dev/null and b/doc/p2tp-lancaster.pdf differ
diff --git a/doc/p2tp-uml-er.pdf b/doc/p2tp-uml-er.pdf
new file mode 100644 (file)
index 0000000..4d858ec
Binary files /dev/null and b/doc/p2tp-uml-er.pdf differ
diff --git a/file.h b/file.h
deleted file mode 100644 (file)
index 29e8f6b..0000000
--- a/file.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#include <mmap.h>
-
-namespace p2tp {
-
-       class   File {
-               
-               typedef enum {EMPTY,IN_PROGRESS,DONE} status_t;
-
-               static std::vector<File*> files;
-               
-               /**     File descriptor. */
-               int                             fd;
-               /**     Whether the file is completely downloaded. */
-               status_t                status_;
-               
-               //      A map for all packets obtained and succesfully checked.
-               bins                    ack_out;
-               //      Hinted packets.
-               bins                    hint_out;
-               
-               HashTree                hashes;
-               //      History of bin retrieval.
-               bin::vec                history;
-               
-               // TBD
-               uint64_t                options;
-
-               /**     Submit a fresh file. */
-               File (int fd);
-               /**     Retrieve a file.        */
-               File (Sha1Hash hash, int fd);
-               /**     Placeholder. */
-               File () : fd(-1), hashes(Sha1Hash::ZERO) {}
-               /**     Close everything. */
-               ~File();
-               
-               bool OfferHash (bin pos, const Sha1Hash& hash);
-               const Sha1Hash& root_hash () const { return hashes.root; }
-               size_t          size () const { return hashes.data_size()<<10; }
-               size_t          packet_size () const { return hashes.data_size(); }
-               status_t status () const { return status_; }
-               
-               static File* find (const Sha1Hash& hash);
-               static File* file (int fd) { return fd<files.size() ? files[fd] : NULL; }
-
-               friend int Open (const char* filename);
-               friend int Open (const Sha1Hash& hash, const char* filename);
-               friend void Close (int fdes);
-               friend class Channel;
-       
-       
-       int             Open (const char* filename) ;
-           int         Open (const Sha1Hash& root_hash, const char* filename); 
-       size_t  file_size (int fd);     
-       void    Close (int fid) ;
-       
-        void*   Map(bin64_t bin);
-        void    UnMap(void*);
-
-       };
-
-};
diff --git a/tests/binstest2.cpp b/tests/binstest2.cpp
new file mode 100755 (executable)
index 0000000..35eb9d4
--- /dev/null
@@ -0,0 +1,230 @@
+/*
+ *  binstest.cpp
+ *  serp++
+ *
+ *  Created by Victor Grishchenko on 3/22/09.
+ *  Copyright 2009 Delft Technical University. All rights reserved.
+ *
+ */
+#include <time.h>
+#include <set>
+#include <gtest/gtest.h>
+#include "bins.h"
+
+
+TEST(BinsTest,Routines) {
+
+    uint32_t cell = (3<<10) | (3<<14) | (3<<0);
+    uint16_t correct = (1<<5) | (1<<7) | (1<<0);
+    uint16_t joined  = bins::join32to16(cell);
+    EXPECT_EQ(correct,joined);
+    
+    uint32_t split = bins::split16to32(correct);
+    EXPECT_EQ(cell,split);
+    
+    EXPECT_EQ(bins::NOJOIN,bins::join32to16(cell|4));
+
+}
+
+TEST(BinsTest,SetGet) {
+
+    bins bs;
+    bin64_t b3(1,0), b2(0,1), b4(0,2), b6(1,1), b7(2,0);
+    bs.set(b3);
+    //bs.dump("set done");
+    EXPECT_EQ(bins::FILLED,bs.get(b3));
+    //bs.dump("set checkd");
+    EXPECT_EQ(bins::FILLED,bs.get(b2));
+    //bs.dump("get b2 done");
+    EXPECT_EQ(bins::FILLED,bs.get(b3));
+    //bs.dump("get b3 done");
+    EXPECT_EQ(bins::EMPTY,bs.get(b4));
+    EXPECT_EQ(bins::EMPTY,bs.get(b6));
+    EXPECT_NE(bins::FILLED,bs.get(b7));
+    EXPECT_NE(bins::EMPTY,bs.get(b7));
+    EXPECT_EQ(bins::FILLED,bs.get(b3));
+    bs.set(bin64_t(1,1));
+    EXPECT_EQ(bins::FILLED,bs.get(bin64_t(2,0)));
+
+}
+
+TEST(BinsTest,Iterator) {
+    bins b;
+    b.set(bin64_t(3,1));
+    iterator i(&b,0,false);
+    while (!i.solid())
+        i.left();
+    EXPECT_EQ(bin64_t(3,0),i.bin());
+    EXPECT_EQ(false,i.deep());
+    EXPECT_EQ(true,i.solid());
+    EXPECT_EQ(bins::EMPTY,*i);
+    i.next();
+    EXPECT_EQ(bin64_t(3,1),i.bin());
+    EXPECT_EQ(false,i.deep());
+    EXPECT_EQ(true,i.solid());
+    EXPECT_EQ(bins::FILLED,*i);
+    i.next();
+    EXPECT_TRUE(i.end());
+}
+
+TEST(BinsTest,Chess) {
+    bins chess16;
+    for(int i=0; i<15; i++)
+        chess16.set(bin64_t(0,i), (i&1)?bins::FILLED:bins::EMPTY);
+    chess16.set(bin64_t(0,15), bins::FILLED);
+    for(int i=0; i<16; i++)
+        EXPECT_EQ((i&1)?bins::FILLED:bins::EMPTY, chess16.get(bin64_t(0,i)));
+    EXPECT_NE(bins::FILLED,chess16.get(bin64_t(4,0)));
+    EXPECT_NE(bins::EMPTY,chess16.get(bin64_t(4,0)));
+    for(int i=0; i<16; i+=2)
+        chess16.set(bin64_t(0,i), bins::FILLED);
+    EXPECT_EQ(bins::FILLED,chess16.get(bin64_t(4,0)));
+    EXPECT_EQ(bins::FILLED,chess16.get(bin64_t(2,3)));
+    
+    chess16.set(bin64_t(4,1),bins::FILLED);
+    EXPECT_EQ(bins::FILLED,chess16.get(bin64_t(5,0)));
+}
+
+TEST(BinsTest,Staircase) {
+    
+    const int TOPLAYR = 44;
+    bins staircase;
+    for(int i=0;i<TOPLAYR;i++)
+        staircase.set(bin64_t(i,1),bins::FILLED);
+    
+    EXPECT_NE(bins::FILLED,staircase.get(bin64_t(TOPLAYR,0)));
+    EXPECT_NE(bins::EMPTY,staircase.get(bin64_t(TOPLAYR,0)));
+
+    staircase.set(bin64_t(0,0),bins::FILLED);
+    EXPECT_EQ(bins::FILLED,staircase.get(bin64_t(TOPLAYR,0)));
+
+}
+
+TEST(BinsTest,Hole) {
+    
+    bins hole;
+    hole.set(bin64_t(8,0),bins::FILLED);
+    hole.set(bin64_t(6,1),bins::EMPTY);
+    hole.set(bin64_t(6,2),bins::EMPTY);
+    EXPECT_EQ(bins::FILLED,hole.get(bin64_t(6,0)));
+    EXPECT_EQ(bins::FILLED,hole.get(bin64_t(6,3)));
+    EXPECT_NE(bins::FILLED,hole.get(bin64_t(8,0)));
+    EXPECT_NE(bins::EMPTY,hole.get(bin64_t(8,0)));
+    EXPECT_EQ(bins::EMPTY,hole.get(bin64_t(6,1)));
+    
+}
+
+TEST(BinsTest,Find){
+    
+    bins hole;
+    hole.set(bin64_t(4,0),bins::FILLED);
+    hole.set(bin64_t(1,1),bins::EMPTY);
+    hole.set(bin64_t(0,7),bins::EMPTY);
+    bin64_t f = hole.find(bin64_t(4,0),0);
+    EXPECT_EQ(bin64_t(0,2),f);
+    
+}
+
+TEST(BinsTest,Stripes) {
+    
+    bins zebra;
+    zebra.set(bin64_t(5,0));
+    zebra.set(bin64_t(3,1),bins::EMPTY);
+    zebra.set(bin64_t(1,12),bins::EMPTY);
+    zebra.set(bin64_t(1,14),bins::EMPTY);
+    int count;
+    uint64_t *stripes = zebra.get_stripes(count);
+    EXPECT_EQ(9,count);
+    EXPECT_EQ(0,stripes[0]);
+    EXPECT_EQ(0,stripes[1]);
+    EXPECT_EQ(8,stripes[2]);
+    EXPECT_EQ(16,stripes[3]);
+    EXPECT_EQ(24,stripes[4]);
+    EXPECT_EQ(26,stripes[5]);
+    EXPECT_EQ(28,stripes[6]);
+    EXPECT_EQ(30,stripes[7]);
+    EXPECT_EQ(32,stripes[8]);
+    free(stripes);
+
+}
+
+TEST(BinsTest,StripesAgg) {
+    
+    bins zebra;
+    zebra.set(bin64_t(0,1));
+    zebra.set(bin64_t(0,2));
+    int count;
+    uint64_t *stripes = zebra.get_stripes(count);
+    EXPECT_EQ(3,count);
+    EXPECT_EQ(0,stripes[0]);
+    EXPECT_EQ(1,stripes[1]);
+    EXPECT_EQ(3,stripes[2]);
+    free(stripes);
+    
+}    
+
+TEST(BinsTest,Alloc) {
+
+    bins b;
+    b.set(bin64_t(1,0));
+    b.set(bin64_t(1,1));
+    b.set(bin64_t(1,0),bins::EMPTY);
+    b.set(bin64_t(1,1),bins::EMPTY);
+    EXPECT_EQ(1,b.size());
+
+}
+
+/*TEST(BinsTest,AddSub) {
+       bins b;
+       b|=15;
+       b-=1;
+       ASSERT_TRUE(b.contains(2));
+       ASSERT_TRUE(b.contains(14));
+       ASSERT_FALSE(b.contains(3));
+       ASSERT_FALSE(b.contains(22));
+       ASSERT_TRUE(b.contains(12));
+       b-=13;
+       ASSERT_FALSE(b.contains(12));
+       ASSERT_FALSE(b.contains(14));
+       ASSERT_FALSE(b.contains(11));
+       ASSERT_TRUE(b.contains(10));
+}
+
+
+TEST(BinsTest,Peaks) {
+       bin::vec peaks = bin::peaks(11);
+       ASSERT_EQ(3,peaks.size());
+       ASSERT_EQ(15,peaks[0]);
+       ASSERT_EQ(18,peaks[1]);
+       ASSERT_EQ(19,peaks[2]);
+}
+
+TEST(BinsTest,Performance) {
+       bins b;
+       std::set<int> s;
+       clock_t start, end;
+       double b_time, s_time;
+       int b_size, s_size;
+       
+       start = clock();
+       for(int i=1; i<(1<<20); i++)
+               b |= bin(i);
+       //b_size = b.bits.size();
+       end = clock();  
+       b_time = ((double) (end - start)) / CLOCKS_PER_SEC;
+       //ASSERT_EQ(1,b.bits.size());
+       
+       start = clock();
+       for(int i=1; i<(1<<20); i++)
+               s.insert(i);
+       s_size = s.size();
+       end = clock();
+       s_time = ((double) (end - start)) / CLOCKS_PER_SEC;
+       
+       printf("bins: %f (%i), set: %f (%i)\n",b_time,b_size,s_time,s_size);
+}*/
+
+int main (int argc, char** argv) {
+       testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}