Example #1
0
        public static bool Stop()
        {
            Status.Update(State.Stopping);
            TapInterface.PutDown();
            LoadingForm splash = LoadingForm.Create("Stopping Load Balancer ...");

            if (physicalWorkers.Count() > 0)
            {
                for (int i = physicalWorkers.Count() - 1; i >= 0; i--)
                {
                    splash.UpdateStatus("Stop capturing from " + physicalWorkers[i].Name + " ...");
                    physicalWorkers[i].Stop();
                    physicalWorkers.RemoveAt(i);
                }
            }
            splash.UpdateStatus("Stop capturing from " + tapWorker.Name + " ...");
            tapWorker.Stop();
            splash.UpdateStatus("Clearing routing table ...");
            RoutingTable.Clear();
            Dependencies.WinPcapInUse.Signal();
            splash.Stop();
            Global.WriteLog("Load Balancer stopped.", true);
            Status.Update(State.Stopped);
            return(true);
        }
Example #2
0
 public void Clear()
 {
     _playerIds.Clear();
     _clientsByConnection.Clear();
     _connectionsByRoom.Clear();
     _connectionsByPlayerId.Clear();
 }
Example #3
0
        public void ReceivePlayerRoutingUpdate(ref PacketReader reader)
        {
            //This method allocates a few temporary lists. This is ok because it only happens very rarely - when a player joins or leaves the session
            Log.Debug("Received player routing table");

            //Deserialize the new session state (this is essentially a list of all players in the session)
            _tempNewRoutingTable.Clear();
            _tempNewRoutingTable.Deserialize(ref reader);

            //Check our own ID. If this isn't present something is wrong and bail out.
            LocalPeerId = _tempNewRoutingTable.GetId(_client.PlayerName);
            if (!LocalPeerId.HasValue)
            {
                Log.Warn("Received player routing update, cannot find self ID");
                return;
            }

            // Find which players are no longer in the session. Do this before copying the information into _playerIds,
            // this ensures the old player IDs can still be looked up inside the OnPlayerLeft method
            foreach (var player in _playerIds.Items)
            {
                if (!_tempNewRoutingTable.GetId(player).HasValue)
                {
                    _client.OnPlayerLeft(player);
                }
            }

            // Clone the old state so we know who has joined the session
            _tempOldRoutingTable.CopyFrom(_playerIds);

            //Copy info from temp into ID table
            _playerIds.CopyFrom(_tempNewRoutingTable);

            // Find which players newly joined the session. Do this after copying the information into _playerIds,
            // this ensures the new player IDs can be looked up inside the OnPlayerJoined methods
            foreach (var player in _tempNewRoutingTable.Items)
            {
                if (!_tempOldRoutingTable.GetId(player).HasValue)
                {
                    _client.OnPlayerJoined(player);
                }
            }

            //Clean up after ourselves
            _tempOldRoutingTable.Clear();
            _tempNewRoutingTable.Clear();
        }
Example #4
0
        /// <summary>
        /// Remove all players from the session
        /// </summary>
        public void Clear()
        {
            var players = _playerIds.Items.ToArray();

            foreach (var player in players)
            {
                _client.OnPlayerLeft(player);
            }
            _playerIds.Clear();
        }
Example #5
0
        public void AddSame()
        {
            _table.Clear();
            for (var i = 0; i < Bucket.MaxCapacity; i++)
            {
                var id = (byte[])_id.Clone();
                _table.Add(new Node(new NodeId(id), new IPEndPoint(IPAddress.Any, 0)));
            }

            Assert.AreEqual(1, _addedCount, "#a");
            Assert.AreEqual(1, _table.Buckets.Count, "#1");
            Assert.AreEqual(1, _table.Buckets[0].Nodes.Count, "#2");

            CheckBuckets();
        }
 private void LoadRoutingTable(GXXmlReader reader)
 {
     RoutingTable.Clear();
     if (reader.IsStartElement("RoutingTable", true))
     {
         while (reader.IsStartElement("Item", false))
         {
             GXDLMSRoutingTable it = new GXDLMSRoutingTable();
             RoutingTable.Add(it);
             it.DestinationAddress = (UInt16)reader.ReadElementContentAsInt("DestinationAddress");
             it.NextHopAddress     = (UInt16)reader.ReadElementContentAsInt("NextHopAddress");
             it.RouteCost          = (UInt16)reader.ReadElementContentAsInt("RouteCost");
             it.HopCount           = (byte)reader.ReadElementContentAsInt("HopCount");
             it.WeakLinkCount      = (byte)reader.ReadElementContentAsInt("WeakLinkCount");
             it.ValidTime          = (UInt16)reader.ReadElementContentAsInt("ValidTime");
         }
         reader.ReadEndElement("RoutingTable");
     }
 }
