import configparser
from io import StringIO
-from lib.micronet_compat import Mininet
from lib.topogen import TopoRouter, get_topogen
from lib.topolog import get_logger, logger
from lib.topotest import frr_unicode, interface_set_status, version_cmp
import time
from lib.topolog import logger
from lib.topotest import json_cmp
-from lib.micronet_compat import Mininet
# L utility functions
* `modname`: module name must be a unique name to identify logs later.
"""
self.config = None
- self.topo = None
self.net = None
self.gears = {}
self.routern = 1
# Allow anyone, but set the sticky bit to avoid file deletions
os.chmod(self.logdir, 0o1777)
- # Old twisty way of creating sub-classed topology object which has it's build
- # method invoked which calls Topogen methods which then call Topo methods to
- # create a topology within the Topo object, which is then used by
+ # Remove old twisty way of creating sub-classed topology object which has it's
+ # build method invoked which calls Topogen methods which then call Topo methods
+ # to create a topology within the Topo object, which is then used by
# Mininet(Micronet) to build the actual topology.
- if inspect.isclass(topodef):
- self.topo = topodef()
+ assert not inspect.isclass(topodef)
- self.net = Mininet(controller=None, topo=self.topo)
+ self.net = Mininet(controller=None)
# New direct way: Either a dictionary defines the topology or a build function
# is supplied, or a json filename all of which build the topology by calling
node1.register_link(ifname1, node2, ifname2)
node2.register_link(ifname2, node1, ifname1)
- if self.net:
- self.net.add_link(node1.name, node2.name, ifname1, ifname2)
- else:
- self.topo.addLink(node1.name, node2.name, intfName1=ifname1, intfName2=ifname2)
+ self.net.add_link(node1.name, node2.name, ifname1, ifname2)
def get_gears(self, geartype):
"""
ROUTER_LIST = []
-def build_topo_from_json(tgen, topo):
+def build_topo_from_json(tgen, topo=None):
"""
Reads configuration from JSON file. Adds routers, creates interface
names dynamically and link routers as defined in JSON to create
topology. Assigns IPs dynamically to all interfaces of each router.
* `tgen`: Topogen object
- * `topo`: json file data
+ * `topo`: json file data, or use tgen.json_topo if None
"""
+ if topo is None:
+ topo = tgen.json_topo
ROUTER_LIST = sorted(
topo["routers"].keys(), key=lambda x: int(re_search(r"\d+", x).group(0))
)
-def linux_intf_config_from_json(tgen, topo):
+def linux_intf_config_from_json(tgen, topo=None):
"""Configure interfaces from linux based on topo."""
+ if topo is None:
+ topo = tgen.json_topo
+
routers = topo["routers"]
for rname in routers:
router = tgen.net[rname]
router.cmd_raises("ip -6 addr add {} dev {}".format(link["ipv6"], lname))
-def build_config_from_json(tgen, topo, save_bkup=True):
+def build_config_from_json(tgen, topo=None, save_bkup=True):
"""
Reads initial configuraiton from JSON for each router, builds
configuration and loads its to router.
* `tgen`: Topogen object
- * `topo`: json file data
+ * `topo`: json file data, or use tgen.json_topo if None
"""
func_dict = OrderedDict(
]
)
+ if topo is None:
+ topo = tgen.json_topo
+
data = topo["routers"]
for func_type in func_dict.keys():
logger.info("Checking for {} configuration in input data".format(func_type))