Пример #1
0
def printRouteDetailEntry(entry, vlan_aggregate_port_map, vlan_port_map):
    suffix = ""
    if entry.isConnected:
        suffix += " (connected)"
    print("Network Address: %s/%d %s" %
          (utils.ip_ntop(entry.dest.ip.addr), entry.dest.prefixLength, suffix))
    for clAndNxthops in entry.nextHopMulti:
        print("  Nexthops from client %d" % clAndNxthops.clientId)
        if clAndNxthops.nextHopAddrs:
            for address in clAndNxthops.nextHopAddrs:
                print("    %s" %
                      utils.nexthop_to_str(NextHopThrift(address=address)))
        elif clAndNxthops.nextHops:
            for nextHop in clAndNxthops.nextHops:
                print("    %s" % utils.nexthop_to_str(nextHop))
    print("  Action: %s" % entry.action)
    if entry.nextHops and len(entry.nextHops) > 0:
        print("  Forwarding via:")
        for nextHop in entry.nextHops:
            print("    {}".format(
                utils.nexthop_to_str(nextHop, vlan_aggregate_port_map,
                                     vlan_port_map)))
    elif len(entry.fwdInfo) > 0:
        print("  Forwarding via:")
        for ifAndIp in entry.fwdInfo:
            print("    (i/f %d) %s" %
                  (ifAndIp.interfaceID, utils.ip_ntop(ifAndIp.ip.addr)))
    else:
        print("  No Forwarding Info")
    print("  Admin Distance: %s" % entry.adminDistance)
    print()
Пример #2
0
    def run(self, client_id, ipv4, ipv6, prefixes: t.List[str]):
        with ExitStack() as stack:
            agent_client = stack.enter_context(self._create_agent_client())
            try:
                qsfp_client = stack.enter_context(self._create_qsfp_client())
            except TTransportException:
                qsfp_client = None
            if client_id is None:
                resp = agent_client.getRouteTable()
            else:
                resp = agent_client.getRouteTableByClient(client_id)
            if not resp:
                print("No Route Table Entries Found")
                return

            # Getting the port/agg to VLAN map in order to display them
            vlan_port_map = utils.get_vlan_port_map(
                agent_client, qsfp_client, colors=False, details=False
            )
            vlan_aggregate_port_map = utils.get_vlan_aggregate_port_map(agent_client)

            for entry in resp:
                prefix_str = (
                    f"{utils.ip_ntop(entry.dest.ip.addr)}/{entry.dest.prefixLength}"
                )
                ucmp_active = " (UCMP Active)" if is_ucmp_active(entry.nextHops) else ""

                # Apply filters
                if ipv6 and not ipv4 and len(entry.dest.ip.addr) == 4:
                    continue
                if ipv4 and not ipv6 and len(entry.dest.ip.addr) == 16:
                    continue
                if prefixes and prefix_str not in prefixes:
                    continue

                # Print header
                print(f"Network Address: {prefix_str}{ucmp_active}")

                # Need to check the nextHopAddresses
                if entry.nextHops:
                    for nextHop in entry.nextHops:
                        print(
                            "\tvia %s"
                            % (
                                utils.nexthop_to_str(
                                    nextHop,
                                    vlan_aggregate_port_map=vlan_aggregate_port_map,
                                    vlan_port_map=vlan_port_map,
                                )
                            )
                        )
                else:
                    for address in entry.nextHopAddrs:
                        print(
                            "\tvia %s"
                            % utils.nexthop_to_str(NextHopThrift(address=address))
                        )
Пример #3
0
    def run(self, client_id, ipv4, ipv6):
        with ExitStack() as stack:
            agent_client = stack.enter_context(self._create_agent_client())
            qsfp_client = stack.enter_context(self._create_qsfp_client())
            if client_id is None:
                resp = agent_client.getRouteTable()
            else:
                resp = agent_client.getRouteTableByClient(client_id)
            if not resp:
                print("No Route Table Entries Found")
                return

            # Getting the port/agg to VLAN map in order to display them
            vlan_port_map = utils.get_vlan_port_map(
                agent_client, qsfp_client, colors=False, details=False
            )
            vlan_aggregate_port_map = utils.get_vlan_aggregate_port_map(agent_client)

            for entry in resp:
                if ipv6 and not ipv4 and len(entry.dest.ip.addr) == 4:
                    continue
                if ipv4 and not ipv6 and len(entry.dest.ip.addr) == 16:
                    continue

                prefix = utils.ip_ntop(entry.dest.ip.addr)
                prefix_mask_len = entry.dest.prefixLength
                ucmp_active = " (UCMP Active)" if is_ucmp_active(entry.nextHops) else ""
                print(f"Network Address: {prefix}/{prefix_mask_len}{ucmp_active}")

                # Need to check the nextHopAddresses
                if entry.nextHops:
                    for nextHop in entry.nextHops:
                        print(
                            "\tvia %s"
                            % (
                                utils.nexthop_to_str(
                                    nextHop,
                                    vlan_aggregate_port_map=vlan_aggregate_port_map,
                                    vlan_port_map=vlan_port_map,
                                    ucmp_active=ucmp_active,
                                )
                            )
                        )
                else:
                    for address in entry.nextHopAddrs:
                        print(
                            "\tvia %s"
                            % utils.nexthop_to_str(NextHopThrift(address=address))
                        )