antfarm 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/CHANGELOG +9 -0
  2. data/{README → README.rdoc} +39 -5
  3. data/bin/antfarm +37 -4
  4. data/db/migrate/010_create_dns_entries.rb +32 -0
  5. data/db/migrate/011_create_actions.rb +34 -0
  6. data/db/migrate/012_create_services.rb +36 -0
  7. data/db/migrate/013_create_operating_systems.rb +34 -0
  8. data/db/schema.rb +30 -22
  9. data/lib/antfarm.jar +0 -0
  10. data/lib/antfarm.rb +4 -0
  11. data/lib/antfarm/action.rb +29 -0
  12. data/lib/antfarm/dns_entry.rb +23 -0
  13. data/lib/antfarm/ip_interface.rb +38 -26
  14. data/lib/antfarm/ip_network.rb +3 -3
  15. data/lib/antfarm/layer2_interface.rb +16 -3
  16. data/lib/antfarm/layer3_network.rb +4 -4
  17. data/lib/antfarm/node.rb +6 -0
  18. data/lib/antfarm/operating_system.rb +25 -0
  19. data/lib/antfarm/service.rb +25 -0
  20. data/lib/console.rb +9 -0
  21. data/lib/cpscript.rb +70 -0
  22. data/lib/dbmanage.rb +34 -5
  23. data/lib/init/initializer.rb +25 -3
  24. data/lib/scparse.rb +14 -1
  25. data/lib/scripts/cisco/parse-pix-config.rb +5 -14
  26. data/lib/scripts/manipulate-dns.rb +87 -0
  27. data/lib/scripts/nmap/parse-xml.rb +147 -0
  28. data/lib/scripts/pcap/parse-pcap-file.rb +83 -21
  29. data/lib/scripts/viz/display-networks.rb +16 -25
  30. data/lib/scripts/viz/display-traffic.rb +111 -0
  31. data/lib/scripts/viz/dump-graphml.rb +1 -1
  32. data/lib/version.rb +5 -0
  33. data/rails/app/controllers/actions_controller.rb +5 -0
  34. data/rails/app/controllers/dns_entries_controller.rb +4 -0
  35. data/rails/app/controllers/layer3_interfaces_controller.rb +2 -2
  36. data/rails/app/controllers/nodes_controller.rb +4 -4
  37. data/rails/app/controllers/operating_systems_controller.rb +5 -0
  38. data/rails/app/controllers/services_controller.rb +5 -0
  39. data/rails/app/controllers/traffic_controller.rb +1 -0
  40. data/rails/app/views/layouts/application.html.erb +35 -0
  41. data/rails/public/stylesheets/site.css +11 -0
  42. metadata +26 -35
  43. data/lib/scripts/load-route.rb +0 -79
  44. data/lib/scripts/load-router-nomac.rb +0 -60
  45. data/lib/scripts/load-router.rb +0 -59
  46. data/lib/scripts/nmap/parse-xml-results.rb +0 -240
  47. data/lib/scripts/route.rb +0 -89
  48. data/lib/scripts/tethereal/load-arp.rb +0 -67
  49. data/lib/scripts/tethereal/load-ip.rb +0 -65
  50. data/rails/app/helpers/application_helper.rb +0 -3
  51. data/rails/app/helpers/ethernet_interfaces_helper.rb +0 -2
  52. data/rails/app/helpers/ip_interfaces_helper.rb +0 -2
  53. data/rails/app/helpers/ip_networks_helper.rb +0 -2
  54. data/rails/app/helpers/layer2_interfaces_helper.rb +0 -2
  55. data/rails/app/helpers/layer3_interfaces_helper.rb +0 -5
  56. data/rails/app/helpers/layer3_networks_helper.rb +0 -2
  57. data/rails/app/helpers/nodes_helper.rb +0 -2
  58. data/rails/app/helpers/private_networks_helper.rb +0 -2
  59. data/rails/app/helpers/traffic_helper.rb +0 -2
  60. data/rails/app/views/layouts/ethernet_interfaces.html.erb +0 -15
  61. data/rails/app/views/layouts/ip_interfaces.html.erb +0 -15
  62. data/rails/app/views/layouts/ip_networks.html.erb +0 -15
  63. data/rails/app/views/layouts/layer2_interfaces.html.erb +0 -15
  64. data/rails/app/views/layouts/layer3_interfaces.html.erb +0 -15
  65. data/rails/app/views/layouts/layer3_networks.html.erb +0 -15
  66. data/rails/app/views/layouts/nodes.html.erb +0 -15
  67. data/rails/app/views/layouts/private_networks.html.erb +0 -15
  68. data/rails/app/views/layouts/traffic.html.erb +0 -15
  69. data/rails/public/000-index.html +0 -277
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (2008) Sandia Corporation.
4
+ # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
5
+ # the U.S. Government retains certain rights in this software.
6
+ #
7
+ # Original Author: Michael Berg, Sandia National Laboratories <mjberg@sandia.gov>
8
+ # Modified By: Bryan T. Richardson, Sandia National Laboratories <btricha@sandia.gov>
9
+ #
10
+ # This library is free software; you can redistribute it and/or modify it
11
+ # under the terms of the GNU Lesser General Public License as published by
12
+ # the Free Software Foundation; either version 2.1 of the License, or (at
13
+ # your option) any later version.
14
+ #
15
+ # This library is distributed in the hope that it will be useful, but WITHOUT
16
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
+ # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18
+ # details.
19
+ #
20
+ # You should have received a copy of the GNU Lesser General Public License
21
+ # along with this library; if not, write to the Free Software Foundation, Inc.,
22
+ # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
+
24
+ def print_help
25
+ puts "Usage: antfarm [options] viz [options] display-traffic"
26
+ puts
27
+ puts "This script utilizes the provided Prefuse-based Java application"
28
+ puts "to display traffic contained in the current database."
29
+ puts
30
+ puts "Script Options:"
31
+ puts " --collapse-ports Only include one node for each port number"
32
+ puts " discovered."
33
+ end
34
+
35
+ def display(options = [])
36
+ output = File.open("#{Antfarm.tmp_dir_to_use}/traffic.gml", "w")
37
+ output.puts "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
38
+ output.puts "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\">"
39
+ output.puts " <graph edgedefault=\"undirected\">"
40
+ output.puts " <key id=\"name\" for=\"node\" attr.name=\"name\" attr.type=\"string\" />"
41
+ output.puts " <key id=\"type\" for=\"node\" attr.name=\"type\" attr.type=\"string\" />"
42
+ output.puts " <key id=\"line\" for=\"edge\" attr.name=\"line\" attr.type=\"string\" />"
43
+ nodes = Array.new
44
+ ports = Array.new
45
+ Traffic.find(:all).each do |traffic|
46
+ source_node = traffic.source_layer3_interface.layer2_interface.node
47
+ target_node = traffic.target_layer3_interface.layer2_interface.node
48
+ port = traffic.port
49
+ unless nodes.include?(source_node)
50
+ output.puts " <node id=\"node_#{source_node.id}\">"
51
+ output.puts " <data key=\"name\">#{source_node.name.nil? ? source_node.device_type : source_node.name}</data>"
52
+ output.puts " <data key=\"type\">#{source_node.device_type}</data>"
53
+ output.puts " </node>"
54
+ nodes << source_node
55
+ end
56
+ unless nodes.include?(target_node)
57
+ output.puts " <node id=\"node_#{target_node.id}\">"
58
+ output.puts " <data key=\"name\">#{target_node.name.nil? ? target_node.device_type : target_node.name}</data>"
59
+ output.puts " <data key=\"type\">#{target_node.device_type}</data>"
60
+ output.puts " </node>"
61
+ nodes << target_node
62
+ end
63
+ if port.zero?
64
+ output.puts " <edge source=\"node_#{source_node.id}\" target=\"node_#{target_node.id}\">"
65
+ output.puts " <data key=\"line\">#{traffic.description}-PORTLESS</data>"
66
+ output.puts " </edge>"
67
+ else
68
+ if options.include?('--collapse-ports')
69
+ unless ports.include?(port)
70
+ output.puts " <node id=\"port_#{port}\">"
71
+ output.puts " <data key=\"name\">#{port}</data>"
72
+ output.puts " <data key=\"type\">PORT</data>"
73
+ output.puts " </node>"
74
+ ports << port
75
+ end
76
+ output.puts " <edge source=\"node_#{source_node.id}\" target=\"port_#{port}\">"
77
+ output.puts " <data key=\"line\">#{traffic.description}</data>"
78
+ output.puts " </edge>"
79
+ output.puts " <edge source=\"port_#{port}\" target=\"node_#{target_node.id}\">"
80
+ output.puts " <data key=\"line\">#{traffic.description}</data>"
81
+ output.puts " </edge>"
82
+ else
83
+ output.puts " <node id=\"port_#{source_node.id}_#{target_node.id}_#{port}\">"
84
+ output.puts " <data key=\"name\">#{port}</data>"
85
+ output.puts " <data key=\"type\">PORT</data>"
86
+ output.puts " </node>"
87
+ output.puts " <edge source=\"node_#{source_node.id}\" target=\"port_#{source_node.id}_#{target_node.id}_#{port}\">"
88
+ output.puts " <data key=\"line\">#{traffic.description}</data>"
89
+ output.puts " </edge>"
90
+ output.puts " <edge source=\"port_#{source_node.id}_#{target_node.id}_#{port}\" target=\"node_#{target_node.id}\">"
91
+ output.puts " <data key=\"line\">#{traffic.description}</data>"
92
+ output.puts " </edge>"
93
+ end
94
+ end
95
+ end
96
+ output.puts " </graph>"
97
+ output.puts "</graphml>"
98
+ output.close
99
+
100
+ if (defined? USER_DIR) && File.exists?("#{USER_DIR}/config/colors.xml")
101
+ `java -jar #{ANTFARM_ROOT}/lib/antfarm.jar -tree -colors #{USER_DIR}/config/colors.xml #{Antfarm.tmp_dir_to_use}/traffic.gml`
102
+ else
103
+ `java -jar #{ANTFARM_ROOT}/lib/antfarm.jar -tree #{Antfarm.tmp_dir_to_use}/traffic.gml`
104
+ end
105
+ end
106
+
107
+ if ['-h', '--help'].include?(ARGV[0])
108
+ print_help
109
+ else
110
+ display(ARGV)
111
+ end
@@ -201,7 +201,7 @@ def dump(file)
201
201
  end
