Anonymous avatar Anonymous committed a4fcbc1

clean up Imalse code with CsmaNetwork support. Create ComplexNetexperiment. There is small bug in ManualTopoBTExperiment, the order of default address helper in Imalse and fs configure part is not consistant

Comments (0)

Files changed (26)

core/ns3/DotConfig.py

 from util import get_net, CIDR_to_subnet_mask
 
 class DotConfig(object):
-    """load dot configurationn. """
+    """load DOT fomat background traffic configurationn.
+
+    """
     # DEFAULT_ROUTING_PREFIX = 8
     DEFAULT_ROUTING_PREFIX = 24
 
-    # the fs dot file doesn't have the botnet and trace information.
-    pcap_nodes = [ 0, 1, 2 ]
-    pcap_links = [ (0, 2) ]
-    botmaster_id_set = [  ]
-    client_id_set = [ ]
-    server_id_set = [  ]
-    server_addr = [ ]
-
     def __init__(self, f_name):
-        self._loadconfig(f_name)
-        # self.__dict__.update(trace_config)
-
-    def _loadconfig(self, config):
-        self.graph = networkx.nx_pydot.read_dot(config)
+        self.graph = networkx.nx_pydot.read_dot(f_name)
 
     @staticmethod
     def nid(node_name):
         """get node id from **node_name**, node_name should start
-        with n and follows with a digit"""
+        with n and follows with a digit
+        """
         return int(node_name[1:])
     @staticmethod
     def nname(nid):
 
     def export_net_settings(self, fname):
         """export **link_attr**, **link_to_ip_map**, from the dot configuration
-        get **link_attr** first, then for each link, search the ipdests for
+
+        Get **link_attr** first, then for each link, search the ipdests for
         the node. Find two ipaddress share with the same prefix, add corresponding
-        item to link_to_ip_map. if the net
-        length in the CIDR format is not specified, use the default value of
+        item to link_to_ip_map. if the net length in the CIDR format is not specified,
+        use the default value of
         24.
         """
         self._load_link_attr()
 
         fid.write('link_attr = ' + pprint.pformat(self.link_attr, indent=4)+'\n')
         fid.write('link_to_ip_map = ' + pprint.pformat(self.link_to_ip_map, indent=4)+'\n')
-#         fid.write("""
-# pcap_nodes = %s
-# pcap_links = %s
-# botmaster_id_set = %s
-# client_id_set = %s
-# server_id_set = %s
-# server_addr = %s"""%(self.pcap_nodes, self.pcap_links,
-#         self.botmaster_id_set,
-#         self.client_id_set,
-#         self.server_id_set,
-#         self.server_addr))
-#         fid.close()
         return self.link_attr, self.link_to_ip_map
 
     def export_inet(self, fname):

core/ns3/NS3Config.py

 from __future__ import division, print_function
 
 import settings
-from Node import ImalseNetnsSimNode
-from Topology import ManualTopologyNet
-from Topology import ComplexNet
+import ns3
+
 from DotConfig import DotConfig
-from util import Namespace
-import ns3
-from random import randint
-from RandomVariable import RV
+# from RandomVariable import RV
+# from RandomVarLib import *
+from RandomVariable import *
 
