Beispiel #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);
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Workstation" /> class.
 /// The IP address of the standardgateway must be set seperatly.
 /// </summary>
 /// <param name="Name">The Name.</param>
 public Workstation(string Name) : base(Name)
 {
     Layerstack.AddLayer(new PhysicalLayer(0));
     Layerstack.AddLayer(new DataLinkLayer(1));
     Layerstack.AddLayer(new NetworkLayer(2));
     Layerstack.AddLayer(new TransportLayer(3));
     Layerstack.AddLayer(new SessionLayer(4));
     Layerstack.AddLayer(new PresentationLayer(5));
     Layerstack.AddLayer(new ApplicationLayer(6));
     Interfaces.Add(new Interface(new IPAddress(new byte[] { 192, 168, 0, 1 }), new IPAddress(new byte[] { 255, 255, 255, 0 }), getNewInterfaceNumber()));
     StandardGateway     = null;
     StandardGatewayPort = null;
 }
Beispiel #3
0
        /// <summary>
        /// Hardwarenode receives the package.
        /// </summary>
        /// <param name="Tags">Optional tags.</param>
        /// <param name="ValInfo">The validation Info</param>
        /// <param name="Destination">The destination</param>
        /// <returns>
        /// bool that indicates if the Hardwarenode received the package
        /// </returns>
        public override bool Receive(Dictionary <string, object> Tags, ValidationInfo ValInfo, Hardwarenode Destination)
        {
            bool res = true;
            int  customLayerCount = 0;

            for (int i = 0; i < Layerstack.GetSize(); i++)
            {
                if (!res)
                {
                    continue;
                }
                res = Layerstack.GetLayer(i).ValidateReceive(this, ValInfo, Tags, Destination, i - customLayerCount);
                if (Layerstack.GetLayer(i) is CustomLayer)
                {
                    customLayerCount++;
                }
            }
            return(res);
        }