202
202
 
203
203
  output.puts " <edge source=\"node_#{source_node.id}\" target=\"node_#{target_node.id}\">"
204
- output.puts " <data key=\"line\">PCAP</data>"
204
+ output.puts " <data key=\"line\">#{traffic.description}</data>"
205
205
  output.puts " </edge>"
206
206
  end
207
207
 
@@ -0,0 +1,5 @@
1
+ MAJOR = 0
2
+ MINOR = 4
3
+ REVISION = 0
4
+
5
+ puts "ANTFARM Version #{MAJOR}.#{MINOR}.#{REVISION}"
@@ -0,0 +1,5 @@
1
+ class ActionsController < ApplicationController
2
+ active_scaffold :action do |config|
3
+ config.list.columns = [:tool, :description, :start, :end]
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ class DnsEntriesController < ApplicationController
2
+ active_scaffold :dns_entry do |config|
3
+ end
4
+ end
@@ -1,6 +1,6 @@
1
1
  class Layer3InterfacesController < ApplicationController
2
2
  active_scaffold :layer3_interface do |config|
3
- config.columns << :node
4
- config.list.columns << :node
3
+ # config.columns << :node
4
+ # config.list.columns << :node
5
5
  end
6
6
  end
@@ -1,9 +1,9 @@
1
1
  class NodesController < ApplicationController
2
2
  active_scaffold :node do |config|
3
3
  config.columns[:certainty_factor].label = 'Certainty Factor'
4
- config.create.columns = [:name, :type, :certainty_factor, :layer2_interfaces]
5
- config.list.columns = [:name, :type, :layer2_interfaces]
6
- config.show.columns = [:name, :type, :certainty_factor, :layer2_interfaces]
7
- config.update.columns = [:name, :type, :certainty_factor, :layer2_interfaces]
4
+ config.create.columns = [:name, :device_type, :certainty_factor, :layer2_interfaces]
5
+ config.list.columns = [:name, :device_type, :layer2_interfaces, :services, :operating_system]
6
+ config.show.columns = [:name, :device_type, :certainty_factor, :layer2_interfaces]
7
+ config.update.columns = [:name, :device_type, :certainty_factor, :layer2_interfaces]
8
8
  end
9
9
  end
@@ -0,0 +1,5 @@
1
+ class OperatingSystemsController < ApplicationController
2
+ active_scaffold :operating_system do |config|
3
+ config.list.columns = [:fingerprint, :certainty_factor, :node, :action]
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ServicesController < ApplicationController
2
+ active_scaffold :service do |config|
3
+ config.list.columns = [:name, :protocol, :port, :certainty_factor, :node, :action]
4
+ end
5
+ end
@@ -1,4 +1,5 @@
1
1
  class TrafficController < ApplicationController
