本文整理汇总了C#中System.Xml.Linq.XElement.AssertShowDecimal方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.AssertShowDecimal方法的具体用法?C# XElement.AssertShowDecimal怎么用?C# XElement.AssertShowDecimal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.AssertShowDecimal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompareField
protected override bool CompareField(XElement field, Datagram parentDatagram, Datagram datagram)
{
IpDatagram ipDatagram = (IpDatagram)parentDatagram;
UdpDatagram udpDatagram = (UdpDatagram)datagram;
switch (field.Name())
{
case "udp.srcport":
field.AssertShowDecimal(udpDatagram.SourcePort);
break;
case "udp.dstport":
field.AssertShowDecimal(udpDatagram.DestinationPort);
break;
case "udp.port":
Assert.IsTrue(ushort.Parse(field.Show()) == udpDatagram.SourcePort ||
ushort.Parse(field.Show()) == udpDatagram.DestinationPort);
break;
case "udp.length":
field.AssertShowDecimal(udpDatagram.TotalLength);
break;
case "udp.checksum":
field.AssertShowDecimal(udpDatagram.Checksum);
if (udpDatagram.Checksum != 0)
{
foreach (var checksumField in field.Fields())
{
switch (checksumField.Name())
{
case "udp.checksum_good":
checksumField.AssertShowDecimal(ipDatagram.IsTransportChecksumCorrect);
break;
case "udp.checksum_bad":
if (checksumField.Show() == "1")
Assert.IsFalse(ipDatagram.IsTransportChecksumCorrect);
else
checksumField.AssertShowDecimal(0);
break;
}
}
}
break;
case "udp.checksum_coverage":
field.AssertShowDecimal(udpDatagram.TotalLength);
break;
case "udp.stream":
break;
default:
throw new InvalidOperationException("Invalid udp field " + field.Name());
}
return true;
}
示例2: CompareField
protected override bool CompareField(XElement field, Datagram datagram)
{
IpV6Datagram ipV6Datagram = datagram as IpV6Datagram;
if (ipV6Datagram == null)
return true;
while (_count > 0)
{
do
{
++_currentExtensionHeaderIndex;
if (_currentExtensionHeaderIndex >= ipV6Datagram.ExtensionHeaders.Headers.Count)
{
Assert.IsFalse(ipV6Datagram.ExtensionHeaders.IsValid);
return false;
}
} while (ipV6Datagram.ExtensionHeaders[_currentExtensionHeaderIndex].Protocol != IpV4Protocol.AuthenticationHeader);
--_count;
}
IpV6ExtensionHeaderAuthentication authenticationHeader = (IpV6ExtensionHeaderAuthentication)ipV6Datagram.ExtensionHeaders[_currentExtensionHeaderIndex];
switch (field.Name())
{
case "":
string[] headerFieldShowParts = field.Show().Split(':');
string headerFieldShowName = headerFieldShowParts[0];
string headerFieldShowValue = headerFieldShowParts[1];
switch (headerFieldShowName)
{
case "Next Header":
field.AssertValue((byte)authenticationHeader.NextHeader.Value);
break;
case "Length":
Assert.AreEqual(string.Format(" {0}", authenticationHeader.Length), headerFieldShowValue);
break;
default:
throw new InvalidOperationException("Invalid ipv6 authentication header unnamed field show name " + headerFieldShowName);
}
break;
case "ah.spi":
field.AssertShowDecimal(authenticationHeader.SecurityParametersIndex);
break;
case "ah.sequence":
field.AssertShowDecimal(authenticationHeader.SequenceNumber);
break;
case "ah.icv":
field.AssertValue(authenticationHeader.AuthenticationData);
break;
default:
throw new InvalidOperationException(string.Format("Invalid ipv6 authentication header field {0}", field.Name()));
}
return true;
}
示例3: CompareField
protected override bool CompareField(XElement field, Datagram datagram)
{
EthernetDatagram ethernetDatagram = (EthernetDatagram)datagram;
switch (field.Name())
{
case "eth.dst":
CompareEthernetAddress(field, ethernetDatagram.Destination);
break;
case "eth.src":
CompareEthernetAddress(field, ethernetDatagram.Source);
break;
case "eth.type":
field.AssertNoFields();
field.AssertShowDecimal((ushort)ethernetDatagram.EtherType);
break;
case "eth.trailer":
// TODO: Support RARP.
if (ethernetDatagram.EtherType != EthernetType.ReverseArp)
field.AssertValue(ethernetDatagram.Trailer);
break;
case "eth.fcs":
// TODO: Support RARP.
if (ethernetDatagram.EtherType != EthernetType.ReverseArp)
field.AssertValue(ethernetDatagram.FrameCheckSequence);
break;
case "eth.padding":
field.AssertNoFields();
field.AssertValue(ethernetDatagram.Padding);
break;
default:
throw new InvalidOperationException("Invalid etherent field " + field.Name());
}
return true;
}
示例4: CompareField
protected override bool CompareField(XElement field, Datagram datagram)
{
GreDatagram greDatagram = (GreDatagram)datagram;
switch (field.Name())
{
case "gre.flags_and_version":
XElement[] innerFields = field.Fields().ToArray();
MoreAssert.IsInRange(8, 9, innerFields.Length);
int currentInnerFieldIndex = 0;
innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.ChecksumPresent);
innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.RoutingPresent);
innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.KeyPresent);
innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.SequenceNumberPresent);
innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.StrictSourceRoute);
innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.RecursionControl);
if (innerFields.Length == 9)
{
innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.AcknowledgmentSequenceNumberPresent);
innerFields[currentInnerFieldIndex++].AssertShowDecimal(greDatagram.FutureUseBits);
}
else
{
byte futureUseBitsValue = (byte)((greDatagram.AcknowledgmentSequenceNumberPresent.ToInt() << 4) | greDatagram.FutureUseBits);
innerFields[currentInnerFieldIndex++].AssertShowDecimal(futureUseBitsValue);
}
innerFields[currentInnerFieldIndex].AssertShowDecimal((byte)greDatagram.Version);
break;
case "data.len":
field.AssertShowDecimal(
greDatagram.Payload.Length + (greDatagram.AcknowledgmentSequenceNumberPresent &&
(greDatagram.Version != GreVersion.EnhancedGre || !greDatagram.SequenceNumberPresent)
? 4
: 0), "GRE data.len");
field.AssertNoFields();
break;
case "gre.checksum":
field.AssertShowDecimal(greDatagram.Checksum);
field.AssertNoFields();
break;
case "gre.key.payload_length":
field.AssertShowDecimal(greDatagram.KeyPayloadLength);
field.AssertNoFields();
break;
case "gre.key.call_id":
field.AssertShowDecimal(greDatagram.KeyCallId);
field.AssertNoFields();
break;
case "gre.ack_number":
field.AssertShowDecimal(greDatagram.AcknowledgmentSequenceNumber);
field.AssertNoFields();
break;
case "gre.sequence_number":
field.AssertShowDecimal(greDatagram.SequenceNumber);
field.AssertNoFields();
break;
case "gre.offset":
field.AssertShowDecimal(greDatagram.RoutingOffset);
field.AssertNoFields();
break;
case "gre.routing":
field.AssertShow("");
field.AssertNoFields();
break;
case "gre.routing.address_family":
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 (_routingEntryIndex == greDatagram.Routing.Count)
field.AssertShowDecimal(0);
else
field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadOffset);
field.AssertNoFields();
break;
case "gre.routing.src_length":
if (_routingEntryIndex == greDatagram.Routing.Count)
field.AssertShowDecimal(0);
else
field.AssertShowDecimal(greDatagram.Routing[_routingEntryIndex].PayloadLength);
field.AssertNoFields();
break;
case "gre.routing.information":
if (_routingEntryIndex != greDatagram.Routing.Count)
{
//.........这里部分代码省略.........
示例5: HandleCommonOptionSubfield
private static bool HandleCommonOptionSubfield(XElement subfield, IpV4Option option)
{
switch (subfield.Name())
{
case "ip.opt.type":
subfield.AssertShowDecimal((byte)option.OptionType);
return true;
case "ip.opt.len":
subfield.AssertShowDecimal(option.Length);
subfield.AssertNoFields();
return true;
default:
return false;
}
}
示例6: CompareField
protected override bool CompareField(XElement field, Datagram datagram)
{
IpV6Datagram ipV6Datagram = (IpV6Datagram)datagram;
SkipAuthenticationHeaders(ipV6Datagram);
int optionsIndex = 0;
switch (field.Name())
{
case "ipv6.version":
// TODO: Remove this when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10706 is fixed.
if (field.Show() != ipV6Datagram.Version.ToString())
return false;
field.AssertShowDecimal(ipV6Datagram.Version);
foreach (XElement subfield in field.Fields())
{
switch (subfield.Name())
{
case "ip.version":
subfield.AssertShowDecimal(ipV6Datagram.Version);
break;
default:
throw new InvalidOperationException(string.Format("Invalid ipv6 version subfield {0}", subfield.Name()));
}
}
break;
case "ipv6.class":
field.AssertShowDecimal(ipV6Datagram.TrafficClass);
break;
case "ipv6.flow":
field.AssertShowDecimal(ipV6Datagram.FlowLabel);
field.AssertNoFields();
break;
case "ipv6.plen":
field.AssertShowDecimal(ipV6Datagram.PayloadLength);
field.AssertNoFields();
break;
case "ipv6.nxt":
field.AssertShowDecimal((byte)ipV6Datagram.NextHeader);
field.AssertNoFields();
break;
case "ipv6.hlim":
field.AssertShowDecimal(ipV6Datagram.HopLimit);
field.AssertNoFields();
break;
case "ipv6.src":
case "ipv6.src_host":
field.AssertShow(ipV6Datagram.Source.GetWiresharkString());
field.AssertNoFields();
break;
case "ipv6.src_6to4_gw_ipv4":
case "ipv6.src_6to4_sla_id":
case "ipv6.6to4_gw_ipv4":
case "ipv6.6to4_sla_id":
field.AssertNoFields();
break;
case "ipv6.dst":
case "ipv6.dst_host":
field.AssertShow(ipV6Datagram.CurrentDestination.GetWiresharkString());
field.AssertNoFields();
break;
case "ipv6.addr":
case "ipv6.host":
Assert.IsTrue(field.Show() == ipV6Datagram.Source.GetWiresharkString() ||
field.Show() == ipV6Datagram.CurrentDestination.GetWiresharkString());
field.AssertNoFields();
break;
case "ipv6.hop_opt":
if (_currentExtensionHeaderIndex >= ipV6Datagram.ExtensionHeaders.Headers.Count)
{
Assert.IsFalse(ipV6Datagram.ExtensionHeaders.IsValid);
int maxLength = ipV6Datagram.Length - IpV6Datagram.HeaderLength - ipV6Datagram.ExtensionHeaders.BytesLength;
if (field.Fields().Any(subfield => subfield.Name() == "ipv6.opt.length"))
{
int length = int.Parse(field.Fields().First(subfield => subfield.Name() == "ipv6.opt.length").Show());
MoreAssert.IsBigger(maxLength, length);
}
else
{
Assert.AreEqual(6, maxLength);
}
}
else
{
IpV6ExtensionHeaderHopByHopOptions hopByHopOptions =
(IpV6ExtensionHeaderHopByHopOptions)ipV6Datagram.ExtensionHeaders[_currentExtensionHeaderIndex];
IncrementCurrentExtensionHeaderIndex(ipV6Datagram);
CompareOptions(field, ref optionsIndex, ipV6Datagram, hopByHopOptions);
}
break;
//.........这里部分代码省略.........
示例7: CompareField
//.........这里部分代码省略.........
protocol == IpV4Protocol.InternetworkPacketExchangeInIp ||
protocol == IpV4Protocol.IntermediateSystemToIntermediateSystemOverIpV4 ||
protocol == IpV4Protocol.ComputerProtocolNetworkExecutive ||
protocol == IpV4Protocol.EncapsulationHeader ||
protocol == IpV4Protocol.GatewayToGateway ||
protocol == IpV4Protocol.SatMon ||
protocol == IpV4Protocol.VersatileMessageTransactionProtocol ||
protocol == IpV4Protocol.ReliableDatagramProtocol ||
protocol == IpV4Protocol.InternetReliableTransactionProtocol ||
protocol == IpV4Protocol.MeritInternodalProtocol ||
protocol == IpV4Protocol.Skip ||
protocol == IpV4Protocol.BurroughsNetworkArchitecture ||
protocol == IpV4Protocol.InterDomainRoutingProtocol ||
protocol == IpV4Protocol.ActiveNetworks ||
protocol == IpV4Protocol.SpectraLinkRadioProtocol ||
protocol == IpV4Protocol.MobileAdHocNetwork ||
protocol == IpV4Protocol.DissimilarGatewayProtocol ||
protocol == IpV4Protocol.SpriteRpc ||
protocol == IpV4Protocol.CombatRadioUserDatagram ||
protocol == IpV4Protocol.Gmtp ||
protocol == IpV4Protocol.MobileHostRoutingProtocol ||
protocol == IpV4Protocol.Shim6 || // TODO: Implement Shim6.
protocol == IpV4Protocol.RemoteVirtualDiskProtocol))
return false;
int currentExtensionHeaderIndex = ipV6Datagram.ExtensionHeaders.TakeWhile(extensionHeader => extensionHeader.Protocol != IpV4Protocol.MobilityHeader).Count();
if (currentExtensionHeaderIndex >= ipV6Datagram.ExtensionHeaders.Headers.Count && !ipV6Datagram.IsValid)
return false;
IpV6ExtensionHeaderMobility mobilityHeader = (IpV6ExtensionHeaderMobility)ipV6Datagram.ExtensionHeaders[currentExtensionHeaderIndex];
switch (field.Name())
{
case "mip6.proto":
field.AssertShowDecimal((byte)mobilityHeader.NextHeader);
field.AssertNoFields();
break;
case "mip6.hlen":
if (mobilityHeader.IsValid)
field.AssertShowDecimal(mobilityHeader.Length / 8 - 1);
field.AssertNoFields();
break;
case "mip6.mhtype":
field.AssertShowDecimal((byte)mobilityHeader.MobilityHeaderType);
break;
case "mip6.reserved":
field.AssertShowDecimal(0);
field.AssertNoFields();
break;
case "mip6.csum":
field.AssertShowDecimal(mobilityHeader.Checksum);
break;
case "mip6.em.data":
IpV6ExtensionHeaderMobilityExperimental experimentalHeader = (IpV6ExtensionHeaderMobilityExperimental)mobilityHeader;
field.AssertValue(experimentalHeader.MessageData);
break;
case "":
switch (field.Show())
{
case "Binding Refresh Request":
Assert.AreEqual(IpV6MobilityHeaderType.BindingRefreshRequest, mobilityHeader.MobilityHeaderType);
示例8: HandleCommonMobilityOptionSubfield
private bool HandleCommonMobilityOptionSubfield(XElement optionSubfield, IpV6MobilityOption option)
{
switch (optionSubfield.Name())
{
case "mip6.mobility_opt":
optionSubfield.AssertNoFields();
optionSubfield.AssertShowDecimal((byte)option.OptionType);
return true;
case "mip6.mobility_opt.len":
optionSubfield.AssertNoFields();
optionSubfield.AssertShowDecimal(option.Length - 2);
return true;
default:
return false;
}
}
示例9: CompareField
protected override bool CompareField(XElement field, Datagram datagram)
{
DnsDatagram dnsDatagram = (DnsDatagram)datagram;
switch (field.Name())
{
case "dns.id":
field.AssertShowDecimal(dnsDatagram.Id);
break;
case "dns.flags":
field.AssertShowDecimal(dnsDatagram.Subsegment(2, 2).ToArray().ReadUShort(0, Endianity.Big));
foreach (var flagField in field.Fields())
{
switch (flagField.Name())
{
case "dns.flags.response":
flagField.AssertShowDecimal(dnsDatagram.IsResponse);
break;
case "dns.flags.opcode":
flagField.AssertShowDecimal((byte)dnsDatagram.OpCode);
break;
case "dns.flags.conflict": // TODO: Support LLMNR.
case "dns.flags.authoritative":
flagField.AssertShowDecimal(dnsDatagram.IsAuthoritativeAnswer);
break;
case "dns.flags.truncated":
flagField.AssertShowDecimal(dnsDatagram.IsTruncated);
break;
case "dns.flags.tentative": // TODO: Support LLMNR.
case "dns.flags.recdesired":
flagField.AssertShowDecimal(dnsDatagram.IsRecursionDesired);
break;
case "dns.flags.recavail":
flagField.AssertShowDecimal(dnsDatagram.IsRecursionAvailable);
break;
case "dns.flags.z":
flagField.AssertShowDecimal(dnsDatagram.FutureUse);
break;
case "dns.flags.authenticated":
flagField.AssertShowDecimal(dnsDatagram.IsAuthenticData);
break;
case "dns.flags.checkdisable":
flagField.AssertShowDecimal(dnsDatagram.IsCheckingDisabled);
break;
case "dns.flags.rcode":
flagField.AssertShowDecimal((ushort)dnsDatagram.ResponseCode);
break;
default:
throw new InvalidOperationException("Invalid DNS flag field " + flagField.Name());
}
}
break;
case "dns.count.queries":
case "dns.count.zones":
field.AssertShowDecimal(dnsDatagram.QueryCount);
break;
case "dns.count.answers":
case "dns.count.prerequisites":
field.AssertShowDecimal(dnsDatagram.AnswerCount);
break;
case "dns.count.auth_rr":
case "dns.count.updates":
field.AssertShowDecimal(dnsDatagram.AuthorityCount);
break;
case "dns.count.add_rr":
field.AssertShowDecimal(dnsDatagram.AdditionalCount);
break;
case "":
var resourceRecordsFields = field.Fields();
switch (field.Show())
{
case "Queries":
case "Zone":
CompareResourceRecords(resourceRecordsFields, dnsDatagram.Queries);
break;
case "Answers":
case "Prerequisites":
CompareResourceRecords(resourceRecordsFields, dnsDatagram.Answers);
break;
case "Authoritative nameservers":
case "Updates":
CompareResourceRecords(resourceRecordsFields, dnsDatagram.Authorities);
//.........这里部分代码省略.........
示例10: CompareField
protected override bool CompareField(XElement field, Datagram datagram)
{
IgmpDatagram igmpDatagram = (IgmpDatagram)datagram;
switch (field.Name())
{
case "igmp.version":
field.AssertShowDecimal(Math.Max(igmpDatagram.Version, 0));
break;
case "igmp.type":
field.AssertShowDecimal((byte)igmpDatagram.MessageType);
break;
case "igmp.checksum":
field.AssertShowDecimal(igmpDatagram.Checksum);
break;
case "igmp.maddr":
field.AssertShow(igmpDatagram.GroupAddress.ToString());
break;
case "igmp.max_resp":
field.AssertShowDecimal((int)((igmpDatagram.MaxResponseTime.TotalSeconds + 0.05) * 10));
break;
case "igmp.checksum_bad":
if (igmpDatagram.IsValid)
field.AssertShowDecimal(!igmpDatagram.IsChecksumCorrect);
break;
case "igmp.num_grp_recs":
field.AssertShowDecimal(igmpDatagram.NumberOfGroupRecords);
break;
case "":
switch (igmpDatagram.MessageType)
{
case IgmpMessageType.MembershipReportVersion3:
CompareIgmpGroupRecord(field, igmpDatagram.GroupRecords[_groupRecordIndex++]);
break;
case IgmpMessageType.MembershipQuery:
return CompareDatagram(field, null, igmpDatagram);
case IgmpMessageType.MulticastTraceRouteResponse:
case IgmpMessageType.MulticastTraceRoute:
// todo support IGMP traceroute http://www.ietf.org/proceedings/48/I-D/idmr-traceroute-ipm-07.txt.
break;
default:
switch (field.Show())
{
case "Data":
if (field.Value().Length > 0)
{
// TODO: Change following https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=11582
field.AssertValue(field.Value().Length / 2 == igmpDatagram.Length - 21 ? igmpDatagram.Skip(21) : igmpDatagram.Skip(1));
}
break;
default:
if (typeof(IgmpMessageType).GetEnumValues<IgmpMessageType>().Contains(igmpDatagram.MessageType))
throw new InvalidOperationException("Invalid message type " + igmpDatagram.MessageType);
break;
}
break;
}
break;
case "igmp.s":
field.AssertShowDecimal(igmpDatagram.IsSuppressRouterSideProcessing);
break;
case "igmp.qrv":
field.AssertShowDecimal(igmpDatagram.QueryRobustnessVariable);
break;
case "igmp.qqic":
field.AssertShowDecimal(igmpDatagram.QueryIntervalCode);
break;
case "igmp.num_src":
field.AssertShowDecimal(igmpDatagram.NumberOfSources);
break;
case "igmp.saddr":
field.AssertShow(igmpDatagram.SourceAddresses[_sourceAddressIndex++].ToString());
break;
case "igmp.identifier":
field.AssertShowDecimal(igmpDatagram.Identifier);
break;
case "igmp.access_key":
field.AssertValue(igmpDatagram.AccessKey);
break;
case "igmp.reply":
field.AssertShowDecimal((byte)igmpDatagram.ReplyCode);
//.........这里部分代码省略.........
示例11: HandleOptionCommonFields
private static bool HandleOptionCommonFields(XElement subfield, TcpOption option)
{
switch (subfield.Name())
{
case "tcp.option_kind":
subfield.AssertNoFields();
subfield.AssertShowDecimal((byte)option.OptionType);
return true;
case "tcp.options.type":
subfield.AssertShowDecimal((byte)option.OptionType);
return true;
case "tcp.option_len":
subfield.AssertNoFields();
subfield.AssertShowDecimal(option.Length);
return true;
default:
return false;
}
}
示例12: CompareField
protected override bool CompareField(XElement field, Datagram parentDatagram, Datagram datagram)
{
IpDatagram ipDatagram = (IpDatagram)parentDatagram;
TcpDatagram tcpDatagram = (TcpDatagram)datagram;
switch (field.Name())
{
case "tcp.len":
field.AssertShowDecimal(tcpDatagram.Length - tcpDatagram.HeaderLength);
field.AssertNoFields();
break;
case "tcp.srcport":
field.AssertShowDecimal(tcpDatagram.SourcePort);
field.AssertNoFields();
break;
case "tcp.dstport":
field.AssertShowDecimal(tcpDatagram.DestinationPort);
field.AssertNoFields();
break;
case "tcp.port":
Assert.IsTrue(ushort.Parse(field.Show()) == tcpDatagram.SourcePort ||
ushort.Parse(field.Show()) == tcpDatagram.DestinationPort);
field.AssertNoFields();
break;
case "tcp.seq":
field.AssertShowDecimal(tcpDatagram.SequenceNumber);
field.AssertNoFields();
break;
case "tcp.nxtseq":
field.AssertShowDecimal(tcpDatagram.NextSequenceNumber);
field.AssertNoFields();
break;
case "tcp.ack":
field.AssertShowDecimal(tcpDatagram.AcknowledgmentNumber);
foreach (XElement subfield in field.Fields())
{
switch (subfield.Name())
{
case "_ws.expert":
break;
default:
subfield.AssertNoFields();
throw new InvalidOperationException("Invalid TCP subfield name " + subfield.Name());
}
}
break;
case "tcp.hdr_len":
field.AssertShowDecimal(tcpDatagram.HeaderLength);
field.AssertNoFields();
break;
case "tcp.flags":
ushort flags =
(ushort)((tcpDatagram.Reserved << 9) |
(((tcpDatagram.ControlBits & TcpControlBits.NonceSum) == TcpControlBits.NonceSum ? 1 : 0) << 8) |
(byte)tcpDatagram.ControlBits);
field.AssertShowDecimal(flags);
foreach (var flagField in field.Fields())
{
switch (flagField.Name())
{
case "tcp.flags.res":
flagField.AssertNoFields();
break;
case "tcp.flags.ns":
flagField.AssertNoFields();
flagField.AssertShowDecimal(tcpDatagram.IsNonceSum);
break;
case "tcp.flags.cwr":
flagField.AssertNoFields();
flagField.AssertShowDecimal(tcpDatagram.IsCongestionWindowReduced);
break;
case "tcp.flags.ecn":
flagField.AssertNoFields();
flagField.AssertShowDecimal(tcpDatagram.IsExplicitCongestionNotificationEcho);
break;
case "tcp.flags.urg":
flagField.AssertNoFields();
flagField.AssertShowDecimal(tcpDatagram.IsUrgent);
break;
case "tcp.flags.ack":
flagField.AssertNoFields();
flagField.AssertShowDecimal(tcpDatagram.IsAcknowledgment);
break;
case "tcp.flags.push":
//.........这里部分代码省略.........
示例13: CompareField
protected override bool CompareField(XElement field, Datagram datagram)
{
HttpDatagram httpDatagram = (HttpDatagram)datagram;
if (field.Name() == "data" || field.Name() == "data.data")
{
if (field.Name() == "data")
field.AssertNoShow();
MoreAssert.AreSequenceEqual(httpDatagram.Subsegment(0, _data.Length / 2), HexEncoding.Instance.GetBytes(_data.ToString()));
// TODO: Uncomment once https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10707 is fixed.
// field.AssertValue(httpDatagram.Subsegment(_data.Length / 2 + 2, httpDatagram.Length - _data.Length / 2 - 2));
return false;
}
string fieldShow = field.Show();
string httpFieldName;
switch (field.Name())
{
case "http.request":
field.AssertShowDecimal(httpDatagram.IsRequest);
break;
case "http.response":
field.AssertShowDecimal(httpDatagram.IsResponse);
break;
case "":
if (fieldShow == "HTTP chunked response")
throw new InvalidOperationException("HTTP chunked response");
if (fieldShow == @"\r\n" || fieldShow == "HTTP response 1/1" || fieldShow == "HTTP request 1/1")
break;
_data.Append(field.Value());
if (_isFirstEmptyName)
{
CompareHttpFirstLine(field, httpDatagram);
_isFirstEmptyName = false;
}
else if (fieldShow.StartsWith("Content-encoded entity body"))
{
break;
}
else
{
fieldShow = EncodingExtensions.Iso88591.GetString(HexEncoding.Instance.GetBytes(field.Value()));
fieldShow = fieldShow.Substring(0, fieldShow.Length - 2);
int colonIndex = fieldShow.IndexOf(':');
MoreAssert.IsBiggerOrEqual(0, colonIndex, "Can't find colon in field with empty name");
if (httpDatagram.Header == null)
{
if (httpDatagram.IsRequest)
Assert.IsNull(httpDatagram.Version);
else
Assert.IsTrue(IsBadHttp(httpDatagram));
break;
}
httpFieldName = fieldShow.Substring(0, colonIndex);
if (!field.Value().EndsWith("0d0a"))
Assert.IsNull(httpDatagram.Header[httpFieldName]);
else
{
string fieldValue = fieldShow.Substring(colonIndex + 1).SkipWhile(c => c == ' ').TakeWhile(c => c != '\\').SequenceToString();
string expectedFieldValue = httpDatagram.Header[httpFieldName].ValueString;
Assert.IsTrue(expectedFieldValue.Contains(fieldValue),
string.Format("{0} <{1}> doesn't contain <{2}>", field.Name(), expectedFieldValue, fieldValue));
}
}
break;
case "data.len":
field.AssertShowDecimal(httpDatagram.Length - _data.Length / 2);
break;
case "http.host":
case "http.user_agent":
case "http.accept":
case "http.accept_language":
case "http.accept_encoding":
case "http.connection":
case "http.cookie":
case "http.cache_control":
case "http.content_encoding":
case "http.date":
case "http.referer":
case "http.last_modified":
case "http.server":
case "http.set_cookie":
case "http.location":
_data.Append(field.Value());
httpFieldName = field.Name().Substring(5).Replace('_', '-');
HttpField httpField = httpDatagram.Header[httpFieldName];
if (!field.Value().EndsWith("0d0a"))
Assert.IsNull(httpField);
else
{
string fieldValue = field.Show().Replace("\\\"", "\"");
string expectedFieldValue = httpField.ValueString;
//.........这里部分代码省略.........
示例14: CompareField
protected override bool CompareField(XElement field, Datagram datagram)
{
IpV4Datagram ipV4Datagram = (IpV4Datagram)datagram;
switch (field.Name())
{
case "ip.version":
field.AssertShowDecimal(ipV4Datagram.Version);
break;
case "ip.hdr_len":
field.AssertShowDecimal(ipV4Datagram.HeaderLength);
break;
case "ip.dsfield":
field.AssertShowDecimal((int)ipV4Datagram.TypeOfService);
break;
case "ip.len":
field.AssertShowDecimal(ipV4Datagram.TotalLength);
break;
case "ip.id":
field.AssertShowHex(ipV4Datagram.Identification);
break;
case "ip.flags":
field.AssertShowHex((byte)((ushort)ipV4Datagram.Fragmentation.Options >> 13));
break;
case "ip.frag_offset":
field.AssertShowDecimal(ipV4Datagram.Fragmentation.Offset);
break;
case "ip.ttl":
field.AssertShowDecimal(ipV4Datagram.Ttl);
break;
case "ip.proto":
field.AssertShowDecimal((byte)ipV4Datagram.Protocol);
break;
case "ip.checksum":
field.AssertShowHex(ipV4Datagram.HeaderChecksum);
foreach (var checksumField in field.Fields())
{
switch (checksumField.Name())
{
case "ip.checksum_good":
checksumField.AssertShowDecimal(ipV4Datagram.IsHeaderChecksumCorrect);
break;
case "ip.checksum_bad":
if (ipV4Datagram.Length < IpV4Datagram.HeaderMinimumLength ||
ipV4Datagram.Length < ipV4Datagram.HeaderLength)
break;
checksumField.AssertShowDecimal(!ipV4Datagram.IsHeaderChecksumCorrect);
break;
}
}
break;
case "ip.src":
case "ip.src_host":
field.AssertShow(ipV4Datagram.Source.ToString());
break;
case "ip.dst":
case "ip.dst_host":
if (field.Show() != ipV4Datagram.Destination.ToString())
{
// TODO: Remove this fallback once https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7043 is fixed.
field.AssertShow(ipV4Datagram.CurrentDestination.ToString());
Assert.IsTrue(ipV4Datagram.Options.IsBadForWireshark(),
string.Format("Expected destination: {0}. Destination: {1}. Current destination: {2}.", field.Show(),
ipV4Datagram.Destination, ipV4Datagram.CurrentDestination));
}
break;
case "ip.addr":
case "ip.host":
Assert.IsTrue(field.Show() == ipV4Datagram.Source.ToString() ||
field.Show() == ipV4Datagram.Destination.ToString() ||
// TODO: Remove this fallback once https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7043 is fixed.
field.Show() == ipV4Datagram.CurrentDestination.ToString() && ipV4Datagram.Options.IsBadForWireshark(),
string.Format("Expected ip: {0}. ", field.Show()) +
(ipV4Datagram.IsValid
? string.Format("Source: {0}. Destination: {1}. Current destination: {2}.", ipV4Datagram.Source,
ipV4Datagram.Destination, ipV4Datagram.CurrentDestination)
: ""));
break;
case "":
CompareIpV4Options(field, ipV4Datagram.Options);
break;
default:
throw new InvalidOperationException("Invalid ip field " + field.Name());
}
//.........这里部分代码省略.........
示例15: CompareField
protected override bool CompareField(XElement field, Datagram datagram)
{
VLanTaggedFrameDatagram vLanTaggedFrameDatagram = (VLanTaggedFrameDatagram)datagram;
switch (field.Name())
{
case "vlan.priority":
field.AssertNoFields();
field.AssertShowDecimal((byte)vLanTaggedFrameDatagram.PriorityCodePoint);
break;
case "vlan.cfi":
field.AssertNoFields();
field.AssertShowDecimal(vLanTaggedFrameDatagram.CanonicalFormatIndicator);
break;
case "vlan.id":
field.AssertNoFields();
field.AssertShowDecimal(vLanTaggedFrameDatagram.VLanIdentifier);
break;
case "vlan.etype":
field.AssertNoFields();
field.AssertShowDecimal((ushort)vLanTaggedFrameDatagram.EtherType);
break;
case "vlan.len":
field.AssertShowDecimal((ushort)vLanTaggedFrameDatagram.EtherType);
if (field.Fields().Any())
{
field.AssertNumFields(1);
field.Fields().First().AssertName("_ws.expert");
}
break;
case "vlan.trailer":
field.AssertNoFields();
if (!new[]
{
(EthernetType)1,
(EthernetType)5,
(EthernetType)12,
(EthernetType)17,
(EthernetType)29,
(EthernetType)30,
(EthernetType)43,
(EthernetType)50,
EthernetType.ReverseArp, // TODO: Support RARP
EthernetType.ExtensibleAuthenticationProtocolOverLan, // TODO: Support this protocol.
}.Contains(
vLanTaggedFrameDatagram.EtherType))
{
field.AssertValue(vLanTaggedFrameDatagram.ExtraData);
}
break;
case "eth.padding":
field.AssertNoFields();
if (!new[]
{
EthernetType.ExtensibleAuthenticationProtocolOverLan, // TODO: Support this protocol.
}.Contains(
vLanTaggedFrameDatagram.EtherType))
{
field.AssertValue(vLanTaggedFrameDatagram.Trailer);
}
break;
default:
throw new InvalidOperationException("Invalid VLanTaggedFrame field " + field.Name());
}
return true;
}