Example #7
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         if (e.Value is string)
         {
             LogicalName = e.Value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString).ToString();
         }
     }
     else if (e.Index == 2)
     {
         MaxHops = Convert.ToByte(e.Value);
     }
     else if (e.Index == 3)
     {
         WeakLqiValue = Convert.ToByte(e.Value);
     }
     else if (e.Index == 4)
     {
         SecurityLevel = Convert.ToByte(e.Value);
     }
     else if (e.Index == 5)
     {
         List <object> list = new List <object>();
         if (e.Value != null)
         {
             list.AddRange((object[])e.Value);
         }
         PrefixTable = list.ToArray();
     }
     else if (e.Index == 6)
     {
         RoutingConfiguration.Clear();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[] tmp = (object[])v;
                 GXDLMSRoutingConfiguration it = new GXDLMSRoutingConfiguration();
                 it.NetTraversalTime     = Convert.ToByte(tmp[0]);
                 it.RoutingTableEntryTtl = Convert.ToUInt16(tmp[1]);
                 it.Kr                     = Convert.ToByte(tmp[2]);
                 it.Km                     = Convert.ToByte(tmp[3]);
                 it.Kc                     = Convert.ToByte(tmp[4]);
                 it.Kq                     = Convert.ToByte(tmp[5]);
                 it.Kh                     = Convert.ToByte(tmp[6]);
                 it.Krt                    = Convert.ToByte(tmp[7]);
                 it.RreqRetries            = Convert.ToByte(tmp[8]);
                 it.RreqRerrWait           = Convert.ToByte(tmp[9]);
                 it.BlacklistTableEntryTtl = Convert.ToUInt16(tmp[10]);
                 it.UnicastRreqGenEnable   = Convert.ToBoolean(tmp[11]);
                 it.RlcEnabled             = Convert.ToBoolean(tmp[12]);
                 it.AddRevLinkCost         = Convert.ToByte(tmp[13]);
                 RoutingConfiguration.Add(it);
             }
         }
     }
     else if (e.Index == 7)
     {
         BroadcastLogTableEntryTtl = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 8)
     {
         RoutingTable.Clear();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[]           tmp = (object[])v;
                 GXDLMSRoutingTable it  = new GXDLMSRoutingTable();
                 it.DestinationAddress = Convert.ToUInt16(tmp[10]);
                 it.NextHopAddress     = Convert.ToUInt16(tmp[10]);
                 it.RouteCost          = Convert.ToUInt16(tmp[10]);
                 it.HopCount           = Convert.ToByte(tmp[10]);
                 it.WeakLinkCount      = Convert.ToByte(tmp[10]);
                 it.ValidTime          = Convert.ToUInt16(tmp[10]);
                 RoutingTable.Add(it);
             }
         }
     }
     else if (e.Index == 9)
     {
         ContextInformationTable.Clear();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[] tmp = (object[])v;
                 GXDLMSContextInformationTable it = new GXDLMSContextInformationTable();
                 it.CID           = (string)tmp[0];
                 it.Context       = (byte[])tmp[2];
                 it.Compression   = Convert.ToBoolean(tmp[3]);
                 it.ValidLifetime = Convert.ToUInt16(tmp[4]);
                 ContextInformationTable.Add(it);
             }
         }
     }
     else if (e.Index == 10)
     {
         List <GXKeyValuePair <UInt16, UInt16> > list = new List <GXKeyValuePair <UInt16, UInt16> >();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[] tmp = (object[])v;
                 list.Add(new GXKeyValuePair <UInt16, UInt16>(Convert.ToUInt16(tmp[0]), Convert.ToUInt16(tmp[1])));
             }
         }
         BlacklistTable = list;
     }
     else if (e.Index == 11)
     {
         BroadcastLogTable.Clear();
         if (e.Value != null)
         {
             foreach (object v in (object[])e.Value)
             {
                 object[] tmp = (object[])v;
                 GXDLMSBroadcastLogTable it = new GXDLMSBroadcastLogTable();
                 it.SourceAddress  = Convert.ToUInt16(tmp[0]);
                 it.SequenceNumber = Convert.ToByte(tmp[1]);
                 it.ValidTime      = Convert.ToUInt16(tmp[2]);
                 BroadcastLogTable.Add(it);
             }
         }
     }
     else if (e.Index == 12)
     {
         List <UInt16> list = new List <UInt16>();
         if (e.Value != null)
         {
             foreach (object it in (object[])e.Value)
             {
                 list.Add(Convert.ToUInt16(it));
             }
         }
         GroupTable = list.ToArray();
     }
     else if (e.Index == 13)
     {
         MaxJoinWaitTime = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 14)
     {
         PathDiscoveryTime = Convert.ToByte(e.Value);
     }
     else if (e.Index == 15)
     {
         ActiveKeyIndex = Convert.ToByte(e.Value);
     }
     else if (e.Index == 16)
     {
         MetricType = Convert.ToByte(e.Value);
     }
     else if (e.Index == 17)
     {
         CoordShortAddress = Convert.ToUInt16(e.Value);
     }
     else if (e.Index == 18)
     {
         DisableDefaultRouting = (bool)e.Value;
     }
     else if (e.Index == 19)
     {
         DeviceType = (DeviceType)Convert.ToInt32(e.Value);
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }