Beispiel #1
0
 def __init__(self, **kwargs):
     super(RootRouter, self).__init__(ospf_priority=2, **kwargs)
     # Register the physical ports apart
     self.physical_links = []
     self.lsdb_log_file = None
     self.lsdb_log_file_name = '%s_%s' % (LSDB_LOG_PATH, self.id)
     if os.path.exists(self.lsdb_log_file_name):
         os.unlink(self.lsdb_log_file_name)
     os.mkfifo(self.lsdb_log_file_name)
     self.lsdb = LSDB()
Beispiel #2
0
 def __init__(self, **kwargs):
     super(RootRouter, self).__init__(ospf_priority=2, **kwargs)
     # Register the physical ports apart
     self.physical_links = []
     self.lsdb_log_file = None
     self.lsdb_log_file_name = '%s_%s' % (LSDB_LOG_PATH, self.id)
     if os.path.exists(self.lsdb_log_file_name):
         os.unlink(self.lsdb_log_file_name)
     os.mkfifo(self.lsdb_log_file_name)
     self.lsdb = LSDB()
Beispiel #3
0
class RootRouter(Router):
    """
    The fibbing router that will interact with the real ones in the network
    """

    def __init__(self, **kwargs):
        super(RootRouter, self).__init__(**kwargs)
        # ospf prio set to 2 to be the DR of all fibbing routers
        self.ospf_priority = 2
        # Register the physical ports apart
        self.physical_links = []
        self.lsdb_log_file = None
        self.lsdb_log_file_name = '%s_%s' % (LSDB_LOG_PATH, self.id)
        if os.path.exists(self.lsdb_log_file_name):
            os.unlink(self.lsdb_log_file_name)
        os.mkfifo(self.lsdb_log_file_name)
        self.lsdb = LSDB()

    def add_physical_link(self, link):
        """
        Add physical ports to its assigned ports
        :param link: A PhysicalLink to 'the outside world'
        """
        self.physical_links.append(link)

    def __str__(self):
        top = ' | '.join([str(port) for port in self.physical_links])
        return '%s\n%s\n%s%s\n%s' %\
               (top,
                '-' * len(top),
                ' ' * ((len(top) - len(self.id)) / 2),
                self.id,
                ' | '.join([str(port)
                            for port in self.interfaces.values()
                            if port not in self.physical_links]))

    def start(self, *extra_args):
        super(RootRouter, self).start('--log_lsdb',
                                      self.lsdb_log_file_name,
                                      *extra_args)

    def delete(self):
        self.lsdb.stop()
        super(RootRouter, self).delete()
        force(self.lsdb_log_file.close)
        force(os.unlink, self.lsdb_log_file_name)

    def parse_lsdblog(self):
        def fifo_readline(f):
            buf = ''
            data = True
            while data:
                data = f.read(1)
                buf += data
                if data == '\n':
                    yield buf
                    buf = ''

        self.lsdb_log_file = open(self.lsdb_log_file_name, 'r')
        for line in fifo_readline(self.lsdb_log_file):
            try:
                self.lsdb.commit_change(line[:-1])
            except Exception as e:
                # We do not want to crash the whole node ...
                # rather log the error
                # And stop parsing the LSDB
                log.error('Failed to parse LSDB update %s [%s]', line, str(e))
                log.exception(e)
        log.debug('Stopped updating the LSDB')

    def send_lsdblog_to(self, listener):
        self.lsdb.register_change_listener(listener)

    def get_fwd_address(self, src, dst):
        fwd = self.lsdb.forwarding_address_of(src, dst)
        log.debug('fwding address of %s-%s is %s', src, dst, fwd)
        return fwd
Beispiel #4
0
class RootRouter(Router):
    """
    The fibbing router that will interact with the real ones in the network
    """

    def __init__(self, **kwargs):
        super(RootRouter, self).__init__(ospf_priority=2, **kwargs)
        # Register the physical ports apart
        self.physical_links = []
        self.lsdb_log_file = None
        self.lsdb_log_file_name = '%s_%s' % (LSDB_LOG_PATH, self.id)
        if os.path.exists(self.lsdb_log_file_name):
            os.unlink(self.lsdb_log_file_name)
        os.mkfifo(self.lsdb_log_file_name)
        self.lsdb = LSDB()

    def add_physical_link(self, link):
        """
        Add physical ports to its assigned ports
        :param link: A PhysicalLink to 'the outside world'
        """
        self.physical_links.append(link)

    def __str__(self):
        top = ' | '.join([str(port) for port in self.physical_links])
        return '%s\n%s\n%s%s\n%s' %\
               (top,
                '-' * len(top),
                ' ' * ((len(top) - len(self.id)) / 2),
                self.id,
                ' | '.join([str(port)
                            for port in self.interfaces.values()
                            if port not in self.physical_links]))

    def start(self, *extra_args):
        super(RootRouter, self).start('--log_lsdb',
                                      self.lsdb_log_file_name,
                                      *extra_args)

    def delete(self):
        self.lsdb.stop()
        for p in self.physical_links:
            p.move_to_root()
        super(RootRouter, self).delete()
        if self.lsdb_log_file:
            force(self.lsdb_log_file.close)
        force(os.unlink, self.lsdb_log_file_name)

    def parse_lsdblog(self):
        def fifo_readline(f):
            buf = ''
            data = True
            while data:
                data = f.read(1)
                buf += data
                if data == '\n':
                    yield buf
                    buf = ''

        self.lsdb_log_file = open(self.lsdb_log_file_name, 'r')
        for line in fifo_readline(self.lsdb_log_file):
            try:
                self.lsdb.commit_change(line[:-1])
            except Exception as e:
                # We do not want to crash the whole node ...
                # rather log the error
                # And stop parsing the LSDB
                log.error('Failed to parse LSDB update %s [%s]', line, str(e))
                log.exception(e)
        log.debug('Stopped updating the LSDB')

    def send_lsdblog_to(self, listener):
        self.lsdb.register_change_listener(listener)

    def get_fwd_address(self, src, dst):
        """Return the list of forwarding address from src to dst"""
        fwd = self.lsdb.forwarding_address_of(src, dst)
        log.debug('fwding address of %s-%s is %s', src, dst, fwd)
        return fwd