コード例 #1
0
        public void Test_True_Equals()
        {
            var ip       = new IP("1", "12.12.12.12/32");
            var other_ip = new IP("1", "12.12.12.12/32");

            Assert.True(ip.Equals(other_ip));
        }
コード例 #2
0
        public void Test_False_Equals(string id, string subnet)
        {
            var ip       = new IP(id, subnet);
            var other_ip = new IP("1", "13.13.13.13/32");

            Assert.False(ip.Equals(other_ip));
        }
コード例 #3
0
        public void Test_Constructor(string subnet)
        {
            var ip = new IP("1", subnet);

            var other_ip = new IP("1", "0.0.0.0/0");

            Assert.True(ip.Equals(other_ip));
        }
コード例 #4
0
            public void Identical()
            {
                IP ip0 = new IP(new byte[4] {
                    0, 0, 0, 0
                });

                Assert.True(ip0.Equals(ip0));
            }
コード例 #5
0
        public void TestEquals()
        {
            IP actual  = new IP("172.0.0.1");
            IP target  = new IP("172.0.0.1");
            IP another = new IP("172.0.0.0");

            Assert.True(actual.Equals(target));
            Assert.True(actual == target);
// ReSharper disable EqualExpressionComparison
            Assert.True(actual == actual);
// ReSharper restore EqualExpressionComparison
            Assert.Equal(actual, target);
            Assert.False(actual == another);
            Assert.True(actual != another);
            Assert.NotEqual(actual, another);

            Assert.False(actual.Equals(1));
        }
コード例 #6
0
        public void TestEquals()
        {
            IP actual = new IP("172.0.0.1");
            IP target = new IP("172.0.0.1");
            IP another = new IP("172.0.0.0");

            Assert.IsTrue(actual.Equals(target));
            Assert.IsTrue(actual == target);
// ReSharper disable EqualExpressionComparison
            Assert.IsTrue(actual == actual);
// ReSharper restore EqualExpressionComparison
            Assert.AreEqual(actual, target);
            Assert.IsFalse(actual == another);
            Assert.IsTrue(actual != another);
            Assert.AreNotEqual(actual, another);

            Assert.IsFalse(actual.Equals(1));
        }
コード例 #7
0
        public bool Equals(Server s)
        {
            if (s == null)
            {
                return(false);
            }

            return(Name.Equals(s.Name) && IP.Equals(s.IP) && ControlPort == s.ControlPort);
        }
コード例 #8
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
            DummyFollowerNode otherNode = (obj as DummyFollowerNode);

            return(IP.Equals(otherNode.IP));
        }
コード例 #9
0
            public void SameByteArray()
            {
                byte[] b = new byte[4] {
                    0, 0, 0, 0
                };
                IP ip0 = new IP(b);
                IP ip1 = new IP(b);

                Assert.True(ip0.Equals(ip1));
            }
コード例 #10
0
 public bool Equal(MemberEvent memberEvent)
 {
     return(memberEvent != null &&
            IP.Equals(memberEvent.IP) &&
            GossipPort == memberEvent.GossipPort &&
            State == memberEvent.State &&
            Generation == memberEvent.Generation &&
            Service == memberEvent.Service &&
            ServicePort == memberEvent.ServicePort);
 }
コード例 #11
0
            public void Equals3()
            {
                IP ip0 = new IP(new byte[4] {
                    0, 0, 0, 0
                });
                IP ip1 = new IP(new byte[4] {
                    0, 0, 0, 1
                });

                Assert.False(ip0.Equals(ip1));
            }
コード例 #12
0
            public void DifferentByteArray()
            {
                IP ip0 = new IP(new byte[4] {
                    0, 0, 0, 0
                });
                IP ip1 = new IP(new byte[4] {
                    0, 0, 0, 0
                });

                Assert.True(ip0.Equals(ip1));
            }
コード例 #13
0
ファイル: Profile.cs プロジェクト: JosephMartell/SetIP
        public bool Equals(Profile other)
        {
            bool AreEqual = (Name == other.Name);

            AreEqual &= (UseDHCP == other.UseDHCP);
            AreEqual &= IP.Equals(other.IP);
            AreEqual &= Subnet.Equals(other.Subnet);
            AreEqual &= Gateway.Equals(other.Gateway);
            AreEqual &= DNSServersAreEqual(other.DNSServers);
            return(AreEqual);
        }