2
2
  active_scaffold :traffic do |config|
3
+ config.label = 'Traffic'
3
4
  end
4
5
  end
@@ -0,0 +1,35 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
7
+ <title>ANTFARM :: Database Management</title>
8
+ <%= stylesheet_link_tag 'site' %>
9
+ <%= javascript_include_tag :defaults %>
10
+ <%= active_scaffold_includes %>
11
+ </head>
12
+ <body>
13
+ <center><h1>ANTFARM Database Management</h1></center>
14
+ <%= yield %>
15
+ <center>
16
+ <div id='management-nav'>
17
+ <%= link_to 'Nodes', '/nodes' %> |
18
+ <%= link_to 'Layer 2 Interfaces', '/layer2_interfaces' %> |
19
+ <%= link_to 'Ethernet Interfaces', '/ethernet_interfaces' %> |
20
+ <%= link_to 'Layer 3 Interfaces', '/layer3_interfaces' %> |
21
+ <%= link_to 'IP Interfaces', '/ip_interfaces' %>
22
+ <br />
23
+ <%= link_to 'Layer 3 Networks', '/layer3_networks' %> |
24
+ <%= link_to 'IP Networks', '/ip_networks' %> |
25
+ <%= link_to 'Private Networks', '/private_networks' %> |
26
+ <%= link_to 'Traffic', '/traffic' %>
27
+ <br />
28
+ <%= link_to 'DNS Entries', '/dns_entries' %> |
29
+ <%= link_to 'Actions', '/actions' %> |
30
+ <%= link_to 'Services', '/services' %> |
31
+ <%= link_to 'Operating Systems', '/operating_systems' %>
32
+ </div>
33
+ </center>
34
+ </body>
35
+ </html>
@@ -0,0 +1,11 @@
1
+ div#management-nav a {
2
+ color:#665;
3
+ font-weight:bold;
4
+ text-decoration:none;
5
+ font-size:small;
6
+ }
7
+
8
+ div#management-nav a:hover {
9
+ color:#665;
10
+ background-color:#fff;
11
+ }
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: antfarm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
- - Michael Berg & Bryan Richardson
7
+ - Michael Berg and Bryan Richardson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-15 00:00:00 -06:00
12
+ date: 2008-10-02 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,66 +33,72 @@ dependencies:
33
33
  version: 1.2.2
34
34
  version:
35
35
  description:
36
- email: btricha@sandia.gov & mjberg@sandia.gov
36
+ email: btricha@sandia.gov and mjberg@sandia.gov
37
37
  executables:
38
38
  - antfarm
39
39
  extensions: []
40
40
 
41
41
  extra_rdoc_files:
42
- - README
42
+ - README.rdoc
43
43
  files:
44
44
  - bin/antfarm
45
45
  - config/environment.rb
46
46
  - config/boot.rb
47
47
  - db/schema.rb
48
48
  - db/migrate
49
+ - db/migrate/012_create_services.rb
49
50
  - db/migrate/002_create_layer2_interfaces.rb
50
51
  - db/migrate/007_create_ip_networks.rb
52
+ - db/migrate/013_create_operating_systems.rb
51
53
  - db/migrate/005_create_ethernet_interfaces.rb
52
54
  - db/migrate/004_create_layer3_networks.rb
53
55
  - db/migrate/009_create_traffic.rb
54
56
  - db/migrate/003_create_layer3_interfaces.rb
57
+ - db/migrate/011_create_actions.rb
55
58
  - db/migrate/006_create_ip_interfaces.rb
56
59
  - db/migrate/008_create_private_networks.rb
60
+ - db/migrate/010_create_dns_entries.rb
57
61
  - db/migrate/001_create_nodes.rb
58
62
  - lib/antfarm.rb
63
+ - lib/cpscript.rb
64
+ - lib/console.rb
59
65
  - lib/antfarm
60
66
  - lib/antfarm/private_network.rb
67
+ - lib/antfarm/operating_system.rb
61
68
  - lib/antfarm/ethernet_interface.rb
69
+ - lib/antfarm/dns_entry.rb
62
70
  - lib/antfarm/layer2_interface.rb
