Ejemplo n.º 1
0
 /// <summary>
 /// Hardwarenode sends the package to specified destination.
 /// </summary>
 /// <param name="Destination">The destination.</param>
 /// <param name="Tags">Optional tags.</param>
 /// <param name="ValInfo"></param>
 /// <returns>
 /// The Hardwarenode which received the package or null if an error occured
 /// </returns>
 public override List <Hardwarenode> Send(Hardwarenode Destination, Dictionary <string, object> Tags, ValidationInfo ValInfo)
 {
     ValInfo.NextNodes = new List <Hardwarenode>();
     ValInfo.Iface     = null;
     for (int i = Layerstack.GetSize() - 1; i >= 0; i--)
     {
         int customLayerCount = 0;
         //Calculate the custom layer count before this layer
         for (int j = 0; j < i; j++)
         {
             if (Layerstack.GetLayer(j) is CustomLayer)
             {
                 customLayerCount++;
             }
         }
         if (ValInfo.NextNodes == null)
         {
             continue;
         }
         Workstation dest = Destination as Workstation;
         if (dest != null)
         {
             Layerstack.GetLayer(i).ValidateSend(dest, this, ValInfo, Tags, i - customLayerCount);
         }
         else
         {
             throw new ArgumentException("Destination is no Workstation.");
         }
     }
     return(ValInfo.NextNodes);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends to destination.
        /// </summary>
        /// <param name="Destination">The destination.</param>
        /// <param name="ValInfo">The value information.</param>
        /// <param name="ComingCon">The coming connection.</param>
        /// <param name="nodeIP">The node ip of the sending node.</param>
        /// <param name="subnetmask">The subnetmask.</param>
        /// <returns>
        /// Bool if it could send
        /// </returns>
        public bool SendToDestination(Workstation Destination, ValidationInfo ValInfo, Connection ComingCon, IPAddress nodeIP, IPAddress subnetmask)
        {
            foreach (Connection c in Connections.Values)
            {
                if (c.End.Equals(Destination))
                {
                    KeyValuePair <string, Connection> kvDest = Destination.Connections.FirstOrDefault(S => S.Value.Equals(c));
                    Interface iDest = Destination.Interfaces.FirstOrDefault(I => I.Name.Equals(kvDest.Key));
                    if (iDest != null && nodeIP.IsInSameSubnet(iDest.IpAddress, subnetmask))
                    {
                        ValInfo.NextNodes.Add(c.End);
                        return(true);
                    }
                }
                if (!c.Start.Equals(Destination))
                {
                    continue;
                }
                ValInfo.NextNodes.Add(c.Start);
                return(true);
            }
            //check if the next switch can send it
            foreach (Connection c in Connections.Values)
            {
                if (c == ComingCon)
                {
                    continue;
                }
                if (c.Start.Equals(this))
                {
                    Switch s = c.End as Switch;
                    if (s == null)
                    {
                        continue;
                    }
                    if (!s.SendToDestination(Destination, ValInfo, c, nodeIP, subnetmask))
                    {
                        continue;
                    }
                    ValInfo.NextNodes.Insert(0, s);
                    return(true);
                }
                else
                {
                    Switch s = c.Start as Switch;
                    if (s == null)
                    {
                        continue;
                    }
                    if (!s.SendToDestination(Destination, ValInfo, c, nodeIP, subnetmask))
                    {
                        continue;
                    }
                    ValInfo.NextNodes.Insert(0, s);
                    return(true);
                }
            }

            return(false);
        }