Beispiel #1
0
        public void testDeliverVeryManyMessages()
        {
            Console.WriteLine("--> deliver very many messages");

            string[] teststrings = new string[10000];
            for (int i = 0; i < teststrings.Length; i++)
            {
                teststrings[i] = "Test string " + i;
            }
            SCTPStream s = mockStream();
            SortedArray <DataChunk> stash  = new SortedArray <DataChunk>();
            List <string>           result = new List <string>();
            ushort mo = (ushort)0;

            foreach (string ts in teststrings)
            {
                DataChunk single = new DataChunk();
                single.setTsn(_tsn++);
                single.setsSeqNo((int)mo++);
                single.setData(ts.getBytes());
                single.setPpid(DataChunk.WEBRTCstring);
                single.setFlags(DataChunk.SINGLEFLAG);
                stash.Add(single);
                result.Add(ts);
            }
            SCTPStreamListener     l        = new CheckingStreamListener(result);
            OrderedStreamBehaviour instance = new OrderedStreamBehaviour();

            instance.deliver(s, stash, l);
        }
Beispiel #2
0
        public void testDeliverTwo()
        {
            Console.WriteLine("--> deliver two");
            SCTPStream s = mockStream();
            SortedArray <DataChunk> stash = new SortedArray <DataChunk>();

            string[]      teststrings = new string[] { "Test string A", "Test string B" };
            List <string> result      = new List <string>();
            int           n           = 0;

            foreach (string ts in teststrings)
            {
                DataChunk single = new DataChunk();
                single.setTsn(_tsn++);
                single.setsSeqNo(n++);
                single.setData(ts.getBytes());
                single.setPpid(DataChunk.WEBRTCstring);
                single.setFlags(DataChunk.SINGLEFLAG);
                stash.Add(single);
                result.Add(ts);
            }
            SCTPStreamListener     l        = new CheckingStreamListener(result);
            OrderedStreamBehaviour instance = new OrderedStreamBehaviour();

            instance.deliver(s, stash, l);

            int remain = result.Count;

            Assert.AreEqual(remain, 0);
        }
Beispiel #3
0
        public void testDeliverSingle()
        {
            Console.WriteLine("--> deliver single");
            SCTPStream s = mockStream();
            SortedArray <DataChunk> stash = new SortedArray <DataChunk>();
            DataChunk single     = new DataChunk();
            string    teststring = "Test string";

            single.setData(teststring.getBytes());
            single.setPpid(DataChunk.WEBRTCstring);
            single.setFlags(DataChunk.SINGLEFLAG);
            single.setTsn(_tsn++);
            single.setsSeqNo(0);
            stash.Add(single);
            List <string> result = new List <string>();

            result.Add(teststring);
            SCTPStreamListener     l        = new CheckingStreamListener(result);
            OrderedStreamBehaviour instance = new OrderedStreamBehaviour();

            instance.deliver(s, stash, l);
            int remain = result.Count;

            Assert.AreEqual(remain, 0);
        }
Beispiel #4
0
        void oneMissingPartMessages(string[] teststrings, string es, int ec)
        {
            SCTPStream s = mockStream();
            SortedArray <DataChunk> stash  = new SortedArray <DataChunk>();
            List <string>           result = new List <string>();
            int  n = 0;
            int  expectedToRemain = 0;
            bool skip             = false;

            foreach (string ts in teststrings)
            {
                for (int i = 0; i < ts.Length; i++)
                {
                    DataChunk single = new DataChunk();
                    single.setTsn(_tsn++);
                    single.setsSeqNo(n);
                    string letter = ts.Substring(i, 1);
                    single.setData(letter.getBytes());
                    single.setPpid(DataChunk.WEBRTCstring);
                    if (i == 0)
                    {
                        single.setFlags(DataChunk.BEGINFLAG);
                    }
                    else if (i == ts.Length - 1)
                    {
                        single.setFlags(DataChunk.ENDFLAG);
                    }
                    if ((ec != i) || !ts.Equals(es))
                    {
                        stash.Add(single);
                    }
                }
                if (ts.Equals(es))
                {
                    skip = true;
                }
                if (skip)
                {
                    expectedToRemain++;
                }
                result.Add(ts);
                n++;
            }

            SCTPStreamListener     l        = new CheckingStreamListener(result);
            OrderedStreamBehaviour instance = new OrderedStreamBehaviour();

            instance.deliver(s, stash, l);

            int remain = result.Count;

            //Console.WriteLine("expected:" + expectedToRemain + " remain:" + remain);

            Assert.AreEqual(remain, expectedToRemain);
        }
