From ab59579a124fa41d9efd0345761ef4df0dea638d Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Tue, 20 Apr 2021 14:54:20 -0300 Subject: [PATCH] topotests: support adding hosts Add API to topogen so we can build topology with simple hosts instead of routers. Signed-off-by: Rafael Zalamena --- tests/topotests/lib/topogen.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 553f2bc6cf..4b0f07eb1e 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -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 -- 2.39.5