Commit a86bb34d authored by Boaz Brickner's avatar Boaz Brickner

6 warnings left.

parent edd7c890
......@@ -103,7 +103,7 @@ namespace PcapDotNet.Packets.Test
MoreAssert.IsSmallerOrEqual(IgmpDatagram.MaxMaxResponseTime, packet.Ethernet.Ip.Igmp.MaxResponseTime);
if (packet.Ethernet.Ip.Igmp.MessageType != IgmpMessageType.MembershipQuery)
Assert.AreEqual(IgmpQueryVersion.None, packet.Ethernet.Ip.Igmp.QueryVersion);
switch (igmpLayer.MessageType)
switch (igmpLayer.MessageTypeValue)
{
case IgmpMessageType.CreateGroupRequestVersion0:
case IgmpMessageType.CreateGroupReplyVersion0:
......@@ -118,7 +118,7 @@ namespace PcapDotNet.Packets.Test
Assert.AreEqual(igmpVersion0Layer.IdentifierValue, packet.Ethernet.Ip.Igmp.Identifier);
Assert.AreEqual(igmpVersion0Layer.AccessKeyValue, packet.Ethernet.Ip.Igmp.AccessKey);
switch (igmpLayer.MessageType)
switch (igmpLayer.MessageTypeValue)
{
case IgmpMessageType.CreateGroupRequestVersion0:
Assert.AreEqual(((IgmpCreateGroupRequestVersion0Layer)igmpLayer).IsPrivate, packet.Ethernet.Ip.Igmp.IsPrivate);
......@@ -172,7 +172,7 @@ namespace PcapDotNet.Packets.Test
break;
default:
Assert.Fail(igmpLayer.MessageType.ToString());
Assert.Fail(igmpLayer.MessageTypeValue.ToString());
break;
}
foreach (IgmpGroupRecordDatagram groupRecord in packet.Ethernet.Ip.Igmp.GroupRecords)
......@@ -544,14 +544,14 @@ namespace PcapDotNet.Packets.Test
[ExpectedException(typeof(ArgumentOutOfRangeException), AllowDerivedTypes = false)]
public void IgmpReplyVersion0LayerSetInvalidType()
{
Assert.IsNotNull(new IgmpReplyVersion0Layer {Type = IgmpMessageType.LeaveGroupVersion2});
Assert.IsNotNull(new IgmpReplyVersion0Layer {MessageType = IgmpMessageType.LeaveGroupVersion2});
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), AllowDerivedTypes = false)]
public void IgmpRequestVersion0LayerSetInvalidType()
{
Assert.IsNotNull(new IgmpRequestVersion0Layer { Type = IgmpMessageType.LeaveGroupVersion2 });
Assert.IsNotNull(new IgmpRequestVersion0Layer { MessageType = IgmpMessageType.LeaveGroupVersion2 });
}
}
}
\ No newline at end of file
......@@ -47,7 +47,7 @@ namespace PcapDotNet.Packets.TestUtils
IgmpVersion0ReplyCode code = random.NextEnum<IgmpVersion0ReplyCode>();
return new IgmpReplyVersion0Layer
{
Type = igmpMessageType,
MessageType = igmpMessageType,
Code = code,
RetryInThisManySeconds = (byte)(code == IgmpVersion0ReplyCode.RequestPendingRetryInThisManySeconds? random.NextByte((byte)IgmpVersion0ReplyCode.RequestPendingRetryInThisManySeconds, byte.MaxValue) : 0),
Identifier = identifier,
......@@ -59,7 +59,7 @@ namespace PcapDotNet.Packets.TestUtils
case IgmpMessageType.LeaveGroupRequestVersion0:
return new IgmpRequestVersion0Layer
{
Type = igmpMessageType,
MessageType = igmpMessageType,
Identifier = identifier,
GroupAddress = igmpGroupAddress,
AccessKey = accessKey,
......
......@@ -10,31 +10,43 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public override IgmpMessageType MessageType
public override IgmpMessageType MessageTypeValue
{
get { return IgmpMessageType.ConfirmGroupRequestVersion0; }
}
/// <summary>
/// Zero.
/// </summary>
public override uint IdentifierValue
{
get { return 0; }
}
/// <summary>
/// Contains a host group address.
/// </summary>
public IpV4Address GroupAddress { get; set; }
/// <summary>
/// Contains the access key assigned to the host group identified in the Group Address field (zero for public groups).
/// </summary>
public ulong AccessKey { get; set; }
/// <summary>
/// Contains the access key assigned to the host group identified in the Group Address field (zero for public groups).
/// </summary>
public override ulong AccessKeyValue
{
get { return AccessKey; }
}
protected override byte CodeValue
internal override byte CodeValue
{
get { return 0; }
}
protected override IpV4Address GroupAddressValue
internal override IpV4Address GroupAddressValue
{
get { return GroupAddress; }
}
......
......@@ -11,31 +11,44 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public override IgmpMessageType MessageType
public override IgmpMessageType MessageTypeValue
{
get { return IgmpMessageType.CreateGroupRequestVersion0; }
}
/// <summary>
/// Indicates if the new host group is to be private or public.
/// </summary>
public bool IsPrivate { get; set; }
/// <summary>
/// Contains a value to distinguish the request from other requests by the same host.
/// </summary>
public uint Identifier { get; set; }
/// <summary>
/// Contains a value to distinguish the request from other requests by the same host.
/// </summary>
public override uint IdentifierValue
{
get { return Identifier; }
}
/// <summary>
/// Zero.
/// </summary>
public override ulong AccessKeyValue
{
get { return 0; }
}
protected override byte CodeValue
internal override byte CodeValue
{
get { return IsPrivate.ToByte(); }
}
protected override IpV4Address GroupAddressValue
internal override IpV4Address GroupAddressValue
{
get { return IpV4Address.Zero; }
}
......
......@@ -286,7 +286,7 @@ namespace PcapDotNet.Packets.Igmp
get
{
if (MessageType != IgmpMessageType.CreateGroupRequestVersion0)
throw new InvalidOperationException("IsPrivate can only be accessed for CreateGroupRequestVersion0.");
throw new InvalidOperationException(System.Reflection.MethodBase.GetCurrentMethod().Name + " can only be accessed for CreateGroupRequestVersion0.");
return ReadBool(Offset.Code, Mask.Code);
}
}
......@@ -303,7 +303,7 @@ namespace PcapDotNet.Packets.Igmp
MessageType != IgmpMessageType.LeaveGroupReplyVersion0 &&
MessageType != IgmpMessageType.ConfirmGroupReplyVersion0)
{
throw new InvalidOperationException("ReplyCode can only be accessed for Version 0 Replies.");
throw new InvalidOperationException(System.Reflection.MethodBase.GetCurrentMethod().Name + " can only be accessed for Version 0 Replies.");
}
return (IgmpVersion0ReplyCode)Math.Min(this[Offset.Code], (byte)IgmpVersion0ReplyCode.RequestPendingRetryInThisManySeconds);
......@@ -318,7 +318,7 @@ namespace PcapDotNet.Packets.Igmp
get
{
if (ReplyCode != IgmpVersion0ReplyCode.RequestPendingRetryInThisManySeconds)
throw new InvalidOperationException("RetryInThisManySeconds can only be accessed when ReplyCode is RequestPendingRetryInThisManySeconds");
throw new InvalidOperationException(System.Reflection.MethodBase.GetCurrentMethod().Name + " can only be accessed when reply code is request pending retry in this many seconds");
return this[Offset.Code];
}
}
......@@ -638,7 +638,7 @@ namespace PcapDotNet.Packets.Igmp
case IgmpMessageType.ConfirmGroupReplyVersion0:
return new IgmpReplyVersion0Layer
{
Type = MessageType,
MessageType = MessageType,
Code = ReplyCode,
RetryInThisManySeconds = (byte)(ReplyCode == IgmpVersion0ReplyCode.RequestPendingRetryInThisManySeconds ? RetryInThisManySeconds : 0),
Identifier = Identifier,
......@@ -650,7 +650,7 @@ namespace PcapDotNet.Packets.Igmp
case IgmpMessageType.LeaveGroupRequestVersion0:
return new IgmpRequestVersion0Layer
{
Type = MessageType,
MessageType = MessageType,
Identifier = Identifier,
GroupAddress = GroupAddress,
AccessKey = AccessKey,
......
......@@ -12,7 +12,7 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public abstract IgmpMessageType MessageType { get; }
public abstract IgmpMessageType MessageTypeValue { get; }
/// <summary>
/// The IGMP version of a Membership Query message.
......@@ -38,7 +38,7 @@ namespace PcapDotNet.Packets.Igmp
public bool Equals(IgmpLayer other)
{
return other != null &&
MessageType == other.MessageType &&
MessageTypeValue == other.MessageTypeValue &&
QueryVersion == other.QueryVersion &&
EqualsVersionSpecific(other);
}
......@@ -57,7 +57,7 @@ namespace PcapDotNet.Packets.Igmp
public override int GetHashCode()
{
return base.GetHashCode() ^
Sequence.GetHashCode(MessageType, QueryVersion);
Sequence.GetHashCode(MessageTypeValue, QueryVersion);
}
/// <summary>
......
......@@ -8,7 +8,7 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public override IgmpMessageType MessageType
public override IgmpMessageType MessageTypeValue
{
get { return IgmpMessageType.LeaveGroupVersion2; }
}
......
......@@ -10,7 +10,7 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public override IgmpMessageType MessageType
public override IgmpMessageType MessageTypeValue
{
get { return IgmpMessageType.MembershipQuery; }
}
......
......@@ -8,7 +8,7 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public override IgmpMessageType MessageType
public override IgmpMessageType MessageTypeValue
{
get { return IgmpMessageType.MembershipQuery; }
}
......
......@@ -85,7 +85,7 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public override IgmpMessageType MessageType
public override IgmpMessageType MessageTypeValue
{
get { return IgmpMessageType.MembershipQuery; }
}
......
using System;
using System.Globalization;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Igmp
......@@ -11,14 +12,18 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public override IgmpMessageType MessageType
public override IgmpMessageType MessageTypeValue
{
get { return Type; }
get { return MessageType; }
}
public IgmpMessageType Type
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// Either CreateGroupReplyVersion0, JoinGroupReplyVersion0, LeaveGroupReplyVersion0 or ConfirmGroupReplyVersion0.
/// </summary>
public IgmpMessageType MessageType
{
get { return _type; }
get { return _messageType; }
set
{
switch (value)
......@@ -27,46 +32,73 @@ namespace PcapDotNet.Packets.Igmp
case IgmpMessageType.JoinGroupReplyVersion0:
case IgmpMessageType.LeaveGroupReplyVersion0:
case IgmpMessageType.ConfirmGroupReplyVersion0:
_type = value;
_messageType = value;
break;
default:
throw new ArgumentOutOfRangeException("value", value, string.Format("Do not use {0} for {1}", GetType(), value));
throw new ArgumentOutOfRangeException("value", value, string.Format(CultureInfo.InvariantCulture, "Do not use {0} for {1}", GetType(), value));
}
}
}
/// <summary>
/// Specifies the outcome of the request.
/// </summary>
public IgmpVersion0ReplyCode Code { get; set; }
/// <summary>
/// When Code = RequestPendingRetryInThisManySeconds, specifies the amount of seconds to retry in.
/// </summary>
public byte RetryInThisManySeconds { get; set; }
/// <summary>
/// Contains the same value as in the corresponding Request message.
/// </summary>
public uint Identifier { get; set; }
/// <summary>
/// Contains the same value as in the corresponding Request message.
/// </summary>
public override uint IdentifierValue
{
get { return Identifier; }
}
/// <summary>
/// In a Create Group Reply message, the group address field contains either a newly allocated host group address (if the request is granted)
/// or zero (if denied).
/// In all other Reply messages, the group address field contains the same host group address as in the corresponding Request message.
/// </summary>
public IpV4Address GroupAddress { get; set; }
/// <summary>
/// In a Create Group Reply message, the access key field contains either a non-zero 64-bit number (if the request for a private group is granted)
/// or zero.
/// In all other Reply messages, the access key field contains the same access key as in the corresponding Request.
/// </summary>
public ulong AccessKey { get; set; }
/// <summary>
/// In a Create Group Reply message, the access key field contains either a non-zero 64-bit number (if the request for a private group is granted)
/// or zero.
/// In all other Reply messages, the access key field contains the same access key as in the corresponding Request.
/// </summary>
public override ulong AccessKeyValue
{
get { return AccessKey; }
}
protected override byte CodeValue
internal override byte CodeValue
{
get { return Code == IgmpVersion0ReplyCode.RequestPendingRetryInThisManySeconds ? RetryInThisManySeconds : (byte)Code; }
}
protected override IpV4Address GroupAddressValue
internal override IpV4Address GroupAddressValue
{
get { return GroupAddress; }
}
private IgmpMessageType _type = IgmpMessageType.CreateGroupReplyVersion0;
private IgmpMessageType _messageType = IgmpMessageType.CreateGroupReplyVersion0;
}
}
\ No newline at end of file
......@@ -8,7 +8,7 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public override IgmpMessageType MessageType
public override IgmpMessageType MessageTypeValue
{
get { return IgmpMessageType.MembershipReportVersion1; }
}
......
......@@ -8,7 +8,7 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public override IgmpMessageType MessageType
public override IgmpMessageType MessageTypeValue
{
get { return IgmpMessageType.MembershipReportVersion2; }
}
......
......@@ -47,7 +47,7 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public override IgmpMessageType MessageType
public override IgmpMessageType MessageTypeValue
{
get { return IgmpMessageType.MembershipReportVersion3; }
}
......
using System;
using System.Globalization;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.Igmp
......@@ -11,55 +12,81 @@ namespace PcapDotNet.Packets.Igmp
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// </summary>
public override IgmpMessageType MessageType
public override IgmpMessageType MessageTypeValue
{
get { return Type; }
get { return MessageType; }
}
public IgmpMessageType Type
/// <summary>
/// The type of the IGMP message of concern to the host-router interaction.
/// Either JoinGroupRequestVersion0 or LeaveGroupRequestVersion0.
/// </summary>
public IgmpMessageType MessageType
{
get { return _type; }
get { return _messageType; }
set
{
switch (value)
{
case IgmpMessageType.JoinGroupRequestVersion0:
case IgmpMessageType.LeaveGroupRequestVersion0:
_type = value;
_messageType = value;
break;
default:
throw new ArgumentOutOfRangeException("value", value, string.Format("Do not use {0} for {1}", GetType(), value));
throw new ArgumentOutOfRangeException("value", value, string.Format(CultureInfo.InvariantCulture, "Do not use {0} for {1}", GetType(), value));
}
}
}
/// <summary>
/// In a Confirm Group Request message, the identifier field should contain zero.
/// In all other Request messages, the identifier field contains a value to distinguish the request from other requests by the same host.
/// </summary>
public uint Identifier { get; set; }
/// <summary>
/// In a Confirm Group Request message, the identifier field contains zero.
/// In all other Request messages, the identifier field contains a value to distinguish the request from other requests by the same host.
/// </summary>
public override uint IdentifierValue
{
get { return Identifier; }
}
/// <summary>
/// In a Create Group Request message, the group address field contains zero.
/// In all other Request messages, the group address field contains a host group address.
/// </summary>
public IpV4Address GroupAddress { get; set; }
/// <summary>
/// In a Create Group Request message, the access key field contains zero.
/// In all other Request messages, the access key field contains the access key assigned to the host group identified in the Group Address field
/// (zero for public groups).
/// </summary>
public ulong AccessKey { get; set; }
/// <summary>
/// In a Create Group Request message, the access key field contains zero.
/// In all other Request messages, the access key field contains the access key assigned to the host group identified in the Group Address field
/// (zero for public groups).
/// </summary>
public override ulong AccessKeyValue
{
get { return AccessKey; }
}
protected override byte CodeValue
internal override byte CodeValue
{
get { return 0; }
}
protected override IpV4Address GroupAddressValue
internal override IpV4Address GroupAddressValue
{
get { return GroupAddress; }
}
private IgmpMessageType _type = IgmpMessageType.JoinGroupRequestVersion0;
private IgmpMessageType _messageType = IgmpMessageType.JoinGroupRequestVersion0;
}
}
\ No newline at end of file
......@@ -16,10 +16,26 @@ namespace PcapDotNet.Packets.Igmp
get { return IgmpDatagram.Version0HeaderLength; }
}
/// <summary>
/// In a Confirm Group Request message, the identifier field contains zero.
/// In all other Request messages, the identifier field contains a value to distinguish the request from other requests by the same host.
/// In a Reply message, the identifier field contains the same value as in the corresponding Request message.
/// </summary>
public abstract uint IdentifierValue { get; }
/// <summary>
/// In a Create Group Request message, the access key field contains zero.
/// In all other Request messages, the access key field contains the access key assigned to the host group identified in the Group Address field
/// (zero for public groups).
/// In a Create Group Reply message, the access key field contains either a non-zero 64-bit number (if the request for a private group is granted)
/// or zero.
/// In all other Reply messages, the access key field contains the same access key as in the corresponding Request.
/// </summary>
public abstract ulong AccessKeyValue { get; }
/// <summary>
/// Xor of the hash codes of the layer length, datalink, message type, query version, code, identifier, group address and access key.
/// </summary>
public override int GetHashCode()
{
return new[]
......@@ -32,19 +48,29 @@ namespace PcapDotNet.Packets.Igmp
}.Xor();
}
/// <summary>
/// true iff the fields that are not mutual to all IGMP layers are equal.
/// </summary>
protected override sealed bool EqualsVersionSpecific(IgmpLayer other)
{
return EqualsVersionSpecific(other as IgmpVersion0Layer);
}
protected abstract byte CodeValue { get; }
protected abstract IpV4Address GroupAddressValue { get; }
/// <summary>
/// Writes the layer to the buffer.
/// This method ignores the payload length, and the previous and next layers.
/// </summary>
/// <param name="buffer">The buffer to write the layer to.</param>
/// <param name="offset">The offset in the buffer to start writing the layer at.</param>
protected override void Write(byte[] buffer, int offset)
{
IgmpDatagram.WriteVersion0Header(buffer, offset, MessageType, CodeValue, IdentifierValue, GroupAddressValue, AccessKeyValue);
IgmpDatagram.WriteVersion0Header(buffer, offset, MessageTypeValue, CodeValue, IdentifierValue, GroupAddressValue, AccessKeyValue);
}
internal abstract byte CodeValue { get; }
internal abstract IpV4Address GroupAddressValue { get; }
private bool EqualsVersionSpecific(IgmpVersion0Layer other)
{
return other != null &&
......
......@@ -3,6 +3,9 @@ using PcapDotNet.Base;
namespace PcapDotNet.Packets.Igmp
{
/// <summary>
/// Base class for all IGMP layers of version 1 or higher.
/// </summary>
public abstract class IgmpVersion1PlusLayer : IgmpLayer
{
/// <summary>
......
......@@ -34,7 +34,7 @@ namespace PcapDotNet.Packets.Igmp
protected sealed override void Write(byte[] buffer, int offset)
{
IgmpDatagram.WriteVersion1PlusSimpleHeader(buffer, offset,
MessageType, MaxResponseTimeValue, GroupAddress);
MessageTypeValue, MaxResponseTimeValue, GroupAddress);
}
/// <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