Example #1
0
def launch_controller():
    CFG.read(cfg.C1_cfg)
    db = TopologyDB(db=cfg.DB_path)
    manager = SouthboundManager(optimizer=OSPFSimple())
    try:
        manager.run()
    except KeyboardInterrupt:
        manager.stop()
Example #2
0
def launch_controller():
    CFG.read(C1_cfg)
    db = TopologyDB(db=DB_path)
    manager = SouthboundManager(optimizer=OSPFSimple())
    manager.simple_path_requirement(db.subnet(R3, D1), [db.routerid(r)
                                                        for r in (R1, R2, R3)])
    manager.simple_path_requirement(db.subnet(R3, D2), [db.routerid(r)
                                                        for r in (R1, R4, R3)])
    try:
        manager.run()
    except KeyboardInterrupt:
        manager.stop()
Example #3
0
def launch_controller():
    CFG.read(C1_cfg)
    db = TopologyDB(db='/tmp/db.topo')
    manager = SouthboundManager(optimizer=OSPFSimple())

    prefix = db.subnet('r2', 'sw1')
    prefix_m = prefix.split('/')[0] + '/25'
    manager.simple_path_requirement(prefix_m, [db.routerid(r) for r in (R1, R3, R2)])
    import ipdb; ipdb.set_trace()

    try:
        manager.run()
    except KeyboardInterrupt:
        manager.stop()
Example #4
0
 def __init__(self,
              cfg=None,
              optimizer=OSPFSimple(),
              additional_routes=None,
              *args,
              **kwargs):
     if cfg:
         # reading CFG config
         CFG.read(pathtoREScfg)
         CFG.read(cfg)
     self.simple_req = {}
     self.change_pfx = [
     ]  #TODO IF prefixfix is already present before adding it
     super(SouthBoundExtended, self).__init__(optimizer=optimizer,
                                              *args,
                                              **kwargs)