71
+ - lib/antfarm/service.rb
63
72
  - lib/antfarm/ip_network.rb
64
73
  - lib/antfarm/layer3_interface.rb
65
74
  - lib/antfarm/layer3_network.rb
66
75
  - lib/antfarm/node.rb
67
76
  - lib/antfarm/ip_interface.rb
68
77
  - lib/antfarm/traffic.rb
78
+ - lib/antfarm/action.rb
79
+ - lib/version.rb
69
80
  - lib/init
70
81
  - lib/init/initializer.rb
71
82
  - lib/scparse.rb
72
83
  - lib/dbmanage.rb
73
84
  - lib/scripts
74
85
  - lib/scripts/load-network.rb
75
- - lib/scripts/load-router.rb
76
- - lib/scripts/load-route.rb
77
- - lib/scripts/route.rb
78
86
  - lib/scripts/load-host.rb
79
87
  - lib/scripts/pcap
80
88
  - lib/scripts/pcap/parse-pcap-file.rb
81
89
  - lib/scripts/nmap
82
- - lib/scripts/nmap/parse-xml-results.rb
90
+ - lib/scripts/nmap/parse-xml.rb
83
91
  - lib/scripts/cisco
84
92
  - lib/scripts/cisco/parse-routes.rb
85
93
  - lib/scripts/cisco/parse-pix-config.rb
86
94
  - lib/scripts/cisco/parse-ip-ifaces.rb
87
95
  - lib/scripts/cisco/parse-network-objects.rb
88
96
  - lib/scripts/cisco/parse-arp.rb
89
- - lib/scripts/tethereal
90
- - lib/scripts/tethereal/load-ip.rb
91
- - lib/scripts/tethereal/load-arp.rb
92
- - lib/scripts/load-router-nomac.rb
97
+ - lib/scripts/manipulate-dns.rb
93
98
  - lib/scripts/viz
94
99
  - lib/scripts/viz/display-networks.rb
95
100
  - lib/scripts/viz/dump-graphviz.rb
101
+ - lib/scripts/viz/display-traffic.rb
96
102
  - lib/scripts/viz/dump-graphml.rb
97
103
  - lib/antfarm.jar
98
104
  - log/antfarm.log
@@ -130,6 +136,7 @@ files:
130
136
  - rails/public/422.html
131
137
  - rails/public/dispatch.cgi
132
138
  - rails/public/stylesheets
139
+ - rails/public/stylesheets/site.css
133
140
  - rails/public/stylesheets/active_scaffold
134
141
  - rails/public/stylesheets/active_scaffold/default
135
142
  - rails/public/stylesheets/active_scaffold/default/stylesheet-ie.css
@@ -137,42 +144,26 @@ files:
137
144
  - rails/public/stylesheets/active_scaffold/DO_NOT_EDIT
138
145
  - rails/public/blank.html
139
146
  - rails/public/robots.txt
140
- - rails/public/000-index.html
141
147
  - rails/public/500.html
142
148
  - rails/app
143
- - rails/app/helpers
144
- - rails/app/helpers/application_helper.rb
145
- - rails/app/helpers/ethernet_interfaces_helper.rb
146
- - rails/app/helpers/ip_interfaces_helper.rb
147
- - rails/app/helpers/layer2_interfaces_helper.rb
148
- - rails/app/helpers/nodes_helper.rb
149
- - rails/app/helpers/layer3_interfaces_helper.rb
150
- - rails/app/helpers/ip_networks_helper.rb
151
- - rails/app/helpers/traffic_helper.rb
152
- - rails/app/helpers/private_networks_helper.rb
153
- - rails/app/helpers/layer3_networks_helper.rb
154
149
  - rails/app/controllers
155
150
  - rails/app/controllers/ip_interfaces_controller.rb
151
+ - rails/app/controllers/operating_systems_controller.rb
156
152
  - rails/app/controllers/application.rb
157
153
  - rails/app/controllers/nodes_controller.rb
158
154
  - rails/app/controllers/ip_networks_controller.rb
155
+ - rails/app/controllers/dns_entries_controller.rb
156
+ - rails/app/controllers/services_controller.rb
159
157
  - rails/app/controllers/layer3_interfaces_controller.rb
160
158
  - rails/app/controllers/layer2_interfaces_controller.rb
159
+ - rails/app/controllers/actions_controller.rb
161
160
  - rails/app/controllers/traffic_controller.rb
