Пример #1
0
        public void MulticastUdp6Test()
        {
            ushort dstport = TestBase.MakePort(53000, 54000);
            ushort srcport = TestBase.MakePort(54000, 55000);
            var    local   = GetFirstInterface(AddressFamily.InterNetworkV6).Item2;

            SocketEcho echo = new SocketEcho()
            {
                localIp = local
            };

            echo.SendOnly(IPAddress.Parse("ff02::22"), dstport);

            try
            {
                string xml = string.Format(template, "Udp", "ff02::22", srcport.ToString(), "Hello World", dstport.ToString());

                PitParser parser = new PitParser();
                Dom.Dom   dom    = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));
                Peach.Core.Publishers.UdpPublisher pub = dom.tests[0].publishers[0] as Peach.Core.Publishers.UdpPublisher;
                pub.Interface = local;

                RunConfiguration config = new RunConfiguration();
                config.singleIteration = true;

                Engine e = new Engine(null);
                e.startFuzzing(dom, config);

                Assert.AreEqual(3, actions.Count);

                var de1 = actions[0].dataModel.find("TheDataModel.str");
                Assert.NotNull(de1);
                var de2 = actions[1].dataModel.find("ResponseModel.str");
                Assert.NotNull(de2);

                string send = (string)de1.DefaultValue;
                string recv = (string)de2.DefaultValue;

                Assert.AreEqual("Hello World", send);
                Assert.AreEqual("SendOnly!", recv);
            }
            finally
            {
                echo.Socket.Close();
            }
        }
Пример #2
0
        public void MulticastUdpTest()
        {
            ushort dstport = TestBase.MakePort(53000, 54000);
            ushort srcport = TestBase.MakePort(54000, 55000);

            SocketEcho echo = new SocketEcho();

            echo.SendOnly(IPAddress.Parse("234.5.6.7"), dstport);

            try
            {
                string xml = string.Format(template, "Udp", "234.5.6.7", srcport.ToString(), "Hello World", dstport.ToString());

                PitParser parser = new PitParser();
                Dom.Dom   dom    = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));

                RunConfiguration config = new RunConfiguration();
                config.singleIteration = true;

                Engine e = new Engine(null);
                e.startFuzzing(dom, config);

                Assert.AreEqual(3, actions.Count);

                var de1 = actions[0].dataModel.find("TheDataModel.str");
                Assert.NotNull(de1);
                var de2 = actions[1].dataModel.find("ResponseModel.str");
                Assert.NotNull(de2);
                var addr = actions[2].dataModel.DefaultValue;
                Assert.NotNull(addr);

                IPAddress ip = new IPAddress(addr.BitsToArray());
                Assert.NotNull(ip);

                string send = (string)de1.DefaultValue;
                string recv = (string)de2.DefaultValue;

                Assert.AreEqual("Hello World", send);
                Assert.AreEqual("SendOnly!", recv);
            }
            finally
            {
                echo.Socket.Close();
            }
        }
Пример #3
0
        public void TestUdpNoPort()
        {
            ushort srcport = TestBase.MakePort(24000, 25000);

            string xml = @"
<Peach>

	<DataModel name=""TheDataModel"">
		<String name=""str""/>
	</DataModel>

	<StateModel name=""TheStateModel"" initialState=""InitialState"">
		<State name=""InitialState"">
			<Action name=""Recv1"" type=""input"">
				<DataModel ref=""TheDataModel""/>
			</Action>

			<Action name=""Send1"" type=""output"">
				<DataModel ref=""TheDataModel""/>
			</Action>

			<Action name=""Recv2"" type=""input"">
				<DataModel ref=""TheDataModel""/>
			</Action>

			<Action name=""Recv3"" type=""input"">
				<DataModel ref=""TheDataModel""/>
			</Action>

		</State>
	</StateModel>

	<Test name=""Default"">
		<StateModel ref=""TheStateModel""/>
		<Publisher class=""Udp"">
			<Param name=""Host"" value=""127.0.0.1""/>
			<Param name=""SrcPort"" value=""{0}""/>
		</Publisher>
	</Test>

</Peach>
".Fmt(srcport);

            this.cloneActions = true;

            SocketEcho echo1 = new SocketEcho()
            {
                WaitTime = 100
            };

            echo1.SendOnly(IPAddress.Loopback, srcport, "Echo1");

            SocketEcho echo2 = new SocketEcho()
            {
                WaitTime = 66
            };

            echo2.SendOnly(IPAddress.Loopback, srcport, "Echo2");

            try
            {
                PitParser parser = new PitParser();
                Dom.Dom   dom    = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));

                RunConfiguration config = new RunConfiguration();
                config.range      = true;
                config.rangeStart = 1;
                config.rangeStop  = 200;

                Engine e = new Engine(null);
                e.IterationFinished += new Engine.IterationFinishedEventHandler(e_IterationFinished);
                e.startFuzzing(dom, config);

                int num1 = 0;
                int num2 = 0;

                for (int i = 0; i < this.actions.Count; i += 4)
                {
                    var exp = (string)actions[i + 0].dataModel[0].DefaultValue;
                    if (exp != "Echo1")
                    {
                        Assert.AreEqual("Echo2", exp);
                        ++num2;
                    }
                    else
                    {
                        ++num1;
                    }

                    Assert.AreEqual(exp, (string)actions[i + 2].dataModel[0].DefaultValue);
                    Assert.AreEqual(exp, (string)actions[i + 3].dataModel[0].DefaultValue);
                }

                Assert.Greater(num1, 0);
                Assert.Greater(num2, 0);
            }
            finally
            {
                echo1.Socket.Close();
                echo2.Socket.Close();
            }
        }