Ejemplo n.º 1
0
 public void Close()
 {
     Logger.Debug("Closing transports");
     if (TCPTransport != null)
     {
         TCPTransport.Close();
     }
     if (UDPTransport != null)
     {
         UDPTransport.Close();
     }
     foreach (var tunnelContainer in _tunnels.Values)
     {
         Logger.Debug("Closing tunnel " + tunnelContainer.Tunnel.Id);
         try
         {
             tunnelContainer.Tunnel.Close();
         }
         catch (Exception e)
         {
             Logger.Warn("Closing tunnel " + tunnelContainer.Tunnel.Id + " failed : " + e.Message);
         }
     }
     _tunnels.Clear();
 }
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec        codec = new Codec();
            Serializer   s     = new DefaultSerializer();

            byte[] key   = s.serialize("key12");
            byte[] value = s.serialize("trinitrotoluene");

            byte[] cacheName  = null;
            int    topologyId = 0;

            Flag[] flags = null;

            int  lifespan = 0;
            int  maxIdle  = 0;
            long version  = 0;
            ReplaceIfUnmodifiedOperation target = new ReplaceIfUnmodifiedOperation(codec, key, cacheName, topologyId, flags, value, lifespan, maxIdle, version);
            Transport transport = trans;
            VersionedOperationResponse expected = null;
            VersionedOperationResponse actual;

            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual.isUpdated());
        }
Ejemplo n.º 3
0
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec        codec = new Codec();

            ClearOperation target    = new ClearOperation(codec, null, 0, null);
            Transport      transport = null;

            target.executeOperation(transport);
        }
Ejemplo n.º 4
0
        public void executeTest()
        {
            Transport     trans  = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec         codec  = new Codec();
            PingOperation target = new PingOperation(codec, 0, trans);

            PingOperation.PingResult expected = PingOperation.PingResult.SUCCESS;
            PingOperation.PingResult actual;
            actual = target.execute();
            Assert.AreEqual(expected, actual);
        }
 private void PhysicalLayerPump()
 {
     while (true)
     {
         lock (PhysicalLayerLock)
         {
             while (PhysicalLayer.Count == 0)
             {
                 Monitor.Wait(PhysicalLayerLock);
             }
         }
         long currentLatencyValue = _transportForm.Latency;
         while (PhysicalLayer.Count > 0)
         {
             var packetHolder = (PhysicalPacketHolder)PhysicalLayer.Dequeue();
             // drop the packet (maybe)
             if (rand.Next(100) < _transportForm.PacketLoss)
             {
                 Logger.Warn("Ooops dropped a packet : " + packetHolder._packet);
                 if (_client)
                 {
                     _transportForm.ClientPacketLoss++;
                 }
                 else
                 {
                     _transportForm.ServerPacketLoss++;
                 }
             }
             else
             {
                 long latencySoFar = Environment.TickCount - packetHolder._sendTime;
                 // latency is done here
                 if (latencySoFar < currentLatencyValue)
                 {
                     //Logger.Info("Implementing remainder latency of " + (currentLatencyValue - latencySoFar) + "ms");
                     Thread.Sleep(TimeSpan.FromMilliseconds(currentLatencyValue - latencySoFar));
                 }
                 // Now pass this onto my Transport
                 Logger.Info("Received packet [size=" + packetHolder._packet.Payload.Length +
                             "] from physical layer, " + PhysicalLayer.Count + " still on the wire.");
                 TCPTransport.ProcessPacket(packetHolder._packet.GetBytes());
                 var actualLatency = Environment.TickCount - packetHolder._sendTime;
                 if (_client)
                 {
                     _transportForm.ClientLatency = actualLatency;
                 }
                 else
                 {
                     _transportForm.ServerLatency = actualLatency;
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec        codec = new Codec();

            byte[] key = UTF8Encoding.UTF8.GetBytes("key10");

            ContainsKeyOperation target    = new ContainsKeyOperation(codec, key, null, 0, null);
            Transport            transport = trans;
            bool expected = false;
            bool actual;

            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual);
        }
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec        codec = new Codec();
            Serializer   s     = new DefaultSerializer();

            byte[] key = UTF8Encoding.UTF8.GetBytes("key10");

            RemoveIfUnmodifiedOperation target = new RemoveIfUnmodifiedOperation(codec, key, null, 0, null, 11);
            Transport transport = trans;
            VersionedOperationResponse expected = null;
            VersionedOperationResponse actual;

            actual = target.executeOperation(transport);
            // Assert.AreEqual(expected, actual.getValue);
        }
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec        codec = new Codec();

            byte[] key = UTF8Encoding.UTF8.GetBytes("key10");


            GetWithVersionOperation target = new GetWithVersionOperation(codec, key, null, 0, null);
            Transport            transport = trans;
            BinaryVersionedValue expected  = null;
            BinaryVersionedValue actual;

            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual.Ver1);
        }
 public ProxyTransportManager(TransportForm transportForm, bool client)
 {
     _isActive = true;
     OnActive(EventArgs.Empty);
     stopwatch                  = new Stopwatch();
     _transportForm             = transportForm;
     _client                    = client;
     rand                       = new Random();;
     TCPTransport               = new TCPTransport(this);
     PhysicalLayer              = Queue.Synchronized(new Queue());
     _physicalTransporterThread = new Thread(PhysicalLayerPump)
     {
         IsBackground = true, Name = _client ? "ClientReceiveThread" : "ServerReceiveThread"
     };
     _physicalTransporterThread.Start();
 }
