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
return;
case 4: // Gre.
layers.Add(random.NextGreLayer());
GreLayer greLayer = random.NextGreLayer();
layers.Add(greLayer);
CreateRandomEthernetPayload(random, greLayer, layers);
return;
case 5: // Udp.
......
......@@ -14,8 +14,10 @@ namespace PcapDotNet.Core.Test
return null;
Datagram datagram = (Datagram)property.GetValue(datagramParent);
if (!Ignore(datagram))
CompareDatagram(layer, datagramParent as Datagram, datagram);
if (Ignore(datagram))
return null;
CompareDatagram(layer, datagramParent as Datagram, datagram);
return datagram;
}
......
......@@ -91,40 +91,31 @@ namespace PcapDotNet.Core.Test
break;
case "gre.routing.address_family":
if (SupportedGre(greDatagram))
{
if (_routingEntryIndex == greDatagram.Routing.Count)
field.AssertShowDecimal(0);
else
field.AssertShowDecimal((ushort)greDatagram.Routing[_routingEntryIndex].AddressFamily);
}
if (_routingEntryIndex == greDatagram.Routing.Count)
field.AssertShowDecimal(0);
else
field.AssertShowDecimal((ushort)greDatagram.Routing[_routingEntryIndex].AddressFamily);
field.AssertNoFields();
break;
case "gre.routing.sre_offset":
if (SupportedGre(greDatagram))
{
if (_routingEntryIndex == greDatagram.Routing.Count)
field.AssertShowDecimal(0);
else
field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadOffset);
}
if (_routingEntryIndex == greDatagram.Routing.Count)
field.AssertShowDecimal(0);
else
field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadOffset);
field.AssertNoFields();
break;
case "gre.routing.src_length":
if (SupportedGre(greDatagram))
{
if (_routingEntryIndex == greDatagram.Routing.Count)
field.AssertShowDecimal(0);
else
field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadLength);
}
if (_routingEntryIndex == greDatagram.Routing.Count)
field.AssertShowDecimal(0);
else
field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadLength);
field.AssertNoFields();
break;
case "gre.routing.information":
if (SupportedGre(greDatagram) && _routingEntryIndex != greDatagram.Routing.Count)
if (_routingEntryIndex != greDatagram.Routing.Count)
{
switch (greDatagram.Routing[_routingEntryIndex].AddressFamily)
{
......@@ -158,8 +149,7 @@ namespace PcapDotNet.Core.Test
case "data":
case "data.data":
if (SupportedGre(greDatagram))
field.AssertDataField(greDatagram.Payload);
field.AssertDataField(greDatagram.Payload);
break;
default:
......@@ -170,12 +160,13 @@ namespace PcapDotNet.Core.Test
return true;
}
private static bool SupportedGre(GreDatagram greDatagram)
protected override bool Ignore(Datagram datagram)
{
return greDatagram.IsValid &&
(greDatagram.ProtocolType == EthernetType.PointToPointProtocol ||
greDatagram.Version == GreVersion.EnhancedGre ||
!greDatagram.AcknowledgmentSequenceNumberPresent);
GreDatagram greDatagram = (GreDatagram)datagram;
return !greDatagram.IsValid ||
(greDatagram.ProtocolType != EthernetType.PointToPointProtocol ||
greDatagram.Version != GreVersion.EnhancedGre) &&
greDatagram.AcknowledgmentSequenceNumberPresent;
}
private int _routingEntryIndex = 0;
......
......@@ -11,7 +11,7 @@ namespace PcapDotNet.Packets.Gre
/// Represents a GRE layer.
/// <seealso cref="GreDatagram"/>
/// </summary>
public sealed class GreLayer : Layer, IIpV4NextLayer, IEquatable<GreLayer>
public sealed class GreLayer : EthernetBaseLayer, IIpV4NextLayer, IEquatable<GreLayer>
{
/// <summary>
/// The GRE Version Number.
......@@ -23,7 +23,11 @@ namespace PcapDotNet.Packets.Gre
/// 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.
/// </summary>
public EthernetType ProtocolType { get; set; }
public EthernetType ProtocolType
{
get { return EtherType; }
set { EtherType = value; }
}
/// <summary>
/// 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