// /** // * File: Router.cs // * Author: haraldwolff // * // * This file and it's content is copyrighted by the Author and / or copyright holder. // * Any use wihtout proper permission is illegal and may lead to legal actions. // * // * // **/ using System; using System.Collections.Generic; using ln.types; using ln.skyscanner.crawl; using ln.types.odb; using Newtonsoft.Json; using LiteDB; using ln.logging; namespace ln.skyscanner.entities { public class NetworkInterface { [DocumentID] public readonly Guid ID = Guid.NewGuid(); public Guid NodeID { get; set; } [JsonIgnoreAttribute] public Node Node { get => SkyScanner.Instance.Entities.nodeCollection[NodeID]; set => NodeID = value.ID; } public string Name { get; private set; } = ""; public string HWAddress { get; set; } = ""; //public CIDR[] IPs { get; set; } = new CIDR[0]; public IEnumerable IPs => SkyScanner.Instance.Entities.intfIPCollection.Select("interfaceID", ID); private NetworkInterface() { } public NetworkInterface(Node node,String name) { Node = node; Name = name; } public bool HasIP(CIDR ip) { ip = ip.Host; foreach (IntfIP ifip in IPs) { if (ifip.IP.Host.Equals(ip)) return true; } return false; } public override int GetHashCode() { if (Node == null) Logging.Log(LogLevel.WARNING, "NetworkInterface without Node detected. ID={2} NodeID={0} Name={1}",NodeID,Name,ID); else return Node.GetHashCode() ^ Name.GetHashCode(); return 0; } public override bool Equals(object obj) { if (obj is NetworkInterface) { NetworkInterface networkInterface = obj as NetworkInterface; return object.Equals(Node,networkInterface.Node) && object.Equals(Name,networkInterface.Name); } return false; } public override string ToString() { return string.Format("[NetworkInterface ID={0} NodeID={1} Name={2}]",ID,NodeID,Name); } } }