Beispiel #5
0
        public void deliverUnorderedPackets(int seed)
        {
            Random rand = new Random(seed);             // deliberately not crypto random so test is repeatable

            // Console.WriteLine("seed = "+seed);
            string[]         teststrings = { "Test string A, ", "Test string B ", "and Test string C" };
            SCTPStream       s           = mockStream();
            List <string>    result      = new List <string>();
            int              n           = 0;
            List <DataChunk> all         = new List <DataChunk>();

            foreach (string ts in teststrings)
            {
                for (int i = 0; i < ts.Length; i++)
                {
                    DataChunk single = new DataChunk();
                    single.setTsn(_tsn++);
                    single.setsSeqNo(n);
                    string letter = ts.Substring(i, 1);
                    single.setData(letter.getBytes());
                    single.setPpid(DataChunk.WEBRTCstring);
                    if (i == 0)
                    {
                        single.setFlags(DataChunk.BEGINFLAG);
                    }
                    else if (i == ts.Length - 1)
                    {
                        single.setFlags(DataChunk.ENDFLAG);
                    }
                    all.Add(single);
                }
                result.Add(ts);
                n++;
            }

            SCTPStreamListener      l        = new CheckingStreamListener(result);
            OrderedStreamBehaviour  instance = new OrderedStreamBehaviour();
            SortedArray <DataChunk> stash    = new SortedArray <DataChunk>();

            while (all.Count > 0)
            {
                int       v = rand.Next(all.Count);
                DataChunk c = all[v];
                all.RemoveAt(v);
                stash.Add(c);
                instance.deliver(s, stash, l);
            }

            int remain = result.Count;

            Assert.AreEqual(remain, 0);
        }
Beispiel #6
0
        void multiPartMessage(string[] teststrings)
        {
            SCTPStream s = mockStream();
            SortedArray <DataChunk> stash  = new SortedArray <DataChunk>();
            List <string>           result = new List <string>();
            int           n  = 0;
            StringBuilder bs = new StringBuilder();

            foreach (string ts in teststrings)
            {
                DataChunk single = new DataChunk();
                single.setTsn((uint)_tsn++);
                single.setsSeqNo(0);
                single.setData(ts.getBytes());
                single.setPpid(DataChunk.WEBRTCstring);
                if (n == 0)
                {
                    single.setFlags(DataChunk.BEGINFLAG);
                }
                else if (n == teststrings.Length - 1)
                {
                    single.setFlags(DataChunk.ENDFLAG);
                }
                n++;
                bs.Append(ts);
                stash.Add(single);
            }
            result.Add(bs.ToString());
            SCTPStreamListener       l        = new CheckingStreamListener(result);
            UnorderedStreamBehaviour instance = new UnorderedStreamBehaviour();

            instance.deliver(s, stash, l);

            int remain = result.Count;

            Assert.AreEqual(remain, 0);
        }
Beispiel #7
0
        void dontDeliverOnePart(int flag)
        {
            SCTPStream s = mockStream();
            SortedArray <DataChunk> stash = new SortedArray <DataChunk>();
            DataChunk single     = new DataChunk();
            string    teststring = "Test string";

            single.setData(teststring.getBytes());
            single.setPpid(DataChunk.WEBRTCstring);
            single.setFlags(flag);
            single.setTsn(_tsn++);
            single.setsSeqNo(0);
            stash.Add(single);
            List <string> result = new List <string>();

            result.Add(teststring);
            SCTPStreamListener     l        = new CheckingStreamListener(result);
            OrderedStreamBehaviour instance = new OrderedStreamBehaviour();

            instance.deliver(s, stash, l);
            int remain = result.Count;

            Assert.AreEqual(1, remain);
        }