aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-12-19 02:55:39 +0000
committerRob Austein <sra@hactrn.net>2007-12-19 02:55:39 +0000
commit963943740c13518f09caffb33551cb86072bbec8 (patch)
tree4eeabe06b272dc02c268bbd6c81f33c7d1d61735
parent7177a7ac05e04d365985f87e3376aaef353f193e (diff)
Start on YAML-based configuration generator for test scripts.
svn path=/scripts/biz-certs/Bob-CA.srl; revision=1390
-rw-r--r--scripts/biz-certs/Bob-CA.srl2
-rw-r--r--scripts/rpki/resource_set.py15
-rw-r--r--scripts/testdb.py53
-rw-r--r--scripts/testdb1.yaml28
-rw-r--r--scripts/testdb2.yaml68
5 files changed, 162 insertions, 4 deletions
diff --git a/scripts/biz-certs/Bob-CA.srl b/scripts/biz-certs/Bob-CA.srl
index b1a226d2..cbd724ba 100644
--- a/scripts/biz-certs/Bob-CA.srl
+++ b/scripts/biz-certs/Bob-CA.srl
@@ -1 +1 @@
-90801F1ED1945550
+90801F1ED1945551
diff --git a/scripts/rpki/resource_set.py b/scripts/rpki/resource_set.py
index 795c695d..ab2d3891 100644
--- a/scripts/rpki/resource_set.py
+++ b/scripts/rpki/resource_set.py
@@ -129,7 +129,7 @@ class resource_set(list):
def __init__(self, ini = None):
"""Initialize a resource_set."""
- if isinstance(ini, long):
+ if isinstance(ini, int) or isinstance(ini, long):
ini = str(ini)
if ini == inherit_token:
self.inherit = True
@@ -140,7 +140,7 @@ class resource_set(list):
elif isinstance(ini, list):
self.extend(ini)
else:
- assert ini is None or ini == ""
+ assert ini is None or ini == "", "Unexpected initializer: %s" % str(ini)
assert not self.inherit or not self
self.sort()
if __debug__:
@@ -189,7 +189,7 @@ class resource_set(list):
def union(self, other):
"""Set union for resource sets."""
assert not self.inherit
- assert type(self) is type(other)
+ assert type(self) is type(other), "Type mismatch: %s %s" % (repr(type(self)), repr(type(other)))
set1 = self[:]
set2 = other[:]
result = []
@@ -442,6 +442,15 @@ class resource_bag(object):
self.v6.intersection(other.v6),
self.valid_until)
+ def union(self, other):
+ """Compute union with another resource_bag.
+ valid_until attribute (if any) inherits from self.
+ """
+ return self.__class__(self.as.union(other.as),
+ self.v4.union(other.v4),
+ self.v6.union(other.v6),
+ self.valid_until)
+
# Test suite for set operations. This will probably go away eventually
if __name__ == "__main__":
diff --git a/scripts/testdb.py b/scripts/testdb.py
new file mode 100644
index 00000000..c57fcd58
--- /dev/null
+++ b/scripts/testdb.py
@@ -0,0 +1,53 @@
+# $Id$
+
+import rpki.resource_set, os, yaml
+
+class allocation(object):
+
+ parent = None
+
+ def __init__(self, yaml, parent = None):
+ self.name = yaml["name"]
+ self.parent = parent
+ self.kids = [allocation(k, self) for k in yaml.get("kids", ())]
+ self.base = rpki.resource_set.resource_bag(
+ as = rpki.resource_set.resource_set_as(yaml.get("asn")),
+ v4 = rpki.resource_set.resource_set_ipv4(yaml.get("ipv4")),
+ v6 = rpki.resource_set.resource_set_ipv6(yaml.get("ipv6")))
+
+ def closure(self):
+ """Compute the transitive resource closure for one resource attribute."""
+ resources = self.base
+ for kid in self.kids:
+ resources = resources.union(kid.closure())
+ self.resources = resources
+ return resources
+
+ def flatten(self):
+ """Return a list of self and kids."""
+ ret = [self]
+ for kid in self.kids:
+ ret.extend(kid.flatten())
+ return ret
+
+ def is_leaf(self):
+ return not self.kids
+
+ def is_root(self):
+ return self.parent is None
+
+ def __str__(self):
+ return "%s\n ASN: %s\n IPv4: %s\n IPv6: %s\n Kids: %s\n" \
+ % (self.name,
+ self.resources.as, self.resources.v4, self.resources.v6,
+ ", ".join(k.name for k in self.kids))
+
+f = open("testdb2.yaml")
+y = yaml.safe_load(f)
+f.close()
+
+root = allocation(y)
+root.closure()
+
+for i in root.flatten():
+ print i
diff --git a/scripts/testdb1.yaml b/scripts/testdb1.yaml
new file mode 100644
index 00000000..e388898b
--- /dev/null
+++ b/scripts/testdb1.yaml
@@ -0,0 +1,28 @@
+# $Id$
+
+name: RIR
+children:
+ - name: LIR1
+ children:
+ - name: ISP1
+ ipv4: 192.0.2.1-192.0.2.33
+ asn: 64533
+ - name: ISP2
+ ipv4: 192.0.2.44-192.0.2.100
+ - name: LIR2
+ children:
+ - name: ISP3
+ ipv6: 2001:db8::44-2001:db8::100
+ - name: ISP4
+ ipv6: 2001:db8::10:0:44/128
+ asn: 64544
+ - name: LIR3
+ children:
+ - name: ISP5a
+ ipv4: 10.0.0.0/24
+ ipv6: 2001:db8::a00:0/120
+ - name: ISP5b
+ ipv4: 10.3.0.0/24
+ ipv6: 2001:db8::a03:0/120
+ - name: ISP5c
+ asn: 64534-64540
diff --git a/scripts/testdb2.yaml b/scripts/testdb2.yaml
new file mode 100644
index 00000000..c3b16901
--- /dev/null
+++ b/scripts/testdb2.yaml
@@ -0,0 +1,68 @@
+# $Id$
+
+name: Root
+kids:
+ - name: R0
+ kids:
+ - name: Alice
+ ipv4: 192.0.2.1-192.0.2.33
+ asn: 64533
+ - name: Bob
+ ipv4: 192.0.2.44-192.0.2.100
+ - name: R1
+ kids:
+ - name: Carol
+ ipv6: 2001:db8::44-2001:db8::100
+ - name: Dave
+ ipv6: 2001:db8::10:0:44/128
+ asn: 64544
+ - name: R2
+ kids:
+ - name: Elena
+ ipv4: 10.0.0.0/24
+ ipv6: 2001:db8::a00:0/120
+ - name: Frank
+ ipv4: 10.3.0.0/24
+ ipv6: 2001:db8::a03:0/120
+ - name: R3
+ kids:
+ - name: Ginny
+ asn: 64534-64540
+ - name: Harry
+ asn: 666-677
+ - name: R4
+ kids:
+ - name: Ilse
+ ipv4: 10.3.0.0/16
+ - name: Jack
+ ipv4: 10.2.0.0/16
+ - name: R5
+ kids:
+ - name: Kari
+ asn: 222-233
+ - name: Leon
+ asn: 244-255
+ - name: R6
+ kids:
+ - name: Mary
+ ipv4: 10.77.0.0/16
+ - name: Neal
+ ipv4: 10.66.0.0/16
+ - name: R7
+ kids:
+ - name: Olga
+ ipv4: 10.88.0.0/16
+ - name: Piet
+ ipv4: 10.99.0.0/16
+ - name: R8
+ kids:
+ - name: Qi
+ asn: 111-122
+ - name: Rex
+ asn: 333-344
+ - name: R9
+ kids:
+ - name: Sandra
+ asn: 555-566
+ - name: Thad
+ asn: 577-588