-#####################################
-####              API            ####
-#####################################
-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
-
-def run_ns3(dot_file, trace_config, sim_time, visual):
-    """run ns3 simulation based on configuration in **dot_file** and **trace_flag**"""
-    if visual:
-        ns3.GlobalValue.Bind("SimulatorImplementationType",
-                ns3.StringValue("ns3::VisualSimulatorImpl"))
-
-    ns3.LogComponentEnable("OnOffApplication", ns3.LOG_LEVEL_INFO)
-    ns3.LogComponentEnable("OnOffApplication", ns3.LOG_LEVEL_INFO)
-
-    ns3_config = NS3Config(settings.ROOT + '/' + dot_file, trace_config)
-    ns3_config.setup()
-    ns3_config.config_onoff_app()
-    ns3.Simulator.Stop(ns3.Seconds(sim_time))
-    ns3.Simulator.Run()
-    ns3.Simulator.Destroy()
-
-##################################################################
-####    Not recommend to call functions in this part directly ####
-##################################################################
 def short_num_to_standard(s):
     """change short text notation to standard numerica value"""
     replace_map = {
         s = s.replace(k, v)
     return s
 
-from RandomVarLib import *
 
 class BackgroundTrafficConfig(object):
-    """config NS3 according to fs dot file"""
+    """Add background traffic pattern to the NS3 Simulator
+
+    The background traffic is specifed by a DOT file
+    """
+
     TOPOLOGY_FILE = settings.ROOT + '/share/bg_topology.inet'
     TOPOLOGY_TYPE = 'Inet'
     NET_SETTINGS_FILE = settings.ROOT + '/share/bg_net_settings_tmp.py'
         self.dot_config.export_net_settings(self.NET_SETTINGS_FILE)
         self.net = net
 
-    def add_onoff_app(self, start_time, end_time, local, remote, on_time, off_time, data_rate, sport, dport):
+    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
 
     @staticmethod
     def transform_para(flowsize, flowstart, ipsrc, ipdst, sport, dport, **argv):
-        """transform the parameter for generator desription to the NS3 onoff application parameters"""
+        """transform the parameter for generator desription to the NS3 onoff application parameters
+        """
         # data_rate = StringValue('1kbps') # constant data rate
         data_rate = 1000
         on_time = RV(flowsize) / data_rate
             for start_time, end_time, num, generator in mod_profs: # for each modulator
                 gen = self.dot_config.get_gen(node, generator)
                 for i in xrange(num):
-                    self.add_onoff_app(start_time, end_time, *self.transform_para(**gen))
+                    self._add_onoff_app(start_time, end_time, *self.transform_para(**gen))
 
 if __name__ == "__main__":
     run_ns3('res.dot', [], 3000, False)

core/ns3/RandomVariable.py

-"""
-Definiation of Different Types Random Variable
+""" Definiation of Different Types Random Variable
+
 allow initialization with string, support extra operations
 ns3 random variable class cannot be the base class
 """
     return ConstantVariable(s)
 
 
+
+##########################################
+##        Random Generator            ####
+##########################################
+
+import random
+import math
+def randomunifint(lo, hi):
+    while True:
+        yield random.randint(lo, hi)
+
+def randomuniffloat(lo, hi):
+    while True:
+        yield random.random()*(hi-lo)+lo
+
+def randomchoice(*choices):
+    while True:
+        yield random.choice(choices)
+
+def randomchoicefile(infilename):
+    xlist = []
+    with open(infilename) as inf:
+        for line in inf:
+            for value in line.strip().split():
+                try:
+                    xlist.append(float(value))
+                except:
+                    pass
+    index = 0
+    while True:
+        yield xlist[index]
+        index = (index + 1) % len(xlist)
+
+def pareto(offset,alpha):
+    while True:
+        # yield offset*random.paretovariate(alpha)
+        yield (offset * ((1.0/math.pow(random.random(), 1.0/alpha)) - 1.0));
+
+#def mypareto(scale, shape):
+#    return (scale * ((1.0/math.pow(random.random(), 1.0/shape)) - 1.0));
+
+def exponential(lam):
+    while True:
+        yield random.expovariate(lam)
+
+def normal(mean, sdev):
+    while True:
+        yield random.normalvariate(mean, sdev)
+
+def lognormal(mean, sdev):
+    while True:
+        yield random.lognormvariate(mean, sdev)
+
+def gamma(alpha, beta):
+    while True:
+        yield random.gammavariate(alpha, beta)
+
+def weibull(alpha, beta):
+    while True:
+        yield random.weibullvariate(alpha, beta)
+
+def mkdict(s):
+    xdict = {}
+    if isinstance(s, str):
+        s = s.split()
+    for kvstr in s:
+        k,v = kvstr.split('=')
+        xdict[k] = v
+    return xdict
+
+
+

core/ns3/Topology.py

 # import ns3
 class ManualTopologyNet(TopologyNet):
     """Topology network with manual ip settings"""
+
+    def _modify_address_helper(self, addressHelper, cidr_addr):
+        """ modify the netbase, mask and and base of the address helper
+        """
+        addr, netBase, mask = CIDR_to_subnet_mask(cidr_addr)
+        netAddr = get_net_addr(addr, mask)
+        addressHelper.SetBase(
+                network=ns3.Ipv4Address(netBase),
+                mask = ns3.Ipv4Mask(mask),
+                base = ns3.Ipv4Address(netAddr),
+                )
+        return addressHelper
+
     def get_link_name(self, i):
         link = self.inFile.m_linksList[i]
         link_name = (int(link.GetFromNodeName()), int(link.GetToNodeName()) )
         return link_name
 
     def get_link_attr(self, i):
-        default = self.net_settings.link_attr_default
-        return self.net_settings.link_attr.get(self.get_link_name(i), default)
+        default = self.net_settings['link_attr_default']
+        return self.net_settings['link_attr'].get(self.get_link_name(i), default)
 
     def set_trace(self):
         # for n in self.net_settings.pcap_nodes:
             for a in xrange(ipv4.GetNInterfaces()):
                 for b in xrange(ipv4.GetNAddresses(a)):
                     local_addr = ipv4.GetAddress (a, b).GetLocal ();
+                    print(' lcao_addr, ', local_addr)
                     if str(local_addr) == addr:
                         return node
 
+        raise Exception('cannot find node with addr: '+ str(addr))
+
 
 
     def init_net_device(self, net_settings, *args, **kwargs):
 
         # Create little subnets, one for each couple of nodes
         defaultAddressHelper = ns3.Ipv4AddressHelper()
-        defaultAddr, defaultNetBase, defaultMask = CIDR_to_subnet_mask(net_settings.ipv4_net_addr_base)
+        defaultAddr, defaultNetBase, defaultMask = CIDR_to_subnet_mask(net_settings['ipv4_net_addr_base'])
         netAddr = get_net_addr(defaultAddr, defaultMask)
         defaultAddressHelper.SetBase(
                 network=ns3.Ipv4Address(defaultNetBase),
                 base = ns3.Ipv4Address(netAddr),
                 )
 
+        # FIXME, THE ORDER HERE WITH THE ORDER in FS CONFIGURE MAY BE
+        # DIFFERENT
         addressHelper = ns3.Ipv4AddressHelper()
         ipic = [] #ip interface container
         for i in xrange(totlinks):
-            ips = self.net_settings.link_to_ip_map.get(self.get_link_name(i), None)
+
+            ips = self.net_settings['link_to_ip_map'].get(self.get_link_name(i), None)
 
             # Use the default base when the ip address is not explictly specified,
             # create new network for each p2p link
             if not ips:
-                # ipic.append( defaultAddressHelper.Assign(ndc[i]) )
+                raise Exception('Sorry, in current version of ManualTopologyNet ' +
+                        'You have to specify the link_to_ip_map for ALL LINKS!')
+                print(self.get_link_name(i), 'use default address helper')
                 ipic.append( defaultAddressHelper.Assign(self.get_link_ndc(i)) )
                 addressHelper.NewNetwork()
                 continue
 
-            # Assign ip address for node 1
-            addr, netBase, mask = CIDR_to_subnet_mask(ips[0])
-            net_addr = get_net_addr(addr, mask)
-            addressHelper.SetBase(
-                    network=ns3.Ipv4Address(netBase),
-                    mask = ns3.Ipv4Mask(mask),
-                    base = ns3.Ipv4Address(net_addr),
-                    )
-            # ip1 = addressHelper.Assign(ns3.NetDeviceContainer(ndc[i].Get(0)))
-            ip1 = addressHelper.Assign(ns3.NetDeviceContainer(self.get_link_ndc(i).Get(0)))
-            # self.get_link_ndc(i).Get(0).SetAddress(ns3.Ip)
+            addressHelper = ns3.Ipv4AddressHelper()
+            j = -1
+            ipic_tmp = []
+            for ip in ips:
+                j += 1
+                print('address, ', ip)
+                addressHelper = self._modify_address_helper(addressHelper, ip)
+                ipc = addressHelper.Assign(ns3.NetDeviceContainer(self.get_link_ndc(i).Get(j)))
+                ipic_tmp.append(ipc)
+            ipic.append(ipic_tmp)
 
-            # Assign ip address for node 2
-            addr, netBase, mask = CIDR_to_subnet_mask(ips[1])
-            net_addr = get_net_addr(addr, mask)
-            addressHelper.SetBase(
-                    network=ns3.Ipv4Address(netBase),
-                    mask = ns3.Ipv4Mask(mask),
-                    base = ns3.Ipv4Address(net_addr)
-                    )
-            # ip2 = addressHelper.Assign(ns3.NetDeviceContainer(ndc[i].Get(1)))
-            ip2 = addressHelper.Assign(ns3.NetDeviceContainer(self.get_link_ndc(i).Get(1)))
-            ipic.append((ip1, ip2))
+
 
         self.p2p = p2p
         self.ipic = ipic
     For example, some parts is Csma Network, which some other parts is
     PointToPoint Network.
     """
+    def __init__(self, NodeCreator, net_settings, *args, **kwargs):
+        self.NodeCreator = NodeCreator
+        self._create_nodes(net_settings, NodeCreator)
+        self.install_stack(kwargs.get('routing_helper_list', None))
+        self.init_net_device(net_settings, *args, **kwargs)
+
+        # create routing table
+        ns3.Ipv4GlobalRoutingHelper.PopulateRoutingTables()
+
+    def _create_nodes(self, net_settings, NodeCreator):
+        """create nodes, self.nodes will be a node container"""
+        # get the number of nodes in the network
+        print('net_settings, ', net_settings)
+        max_node = []
+        for type_, desc in net_settings['nets'].iteritems():
+            max_node.append(max( max(v) for v in desc['IpMap'].keys()))
+        node_num = max(max_node) + 1
+        print('node_num, ', node_num)
+
+        self.nodes = ns3.NodeContainer()
+        for i in xrange(node_num):
+            node = NodeCreator()
+            self.nodes.Add(node)
+
     def _modify_address_helper(self, addressHelper, cidr_addr):
         """ modify the netbase, mask and and base of the address helper
         """
                 )
         return addressHelper
 
-    def init_link(self):
-        pass
-
     def _initSubnet(self, type_, desc):
         """ Initialize subnet in the complex network.
 

experiments/ComplexNetExperiment.py

+"""
+Complex Network Experiment with Background Traffic
+
+This experiment will deal with heterogeneous network
+that consists of not only PointToPointLink but also
+CsmaNetwork, etc
+"""
+from __future__ import print_function
+import settings
+from core.ns3.NS3Config import BackgroundTrafficConfig
+from core.ns3.Topology import ComplexNet
+from experiments import experiment_factory
+from core.configure import gen_anomaly_dot
+import ns3
+
+ManualTopoExperiment = experiment_factory('ManualTopoExperiment', BaseClass)
+
+zeros = lambda s:[[0 for i in xrange(s[1])] for j in xrange(s[0])]
+import copy
+
+class ComplexNetExperiment(ManualTopoExperiment):
+    """This experiment deals with hetergenous network
+    """
+    # routing protocol list, 'type':priority
+    routing_helper_list = {
+            'static':0,
+            'nix':5,
+            # 'olsr':10,
+            }
+
+    def initparser(self, parser):
+        ManualTopoExperiment.initparser(self, parser)
+
+        parser.set_defaults(back_traf="net_config/back_traf.py",
+                )
+        parser.add_option('--back_traf', dest="back_traf",
+                help='confgiuration files for back ground traffic',
+                )
+        parser.add_option('--dot_file', default='net_config/ManualTopoBTConf.dot',
+                help='the configured dot file')
+
+
+    @staticmethod
+    def load_para(f_name, encap=None, **kwargs):
+        """load parameters.
+
+        - **f_name**: is the path of the configuration file
+        - **encap**: is the additional operation done to the data, for example,
+            the default value encap=Namespace is to change parameters from dict
+            to Namespace class.
+        - **kwargs**: contains some additional parameters
+        """
+        s = kwargs
+        execfile(f_name, s)
+        return s if encap is None else encap(s)
+
+    @staticmethod
+    def transform_to_net_desc(net_settings):
+        """ Transform the net_setting used by ComplextNet to net_desc paramter used by fs configure
+
+        The net specification parameter in *Imalse* and *fs* configure module
+        are quite different. This function tranform a net_setting parameter to
+        a net_desc parameter used by fs/configure module
+        we don't need topology in the dot file to be exactly the same.
+        we just need the ip address for each interface.
+
+        """
+        net_desc = copy.copy(net_settings) # shallow copy
+        net_desc['node_type'] = 'NNode'
+        net_desc['node_para'] = {}
+
+        # Create a Suitable Topology. For CSMA network. It will simply
+        # create circle topology.
+        net_desc['link_to_ip_map'] = {}
+        for type_, desc in net_desc['nets'].iteritems():
+            if type_ == 'PointToPoint':
+                net_desc['link_to_ip_map'].update(desc['IpMap'])
+            elif type_ == "Csma":
+                for nodes, ips in desc['IpMap'].iteritems():
+                    for i in xrange(len(nodes) - 1):
+                        net_desc['link_to_ip_map'].update({ (nodes[i], nodes[i+1]):(ips[i], ips[i+1]) })
+
+        pairs = net_desc['link_to_ip_map'].keys()
+        g_size = max(max(pairs)) + 1
+        topo = zeros((g_size, g_size))
+        for x, y in pairs:
+            topo[x][y] = 1
+        net_desc['topo'] = topo
+
+        return net_desc
+
+    def load_exper_settings(self, ns):
+        """ load experiment related settings
+
+        **server_id_set**:
+        **botmaster_id_set**:
+        **client_id_set**:
+        **SERVER_ADDR**:
+        **NETWORK_BASE**:
+        **IP_MASK**:
+
+        """
+        from util import CIDR_to_subnet_mask
+        # 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']
+
+        # parse the server address
+        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 gen_back_traf_dot(self, net_settings):
+        """generate background traffic DOT file
+
+        *input*: is the a dict of net_settings
+        *output*: DOT_FILE_PATH
+        """
+
+        # get back_traf parameter
+        back_traf = self.load_para(
+                f_name = settings.ROOT + '/' + self.options.back_traf,
+                sim_t = self.options.simtime,
+                )
+
+        # call the SADIT/Configure module to generate the dot file specifying the background
+        # traffic pattern.
+        dot_file = settings.ROOT + '/' + self.options.dot_file
+        gen_anomaly_dot(
+                back_traf['ANO_LIST'],
+                self.transform_to_net_desc(net_settings),
+                back_traf['NORM_DESC'],
+                dot_file
+                )
+        return dot_file
+
+    def setup(self):
+        BaseClass.setup(self)
+
+        net_settings = self.load_para(f_name = settings.ROOT + '/' + self.options.net_settings)
+        self.load_exper_settings(net_settings)
+
+        # Generate dot file that describe the background traffic.
+        dot_file = self.gen_back_traf_dot(net_settings)
+
+        ns3.LogComponentEnable("OnOffApplication", ns3.LOG_LEVEL_INFO)
+        self.net = ComplexNet(
+                self.NodeCreator,
+                net_settings,
+                )
+
+        bg_cofig = BackgroundTrafficConfig(dot_file, self.net)
+        bg_cofig.config_onoff_app()
+
+        self.net.set_trace()
+        self._install_cmds(srv_addr = self.SERVER_ADDR)
+        self.print_srv_addr()
+        self._set_server_info()
+        self.start_nodes()
+

experiments/ManualTopoBTExperiment.py

 Manual Topology Experiment with Background Traffic
 
 """
