Communitygithub.com

网络BGP诊断

仅用于诊断的BGP故障排查模式,涵盖邻居状态、路由交换、前缀策略、AS路径检查和安全证据收集。当BGP邻居中断、路由丢失或需要检查前缀策略和AS路径时使用。

网络BGP诊断 是什么?

该技能提供了一套全面的BGP诊断工作流,专注于只读证据收集,适用于BGP会话中断、振荡、已建立但路由缺失或广播意外前缀等场景。它支持所有主流网络平台(如Cisco IOS、NX-OS、Juniper等),并通过标准show命令和Python解析器模式帮助工程师快速定位问题。其核心优势在于避免误诊常见陷阱(如将Active状态误判为对端故障、忽略VRF和地址族差异),并严格区分只读诊断与变更窗口操作(如清除会话、修改路由策略)。技能内容覆盖了状态解释、传输层检查、路由策略分析、AS路径审查,并提供了可复用的解析器代码示例,特别适合与自动化运维工具或AI助手(如Claude Code、Coder)集成,用于网络故障排查和变更前验证。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/network-bgp-diagnostics

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

网络BGP诊断 是做什么的?

当BGP会话中断、振荡、已建立但缺少路由,或广播异常前缀时,使用本技能。默认工作流仅为只读证据收集;策略修改和重置操作应在经过审核的变更窗口中进行。

何时使用

  • BGP邻居卡在Idle、Connect、Active、OpenSent或OpenConfirm状态。
  • 会话已建立(Established),但预期前缀缺失。
  • 可能存在路由映射(route-map)、前缀列表(prefix-list)、最大前缀限制(max-prefix limit)或AS路径策略导致路由被过滤。
  • 需要收集BGP变更前后的证据。
  • 审查解析BGP摘要输出的自动化脚本。

只读排查流程

  1. 确认确切的邻居、地址族、VRF以及本地/远程AS号。
  2. 捕获摘要状态和最后一次重置原因。
  3. 验证与对端源地址的可达性。
  4. 在假设传输层故障前,先检查路由策略引用。
  5. 在支持的平台上,比较通告路由、接收路由和已安装路由。
show bgp summary
show bgp neighbors <peer>
show ip route <peer>
show tcp brief | include <peer>|:179
show logging | include BGP|<peer>
show running-config | section router bgp
show ip prefix-list
show route-map

当设备使用VRF、IPv6、VPNv4或EVPN时,请使用平台特定的地址族命令。不要假设全局IPv4单播。

状态解释

状态首要检查项
Established(有前缀计数)路由交换正常;检查策略和表选择
Established(零前缀)检查入站策略、max-prefix、通告路由和AFI/SAFI
ActiveTCP会话未完成;检查路由、源地址、ACL和对端可达性
ConnectTCP连接进行中;检查路径和远程监听器
OpenSent/OpenConfirmTCP正常;检查AS号、认证、计时器、能力和日志
Idle邻居可能被禁用、缺少配置、被策略阻止,或处于回退计时器状态

传输层检查

ping <peer> source <local-source>
traceroute <peer> source <local-source>
show ip route <peer>
show bgp neighbors <peer> | include BGP state|Last reset|Local host|Foreign host

如果对端源地址来自环回接口,请确认两个方向的路由都能到达环回地址,并且邻居配置使用了预期的更新源。

避免将禁用ACL或防火墙策略作为诊断捷径。先读取命中计数器、日志和路径状态。

路由策略检查

show bgp neighbors <peer> advertised-routes
show bgp neighbors <peer> routes
show ip prefix-list <name>
show route-map <name>
show bgp <prefix>

有些平台需要额外配置才能启用received-routes。在事件排查期间,除非操作员批准变更,否则不要添加该配置。

AS路径与前缀审查

show bgp regexp _65001_
show bgp regexp ^65001$
show bgp <prefix>
show bgp neighbors <peer> advertised-routes | include Network|Path|<prefix>

谨慎使用AS路径正则。_65001_匹配作为令牌的AS 65001。单纯的65001可能匹配更长的AS号或不相关的文本。

解析器模式

import re
from typing import Any

BGP_SUMMARY_RE = re.compile(
    r"^(?P<neighbor>\d{1,3}(?:\.\d{1,3}){3})\s+"
    r"(?P<version>\d+)\s+"
    r"(?P<remote_as>\d+)\s+"
    r"(?P<msg_rcvd>\d+)\s+"
    r"(?P<msg_sent>\d+)\s+"
    r"(?P<table_version>\d+)\s+"
    r"(?P<input_queue>\d+)\s+"
    r"(?P<output_queue>\d+)\s+"
    r"(?P<uptime>\S+)\s+"
    r"(?P<state_or_prefixes>\S+)$",
    re.M,
)

def parse_bgp_summary(raw: str) -> list[dict[str, Any]]:
    rows = []
    for match in BGP_SUMMARY_RE.finditer(raw):
        state_or_prefixes = match.group("state_or_prefixes")
        if state_or_prefixes.isdigit():
            state = "Established"
            prefixes_received = int(state_or_prefixes)
        else:
            state = state_or_prefixes
            prefixes_received = None
        rows.append({
            "neighbor": match.group("neighbor"),
            "remote_as": int(match.group("remote_as")),
            "state": state,
            "prefixes_received": prefixes_received,
            "uptime": match.group("uptime"),
        })
    return rows

尽可能使用结构化解析器输出,但也要将原始输出与事件记录一起保存,因为BGP摘要格式因平台和地址族而异。

仅限变更窗口

以下操作会影响路由,不应作为自动诊断建议:

  • 清除BGP会话。
  • 更改邻居认证、计时器、更新源、路由映射或前缀列表。
  • 启用额外的接收路由存储。
  • 放宽防火墙、ACL或控制平面策略。

如果重置操作获得批准,优先选择平台支持的、干扰最小的软重置或路由刷新选项,并明确记录其安全性依据。

反模式

  • 假设Active状态总是意味着对端宕机。
  • 忽略VRF、地址族或更新源差异。
  • 使用不含令牌边界的宽泛AS路径正则。
  • 在读取最后一次重置原因和日志之前,直接硬重置对等体。
  • 将缺失的received-routes输出作为没有路由到达的证据。

参见

  • 技能:cisco-ios-patterns
  • 技能:network-config-validation
  • 技能:network-interface-health

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相关技能