Commits

Anonymous committed 0c5ad70

fix the nixRouting protocol assert bug, add routin_help_list configuration in Topology and ManualTopoExperiment

Comments (0)

Files changed (5)

core/ns3/NS3Config.py

 #####################################
 ####              API            ####
 #####################################
-def TopologyNetBT(dot_file, trace_config):
+def TopologyNetBT(dot_file, trace_config, **kwargs):
     """return a TopologyNet with Background traffic already configured
         - **dotfile** is the path of dot configuration file relative to ROOT directory
         - **trace_config** is a dictionary contains the trace and bot server client information
     """
     ns3_config = NS3Config(dot_file, trace_config)
+    # set other parameters
+    for k, v in kwargs.iteritems():
+        ns3_config.__dict__[k] = v
+
     ns3_config.setup()
     ns3_config.config_onoff_app()
     return ns3_config.net
                 self.TOPOLOGY_TYPE,
                 self.NodeCreator,
                 net_settings,
+                routing_helper_list = self.routing_helper_list,
                 )
         self.net.set_trace()
 
     def add_onoff_app(self, start_time, end_time, local, remote, on_time, off_time, data_rate, sport, dport):
         """add one ns3 onoff application to the network
         """
+        # ignore the network prefix length if there is
+        if '/' in remote: remote = remote.rsplit('/')[0]
+        if '/' in local: local = local.rsplit('/')[0]
+
         ### Install OnOff Application ###
         socketType = "ns3::UdpSocketFactory"
+        # socketType = "ns3::TcpSocketFactory"
         helper = ns3.OnOffHelper(socketType,
                 ns3.InetSocketAddress(remote, dport))
 

core/ns3/Topology.py

     routing_helper_list = {
             'static':0,
             'nix':5,
-            'olsr':10,
+            # 'olsr':10,
             }
     def __init__(self, _input, _format, NodeCreator, *args, **kwargs):
         self._input = _input
         self._format = _format
         self.NodeCreator = NodeCreator
         self.load_file()
-        self.install_stack()
+
+        self.install_stack(kwargs.get('routing_helper_list', None))
         self.init_link()
         self.init_net_device(*args, **kwargs)
 
         """Load Topology File"""
         self.inFile, self.nodes = self._load_file(self._input, self._format, self.NodeCreator)
 
-    def install_stack(self):
+    def install_stack(self, routing_helper_list=None):
         """Install Internet Stack"""
+        if routing_helper_list is not None:
+            self.routing_helper_list = routing_helper_list
+
         stack = ns.internet.InternetStackHelper()
         nix = Ipv4NixVectorHelper()
         static = ns.internet.Ipv4StaticRoutingHelper()

experiments/ManualTopoBTExperiment.py

 from core.ns3.NS3Config import TopologyNetBT
 from experiments import experiment_factory
 from core.configure import gen_anomaly_dot
+import ns3
 
 ManualTopoExperiment = experiment_factory('ManualTopoExperiment', BaseClass)
 from util import Namespace
     """This is a extension of manual topology experiment which add background traffic
     to the network. """
     DOT_FILE = settings.ROOT + '/net_config/ManualTopoBTTopology.dot'
+
+    # routing protocol list, 'type':priority
+    routing_helper_list = {
+            'static':0,
+            'nix':5,
+            # 'olsr':10,
+            }
+
     def initparser(self, parser):
         ManualTopoExperiment.initparser(self, parser)
 
         net_settings = self.load_net_settings()
         self.load_exper_settings(net_settings)
 
-        # back_traf = self.load_back_traf() # get back_traf parameter
+        # Generate dot file that describe the background traffic.
         dot_file, trace_config = self.gen_back_traf_dot(net_settings)
 
-        self.net = TopologyNetBT(dot_file, trace_config)
+        ns3.LogComponentEnable("OnOffApplication", ns3.LOG_LEVEL_INFO)
+        self.net = TopologyNetBT(dot_file, trace_config,
+                routing_helper_list = self.routing_helper_list)
 
         self.net.set_trace()
         self._install_cmds(srv_addr = self.SERVER_ADDR)

experiments/ManualTopoExperiment.py

         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.SERVER_ADDR, self.NETWORK_BASE, self.IP_MASK = CIDR_to_subnet_mask(ns.server_addr[0]);
+        # print 'ns.server_addr, ', ns.server_addr
+        # self.SERVER_ADDR, self.NETWORK_BASE, self.IP_MASK = CIDR_to_subnet_mask(ns.server_addr[0]);
+
+        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):
         BaseClass.setup(self)
 # ROOT should be the absolute path of the Imalse installation directory
 # ROOT = '/home/wangjing/Dropbox/GSOC/code/imalse'
 # ROOT = '/Users/wangjing/Dropbox/GSOC/code/imalse'
-ROOT = '/home/wangjing/Dropbox/imalse'
+# ROOT = '/home/wangjing/Dropbox/imalse'
 ROOT = '/home/wangjing/LocalResearch/imalse'
 
 import sys