-from __future__ import print_function
+from __future__ import print_function, division
 import settings
-# from core.ns3.NS3Config import TopologyNetBT
 from core.ns3.NS3Config import BackgroundTrafficConfig
-from core.ns3.Topology import ComplexNet
+from core.ns3.Topology import ManualTopologyNet
 from experiments import experiment_factory
 from core.configure import gen_anomaly_dot
 import ns3
+import copy
 
 ManualTopoExperiment = experiment_factory('ManualTopoExperiment', BaseClass)
-from util import Namespace
 
 zeros = lambda s:[[0 for i in xrange(s[1])] for j in xrange(s[0])]
+
 def get_inet_adj_mat(fname):
-    """ get the adjacent matrix from the topology.inet file.
-    """
     fid = open(fname, 'r')
     i = -1
     while True:
 
     return adj_mat
 
-import pprint
-import os
-def fix_fs_addr_prefix_bug(f_name):
-    """A fs node can either represent a real node or a network. If the addr in
-    node's ipdests is add prefix, then fs will automatically consider it as network.
-    However, the net_settings generated by Imalse GUI topology also use CIDR format.
-    To reduce ambiguity, delete all network length information in **link_to_ip_map**
+class ManualTopoBTExperiment(ManualTopoExperiment):
+    """ This is a extension of Manual topology experiment it
+    add background traffic to the network.
     """
-    s = {}
-    execfile(f_name, s)
-    new_link_to_ip_map = {}
-    for k, v in s.get('link_to_ip_map', {}).iteritems():
-        new_link_to_ip_map[k] = [val.rsplit('/')[0] for val in v]
-    s['link_to_ip_map'] = new_link_to_ip_map
-    new_f_name = os.path.dirname(f_name) + '/new_' + os.path.basename(f_name)
-    fid = open(new_f_name, 'w')
-    fid.close()
-    fid = open(new_f_name, 'a')
-    for k, v in s.iteritems():
-        if k.startswith('__'):
-            continue
-        fid.write('%s = '%(k))
-        pprint.pprint(v, stream=fid)
-    fid.close()
-    return new_f_name
-
-class ManualTopoBTExperiment(ManualTopoExperiment):
-    """This is a extension of manual topology experiment which add background traffic
-    to the network. """
     # routing protocol list, 'type':priority
     routing_helper_list = {
             'static':0,
                 help='the configured dot file')
 
 
-
-    def load_para(self, f_name, encap=None, **kwargs):
+    @staticmethod
+    def load_para(f_name, encap=None, **kwargs):
         """load parameters.
 
-        - **kwargs** contains some additional parameters
-        - **encap** is the additional operation done to the data, for example,
+        - **f_name**: is the path of the configuration file
+        - **encap**: is the additional operation done to the data, for example,
             the default value encap=Namespace is to change parameters from dict
             to Namespace class.
+        - **kwargs**: contains some additional parameters
         """
         s = kwargs
         execfile(f_name, s)
         return s if encap is None else encap(s)
 
-    def get_config_net_desc(self):
-        """ get the network description parameters
-
-        It will load the network_settings file and
-
-        - the new format of net_settings for Imalse and fs configure module
-          are quite different. need to transform the net settigns parameters
-
-        # transform the net settings format file to fs configure format
-        # since the function of the generated dot file is just to provide behaviour
-        # of models.
-        # we don't need topology in the dot file to be exactly the same.
-        # we just need the ip address for each interface.
-
-        """
-        # topo = get_inet_adj_mat(settings.ROOT + '/' + self.options.topology_file)
-        # new_net_settings_file = fix_fs_addr_prefix_bug(settings.ROOT + '/' + self.options.net_settings)
-        new_net_settings_file = settings.ROOT + '/' + self.options.net_settings
-        net_desc= self.load_para(f_name=new_net_settings_file, encap=None)
+    def transform_to_net_desc(self, net_settings):
+        """add topology from topoloy file"""
+        net_desc = copy.copy(net_settings) # shallow copy
         net_desc['node_type'] = 'NNode'
         net_desc['node_para'] = {}
-
-        net_desc['link_to_ip_map'] = {}
-        for type_, desc in net_desc['nets'].iteritems():
-            if type_ == 'PointToPoint':
-                net_desc['link_to_ip_map'].update(desc['IpMap'])
-            elif type_ == "Csma":
-                for nodes, ips in desc['IpMap'].iteritems():
-                    for i in xrange(len(nodes) - 1):
-                        net_desc['link_to_ip_map'].update({ (nodes[i], nodes[i+1]):(ips[i], ips[i+1]) })
-
-        pairs = net_desc['link_to_ip_map'].keys()
-        g_size = max(max(pairs)) + 1
-        topo = zeros((g_size, g_size))
-        for x, y in pairs:
-            topo[x][y] = 1
-        net_desc['topo'] = topo
-
+        net_desc['topo'] = get_inet_adj_mat(settings.ROOT + '/' + self.options.topology_file)
         return net_desc
 
     def load_exper_settings(self, ns):
+        """ load experiment related settings
+
+        **server_id_set**:
+        **botmaster_id_set**:
+        **client_id_set**:
+        **SERVER_ADDR**:
+        **NETWORK_BASE**:
+        **IP_MASK**:
+
+        """
         from util import CIDR_to_subnet_mask
         # 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']
-        # print('ns.server_addr', ns.server_addr)
 
         # parse the server address
         if len(ns['server_addr']) == 0:
         else:
             self.SERVER_ADDR, self.NETWORK_BASE, self.IP_MASK = CIDR_to_subnet_mask(ns['server_addr'][0]);
 
+    def gen_back_traf_dot(self, net_settings):
+        """generate background traffic DOT file
 
