WIP
parent
1177310f7f
commit
b71f5cc279
22
Program.cs
22
Program.cs
|
@ -15,6 +15,7 @@ using ln.skyscanner.entities;
|
||||||
using ln.types.threads;
|
using ln.types.threads;
|
||||||
using ln.types.net;
|
using ln.types.net;
|
||||||
using ln.types.odb;
|
using ln.types.odb;
|
||||||
|
using ln.types.odb.index;
|
||||||
|
|
||||||
namespace ln.skyscanner
|
namespace ln.skyscanner
|
||||||
{
|
{
|
||||||
|
@ -38,16 +39,25 @@ namespace ln.skyscanner
|
||||||
skyScanner.Start();
|
skyScanner.Start();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (IntfIP iip in SkyScanner.Instance.Entities.intfIPCollection.Select("Network", Network4.Parse("10.255.9.16/29")))
|
Node coreNode = skyScanner.Entities.GlobalNetwork.FindNodeByIP(IPv4.Parse("10.10.10.2"));
|
||||||
|
Console.WriteLine("Core Node: {0}", coreNode);
|
||||||
|
|
||||||
|
Node coreNode2 = skyScanner.Entities.GlobalNetwork.FindNodeByIP(IPv4.Parse("10.255.7.129"));
|
||||||
|
Console.WriteLine("Core Node (alt): {0}", coreNode2);
|
||||||
|
|
||||||
|
Query nodeByIpQuery = Query.Equals<Node>("Interfaces[].ConfiguredIPs[].IP", IPv4.Parse("10.255.7.129"));
|
||||||
|
IEnumerable<Node> qnodes = skyScanner.Entities.nodeCollection.Select(nodeByIpQuery);
|
||||||
|
|
||||||
|
IEnumerable<Node> neighbors = skyScanner.Entities.GlobalNetwork.FindNeighbors(coreNode);
|
||||||
|
|
||||||
|
foreach (Node neigh in neighbors)
|
||||||
{
|
{
|
||||||
Console.WriteLine("INTF-IP ():{0}", iip);
|
Console.WriteLine("Neighbor: {0}", neigh);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (IntfIP iip in SkyScanner.Instance.Entities.intfIPCollection)
|
SkyScanner.Instance.Stop();
|
||||||
{
|
|
||||||
Console.WriteLine("INTF-IP: {0}", iip);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
IEnumerable<Node> nodes = skyScanner.Entities.nodeCollection;
|
IEnumerable<Node> nodes = skyScanner.Entities.nodeCollection;
|
||||||
foreach (Node node in nodes)
|
foreach (Node node in nodes)
|
||||||
|
|
|
@ -23,8 +23,8 @@ namespace ln.skyscanner
|
||||||
public GlobalNetwork GlobalNetwork { get; private set; }
|
public GlobalNetwork GlobalNetwork { get; private set; }
|
||||||
public ODB odDatabase { get; private set; }
|
public ODB odDatabase { get; private set; }
|
||||||
public ODBCollection<Node> nodeCollection { get; private set; }
|
public ODBCollection<Node> nodeCollection { get; private set; }
|
||||||
public ODBCollection<NetworkInterface> interfaceCollection { get; private set; }
|
//public ODBCollection<NetworkInterface> interfaceCollection { get; private set; }
|
||||||
public ODBCollection<IntfIP> intfIPCollection { get; private set; }
|
//public ODBCollection<IntfIP> intfIPCollection { get; private set; }
|
||||||
public ODBCollection<Subnet> subnetCollection { get; private set; }
|
public ODBCollection<Subnet> subnetCollection { get; private set; }
|
||||||
|
|
||||||
public SkyEntities(SkyScanner skyScanner)
|
public SkyEntities(SkyScanner skyScanner)
|
||||||
|
@ -33,15 +33,13 @@ namespace ln.skyscanner
|
||||||
|
|
||||||
odDatabase = new ODB(BasePath);
|
odDatabase = new ODB(BasePath);
|
||||||
nodeCollection = odDatabase.GetCollection<Node>();
|
nodeCollection = odDatabase.GetCollection<Node>();
|
||||||
//interfaceCollection = odDatabase.GetCollection<NetworkInterface>();
|
|
||||||
//intfIPCollection = odDatabase.GetCollection<IntfIP>();
|
|
||||||
subnetCollection = odDatabase.GetCollection<Subnet>();
|
subnetCollection = odDatabase.GetCollection<Subnet>();
|
||||||
|
|
||||||
nodeCollection.EnsureIndex("PrimaryIP");
|
nodeCollection.EnsureIndex("PrimaryIP");
|
||||||
|
nodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].IP");
|
||||||
|
nodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].Network");
|
||||||
|
|
||||||
//interfaceCollection.EnsureIndex("NodeID");
|
subnetCollection.EnsureIndex("Network");
|
||||||
//intfIPCollection.EnsureIndex("interfaceID");
|
|
||||||
//intfIPCollection.EnsureIndex("Network");
|
|
||||||
|
|
||||||
GlobalNetwork = new GlobalNetwork(this);
|
GlobalNetwork = new GlobalNetwork(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,7 @@ namespace ln.skyscanner.crawl
|
||||||
}
|
}
|
||||||
public CrawledSubnet FindSubnet(Network4 network)
|
public CrawledSubnet FindSubnet(Network4 network)
|
||||||
{
|
{
|
||||||
CrawledSubnet sn = CrawledSubnets.Where(subnet => subnet.Network.Equals(network)).FirstOrDefault();
|
CrawledSubnet sn = CrawledSubnets.Select("Network", network).FirstOrDefault();
|
||||||
if (sn == null)
|
if (sn == null)
|
||||||
{
|
{
|
||||||
Logging.Log(LogLevel.INFO, "Crawler adds new subnet: {0}",network);
|
Logging.Log(LogLevel.INFO, "Crawler adds new subnet: {0}",network);
|
||||||
|
|
|
@ -14,25 +14,19 @@ using Newtonsoft.Json;
|
||||||
using ln.types.net;
|
using ln.types.net;
|
||||||
namespace ln.skyscanner.entities
|
namespace ln.skyscanner.entities
|
||||||
{
|
{
|
||||||
public class IntfIP
|
public class ConfiguredIP
|
||||||
{
|
{
|
||||||
[DocumentID]
|
[DocumentID]
|
||||||
public readonly Guid ID = Guid.NewGuid();
|
public readonly Guid ID = Guid.NewGuid();
|
||||||
|
|
||||||
Guid interfaceID = Guid.Empty;
|
|
||||||
|
|
||||||
[JsonIgnore]
|
|
||||||
public NetworkInterface NetworkInterface => SkyScanner.Instance.Entities.interfaceCollection.Select(interfaceID);
|
|
||||||
|
|
||||||
public IPv4 IP { get; private set; }
|
public IPv4 IP { get; private set; }
|
||||||
public Network4 Network { get; private set; }
|
public Network4 Network { get; private set; }
|
||||||
|
|
||||||
public IntfIP()
|
public ConfiguredIP()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public IntfIP(NetworkInterface networkInterface,IPv4 ip,Network4 network)
|
public ConfiguredIP(IPv4 ip,Network4 network)
|
||||||
{
|
{
|
||||||
interfaceID = networkInterface.ID;
|
|
||||||
IP = ip;
|
IP = ip;
|
||||||
Network = network;
|
Network = network;
|
||||||
}
|
}
|
|
@ -65,25 +65,29 @@ namespace ln.skyscanner.entities
|
||||||
|
|
||||||
public IEnumerable<Node> FindHostsInSubnet(Network4 network)
|
public IEnumerable<Node> FindHostsInSubnet(Network4 network)
|
||||||
{
|
{
|
||||||
IntfIP[] intfIPs = SkyEntities.intfIPCollection.Select("Network",network).ToArray();
|
Query nodeByIpQuery = Query.Equals<Node>("Interfaces[].ConfiguredIPs[].Network", network);
|
||||||
NetworkInterface[] networkInterfaces = intfIPs.Select((iip) => iip.NetworkInterface).ToArray();
|
return SkyEntities.nodeCollection.Select(nodeByIpQuery);
|
||||||
|
|
||||||
Node[] nodes = SkyEntities.nodeCollection.Select(networkInterfaces.Select((ni) => new ODBGuid(ni.NodeID))).ToArray();
|
|
||||||
|
|
||||||
return nodes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Node> FindNeighbors(Node node)
|
public IEnumerable<Node> FindNeighbors(Node node)
|
||||||
{
|
{
|
||||||
HashSet<Node> nodes = new HashSet<Node>();
|
HashSet<Node> nodes = new HashSet<Node>();
|
||||||
|
|
||||||
//foreach (Network4 network in node.Networks)
|
if (node.Interfaces.Count > 0)
|
||||||
//{
|
{
|
||||||
// foreach (Node neighbor in FindHostsInSubnet(network))
|
foreach (Network4 network in node.Networks)
|
||||||
// {
|
{
|
||||||
// nodes.Add(neighbor);
|
foreach (Node neighbor in FindHostsInSubnet(network))
|
||||||
// }
|
nodes.Add(neighbor);
|
||||||
//}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Subnet subnet = FindSubnetForIP(node.PrimaryIP);
|
||||||
|
IEnumerable<Node> nodelist = FindHostsInSubnet(subnet.Network);
|
||||||
|
foreach (Node n in nodelist)
|
||||||
|
nodes.Add(n);
|
||||||
|
}
|
||||||
|
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
@ -98,24 +102,14 @@ namespace ln.skyscanner.entities
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//public Node FindNodeByIP(CIDR ip)
|
|
||||||
//{
|
|
||||||
// ip = ip.Host;
|
|
||||||
// /*
|
|
||||||
// * ToDo: Alternative Implementation
|
|
||||||
// * a) higher performance (use indexing)
|
|
||||||
// * b) fix bug: Node not found if no interface ips exist...
|
|
||||||
// */
|
|
||||||
// IntfIP _iip = SkyEntities.intfIPCollection.Where((iip) => iip.IP.Host.Equals(ip)).FirstOrDefault();
|
|
||||||
// return _iip?.NetworkInterface?.Node;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public Node FindNodeByIP(IPv4 ip)
|
public Node FindNodeByIP(IPv4 ip)
|
||||||
{
|
{
|
||||||
Node node = SkyEntities.nodeCollection.SelectOne("PrimaryIP", ip);
|
Node node = SkyEntities.nodeCollection.SelectOne("PrimaryIP", ip);
|
||||||
if (node == null)
|
if (node == null)
|
||||||
{
|
{
|
||||||
|
Query nodeByIpQuery = Query.Equals<Node>("Interfaces[].ConfiguredIPs[].IP", ip);
|
||||||
|
node = SkyEntities.nodeCollection.Select(nodeByIpQuery).FirstOrDefault();
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +187,7 @@ namespace ln.skyscanner.entities
|
||||||
NetworkInterface networkInterface = node.GetInterface(fields[0]);
|
NetworkInterface networkInterface = node.GetInterface(fields[0]);
|
||||||
if (networkInterface == null)
|
if (networkInterface == null)
|
||||||
{
|
{
|
||||||
networkInterface = new NetworkInterface(node, fields[0]);
|
networkInterface = new NetworkInterface(fields[0]);
|
||||||
node.Interfaces.Add(networkInterface);
|
node.Interfaces.Add(networkInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +196,7 @@ namespace ln.skyscanner.entities
|
||||||
IPv4[][] crawledIPs = fields[2].Split(',').Where((sip) => !String.Empty.Equals(sip))
|
IPv4[][] crawledIPs = fields[2].Split(',').Where((sip) => !String.Empty.Equals(sip))
|
||||||
.Select((sip) => sip.Split('/').Select(ip => IPv4.Parse(ip)).ToArray()).ToArray();
|
.Select((sip) => sip.Split('/').Select(ip => IPv4.Parse(ip)).ToArray()).ToArray();
|
||||||
|
|
||||||
IntfIP[] currentIPs = networkInterface.ConfiguredIPs.ToArray();
|
ConfiguredIP[] currentIPs = networkInterface.ConfiguredIPs.ToArray();
|
||||||
|
|
||||||
foreach (IPv4[] crawledIP in crawledIPs)
|
foreach (IPv4[] crawledIP in crawledIPs)
|
||||||
{
|
{
|
||||||
|
@ -212,12 +206,12 @@ namespace ln.skyscanner.entities
|
||||||
break;
|
break;
|
||||||
if (n == currentIPs.Length)
|
if (n == currentIPs.Length)
|
||||||
{
|
{
|
||||||
IntfIP miss = new IntfIP(networkInterface, crawledIP[0], new Network4(crawledIP[0], crawledIP[1]));
|
ConfiguredIP miss = new ConfiguredIP(crawledIP[0], new Network4(crawledIP[0], crawledIP[1]));
|
||||||
networkInterface.ConfiguredIPs.Add(miss);
|
networkInterface.ConfiguredIPs.Add(miss);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (IntfIP iip in currentIPs)
|
foreach (ConfiguredIP iip in currentIPs)
|
||||||
{
|
{
|
||||||
IPv4 ip = iip.IP;
|
IPv4 ip = iip.IP;
|
||||||
|
|
||||||
|
|
|
@ -22,34 +22,23 @@ namespace ln.skyscanner.entities
|
||||||
{
|
{
|
||||||
[DocumentID]
|
[DocumentID]
|
||||||
public readonly Guid ID = Guid.NewGuid();
|
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 Name { get; private set; } = "";
|
||||||
public string HWAddress { get; set; } = "";
|
public string HWAddress { get; set; } = "";
|
||||||
|
|
||||||
public List<IntfIP> ConfiguredIPs { get; private set; } = new List<IntfIP>();
|
public List<ConfiguredIP> ConfiguredIPs { get; private set; } = new List<ConfiguredIP>();
|
||||||
//public IEnumerable<IntfIP> ConfiguredIPs => SkyScanner.Instance.Entities.intfIPCollection.Select("interfaceID", ID);
|
|
||||||
|
|
||||||
private NetworkInterface()
|
private NetworkInterface()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public NetworkInterface(Node node,String name)
|
public NetworkInterface(String name)
|
||||||
{
|
{
|
||||||
Node = node;
|
|
||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasIP(IPv4 ip)
|
public bool HasIP(IPv4 ip)
|
||||||
{
|
{
|
||||||
foreach (IntfIP ifip in ConfiguredIPs)
|
foreach (ConfiguredIP ifip in ConfiguredIPs)
|
||||||
{
|
{
|
||||||
if (ifip.IP.Equals(ip))
|
if (ifip.IP.Equals(ip))
|
||||||
return true;
|
return true;
|
||||||
|
@ -60,11 +49,7 @@ namespace ln.skyscanner.entities
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
if (Node == null)
|
return Name.GetHashCode();
|
||||||
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)
|
public override bool Equals(object obj)
|
||||||
|
@ -72,14 +57,14 @@ namespace ln.skyscanner.entities
|
||||||
if (obj is NetworkInterface)
|
if (obj is NetworkInterface)
|
||||||
{
|
{
|
||||||
NetworkInterface networkInterface = obj as NetworkInterface;
|
NetworkInterface networkInterface = obj as NetworkInterface;
|
||||||
return object.Equals(Node,networkInterface.Node) && object.Equals(Name,networkInterface.Name);
|
return object.Equals(Name,networkInterface.Name);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return string.Format("[NetworkInterface ID={0} NodeID={1} Name={2}]",ID,NodeID,Name);
|
return string.Format("[NetworkInterface ID={0} Name={1}]",ID,Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,12 @@ namespace ln.skyscanner.entities
|
||||||
|
|
||||||
public List<NetworkInterface> Interfaces { get; private set; } = new List<NetworkInterface>();
|
public List<NetworkInterface> Interfaces { get; private set; } = new List<NetworkInterface>();
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
public IEnumerable<IPv4> IPAdresses => Interfaces.SelectMany(intf => intf.ConfiguredIPs.Select(nip => nip.IP));
|
public IEnumerable<IPv4> IPAdresses => Interfaces.SelectMany(intf => intf.ConfiguredIPs.Select(nip => nip.IP));
|
||||||
public IEnumerable<Network4> Networks => Interfaces.SelectMany(intf => intf.ConfiguredIPs.Select(nip => nip.Network));
|
[JsonIgnore]
|
||||||
|
public IEnumerable<Network4> Networks => Interfaces.SelectMany(intf => intf.ConfiguredIPs.Select(nip => nip.Network)).Distinct();
|
||||||
|
[JsonIgnore]
|
||||||
|
public IEnumerable<Subnet> Subnets => SkyScanner.Instance.Entities.subnetCollection.Select("Network", Networks.Select(net => net.Network));
|
||||||
|
|
||||||
private HashSet<URI> uris = new HashSet<URI>();
|
private HashSet<URI> uris = new HashSet<URI>();
|
||||||
|
|
||||||
|
@ -87,7 +91,7 @@ namespace ln.skyscanner.entities
|
||||||
|
|
||||||
public NetworkInterface GetInterface(String intfName)
|
public NetworkInterface GetInterface(String intfName)
|
||||||
{
|
{
|
||||||
return SkyScanner.Instance.Entities.interfaceCollection.Where(intf => intf.NodeID.Equals(ID) && intf.Name.Equals(intfName)).FirstOrDefault();
|
return Interfaces.Where(intf => intf.Name.Equals(intfName)).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasInterface(string intfName)
|
public bool HasInterface(string intfName)
|
||||||
|
|
|
@ -13,6 +13,7 @@ using ln.types.odb;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ln.types.net;
|
using ln.types.net;
|
||||||
|
using Newtonsoft.Json;
|
||||||
namespace ln.skyscanner.entities
|
namespace ln.skyscanner.entities
|
||||||
{
|
{
|
||||||
public class Subnet : Persistent
|
public class Subnet : Persistent
|
||||||
|
@ -30,8 +31,10 @@ namespace ln.skyscanner.entities
|
||||||
|
|
||||||
public bool AutoScan { get; set; }
|
public bool AutoScan { get; set; }
|
||||||
|
|
||||||
public IEnumerable<NetworkInterface> AttachedInterfaces => SkyEntities.interfaceCollection.Where((intf) => Network.Contains(intf.ConfiguredIPs.Select((iip)=>iip.IP)));
|
[JsonIgnore]
|
||||||
public IEnumerable<Node> AttachedNodes => AttachedInterfaces.Select(intf => intf.Node).Distinct();
|
public IEnumerable<NetworkInterface> AttachedInterfaces => throw new NotImplementedException();
|
||||||
|
[JsonIgnore]
|
||||||
|
public IEnumerable<Node> AttachedNodes => throw new NotImplementedException();
|
||||||
|
|
||||||
private Subnet()
|
private Subnet()
|
||||||
{
|
{
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
<Compile Include="http\NetworkApi.cs" />
|
<Compile Include="http\NetworkApi.cs" />
|
||||||
<Compile Include="crawl\service\CrawlService.cs" />
|
<Compile Include="crawl\service\CrawlService.cs" />
|
||||||
<Compile Include="crawl\service\TCP.cs" />
|
<Compile Include="crawl\service\TCP.cs" />
|
||||||
<Compile Include="entities\IntfIP.cs" />
|
<Compile Include="entities\ConfiguredIP.cs" />
|
||||||
<Compile Include="crawl\service\HTTP.cs" />
|
<Compile Include="crawl\service\HTTP.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Loading…
Reference in New Issue