Exemplo n.º 1
0
 def _update(interface_info_dict, interface_info):
     interface_info_dict.update({
         'v4Addrs': [utils.sprint_addr(v4Addr.addr)
                     for v4Addr in interface_info.v4Addrs],
         'v6LinkLocalAddrs': [utils.sprint_addr(v6Addr.addr)
                              for v6Addr in interface_info.v6LinkLocalAddrs]
     })
Exemplo n.º 2
0
 def _parse(if2node, adj_db):
     nexthop_dict = if2node[adj_db.thisNodeName]
     for adj in adj_db.adjacencies:
         nh6_addr = utils.sprint_addr(adj.nextHopV6.addr)
         nh4_addr = utils.sprint_addr(adj.nextHopV4.addr)
         nexthop_dict[(adj.ifName, nh6_addr)] = adj.otherNodeName
         nexthop_dict[(adj.ifName, nh4_addr)] = adj.otherNodeName
Exemplo n.º 3
0
        def _backtracking(cur, path, hop, visited, in_fib):
            if hop > max_hop:
                return

            cur_lpm_len = self.get_lpm_len_from_node(cur, dst_addr, prefix_dbs)
            next_hop_nodes = self.get_nexthop_nodes(client.get_route_db(cur),
                                                    dst_addr, cur_lpm_len,
                                                    if2node, fib_routes,
                                                    in_fib)

            if len(next_hop_nodes) == 0:
                if hop != 1:
                    paths.append((in_fib, path[:]))
                return

            for next_hop_node in next_hop_nodes:
                next_hop_node_name = next_hop_node[0]
                # prevent loops
                if next_hop_node_name in visited:
                    return

                path.append([hop] + next_hop_node)
                visited.add(next_hop_node_name)

                # check if next hop node is in fib path
                is_nexthop_in_fib_path = False
                for nexthop in fib_routes[cur]:
                    if next_hop_node[3] == utils.sprint_addr(nexthop.addr) and\
                            next_hop_node[1] == nexthop.ifName:
                        is_nexthop_in_fib_path = True

                _backtracking(next_hop_node_name, path, hop + 1, visited,
                              is_nexthop_in_fib_path and in_fib)
                visited.remove(next_hop_node_name)
                path.pop()
Exemplo n.º 4
0
    def get_nexthop_nodes(self, route_db, dst_addr, cur_lpm_len, if2node,
                          fib_routes, in_fib):
        ''' get the next hop nodes.
        if the longest prefix is coming from the current node,
        return an empty list to terminate the path searching. '''

        next_hop_nodes = []
        is_initialized = fib_routes[route_db.thisNodeName]

        for lpm_route in self.get_lpm_routes(route_db, dst_addr):
            if lpm_route.prefix.prefixLength <= cur_lpm_len:
                continue
            if in_fib and not is_initialized:
                fib_routes[route_db.thisNodeName].extend(
                    self.get_fib_path(route_db.thisNodeName,
                                      utils.sprint_prefix(lpm_route.prefix),
                                      self.fib_agent_port, self.timeout))

            for path in lpm_route.paths:
                if len(path.nextHop.addr) == 16:
                    next_hop_node_name = if2node[route_db.thisNodeName][
                        path.ifName]
                    next_hop_nodes.append([
                        next_hop_node_name, path.ifName, path.metric,
                        utils.sprint_addr(path.nextHop.addr)
                    ])

        return next_hop_nodes
Exemplo n.º 5
0
    def get_nexthop_nodes(self, route_db, dst_addr, cur_lpm_len,
                          if2node, fib_routes, in_fib):
        ''' get the next hop nodes.
        if the longest prefix is coming from the current node,
        return an empty list to terminate the path searching. '''

        next_hop_nodes = []
        is_initialized = fib_routes[route_db.thisNodeName]

        lpm_route = self.get_lpm_route(route_db, dst_addr)
        if lpm_route and lpm_route.prefix.prefixLength >= cur_lpm_len:
            if in_fib and not is_initialized:
                fib_routes[route_db.thisNodeName].extend(
                    self.get_fib_path(
                        route_db.thisNodeName,
                        utils.sprint_prefix(lpm_route.prefix),
                        self.fib_agent_port,
                        self.timeout))
            min_cost = min([p.metric for p in lpm_route.paths])
            for path in [p for p in lpm_route.paths if p.metric == min_cost]:
                if len(path.nextHop.addr) == 16:
                    nh_addr = utils.sprint_addr(path.nextHop.addr)
                    next_hop_node_name = \
                        if2node[route_db.thisNodeName][(path.ifName, nh_addr)]
                    next_hop_nodes.append([
                        next_hop_node_name,
                        path.ifName,
                        path.metric,
                        nh_addr,
                    ])
        return next_hop_nodes