-    @staticmethod
-    def get_trace_config(net_settings):
-        """transform net_setting to trace config
-        """
-        # TODO generate netDesc, normalDesc
-        keys = ['pcap_links', 'pcap_nodes',
-                'server_id_set', 'botmaster_id_set', 'client_id_set',
-                'server_addr']
-        ns = dict.copy(net_settings)
-        return dict(elem for elem in ns.items() if elem[0] in keys)
-
-    # @staticmethod
-    def gen_back_traf_dot(self, net_settings):
-        """generate background traffic dot file
+        *input*: is the a dict of net_settings
+        *output*: DOT_FILE_PATH
         """
 
         # get back_traf parameter
         dot_file = settings.ROOT + '/' + self.options.dot_file
         gen_anomaly_dot(
                 back_traf['ANO_LIST'],
-                self.get_config_net_desc(),
+                self.transform_to_net_desc(net_settings),
                 back_traf['NORM_DESC'],
-                # self.options.dot_file
                 dot_file
                 )
-        # return self.options.dot_file, self.get_trace_config(net_settings)
-        return dot_file, self.get_trace_config(net_settings)
+        return dot_file
+
+    def setup(self):
+        BaseClass.setup(self)
+
+        net_settings = self.load_para(f_name = settings.ROOT + '/' + self.options.net_settings)
+        self.load_exper_settings(net_settings)
+
+        # Generate dot file that describe the background traffic.
+        dot_file = self.gen_back_traf_dot(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,
+                )
+
+
+        bg_cofig = BackgroundTrafficConfig(dot_file, self.net)
+        bg_cofig.config_onoff_app()
+
+        self.net.set_trace()
+        self._install_cmds(srv_addr = self.SERVER_ADDR)
+        self.print_srv_addr()
+        self._set_server_info()
+        self.start_nodes()
 
     def setup(self):
         BaseClass.setup(self)
         self.load_exper_settings(net_settings)
 
         # Generate dot file that describe the background traffic.
