The unified diff between revisions [19d4693b..] and [ea8ef2d2..] is displayed below. It can also be downloaded as a raw diff.

#
#
# add_file "iputils.py"
#  content [d10413b7982a049c60d75ad671bae620f8ccd250]
#
# patch "plugins/basic_snmp.py"
#  from [70769aabb99d393217f8760c13214b38696921ed]
#    to [f4361556222d4ff31fc9a0693b384723c24677ed]
#
# patch "plugins/cisco_ios.py"
#  from [435cb5aa7252bf973200b392a7465de7321766a8]
#    to [c22b8cbe73befe343ea39b472c8929b7f678276b]
#
#   set "iputils.py"
#  attr "mtn:execute"
# value "true"
#
============================================================
--- iputils.py	d10413b7982a049c60d75ad671bae620f8ccd250
+++ iputils.py	d10413b7982a049c60d75ad671bae620f8ccd250
@@ -0,0 +1,63 @@
+#!/usr/bin/env python2.1
+
+# iputils.py
+#
+# Author: Grahame Bowland <grahame@ucs.uwa.edu.au>
+# License: GNU GPL
+
+import sys
+import socket
+
+class Network:
+    def __init__(self, address, mask):
+        self.address = address
+        self.mask = mask
+    def is_in(self, ip):
+        # is "ip" within our network
+        c1 = ip & self.mask
+        c2 = self.address & self.mask
+	# 130.95.0.0 & 255.255.255.0 = 130.95.0.0
+	# 130.95.2.0 & 255.255.255.0 = 130.95.2.0
+        if c1 == c2:
+            if c1 == 0 and self.address <> ip:
+                # /32 route and not equal host addresses
+                return 0
+            return 1
+        else:
+            return 0
+
+def ip_to_int(str, invert = 0):
+    quads = str.split(".")
+    if len(quads) <> 4:
+        print "Invalid ip:", str
+        sys.exit(1)
+    rv = 0
+    m = long(1)
+    for i in range(len(quads)):
+        cval = int(quads[3-i])
+        if invert:
+            cval = cval ^ 255
+        if cval > 255 or cval < 0:
+            print "Invalid ip; contains section out of bounds at index %d : %s"\
+                % (4-i, str)
+        rv = rv + (m * cval)
+        m = m * 256
+    return rv
+
+def int_to_length(ip_int):
+	len = 0
+	while ip_int > 0:
+		if ip_int % 2: break
+		ip_int /= 2
+		len += 1
+	return 32 - len
+
+def network_from_ip(ip, mask):
+   pip = ip_to_int(ip)
+   pmask = ip_to_int(mask)
+   return Network(pip, pmask)
+
+if __name__ == "__main__":
+    a = network_from_ip("130.95.2.0", "255.255.255.0")
+    print a.is_in(ip_to_int("130.95.0.0"))
+
============================================================
--- plugins/basic_snmp.py	70769aabb99d393217f8760c13214b38696921ed
+++ plugins/basic_snmp.py	f4361556222d4ff31fc9a0693b384723c24677ed
@@ -44,11 +44,7 @@ def ip_routing(hostname, community):
 		if ifindex: ifindex = int(ifindex)
 		yield route_type, ifindex, False, network, via, metric

-def ethernet_forwarding(table_name, table_io, device):
-    yield device.config['zone'], 1, '00:11:24:c7:dd:41', 'en1'
-
 tables = {
-    'ethernet_forwarding' : ethernet_forwarding,
     'ip_arp' : ip_arp,
     'ip_routing' : ip_routing,
 }
============================================================
--- plugins/cisco_ios.py	435cb5aa7252bf973200b392a7465de7321766a8
+++ plugins/cisco_ios.py	c22b8cbe73befe343ea39b472c8929b7f678276b
@@ -2,6 +2,11 @@ from basic_snmp import ip_arp, ethernet_
 from basic_snmp import ip_arp, ethernet_forwarding


+# see: http://www.cisco.com/en/US/tech/tk648/tk362/technologies_tech_note09186a0080094a9b.shtml
+def ethernet_forwarding(table_name, table_io, device):
+    yield device.config['zone'], 1, '00:11:24:c7:dd:41', 'en1'
+
+
 tables = {
     'ethernet_forwarding' : ethernet_forwarding,
     'ip_arp' : ip_arp,