Example #1
0
        public void Hops_Valid_NonEmpty()
        {
            Hops hops = new Hops();

            Mock <Hop> hop = GetMockHop();

            hop.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            hops.Add(hop.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // need to suppress the type check because moq uses a different type
            Assert.IsTrue(hops.IsValidRecordSet(ref errorCode, suppressTypeCheck: true));
        }
Example #2
0
 /// <summary>
 /// Constructor for Packet
 /// </summary>
 /// <param name="Src">Source-Node</param>
 /// <param name="Dest">Destination-Node</param>
 /// <param name="T">TTL</param>
 /// <param name="ExpRes">Expected Result</param>
 public Packet(Hardwarenode Src, Hardwarenode Dest,
               int T, bool ExpRes)
 {
     Source      = Src;
     Destination = Dest;
     if (Source == null || Destination == null)
     {
         Result.ErrorId   = Result.Errors.SourceDestinationNull;
         Result.Res       = Result.ResultStrings[(int)Result.ErrorId];
         Result.SendError = true;
     }
     Ttl            = T;
     ExpectedResult = ExpRes;
     Hops.Add(Source);
 }
Example #3
0
        public void Hops_Invalid_BadType()
        {
            Hops hops = new Hops();

            Mock <Hop> hop = GetMockHop();

            hop.Setup(s => s.IsValid(ref It.Ref <ValidationCode> .IsAny)).Returns(true);

            hops.Add(hop.Object);

            ValidationCode errorCode = ValidationCode.SUCCESS;

            // do not suppress type check. Since moq uses a different type anyway,
            // there is no need to test with a different IRecord type
            Assert.IsFalse(hops.IsValidRecordSet(ref errorCode, suppressTypeCheck: false));
        }
Example #4
0
        /// <summary>
        /// Sends this packet to the destination.
        /// </summary>
        /// <returns>The Returnpacket if sending to destination was successfull or null</returns>
        public Packet Send()
        {
            ValidationInfo valInfo = new ValidationInfo
            {
                NextNodeIp = null,
                Res        = Result,
                Source     = Source as Workstation
            };

            while (!Hops[Hops.Count - 1].Equals(Destination) && valInfo.Res.ErrorId == 0 && Ttl > 0)
            {
                List <Hardwarenode> nextNodes = Hops[Hops.Count - 1].Send(Destination, tags, valInfo);
                if (nextNodes != null)
                {
                    if (nextNodes[nextNodes.Count - 1].Receive(tags, valInfo, Destination))
                    {
                        Ttl--;
                    }
                    foreach (Hardwarenode n in nextNodes)
                    {
                        Hops.Add(n);
                    }
                }
            }
            Result = valInfo.Res;
            if (!Hops[Hops.Count - 1].Equals(Destination) && Ttl == 0)
            {
                //TTL Error
                Result.ErrorId   = Result.Errors.TtlError;
                Result.Res       = Result.ResultStrings[(int)Result.ErrorId];
                Result.SendError = true;
            }
            if (Result.ErrorId == 0 && tags.Count != 0)
            {
                //Layer Error
                Result.ErrorId    = Result.Errors.CustomLayerError;
                Result.Res        = String.Format(Result.ResultStrings[(int)Result.ErrorId], tags.Keys.First());
                Result.LayerError = new CustomLayer(tags.Keys.First(), 0);
                Result.SendError  = false;
            }
            if (Result.ErrorId == 0)
            {
                return(new Packet(Destination, Source, Ttl, ExpectedResult));
            }
            return(null);
        }