コード例 #14
0
        /// <summary>
        /// O(n * k * logk)  // much faster than O(n logn) for k << n
        /// </summary>
        /// <param name="s"></param>
        /// <param name="p"></param>
        /// <param name="conf"></param>
        /// <returns></returns>
        public long UpdateKnn(IAlgorithm s, IP p, KnnConfiguration conf)
        {
            conf = conf ?? new KnnConfiguration();

            var sw = new Stopwatch();

            sw.Start();

            s.Knn.Clear();
            s.Knn.Origin = p;
            s.Knn.K      = conf.K;

            //var all = new List<IPDist>(); // naive version
            var sortedList2 = new SortedList2();  // better naive version

            var n = s.Points.Count;

            for (var i = 0; i < n; i++)
            {
                var p1 = s.Points[i];
                if (p.Equals(p1))
                {
                    continue;               // don't include origin
                }
                if (conf.SameTypeOnly && p.Type != p1.Type)
                {
                    continue;                                         // only same type used
                }
                var dist = p.Distance(p1.X, p1.Y);
                if (dist >= conf.MaxDistance)
                {
                    continue;
                }

                var pdist = new PDist {
                    Point = p1, Distance = dist
                };

                //all.Add(pdist); // naive version
                sortedList2.Add(pdist, conf.K);  // better naive version
            }

            //s.Knn.NNs = all.OrderBy(i => i.Distance).Take(conf.K).ToList(); // O(n logn)
            s.Knn.NNs = sortedList2.GetAll(); // O(n * k * logk) // better naive version

            sw.Stop();
            return(sw.ElapsedMilliseconds);
        }
コード例 #15
0
        private void Communication_StaticOnLayoutEvent(object sender, LayoutEventArgs e)
        {
            if (!IP.Equals(e.IP))
            {
                return;
            }

            var pp = e.LayoutEvent.Layout.PanelPositions.FirstOrDefault(p => p.PanelId.Equals(ID));

            if (pp != null)
            {
                X           = pp.X;
                Y           = pp.Y;
                Orientation = pp.Orientation;
            }
        }
コード例 #16
0
        /// <summary>
        /// Determines whether the specified object is equal to the current object.
        /// </summary>
        /// <param name="obj">The object to compare with the current object.</param>
        /// <returns>true if the specified object is equal to the current object; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            var result = false;

            if (obj is CheckpointDTO item)
            {
                result  = ID == item.ID;
                result &= IP.Equals(item.IP);
                result &= Campus.Equals(item.Campus);
                result &= Row.Equals(item.Row);
                result &= Description.Equals(item.Description);
                result &= Status.Equals(item.Status);
                result &= Type.Equals(item.Type);
                result &= Admissions.Equals(item.Admissions);
                return(result);
            }
            return(false);
        }