Example #5
0
def write_CFG_ospf(config) :
    # create new parser
    cfg = cparser.ConfigParser()
    # read the template
    cfg.read(template)

    conf = config['config']

    fibbing_ctrl = conf.get('fibbing-controller')
    controller_o_conf = fibbing_ctrl.get('controller-config').get('ospf')
    th_initial_holdtime = controller_o_conf.get('throttle').get('initial_holdtime')
    th_delay = controller_o_conf.get('throttle').get('delay')
    th_max_holdtime = controller_o_conf.get('throttle').get('max_holdtime')
    min_ls_arrival = controller_o_conf.get('lsa').get('min_ls_arrival')
    min_ls_interval = controller_o_conf.get('lsa').get('min_ls_interval')
    hello = controller_o_conf.get('hello-interval')
    dead = controller_o_conf.get('dead-interval')

    private_net = fibbing_ctrl.get('controller-config').get('private-ip-prefix')
    base_net = fibbing_ctrl.get('controller-config').get('base-net-perfix')
    cfg.set(cparser.DEFAULTSECT, 'area', str(controller_o_conf.get('area')))
    cfg.set(cparser.DEFAULTSECT, 'initial_holdtime', int(th_initial_holdtime))
    cfg.set(cparser.DEFAULTSECT, 'delay', int(th_delay))
    cfg.set(cparser.DEFAULTSECT, 'max_holdtime', int(th_max_holdtime))
    cfg.set(cparser.DEFAULTSECT, 'min_ls_interval', int(min_ls_interval))
    cfg.set(cparser.DEFAULTSECT, 'min_ls_arrival', int(min_ls_arrival))
    cfg.set(cparser.DEFAULTSECT, 'hello_interval', str(hello))
    cfg.set(cparser.DEFAULTSECT, 'dead_interval', str(dead))

    # set private ips needed for the fibbing controller
    cfg.set(cparser.DEFAULTSECT, 'private_net', str(private_net))
    cfg.set(cparser.DEFAULTSECT, 'base_net', str(base_net))
    # overrite the default.cfg file
    with open(pathtoREScfg, 'w') as f :
        cfg.write(f)

    # reload the configuration
    CFG.read(pathtoREScfg)
    def __init__(self, congestionThreshold = 0.95):
        """It basically reads the network topology from the MyGraphProvider,
        which is running in another thread because
        SouthboundManager.run() is blocking.
        
        Here we are assuming that the topology does not change.
        """
        # Dictionary that keeps the allocation of the flows in the network paths
        self.flow_allocation = {} 
        # {prefixA: {flow1 : [path_list], flow2 : [path_list]},
        #  prefixB: {flow4 : [path_list], flow3 : [path_list]}}

        # Lock to make flow_allocation thread-safe
        self.flowAllocationLock = threading.Lock()
        
        # From where to read events 
        self.eventQueue = eventQueue
        
        # Used to schedule flow alloc. removals
        self.thread_handlers = {} 

        # Data structure that holds the current forwarding dags for
        # all advertised destinations in the network
        self.dagsLock = threading.Lock()
        self.dags = {}

        # Set the congestion threshold
        self.congestionThreshold = congestionThreshold
        t = time.strftime("%H:%M:%S", time.gmtime())
        log.info("%s - Congestion Threshold is set to %.2f%% of the link\n"%(t, (self.congestionThreshold)*100.0))
        
        # Used to stop the thread
        self._stop = threading.Event() 

        # Object that handles the topology database
        self.db = DatabaseHandler()
    
        # Connects to the southbound controller. Must be called before
        # create instance of SouthboundManager
        CFG.read(dconf.C1_Cfg) 

        # Start the Southbound manager in a different thread.    
        self.sbmanager = MyGraphProvider()
        t = threading.Thread(target=self.sbmanager.run, name="Graph Listener")
        t.start()
        t = time.strftime("%H:%M:%S", time.gmtime())
        log.info("%s - Graph Listener thread started\n"%t)

        # Blocks until initial graph arrived notification is received
        # from southbound manager
        HAS_INITIAL_GRAPH.wait() 
        t = time.strftime("%H:%M:%S", time.gmtime())
        log.info("%s - Initial graph received\n"%t)

        # Retreieve network graph from southbound manager
        self.network_graph = self.sbmanager.igp_graph

        # Mantains the list of the network prefixes advertised by the OSPF routers
        self.ospf_prefixes = self._fillInitialOSPFPrefixes()
        t = time.strftime("%H:%M:%S", time.gmtime())
        log.info("%s - Initial OSPF prefixes read\n"%t)
        
        # Include BW data inside the initial graph.
        n_router_links = self._countRouter2RouterEdges()
        self._readBwDataFromDB()
        i = 0
        while not self._bwInAllRouterEdges(n_router_links):
            i += 1
            time.sleep(1)
            self._readBwDataFromDB()            
        t = time.strftime("%H:%M:%S", time.gmtime())
        log.info("%s - Bandwidths written in network_graph after %d iterations\n"%(t,i))

        # Read the initial graph. We keep this as a copy of the
        # physical topology. In initial graph, the instantaneous
        # capacities of the links are kept.
        self.initial_graph = self.network_graph.copy()
        
        t = time.strftime("%H:%M:%S", time.gmtime())
        log.info("%s - Created IP-names bindings\n"%t)
        log.info("\tHostname\tip\tsubnet\n")
        for name, data in self.db.hosts_to_ip.iteritems():
            log.info("\t%s\t%s\t%s\n"%(name, data['iface_host'], data['iface_router']))

        log.info("\tRouter name\tip\t\n")
        for name, ip in self.db.routers_to_ip.iteritems():
            log.info("\t%s\t%s\n"%(name, ip))

        # Create here the initial DAGS for each destination in the
        # network
        self._createInitialDags()
        t = time.strftime("%H:%M:%S", time.gmtime())
        log.info("%s - Initial DAGS created\n"%t)

        # Spawn Json listener thread
        jl = JsonListener(self.eventQueue)
        jl.start()
        t = time.strftime("%H:%M:%S", time.gmtime())
        log.info("%s - Json listener thread created\n"%t)

        # Create attributes
        self.feedbackRequestQueue = feedbackRequestQueue
        self.feedbackResponseQueue = feedbackResponseQueue
        
        # Dict in which we save flows pending for allocation feedback
        self.pendingForFeedback = {}

        # Spawn FeedbackThread
        ft = feedbackThread(self.feedbackRequestQueue, self.feedbackResponseQueue)
        ft.start()
        t = time.strftime("%H:%M:%S", time.gmtime())
        log.info("%s - feedbackThread started\n"%t)