141 lines
3.9 KiB
C#
141 lines
3.9 KiB
C#
// /**
|
|
// * File: IPNode.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 ln.types;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using ln.types.odb;
|
|
using Newtonsoft.Json;
|
|
using ln.types.threads;
|
|
using ln.types.net;
|
|
using ln.types.odb.attributes;
|
|
namespace ln.skyscanner.entities
|
|
{
|
|
public class Node
|
|
{
|
|
[DocumentID]
|
|
public Guid ID { get; set; } = Guid.NewGuid();
|
|
|
|
public IPv4 PrimaryIP { get; set; }
|
|
public String PrimaryMac { get; set; }
|
|
|
|
public String Name { get; set; }
|
|
|
|
public DateTime Created { get; }
|
|
public DateTime LastUpdate { get; set; }
|
|
|
|
public URI[] URIs => uris.ToArray();
|
|
|
|
public GeoLocation Location { get; set; }
|
|
public string Vendor { get; set; }
|
|
public string Product { get; set; }
|
|
|
|
public string ProductLine { get; set; }
|
|
public CheckSeverity Severity { get; set; } = CheckSeverity.PLANNED;
|
|
|
|
public DeviceType DeviceType { get; set; }
|
|
|
|
public List<NetworkInterface> Interfaces { get; private set; } = new List<NetworkInterface>();
|
|
|
|
[JsonIgnore]
|
|
public IEnumerable<IPv4> IPAdresses => Interfaces.SelectMany(intf => intf.ConfiguredIPs.Select(nip => nip.IP));
|
|
[JsonIgnore]
|
|
public IEnumerable<Network4> Networks => Interfaces.SelectMany(intf => intf.ConfiguredIPs.Select(nip => nip.Network)).Distinct();
|
|
[JsonIgnore]
|
|
public IEnumerable<Subnet> Subnets => SkyScanner.Instance.Entities.SubnetCollection.Query(Query.Equals<Network4>("Network", Networks.Select(net => net.Network)));
|
|
|
|
private string uniqueIdentity;
|
|
public String UniqueIdentity {
|
|
get {
|
|
if (uniqueIdentity == null)
|
|
uniqueIdentity = PrimaryIP.ToString();
|
|
return uniqueIdentity;
|
|
}
|
|
set => uniqueIdentity = value;
|
|
}
|
|
public String[] Checks => checks.ToArray();
|
|
|
|
private HashSet<URI> uris = new HashSet<URI>();
|
|
private HashSet<string> checks = new HashSet<string>();
|
|
|
|
private Node()
|
|
{
|
|
}
|
|
|
|
public Node(IPv4 primaryIP)
|
|
{
|
|
PrimaryIP = primaryIP;
|
|
Name = PrimaryIP.ToString();
|
|
Created = DateTime.Now;
|
|
}
|
|
|
|
public bool AddCheck(string perfName)
|
|
{
|
|
if (checks == null)
|
|
checks = new HashSet<string>();
|
|
return checks.Add(perfName);
|
|
}
|
|
|
|
public void RemoveURI(string scheme)
|
|
{
|
|
RemoveURI(FindURIs(scheme));
|
|
}
|
|
public void RemoveURI(IEnumerable<URI> uris)
|
|
{
|
|
foreach (URI uri in uris.ToArray())
|
|
RemoveURI(uri);
|
|
}
|
|
public void RemoveURI(URI uri)
|
|
{
|
|
foreach (URI u in uris.ToArray())
|
|
{
|
|
if (uri.Equals(u))
|
|
uris.Remove(u);
|
|
}
|
|
}
|
|
|
|
public void AddURI(URI uri)
|
|
{
|
|
uris.Add(uri);
|
|
}
|
|
|
|
public IEnumerable<URI> FindURIs(string scheme)
|
|
{
|
|
return uris.Where((u) => scheme.Equals(u.Scheme));
|
|
}
|
|
|
|
public NetworkInterface GetInterface(String intfName)
|
|
{
|
|
return Interfaces.Where(intf => intf.Name.Equals(intfName)).FirstOrDefault();
|
|
}
|
|
|
|
public bool HasInterface(string intfName)
|
|
{
|
|
return GetInterface(intfName) != null;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return ID.GetHashCode();
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return (obj is Node) && (ID.Equals((obj as Node).ID));
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return String.Format("[Node ID={0} PrimaryIP={1} Name={2}]",ID,PrimaryIP,Name);
|
|
}
|
|
|
|
}
|
|
}
|