]> git.puffer.fish Git - matthieu/frr.git/commitdiff
topotests: support adding hosts
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 20 Apr 2021 17:54:20 +0000 (14:54 -0300)
committerRafael Zalamena <rzalamena@gmail.com>
Wed, 9 Jun 2021 15:32:24 +0000 (12:32 -0300)
Add API to topogen so we can build topology with simple hosts instead
of routers.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
tests/topotests/lib/topogen.py

index 553f2bc6cf03758c45e8a9c021bf6e831ab31ebc..4b0f07eb1e379f02661ca05c00da31fa3506486b 100644 (file)
@@ -222,6 +222,22 @@ class Topogen(object):
         self.peern += 1
         return self.gears[name]
 
+    def add_host(self, name, ip, defaultRoute):
+        """
+        Adds a new host to the topology. This function has the following
+        parameters:
+        * `ip`: the peer address (e.g. '1.2.3.4/24')
+        * `defaultRoute`: the peer default route (e.g. 'via 1.2.3.1')
+        """
+        if name is None:
+            name = "host{}".format(self.peern)
+        if name in self.gears:
+            raise KeyError("host already exists")
+
+        self.gears[name] = TopoHost(self, name, ip=ip, defaultRoute=defaultRoute)
+        self.peern += 1
+        return self.gears[name]
+
     def add_link(self, node1, node2, ifname1=None, ifname2=None):
         """
         Creates a connection between node1 and node2. The nodes can be the