Esempio n. 1
0
        public override ILayer ExtractLayer()
        {
            switch (this.MessageType)
            {
            case IgmpMessageType.MembershipQuery:
                switch (this.QueryVersion)
                {
                case IgmpQueryVersion.Version1:
                    IgmpQueryVersion1Layer queryVersion1Layer = new IgmpQueryVersion1Layer();
                    queryVersion1Layer.GroupAddress = this.GroupAddress;
                    return((ILayer)queryVersion1Layer);

                case IgmpQueryVersion.Version2:
                    IgmpQueryVersion2Layer queryVersion2Layer = new IgmpQueryVersion2Layer();
                    queryVersion2Layer.MaxResponseTime = this.MaxResponseTime;
                    queryVersion2Layer.GroupAddress    = this.GroupAddress;
                    return((ILayer)queryVersion2Layer);

                case IgmpQueryVersion.Version3:
                    return((ILayer) new IgmpQueryVersion3Layer()
                    {
                        SourceAddresses = this.SourceAddresses,
                        MaxResponseTime = this.MaxResponseTime,
                        GroupAddress = this.GroupAddress,
                        IsSuppressRouterSideProcessing = this.IsSuppressRouterSideProcessing,
                        QueryRobustnessVariable = this.QueryRobustnessVariable,
                        QueryInterval = this.QueryInterval
                    });

                default:
                    throw new InvalidOperationException("Invalid Query Version " + (object)this.QueryVersion);
                }

            case IgmpMessageType.MembershipReportVersion1:
                IgmpReportVersion1Layer reportVersion1Layer = new IgmpReportVersion1Layer();
                reportVersion1Layer.GroupAddress = this.GroupAddress;
                return((ILayer)reportVersion1Layer);

            case IgmpMessageType.MembershipReportVersion2:
                IgmpReportVersion2Layer reportVersion2Layer = new IgmpReportVersion2Layer();
                reportVersion2Layer.MaxResponseTime = this.MaxResponseTime;
                reportVersion2Layer.GroupAddress    = this.GroupAddress;
                return((ILayer)reportVersion2Layer);

            case IgmpMessageType.LeaveGroupVersion2:
                IgmpLeaveGroupVersion2Layer groupVersion2Layer = new IgmpLeaveGroupVersion2Layer();
                groupVersion2Layer.MaxResponseTime = this.MaxResponseTime;
                groupVersion2Layer.GroupAddress    = this.GroupAddress;
                return((ILayer)groupVersion2Layer);

            case IgmpMessageType.MembershipReportVersion3:
                return((ILayer) new IgmpReportVersion3Layer()
                {
                    GroupRecords = Enumerable.ToList <IgmpGroupRecord>(Enumerable.Select <IgmpGroupRecordDatagram, IgmpGroupRecord>((IEnumerable <IgmpGroupRecordDatagram>) this.GroupRecords, (Func <IgmpGroupRecordDatagram, IgmpGroupRecord>)(record => record.ToGroupRecord()))).AsReadOnly()
                });

            default:
                throw new InvalidOperationException("Invalid message type " + (object)this.MessageType);
            }
        }
Esempio n. 2
0
 public void DifferentIgmpSimpleLayersTest()
 {
     IgmpSimpleLayer layer1 = new IgmpQueryVersion1Layer
                                  {
                                      GroupAddress = new IpV4Address("1.2.3.4")
                                  };
     IgmpSimpleLayer layer2 = new IgmpQueryVersion2Layer
                                  {
                                      GroupAddress = new IpV4Address("1.2.3.4"),
                                      MaxResponseTime = TimeSpan.FromMinutes(55)
                                  };
     Assert.IsFalse(layer1.Equals(layer2));
 }
Esempio n. 3
0
        /// <summary>
        /// This function build an IGMP over IPv4 over Ethernet packet.
        /// </summary>
        private static Packet BuildIgmpPacket()
        {
            EthernetLayer ethernetLayer =
                new EthernetLayer
                    {
                        Source = new MacAddress("01:01:01:01:01:01"),
                        Destination = new MacAddress("02:02:02:02:02:02"),
                        EtherType = EthernetType.None, // Will be filled automatically.
                    };

            IpV4Layer ipV4Layer =
                new IpV4Layer
                    {
                        Source = new IpV4Address("1.2.3.4"),
                        CurrentDestination = new IpV4Address("11.22.33.44"),
                        Fragmentation = IpV4Fragmentation.None,
                        HeaderChecksum = null, // Will be filled automatically.
                        Identification = 123,
                        Options = IpV4Options.None,
                        Protocol = null, // Will be filled automatically.
                        Ttl = 100,
                        TypeOfService = 0,
                    };

            IgmpQueryVersion1Layer igmpLayer =
                new IgmpQueryVersion1Layer
                    {
                        GroupAddress = new IpV4Address("1.2.3.4"),
                    };

            PacketBuilder builder = new PacketBuilder(ethernetLayer, ipV4Layer, igmpLayer);

            return builder.Build(DateTime.Now);
        }