From 1177310f7f72d77909710b229398535f8906b7c9 Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Tue, 2 Apr 2019 13:00:15 +0200 Subject: [PATCH] WIP --- Program.cs | 1 + SkyEntities.cs | 11 ++++++----- crawl/service/SNMP.cs | 1 - entities/GlobalNetwork.cs | 30 ++++++++++++------------------ entities/NetworkInterface.cs | 3 ++- entities/Node.cs | 6 ++---- 6 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Program.cs b/Program.cs index 81a754d..8231b83 100644 --- a/Program.cs +++ b/Program.cs @@ -14,6 +14,7 @@ using ln.logging; using ln.skyscanner.entities; using ln.types.threads; using ln.types.net; +using ln.types.odb; namespace ln.skyscanner { diff --git a/SkyEntities.cs b/SkyEntities.cs index 5653667..530a275 100644 --- a/SkyEntities.cs +++ b/SkyEntities.cs @@ -33,14 +33,15 @@ namespace ln.skyscanner odDatabase = new ODB(BasePath); nodeCollection = odDatabase.GetCollection(); - interfaceCollection = odDatabase.GetCollection(); - intfIPCollection = odDatabase.GetCollection(); + //interfaceCollection = odDatabase.GetCollection(); + //intfIPCollection = odDatabase.GetCollection(); subnetCollection = odDatabase.GetCollection(); nodeCollection.EnsureIndex("PrimaryIP"); - interfaceCollection.EnsureIndex("NodeID"); - intfIPCollection.EnsureIndex("interfaceID"); - intfIPCollection.EnsureIndex("Network"); + + //interfaceCollection.EnsureIndex("NodeID"); + //intfIPCollection.EnsureIndex("interfaceID"); + //intfIPCollection.EnsureIndex("Network"); GlobalNetwork = new GlobalNetwork(this); } diff --git a/crawl/service/SNMP.cs b/crawl/service/SNMP.cs index 6fc368e..4e33f72 100644 --- a/crawl/service/SNMP.cs +++ b/crawl/service/SNMP.cs @@ -114,7 +114,6 @@ namespace ln.skyscanner.crawl.tests } catch (TimeoutException) { - return false; } catch (SnmpError) { diff --git a/entities/GlobalNetwork.cs b/entities/GlobalNetwork.cs index c753df9..a032cf0 100644 --- a/entities/GlobalNetwork.cs +++ b/entities/GlobalNetwork.cs @@ -77,13 +77,13 @@ namespace ln.skyscanner.entities { HashSet nodes = new HashSet(); - foreach (Network4 network in node.Networks) - { - foreach (Node neighbor in FindHostsInSubnet(network)) - { - nodes.Add(neighbor); - } - } + //foreach (Network4 network in node.Networks) + //{ + // foreach (Node neighbor in FindHostsInSubnet(network)) + // { + // nodes.Add(neighbor); + // } + //} return nodes; } @@ -160,8 +160,6 @@ namespace ln.skyscanner.entities Logging.Log(e); } } - - //SkyScanner.Entities.DBGlobalNetwork.SavePersistent(SkyScanner.Entities.DBGlobalNetwork.Root); } private void Update(CrawledHost crawledHost) @@ -194,12 +192,13 @@ namespace ln.skyscanner.entities NetworkInterface networkInterface = node.GetInterface(fields[0]); if (networkInterface == null) + { networkInterface = new NetworkInterface(node, fields[0]); + node.Interfaces.Add(networkInterface); + } networkInterface.HWAddress = fields[1]; - SkyEntities.interfaceCollection.Upsert(networkInterface); - IPv4[][] crawledIPs = fields[2].Split(',').Where((sip) => !String.Empty.Equals(sip)) .Select((sip) => sip.Split('/').Select(ip => IPv4.Parse(ip)).ToArray()).ToArray(); @@ -214,7 +213,7 @@ namespace ln.skyscanner.entities if (n == currentIPs.Length) { IntfIP miss = new IntfIP(networkInterface, crawledIP[0], new Network4(crawledIP[0], crawledIP[1])); - SkyEntities.intfIPCollection.Upsert(miss); + networkInterface.ConfiguredIPs.Add(miss); } } @@ -224,7 +223,7 @@ namespace ln.skyscanner.entities if (!crawledIPs.Select((ipl)=>ipl[0]).Contains(ip)) { - SkyEntities.intfIPCollection.Delete(iip); + networkInterface.ConfiguredIPs.Remove(iip); } } } @@ -267,11 +266,6 @@ namespace ln.skyscanner.entities node.Vendor = "Ubiquity"; } - - - - - foreach (Network4 network in node.Networks) EnsureSubnet(network); diff --git a/entities/NetworkInterface.cs b/entities/NetworkInterface.cs index 7147e28..5e68cd8 100644 --- a/entities/NetworkInterface.cs +++ b/entities/NetworkInterface.cs @@ -35,7 +35,8 @@ namespace ln.skyscanner.entities public string Name { get; private set; } = ""; public string HWAddress { get; set; } = ""; - public IEnumerable ConfiguredIPs => SkyScanner.Instance.Entities.intfIPCollection.Select("interfaceID", ID); + public List ConfiguredIPs { get; private set; } = new List(); + //public IEnumerable ConfiguredIPs => SkyScanner.Instance.Entities.intfIPCollection.Select("interfaceID", ID); private NetworkInterface() { } diff --git a/entities/Node.cs b/entities/Node.cs index 6219992..6ed4db0 100644 --- a/entities/Node.cs +++ b/entities/Node.cs @@ -39,11 +39,9 @@ namespace ln.skyscanner.entities public string ProductLine { get; set; } - [JsonIgnore] - public IEnumerable Interfaces => SkyScanner.Instance.Entities.interfaceCollection.Select("NodeID", ID); - [JsonIgnore] + public List Interfaces { get; private set; } = new List(); + public IEnumerable IPAdresses => Interfaces.SelectMany(intf => intf.ConfiguredIPs.Select(nip => nip.IP)); - [JsonIgnore] public IEnumerable Networks => Interfaces.SelectMany(intf => intf.ConfiguredIPs.Select(nip => nip.Network)); private HashSet uris = new HashSet();