internal static IpV6ExtensionHeaderMobility ParseData(IpV4Protocol nextHeader, DataSegment data)
        {
            if (data.Length < MinimumDataLength)
            {
                return(null);
            }

            IpV6MobilityHeaderType mobilityHeaderType = (IpV6MobilityHeaderType)data[DataOffset.MobilityHeaderType];
            ushort      checksum    = data.ReadUShort(DataOffset.Checksum, Endianity.Big);
            DataSegment messageData = data.Subsegment(DataOffset.MessageData, data.Length - DataOffset.MessageData);

            switch (mobilityHeaderType)
            {
            case IpV6MobilityHeaderType.BindingRefreshRequest:     // 0
                return(IpV6ExtensionHeaderMobilityBindingRefreshRequest.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.HomeTestInit:     // 1
                return(IpV6ExtensionHeaderMobilityHomeTestInit.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.CareOfTestInit:     // 2
                return(IpV6ExtensionHeaderMobilityCareOfTestInit.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.HomeTest:     // 3
                return(IpV6ExtensionHeaderMobilityHomeTest.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.CareOfTest:     // 4
                return(IpV6ExtensionHeaderMobilityCareOfTest.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.BindingUpdate:     // 5
                return(IpV6ExtensionHeaderMobilityBindingUpdate.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.BindingAcknowledgement:     // 6
                return(IpV6ExtensionHeaderMobilityBindingAcknowledgement.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.BindingError:     // 7
                return(IpV6ExtensionHeaderMobilityBindingError.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.FastBindingUpdate:     // 8
                return(IpV6ExtensionHeaderMobilityFastBindingUpdate.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.FastBindingAcknowledgement:     // 9
                return(IpV6ExtensionHeaderMobilityFastBindingAcknowledgement.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.FastNeighborAdvertisement:     // 10
                return(IpV6ExtensionHeaderMobilityFastNeighborAdvertisement.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.Experimental:     // 11
                return(IpV6ExtensionHeaderMobilityExperimental.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.HomeAgentSwitchMessage:     // 12
                return(IpV6ExtensionHeaderMobilityHomeAgentSwitchMessage.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.HeartbeatMessage:     // 13
                return(IpV6ExtensionHeaderMobilityHeartbeatMessage.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.HandoverInitiateMessage:     // 14
                return(IpV6ExtensionHeaderMobilityHandoverInitiateMessage.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.HandoverAcknowledgeMessage:     // 15
                return(IpV6ExtensionHeaderMobilityHandoverAcknowledgeMessage.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.BindingRevocationMessage:     // 16
                return(IpV6ExtensionHeaderMobilityBindingRevocationMessage.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.LocalizedRoutingInitiation:     // 17
                return(IpV6ExtensionHeaderMobilityLocalizedRoutingInitiation.ParseMessageData(nextHeader, checksum, messageData));

            case IpV6MobilityHeaderType.LocalizedRoutingAcknowledgement:     // 18
                return(IpV6ExtensionHeaderMobilityLocalizedRoutingAcknowledgement.ParseMessageData(nextHeader, checksum, messageData));

            default:
                return(null);
            }
        }
Esempio n. 2
0
        public static IpV6ExtensionHeaderMobility NextIpV6ExtensionHeaderMobility(this Random random, IpV4Protocol?nextHeader)
        {
            IpV6MobilityHeaderType mobilityHeaderType = random.NextEnum <IpV6MobilityHeaderType>();
            ushort checksum = random.NextUShort();

            switch (mobilityHeaderType)
            {
            case IpV6MobilityHeaderType.BindingRefreshRequest:     // 0
                return(new IpV6ExtensionHeaderMobilityBindingRefreshRequest(nextHeader, checksum, random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.HomeTestInit:     // 1
                return(new IpV6ExtensionHeaderMobilityHomeTestInit(nextHeader, checksum, random.NextULong(), random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.CareOfTestInit:     // 2
                return(new IpV6ExtensionHeaderMobilityCareOfTestInit(nextHeader, checksum, random.NextULong(), random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.HomeTest:     // 3
                return(new IpV6ExtensionHeaderMobilityHomeTest(nextHeader, checksum, random.NextUShort(), random.NextULong(), random.NextULong(),
                                                               random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.CareOfTest:     // 4
                return(new IpV6ExtensionHeaderMobilityCareOfTest(nextHeader, checksum, random.NextUShort(), random.NextULong(), random.NextULong(),
                                                                 random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.BindingUpdate:     // 5
                return(new IpV6ExtensionHeaderMobilityBindingUpdate(nextHeader, checksum, random.NextUShort(), random.NextBool(), random.NextBool(),
                                                                    random.NextBool(), random.NextBool(), random.NextBool(), random.NextBool(),
                                                                    random.NextBool(), random.NextBool(), random.NextBool(), random.NextBool(),
                                                                    random.NextUShort(), random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.BindingAcknowledgement:     // 6
                return(new IpV6ExtensionHeaderMobilityBindingAcknowledgement(nextHeader, checksum, random.NextEnum <IpV6BindingAcknowledgementStatus>(),
                                                                             random.NextBool(), random.NextBool(), random.NextBool(), random.NextBool(),
                                                                             random.NextUShort(), random.NextUShort(), random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.BindingError:     // 7
                return(new IpV6ExtensionHeaderMobilityBindingError(nextHeader, checksum, random.NextEnum <IpV6BindingErrorStatus>(), random.NextIpV6Address(),
                                                                   random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.FastBindingUpdate:     // 8
                return(new IpV6ExtensionHeaderMobilityFastBindingUpdate(nextHeader, checksum, random.NextUShort(), random.NextBool(), random.NextBool(),
                                                                        random.NextBool(), random.NextBool(), random.NextUShort(),
                                                                        random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.FastBindingAcknowledgement:     // 9
                return(new IpV6ExtensionHeaderMobilityFastBindingAcknowledgement(nextHeader, checksum, random.NextEnum <IpV6BindingAcknowledgementStatus>(),
                                                                                 random.NextBool(), random.NextUShort(), random.NextUShort(),
                                                                                 random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.FastNeighborAdvertisement:     // 10
                return(new IpV6ExtensionHeaderMobilityFastNeighborAdvertisement(nextHeader, checksum, random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.Experimental:     // 11
                return(new IpV6ExtensionHeaderMobilityExperimental(nextHeader, checksum, random.NextDataSegment(2 + random.Next(10) * 8)));

            case IpV6MobilityHeaderType.HomeAgentSwitchMessage:     // 12
                return(new IpV6ExtensionHeaderMobilityHomeAgentSwitchMessage(nextHeader, checksum, random.NextIpV6AddressArray(random.NextInt(0, 10)),
                                                                             random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.HeartbeatMessage:     // 13
                return(new IpV6ExtensionHeaderMobilityHeartbeatMessage(nextHeader, checksum, random.NextBool(), random.NextBool(), random.NextUInt(),
                                                                       random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.HandoverInitiateMessage:     // 14
                return(new IpV6ExtensionHeaderMobilityHandoverInitiateMessage(nextHeader, checksum, random.NextUShort(), random.NextBool(),
                                                                              random.NextBool(), random.NextEnum <IpV6HandoverInitiateMessageCode>(),
                                                                              random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.HandoverAcknowledgeMessage:     // 15
                return(new IpV6ExtensionHeaderMobilityHandoverAcknowledgeMessage(nextHeader, checksum, random.NextUShort(),
                                                                                 random.NextEnum <IpV6MobilityHandoverAcknowledgeCode>(),
                                                                                 random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.BindingRevocationMessage:     // 16
                IpV6MobilityBindingRevocationType bindingRevocationType = random.NextEnum(IpV6MobilityBindingRevocationType.None);
                byte   revocationTriggerOrStatus = random.NextByte();
                ushort sequenceNumber            = random.NextUShort();
                bool   proxyBinding = random.NextBool();
                bool   ipV4HomeAddressBindingOnly = random.NextBool();
                bool   global = random.NextBool();
                IpV6MobilityOptions options = random.NextIpV6MobilityOptions();
                switch (bindingRevocationType)
                {
                case IpV6MobilityBindingRevocationType.BindingRevocationIndication:
                    return(new IpV6ExtensionHeaderMobilityBindingRevocationIndicationMessage(
                               nextHeader, checksum, (Ipv6MobilityBindingRevocationTrigger)revocationTriggerOrStatus, sequenceNumber, proxyBinding,
                               ipV4HomeAddressBindingOnly, global, options));

                case IpV6MobilityBindingRevocationType.BindingRevocationAcknowledgement:
                    return(new IpV6ExtensionHeaderMobilityBindingRevocationAcknowledgementMessage(
                               nextHeader, checksum, (Ipv6MobilityBindingRevocationStatus)revocationTriggerOrStatus, sequenceNumber, proxyBinding,
                               ipV4HomeAddressBindingOnly, global, options));

                default:
                    throw new InvalidOperationException(string.Format("Invalid bindingRevocationType value {0}", bindingRevocationType));
                }

            case IpV6MobilityHeaderType.LocalizedRoutingInitiation:     // 17
                return(new IpV6ExtensionHeaderMobilityLocalizedRoutingInitiation(nextHeader, checksum, random.NextUShort(), random.NextUShort(),
                                                                                 random.NextIpV6MobilityOptions()));

            case IpV6MobilityHeaderType.LocalizedRoutingAcknowledgement:     // 18
                return(new IpV6ExtensionHeaderMobilityLocalizedRoutingAcknowledgement(nextHeader, checksum, random.NextUShort(), random.NextBool(),
                                                                                      random.NextEnum <IpV6MobilityLocalizedRoutingAcknowledgementStatus>(),
                                                                                      random.NextUShort(), random.NextIpV6MobilityOptions()));

            default:
                throw new InvalidOperationException(string.Format("Invalid mobilityHeaderType value {0}", mobilityHeaderType));
            }
        }