Ejemplo n.º 10
0
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec        codec = new Codec();

            byte[] cacheName  = null;
            int    topologyId = 0;

            Flag[]         flags     = null;
            StatsOperation target    = new StatsOperation(codec, cacheName, topologyId, flags);
            Transport      transport = trans;
            string         expected  = "";
            Dictionary <string, string> actual;

            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual[ServerStatistics.CURRENT_NR_OF_ENTRIES]);
        }
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec        codec = new Codec();
            Serializer   s     = new DefaultSerializer();

            //byte[] key = UTF8Encoding.UTF8.GetBytes("key11");
            byte[] key = s.serialize("key12");
            byte[] val = s.serialize("ozone");

            PutIFAbsentOperation target    = new PutIFAbsentOperation(codec, key, null, 0, null, val, 0, 0);
            Transport            transport = trans;

            byte[] expected = null;
            byte[] actual;
            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public void executeOperationTest()
        {
            Transport  trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec      codec = new Codec();
            Serializer s     = new DefaultSerializer();
            Serializer s2    = new DefaultSerializer();


            //byte[] key = s.serialize("11");
            byte[] key = s.serialize("key15");
            //byte[] key=UTF8Encoding.UTF8.GetBytes("key10");
            byte[]       val       = s.serialize("hexachlorocyclohexane777");                //UTF8Encoding.UTF8.GetBytes("hexachlorocyclohexane777");
            PutOperation target    = new PutOperation(codec, key, null, 0, null, val, 0, 0); // TODO: Initialize to an appropriate value
            Transport    transport = trans;

            byte[] expected = null; // TODO: Initialize to an appropriate value
            byte[] actual;
            actual = target.executeOperation(transport);
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
        public void executeOperationTest()
        {
            TCPTransport trans = new TCPTransport(System.Net.IPAddress.Loopback, 11222);
            Codec        codec = new Codec();
            Serializer   s     = new DefaultSerializer();

            // byte[] key = s.serialize("11");

            byte[] key = s.serialize("key10");
            //byte[] key= UTF8Encoding.UTF8.GetBytes("key10");

            GetOperation target    = new GetOperation(codec, key, null, 0, null);
            Transport    transport = trans;
            string       expected  = "hexachlorocyclohexane 777";

            byte[] actual;
            actual = target.executeOperation(transport);
            string res = (string)(s.deserialize(actual));


            Assert.AreEqual(expected, res);
        }
Ejemplo n.º 14
0
        private void ProcessTunnelData(byte[] bytes, String id)
        {
            // Get the transport packet type out before
            byte[] packetData = new byte[bytes.Length - 1];
            Array.Copy(bytes, 1, packetData, 0, bytes.Length - 1);
            // Set this tunnel as MRU
            if (id != null && (_mruTunnel == null || !_mruTunnel.Tunnel.Id.Equals(id)) && _tunnels.ContainsKey(id))
            {
#if DEBUG
                Logger.Debug("Received data on tunnel " + id + ", this tunnels is now MRU");
#endif

                _mruTunnel = _tunnels[id];
            }
            if (bytes[0] == PACKET_TYPE_TCP)
            {
                TCPTransport.ProcessPacket(packetData);
            }
            else
            {
                Logger.Error("Error processing tunnel data, packet type not supported " + bytes[0]);
            }
        }
Ejemplo n.º 15
0
 public TCPConnectionHelper(TCPTransport transport)
 {
     _transport = transport;
     _rand      = new Random();
 }
Ejemplo n.º 16
0
 public TransportManager()
 {
     _tunnels     = new Dictionary <string, TunnelContainer>();
     TCPTransport = new TCPTransport(this);
     UDPTransport = new UDPTransport(this);
 }