Commit 97ea93e2 authored by Brickner_cp's avatar Brickner_cp

Test GRE with inner layers.

parent accb8c69
...@@ -244,7 +244,9 @@ namespace PcapDotNet.Core.Test ...@@ -244,7 +244,9 @@ namespace PcapDotNet.Core.Test
return; return;
case 4: // Gre. case 4: // Gre.
layers.Add(random.NextGreLayer()); GreLayer greLayer = random.NextGreLayer();
layers.Add(greLayer);
CreateRandomEthernetPayload(random, greLayer, layers);
return; return;
case 5: // Udp. case 5: // Udp.
......
...@@ -14,8 +14,10 @@ namespace PcapDotNet.Core.Test ...@@ -14,8 +14,10 @@ namespace PcapDotNet.Core.Test
return null; return null;
Datagram datagram = (Datagram)property.GetValue(datagramParent); Datagram datagram = (Datagram)property.GetValue(datagramParent);
if (!Ignore(datagram)) if (Ignore(datagram))
CompareDatagram(layer, datagramParent as Datagram, datagram); return null;
CompareDatagram(layer, datagramParent as Datagram, datagram);
return datagram; return datagram;
} }
......
...@@ -91,40 +91,31 @@ namespace PcapDotNet.Core.Test ...@@ -91,40 +91,31 @@ namespace PcapDotNet.Core.Test
break; break;
case "gre.routing.address_family": case "gre.routing.address_family":
if (SupportedGre(greDatagram)) if (_routingEntryIndex == greDatagram.Routing.Count)
{ field.AssertShowDecimal(0);
if (_routingEntryIndex == greDatagram.Routing.Count) else
field.AssertShowDecimal(0); field.AssertShowDecimal((ushort)greDatagram.Routing[_routingEntryIndex].AddressFamily);
else
field.AssertShowDecimal((ushort)greDatagram.Routing[_routingEntryIndex].AddressFamily);
}
field.AssertNoFields(); field.AssertNoFields();
break; break;
case "gre.routing.sre_offset": case "gre.routing.sre_offset":
if (SupportedGre(greDatagram)) if (_routingEntryIndex == greDatagram.Routing.Count)
{ field.AssertShowDecimal(0);
if (_routingEntryIndex == greDatagram.Routing.Count) else
field.AssertShowDecimal(0); field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadOffset);
else
field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadOffset);
}
field.AssertNoFields(); field.AssertNoFields();
break; break;
case "gre.routing.src_length": case "gre.routing.src_length":
if (SupportedGre(greDatagram)) if (_routingEntryIndex == greDatagram.Routing.Count)
{ field.AssertShowDecimal(0);
if (_routingEntryIndex == greDatagram.Routing.Count) else
field.AssertShowDecimal(0); field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadLength);
else
field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadLength);
}
field.AssertNoFields(); field.AssertNoFields();
break; break;
case "gre.routing.information": case "gre.routing.information":
if (SupportedGre(greDatagram) && _routingEntryIndex != greDatagram.Routing.Count) if (_routingEntryIndex != greDatagram.Routing.Count)
{ {
switch (greDatagram.Routing[_routingEntryIndex].AddressFamily) switch (greDatagram.Routing[_routingEntryIndex].AddressFamily)
{ {
...@@ -158,8 +149,7 @@ namespace PcapDotNet.Core.Test ...@@ -158,8 +149,7 @@ namespace PcapDotNet.Core.Test
case "data": case "data":
case "data.data": case "data.data":
if (SupportedGre(greDatagram)) field.AssertDataField(greDatagram.Payload);
field.AssertDataField(greDatagram.Payload);
break; break;
default: default:
...@@ -170,12 +160,13 @@ namespace PcapDotNet.Core.Test ...@@ -170,12 +160,13 @@ namespace PcapDotNet.Core.Test
return true; return true;
} }
private static bool SupportedGre(GreDatagram greDatagram) protected override bool Ignore(Datagram datagram)
{ {
return greDatagram.IsValid && GreDatagram greDatagram = (GreDatagram)datagram;
(greDatagram.ProtocolType == EthernetType.PointToPointProtocol || return !greDatagram.IsValid ||
greDatagram.Version == GreVersion.EnhancedGre || (greDatagram.ProtocolType != EthernetType.PointToPointProtocol ||
!greDatagram.AcknowledgmentSequenceNumberPresent); greDatagram.Version != GreVersion.EnhancedGre) &&
greDatagram.AcknowledgmentSequenceNumberPresent;
} }
private int _routingEntryIndex = 0; private int _routingEntryIndex = 0;
......
...@@ -11,7 +11,7 @@ namespace PcapDotNet.Packets.Gre ...@@ -11,7 +11,7 @@ namespace PcapDotNet.Packets.Gre
/// Represents a GRE layer. /// Represents a GRE layer.
/// <seealso cref="GreDatagram"/> /// <seealso cref="GreDatagram"/>
/// </summary> /// </summary>
public sealed class GreLayer : Layer, IIpV4NextLayer, IEquatable<GreLayer> public sealed class GreLayer : EthernetBaseLayer, IIpV4NextLayer, IEquatable<GreLayer>
{ {
/// <summary> /// <summary>
/// The GRE Version Number. /// The GRE Version Number.
...@@ -23,7 +23,11 @@ namespace PcapDotNet.Packets.Gre ...@@ -23,7 +23,11 @@ namespace PcapDotNet.Packets.Gre
/// These Protocol Types are defined in [RFC1700] as "ETHER TYPES" and in [ETYPES]. /// These Protocol Types are defined in [RFC1700] as "ETHER TYPES" and in [ETYPES].
/// An implementation receiving a packet containing a Protocol Type which is not listed in [RFC1700] or [ETYPES] SHOULD discard the packet. /// An implementation receiving a packet containing a Protocol Type which is not listed in [RFC1700] or [ETYPES] SHOULD discard the packet.
/// </summary> /// </summary>
public EthernetType ProtocolType { get; set; } public EthernetType ProtocolType
{
get { return EtherType; }
set { EtherType = value; }
}
/// <summary> /// <summary>
/// Recursion control contains a three bit unsigned integer which contains the number of additional encapsulations which are permissible. /// Recursion control contains a three bit unsigned integer which contains the number of additional encapsulations which are permissible.
......
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