162
161
  - rails/app/controllers/private_networks_controller.rb
163
162
  - rails/app/controllers/layer3_networks_controller.rb
164
163
  - rails/app/controllers/ethernet_interfaces_controller.rb
165
164
  - rails/app/views
166
165
  - rails/app/views/layouts
167
- - rails/app/views/layouts/layer3_interfaces.html.erb
168
- - rails/app/views/layouts/layer2_interfaces.html.erb
169
- - rails/app/views/layouts/nodes.html.erb
170
- - rails/app/views/layouts/layer3_networks.html.erb
171
- - rails/app/views/layouts/ip_networks.html.erb
172
- - rails/app/views/layouts/ethernet_interfaces.html.erb
173
- - rails/app/views/layouts/traffic.html.erb
174
- - rails/app/views/layouts/private_networks.html.erb
175
- - rails/app/views/layouts/ip_interfaces.html.erb
166
+ - rails/app/views/layouts/application.html.erb
176
167
  - rails/vendor
177
168
  - rails/vendor/rails
178
169
  - rails/vendor/rails/railties
@@ -2091,7 +2082,7 @@ files:
2091
2082
  - tmp/useless.txt
2092
2083
  - CHANGELOG
2093
2084
  - LICENSE
2094
- - README
2085
+ - README.rdoc
2095
2086
  has_rdoc: true
2096
2087
  homepage: http://antfarm.rubyforge.org
2097
2088
  post_install_message:
@@ -1,79 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- # Copyright (2008) Sandia Corporation.
4
- # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
5
- # the U.S. Government retains certain rights in this software.
6
- #
7
- # Original Author: Michael Berg, Sandia National Laboratories <mjberg@sandia.gov>
8
- # Modified By: Bryan T. Richardson, Sandia National Laboratories <btricha@sandia.gov>
9
- #
10
- # This library is free software; you can redistribute it and/or modify it
11
- # under the terms of the GNU Lesser General Public License as published by
12
- # the Free Software Foundation; either version 2.1 of the License, or (at
13
- # your option) any later version.
14
- #
15
- # This library is distributed in the hope that it will be useful, but WITHOUT
16
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
- # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18
- # details.
19
- #
20
- # You should have received a copy of the GNU Lesser General Public License
21
- # along with this library; if not, write to the Free Software Foundation, Inc.,
22
- # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
-
24
- def insert(addr_path)
25
- path = Array.new
26
- node_path = Array.new
27
-
28
- # Insert the nodes
29
- for addr in addr_path
30
- if addr
31
- iface = Hash.new
32
- # Insert IP address
33
- ip_if = IpInterface.create(:address => addr)
34
- # Store the needed information for the next step
35
- iface['ip_interface'] = ip_if
36
- iface['ip_network'] = ip_if.layer3_interface.layer3_network.ip_network
37
- iface['node'] = ip_if.layer3_interface.layer2_interface.node
38
- path.push(iface)
39
- node_path.push(ip_if.layer3_interface.layer2_interface.node)
40
- end
41
- end
42
-
43
- # Insert the edges
44
- for i in 0..(path.size - 2)
45
- u = path[i]
46
- v = path[i + 1]
47
- if u and v
48
- # Get nodes connected to the IP network
49
- connected_nodes = Array.new
50
- v['ip_network'].layer3_network.layer3_interfaces.each do |l3_if|
51
- connected_nodes << l3_if.layer2_interface.node
52
- end
53
- unless connected_nodes.include?(u['node'])
54
- # Create a new Layer2_Interface for the Node
55
- layer2_if_id = @layer2_if_table.insert(CF_LACK_OF_PROOF, nil,
56
- u['node_id'])
57
- # Connect a new "unknown" Layer3_Interface that
58
- # is connected to the specified layer3_net_id
59
- @layer3_if_table.insert(CF_LACK_OF_PROOF, "IP",
60
- v['ip_network_id'], layer2_if_id)
61
-
62
- end
63
- end
64
- end
65
-
66
- return node_id_path
67
- end
68
-
69
- def parse
70
- path = ['146.146.161.250', '146.146.150.6']
71
- insert(path)
72
-
73
- path = ['146.146.161.250', '146.146.151.224']
74
- insert(path)
75
-
76
- path = ['146.146.161.253', '146.146.252.185', '146.146.111.253',
77
- '146.146.249.202', '209.64.200.65', '146.146.4.11']
78
- insert(path)
79
- end