Exemplo n.º 6
0
def ip_nexthop_to_str(nh):
    '''
    Convert ttypes.BinaryAddress to string representation of a nexthop
    '''

    return "{}{}{}".format(utils.sprint_addr(nh.addr),
                           '@' if nh.ifName else '', nh.ifName)
Exemplo n.º 7
0
    def print_links_table(interfaces, caption=None):
        '''
        @param interfaces: dict<interface-name, InterfaceDetail>
        @param caption: Caption to show on table name
        '''

        rows = []
        columns = [
            'Interface', 'Status', 'Overloaded', 'Metric Override', 'ifIndex',
            'Addresses'
        ]

        for (k, v) in sorted(interfaces.items()):
            state = 'Up' if v.info.isUp else 'Down'
            overloaded = 'True' if v.isOverloaded else ''
            metric_override = v.metricOverride if v.metricOverride else ''
            index = v.info.ifIndex
            rows.append([k, state, overloaded, metric_override, index, ''])
            firstAddr = True
            for a in (v.info.v4Addrs + v.info.v6LinkLocalAddrs):
                addrStr = utils.sprint_addr(a.addr)
                if firstAddr:
                    rows[-1][5] = addrStr
                    firstAddr = False
                else:
                    rows.append(['', '', '', '', '', addrStr])

        print(printing.render_horizontal_table(rows, columns, caption))
        print()
Exemplo n.º 8
0
    def print_config(self, prefix_alloc):
        seed_prefix = prefix_alloc.seedPrefix
        seed_prefix_addr = utils.sprint_addr(seed_prefix.prefixAddress.addr)

        caption = 'Prefix Allocator parameters stored'
        rows = []
        rows.append(['Seed prefix: {}/{}'.format(seed_prefix_addr,
                    seed_prefix.prefixLength)])
        rows.append(['Allocated prefix length: {}'.format(
                    prefix_alloc.allocPrefixLen)])
        rows.append(['Allocated prefix index: {}'.format(
            prefix_alloc.allocPrefixIndex)])

        print(printing.render_vertical_table(rows, caption=caption))
Exemplo n.º 9
0
    def run(self):
        resp = self.client.peek()
        headers = [
            'Node', 'IP Address', 'Last Value Sent', 'Last Ack From Node',
            'Last Ack To Node'
        ]
        rows = []
        for name, node in resp.nodeInfo.items():
            rows.append([
                name,
                utils.sprint_addr(node.ipAddress), node.lastValSent,
                node.lastAckFromNode, node.lastAckToNode
            ])

        print()
        print(tabulate.tabulate(rows, headers=headers))
        print()
Exemplo n.º 10
0
    def get_node_ip(self, prefix_db):
        '''
        get routable IP address of node from it's prefix database
        :return: string representation of Node's IP addresss. Returns None if
                 no IP found.
        '''

        # First look for LOOPBACK prefix
        for prefix_entry in prefix_db.prefixEntries:
            if prefix_entry.type == lsdb_types.PrefixType.LOOPBACK:
                return utils.sprint_addr(prefix_entry.prefix.prefixAddress.addr)

        # Next look for PREFIX_ALLOCATOR prefix if any
        for prefix_entry in prefix_db.prefixEntries:
            if prefix_entry.type == lsdb_types.PrefixType.PREFIX_ALLOCATOR:
                return utils.alloc_prefix_to_loopback_ip_str(
                    prefix_entry.prefix)

        # Else return None
        return None