Commit caa898ce authored by Brickner_cp's avatar Brickner_cp

IPv6

Code Coverage 95.68%
parent 19c96296
...@@ -111,6 +111,7 @@ namespace PcapDotNet.Core.Test ...@@ -111,6 +111,7 @@ namespace PcapDotNet.Core.Test
protocol == IpV4Protocol.ActiveNetworks || protocol == IpV4Protocol.ActiveNetworks ||
protocol == IpV4Protocol.SpectraLinkRadioProtocol || protocol == IpV4Protocol.SpectraLinkRadioProtocol ||
protocol == IpV4Protocol.MobileAdHocNetwork || protocol == IpV4Protocol.MobileAdHocNetwork ||
protocol == IpV4Protocol.Shim6 || // TODO: Implement Shim6.
protocol == IpV4Protocol.RemoteVirtualDiskProtocol)) protocol == IpV4Protocol.RemoteVirtualDiskProtocol))
return false; return false;
......
...@@ -171,6 +171,16 @@ namespace PcapDotNet.Packets.Test ...@@ -171,6 +171,16 @@ namespace PcapDotNet.Packets.Test
} }
} }
break; break;
case IpV6MobilityOptionType.CgaParameters:
IpV6MobilityOptionCgaParameters optionCgaParameters = (IpV6MobilityOptionCgaParameters)option;
Assert.AreEqual(optionCgaParameters.Length - 2, optionCgaParameters.CgaParameters.Length);
break;
case IpV6MobilityOptionType.CareOfTest:
IpV6MobilityOptionCareOfTest optionCareOfTest = (IpV6MobilityOptionCareOfTest)option;
Assert.IsInstanceOfType(optionCareOfTest.CareOfKeygenToken, typeof(ulong));
break;
} }
} }
} }
...@@ -476,16 +486,16 @@ namespace PcapDotNet.Packets.Test ...@@ -476,16 +486,16 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = ExtensionHeaders =
new IpV6ExtensionHeaders( new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError( new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero, IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions( new IpV6MobilityOptions(
new IpV6MobilityOptionAccessNetworkIdentifier( new IpV6MobilityOptionAccessNetworkIdentifier(
new IpV6AccessNetworkIdentifierSubOptions( new IpV6AccessNetworkIdentifierSubOptions(
new IpV6AccessNetworkIdentifierSubOptionNetworkIdentifier(false, DataSegment.Empty, new DataSegment(new byte[1]))))))) new IpV6AccessNetworkIdentifierSubOptionNetworkIdentifier(false, DataSegment.Empty, new DataSegment(new byte[1])))))))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
--packet.Buffer[14 + 40 + 24 + 2 + 1]; --packet.Buffer[14 + 40 + 24 + 2 + 1];
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
...@@ -640,6 +650,13 @@ namespace PcapDotNet.Packets.Test ...@@ -640,6 +650,13 @@ namespace PcapDotNet.Packets.Test
new IpV6MobilityOptionContextRequestEntry(0, new DataSegment(new byte[100])))); new IpV6MobilityOptionContextRequestEntry(0, new DataSegment(new byte[100]))));
} }
[TestMethod]
public void IpV6MobilityOptionContextRequestEntryEquals()
{
Assert.AreNotEqual(new IpV6MobilityOptionContextRequestEntry(0, DataSegment.Empty), 1);
Assert.AreEqual(new IpV6MobilityOptionContextRequestEntry(0, DataSegment.Empty), new IpV6MobilityOptionContextRequestEntry(0, DataSegment.Empty));
}
[TestMethod] [TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), AllowDerivedTypes = false)] [ExpectedException(typeof(ArgumentOutOfRangeException), AllowDerivedTypes = false)]
public void IpV6MobilityOptionFlowIdentificationSubOptionsTooLong() public void IpV6MobilityOptionFlowIdentificationSubOptionsTooLong()
...@@ -836,11 +853,11 @@ namespace PcapDotNet.Packets.Test ...@@ -836,11 +853,11 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = ExtensionHeaders =
new IpV6ExtensionHeaders( new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderRoutingHomeAddress(IpV4Protocol.Skip, 0, IpV6Address.Zero)) new IpV6ExtensionHeaderRoutingHomeAddress(IpV4Protocol.Skip, 0, IpV6Address.Zero))
}); });
packet.Buffer[14 + 40 + 2] = 0x55; packet.Buffer[14 + 40 + 2] = 0x55;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid); Assert.IsFalse(invalidPacket.IsValid);
...@@ -891,13 +908,13 @@ namespace PcapDotNet.Packets.Test ...@@ -891,13 +908,13 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = ExtensionHeaders =
new IpV6ExtensionHeaders( new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError( new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero, IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions(new IpV6MobilityOptionLocalMobilityAnchorAddress(IpV4Address.Zero)))) new IpV6MobilityOptions(new IpV6MobilityOptionLocalMobilityAnchorAddress(IpV4Address.Zero))))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 24 + 1] -= 5; packet.Buffer[14 + 40 + 24 + 1] -= 5;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
...@@ -911,13 +928,13 @@ namespace PcapDotNet.Packets.Test ...@@ -911,13 +928,13 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = ExtensionHeaders =
new IpV6ExtensionHeaders( new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError( new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero, IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions(new IpV6MobilityOptionLocalMobilityAnchorAddress(IpV6Address.Zero)))) new IpV6MobilityOptions(new IpV6MobilityOptionLocalMobilityAnchorAddress(IpV6Address.Zero))))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
++packet.Buffer[14 + 40 + 24 + 1]; ++packet.Buffer[14 + 40 + 24 + 1];
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
...@@ -953,13 +970,13 @@ namespace PcapDotNet.Packets.Test ...@@ -953,13 +970,13 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = ExtensionHeaders =
new IpV6ExtensionHeaders( new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError( new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero, IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions(new IpV6MobilityOptionLocalMobilityAnchorAddress(IpV4Address.Zero)))) new IpV6MobilityOptions(new IpV6MobilityOptionLocalMobilityAnchorAddress(IpV4Address.Zero))))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 24 + 2] = 5; packet.Buffer[14 + 40 + 24 + 2] = 5;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
...@@ -1050,12 +1067,12 @@ namespace PcapDotNet.Packets.Test ...@@ -1050,12 +1067,12 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = ExtensionHeaders =
new IpV6ExtensionHeaders( new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderDestinationOptions( new IpV6ExtensionHeaderDestinationOptions(
IpV4Protocol.Skip, new IpV6Options(new IpV6OptionPadN(4)))) IpV4Protocol.Skip, new IpV6Options(new IpV6OptionPadN(4))))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 3] = 50; packet.Buffer[14 + 40 + 3] = 50;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
...@@ -1065,7 +1082,7 @@ namespace PcapDotNet.Packets.Test ...@@ -1065,7 +1082,7 @@ namespace PcapDotNet.Packets.Test
[TestMethod] [TestMethod]
public void IpV6OptionsEnumerableConstructor() public void IpV6OptionsEnumerableConstructor()
{ {
IpV6Options options = new IpV6Options(new IpV6Option[]{new IpV6OptionPad1()}.Concat(new IpV6OptionPad1())); IpV6Options options = new IpV6Options(new IpV6Option[] {new IpV6OptionPad1()}.Concat(new IpV6OptionPad1()));
Assert.AreEqual(2, options.Count); Assert.AreEqual(2, options.Count);
Assert.AreEqual(new IpV6OptionPad1(), options[0]); Assert.AreEqual(new IpV6OptionPad1(), options[0]);
Assert.AreEqual(new IpV6OptionPad1(), options[1]); Assert.AreEqual(new IpV6OptionPad1(), options[1]);
...@@ -1097,12 +1114,12 @@ namespace PcapDotNet.Packets.Test ...@@ -1097,12 +1114,12 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = ExtensionHeaders =
new IpV6ExtensionHeaders( new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderDestinationOptions( new IpV6ExtensionHeaderDestinationOptions(
IpV4Protocol.Skip, new IpV6Options(new IpV6OptionSmfDpdIpV4(IpV4Address.Zero, DataSegment.Empty)))) IpV4Protocol.Skip, new IpV6Options(new IpV6OptionSmfDpdIpV4(IpV4Address.Zero, DataSegment.Empty))))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 2 + 2] &= 0xF0; packet.Buffer[14 + 40 + 2 + 2] &= 0xF0;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
...@@ -1116,12 +1133,12 @@ namespace PcapDotNet.Packets.Test ...@@ -1116,12 +1133,12 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = ExtensionHeaders =
new IpV6ExtensionHeaders( new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderDestinationOptions( new IpV6ExtensionHeaderDestinationOptions(
IpV4Protocol.Skip, new IpV6Options(new IpV6OptionSmfDpdIpV6(IpV6Address.Zero, DataSegment.Empty)))) IpV4Protocol.Skip, new IpV6Options(new IpV6OptionSmfDpdIpV6(IpV6Address.Zero, DataSegment.Empty))))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 2 + 2] &= 0xF0; packet.Buffer[14 + 40 + 2 + 2] &= 0xF0;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
...@@ -1135,12 +1152,12 @@ namespace PcapDotNet.Packets.Test ...@@ -1135,12 +1152,12 @@ namespace PcapDotNet.Packets.Test
DateTime.Now, DateTime.Now,
new EthernetLayer(), new EthernetLayer(),
new IpV6Layer new IpV6Layer
{ {
ExtensionHeaders = ExtensionHeaders =
new IpV6ExtensionHeaders( new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderDestinationOptions( new IpV6ExtensionHeaderDestinationOptions(
IpV4Protocol.Skip, new IpV6Options(new IpV6OptionSmfDpdIpV4(IpV4Address.Zero, DataSegment.Empty)))) IpV4Protocol.Skip, new IpV6Options(new IpV6OptionSmfDpdIpV4(IpV4Address.Zero, DataSegment.Empty))))
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
packet.Buffer[14 + 40 + 2 + 2] |= 0x70; packet.Buffer[14 + 40 + 2 + 2] |= 0x70;
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet); Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
...@@ -1159,5 +1176,34 @@ namespace PcapDotNet.Packets.Test ...@@ -1159,5 +1176,34 @@ namespace PcapDotNet.Packets.Test
Assert.AreNotEqual(new IpV6OptionSmfDpdDefault(new DataSegment(new byte[16]), DataSegment.Empty), Assert.AreNotEqual(new IpV6OptionSmfDpdDefault(new DataSegment(new byte[16]), DataSegment.Empty),
new IpV6OptionSmfDpdIpV6(IpV6Address.Zero, DataSegment.Empty)); new IpV6OptionSmfDpdIpV6(IpV6Address.Zero, DataSegment.Empty));
} }
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), AllowDerivedTypes = false)]
public void IpV6MobilityOptionCgaParametersTooLong()
{
Assert.IsNull(new IpV6MobilityOptionCgaParameters(new DataSegment(new byte[256])));
Assert.Fail();
}
[TestMethod]
public void IpV6MobilityOptionCareOfTestCreateInstanceDataTooShort()
{
Packet packet = PacketBuilder.Build(
DateTime.Now,
new EthernetLayer(),
new IpV6Layer
{
ExtensionHeaders =
new IpV6ExtensionHeaders(
new IpV6ExtensionHeaderMobilityBindingError(
IpV4Protocol.Skip, 0, IpV6BindingErrorStatus.UnrecognizedMhTypeValue, IpV6Address.Zero,
new IpV6MobilityOptions(new IpV6MobilityOptionCareOfTest(0))))
});
Assert.IsTrue(packet.IsValid);
--packet.Buffer[14 + 40 + 24 + 1];
Packet invalidPacket = new Packet(packet.Buffer, DateTime.Now, DataLinkKind.Ethernet);
Assert.IsFalse(invalidPacket.IsValid);
}
} }
} }
using System;
namespace PcapDotNet.Packets.IpV6 namespace PcapDotNet.Packets.IpV6
{ {
/// <summary> /// <summary>
...@@ -21,6 +23,8 @@ namespace PcapDotNet.Packets.IpV6 ...@@ -21,6 +23,8 @@ namespace PcapDotNet.Packets.IpV6
public IpV6MobilityOptionCgaParameters(DataSegment cgaParameters) public IpV6MobilityOptionCgaParameters(DataSegment cgaParameters)
: base(IpV6MobilityOptionType.CgaParameters, cgaParameters) : base(IpV6MobilityOptionType.CgaParameters, cgaParameters)
{ {
if (cgaParameters.Length > OptionDataMaxLength)
throw new ArgumentOutOfRangeException("cgaParameters", cgaParameters, string.Format("Must not exceed {0} bytes.", OptionDataMaxLength));
} }
/// <summary> /// <summary>
......
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