88 lines
2.3 KiB
C#
88 lines
2.3 KiB
C#
// /**
|
|
// * 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;
|
|
using ln.types.net;
|
|
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 List<IntfIP> ConfiguredIPs { get; private set; } = new List<IntfIP>();
|
|
//public IEnumerable<IntfIP> ConfiguredIPs => SkyScanner.Instance.Entities.intfIPCollection.Select("interfaceID", ID);
|
|
|
|
private NetworkInterface()
|
|
{ }
|
|
|
|
public NetworkInterface(Node node,String name)
|
|
{
|
|
Node = node;
|
|
Name = name;
|
|
}
|
|
|
|
public bool HasIP(IPv4 ip)
|
|
{
|
|
foreach (IntfIP ifip in ConfiguredIPs)
|
|
{
|
|
if (ifip.IP.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);
|
|
}
|
|
|
|
}
|
|
|
|
}
|