Commit d0ed8367 authored by Brickner_cp's avatar Brickner_cp

PacketBuilder new design

parent cd86ed94
<?xml version="1.0" encoding="UTF-8"?>
<TestRunConfiguration name="Local Test Run" id="be17286c-6d1c-43dd-b068-e83867abf9c5" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2006">
<Description>This is a default test run configuration for a local test run.</Description>
<CodeCoverage keyFile="PcapDotNet.snk" />
<CodeCoverage enabled="true" keyFile="PcapDotNet.snk">
<Regular>
<CodeCoverageItem binaryFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Base.dll" pdbFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Base.pdb" instrumentInPlace="true" />
<CodeCoverageItem binaryFile="c:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.dll" pdbFile="c:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.pdb" instrumentInPlace="true" />
<CodeCoverageItem binaryFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.Extensions.dll" pdbFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.Extensions.pdb" instrumentInPlace="true" />
<CodeCoverageItem binaryFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Packets.dll" pdbFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Packets.pdb" instrumentInPlace="true" />
</Regular>
</CodeCoverage>
<TestTypeSpecific>
<WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207">
<Browser name="Internet Explorer 7.0">
......
......@@ -64,8 +64,17 @@ namespace PcapDotNet.Core.Test
{
string filename = Path.GetTempPath() + @"dump.pcap";
Packet expectedPacket = PacketBuilder.Ethernet(DateTime.Now, new MacAddress(1), new MacAddress(2), EthernetType.QInQ,
new Datagram(new byte[] {1, 2, 3}));
Packet expectedPacket = PacketBuilder2.Build(DateTime.Now,
new EthernetLayer
{
Source = new MacAddress(1),
Destination = new MacAddress(2),
EtherType = EthernetType.QInQ,
},
new PayloadLayer
{
Data = new Datagram(new byte[] {1, 2, 3})
});
PacketDumpFile.Dump(filename, new PcapDataLink(DataLinkKind.Ethernet), PacketDevice.DefaultSnapshotLength,
new[] {expectedPacket});
......
......@@ -85,11 +85,20 @@ namespace PcapDotNet.Packets.Test
[TestMethod]
public void ArpProtocolIpV4Address()
{
Packet packet = PacketBuilder.EthernetArp(DateTime.Now,
new MacAddress(),
EthernetType.QInQ, ArpOperation.Request,
new byte[8], new byte[] {1,2,3,4},
new byte[8], new byte[] {11,22,33,44});
Packet packet = PacketBuilder2.Build(DateTime.Now,
new EthernetLayer
{
Source = new MacAddress(),
EtherType = EthernetType.QInQ
},
new ArpLayer
{
Operation = ArpOperation.Request,
SenderHardwareAddress = new byte[8],
SenderProtocolAddress = new byte[]{1,2,3,4},
TargetHardwareAddress = new byte[8],
TargetProtocolAddress = new byte[]{11,22,33,44}
});
Assert.AreEqual(new IpV4Address("1.2.3.4"), packet.Ethernet.Arp.SenderProtocolIpV4Address);
Assert.AreEqual(new IpV4Address("11.22.33.44"), packet.Ethernet.Arp.TargetProtocolIpV4Address);
......@@ -99,8 +108,20 @@ namespace PcapDotNet.Packets.Test
[ExpectedException(typeof(ArgumentException))]
public void ArpIncosistentSenderAddressSizeTest()
{
Packet packet = PacketBuilder.EthernetArp(DateTime.Now, new MacAddress(), EthernetType.IpV4, ArpOperation.Request,
new byte[4], new byte[6], new byte[5], new byte[6]);
Packet packet = PacketBuilder2.Build(DateTime.Now,
new EthernetLayer
{
Source = new MacAddress(),
EtherType = EthernetType.IpV4
},
new ArpLayer
{
Operation = ArpOperation.Request,
SenderHardwareAddress = new byte[4],
SenderProtocolAddress = new byte[6],
TargetHardwareAddress = new byte[5],
TargetProtocolAddress = new byte[6]
});
Assert.IsNull(packet);
Assert.Fail();
}
......@@ -109,8 +130,20 @@ namespace PcapDotNet.Packets.Test
[ExpectedException(typeof(ArgumentException))]
public void ArpIncosistentTargetAddressSizeTest()
{
Packet packet = PacketBuilder.EthernetArp(DateTime.Now, new MacAddress(), EthernetType.IpV4, ArpOperation.Request,
new byte[4], new byte[6], new byte[4], new byte[7]);
Packet packet = PacketBuilder2.Build(DateTime.Now,
new EthernetLayer
{
Source = new MacAddress(),
EtherType = EthernetType.IpV4
},
new ArpLayer
{
Operation = ArpOperation.Request,
SenderHardwareAddress = new byte[4],
SenderProtocolAddress = new byte[6],
TargetHardwareAddress = new byte[4],
TargetProtocolAddress = new byte[7]
});
Assert.IsNull(packet);
Assert.Fail();
}
......
......@@ -160,11 +160,14 @@ namespace PcapDotNet.Packets.Test
[TestMethod]
public void TcpOptionMd5SignatureCreateInstanceErrorDataLengthTest()
{
Packet packet = PacketBuilder.EthernetIpV4Tcp(DateTime.Now,
new MacAddress(), new MacAddress(),
0, 0, new IpV4Fragmentation(), 0, new IpV4Address(), new IpV4Address(), new IpV4Options(),
0, 0, 0, 0, new TcpControlBits(), 0, 0,
new TcpOptions(new TcpOptionMd5Signature(new byte[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16})), Datagram.Empty);
Packet packet =
PacketBuilder2.Build(DateTime.Now, new EthernetLayer(), new IpV4Layer(),
new TcpLayer
{
Options =
new TcpOptions(
new TcpOptionMd5Signature(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}))
});
Assert.IsTrue(packet.IsValid);
Assert.IsTrue(packet.Ethernet.IpV4.Tcp.Options.IsValid);
......
......@@ -75,9 +75,14 @@ namespace PcapDotNet.Packets.TestUtils
if (packetSize < EthernetDatagram.HeaderLength)
throw new ArgumentOutOfRangeException("packetSize", packetSize, "Must be at least the ethernet header length (" + EthernetDatagram.HeaderLength + ")");
return PacketBuilder.Ethernet(timestamp,
ethernetSource, ethernetDestination, random.NextEthernetType(),
random.NextDatagram(packetSize - EthernetDatagram.HeaderLength));
return PacketBuilder2.Build(timestamp,
new EthernetLayer
{
Source = ethernetSource,
Destination = ethernetDestination,
EtherType = random.NextEthernetType()
},
random.NextPayloadLayer(packetSize - EthernetDatagram.HeaderLength));
}
public static Packet NextEthernetPacket(this Random random, int packetSize, DateTime timestamp, string ethernetSource, string ethernetDestination)
......
......@@ -592,6 +592,11 @@ namespace PcapDotNet.Packets
public class IgmpQueryVersion3Layer : IgmpLayer, IIgmpLayerWithGroupAddress
{
public IgmpQueryVersion3Layer()
{
SourceAddresses = new List<IpV4Address>();
}
public TimeSpan MaxResponseTime { get; set; }
public IpV4Address GroupAddress { get; set; }
public bool IsSuppressRouterSideProcessing { get; set; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment