コード例 #1
1
        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;
                        Assert.IsTrue(expectedFieldValue.Contains(fieldValue),
                                      string.Format("{0} <{1}> doesn't contain <{2}>", field.Name(), expectedFieldValue, fieldValue));
                    }
                    break;

                case "http.content_length_header":
                    _data.Append(field.Value());
                    if (!IsBadHttp(httpDatagram))
                    {
                        if (!field.Value().EndsWith("0d0a"))
                            Assert.IsNull(httpDatagram.Header.ContentLength);
                        else
                            field.AssertShowDecimal(httpDatagram.Header.ContentLength.ContentLength.Value);
                    }
                    break;

                case "http.content_type":
                    _data.Append(field.Value());
                    string[] mediaType = fieldShow.Split(new[] {';', ' ', '/'}, StringSplitOptions.RemoveEmptyEntries);
                    if (!IsBadHttp(httpDatagram))
                    {
                        if (!field.Value().EndsWith("0d0a"))
                            Assert.IsNull(httpDatagram.Header.ContentType);
                        else
                        {
                            Assert.AreEqual(httpDatagram.Header.ContentType.MediaType, mediaType[0]);
                            Assert.AreEqual(httpDatagram.Header.ContentType.MediaSubtype, mediaType[1]);
                            int fieldShowParametersStart = fieldShow.IndexOf(';');
                            if (fieldShowParametersStart == -1)
                                Assert.IsFalse(httpDatagram.Header.ContentType.Parameters.Any());
                            else
                            {
                                string expected =
                                    httpDatagram.Header.ContentType.Parameters.Select(pair => pair.Key + '=' + pair.Value.ToWiresharkLiteral()).
                                        SequenceToString(';');
                                Assert.AreEqual(expected, fieldShow.Substring(fieldShowParametersStart + 1));
                            }
                        }
                    }
                    break;

                case "http.request.line":
                case "http.response.line":
                    if (_data.ToString().EndsWith(field.Value()))
                        break;
                    {
                        _data.Append(field.Value());
                    }
                    break;

                case "http.transfer_encoding":
                    if (!IsBadHttp(httpDatagram))
                    {
                        Assert.AreEqual(fieldShow.ToWiresharkLowerLiteral(),
                                        httpDatagram.Header.TransferEncoding.TransferCodings.SequenceToString(',').ToLowerInvariant().ToWiresharkLiteral());
                    }
                    break;

                case "http.request.full_uri":
                    // TODO: Uncomment when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10681 is fixed.
                    // Assert.AreEqual(fieldShow, ("http://" + httpDatagram.Header["Host"].ValueString + ((HttpRequestDatagram)httpDatagram).Uri).ToWiresharkLiteral());
                    break;

                default:
                    throw new InvalidOperationException("Invalid HTTP field " + field.Name());
            }

            return true;
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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.AssertShowHex((ushort)ethernetDatagram.EtherType);
                    break;

                case "eth.trailer":
                    if (ethernetDatagram.Trailer != null)
                        field.AssertValue(ethernetDatagram.Trailer);
                    break;

                case "":
                    if (ethernetDatagram.Trailer != null)
                        field.AssertValue(ethernetDatagram.FrameCheckSequence);
                    break;

                default:
                    throw new InvalidOperationException("Invalid etherent field " + field.Name());
            }

            return true;
        }
        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;
        }
コード例 #5
0
        protected void CompareDatagram(XElement layer, Datagram parentDatagram, Datagram datagram)
        {
            foreach (var field in layer.Fields())
            {
                if (!CompareField(field, parentDatagram, datagram))
                    break;
            }

            WiresharkCompareTests.CompareProtocols(datagram, layer);
        }
コード例 #6
0
        protected bool CompareDatagram(XElement layer, Datagram parentDatagram, Datagram datagram)
        {
            bool success = true;
            foreach (var element in layer.Fields())
            {
                if (!CompareField(element, parentDatagram, datagram))
                {
                    success = false;
                    break;
                }
            }

            WiresharkCompareTests.CompareProtocols(datagram, layer, success);
            return success;
        }
コード例 #7
0
        protected bool CompareDatagram(XElement layer, Datagram parentDatagram, Datagram datagram)
        {
            bool success = true;
            foreach (var element in layer.Fields())
            {
                // TODO: Remove this hack when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=11802 is fixed.
                IpV6Datagram ipV6ParentDatagram = parentDatagram as IpV6Datagram;
                if (ipV6ParentDatagram != null && (ipV6ParentDatagram.NextHeader == IpV4Protocol.IsoIp || ipV6ParentDatagram.ExtensionHeaders.NextHeader == IpV4Protocol.IsoIp))
                    return false;
                if (!CompareField(element, parentDatagram, datagram))
                {
                    success = false;
                    break;
                }
            }

            WiresharkCompareTests.CompareProtocols(datagram, layer, success);
            return success;
        }
コード例 #8
0
        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;
        }
コード例 #9
0
        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);
                            break;

                        case "Additional records":
                            CompareResourceRecords(resourceRecordsFields, dnsDatagram.Additionals);
                            break;

                        default:
                            throw new InvalidOperationException("Invalid DNS resource records field " + field.Show());
                    }
                    break;

                case "dns.response_to":
                case "dns.time":
                    break;

                default:
                    throw new InvalidOperationException("Invalid DNS field " + field.Name());
            }

            return true;
        }
コード例 #10
0
 protected override sealed bool CompareField(XElement field, Datagram parentDatagram, Datagram datagram)
 {
     return CompareField(field, datagram);
 }
コード例 #11
0
        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;
        }
コード例 #12
0
        protected override bool CompareField(XElement field, Datagram datagram)
        {
            IcmpDatagram icmpDatagram = (IcmpDatagram)datagram;
            switch (field.Name())
            {
                case "icmp.type":
                    field.AssertShowDecimal((byte)icmpDatagram.MessageType);
                    field.AssertNoFields();
                    break;

                case "icmp.code":
                    field.AssertShowDecimal(icmpDatagram.Code);
                    field.AssertNoFields();
                    break;

                case "icmp.checksum_bad":
                    field.AssertShowDecimal(!icmpDatagram.IsChecksumCorrect);
                    field.AssertNoFields();
                    break;

                case "icmp.checksum":
                    field.AssertShowDecimal(icmpDatagram.Checksum);
                    field.AssertNoFields();
                    break;

                case "data":
                    var icmpIpV4PayloadDatagram = icmpDatagram as IcmpIpV4PayloadDatagram;
                    if (icmpIpV4PayloadDatagram != null)
                    {
                        if (!new[]
                                 {
                                     IpV4Protocol.IpComp, // TODO: Support IpComp.
                                     IpV4Protocol.Ax25, // TODO: Support Ax25.
                                     IpV4Protocol.FibreChannel, // TODO: Support FibreChannel.
                                 }.Contains(icmpIpV4PayloadDatagram.IpV4.Protocol))
                        {
                            if (icmpIpV4PayloadDatagram.IpV4.Protocol == IpV4Protocol.Udp)
                            {
                                // Uncomment this when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10990 is fixed.
                                //                                field.AssertDataField(casted1.IpV4.Udp.Payload);
                            }
                            else
                            {
                                // TODO: Remove this condition when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10991 and https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10992 are fixed.
                                if (!(icmpIpV4PayloadDatagram is IcmpParameterProblemDatagram || icmpIpV4PayloadDatagram is IcmpRedirectDatagram))
                                    field.AssertDataField(icmpIpV4PayloadDatagram.IpV4.Payload);
                            }
                        }
                    }
                    else
                    {
                        field.AssertDataField(icmpDatagram.Payload);
                    }
                    break;

                case "":
                    switch (icmpDatagram.MessageType)
                    {
                        case IcmpMessageType.ParameterProblem:
                            if (field.Show() != "Unknown session type")
                                field.AssertShow("Pointer: " + ((IcmpParameterProblemDatagram)icmpDatagram).Pointer);
                            break;

                        case IcmpMessageType.RouterAdvertisement:
                            IcmpRouterAdvertisementDatagram routerAdvertisementDatagram = (IcmpRouterAdvertisementDatagram)icmpDatagram;
                            string fieldName = field.Show().Split(':')[0];
                            switch (fieldName)
                            {
                                case "Number of addresses":
                                    field.AssertShow(fieldName + ": " + routerAdvertisementDatagram.NumberOfAddresses);
                                    break;

                                case "Address entry size":
                                    field.AssertShow(fieldName + ": " + routerAdvertisementDatagram.AddressEntrySize);
                                    break;

                                case "Lifetime":
                                    TimeSpan actualLifetime = routerAdvertisementDatagram.Lifetime;
                                    StringBuilder actualLifetimeString = new StringBuilder(fieldName + ": ");
                                    if (actualLifetime.Hours != 0)
                                    {
                                        actualLifetimeString.Append(actualLifetime.Hours + " hour");
                                        if (actualLifetime.Hours != 1)
                                            actualLifetimeString.Append('s');
                                    }
                                    if (actualLifetime.Minutes != 0)
                                    {
                                        if (actualLifetime.Hours != 0)
                                            actualLifetimeString.Append(", ");
                                        actualLifetimeString.Append(actualLifetime.Minutes + " minute");
                                        if (actualLifetime.Minutes != 1)
                                            actualLifetimeString.Append('s');
                                    }
                                    if (actualLifetime.Seconds != 0)
                                    {
                                        if (actualLifetime.Hours != 0 || actualLifetime.Minutes != 0)
                                            actualLifetimeString.Append(", ");
                                        actualLifetimeString.Append(actualLifetime.Seconds + " second");
                                        if (actualLifetime.Seconds != 1)
                                            actualLifetimeString.Append('s');
                                    }
                                    break;

                                case "Router address":
                                    field.AssertShow(fieldName + ": " + routerAdvertisementDatagram.Entries[_routerIndex].RouterAddress);
                                    break;

                                case "Preference level":
                                    field.AssertShow(fieldName + ": " + routerAdvertisementDatagram.Entries[_routerIndex++].RouterAddressPreference);
                                    break;

                                default:
                                    throw new InvalidOperationException("Invalid icmp " + icmpDatagram.MessageType + " field " + fieldName);
                            }
                            break;
                    }
                    field.AssertNoFields();
                    break;

                case "icmp.ident":
                    ushort identifier = ((IcmpIdentifiedDatagram)icmpDatagram).Identifier;
                    field.AssertShowDecimal(field.Showname().StartsWith("Identifier (BE): ") ? identifier : identifier.ReverseEndianity());
                    field.AssertNoFields();
                    break;

                case "icmp.seq":
                    field.AssertShowDecimal(((IcmpIdentifiedDatagram)icmpDatagram).SequenceNumber);
                    field.AssertNoFields();
                    break;

                case "icmp.seq_le":
                    byte[] sequenceNumberBuffer = new byte[sizeof(ushort)];
                    sequenceNumberBuffer.Write(0, ((IcmpIdentifiedDatagram)icmpDatagram).SequenceNumber, Endianity.Big);
                    ushort lowerEndianSequenceNumber = sequenceNumberBuffer.ReadUShort(0, Endianity.Small);
                    field.AssertShowDecimal(lowerEndianSequenceNumber);
                    field.AssertNoFields();
                    break;

                case "icmp.redir_gw":
                    field.AssertShow(((IcmpRedirectDatagram)icmpDatagram).GatewayInternetAddress.ToString());
                    field.AssertNoFields();
                    break;

                case "icmp.mtu":
                    field.AssertShowDecimal(((IcmpDestinationUnreachableDatagram)icmpDatagram).NextHopMaximumTransmissionUnit);
                    field.AssertNoFields();
                    break;

                case "l2tp.l2_spec_def":
                    field.AssertShow("");
                    field.AssertNoFields();
                    break;

                case "icmp.resp_to":
                case "icmp.resptime":
                    break;

                // TODO: Remove this case when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10939 is fixed.
                case "icmp.length":
                    break;

                default:
                    if (!field.Name().StartsWith("lt2p.") &&
                        field.Name() != "pweth" &&
                        !field.Name().StartsWith("pweth."))
                        throw new InvalidOperationException("Invalid icmp field " + field.Name());
                    break;
            }

            return true;
        }
コード例 #13
0
        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":
                                flagField.AssertNoFields();
                                flagField.AssertShowDecimal(tcpDatagram.IsPush);
                                break;

                            case "tcp.flags.reset":
                                flagField.AssertShowDecimal(tcpDatagram.IsReset);
                                foreach (XElement subfield in flagField.Fields())
                                {
                                    switch (subfield.Name())
                                    {
                                        case "_ws.expert":
                                            break;

                                        default:
                                            throw new InvalidOperationException("Invalid TCP subfield name " + subfield.Name());
                                    }
                                }
                                break;

                            case "tcp.flags.syn":
                                flagField.AssertShowDecimal(tcpDatagram.IsSynchronize);
                                foreach (XElement subfield in flagField.Fields())
                                {
                                    switch (subfield.Name())
                                    {
                                        case "_ws.expert":
                                            break;

                                        default:
                                            throw new InvalidOperationException("Invalid TCP subfield name " + subfield.Name());
                                    }
                                }
                                break;

                            case "tcp.flags.fin":
                                flagField.AssertShowDecimal(tcpDatagram.IsFin);
                                foreach (XElement subfield in flagField.Fields())
                                {
                                    switch (subfield.Name())
                                    {
                                        case "_ws.expert":
                                            break;

                                        default:
                                            throw new InvalidOperationException("Invalid TCP subfield name " + subfield.Name());
                                    }
                                }
                                break;

                            default:
                                throw new InvalidOperationException("Invalid TCP flag field name " + flagField.Name());
                        }
                    }
                    break;

                case "tcp.window_size_value":
                    field.AssertShowDecimal(tcpDatagram.Window);
                    field.AssertNoFields();
                    break;

                case "tcp.checksum":
                    field.AssertShowDecimal(tcpDatagram.Checksum);
                    IpV4Datagram ipV4Datagram = ipDatagram as IpV4Datagram;
                    if (ipV4Datagram != null)
                    {
                        foreach (var checksumField in field.Fields())
                        {
                            // When TCP checksum is zero Wireshark assumes it's Checksum Offloading and puts false in both checksum_good and checksum_bad.
                            switch (checksumField.Name())
                            {
                                case "tcp.checksum_good":
                                    checksumField.AssertNoFields();
                                    checksumField.AssertShowDecimal(tcpDatagram.Checksum != 0 && ipDatagram.IsTransportChecksumCorrect);
                                    break;

                                case "tcp.checksum_bad":
                                    checksumField.AssertShowDecimal(!ipDatagram.IsTransportChecksumCorrect);
                                    if (checksumField.Fields().Any())
                                    {
                                        checksumField.AssertNumFields(1);
                                        checksumField.Fields().First().AssertName("_ws.expert");
                                    }
                                    break;

                                case "tcp.checksum_calculated":
                                    checksumField.AssertNoFields();
                                    if (ipDatagram.IsTransportChecksumCorrect)
                                        checksumField.AssertShowDecimal(tcpDatagram.Checksum);
                                    break;

                                default:
                                    throw new InvalidOperationException("Invalid checksum field name " + checksumField.Name());
                            }
                        }
                    }
                    break;

                case "tcp.urgent_pointer":
                    field.AssertShowDecimal(tcpDatagram.UrgentPointer);
                    break;

                case "tcp.options":
                    CompareTcpOptions(field, tcpDatagram.Options);
                    break;

                case "tcp.stream":
                case "tcp.pdu.size":
                case "tcp.window_size":
                case "tcp.window_size_scalefactor":
                    field.AssertNoFields();
                    break;

                case "":
                    if (field.Show() == "Short segment. Segment/fragment does not contain a full TCP header (might be NMAP or someone else deliberately sending unusual packets)")
                    {
                        field.AssertNumFields(1);
                        field.Fields().First().AssertName("_ws.expert");
                    }
                    else
                    {
                        field.AssertNoFields();
                    }
                    break;

                default:
                    throw new InvalidOperationException("Invalid tcp field " + field.Name());
            }

            return true;
        }
コード例 #14
0
        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)
                    {
                        switch (greDatagram.Routing[_routingEntryIndex].AddressFamily)
                        {
                            case GreSourceRouteEntryAddressFamily.IpSourceRoute:
                                field.AssertValue(((GreSourceRouteEntryIp)greDatagram.Routing[_routingEntryIndex]).Addresses);
                                break;

                            case GreSourceRouteEntryAddressFamily.AsSourceRoute:
                                field.AssertValue(((GreSourceRouteEntryAs)greDatagram.Routing[_routingEntryIndex]).AsNumbers);
                                break;

                            default:
                                field.AssertValue(((GreSourceRouteEntryUnknown)greDatagram.Routing[_routingEntryIndex]).Data);
                                break;
                        }

                        ++_routingEntryIndex;
                    }
                    field.AssertNoFields();
                    break;

                case "gre.proto":
                    field.AssertShowDecimal((ushort)greDatagram.ProtocolType);
                    field.AssertNoFields();
                    break;

                case "gre.key":
                    field.AssertShowDecimal(greDatagram.Key);
                    field.AssertNoFields();
                    break;

                case "data":
                case "data.data":
                    field.AssertDataField(greDatagram.Payload);
                    break;

                default:
                    Assert.Fail("Invalid field name: " + field.Name());
                    break;
            }

            return true;
        }
コード例 #15
0
        protected override bool CompareField(XElement field, Datagram parentDatagram, Datagram datagram)
        {
            IpV4Datagram ipV4Datagram = (IpV4Datagram)parentDatagram;
            TcpDatagram tcpDatagram = (TcpDatagram)datagram;

            switch (field.Name())
            {
                case "tcp.len":
                    if (tcpDatagram.Payload == null)
                    {
                        // todo seems like a bug in tshark https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=5235
                        break;
//                            field.AssertShowDecimal(tcpDatagram.Length);
                    }
                    else
                        field.AssertShowDecimal(tcpDatagram.Payload.Length);
                    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);
                    field.AssertNoFields();
                    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.AssertShow("0x" + flags.ToString("x" + 4 * sizeof(byte)));
                    foreach (var flagField in field.Fields())
                    {
                        switch (flagField.Name())
                        {
                            case "tcp.flags.cwr":
                                flagField.AssertShowDecimal(tcpDatagram.IsCongestionWindowReduced);
                                break;

                            case "tcp.flags.ecn":
                                flagField.AssertShowDecimal(tcpDatagram.IsExplicitCongestionNotificationEcho);
                                break;

                            case "tcp.flags.urg":
                                flagField.AssertShowDecimal(tcpDatagram.IsUrgent);
                                break;

                            case "tcp.flags.ack":
                                flagField.AssertShowDecimal(tcpDatagram.IsAcknowledgment);
                                break;

                            case "tcp.flags.push":
                                flagField.AssertShowDecimal(tcpDatagram.IsPush);
                                break;

                            case "tcp.flags.reset":
                                flagField.AssertShowDecimal(tcpDatagram.IsReset);
                                break;

                            case "tcp.flags.syn":
                                flagField.AssertShowDecimal(tcpDatagram.IsSynchronize);
                                break;

                            case "tcp.flags.fin":
                                flagField.AssertShowDecimal(tcpDatagram.IsFin);
                                break;
                        }
                        flagField.AssertNoFields();
                    }
                    break;

                case "tcp.window_size_value":
                    field.AssertShowDecimal(tcpDatagram.Window);
                    field.AssertNoFields();
                    break;

                case "tcp.checksum":
                    field.AssertShowHex(tcpDatagram.Checksum);
                    if (!ipV4Datagram.Options.IsBadForWireshark())
                    {
                        foreach (var checksumField in field.Fields())
                        {
                            // When TCP checksum is zero Wireshark assumes it's Checksum Offloading and puts false in both checksum_good and checksum_bad.
                            switch (checksumField.Name())
                            {
                                case "tcp.checksum_good":
                                    checksumField.AssertShowDecimal(tcpDatagram.Checksum != 0 && ipV4Datagram.IsTransportChecksumCorrect);
                                    break;

                                case "tcp.checksum_bad":
                                    checksumField.AssertShowDecimal(tcpDatagram.Checksum != 0 && !ipV4Datagram.IsTransportChecksumCorrect);
                                    break;

                                default:
                                    throw new InvalidOperationException("Invalid checksum field name " + checksumField.Name());
                            }
                            checksumField.AssertNoFields();
                        }
                    }
                    break;

                case "tcp.urgent_pointer":
                    field.AssertShowDecimal(tcpDatagram.UrgentPointer);
                    field.AssertNoFields();
                    break;

                case "tcp.options":
                    CompareTcpOptions(field, tcpDatagram.Options);
                    break;

                case "tcp.stream":
                case "tcp.pdu.size":
                case "tcp.window_size":
                case "tcp.window_size_scalefactor":
                case "":
                    field.AssertNoFields();
                    break;

                default:
                    throw new InvalidOperationException("Invalid tcp field " + field.Name());
            }

            return true;
        }
コード例 #16
0
        protected override bool CompareField(XElement field, Datagram datagram)
        {
            IgmpDatagram igmpDatagram = (IgmpDatagram)datagram;
            switch (field.Name())
            {
                case "igmp.version":
                    if (field.Show() == "0")
                        return false; // TODO: support IGMP version 0.

                    field.AssertShowDecimal(igmpDatagram.Version);
                    break;

                case "igmp.type":
                    field.AssertShowHex((byte)igmpDatagram.MessageType);
                    break;

                case "igmp.checksum":
                    field.AssertShowHex(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":
                    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:
                            CompareDatagram(field, null, igmpDatagram);
                            break;

                        case IgmpMessageType.MulticastTraceRouteResponse:
                            // todo support IGMP traceroute http://www.ietf.org/proceedings/48/I-D/idmr-traceroute-ipm-07.txt.
                            break;

                        default:
                            if (typeof(IgmpMessageType).GetEnumValues<IgmpMessageType>().Contains(igmpDatagram.MessageType))
                                throw new InvalidOperationException("Invalid message type " + igmpDatagram.MessageType);

                            field.AssertValue(igmpDatagram.Skip(1));
//                                field.AssertShow(igmpDatagram.Skip(1));
                            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":
                    // todo support IGMP version 0 and IGMP identifier.
                    break;

                case "igmp.mtrace.max_hops":
                case "igmp.mtrace.saddr":
                case "igmp.mtrace.raddr":
                case "igmp.mtrace.rspaddr":
                case "igmp.mtrace.resp_ttl":
                case "igmp.mtrace.q_id":
                    // todo support IGMP traceroute http://www.ietf.org/proceedings/48/I-D/idmr-traceroute-ipm-07.txt.
                    Assert.AreEqual(IgmpMessageType.MulticastTraceRouteResponse, igmpDatagram.MessageType);
                    break;

                default:
                    throw new InvalidOperationException("Invalid igmp field " + field.Name());
            }

            return true;
        }
コード例 #17
0
        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;

                case "ipv6.routing_hdr":
                    if (!ipV6Datagram.IsValid)
                        return false;
                    IpV6ExtensionHeaderRouting routing = (IpV6ExtensionHeaderRouting)ipV6Datagram.ExtensionHeaders[_currentExtensionHeaderIndex];
                        IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks routingProtocolLowPowerAndLossyNetworks =
                            routing as IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks;
                    int routingProtocolLowPowerAndLossyNetworksAddressIndex = 0;
                    IncrementCurrentExtensionHeaderIndex(ipV6Datagram);
                    int sourceRouteAddressIndex = 0;
                    foreach (var headerField in field.Fields())
                    {
                        switch (headerField.Name())
                        {
                            case "":
                                headerField.AssertNoFields();
                                ValidateExtensionHeaderUnnamedField(routing, headerField);
                                break;

                            case "ipv6.routing_hdr.type":
                                headerField.AssertNoFields();
                                headerField.AssertShowDecimal((byte)routing.RoutingType);
                                break;

                            case "ipv6.routing_hdr.left":
                                headerField.AssertNoFields();
                                headerField.AssertShowDecimal(routing.SegmentsLeft);
                                break;

                            case "ipv6.mipv6_home_address":
                                headerField.AssertNoFields();
                                IpV6ExtensionHeaderRoutingHomeAddress routingHomeAddress = (IpV6ExtensionHeaderRoutingHomeAddress)routing;
                                headerField.AssertShow(routingHomeAddress.HomeAddress.ToString("x"));
                                break;

                            case "ipv6.routing_hdr.addr":
                                headerField.AssertNoFields();
                                IpV6ExtensionHeaderRoutingSourceRoute routingSourceRoute = (IpV6ExtensionHeaderRoutingSourceRoute)routing;
                                headerField.AssertShow(routingSourceRoute.Addresses[sourceRouteAddressIndex++].ToString("x"));
                                break;

                            case "ipv6.routing_hdr.rpl.cmprI":
                                headerField.AssertNoFields();
                                headerField.AssertShowDecimal(routingProtocolLowPowerAndLossyNetworks.CommonPrefixLengthForNonLastAddresses);
                                break;

                            case "ipv6.routing_hdr.rpl.cmprE":
                                headerField.AssertNoFields();
                                headerField.AssertShowDecimal(routingProtocolLowPowerAndLossyNetworks.CommonPrefixLengthForLastAddress);
                                break;

                            case "ipv6.routing_hdr.rpl.pad":
                                headerField.AssertNoFields();
                                headerField.AssertShowDecimal(routingProtocolLowPowerAndLossyNetworks.PadSize);
                                break;

                            case "ipv6.routing_hdr.rpl.reserved":
                                headerField.AssertNoFields();
                                headerField.AssertShowDecimal(0);
                                break;

                            case "ipv6.routing_hdr.rpl.segments":
                                if (headerField.Fields().Any())
                                {
                                    headerField.AssertNumFields(1);
                                    headerField.Fields().First().AssertName("_ws.expert");
                                }
                                // TODO: Uncomment when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10560 is fixed.
            //                                headerField.AssertShowDecimal(routingProtocolLowPowerAndLossyNetworks.Addresses.Count);
                                break;

                            case "ipv6.routing_hdr.rpl.address":
                                headerField.AssertNoFields();
                                // TODO: Implement when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10560 is fixed.
                                break;

                            case "ipv6.routing_hdr.rpl.full_address":
                                headerField.AssertNoFields();
                                // TODO: Implement when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10673 is fixed.
                                ++routingProtocolLowPowerAndLossyNetworksAddressIndex;
                                break;

                            default:
                                throw new InvalidOperationException("Invalid IPv6 routing source route field " + headerField.Name());
                        }
                    }
                    break;

                case "ipv6.dst_opt":
                    if (_currentExtensionHeaderIndex >= ipV6Datagram.ExtensionHeaders.Headers.Count)
                    {
                        int expectedExtensionHeaderLength = (int.Parse(field.Fields().Skip(1).First().Value(), NumberStyles.HexNumber) + 1) * 8;
                        int actualMaxPossibleLength = ipV6Datagram.RealPayloadLength -
                                                   ipV6Datagram.ExtensionHeaders.Take(_currentExtensionHeaderIndex).Sum(
                                                       extensionHeader => extensionHeader.Length);
                        MoreAssert.IsSmaller(expectedExtensionHeaderLength, actualMaxPossibleLength);
                        return false;
                    }
                    IpV6ExtensionHeaderDestinationOptions destinationOptions = (IpV6ExtensionHeaderDestinationOptions)ipV6Datagram.ExtensionHeaders[_currentExtensionHeaderIndex];
                    IncrementCurrentExtensionHeaderIndex(ipV6Datagram);
                    CompareOptions(field, ref optionsIndex, ipV6Datagram, destinationOptions);
                    break;

                case "ipv6.shim6":
                    // TODO: Implement Shim6.
                    IpV4Protocol nextHeader = _currentExtensionHeaderIndex > 0
                                                  ? ipV6Datagram.ExtensionHeaders[_currentExtensionHeaderIndex - 1].NextHeader.Value
                                                  : ipV6Datagram.NextHeader;
                    Assert.IsTrue(nextHeader == IpV4Protocol.Shim6);
                    break;

                case "ipv6.unknown_hdr":
                    Assert.AreEqual(ipV6Datagram.ExtensionHeaders.Count(), _currentExtensionHeaderIndex);
                    // TODO: Fix according to https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9996
                    return false;

                case "ipv6.src_sa_mac":
                case "ipv6.dst_sa_mac":
                case "ipv6.sa_mac":
                case "ipv6.dst_6to4_gw_ipv4":
                case "ipv6.dst_6to4_sla_id":
                    // TODO: Understand how these are calculated.
                    break;

                case "":
                    switch (field.Show())
                    {
                        case "Fragmentation Header":
                            if (_currentExtensionHeaderIndex >= ipV6Datagram.ExtensionHeaders.Headers.Count && !ipV6Datagram.IsValid)
                                return false;
                            IpV6ExtensionHeaderFragmentData fragmentData =
                                (IpV6ExtensionHeaderFragmentData)ipV6Datagram.ExtensionHeaders[_currentExtensionHeaderIndex];
                            IncrementCurrentExtensionHeaderIndex(ipV6Datagram);
                            foreach (var headerField in field.Fields())
                            {
                                switch (headerField.Name())
                                {
                                    case "ipv6.fragment.nxt":
                                        headerField.AssertValue((byte)fragmentData.NextHeader.Value);
                                        break;

                                    case "ipv6.fragment.offset":
                                        headerField.AssertShowDecimal(fragmentData.FragmentOffset);
                                        break;

                                    case "ipv6.fragment.more":
                                        headerField.AssertShowDecimal(fragmentData.MoreFragments);
                                        break;

                                    case "ipv6.fragment.id":
                                        headerField.AssertShowDecimal(fragmentData.Identification);
                                        break;

                                    case "ipv6.fragment.reserved_octet":
                                    case "ipv6.fragment.reserved_bits":
                                        headerField.AssertShowDecimal(0);
                                        break;

                                    default:
                                        throw new InvalidOperationException("Invalid ipv6 fragmentation field " + headerField.Name());
                                }
                            }
                            break;

                        default:
                            throw new InvalidOperationException(string.Format("Invalid ipv6 field {0}", field.Show()));
                    }
                    break;

                default:
                    throw new InvalidOperationException(string.Format("Invalid ipv6 field {0}", field.Name()));
            }

            return true;
        }
コード例 #18
0
        protected override bool CompareField(XElement field, Datagram datagram)
        {
            field.AssertNoFields();
            ArpDatagram arpDatagram = (ArpDatagram)datagram;
            switch (field.Name())
            {
                case "arp.hw.type":
                    field.AssertShowDecimal((ushort)arpDatagram.HardwareType);
                    break;

                case "arp.proto.type":
                    field.AssertShowDecimal((ushort)arpDatagram.ProtocolType);
                    break;

                case "arp.hw.size":
                    field.AssertShowDecimal(arpDatagram.HardwareLength);
                    break;

                case "arp.proto.size":
                    field.AssertShowDecimal(arpDatagram.ProtocolLength);
                    break;

                case "arp.opcode":
                    field.AssertShowDecimal((ushort)arpDatagram.Operation);
                    break;

                case "arp.src.hw":
                case "arp.src.hw_mac":
                    field.AssertShow(arpDatagram.SenderHardwareAddress);
                    break;

                case "arp.src.proto":
                    field.AssertShow(arpDatagram.SenderProtocolAddress);
                    break;

                case "arp.src.proto_ipv4":
                    field.AssertShow(arpDatagram.SenderProtocolIpV4Address.ToString());
                    break;

                case "arp.dst.hw":
                case "arp.dst.hw_mac":
                    field.AssertShow(arpDatagram.TargetHardwareAddress);
                    break;

                case "arp.dst.proto":
                    field.AssertShow(arpDatagram.TargetProtocolAddress);
                    break;

                case "arp.dst.proto_ipv4":
                    field.AssertShow(arpDatagram.TargetProtocolIpV4Address.ToString());
                    break;

                case "arp.isgratuitous":
                case "arp.dst.drarp_error_status":
                    // TODO: Support DRARP (RFC 1931).
                    break;

                default:
                    throw new InvalidOperationException("Invalid arp field " + field.Name());
            }

            return true;
        }
コード例 #19
0
        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());
            }

            return true;
        }
コード例 #20
0
 protected virtual bool Ignore(Datagram datagram)
 {
     return false;
 }
コード例 #21
0
        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);
                    break;

                case "igmp.reply.pending":
                    field.AssertShowDecimal(igmpDatagram.RetryInThisManySeconds);
                    break;

                case "igmp.group_type":
                    field.AssertShowDecimal((byte)igmpDatagram.CreateGroupRequestCode);
                    break;

                case "igmp.mtrace.max_hops":
                case "igmp.mtrace.saddr":
                case "igmp.mtrace.raddr":
                case "igmp.mtrace.rspaddr":
                case "igmp.mtrace.resp_ttl":
                case "igmp.mtrace.q_id":
                    // todo support IGMP traceroute http://www.ietf.org/proceedings/48/I-D/idmr-traceroute-ipm-07.txt.
                    Assert.IsTrue(new[] { IgmpMessageType.MulticastTraceRouteResponse, IgmpMessageType.MulticastTraceRoute }.Contains(igmpDatagram.MessageType));
                    break;

                default:
                    throw new InvalidOperationException("Invalid igmp field " + field.Name());
            }

            return true;
        }
コード例 #22
0
 protected abstract bool CompareField(XElement field, Datagram datagram);
コード例 #23
0
        protected override bool CompareField(XElement field, Datagram datagram)
        {
            IpV4Datagram ipV4Datagram = (IpV4Datagram)datagram;
            switch (field.Name())
            {
                case "ip.version":
                    field.AssertShowDecimal(ipV4Datagram.Version);
                    field.AssertNoFields();
                    break;

                case "ip.hdr_len":
                    field.AssertShowDecimal(ipV4Datagram.HeaderLength);
                    field.AssertNoFields();
                    break;

                case "ip.dsfield":
                    field.AssertShowDecimal((int)ipV4Datagram.TypeOfService);
                    // TODO: Parse TypeOfService to Differentiated Services and ECN.
                    break;

                case "ip.len":
                    field.AssertShowDecimal(ipV4Datagram.TotalLength);
                    field.AssertNoFields();
                    break;

                case "ip.id":
                    field.AssertShowDecimal(ipV4Datagram.Identification);
                    field.AssertNoFields();
                    break;

                case "ip.flags":
                    field.AssertShowDecimal(((ushort)ipV4Datagram.Fragmentation.Options >> 13));
                    foreach (XElement subfield in field.Fields())
                    {
                        subfield.AssertNoFields();
                        switch (subfield.Name())
                        {
                            case "ip.flags.rb":
                                break;

                            case "ip.flags.df":
                                subfield.AssertShowDecimal((ipV4Datagram.Fragmentation.Options & IpV4FragmentationOptions.DoNotFragment) ==
                                                           IpV4FragmentationOptions.DoNotFragment);
                                break;

                            case "ip.flags.mf":
                                subfield.AssertShowDecimal((ipV4Datagram.Fragmentation.Options & IpV4FragmentationOptions.MoreFragments) ==
                                                           IpV4FragmentationOptions.MoreFragments);
                                break;

                            default:
                                throw new InvalidOperationException(string.Format("Invalid ip flags subfield {0}", subfield.Name()));
                        }
                    }
                    break;

                case "ip.frag_offset":
                    field.AssertShowDecimal(ipV4Datagram.Fragmentation.Offset);
                    field.AssertNoFields();
                    break;

                case "ip.ttl":
                    field.AssertShowDecimal(ipV4Datagram.Ttl);
                    foreach (XElement subfield in field.Fields())
                    {
                        switch (subfield.Name())
                        {
                            case "_ws.expert":
                                break;

                            default:
                                subfield.AssertNoFields();
                                throw new InvalidOperationException(string.Format("Invalid ip subfield {0}", subfield.Name()));
                        }
                    }
                    break;

                case "ip.proto":
                    field.AssertShowDecimal((byte)ipV4Datagram.Protocol);
                    field.AssertNoFields();
                    break;

                case "ip.checksum":
                    field.AssertShowDecimal(ipV4Datagram.HeaderChecksum);
                    if (field.Showname().EndsWith(" [not all data available]"))
                    {
                        Assert.IsFalse(ipV4Datagram.IsValid);
                        break;
                    }
                    foreach (var checksumField in field.Fields())
                    {
                        switch (checksumField.Name())
                        {
                            case "ip.checksum_good":
                                checksumField.AssertNoFields();
                                // TODO: Remove this case when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10579 is fixed.
                                if (field.Showname().EndsWith(" [in ICMP error packet]"))
                                    break;
                                checksumField.AssertShowDecimal(ipV4Datagram.IsHeaderChecksumCorrect);
                                break;

                            case "ip.checksum_bad":
                                if (ipV4Datagram.Length < IpV4Datagram.HeaderMinimumLength ||
                                    ipV4Datagram.Length < ipV4Datagram.HeaderLength ||
                                    // TODO: Remove this case when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10579 is fixed.
                                    field.Showname().EndsWith(" [in ICMP error packet]"))
                                    break;

                                checksumField.AssertShowDecimal(!ipV4Datagram.IsHeaderChecksumCorrect);
                                break;
                        }
                    }
                    break;

                case "ip.src":
                case "ip.src_host":
                    field.AssertShow(ipV4Datagram.Source.ToString());
                    field.AssertNoFields();
                    break;

                case "ip.dst":
                case "ip.dst_host":
                    // TODO: Remove this condition when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10959 is fixed or (worst case) when MTU Reply and CommercialSecurity options are supported.
                    if (ipV4Datagram.Options == null || !ipV4Datagram.Options.Any(option => option.OptionType == IpV4OptionType.MaximumTransmissionUnitReply ||
                                                                                            option.OptionType == IpV4OptionType.CommercialSecurity))
                    {
                        field.AssertShow(ipV4Datagram.Destination.ToString());
                    }
                    field.AssertNoFields();
                    break;

                case "ip.addr":
                case "ip.host":
                    // TODO: Remove this condition when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10959 is fixed or (worst case) when MTU Reply and CommercialSecurity options are supported.
                    if (ipV4Datagram.Options == null || !ipV4Datagram.Options.Any(option => option.OptionType == IpV4OptionType.MaximumTransmissionUnitReply ||
                                                                                            option.OptionType == IpV4OptionType.CommercialSecurity))
                    {
                        Assert.IsTrue(field.Show() == ipV4Datagram.Source.ToString() ||
                                      field.Show() == ipV4Datagram.Destination.ToString());
                    }
                    field.AssertNoFields();
                    break;

                case "ip.cur_rt":
                case "ip.cur_rt_host":
                    field.AssertShow(ipV4Datagram.CurrentDestination.ToString());
                    break;

                case "":
                    CompareIpV4Options(field, ipV4Datagram, ipV4Datagram.Options);
                    break;

                default:
                    throw new InvalidOperationException(string.Format("Invalid ip field {0}", field.Name()));
            }

            return true;
        }
コード例 #24
0
        protected override bool CompareField(XElement field, Datagram datagram)
        {
            IpV6Datagram ipV6Datagram = datagram as IpV6Datagram;
            if (ipV6Datagram == null)
                return true;
            if (ipV6Datagram.NextHeader == IpV4Protocol.Cftp ||
                ipV6Datagram.ExtensionHeaders.Any(extensionHeader => extensionHeader.NextHeader == IpV4Protocol.Cftp))
                return false;
            // TODO: Remove after https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9996 is fixed.
            if (ipV6Datagram.ExtensionHeaders.Select(extensionHeader => extensionHeader.NextHeader).Concat(ipV6Datagram.NextHeader).Any(
                protocol => protocol == IpV4Protocol.WidebandMonitoring ||
                            protocol == IpV4Protocol.SunNetworkDisk ||
                            protocol == IpV4Protocol.Swipe ||
                            protocol == IpV4Protocol.AnyHostInternal ||
                            protocol == IpV4Protocol.SourceDemandRoutingProtocol ||
                            protocol == IpV4Protocol.MobileInternetworkingControlProtocol ||
                            protocol == IpV4Protocol.IsoIp ||
                            protocol == IpV4Protocol.Kryptolan ||
                            protocol == IpV4Protocol.LArp ||
                            protocol == IpV4Protocol.SecureVersatileMessageTransactionProtocol ||
                            protocol == IpV4Protocol.WangSpanNetwork ||
                            protocol == IpV4Protocol.Cbt ||
                            protocol == IpV4Protocol.Visa ||
                            protocol == IpV4Protocol.SimpleMessageProtocol ||
                            protocol == IpV4Protocol.InternetPacketCoreUtility ||
                            protocol == IpV4Protocol.BbnRccMonitoring ||
                            protocol == IpV4Protocol.IpIp ||
                            protocol == IpV4Protocol.FibreChannel ||
                            protocol == IpV4Protocol.ServiceSpecificConnectionOrientedProtocolInAMultilinkAndConnectionlessEnvironment ||
                            protocol == IpV4Protocol.SitaraNetworksProtocol ||
                            protocol == IpV4Protocol.Fire ||
                            protocol == IpV4Protocol.Leaf1 ||
                            protocol == IpV4Protocol.IpsilonFlowManagementProtocol ||
                            protocol == IpV4Protocol.CompaqPeer ||
                            protocol == IpV4Protocol.InterDomainPolicyRoutingProtocolControlMessageTransportProtocol ||
                            protocol == IpV4Protocol.BulkDataTransferProtocol ||
                            protocol == IpV4Protocol.SemaphoreCommunicationsSecondProtocol ||
                            protocol == IpV4Protocol.Mobile ||
                            protocol == IpV4Protocol.HostMonitoringProtocol ||
                            protocol == IpV4Protocol.Chaos ||
                            protocol == IpV4Protocol.DiiDataExchange ||
                            protocol == IpV4Protocol.Emcon ||
                            protocol == IpV4Protocol.ThirdPartyConnect ||
                            protocol == IpV4Protocol.Aris ||
                            protocol == IpV4Protocol.NetworkVoice ||
                            protocol == IpV4Protocol.AnyPrivateEncryptionScheme ||
                            protocol == IpV4Protocol.PacketVideoProtocol ||
                            protocol == IpV4Protocol.PacketRadioMeasurement ||
                            protocol == IpV4Protocol.AnyLocalNetwork ||
                            protocol == IpV4Protocol.Qnx ||
                            protocol == IpV4Protocol.Tcf ||
                            protocol == IpV4Protocol.Ttp ||
                            protocol == IpV4Protocol.ScheduleTransferProtocol ||
                            protocol == IpV4Protocol.TransportLayerSecurityProtocol ||
                            protocol == IpV4Protocol.Ax25 ||
                            protocol == IpV4Protocol.CombatRadioTransportProtocol ||
                            protocol == IpV4Protocol.PerformanceTransparencyProtocol ||
                            protocol == IpV4Protocol.IntegratedNetLayerSecurityProtocol ||
                            protocol == IpV4Protocol.DatagramDeliveryProtocol ||
                            protocol == IpV4Protocol.PrivateNetworkToNetworkInterface ||
                            protocol == IpV4Protocol.Pipe ||
                            protocol == IpV4Protocol.BackroomSatMon ||
                            protocol == IpV4Protocol.Iplt ||
                            protocol == IpV4Protocol.Any0HopProtocol ||
                            protocol == IpV4Protocol.Leaf2 ||
                            protocol == IpV4Protocol.InterDomainPolicyRoutingProtocol ||
                            protocol == IpV4Protocol.NationalScienceFoundationNetworkInteriorGatewayProtocol ||
                            protocol == IpV4Protocol.WidebandExpak ||
                            protocol == IpV4Protocol.Uti ||
                            protocol == IpV4Protocol.Multiplexing ||
                            protocol == IpV4Protocol.Il ||
                            protocol == IpV4Protocol.MulticastTransportProtocol ||
                            protocol == IpV4Protocol.AnyDistributedFileSystem ||
                            protocol == IpV4Protocol.InteractiveAgentTransferProtocol ||
                            protocol == IpV4Protocol.InternetPluribusPacketCore ||
                            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);
                            field.AssertNoFields();
                            break;

                        case "Heartbeat":
                            IpV6ExtensionHeaderMobilityHeartbeatMessage heartbeatMessage = (IpV6ExtensionHeaderMobilityHeartbeatMessage)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.hb.u_flag":
                                        subfield.AssertShowDecimal(heartbeatMessage.IsUnsolicitedHeartbeatResponse);
                                        break;

                                    case "mip6.hb.r_flag":
                                        subfield.AssertShowDecimal(heartbeatMessage.IsResponse);
                                        break;

                                    case "mip6.hb.seqnr":
                                        subfield.AssertShowDecimal(heartbeatMessage.SequenceNumber);
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Heartbeat mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Binding Revocation Indication":
                            IpV6ExtensionHeaderMobilityBindingRevocationIndicationMessage bindingRevocationIndicationMessage = (IpV6ExtensionHeaderMobilityBindingRevocationIndicationMessage)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.bri_br.type":
                                        subfield.AssertShowDecimal((byte)bindingRevocationIndicationMessage.BindingRevocationType);
                                        break;

                                    case "mip6.bri_r.trigger":
                                        subfield.AssertShowDecimal((byte)bindingRevocationIndicationMessage.RevocationTrigger);
                                        break;

                                    case "mip6.bri_seqnr":
                                        subfield.AssertShowDecimal(bindingRevocationIndicationMessage.SequenceNumber);
                                        break;

                                    case "mip6.bri_ip":
                                        subfield.AssertShowDecimal(bindingRevocationIndicationMessage.ProxyBinding);
                                        break;

                                    case "mip6.bri_iv":
                                        subfield.AssertShowDecimal(bindingRevocationIndicationMessage.IpV4HomeAddressBindingOnly);
                                        break;

                                    case "mip6.bri_ig":
                                        subfield.AssertShowDecimal(bindingRevocationIndicationMessage.Global);
                                        break;

                                    case "mip6.bri_res":
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Binding Revocation Acknowledgement Message mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Binding Revocation Acknowledge":
                            IpV6ExtensionHeaderMobilityBindingRevocationAcknowledgementMessage bindingRevocationAcknowledgementMessage = (IpV6ExtensionHeaderMobilityBindingRevocationAcknowledgementMessage)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.bri_br.type":
                                        subfield.AssertShowDecimal((byte)bindingRevocationAcknowledgementMessage.BindingRevocationType);
                                        break;

                                    case "mip6.bri_status":
                                        subfield.AssertShowDecimal((byte)bindingRevocationAcknowledgementMessage.Status);
                                        break;

                                    case "mip6.bri_seqnr":
                                        subfield.AssertShowDecimal(bindingRevocationAcknowledgementMessage.SequenceNumber);
                                        break;

                                    case "mip6.bri_ap":
                                        subfield.AssertShowDecimal(bindingRevocationAcknowledgementMessage.ProxyBinding);
                                        break;

                                    case "mip6.bri_av":
                                        subfield.AssertShowDecimal(bindingRevocationAcknowledgementMessage.IpV4HomeAddressBindingOnly);
                                        break;

                                    case "mip6.bri_ag":
                                        subfield.AssertShowDecimal(bindingRevocationAcknowledgementMessage.Global);
                                        break;

                                    case "mip6.bri_res":
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Binding Revocation Acknowledgement Message mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Care-of Test Init":
                            IpV6ExtensionHeaderMobilityCareOfTestInit careOfTestInit = (IpV6ExtensionHeaderMobilityCareOfTestInit)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.coti.cookie":
                                        subfield.AssertShowDecimal(careOfTestInit.CareOfInitCookie);
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Care Of Test Init mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Care-of Test":
                            IpV6ExtensionHeaderMobilityCareOfTest careOfTest = (IpV6ExtensionHeaderMobilityCareOfTest)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.cot.nindex":
                                        subfield.AssertShowDecimal(careOfTest.CareOfNonceIndex);
                                        break;

                                    case "mip6.cot.cookie":
                                        subfield.AssertShowDecimal(careOfTest.CareOfInitCookie);
                                        break;

                                    case "mip6.hot.token":
                                        subfield.AssertShowDecimal(careOfTest.CareOfKeygenToken);
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Care Of Test mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Fast Binding Acknowledgement":
                            IpV6ExtensionHeaderMobilityFastBindingAcknowledgement fastBindingAcknowledgement = (IpV6ExtensionHeaderMobilityFastBindingAcknowledgement)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "fmip6.fback.status":
                                        subfield.AssertShowDecimal((byte)fastBindingAcknowledgement.Status);
                                        break;

                                    case "fmip6.fback.k_flag":
                                        subfield.AssertShowDecimal(fastBindingAcknowledgement.KeyManagementMobilityCapability);
                                        break;

                                    case "fmip6.fback.seqnr":
                                        subfield.AssertShowDecimal(fastBindingAcknowledgement.SequenceNumber);
                                        break;

                                    case "fmip6.fback.lifetime":
                                        subfield.AssertShowDecimal(fastBindingAcknowledgement.Lifetime);
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Fast Binding Acknowledgement mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Binding Error":
                            IpV6ExtensionHeaderMobilityBindingError bindingError = (IpV6ExtensionHeaderMobilityBindingError)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.be.status":
                                        subfield.AssertShowDecimal((byte)bindingError.Status);
                                        break;

                                    case "mip6.be.haddr":
                                        subfield.AssertShow(bindingError.HomeAddress.ToString("x"));
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Binding Error mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Fast Neighbor Advertisement":
                            Assert.AreEqual(IpV6MobilityHeaderType.FastNeighborAdvertisement, mobilityHeader.MobilityHeaderType);
                            field.AssertNoFields();
                            break;

                        case "Home Test":
                            IpV6ExtensionHeaderMobilityHomeTest homeTest = (IpV6ExtensionHeaderMobilityHomeTest)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.hot.nindex":
                                        subfield.AssertShowDecimal(homeTest.HomeNonceIndex);
                                        break;

                                    case "mip6.hot.cookie":
                                        subfield.AssertShowDecimal(homeTest.HomeInitCookie);
                                        break;

                                    case "mip6.hot.token":
                                        subfield.AssertShowDecimal(homeTest.HomeKeygenToken);
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Home Test mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Home Test Init":
                            IpV6ExtensionHeaderMobilityHomeTestInit homeTestInit = (IpV6ExtensionHeaderMobilityHomeTestInit)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.hoti.cookie":
                                        subfield.AssertShowDecimal(homeTestInit.HomeInitCookie);
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Home Test Init mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Binding Update":
                            IpV6ExtensionHeaderMobilityBindingUpdate bindingUpdate = (IpV6ExtensionHeaderMobilityBindingUpdate)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.bu.seqnr":
                                        subfield.AssertShowDecimal(bindingUpdate.SequenceNumber);
                                        break;

                                    case "mip6.bu.a_flag":
                                        subfield.AssertShowDecimal(bindingUpdate.Acknowledge);
                                        break;

                                    case "mip6.bu.h_flag":
                                        subfield.AssertShowDecimal(bindingUpdate.HomeRegistration);
                                        break;

                                    case "mip6.bu.l_flag":
                                        subfield.AssertShowDecimal(bindingUpdate.LinkLocalAddressCompatibility);
                                        break;

                                    case "mip6.bu.k_flag":
                                        subfield.AssertShowDecimal(bindingUpdate.KeyManagementMobilityCapability);
                                        break;

                                    case "mip6.bu.m_flag":
                                        subfield.AssertShowDecimal(bindingUpdate.MapRegistration);
                                        break;

                                    case "mip6.nemo.bu.r_flag":
                                        subfield.AssertShowDecimal(bindingUpdate.MobileRouter);
                                        break;

                                    case "mip6.bu.p_flag":
                                        subfield.AssertShowDecimal(bindingUpdate.ProxyRegistration);
                                        break;

                                    case "mip6.bu.f_flag":
                                        subfield.AssertShowDecimal(bindingUpdate.ForcingUdpEncapsulation);
                                        break;

                                    case "mip6.bu.t_flag":
                                        subfield.AssertShowDecimal(bindingUpdate.TypeLengthValueHeaderFormat);
                                        break;

                                    case "mip6.bu.b_flag":
                                        subfield.AssertShowDecimal(bindingUpdate.BulkBindingUpdate);
                                        break;

                                    case "mip6.bu.lifetime":
                                        subfield.AssertShowDecimal(bindingUpdate.Lifetime);
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Binding Update mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Binding Acknowledgement":
                            IpV6ExtensionHeaderMobilityBindingAcknowledgement bindingAcknowledgement = (IpV6ExtensionHeaderMobilityBindingAcknowledgement)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.ba.status":
                                        subfield.AssertShowDecimal((byte)bindingAcknowledgement.Status);
                                        break;

                                    case "mip6.ba.k_flag":
                                        subfield.AssertShowDecimal(bindingAcknowledgement.KeyManagementMobilityCapability);
                                        break;

                                    case "mip6.nemo.ba.r_flag":
                                        subfield.AssertShowDecimal(bindingAcknowledgement.MobileRouter);
                                        break;

                                    case "mip6.ba.p_flag":
                                        subfield.AssertShowDecimal(bindingAcknowledgement.ProxyRegistration);
                                        break;

                                    case "mip6.ba.t_flag":
                                        subfield.AssertShowDecimal(bindingAcknowledgement.TypeLengthValueHeaderFormat);
                                        break;

                                    case "mip6.ba.b_flag":
                                        // TODO: Support Bulk Binding Update Support for Proxy Mobile IPv6 (RFC 6602).
                                        break;

                                    case "mip6.ba.seqnr":
                                        subfield.AssertShowDecimal(bindingAcknowledgement.SequenceNumber);
                                        break;

                                    case "mip6.ba.lifetime":
                                        subfield.AssertShowDecimal(bindingAcknowledgement.Lifetime);
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Binding Acknowledgement mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Fast Binding Update":
                            IpV6ExtensionHeaderMobilityFastBindingUpdate fastBindingUpdate = (IpV6ExtensionHeaderMobilityFastBindingUpdate)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "fmip6.fbu.seqnr":
                                        subfield.AssertShowDecimal(fastBindingUpdate.SequenceNumber);
                                        break;

                                    case "fmip6.fbu.a_flag":
                                        subfield.AssertShowDecimal(fastBindingUpdate.Acknowledge);
                                        break;

                                    case "fmip6.fbu.h_flag":
                                        subfield.AssertShowDecimal(fastBindingUpdate.HomeRegistration);
                                        break;

                                    case "fmip6.fbu.l_flag":
                                        subfield.AssertShowDecimal(fastBindingUpdate.LinkLocalAddressCompatibility);
                                        break;

                                    case "fmip6.fbu.k_flag":
                                        subfield.AssertShowDecimal(fastBindingUpdate.KeyManagementMobilityCapability);
                                        break;

                                    case "fmip6.fbu.lifetime":
                                        subfield.AssertShowDecimal(fastBindingUpdate.Lifetime);
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Fast Binding Update mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Handover Acknowledge ":
                            var handoverAcknowledgeMessage = (IpV6ExtensionHeaderMobilityHandoverAcknowledgeMessage)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.hack.seqnr":
                                        subfield.AssertShowDecimal(handoverAcknowledgeMessage.SequenceNumber);
                                        break;

                                    case "mip6.hack.code":
                                        subfield.AssertShowDecimal((byte)handoverAcknowledgeMessage.Code);
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Handover Acknowledge mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Handover Initiate":
                            var handoverInitiateMessage = (IpV6ExtensionHeaderMobilityHandoverInitiateMessage)mobilityHeader;
                            foreach (XElement subfield in field.Fields())
                            {
                                subfield.AssertNoFields();
                                switch (subfield.Name())
                                {
                                    case "mip6.hi.seqnr":
                                        subfield.AssertShowDecimal(handoverInitiateMessage.SequenceNumber);
                                        break;

                                    case "mip6.hi.s_flag":
                                        subfield.AssertShowDecimal(handoverInitiateMessage.AssignedAddressConfiguration);
                                        break;

                                    case "mip6.hi.u_flag":
                                        subfield.AssertShowDecimal(handoverInitiateMessage.Buffer);
                                        break;

                                    case "mip6.hi.code":
                                        subfield.AssertShowDecimal((byte)handoverInitiateMessage.Code);
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid IPv6 mobility header field {0}", subfield.Name()));
                                }
                            }
                            break;

                        case "Mobility Options":
                            int optionIndex = 0;
                            foreach (XElement optionField in field.Fields())
                            {
                                IpV6MobilityOption option = mobilityHeader.MobilityOptions[optionIndex];
                                switch (optionField.Name())
                                {
                                    case "":
                                        switch (option.OptionType)
                                        {
                                            case IpV6MobilityOptionType.LinkLayerAddress:
                                                optionField.AssertShow("Mobility Header Link-Layer Address");
                                                IpV6MobilityOptionLinkLayerAddress linkLayerAddress = (IpV6MobilityOptionLinkLayerAddress)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "":
                                                            optionSubfield.AssertShow("Mobility Header Link-Layer Address option");
                                                            foreach (XElement optionSubsubfield in optionSubfield.Fields())
                                                            {
                                                                if (HandleCommonMobilityOptionSubfield(optionSubsubfield, option))
                                                                    continue;

                                                                switch (optionSubsubfield.Name())
                                                                {
                                                                    case "mip6.lla.optcode":
                                                                        optionSubsubfield.AssertShowDecimal((byte)linkLayerAddress.Code);
                                                                        break;

                                                                    case "":
                                                                        // TODO: Uncomment when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10627 is fixed.
//                                                                        optionSubsubfield.AssertValue(linkLayerAddress.LinkLayerAddress);
                                                                        break;

                                                                    default:
                                                                        throw new InvalidOperationException(string.Format(
                                                                            "Invalid IPv6 Link Layer Address option subfield {0}", optionSubsubfield.Name()));
                                                                }
                                                            }
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format(
                                                                "Invalid IPv6 Link Layer Address option field {0}", optionSubfield.Name()));
                                                    }
                                                }
                                                // TODO: Change to break when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10627 is fixed.
                                                return false;

                                            case IpV6MobilityOptionType.IpV4DefaultRouterAddress:
                                                var ipV4DefaultRouterAddress = (IpV6MobilityOptionIpV4DefaultRouterAddress)option;
                                                optionField.AssertShow("IPv4 Default-Router Address: " + ipV4DefaultRouterAddress.DefaultRouterAddress);
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;
                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.ipv4dra.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mip6.ipv4dra.dra":
                                                            optionSubfield.AssertShow(ipV4DefaultRouterAddress.DefaultRouterAddress.ToString());
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(
                                                                string.Format("Invalid IPv6 IPv4 Default Router Address option field {0}", optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.Pad1:
                                                optionField.AssertShow("Pad1");
                                                optionField.AssertNoFields();
                                                break;

                                            case IpV6MobilityOptionType.PadN:
                                                if (optionField.Show() != "PadN" && optionIndex == mobilityHeader.MobilityOptions.Count - 1)
                                                {
                                                    Assert.IsFalse(mobilityHeader.IsValid);
                                                    return true;
                                                }
                                                optionField.AssertShow("PadN");
                                                IpV6MobilityOptionPadN padN = (IpV6MobilityOptionPadN)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;
                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "":
                                                            optionSubfield.AssertShow(string.Format("PadN: {0} bytes", padN.PaddingDataLength));
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.IpV4HomeAddressReply:
                                                IpV6MobilityOptionIpV4HomeAddressReply ipV4HomeAddressReply = (IpV6MobilityOptionIpV4HomeAddressReply)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;
                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.ipv4aa.sts":
                                                            optionSubfield.AssertShowDecimal((byte)ipV4HomeAddressReply.Status);
                                                            break;

                                                        default:
                                                            ValidateIpV6MobilityOptionIpV4HomeAddressField(optionSubfield, ipV4HomeAddressReply);
                                                            break;
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.IpV4HomeAddressRequest:
                                                var ipV4HomeAddressRequest = (IpV6MobilityOptionIpV4HomeAddressRequest)option;
                                                optionField.AssertShow("IPv4 Home Address Request: " + ipV4HomeAddressRequest.HomeAddress);
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    ValidateIpV6MobilityOptionIpV4HomeAddressField(optionSubfield, ipV4HomeAddressRequest);
                                                }
                                                break;

                                            case IpV6MobilityOptionType.IpV4AddressAcknowledgement:
                                                optionField.AssertShow("IPv4 Address Acknowledgement");
                                                var ipV4AddressAcknowledgement = (IpV6MobilityOptionIpV4AddressAcknowledgement)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "":
                                                            optionSubfield.AssertShow("IPv4 Address Acknowledgement");
                                                            foreach (XElement optionSubsubfield in optionSubfield.Fields())
                                                            {
                                                                optionSubsubfield.AssertNoFields();
                                                                switch (optionSubsubfield.Name())
                                                                {
                                                                    case "mip6.ipv4aa.sts":
                                                                        optionSubsubfield.AssertShowDecimal((byte)ipV4AddressAcknowledgement.Status);
                                                                        break;

                                                                    default:
                                                                        ValidateIpV6MobilityOptionIpV4HomeAddressField(optionSubsubfield, ipV4AddressAcknowledgement);
                                                                        break;
                                                                }
                                                            }
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.MobileNetworkPrefix:
                                                optionField.AssertShow("Mobile Network Prefix");
                                                var mobileNetworkPrefix = (IpV6MobilityOptionMobileNetworkPrefix)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "":
                                                            optionSubfield.AssertShow("Mobile Network Prefix");
                                                            foreach (XElement optionSubsubfield in optionSubfield.Fields())
                                                            {
                                                                optionSubsubfield.AssertNoFields();
                                                                switch (optionSubsubfield.Name())
                                                                {
                                                                    case "mip6.nemo.mnp.mnp":
                                                                        optionSubsubfield.AssertShow(mobileNetworkPrefix.NetworkPrefix.ToString("x"));
                                                                        break;

                                                                    default:
                                                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subsubfield {0}",
                                                                                                                          optionSubsubfield.Name()));
                                                                }
                                                            }
                                                            break;

                                                        case "mip6.nemo.mnp.pfl":
                                                            optionSubfield.AssertNoFields();
                                                            optionSubfield.AssertShowDecimal(mobileNetworkPrefix.PrefixLength);
                                                            break;

                                                        default:
                                                            optionSubfield.AssertNoFields();
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.HomeNetworkPrefix:
                                                optionField.AssertShow("Home Network Prefix");
                                                var homeNetworkPrefix = (IpV6MobilityOptionHomeNetworkPrefix)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "":
                                                            optionSubfield.AssertShow("Home Network Prefix");
                                                            foreach (XElement optionSubsubfield in optionSubfield.Fields())
                                                            {
                                                                switch (optionSubsubfield.Name())
                                                                {
                                                                    case "mip6.nemo.mnp.mnp":
                                                                        optionSubsubfield.AssertShow(homeNetworkPrefix.NetworkPrefix.ToString("x"));
                                                                        break;

                                                                    default:
                                                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Network Prefix option subfield {0}", optionSubsubfield.Name()));
                                                                }
                                                            }
                                                            break;

                                                        case "mip6.nemo.mnp.pfl":
                                                            optionSubfield.AssertShowDecimal(homeNetworkPrefix.PrefixLength);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Network Prefix option field {0}", optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.VendorSpecific:
                                                Assert.IsTrue(optionField.Show().StartsWith("Vendor Specific: "));
                                                IpV6MobilityOptionVendorSpecific vendorSpecific = (IpV6MobilityOptionVendorSpecific)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;
                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.vsm.vendorId":
                                                            optionSubfield.AssertShowDecimal(vendorSpecific.VendorId);
                                                            break;

                                                        case "mip6.vsm.subtype":
                                                            optionSubfield.AssertShowDecimal(vendorSpecific.Subtype);
                                                            break;

                                                        case "":
                                                            optionSubfield.AssertValue(vendorSpecific.Data);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Vendor Specific option field {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.NonceIndexes:
                                                optionField.AssertShow("Nonce Indices");
                                                IpV6MobilityOptionNonceIndexes nonceIndexes = (IpV6MobilityOptionNonceIndexes)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "":
                                                            optionSubfield.AssertShow("Nonce Indices");
                                                            foreach (XElement optionSubsubfield in optionSubfield.Fields())
                                                            {
                                                                optionSubsubfield.AssertNoFields();
                                                                switch (optionSubsubfield.Name())
                                                                {
                                                                    case "mip6.ni.hni":
                                                                        optionSubsubfield.AssertShowDecimal(nonceIndexes.HomeNonceIndex);
                                                                        break;

                                                                    case "mip6.ni.cni":
                                                                        optionSubsubfield.AssertShowDecimal(nonceIndexes.CareOfNonceIndex);
                                                                        break;

                                                                    default:
                                                                        throw new InvalidOperationException(string.Format("Invalid IPv6 Nonce Indices option subfield {0}",
                                                                                                                          optionSubsubfield.Name()));
                                                                }
                                                            }
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Nonce Indices option field {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.LinkLocalAddress:
                                                optionField.AssertShow("Link-local Address");
                                                IpV6MobilityOptionLinkLocalAddress linkLocalAddress = (IpV6MobilityOptionLinkLocalAddress)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "":
                                                            optionSubfield.AssertShow("Link-local Address");
                                                            foreach (XElement optionSubsubfield in optionSubfield.Fields())
                                                            {
                                                                optionSubsubfield.AssertNoFields();
                                                                switch (optionSubsubfield.Name())
                                                                {
                                                                    case "mip6.lila_lla":
                                                                        optionSubsubfield.AssertShow(linkLocalAddress.LinkLocalAddress.ToString("x"));
                                                                        break;

                                                                    default:
                                                                        throw new InvalidOperationException(string.Format(
                                                                            "Invalid IPv6 Link-local Address option field {0}", optionSubsubfield.Name()));
                                                                }
                                                            }
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format(
                                                                "Invalid IPv6 Link-local Address option field {0}", optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.MobileNodeIdentifier:
                                                Assert.IsTrue(optionField.Show().StartsWith("Mobile Node Identifier"));
                                                IpV6MobilityOptionMobileNodeIdentifier mobileNodeIdentifier = (IpV6MobilityOptionMobileNodeIdentifier)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.mnid.subtype":
                                                            optionSubfield.AssertShowDecimal((byte)mobileNodeIdentifier.Subtype);
                                                            break;

                                                        case "":
                                                            optionSubfield.AssertValue(mobileNodeIdentifier.Identifier);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(
                                                                string.Format("Invalid IPv6 Mobile Node Identifier option field {0}", optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.BindingAuthorizationData:
                                                optionField.AssertShow("Authorization Data");
                                                IpV6MobilityOptionBindingAuthorizationData authorizationData =
                                                    (IpV6MobilityOptionBindingAuthorizationData)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "":
                                                            foreach (XElement authSubfield in optionSubfield.Fields())
                                                            {
                                                                switch (authSubfield.Name())
                                                                {
                                                                    case "mip6.bad.auth":
                                                                        authSubfield.AssertValue(authorizationData.Authenticator);
                                                                        break;

                                                                    default:
                                                                        throw new InvalidOperationException(
                                                                            string.Format("Invalid IPv6 Authorization Data option subfield {0}",
                                                                                          authSubfield.Name()));
                                                                }
                                                            }
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format(
                                                                "Invalid IPv6 Authorization Data option field {0}", optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.IpV4HomeAddress:
                                                optionField.AssertShow("IPv4 Home Address");
                                                IpV6MobilityOptionIpV4HomeAddress ipV4HomeAddress = (IpV6MobilityOptionIpV4HomeAddress)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "":
                                                            foreach (XElement optionSubsubfield in optionSubfield.Fields())
                                                            {
                                                                optionSubsubfield.AssertNoFields();
                                                                switch (optionSubsubfield.Name())
                                                                {
                                                                    case "mip6.ipv4ha.p_flag":
                                                                        optionSubsubfield.AssertShowDecimal(ipV4HomeAddress.RequestPrefix);
                                                                        break;

                                                                    default:
                                                                        ValidateIpV6MobilityOptionIpV4HomeAddressField(optionSubsubfield, ipV4HomeAddress);
                                                                        break;
                                                                }
                                                            }
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format(
                                                                "Invalid IPv6 Authorization Data option field {0}", optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.ServiceSelection:
                                                IpV6MobilityOptionServiceSelection serviceSelection = (IpV6MobilityOptionServiceSelection)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;
                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.ss.identifier":
                                                            optionSubfield.AssertValue(serviceSelection.Identifier);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.RedirectCapability:
                                                IpV6MobilityOptionRedirectCapability redirectCapability = (IpV6MobilityOptionRedirectCapability)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;
                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.recap.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.BindingIdentifier:
                                                IpV6MobilityOptionBindingIdentifier bindingIdentifier = (IpV6MobilityOptionBindingIdentifier)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;
                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.bi.bid":
                                                            optionSubfield.AssertShowDecimal(bindingIdentifier.BindingId);
                                                            break;

                                                        case "mip6.bi.status":
                                                            optionSubfield.AssertShowDecimal((byte)bindingIdentifier.Status);
                                                            break;

                                                        case "mip6.bi.h_flag":
                                                            optionSubfield.AssertShowDecimal(bindingIdentifier.SimultaneousHomeAndForeignBinding);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.LoadInformation:
                                                IpV6MobilityOptionLoadInformation loadInformation = (IpV6MobilityOptionLoadInformation)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.load_inf.priority":
                                                            optionSubfield.AssertShowDecimal(loadInformation.Priority);
                                                            break;

                                                        case "mip6.load_inf.sessions_in_use":
                                                            optionSubfield.AssertShowDecimal(loadInformation.SessionsInUse);
                                                            break;

                                                        case "mip6.load_inf.maximum_sessions":
                                                            optionSubfield.AssertShowDecimal(loadInformation.MaximumSessions);
                                                            break;

                                                        case "mip6.load_inf.used_capacity":
                                                            optionSubfield.AssertShowDecimal(loadInformation.UsedCapacity);
                                                            break;

                                                        case "mip6.load_inf.maximum_capacity":
                                                            optionSubfield.AssertShowDecimal(loadInformation.MaximumCapacity);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.IpV4CareOfAddress:
                                                IpV6MobilityOptionIpV4CareOfAddress ipV4CareOfAddress = (IpV6MobilityOptionIpV4CareOfAddress)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.ipv4coa.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mip6.ipv4coa.addr":
                                                            optionSubfield.AssertShow(ipV4CareOfAddress.CareOfAddress.ToString());
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.CryptographicallyGeneratedAddressParametersRequest:
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.IpV6AddressPrefix:
                                                var ipV6AddressPrefix = (IpV6MobilityOptionIpV6AddressPrefix)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.mhipv6ap.opt_code":
                                                            optionSubfield.AssertShowDecimal((byte)ipV6AddressPrefix.Code);
                                                            break;

                                                        case "mip6.mhipv6ap.len":
                                                            optionSubfield.AssertShowDecimal(ipV6AddressPrefix.PrefixLength);
                                                            break;

                                                        case "mip6.mhipv6ap.ipv6_address":
                                                            optionSubfield.AssertValue(ipV6AddressPrefix.AddressOrPrefix.ToValue());
                                                            break;

                                                        case "mip6.mhipv6ap.ipv6_address_prefix":
                                                            Assert.IsTrue(optionSubfield.Value().EndsWith(ipV6AddressPrefix.AddressOrPrefix.ToValue().ToString("x32")));
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.MobileNodeGroupIdentifier:
                                                var mobileNodeGroupIdentifier = (IpV6MobilityOptionMobileNodeGroupIdentifier)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.mng.sub_type":
                                                            optionSubfield.AssertShowDecimal((byte)mobileNodeGroupIdentifier.Subtype);
                                                            break;

                                                        case "mip6.mng.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mip6.mng._mng_id":
                                                            optionSubfield.AssertShowDecimal(mobileNodeGroupIdentifier.MobileNodeGroupIdentifier);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.BindingAuthorizationDataForFmIpV6:
                                                var bindingAuthorizationDataForFmIpV6 = (IpV6MobilityOptionBindingAuthorizationDataForFmIpV6)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.badff.spi":
                                                            optionSubfield.AssertShowDecimal(bindingAuthorizationDataForFmIpV6.SecurityParameterIndex);
                                                            break;

                                                        case "mip6.badff.auth":
                                                            optionSubfield.AssertValue(bindingAuthorizationDataForFmIpV6.Authenticator);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.MobileNodeLinkLayerIdentifier:
                                                var mobileNodeLinkLayerIdentifier = (IpV6MobilityOptionMobileNodeLinkLayerIdentifier)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.mnlli.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mip6.mnlli.lli":
                                                            optionSubfield.AssertValue(mobileNodeLinkLayerIdentifier.LinkLayerIdentifier);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.AccessTechnologyType:
                                                var accessTechnologyType = (IpV6MobilityOptionAccessTechnologyType)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.att.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mip6.att":
                                                            optionSubfield.AssertShowDecimal((byte)accessTechnologyType.AccessTechnologyType);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.AccessNetworkIdentifier:
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "_ws.expert":
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.BindingRefreshAdvice:
                                                var bindingRefreshAdvice = (IpV6MobilityOptionBindingRefreshAdvice)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.bra.interval":
                                                            optionSubfield.AssertShowDecimal(bindingRefreshAdvice.RefreshInterval);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.PermanentHomeKeygenToken:
                                                var permanentHomeKeygenToken = (IpV6MobilityOptionPermanentHomeKeygenToken)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.phkt.phkt":
                                                            optionSubfield.AssertValue(permanentHomeKeygenToken.PermanentHomeKeygenToken);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.Redirect:
                                                var redirect = (IpV6MobilityOptionRedirect)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.redir.k":
                                                            optionSubfield.AssertShowDecimal(redirect.LocalMobilityAddressIpV6 != null);
                                                            break;

                                                        case "mip6.redir.n":
                                                            optionSubfield.AssertShowDecimal(redirect.LocalMobilityAddressIpV4 != null);
                                                            break;

                                                        case "mip6.redir.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mip6.redir.addr_r2lma_ipv4":
                                                            optionSubfield.AssertShow(redirect.LocalMobilityAddressIpV4.ToString());
                                                            break;

                                                        case "mip6.redir.addr_r2lma_ipv6":
                                                            optionSubfield.AssertValue(redirect.LocalMobilityAddressIpV6.Value.ToValue());
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.CareOfTest:
                                                var careOfTestOption = (IpV6MobilityOptionCareOfTest)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.mocot.co_keygen_tok":
                                                            optionSubfield.AssertValue(careOfTestOption.CareOfKeygenToken);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.ReplayProtection:
                                                var replayProtection = (IpV6MobilityOptionReplayProtection)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.mseg_id.timestamp":
                                                            optionSubfield.AssertValue(replayProtection.Timestamp);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.Authentication:
                                                var authentication = (IpV6MobilityOptionAuthentication)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.auth.subtype":
                                                            optionSubfield.AssertShowDecimal((byte)authentication.Subtype);
                                                            break;

                                                        case "mip6.auth.mobility_spi":
                                                            optionSubfield.AssertShowDecimal(authentication.MobilitySecurityParameterIndex);
                                                            break;

                                                        case "mip6.auth.auth_data":
                                                            optionSubfield.AssertValue(authentication.AuthenticationData);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.HandoffIndicator:
                                                var handoffIndicator = (IpV6MobilityOptionHandoffIndicator)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.hi.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mip6.hi":
                                                            optionSubfield.AssertShowDecimal((byte)handoffIndicator.HandoffIndicator);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.IpV4DhcpSupportMode:
                                                var ipV4DhcpSupportMode = (IpV6MobilityOptionIpV4DhcpSupportMode)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.ipv4dsm.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mip6.ipv4dsm.s_flag":
                                                            optionSubfield.AssertShowDecimal(ipV4DhcpSupportMode.IsServer);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.DnsUpdate:
                                                var dnsUpdate = (IpV6MobilityOptionDnsUpdate)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.dnsu.status":
                                                            optionSubfield.AssertShowDecimal((byte)dnsUpdate.Status);
                                                            break;

                                                        case "mip6.dnsu.flag.r":
                                                            optionSubfield.AssertShowDecimal(dnsUpdate.Remove);
                                                            break;

                                                        case "mip6.dnsu.mn_id":
                                                            optionSubfield.AssertValue(dnsUpdate.MobileNodeIdentity);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.LocalMobilityAnchorAddress:
                                                var localMobilityAnchorAddress = (IpV6MobilityOptionLocalMobilityAnchorAddress)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mmip6.lmaa.opt_code":
                                                            optionSubfield.AssertShowDecimal((byte)localMobilityAnchorAddress.Code);
                                                            break;

                                                        case "mmip6.lmaa.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mip6.lmaa.ipv6":
                                                            optionSubfield.AssertValue(localMobilityAnchorAddress.LocalMobilityAnchorAddressIpV6.Value.ToValue());
                                                            break;

                                                        case "mip6.lmaa.ipv4":
                                                            optionSubfield.AssertShow(localMobilityAnchorAddress.LocalMobilityAnchorAddressIpV4.Value.ToString());
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.ContextRequest:
                                                var contextRequest = (IpV6MobilityOptionContextRequest)option;
                                                optionField.AssertShow("Context Request" +
                                                                       (contextRequest.Requests.Any() ? "" : " (with option length = 2 bytes; should be >= 4)"));
                                                int requestIndex = 0;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.cr.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mmip6.cr.req_type":
                                                            optionSubfield.AssertShowDecimal(contextRequest.Requests[requestIndex].RequestType);
                                                            break;

                                                        case "mmip6.cr.req_length":
                                                            optionSubfield.AssertShowDecimal(contextRequest.Requests[requestIndex].OptionLength);
                                                            if (contextRequest.Requests[requestIndex].OptionLength == 0)
                                                                ++requestIndex;
                                                            break;

                                                        case "mip6.vsm.vendorId":
                                                            optionSubfield.AssertValue(contextRequest.Requests[requestIndex].Option.Subsegment(0, 4));
                                                            break;

                                                        case "mip6.vsm.subtype":
                                                            optionSubfield.AssertValue(contextRequest.Requests[requestIndex].Option.Subsegment(4, 1));
                                                            ++requestIndex;
                                                            break;

                                                        case "":
                                                            optionSubfield.AssertValue(contextRequest.Requests[requestIndex].Option);
                                                            ++requestIndex;
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.AlternateIpV4CareOfAddress:
                                                var alternateIpV4CareOfAddress = (IpV6MobilityOptionAlternateIpV4CareOfAddress)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.alt_ip4":
                                                            optionSubfield.AssertShow(alternateIpV4CareOfAddress.AlternateCareOfAddress.ToString());
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.Signature:
                                                var signature = (IpV6MobilityOptionSignature)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.sign.sign":
                                                            optionSubfield.AssertValue(signature.Signature);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.TransientBinding:
                                                optionField.AssertShow("Transient Binding(2 bytes)");
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "_ws.expert":
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.Timestamp:
                                                var timestamp = (IpV6MobilityOptionTimestamp)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.timestamp_tmp":
                                                            optionSubfield.AssertValue(timestamp.Timestamp);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.RestartCounter:
                                                var restartCounter = (IpV6MobilityOptionRestartCounter)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.rc":
                                                            optionSubfield.AssertShowDecimal(restartCounter.RestartCounter);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.CryptographicallyGeneratedAddressParameters:
                                                var cryptographicallyGeneratedAddressParameters = (IpV6MobilityOptionCryptographicallyGeneratedAddressParameters)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.cgar.cga_par":
                                                            optionSubfield.AssertValue(cryptographicallyGeneratedAddressParameters.CryptographicallyGeneratedAddressParameters);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.FlowIdentification:
                                                optionField.AssertShow("Flow Identification(" + (option.Length - 2) + " bytes)");
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "_ws.expert":
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.NatDetection:
                                                optionField.AssertShow("NAT Detection");
                                                var natDetection = (IpV6MobilityOptionNatDetection)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.natd.f_flag":
                                                            optionSubfield.AssertShowDecimal(natDetection.UdpEncapsulationRequired);
                                                            break;

                                                        case "mip6.natd.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mip6.natd.refresh_t":
                                                            optionSubfield.AssertShowDecimal(natDetection.RefreshTime);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.FlowSummary:
                                                optionField.AssertShow("Flow Summary(" + (option.Length - 2) + " bytes)");
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "_ws.expert":
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.Experimental:
                                                optionField.AssertShow("Experimental" +
                                                                       (option.Length == 2 ? " (with option length = 0 bytes; should be >= 1)" : ""));
                                                var experimental = (IpV6MobilityOptionExperimental)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.em.data":
                                                            optionSubfield.AssertValue(experimental.Data);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.MobileAccessGatewayIpV6Address:
                                                optionField.AssertShow("MAG IPv6 Address(18 bytes)");

                                                // TODO: Dedup this code.
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "_ws.expert":
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.CareOfTestInit:
                                                optionField.AssertShow("Care-of Test Init");
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    Assert.IsTrue(HandleCommonMobilityOptionSubfield(optionSubfield, option));
                                                }
                                                break;

                                            case IpV6MobilityOptionType.MobileNodeLinkLocalAddressInterfaceIdentifier:
                                                optionField.AssertShow("Mobile Node Link-local Address Interface Identifier(10 bytes)");

                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "_ws.expert":
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.AlternateCareOfAddress:
                                                optionField.AssertShow("Alternate Care-of Address");
                                                var alternateCareOfAddress = (IpV6MobilityOptionAlternateCareOfAddress)option;
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.acoa.acoa":
                                                            optionSubfield.AssertValue(alternateCareOfAddress.AlternateCareOfAddress.ToValue());
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;

                                            case IpV6MobilityOptionType.GreKey:
                                                var greKey = (IpV6MobilityOptionGreKey)option;
                                                optionField.AssertShow("GRE Key: " + greKey.GreKeyIdentifier);
                                                foreach (XElement optionSubfield in optionField.Fields())
                                                {
                                                    if (HandleCommonMobilityOptionSubfield(optionSubfield, option))
                                                        continue;

                                                    optionSubfield.AssertNoFields();
                                                    switch (optionSubfield.Name())
                                                    {
                                                        case "mip6.ipv4dra.reserved":
                                                            optionSubfield.AssertShowDecimal(0);
                                                            break;

                                                        case "mip6.gre_key":
                                                            optionSubfield.AssertShowDecimal(greKey.GreKeyIdentifier);
                                                            break;

                                                        default:
                                                            throw new InvalidOperationException(string.Format("Invalid IPv6 Mobility option subfield {0}",
                                                                                                              optionSubfield.Name()));
                                                    }
                                                }
                                                break;
                                            default:
                                                throw new InvalidOperationException(string.Format("Unsupported IPv6 mobility option type {0}", option.OptionType));
                                        }
                                        ++optionIndex;
                                        break;

                                    default:
                                        throw new InvalidOperationException(string.Format("Invalid ipv6 mobility header option field {0}", optionField.Name()));
                                }
                            }
                            break;

                        default:
                            field.AssertShow("Unknown MH Type");
                            Assert.IsTrue(mobilityHeader.MobilityHeaderType == IpV6MobilityHeaderType.Experimental ||
                                          mobilityHeader.MobilityHeaderType == IpV6MobilityHeaderType.HomeAgentSwitchMessage ||
                                          mobilityHeader.MobilityHeaderType == IpV6MobilityHeaderType.LocalizedRoutingInitiation ||
                                          mobilityHeader.MobilityHeaderType == IpV6MobilityHeaderType.LocalizedRoutingAcknowledgement);
                            field.AssertNoFields();
                            break;
                    }
                    break;

                default:
                    throw new InvalidOperationException(string.Format("Invalid ipv6 mobility header field {0}", field.Name()));
            }

            return true;
        }
コード例 #25
0
 protected override bool Ignore(Datagram datagram)
 {
     GreDatagram greDatagram = (GreDatagram)datagram;
     return !greDatagram.IsValid ||
            (greDatagram.ProtocolType != EthernetType.PointToPointProtocol ||
             greDatagram.Version != GreVersion.EnhancedGre) &&
            greDatagram.AcknowledgmentSequenceNumberPresent;
 }
コード例 #26
0
		/// <summary>
		/// Format a packet, e.g.
		/// Offset		Byte form				ASCII form
		/// 0000		F3 63 78 A7...			abcd...
		/// </summary>
		/// <param name="packet">Packet to dump</param>
		/// <param name="ctrl">UI control to update</param>
		public static void DumpPacket(Datagram packet, object ctrl)
		{
			int len = packet.Length;
			List<string> lines = new List<string>();
			string line = null;
			int offset = 0;
			const int step = 16;
			MemoryStream ms = packet.ToMemoryStream();

			while (len > 0) {
				int num = len >= step ? step : len;
				byte[] bytes = new byte[num];
				ms.Read(bytes, 0, num);

				line = string.Format("{0:X4}  ", offset);
				string[] hex = ParserHelper.ByteToHexString(bytes);
				line += string.Join(" ", hex);

				// Padding, if byte number is fewer than a line
				if (num < 16) {
					int padding = 16 -num;
					while (padding-- > 0)
						line += "   "; 
				}
				line += "  ";

				line += string.Join("", ParserHelper.EncodeBytes(bytes));
				lines.Add(line);

				offset += num;
				len -= num;
			}

			// Update UI
			TextBox text = (TextBox)ctrl;
			object[] param = new object[2];
			param[0] = ctrl;
			param[1] = lines;
 			text.BeginInvoke(new ParserHelper.UIHandler(ParserHelper.UpdateDumpUI), param);

		}
コード例 #27
0
 protected override bool Ignore(Datagram datagram)
 {
     HttpDatagram httpDatagram = (HttpDatagram)datagram;
     return (httpDatagram.Header != null && httpDatagram.Header.ContentLength != null && httpDatagram.Header.TransferEncoding != null);
 }