Source

imalse / core / ns3 / experiment / imalse_netns_experiment.py

"""

This file contains the imalse netns3 experiment. It inherits from the 
standard ImalseExperiment and NetnsExperiment from the ns3 framework.

"""

from core.ns3.util.netns3 import NetnsExperiment
from core.ns3.node import ImalseNetnsNode
from core.ns3.experiment import ImalseExperiment

NODE_NUM = 0
class ImalseNetnsExperiment(ImalseExperiment, NetnsExperiment):
    
    """Base Class for imalse experiments in netns3 mode."""
    
    def __init__(self, *args, **kwargs):
        """Initialize the parents first."""
        NetnsExperiment.__init__(self, *args, **kwargs)
        ImalseExperiment.__init__(self)
        self._init()

    def initparser(self, parser):
        """Initialize the parsers in both parents."""
        ImalseExperiment.initparser(self, parser)
        NetnsExperiment.initparser(self, parser)

    def get_node(self, i):
        """Get the ith node"""
        return self.nodes[i]

    @property
    def node_num(self):
        """Return the number of nodes."""
        return len(self.nodes)

    @staticmethod
    def NodeCreator():
        """Create a node."""
        global NODE_NUM
        NODE_NUM += 1
        name = "n%s" %NODE_NUM
        return ImalseNetnsNode(name, logfile = "/tmp/%s.log" % name)