Source

imalse / experiments / manual_topo_exp.py

"""

It demos the process of loading a predefined topology file. It only works with
networks that are formed by point to point links.

"""

import settings

from core.ns3.util.topology import ManualTopologyNet
from experiments import TopoExperiment
from util import Namespace
from util.net import cidr_to_subnet_mask

class ManualTopoExperiment(TopoExperiment):
    
    """In Manual Topo Experiment,  You can specify and ip address for each indexing"""
    
    def initparser(self, parser):
        """"""
        TopoExperiment.initparser(self, parser)

        parser.set_defaults(net_settings="net_config/net_settings.py",
                )
        parser.add_option('--net_settings', dest="net_settings",
                help='net settings file',
                )

    def load_net_settings(self):
        """"""
        s = {}
        execfile(settings.ROOT + '/' + self.options.net_settings, s)
        return Namespace(s)

    def load_exper_settings(self, ns):
        """"""        
        # botnet related configuration
        self.server_id_set = ns.server_id_set
        self.botmaster_id_set = ns.botmaster_id_set
        self.client_id_set = ns.client_id_set       
        self.target_id = ns.target_id
        
        if len(ns.server_addr) == 0:
            self.SERVER_ADDR = ''
            self.NETWORK_BASE = ''
            self.IP_MASK = ''
        else:
            self.SERVER_ADDR, self.NETWORK_BASE, self.IP_MASK = cidr_to_subnet_mask(ns.server_addr[0]);

    def setup(self):
        """"""        
        net_settings = self.load_net_settings()        
        self.load_exper_settings(net_settings)

        self.net = ManualTopologyNet(
                # os.path.abspath(self.options.topology_file),
                settings.ROOT + '/' + self.options.topology_file,
                self.options.topology_type,
                self.NodeCreator,
                net_settings,
                )
        self.net.set_trace()

        self.install_cmds(srv_addr = self.SERVER_ADDR)
        self.print_srv_addr()
        self.set_server_info()
        self.start_nodes()