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.net;
|
||||
using ln.types.odb;
|
||||
using ln.types.odb.index;
|
||||
|
||||
namespace ln.skyscanner
|
||||
{
|
||||
|
@ -38,16 +39,25 @@ namespace ln.skyscanner
|
|||
skyScanner.Start();
|
||||
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)
|
||||
{
|
||||
Console.WriteLine("INTF-IP: {0}", iip);
|
||||
}
|
||||
SkyScanner.Instance.Stop();
|
||||
|
||||
return;
|
||||
|
||||
IEnumerable<Node> nodes = skyScanner.Entities.nodeCollection;
|
||||
foreach (Node node in nodes)
|
||||
|
|
|
@ -23,8 +23,8 @@ namespace ln.skyscanner
|
|||
public GlobalNetwork GlobalNetwork { get; private set; }
|
||||
public ODB odDatabase { get; private set; }
|
||||
public ODBCollection<Node> nodeCollection { get; private set; }
|
||||
public ODBCollection<NetworkInterface> interfaceCollection { get; private set; }
|
||||
public ODBCollection<IntfIP> intfIPCollection { get; private set; }
|
||||
//public ODBCollection<NetworkInterface> interfaceCollection { get; private set; }
|
||||
//public ODBCollection<IntfIP> intfIPCollection { get; private set; }
|
||||
public ODBCollection<Subnet> subnetCollection { get; private set; }
|
||||
|
||||
public SkyEntities(SkyScanner skyScanner)
|
||||
|
@ -33,15 +33,13 @@ namespace ln.skyscanner
|
|||
|
||||
odDatabase = new ODB(BasePath);
|
||||
nodeCollection = odDatabase.GetCollection<Node>();
|
||||
//interfaceCollection = odDatabase.GetCollection<NetworkInterface>();
|
||||
//intfIPCollection = odDatabase.GetCollection<IntfIP>();
|
||||
subnetCollection = odDatabase.GetCollection<Subnet>();
|
||||
|
||||
nodeCollection.EnsureIndex("PrimaryIP");
|
||||
nodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].IP");
|
||||
nodeCollection.EnsureIndex("Interfaces[].ConfiguredIPs[].Network");
|
||||
|
||||
//interfaceCollection.EnsureIndex("NodeID");
|
||||
//intfIPCollection.EnsureIndex("interfaceID");
|
||||
//intfIPCollection.EnsureIndex("Network");
|
||||
subnetCollection.EnsureIndex("Network");
|
||||
|
||||
GlobalNetwork = new GlobalNetwork(this);
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ namespace ln.skyscanner.crawl
|
|||
}
|
||||
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)
|
||||
{
|
||||
Logging.Log(LogLevel.INFO, "Crawler adds new subnet: {0}",network);
|
||||
|
|
|
@ -14,25 +14,19 @@ using Newtonsoft.Json;
|
|||
using ln.types.net;
|
||||
namespace ln.skyscanner.entities
|
||||
{
|
||||
public class IntfIP
|
||||
public class ConfiguredIP
|
||||
{
|
||||
[DocumentID]
|
||||
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 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;
|
||||
Network = network;
|
||||
}
|
|
@ -65,25 +65,29 @@ namespace ln.skyscanner.entities
|
|||
|
||||
public IEnumerable<Node> FindHostsInSubnet(Network4 network)
|
||||
{
|
||||
IntfIP[] intfIPs = SkyEntities.intfIPCollection.Select("Network",network).ToArray();
|
||||
NetworkInterface[] networkInterfaces = intfIPs.Select((iip) => iip.NetworkInterface).ToArray();
|
||||
|
||||
Node[] nodes = SkyEntities.nodeCollection.Select(networkInterfaces.Select((ni) => new ODBGuid(ni.NodeID))).ToArray();
|
||||
|
||||
return nodes;
|
||||
Query nodeByIpQuery = Query.Equals<Node>("Interfaces[].ConfiguredIPs[].Network", network);
|
||||
return SkyEntities.nodeCollection.Select(nodeByIpQuery);
|
||||
}
|
||||
|
||||
public IEnumerable<Node> FindNeighbors(Node node)
|
||||
{
|
||||
HashSet<Node> nodes = new HashSet<Node>();
|
||||
|
||||
//foreach (Network4 network in node.Networks)
|
||||
//{
|
||||
// foreach (Node neighbor in FindHostsInSubnet(network))
|
||||
// {
|
||||
// nodes.Add(neighbor);
|
||||
// }
|
||||
//}
|
||||
if (node.Interfaces.Count > 0)
|
||||
{
|
||||
foreach (Network4 network in node.Networks)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -98,24 +102,14 @@ namespace ln.skyscanner.entities
|
|||
}
|
||||
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)
|
||||
{
|
||||
Node node = SkyEntities.nodeCollection.SelectOne("PrimaryIP", ip);
|
||||
if (node == null)
|
||||
{
|
||||
|
||||
Query nodeByIpQuery = Query.Equals<Node>("Interfaces[].ConfiguredIPs[].IP", ip);
|
||||
node = SkyEntities.nodeCollection.Select(nodeByIpQuery).FirstOrDefault();
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
@ -193,7 +187,7 @@ namespace ln.skyscanner.entities
|
|||
NetworkInterface networkInterface = node.GetInterface(fields[0]);
|
||||
if (networkInterface == null)
|
||||
{
|
||||
networkInterface = new NetworkInterface(node, fields[0]);
|
||||
networkInterface = new NetworkInterface(fields[0]);
|
||||
node.Interfaces.Add(networkInterface);
|
||||
}
|
||||
|
||||
|
@ -202,7 +196,7 @@ namespace ln.skyscanner.entities
|
|||
IPv4[][] crawledIPs = fields[2].Split(',').Where((sip) => !String.Empty.Equals(sip))
|
||||
.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)
|
||||
{
|
||||
|
@ -212,12 +206,12 @@ namespace ln.skyscanner.entities
|
|||
break;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (IntfIP iip in currentIPs)
|
||||
foreach (ConfiguredIP iip in currentIPs)
|
||||
{
|
||||
IPv4 ip = iip.IP;
|
||||
|
||||
|
|
|
@ -22,34 +22,23 @@ namespace ln.skyscanner.entities
|
|||
{
|
||||
[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);
|
||||
public List<ConfiguredIP> ConfiguredIPs { get; private set; } = new List<ConfiguredIP>();
|
||||
|
||||
private NetworkInterface()
|
||||
{ }
|
||||
|
||||
public NetworkInterface(Node node,String name)
|
||||
public NetworkInterface(String name)
|
||||
{
|
||||
Node = node;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public bool HasIP(IPv4 ip)
|
||||
{
|
||||
foreach (IntfIP ifip in ConfiguredIPs)
|
||||
foreach (ConfiguredIP ifip in ConfiguredIPs)
|
||||
{
|
||||
if (ifip.IP.Equals(ip))
|
||||
return true;
|
||||
|
@ -60,11 +49,7 @@ namespace ln.skyscanner.entities
|
|||
|
||||
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;
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
@ -72,14 +57,14 @@ namespace ln.skyscanner.entities
|
|||
if (obj is 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;
|
||||
}
|
||||
|
||||
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>();
|
||||
|
||||
[JsonIgnore]
|
||||
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>();
|
||||
|
||||
|
@ -87,7 +91,7 @@ namespace ln.skyscanner.entities
|
|||
|
||||
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)
|
||||
|
|
|
@ -13,6 +13,7 @@ using ln.types.odb;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ln.types.net;
|
||||
using Newtonsoft.Json;
|
||||
namespace ln.skyscanner.entities
|
||||
{
|
||||
public class Subnet : Persistent
|
||||
|
@ -30,8 +31,10 @@ namespace ln.skyscanner.entities
|
|||
|
||||
public bool AutoScan { get; set; }
|
||||
|
||||
public IEnumerable<NetworkInterface> AttachedInterfaces => SkyEntities.interfaceCollection.Where((intf) => Network.Contains(intf.ConfiguredIPs.Select((iip)=>iip.IP)));
|
||||
public IEnumerable<Node> AttachedNodes => AttachedInterfaces.Select(intf => intf.Node).Distinct();
|
||||
[JsonIgnore]
|
||||
public IEnumerable<NetworkInterface> AttachedInterfaces => throw new NotImplementedException();
|
||||
[JsonIgnore]
|
||||
public IEnumerable<Node> AttachedNodes => throw new NotImplementedException();
|
||||
|
||||
private Subnet()
|
||||
{
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
<Compile Include="http\NetworkApi.cs" />
|
||||
<Compile Include="crawl\service\CrawlService.cs" />
|
||||
<Compile Include="crawl\service\TCP.cs" />
|
||||
<Compile Include="entities\IntfIP.cs" />
|
||||
<Compile Include="entities\ConfiguredIP.cs" />
|
||||
<Compile Include="crawl\service\HTTP.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Reference in New Issue