-        dot_file, trace_config = self.gen_back_traf_dot(net_settings)
+        dot_file = self.gen_back_traf_dot(net_settings)
 
         ns3.LogComponentEnable("OnOffApplication", ns3.LOG_LEVEL_INFO)
-        # self.net = TopologyNetBT(dot_file, trace_config,
-                # routing_helper_list = self.routing_helper_list)
-        self.net = ComplexNet(
+        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()
 
         bg_cofig = BackgroundTrafficConfig(dot_file, self.net)
         bg_cofig.config_onoff_app()
         self.print_srv_addr()
         self._set_server_info()
         self.start_nodes()
-

gui/imalse_config/net_settings.py

 ipv4_net_addr_base = '10.7.0.1/24'
 link_attr_default = ['2ms','5Mbps']
 link_to_ip_map = {
-	(0, 2):['10.1.1.5/24', '10.20.30.1/24'],
+	(0, 2):['', '10.20.30.1/24'],
 	(0, 3):['', '10.20.30.2/24'],
 	(0, 4):['', '10.20.30.3/24'],
 	(0, 5):['', '10.20.30.4/24'],
-	(1, 0):['10.200.1.1/24', '10.200.1.3/24'],
+	(1, 0):['10.200.1.1', ''],
 	(6, 0):['10.1.1.1/24', '10.20.30.9/24'],
-	(7, 6):['1.1.1.1/24', '2.3.5.10/24'],
-	(8, 6):['2.3.5.6/24', '1.1.1.10/24'],
-	(6, 9):['5.6.8.10/24', '5.6.8.9/24'],
-	(12, 0):['10.20.30.8/24', ''],
-	(11, 0):['10.20.30.7/24', ''],
-	(10, 0):['10.20.30.6/24', ''],
-	(13, 0):['10.20.30.5/24', ''],
+	(7, 6):['1.1.1.1/24', '60.70.80.1/24'],
+	(8, 6):['2.3.5.6/24', '10.0.0.1/24'],
+	(6, 9):['10.0.1.1/24', '5.6.8.9/24'],
+	(12, 0):['10.20.30.8/24', '10.0.2.1/24'],
+	(11, 0):['10.20.30.7/24', '10.0.3.1/24'],
+	(10, 0):['10.20.30.6/24', '10.0.4.1/24'],
+	(13, 0):['10.20.30.5/24', '10.0.5.1/24'],
 }
 link_attr = {
 }
 pcap_nodes = [  ]
 pcap_links = [  ]
-botmaster_id_set = [  ]
-client_id_set = [  ]
+botmaster_id_set = [ 5 ]
+client_id_set = [ 2, 3, 4 ]
 server_id_set = [  ]
 server_addr = [  ]

gui/imalse_config/topology.inet

 14 1
-0	529.0	380.0
-2	330.0	538.0
+0	526.0	349.0
+2	331.0	538.0
 3	545.0	545.0
 4	724.0	537.0
 5	876.0	528.0
 # CORE 4.3 GUI preference file
-set g_mrulist "/home/wangjing/Apps/imalse/net_config/aro_demo/ARO.imn ./sample.imn /home/wangjing/Downloads/ARO.imn ./sample.imm"
+set g_mrulist "./sample.imn /home/wangjing/Dropbox/Research/CyberSecurity/ARO_demo/ARO.imn ./sample.imm /Users/wangjing/Dropbox/GSOC/code/imalse/gui/sample.imm"
 array set g_prefs {
 	default_conf_path	"./configs"
 	enable_rj45		"1"
 # 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/Apps/imalse'
+ROOT = '/home/wangjing/Dropbox/imalse'
+# ROOT = '/home/wangjing/Apps/imalse'
 
 import sys
 sys.path.insert(0, ROOT)
 
 # NS3_PATH should be the absolute path of the NS3 installation.
-# NS3_PATH = '/home/wangjing/Apps/ns-allinone-3.14.1/ns-3.14.1'
-NS3_PATH =  ROOT + '/tools/ns-allinone-3.14.1/ns-3.14.1'
+NS3_PATH = '/home/wangjing/Apps/ns-allinone-3.14.1/ns-3.14.1'
+# NS3_PATH =  ROOT + '/tools/ns-allinone-3.14.1/ns-3.14.1'
 # NS3_PATH = '/Users/wangjing/Apps/ns-allinone-3.14.1/ns-3.14.1'
 #!/usr/bin/env sh
-./sim -e ManualTopoBTExperiment --net_settings=net_config/aro_demo/nf_net_settings.py --topology_file=net_config/aro_demo/topology.inet --Simulator=Visual -s file_exfiltration
+# ./sim -e ManualTopoBTExperiment --net_settings=net_config/net_settings.py --topology_file=net_config/Inet_small_toposample.txt --Simulator=Visual -s file_exfiltration
+# ./sim -e ManualTopoBTExperiment --net_settings=net_config/aro_demo/net_settings.py --topology_file=net_config/aro_demo/topology.inet --Simulator=Visual -s file_exfiltration
+./sim -e ComplexNetExperiment --net_settings=net_config/aro_demo/nf_net_settings.py --topology_file=net_config/aro_demo/topology.inet --Simulator=Visual -s file_exfiltration

tools/ns-allinone-3.14.1/ns-3.14.1/doc/manual/source/figures

-../figures

tools/ns-allinone-3.14.1/ns-3.14.1/doc/manual/source/figures/README

+Please write image files in a vector graphics format, when possible, and
+generate the .png and .pdf versions on the fly (see ../Makefile).  
+
+The currently supported tool is dia.  xfig could be added similarly
+if someone wants to add it.  The main requirement for adding another format
+is that the tool to edit it is freely available and that a cron script can 
+autogenerate the pdf and png from the figure source.  Tgif (.obj) files
+were once used but the file conversions require a valid X display to 
+be running, and are therefore to be avoided since our code server 
+does not run such a server.  Tgif pdf conversions were also cumbersome.
+
+Store the .dia versions in mercurial, but not the .png or .pdfs.  
+If the figure is not available in a vector graphics format, store both
+a .png and a .pdf version in this directory.
+
+If you add a source (.dia) file here, remember to add it to
+the list of figure sources in the Makefile in the directory above
+
Add a comment to this file

tools/ns-allinone-3.14.1/ns-3.14.1/doc/manual/source/figures/plot-2d-with-error-bars.png

Added
New image
Add a comment to this file

tools/ns-allinone-3.14.1/ns-3.14.1/doc/manual/source/figures/plot-2d.png

Added
New image
Add a comment to this file

tools/ns-allinone-3.14.1/ns-3.14.1/doc/manual/source/figures/plot-3d.png

Added
New image
Add a comment to this file

tools/ns-allinone-3.14.1/ns-3.14.1/doc/manual/source/figures/software-organization.dia

Binary file added.

tools/ns-allinone-3.14.1/ns-3.14.1/doc/tutorial/source/figures

-../figures

tools/ns-allinone-3.14.1/ns-3.14.1/doc/tutorial/source/figures/README

+Please write image files in a vector graphics format, when possible, and
+generate the .png and .pdf versions on the fly (see ../Makefile).  
+
+The currently supported tool is dia.  xfig could be added similarly
+if someone wants to add it.  The main requirement for adding another format
+is that the tool to edit it is freely available and that a cron script can 
+autogenerate the pdf and png from the figure source.  Tgif (.obj) files
+were once used but the file conversions require a valid X display to 
+be running, and are therefore to be avoided since our code server 
+does not run such a server.  Tgif pdf conversions were also cumbersome.
+
+Store the .dia versions in mercurial, but not the .png or .pdfs.  
+If the figure is not available in a vector graphics format, store both
+a .png and a .pdf version in this directory.
+
+If you add a source (.dia) file here, remember to add it to
+the list of figure sources in the Makefile in the directory above
+
Add a comment to this file

tools/ns-allinone-3.14.1/ns-3.14.1/doc/tutorial/source/figures/cwnd.png

Added
New image
Add a comment to this file

tools/ns-allinone-3.14.1/ns-3.14.1/doc/tutorial/source/figures/dumbbell.dia

Binary file added.

Add a comment to this file

tools/ns-allinone-3.14.1/ns-3.14.1/doc/tutorial/source/figures/helpers.dia

Binary file added.

Add a comment to this file

tools/ns-allinone-3.14.1/ns-3.14.1/doc/tutorial/source/figures/oneobj.png

Added
New image
Add a comment to this file

tools/ns-allinone-3.14.1/ns-3.14.1/doc/tutorial/source/figures/pp.dia

Binary file added.

Add a comment to this file

tools/ns-allinone-3.14.1/ns-3.14.1/doc/tutorial/source/figures/star.dia

Binary file added.

Add a comment to this file

tools/ns-allinone-3.14.1/ns-3.14.1/doc/tutorial/source/figures/threeobj.png

Added
New image
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.