コード例 #17
0
        public override bool Equals(System.Object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            Server s = obj as Server;

            if ((System.Object)s == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return(Name.Equals(s.Name) && IP.Equals(s.IP) && ControlPort == s.ControlPort);
        }
コード例 #18
0
        /// <summary>        
        /// O(n * k * logk)  // much faster than O(n logn) for k << n
        /// </summary>
        /// <param name="s"></param>
        /// <param name="p"></param>       
        /// <param name="conf"></param>
        /// <returns></returns>
        public override long UpdateKnn(IAlgorithm s, IP p, KnnConfiguration conf)
        {
            if (conf == null) conf = new KnnConfiguration();

            var sw = new Stopwatch();
            sw.Start();

            s.Knn.Clear();
            s.Knn.Origin = p;
            s.Knn.K = conf.K;

            //var all = new List<IPDist>();
            var sortedList2 = new SortedList2();

            var n = s.Points.Count;
            for (var i = 0; i < n; i++)
            {
                var p1 = s.Points[i];
                if (p.Equals(p1)) continue; // don't include origin
                if (conf.SameTypeOnly && p.Type != p1.Type) continue; // only same type used

                var dist = p.Distance(p1.X, p1.Y);
                if (dist >= conf.MaxDistance) continue;

                var pdist = new PDist { Point = p1, Distance = dist };

                //all.Add(pdist);
                sortedList2.Add(pdist, conf.K);
            }

            //s.Knn.NNs = all.OrderBy(i => i.Distance).Take(conf.K).ToList(); // O(n logn)
            s.Knn.NNs = sortedList2.GetAll(); // O(n * k * logk)

            sw.Stop();
            return sw.ElapsedMilliseconds;
        }
コード例 #19
0
        static void Main(string[] args)
        {
            {
                Console.WriteLine("NSHG.IP");
                IP ip0 = new IP(new Byte[] { 0, 0, 0, 0 });
                Output(ip0.Equals(ip0), "ip.Equals (Identical)");

                Console.WriteLine("NSHG.IP");
                IP ip1234  = new IP(new Byte[] { 1, 2, 3, 4, 5 }, 0);
                IP ip12342 = new IP(new Byte[] { 1, 2, 3, 4 });
                Output(ip12342.Equals(ip1234), "ip.from array size > 4");


                IP ip255  = new IP(new Byte[] { 255, 255, 255, 255 });
                IP ip2552 = new IP(new Byte[] { 255, 255, 255, 255 });
                Output(ip255.Equals(ip2552), "ip.Equals (Non Identical)");

                IP ip3 = new IP(new Byte[] { 0, 0, 0, 0 });
                Output(ip0.Equals(ip3), "ip.Equals (Non Identical)");

                IP ip4 = new IP(new Byte[] { 0, 0, 0, 1 });
                Output(!ip0.Equals(ip4), "ip.Equals (Non Identical, Not Equal)");

                // Parse
                // Normal Parse's
                IP ip5   = IP.Parse("192.168.1.1");
                IP ip192 = new IP(new Byte[] { 192, 168, 1, 1 });
                Output(ip5.Equals(ip192), "ip.Parse(\"192.168.1.1\")");

                ip5 = IP.Parse("0.0.0.0");
                Output(ip5.Equals(ip0), "ip.Parse(\"0.0.0.0\")");

                ip5 = IP.Parse("255.255.255.255");
                Output(ip5.Equals(ip255), "ip.Parse(\"255.255.255.255\")");


                // Address Segments > 255
                bool result = false;
                try
                {
                    IP ip = IP.Parse("256.256.256.256");
                }
                catch (OverflowException)
                {
                    result = true;
                }
                finally
                {
                    Output(result, "IP.Parse (Overflow)");
                }

                // Null Input
                result = false;
                try
                {
                    IP ip = IP.Parse("");
                }
                catch (ArgumentNullException)
                {
                    result = true;
                }
                finally
                {
                    Output(result, "IP.Parse (Null)");
                }

                // Not Enough Segments
                result = false;
                try
                {
                    IP ip = IP.Parse("1");
                }
                catch (ArgumentOutOfRangeException)
                {
                    result = true;
                }
                finally
                {
                    Output(result, "IP.Parse (1)");
                }
                result = false;
                try
                {
                    IP ip = IP.Parse("1.1");
                }
                catch (ArgumentOutOfRangeException)
                {
                    result = true;
                }
                finally
                {
                    Output(result, "IP.Parse (1.1)");
                }
                result = false;
                try
                {
                    IP ip = IP.Parse("1.1.1");
                }
                catch (ArgumentOutOfRangeException)
                {
                    result = true;
                }
                finally
                {
                    Output(result, "IP.Parse (1.1.1)");
                }
            }// IP

            {
                MAC m = new MAC(new Byte[] { 255, 255, 255, 255, 255, 255 });

                m = MAC.Parse("FF:FF:FF:FF:FF:00");
                Console.WriteLine(m.ToString());
                foreach (Byte b in m.ToBytes())
                {
                    Console.WriteLine(b);
                }
            }// MAC

            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();

                byte[] expected, actual;

                expected = new byte[]
                {
                    0x45, 0x00, 0x00, 0x28, 0x6e, 0x9c, 0x40, 0x00, 0x80, 0x06, 0x77, 0xd7, 0x0a, 0x90, 0xe3, 0x64, 0x28, 0x43, 0xfe, 0x24
                };

                IPv4Header ipv4 = new IPv4Header(0x6E9C, true, false, 128, (IPv4Header.ProtocolType) 6, IP.Parse("10.144.227.100"), IP.Parse("40.67.254.36"), new byte[0], new byte[20]);



                actual = ipv4.ToBytes();

                foreach (byte b in expected)
                {
                    Console.Write(b.ToString("X"));
                    Console.Write(" ");
                }
                Console.WriteLine();


                foreach (byte b in actual)
                {
                    Console.Write(b.ToString("X"));
                    Console.Write(" ");
                }
                Console.WriteLine();
            }// IP  Header

            {
            }// TCP Header


            Console.ReadLine();
        }
コード例 #20
0
ファイル: IPCom.cs プロジェクト: fomin-stas/cisco_monitoring
        public override bool Equals(object obj)
        {
            var item = obj as IPCom;

            return(item != null && IP.Equals(item.IP) && Com.Equals(item.Com));
        }
コード例 #21
0
ファイル: Pinger.cs プロジェクト: marcinzaczynski/wanna2
 public override bool Equals(object obj)
 {
     return(IP.Equals((obj as Host).IP));
 }
コード例 #22
0
ファイル: NetworkInterfaces.cs プロジェクト: Geoed2000/NSHG
        public override bool Equals(object obj)
        {
            Adapter a;

            try
            {
                a = (Adapter)obj;
            }
            catch (InvalidCastException)
            {
                return(false);
            }

            if (MyMACAddress == null)
            {
                if (a.MyMACAddress != null)
                {
                    return(false);
                }
            }
            else if (!MyMACAddress.Equals(a.MyMACAddress))
            {
                return(false);
            }

            if (LocalIP == null)
            {
                if (a.LocalIP != null)
                {
                    return(false);
                }
            }
            else if (!LocalIP.Equals(a.LocalIP))
            {
                return(false);
            }

            if (SubnetMask == null)
            {
                if (a.SubnetMask != null)
                {
                    return(false);
                }
            }
            else if (!SubnetMask.Equals(a.SubnetMask))
            {
                return(false);
            }

            if (DefaultGateway == null)
            {
                if (a.DefaultGateway != null)
                {
                    return(false);
                }
            }
            else if (!DefaultGateway.Equals(a.DefaultGateway))
            {
                return(false);
            }

            if (DNS == null)
            {
                if (a.DNS != null)
                {
                    return(false);
                }
            }
            else if (!DNS.Equals(a.DNS))
            {
                return(false);
            }


            if ((Name == a.Name) && (OtherEndID == a.OtherEndID) && (Connected == a.Connected) && (Associated == a.Associated))
            {
                return(true);
            }
            return(false);
        }