Class: Scriptroute::Tulip::AliasResolution
- Inherits:
-
Object
- Object
- Scriptroute::Tulip::AliasResolution
- Defined in:
- lib/scriptroute/tulip/helper.rb
Overview
alias resolution: ally + ttl-testing + result cache #######
Constant Summary collapse
- @@aliasCache =
Hash.new(-1)
- @@logAllyResults =
false
- @@doTTLTesting =
false
- @@seqIPIDCache =
Hash.new(-1)
- @@ally =
(FileTest.executable?("/usr/bin/sr-ally"))? "/usr/bin/sr-ally" : "/usr/local/bin/sr-ally"
Class Method Summary collapse
- .aliases(hop1, hop2) ⇒ Object
- .before(seq1, seq2) ⇒ Object
- .cacheKey(ip1, ip2) ⇒ Object
- .seqIPID(thop) ⇒ Object
- .ttlBasedTest(hop1, hop2) ⇒ Object
Class Method Details
.aliases(hop1, hop2) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/scriptroute/tulip/helper.rb', line 198 def AliasResolution.aliases (hop1, hop2) key = cacheKey(hop1.ip, hop2.ip); return @@aliasCache[key] if (@@aliasCache[key] != -1) output = `#{@@ally} #{hop1.ip} #{hop2.ip}` output.gsub!(/\n/, " "); Kernel::system("echo '#{hop1.ip} #{hop2.ip} #{output}' >> ally.stats") if (@@logAllyResults); if (/ALIAS/.match(output) && !/NOT/.match(output)) then @@aliasCache[key] = true; return true; elsif (@@doTTLTesting and /UNKNOWN/.match(output)) then ttlSays = ttlBasedTest(hop1, hop2); Kernel::system("echo 'ttlTest: #{hop1} #{hop2} #{ttlSays}' >> ally.stats") if (@@logAllyResults); return ttlSays[0]; else @@aliasCache[key] = false; return false; end end |
.before(seq1, seq2) ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/scriptroute/tulip/helper.rb', line 266 def AliasResolution.before(seq1,seq2) diff = seq1-seq2 # emulate signed short arithmetic. if (diff > 32767) then diff-=65535; elsif (diff < -32768) then diff+=65535; end # puts "#{seq1} #{diff < 0 ? "" : "not"} before #{seq2}\n" (diff < 0) end |
.cacheKey(ip1, ip2) ⇒ Object
194 195 196 |
# File 'lib/scriptroute/tulip/helper.rb', line 194 def AliasResolution.cacheKey (ip1, ip2) (ip1 < ip2)? "#{ip1}:#{ip2}" : "#{ip2}:#{ip1}"; end |
.seqIPID(thop) ⇒ Object
219 220 221 222 223 224 225 226 |
# File 'lib/scriptroute/tulip/helper.rb', line 219 def AliasResolution.seqIPID (thop) if (@@seqIPIDCache["#{thop.dst} #{thop.hop}"] == -1) @@seqIPIDCache["#{thop.dst} #{thop.hop}"] = LangChecker.increasingIPIDs(thop.dst, thop.hop, "udp"); puts "seqIPID results for #{thop.dst} #{thop.hop} is %s\n" % [@@seqIPIDCache["#{thop.dst} #{thop.hop}"]]; end return @@seqIPIDCache["#{thop.dst} #{thop.hop}"]; end |
.ttlBasedTest(hop1, hop2) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/scriptroute/tulip/helper.rb', line 229 def AliasResolution.ttlBasedTest (hop1, hop2) return [false, "non-seq-ipid"] if (!seqIPID(hop1) or !seqIPID(hop2)); a = Scriptroute::UDP.new(12) b = Scriptroute::UDP.new(12) a.ip_dst, a.ip_ttl = hop1.dst, hop1.hop; b.ip_dst, b.ip_ttl = hop2.dst, hop2.hop; packets = Scriptroute::send_train([ Struct::DelayedPacket.new(0,a), Struct::DelayedPacket.new(0.001,b) ]) return [false, "insufficient info"] if (!packets[0] || !packets[1] || !packets[0].response || !packets[1].response || packets[0].response.packet.ip_src != hop1.ip || packets[1].response.packet.ip_src != hop2.ip); id0 = packets[0].response.packet.ip_id id1 = packets[1].response.packet.ip_id return [false, "ids dont match"] if (!before(id0-10, id1) || !before(id1, id0+200) || id0 == id1); packetz = Scriptroute::send_train([ Struct::DelayedPacket.new(0,b), Struct::DelayedPacket.new(0.001,a) ]) return [false, "insufficient info2"] if (!packetz[0] || !packetz[1] || !packetz[0].response || !packetz[1].response || packetz[0].response.packet.ip_src != hop2.ip || packetz[1].response.packet.ip_src != hop1.ip); id2 = packets[0].response.packet.ip_id id3 = packets[1].response.packet.ip_id return [true, "excellent"] if(before(id2-10, id3) && before(id3, id2+200) && id3 != id2 && before(id0, id2) && before(id1, id3) && id2 != id1 && id2 != id0 && id3 != id1 && id3 != id0 ); return [false, "final failure"]; end |