├── requirements.txt ├── output ├── junos_gnmi.md ├── architecture.md ├── api.md ├── security.md └── evpn_design.md ├── processed ├── junos_gnmi.jsonld ├── architecture.jsonld ├── api.jsonld ├── security.jsonld ├── junos_gnmi.ast.json ├── api.ast.json ├── architecture.ast.json ├── security.ast.json └── evpn_design.jsonld ├── md2jsonld.py ├── README.md ├── rag_chat.py └── LICENSE /requirements.txt: -------------------------------------------------------------------------------- 1 | # Core RAG dependencies 2 | sentence-transformers>=2.2.2 3 | faiss-cpu>=1.7.4 4 | openai>=1.3.0 5 | gradio>=4.0.0 6 | numpy>=1.21.0 7 | 8 | # Document processing 9 | panflute>=2.3.0 10 | pandoc-filter>=0.2.16 11 | pyyaml>=6.0 12 | 13 | # Utilities 14 | requests>=2.28.0 15 | pathlib>=1.0.0 16 | logging>=0.4.9.6 17 | 18 | # Optional: GPU support for FAISS (uncomment if you have CUDA) 19 | # faiss-gpu>=1.7.4 20 | 21 | # Optional: Alternative sentence transformers backends 22 | # torch>=1.9.0 23 | # transformers>=4.20.0 -------------------------------------------------------------------------------- /output/junos_gnmi.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: junos_gnmimd 3 | title: "GNMI without Certificates on Juniper" 4 | description: "Config guide to run JunOS GNMI in insecure mode without certs" 5 | created: 2024-01-20 6 | author: "Network Automation Team" 7 | version: "1.0" 8 | category: "network-knowledge-base" 9 | keywords: 10 | - gnmi 11 | - juniper 12 | - grpc 13 | - insecure-mode 14 | training_questions: 15 | - How do I configure JunOS GNMI without certificates? 16 | - What port does JunOS use for insecure GNMI? 17 | related_products: 18 | - vMX 22.3R1.11 19 | - vQFX 19.4R1.10 20 | topics: 21 | - Network Telemetry 22 | - Juniper Configuration 23 | --- 24 | 25 | 26 | ## How to setup a JunOS device for GNMI 27 | 28 | The configuration is fairly simple for a lab scenario where we will not use certificates and use the insecure mode. 29 | Please refer to the Juniper Site for details on configuration using Certificates. 30 | 31 | This was tested on the vMX 22.3R1.11 and vQFX 19.4R1.10 32 | Note: Although configuration is accepted on the vQFX it was not possible to get GNMI working on this platform. This could be due to the fact that the insecure mode is not supported in earlier releases 33 | 34 | ## How to setup a JunOS device for GNMI without certificates {#gnmi_no_certs .Section primary="true"} 35 | ``` 36 | set system services extension-service request-response grpc clear-text port 57400 37 | set system services extension-service request-response grpc max-connections 4 38 | ``` 39 | 40 | You will also need this for the reponse to be sent back to the client. 41 | 42 | ``` 43 | set system services extension-service request-response grpc routing-instance mgmt_junos 44 | ``` -------------------------------------------------------------------------------- /processed/junos_gnmi.jsonld: -------------------------------------------------------------------------------- 1 | { 2 | "@context": { 3 | "@vocab": "https://schema.org/", 4 | "mainEntity": { 5 | "@id": "schema:mainEntity", 6 | "@type": "@id" 7 | }, 8 | "trainingQuestions": { 9 | "@container": "@list" 10 | }, 11 | "relatedProducts": { 12 | "@container": "@list" 13 | }, 14 | "topics": { 15 | "@container": "@list" 16 | }, 17 | "keywords": { 18 | "@container": "@list" 19 | } 20 | }, 21 | "@graph": [ 22 | { 23 | "@type": "Document", 24 | "@id": "junos_gnmimd", 25 | "filename": "junos_gnmi.md", 26 | "title": "GNMI without Certificates on Juniper", 27 | "description": "Config guide to run JunOS GNMI in insecure mode without certs", 28 | "dateCreated": "2024-01-20", 29 | "author": "Network Automation Team", 30 | "version": "1.0", 31 | "category": "network-knowledge-base", 32 | "keywords": [ 33 | "gnmi", 34 | "juniper", 35 | "grpc", 36 | "insecure-mode" 37 | ], 38 | "trainingQuestions": [ 39 | "How do I configure JunOS GNMI without certificates?", 40 | "What port does JunOS use for insecure GNMI?" 41 | ], 42 | "relatedProducts": [ 43 | "vMX 22.3R1.11", 44 | "vQFX 19.4R1.10" 45 | ], 46 | "topics": [ 47 | "Network Telemetry", 48 | "Juniper Configuration" 49 | ], 50 | "mainEntity": "junos_gnmimd-sec-3-how-to-setup-a-junos-device-for-gnmi-without-certificates" 51 | }, 52 | { 53 | "@type": "Section", 54 | "@id": "junos_gnmimd-sec-2-how-to-setup-a-junos-device-for-gnmi", 55 | "title": "How to setup a JunOS device for GNMI", 56 | "level": 2, 57 | "content": "The configuration is fairly simple for a lab scenario where we will not use certificates and use the insecure mode. Please refer to the Juniper Site for details on configuration using Certificates.\n\nThis was tested on the vMX 22.3R1.11 and vQFX 19.4R1.10 Note: Although configuration is accepted on the vQFX it was not possible to get GNMI working on this platform. This could be due to the fact that the insecure mode is not supported in earlier releases", 58 | "primary": false 59 | }, 60 | { 61 | "@type": "Section", 62 | "@id": "junos_gnmimd-sec-3-how-to-setup-a-junos-device-for-gnmi-without-certificates", 63 | "title": "How to setup a JunOS device for GNMI without certificates", 64 | "level": 2, 65 | "content": "```\nset system services extension-service request-response grpc clear-text port 57400\nset system services extension-service request-response grpc max-connections 4\n```\n\nYou will also need this for the reponse to be sent back to the client.\n\n```\nset system services extension-service request-response grpc routing-instance mgmt_junos\n```", 66 | "primary": true 67 | } 68 | ] 69 | } -------------------------------------------------------------------------------- /output/architecture.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "System Architecture Design" 3 | description: "Overall system architecture and core components" 4 | author: "Engineering Team" 5 | created: "2024-01-15" 6 | version: "1.0" 7 | id: "system-architecture" 8 | category: "architecture" 9 | keywords: 10 | - system-architecture 11 | - microservices 12 | - api-gateway 13 | - kubernetes 14 | - docker 15 | - jwt-authentication 16 | - cloud-native 17 | topics: 18 | - Software Architecture 19 | - Distributed Systems 20 | - Cloud-Native Design 21 | - DevOps Practices 22 | relatedProducts: 23 | - "Core Platform v2.0" 24 | trainingQuestions: 25 | - "What is the role of the API Gateway in this architecture?" 26 | - "How is authentication managed across services?" 27 | - "What principles drive this system architecture?" 28 | - "What are the core services in the design?" 29 | - "How is the deployment managed using Kubernetes?" 30 | --- 31 | 32 | 33 | # System Architecture Design 34 | 35 | This document outlines the high-level architecture of our distributed system. 36 | 37 | ## Overview 38 | 39 | Our system follows a microservices architecture pattern with clear separation of concerns. The architecture is designed for scalability, maintainability, and fault tolerance. 40 | 41 | Key principles: 42 | - Microservices architecture 43 | - Event-driven communication 44 | - API-first design 45 | - Cloud-native deployment 46 | 47 | ## Core Components 48 | 49 | ### API Gateway 50 | 51 | The API Gateway serves as the single entry point for all client requests. It handles: 52 | - Request routing and load balancing 53 | - Authentication and authorization 54 | - Rate limiting and throttling 55 | - Request/response transformation 56 | 57 | ```yaml 58 | apiGateway: 59 | port: 8080 60 | timeout: 30s 61 | rateLimit: 1000/min 62 | auth: 63 | type: JWT 64 | secret: ${JWT_SECRET} 65 | ``` 66 | 67 | ### User Service 68 | 69 | Manages user accounts, profiles, and authentication: 70 | - User registration and login 71 | - Profile management 72 | - Password reset functionality 73 | - Social authentication integration 74 | 75 | ### Data Service 76 | 77 | Handles all data operations: 78 | - CRUD operations for business entities 79 | - Data validation and transformation 80 | - Caching layer integration 81 | - Database connection pooling 82 | 83 | ## Database Schema 84 | 85 | | Table | Purpose | Key Fields | 86 | |-------|---------|------------| 87 | | users | User accounts | id, email, password_hash | 88 | | profiles | User profiles | user_id, name, avatar_url | 89 | | sessions | Active sessions | id, user_id, expires_at | 90 | 91 | ## Deployment Architecture 92 | 93 | The system is deployed using Docker containers orchestrated by Kubernetes: 94 | 95 | ```dockerfile 96 | FROM node:16-alpine 97 | WORKDIR /app 98 | COPY package*.json ./ 99 | RUN npm ci --only=production 100 | COPY . . 101 | EXPOSE 3000 102 | CMD ["npm", "start"] 103 | ``` -------------------------------------------------------------------------------- /output/api.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "REST API Documentation" 3 | description: "Complete API reference for client integration" 4 | author: "API Team" 5 | created: "2024-01-20" 6 | version: "1.0" 7 | id: "rest_api_doc" 8 | category: "api" 9 | keywords: 10 | - api 11 | - rest 12 | - jwt 13 | - authentication 14 | - pagination 15 | - error-handling 16 | - client-integration 17 | topics: 18 | - REST API Design 19 | - Secure API Access 20 | - Client Development 21 | relatedProducts: 22 | - "API Platform v1.0" 23 | trainingQuestions: 24 | - "How do I authenticate using JWT with the API?" 25 | - "How can I retrieve a paginated list of items?" 26 | - "What does the login endpoint return?" 27 | - "How does the API handle input validation errors?" 28 | - "What rate limits are enforced per user?" 29 | --- 30 | 31 | 32 | # REST API Documentation 33 | 34 | This document provides comprehensive documentation for our REST API endpoints. 35 | 36 | ## Authentication 37 | 38 | All API endpoints require authentication using JWT tokens. Include the token in the Authorization header: 39 | 40 | ``` 41 | Authorization: Bearer 42 | ``` 43 | 44 | ## User Endpoints 45 | 46 | ### POST /api/users/register 47 | 48 | Register a new user account. 49 | 50 | **Request Body:** 51 | ```json 52 | { 53 | "email": "user@example.com", 54 | "password": "securePassword123", 55 | "name": "John Doe" 56 | } 57 | ``` 58 | 59 | **Response:** 60 | ```json 61 | { 62 | "id": "user_123", 63 | "email": "user@example.com", 64 | "name": "John Doe", 65 | "createdAt": "2024-01-20T10:00:00Z" 66 | } 67 | ``` 68 | 69 | ### POST /api/users/login 70 | 71 | Authenticate user and receive JWT token. 72 | 73 | **Request Body:** 74 | ```json 75 | { 76 | "email": "user@example.com", 77 | "password": "securePassword123" 78 | } 79 | ``` 80 | 81 | **Response:** 82 | ```json 83 | { 84 | "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", 85 | "expiresIn": 3600, 86 | "user": { 87 | "id": "user_123", 88 | "email": "user@example.com", 89 | "name": "John Doe" 90 | } 91 | } 92 | ``` 93 | 94 | ## Data Endpoints 95 | 96 | ### GET /api/data/items 97 | 98 | Retrieve paginated list of items. 99 | 100 | **Query Parameters:** 101 | - `page`: Page number (default: 1) 102 | - `limit`: Items per page (default: 20, max: 100) 103 | - `sort`: Sort field (id, name, createdAt) 104 | - `order`: Sort order (asc, desc) 105 | 106 | **Response:** 107 | ```json 108 | { 109 | "items": [ 110 | { 111 | "id": "item_1", 112 | "name": "Sample Item", 113 | "description": "A sample item", 114 | "createdAt": "2024-01-20T10:00:00Z" 115 | } 116 | ], 117 | "pagination": { 118 | "page": 1, 119 | "limit": 20, 120 | "total": 150, 121 | "pages": 8 122 | } 123 | } 124 | ``` 125 | 126 | ### POST /api/data/items 127 | 128 | Create a new item. 129 | 130 | **Request Body:** 131 | ```json 132 | { 133 | "name": "New Item", 134 | "description": "Description of the new item", 135 | "category": "electronics" 136 | } 137 | ``` 138 | 139 | ## Error Handling 140 | 141 | The API uses standard HTTP status codes and returns error details in JSON format: 142 | 143 | ```json 144 | { 145 | "error": { 146 | "code": "VALIDATION_ERROR", 147 | "message": "Invalid input data", 148 | "details": [ 149 | { 150 | "field": "email", 151 | "message": "Invalid email format" 152 | } 153 | ] 154 | } 155 | } 156 | ``` 157 | 158 | ## Rate Limiting 159 | 160 | API requests are limited to 1000 requests per hour per user. Rate limit information is included in response headers: 161 | 162 | ``` 163 | X-RateLimit-Limit: 1000 164 | X-RateLimit-Remaining: 999 165 | X-RateLimit-Reset: 1642694400 166 | ``` -------------------------------------------------------------------------------- /processed/architecture.jsonld: -------------------------------------------------------------------------------- 1 | { 2 | "@context": { 3 | "@vocab": "https://schema.org/", 4 | "mainEntity": { 5 | "@id": "schema:mainEntity", 6 | "@type": "@id" 7 | }, 8 | "trainingQuestions": { 9 | "@container": "@list" 10 | }, 11 | "relatedProducts": { 12 | "@container": "@list" 13 | }, 14 | "topics": { 15 | "@container": "@list" 16 | }, 17 | "keywords": { 18 | "@container": "@list" 19 | } 20 | }, 21 | "@graph": [ 22 | { 23 | "@type": "Document", 24 | "@id": "system-architecture", 25 | "filename": "architecture.md", 26 | "title": "System Architecture Design", 27 | "description": "Overall system architecture and core components", 28 | "dateCreated": "2024-01-15", 29 | "author": "Engineering Team", 30 | "version": "1.0", 31 | "category": "architecture", 32 | "keywords": [ 33 | "system-architecture", 34 | "microservices", 35 | "api-gateway", 36 | "kubernetes", 37 | "docker", 38 | "jwt-authentication", 39 | "cloud-native" 40 | ], 41 | "trainingQuestions": [ 42 | "What is the role of the API Gateway in this architecture?", 43 | "How is authentication managed across services?", 44 | "What principles drive this system architecture?", 45 | "What are the core services in the design?", 46 | "How is the deployment managed using Kubernetes?" 47 | ], 48 | "relatedProducts": [ 49 | "Core Platform v2.0" 50 | ], 51 | "topics": [ 52 | "Software Architecture", 53 | "Distributed Systems", 54 | "Cloud-Native Design", 55 | "DevOps Practices" 56 | ] 57 | }, 58 | { 59 | "@type": "Section", 60 | "@id": "architecturemd-sec-2-system-architecture-design", 61 | "title": "System Architecture Design", 62 | "level": 1, 63 | "content": "This document outlines the high-level architecture of our distributed system.", 64 | "primary": false 65 | }, 66 | { 67 | "@type": "Section", 68 | "@id": "architecturemd-sec-3-overview", 69 | "title": "Overview", 70 | "level": 2, 71 | "content": "Our system follows a microservices architecture pattern with clear separation of concerns. The architecture is designed for scalability, maintainability, and fault tolerance.\n\nKey principles: - Microservices architecture - Event-driven communication - API-first design - Cloud-native deployment", 72 | "primary": false 73 | }, 74 | { 75 | "@type": "Section", 76 | "@id": "architecturemd-sec-4-core-components", 77 | "title": "Core Components", 78 | "level": 2, 79 | "content": "### API Gateway\n\nThe API Gateway serves as the single entry point for all client requests. It handles: - Request routing and load balancing - Authentication and authorization - Rate limiting and throttling - Request/response transformation\n\n```yaml\napiGateway:\n port: 8080\n timeout: 30s\n rateLimit: 1000/min\n auth:\n type: JWT\n secret: ${JWT_SECRET}\n```\n\n### User Service\n\nManages user accounts, profiles, and authentication: - User registration and login - Profile management - Password reset functionality - Social authentication integration\n\n### Data Service\n\nHandles all data operations: - CRUD operations for business entities - Data validation and transformation - Caching layer integration - Database connection pooling", 80 | "primary": false 81 | }, 82 | { 83 | "@type": "Section", 84 | "@id": "architecturemd-sec-5-database-schema", 85 | "title": "Database Schema", 86 | "level": 2, 87 | "content": "TablePurposeKey FieldsusersUser accountsid, email, password_hashprofilesUser profilesuser_id, name, avatar_urlsessionsActive sessionsid, user_id, expires_at", 88 | "primary": false 89 | }, 90 | { 91 | "@type": "Section", 92 | "@id": "architecturemd-sec-6-deployment-architecture", 93 | "title": "Deployment Architecture", 94 | "level": 2, 95 | "content": "The system is deployed using Docker containers orchestrated by Kubernetes:\n\n```dockerfile\nFROM node:16-alpine\nWORKDIR /app\nCOPY package*.json ./\nRUN npm ci --only=production\nCOPY . .\nEXPOSE 3000\nCMD [\"npm\", \"start\"]\n```", 96 | "primary": false 97 | } 98 | ] 99 | } -------------------------------------------------------------------------------- /output/security.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "security-guidelines" 3 | title: "Security Guidelines" 4 | description: > 5 | Security best practices covering authentication, encryption, input validation, and compliance controls. 6 | author: "Security Team" 7 | created: "2024-01-25" 8 | version: "1.0" 9 | category: "security" 10 | type: "http://example.com/security#SecurityPolicyDocument" 11 | keywords: 12 | - JWT 13 | - Password Policy 14 | - XSS 15 | - SQL Injection 16 | - TLS 17 | - Encryption 18 | - GDPR 19 | - SOC 2 20 | - Logging 21 | - Incident Response 22 | topics: 23 | - Authentication & Authorization 24 | - Secure Coding Practices 25 | - Encryption at Rest & in Transit 26 | - Security Monitoring & Logging 27 | - Regulatory Compliance 28 | - Incident Response Planning 29 | trainingQuestions: 30 | - "How should JWT tokens be configured securely?" 31 | - "What password hashing algorithm and rotation policy is recommended?" 32 | - "How do you mitigate XSS and SQL injection risks?" 33 | - "What logging events are critical for security auditing?" 34 | - "What controls are required for GDPR and SOC 2 compliance?" 35 | relatedStandards: 36 | - GDPR 37 | - SOC 2 Type II 38 | - NIST SP 800-53 39 | - OWASP Top 10 40 | status: "approved" 41 | reviewed: "2024-01-30" 42 | --- 43 | 44 | 45 | # Security Guidelines 46 | 47 | This document outlines security best practices and implementation guidelines for our system. 48 | 49 | ## Authentication & Authorization 50 | 51 | ### JWT Token Security 52 | 53 | JSON Web Tokens (JWT) are used for stateless authentication: 54 | 55 | - Tokens expire after 1 hour for security 56 | - Refresh tokens are valid for 30 days 57 | - Use strong, random secrets for token signing 58 | - Implement token blacklisting for logout 59 | 60 | ```javascript 61 | const jwt = require('jsonwebtoken'); 62 | 63 | const generateToken = (user) => { 64 | return jwt.sign( 65 | { id: user.id, email: user.email }, 66 | process.env.JWT_SECRET, 67 | { expiresIn: '1h' } 68 | ); 69 | }; 70 | ``` 71 | 72 | ### Password Security 73 | 74 | Password handling requirements: 75 | - Minimum 8 characters with mixed case, numbers, symbols 76 | - Hash passwords using bcrypt with salt rounds ≥ 12 77 | - Implement password history to prevent reuse 78 | - Enforce password rotation every 90 days 79 | 80 | ## Input Validation 81 | 82 | ### SQL Injection Prevention 83 | 84 | Always use parameterized queries or ORMs: 85 | 86 | ```sql 87 | -- Bad: Direct string concatenation 88 | SELECT * FROM users WHERE email = '" + userInput + "' 89 | 90 | -- Good: Parameterized query 91 | SELECT * FROM users WHERE email = ? 92 | ``` 93 | 94 | ### XSS Prevention 95 | 96 | Sanitize all user inputs: 97 | - Escape HTML entities in output 98 | - Use Content Security Policy (CSP) headers 99 | - Validate input on both client and server side 100 | 101 | ## Data Protection 102 | 103 | ### Encryption at Rest 104 | 105 | Sensitive data must be encrypted using AES-256: 106 | 107 | ```python 108 | from cryptography.fernet import Fernet 109 | 110 | def encrypt_sensitive_data(data, key): 111 | cipher = Fernet(key) 112 | encrypted_data = cipher.encrypt(data.encode()) 113 | return encrypted_data 114 | ``` 115 | 116 | ### Encryption in Transit 117 | 118 | All communications must use TLS 1.2 or higher: 119 | - HTTPS for web traffic 120 | - TLS for database connections 121 | - mTLS for service-to-service communication 122 | 123 | ## Monitoring & Logging 124 | 125 | ### Security Event Logging 126 | 127 | Log all security-relevant events: 128 | - Authentication attempts (success/failure) 129 | - Authorization failures 130 | - Data access patterns 131 | - Admin actions 132 | 133 | ### Incident Response 134 | 135 | Incident response procedures: 136 | 1. Immediate containment 137 | 2. Impact assessment 138 | 3. Evidence collection 139 | 4. System recovery 140 | 5. Post-incident review 141 | 142 | ## Compliance Requirements 143 | 144 | ### GDPR Compliance 145 | 146 | Data protection measures: 147 | - Right to be forgotten implementation 148 | - Data portability features 149 | - Consent management 150 | - Data minimization principles 151 | 152 | ### SOC 2 Type II 153 | 154 | Control objectives: 155 | - Security controls testing 156 | - Availability monitoring 157 | - Processing integrity validation 158 | - Confidentiality protection 159 | - Privacy safeguards -------------------------------------------------------------------------------- /processed/api.jsonld: -------------------------------------------------------------------------------- 1 | { 2 | "@context": { 3 | "@vocab": "https://schema.org/", 4 | "mainEntity": { 5 | "@id": "schema:mainEntity", 6 | "@type": "@id" 7 | }, 8 | "trainingQuestions": { 9 | "@container": "@list" 10 | }, 11 | "relatedProducts": { 12 | "@container": "@list" 13 | }, 14 | "topics": { 15 | "@container": "@list" 16 | }, 17 | "keywords": { 18 | "@container": "@list" 19 | } 20 | }, 21 | "@graph": [ 22 | { 23 | "@type": "Document", 24 | "@id": "rest_api_doc", 25 | "filename": "api.md", 26 | "title": "REST API Documentation", 27 | "description": "Complete API reference for client integration", 28 | "dateCreated": "2024-01-20", 29 | "author": "API Team", 30 | "version": "1.0", 31 | "category": "api", 32 | "keywords": [ 33 | "api", 34 | "rest", 35 | "jwt", 36 | "authentication", 37 | "pagination", 38 | "error-handling", 39 | "client-integration" 40 | ], 41 | "trainingQuestions": [ 42 | "How do I authenticate using JWT with the API?", 43 | "How can I retrieve a paginated list of items?", 44 | "What does the login endpoint return?", 45 | "How does the API handle input validation errors?", 46 | "What rate limits are enforced per user?" 47 | ], 48 | "relatedProducts": [ 49 | "API Platform v1.0" 50 | ], 51 | "topics": [ 52 | "REST API Design", 53 | "Secure API Access", 54 | "Client Development" 55 | ] 56 | }, 57 | { 58 | "@type": "Section", 59 | "@id": "apimd-sec-2-rest-api-documentation", 60 | "title": "REST API Documentation", 61 | "level": 1, 62 | "content": "This document provides comprehensive documentation for our REST API endpoints.", 63 | "primary": false 64 | }, 65 | { 66 | "@type": "Section", 67 | "@id": "apimd-sec-3-authentication", 68 | "title": "Authentication", 69 | "level": 2, 70 | "content": "All API endpoints require authentication using JWT tokens. Include the token in the Authorization header:\n\n```\nAuthorization: Bearer \n```", 71 | "primary": false 72 | }, 73 | { 74 | "@type": "Section", 75 | "@id": "apimd-sec-4-user-endpoints", 76 | "title": "User Endpoints", 77 | "level": 2, 78 | "content": "### POST /api/users/register\n\nRegister a new user account.\n\nRequest Body:\n\n```json\n{\n \"email\": \"user@example.com\",\n \"password\": \"securePassword123\",\n \"name\": \"John Doe\"\n}\n```\n\nResponse:\n\n```json\n{\n \"id\": \"user_123\",\n \"email\": \"user@example.com\",\n \"name\": \"John Doe\",\n \"createdAt\": \"2024-01-20T10:00:00Z\"\n}\n```\n\n### POST /api/users/login\n\nAuthenticate user and receive JWT token.\n\nRequest Body:\n\n```json\n{\n \"email\": \"user@example.com\",\n \"password\": \"securePassword123\"\n}\n```\n\nResponse:\n\n```json\n{\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\",\n \"expiresIn\": 3600,\n \"user\": {\n \"id\": \"user_123\",\n \"email\": \"user@example.com\",\n \"name\": \"John Doe\"\n }\n}\n```", 79 | "primary": false 80 | }, 81 | { 82 | "@type": "Section", 83 | "@id": "apimd-sec-5-data-endpoints", 84 | "title": "Data Endpoints", 85 | "level": 2, 86 | "content": "### GET /api/data/items\n\nRetrieve paginated list of items.\n\nQuery Parameters: - page: Page number (default: 1) - limit: Items per page (default: 20, max: 100) - sort: Sort field (id, name, createdAt) - order: Sort order (asc, desc)\n\nResponse:\n\n```json\n{\n \"items\": [\n {\n \"id\": \"item_1\",\n \"name\": \"Sample Item\",\n \"description\": \"A sample item\",\n \"createdAt\": \"2024-01-20T10:00:00Z\"\n }\n ],\n \"pagination\": {\n \"page\": 1,\n \"limit\": 20,\n \"total\": 150,\n \"pages\": 8\n }\n}\n```\n\n### POST /api/data/items\n\nCreate a new item.\n\nRequest Body:\n\n```json\n{\n \"name\": \"New Item\",\n \"description\": \"Description of the new item\",\n \"category\": \"electronics\"\n}\n```", 87 | "primary": false 88 | }, 89 | { 90 | "@type": "Section", 91 | "@id": "apimd-sec-6-error-handling", 92 | "title": "Error Handling", 93 | "level": 2, 94 | "content": "The API uses standard HTTP status codes and returns error details in JSON format:\n\n```json\n{\n \"error\": {\n \"code\": \"VALIDATION_ERROR\",\n \"message\": \"Invalid input data\",\n \"details\": [\n {\n \"field\": \"email\",\n \"message\": \"Invalid email format\"\n }\n ]\n }\n}\n```", 95 | "primary": false 96 | }, 97 | { 98 | "@type": "Section", 99 | "@id": "apimd-sec-7-rate-limiting", 100 | "title": "Rate Limiting", 101 | "level": 2, 102 | "content": "API requests are limited to 1000 requests per hour per user. Rate limit information is included in response headers:\n\n```\nX-RateLimit-Limit: 1000\nX-RateLimit-Remaining: 999\nX-RateLimit-Reset: 1642694400\n```", 103 | "primary": false 104 | } 105 | ] 106 | } -------------------------------------------------------------------------------- /processed/security.jsonld: -------------------------------------------------------------------------------- 1 | { 2 | "@context": { 3 | "@vocab": "https://schema.org/", 4 | "mainEntity": { 5 | "@id": "schema:mainEntity", 6 | "@type": "@id" 7 | }, 8 | "trainingQuestions": { 9 | "@container": "@list" 10 | }, 11 | "relatedProducts": { 12 | "@container": "@list" 13 | }, 14 | "topics": { 15 | "@container": "@list" 16 | }, 17 | "keywords": { 18 | "@container": "@list" 19 | } 20 | }, 21 | "@graph": [ 22 | { 23 | "@type": "Document", 24 | "@id": "security-guidelines", 25 | "filename": "security.md", 26 | "title": "Security Guidelines", 27 | "description": "Security best practices covering authentication, encryption, input validation, and compliance controls.\n\n", 28 | "dateCreated": "2024-01-25", 29 | "author": "Security Team", 30 | "version": "1.0", 31 | "category": "security", 32 | "keywords": [ 33 | "JWT", 34 | "Password Policy", 35 | "XSS", 36 | "SQL Injection", 37 | "TLS", 38 | "Encryption", 39 | "GDPR", 40 | "SOC 2", 41 | "Logging", 42 | "Incident Response" 43 | ], 44 | "trainingQuestions": [ 45 | "How should JWT tokens be configured securely?", 46 | "What password hashing algorithm and rotation policy is recommended?", 47 | "How do you mitigate XSS and SQL injection risks?", 48 | "What logging events are critical for security auditing?", 49 | "What controls are required for GDPR and SOC 2 compliance?" 50 | ], 51 | "relatedProducts": [], 52 | "topics": [ 53 | "Authentication & Authorization", 54 | "Secure Coding Practices", 55 | "Encryption at Rest & in Transit", 56 | "Security Monitoring & Logging", 57 | "Regulatory Compliance", 58 | "Incident Response Planning" 59 | ] 60 | }, 61 | { 62 | "@type": "Section", 63 | "@id": "securitymd-sec-1-document-introduction", 64 | "title": "Document Introduction", 65 | "level": 1, 66 | "content": "Security best practices covering authentication, encryption, input validation, and compliance controls.", 67 | "primary": false 68 | }, 69 | { 70 | "@type": "Section", 71 | "@id": "securitymd-sec-2-security-guidelines", 72 | "title": "Security Guidelines", 73 | "level": 1, 74 | "content": "This document outlines security best practices and implementation guidelines for our system.", 75 | "primary": false 76 | }, 77 | { 78 | "@type": "Section", 79 | "@id": "securitymd-sec-3-authentication-authorization", 80 | "title": "Authentication & Authorization", 81 | "level": 2, 82 | "content": "### JWT Token Security\n\nJSON Web Tokens (JWT) are used for stateless authentication:\n\nTokens expire after 1 hour for securityRefresh tokens are valid for 30 daysUse strong, random secrets for token signingImplement token blacklisting for logout\n\n```javascript\nconst jwt = require('jsonwebtoken');\n\nconst generateToken = (user) => {\n return jwt.sign(\n { id: user.id, email: user.email },\n process.env.JWT_SECRET,\n { expiresIn: '1h' }\n );\n};\n```\n\n### Password Security\n\nPassword handling requirements: - Minimum 8 characters with mixed case, numbers, symbols - Hash passwords using bcrypt with salt rounds \u2265 12 - Implement password history to prevent reuse - Enforce password rotation every 90 days", 83 | "primary": false 84 | }, 85 | { 86 | "@type": "Section", 87 | "@id": "securitymd-sec-4-input-validation", 88 | "title": "Input Validation", 89 | "level": 2, 90 | "content": "### SQL Injection Prevention\n\nAlways use parameterized queries or ORMs:\n\n```sql\n-- Bad: Direct string concatenation\nSELECT * FROM users WHERE email = '\" + userInput + \"'\n\n-- Good: Parameterized query\nSELECT * FROM users WHERE email = ?\n```\n\n### XSS Prevention\n\nSanitize all user inputs: - Escape HTML entities in output - Use Content Security Policy (CSP) headers - Validate input on both client and server side", 91 | "primary": false 92 | }, 93 | { 94 | "@type": "Section", 95 | "@id": "securitymd-sec-5-data-protection", 96 | "title": "Data Protection", 97 | "level": 2, 98 | "content": "### Encryption at Rest\n\nSensitive data must be encrypted using AES-256:\n\n```python\nfrom cryptography.fernet import Fernet\n\ndef encrypt_sensitive_data(data, key):\n cipher = Fernet(key)\n encrypted_data = cipher.encrypt(data.encode())\n return encrypted_data\n```\n\n### Encryption in Transit\n\nAll communications must use TLS 1.2 or higher: - HTTPS for web traffic - TLS for database connections - mTLS for service-to-service communication", 99 | "primary": false 100 | }, 101 | { 102 | "@type": "Section", 103 | "@id": "securitymd-sec-6-monitoring-logging", 104 | "title": "Monitoring & Logging", 105 | "level": 2, 106 | "content": "### Security Event Logging\n\nLog all security-relevant events: - Authentication attempts (success/failure) - Authorization failures - Data access patterns - Admin actions\n\n### Incident Response\n\nIncident response procedures: 1. Immediate containment 2. Impact assessment 3. Evidence collection 4. System recovery 5. Post-incident review", 107 | "primary": false 108 | }, 109 | { 110 | "@type": "Section", 111 | "@id": "securitymd-sec-7-compliance-requirements", 112 | "title": "Compliance Requirements", 113 | "level": 2, 114 | "content": "### GDPR Compliance\n\nData protection measures: - Right to be forgotten implementation - Data portability features - Consent management - Data minimization principles\n\n### SOC 2 Type II\n\nControl objectives: - Security controls testing - Availability monitoring - Processing integrity validation - Confidentiality protection - Privacy safeguards", 115 | "primary": false 116 | } 117 | ] 118 | } -------------------------------------------------------------------------------- /processed/junos_gnmi.ast.json: -------------------------------------------------------------------------------- 1 | {"pandoc-api-version":[1,23,1],"meta":{"author":{"t":"MetaInlines","c":[{"t":"Str","c":"Network"},{"t":"Space"},{"t":"Str","c":"Automation"},{"t":"Space"},{"t":"Str","c":"Team"}]},"category":{"t":"MetaInlines","c":[{"t":"Str","c":"network-knowledge-base"}]},"created":{"t":"MetaInlines","c":[{"t":"Str","c":"2024-01-20"}]},"description":{"t":"MetaInlines","c":[{"t":"Str","c":"Config"},{"t":"Space"},{"t":"Str","c":"guide"},{"t":"Space"},{"t":"Str","c":"to"},{"t":"Space"},{"t":"Str","c":"run"},{"t":"Space"},{"t":"Str","c":"JunOS"},{"t":"Space"},{"t":"Str","c":"GNMI"},{"t":"Space"},{"t":"Str","c":"in"},{"t":"Space"},{"t":"Str","c":"insecure"},{"t":"Space"},{"t":"Str","c":"mode"},{"t":"Space"},{"t":"Str","c":"without"},{"t":"Space"},{"t":"Str","c":"certs"}]},"id":{"t":"MetaInlines","c":[{"t":"Str","c":"junos_gnmimd"}]},"keywords":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"gnmi"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"juniper"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"grpc"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"insecure-mode"}]}]},"related_products":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"vMX"},{"t":"Space"},{"t":"Str","c":"22.3R1.11"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"vQFX"},{"t":"Space"},{"t":"Str","c":"19.4R1.10"}]}]},"title":{"t":"MetaInlines","c":[{"t":"Str","c":"GNMI"},{"t":"Space"},{"t":"Str","c":"without"},{"t":"Space"},{"t":"Str","c":"Certificates"},{"t":"Space"},{"t":"Str","c":"on"},{"t":"Space"},{"t":"Str","c":"Juniper"}]},"topics":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"Network"},{"t":"Space"},{"t":"Str","c":"Telemetry"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Juniper"},{"t":"Space"},{"t":"Str","c":"Configuration"}]}]},"training_questions":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"How"},{"t":"Space"},{"t":"Str","c":"do"},{"t":"Space"},{"t":"Str","c":"I"},{"t":"Space"},{"t":"Str","c":"configure"},{"t":"Space"},{"t":"Str","c":"JunOS"},{"t":"Space"},{"t":"Str","c":"GNMI"},{"t":"Space"},{"t":"Str","c":"without"},{"t":"Space"},{"t":"Str","c":"certificates?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"What"},{"t":"Space"},{"t":"Str","c":"port"},{"t":"Space"},{"t":"Str","c":"does"},{"t":"Space"},{"t":"Str","c":"JunOS"},{"t":"Space"},{"t":"Str","c":"use"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"insecure"},{"t":"Space"},{"t":"Str","c":"GNMI?"}]}]},"version":{"t":"MetaInlines","c":[{"t":"Str","c":"1.0"}]}},"blocks":[{"t":"Header","c":[2,["how-to-setup-a-junos-device-for-gnmi",[],[]],[{"t":"Str","c":"How"},{"t":"Space"},{"t":"Str","c":"to"},{"t":"Space"},{"t":"Str","c":"setup"},{"t":"Space"},{"t":"Str","c":"a"},{"t":"Space"},{"t":"Str","c":"JunOS"},{"t":"Space"},{"t":"Str","c":"device"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"GNMI"}]]},{"t":"Para","c":[{"t":"Str","c":"The"},{"t":"Space"},{"t":"Str","c":"configuration"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"fairly"},{"t":"Space"},{"t":"Str","c":"simple"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"a"},{"t":"Space"},{"t":"Str","c":"lab"},{"t":"Space"},{"t":"Str","c":"scenario"},{"t":"Space"},{"t":"Str","c":"where"},{"t":"Space"},{"t":"Str","c":"we"},{"t":"Space"},{"t":"Str","c":"will"},{"t":"Space"},{"t":"Str","c":"not"},{"t":"Space"},{"t":"Str","c":"use"},{"t":"Space"},{"t":"Str","c":"certificates"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"use"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"insecure"},{"t":"Space"},{"t":"Str","c":"mode."},{"t":"SoftBreak"},{"t":"Str","c":"Please"},{"t":"Space"},{"t":"Str","c":"refer"},{"t":"Space"},{"t":"Str","c":"to"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"Juniper"},{"t":"Space"},{"t":"Str","c":"Site"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"details"},{"t":"Space"},{"t":"Str","c":"on"},{"t":"Space"},{"t":"Str","c":"configuration"},{"t":"Space"},{"t":"Str","c":"using"},{"t":"Space"},{"t":"Str","c":"Certificates."}]},{"t":"Para","c":[{"t":"Str","c":"This"},{"t":"Space"},{"t":"Str","c":"was"},{"t":"Space"},{"t":"Str","c":"tested"},{"t":"Space"},{"t":"Str","c":"on"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"vMX"},{"t":"Space"},{"t":"Str","c":"22.3R1.11"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"vQFX"},{"t":"Space"},{"t":"Str","c":"19.4R1.10"},{"t":"SoftBreak"},{"t":"Str","c":"Note:"},{"t":"Space"},{"t":"Str","c":"Although"},{"t":"Space"},{"t":"Str","c":"configuration"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"accepted"},{"t":"Space"},{"t":"Str","c":"on"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"vQFX"},{"t":"Space"},{"t":"Str","c":"it"},{"t":"Space"},{"t":"Str","c":"was"},{"t":"Space"},{"t":"Str","c":"not"},{"t":"Space"},{"t":"Str","c":"possible"},{"t":"Space"},{"t":"Str","c":"to"},{"t":"Space"},{"t":"Str","c":"get"},{"t":"Space"},{"t":"Str","c":"GNMI"},{"t":"Space"},{"t":"Str","c":"working"},{"t":"Space"},{"t":"Str","c":"on"},{"t":"Space"},{"t":"Str","c":"this"},{"t":"Space"},{"t":"Str","c":"platform."},{"t":"Space"},{"t":"Str","c":"This"},{"t":"Space"},{"t":"Str","c":"could"},{"t":"Space"},{"t":"Str","c":"be"},{"t":"Space"},{"t":"Str","c":"due"},{"t":"Space"},{"t":"Str","c":"to"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"fact"},{"t":"Space"},{"t":"Str","c":"that"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"insecure"},{"t":"Space"},{"t":"Str","c":"mode"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"not"},{"t":"Space"},{"t":"Str","c":"supported"},{"t":"Space"},{"t":"Str","c":"in"},{"t":"Space"},{"t":"Str","c":"earlier"},{"t":"Space"},{"t":"Str","c":"releases"}]},{"t":"Header","c":[2,["gnmi_no_certs",["Section"],[["primary","true"]]],[{"t":"Str","c":"How"},{"t":"Space"},{"t":"Str","c":"to"},{"t":"Space"},{"t":"Str","c":"setup"},{"t":"Space"},{"t":"Str","c":"a"},{"t":"Space"},{"t":"Str","c":"JunOS"},{"t":"Space"},{"t":"Str","c":"device"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"GNMI"},{"t":"Space"},{"t":"Str","c":"without"},{"t":"Space"},{"t":"Str","c":"certificates"}]]},{"t":"CodeBlock","c":[["",[],[]],"set system services extension-service request-response grpc clear-text port 57400\nset system services extension-service request-response grpc max-connections 4"]},{"t":"Para","c":[{"t":"Str","c":"You"},{"t":"Space"},{"t":"Str","c":"will"},{"t":"Space"},{"t":"Str","c":"also"},{"t":"Space"},{"t":"Str","c":"need"},{"t":"Space"},{"t":"Str","c":"this"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"reponse"},{"t":"Space"},{"t":"Str","c":"to"},{"t":"Space"},{"t":"Str","c":"be"},{"t":"Space"},{"t":"Str","c":"sent"},{"t":"Space"},{"t":"Str","c":"back"},{"t":"Space"},{"t":"Str","c":"to"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"client."}]},{"t":"CodeBlock","c":[["",[],[]],"set system services extension-service request-response grpc routing-instance mgmt_junos"]}]} 2 | -------------------------------------------------------------------------------- /md2jsonld.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | Panflute filter to convert Markdown to JSON-LD with embedded content chunks. 4 | """ 5 | import panflute as pf 6 | import re 7 | import json 8 | import logging 9 | from typing import Dict, Any, List 10 | 11 | logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') 12 | logger = logging.getLogger(__name__) 13 | 14 | 15 | def slugify(text: str) -> str: 16 | t = re.sub(r'[^\w\s-]', '', text.lower()) 17 | return re.sub(r'[-\s]+', '-', t).strip('-') 18 | 19 | 20 | class MarkdownToJSONLD: 21 | def __init__(self): 22 | self.reset() 23 | self.filename = 'unknown' 24 | 25 | def reset(self): 26 | self.meta: Dict[str, Any] = {} 27 | self.sections: list = [] 28 | self.current: Dict[str, Any] = {} 29 | self.buffer: list = [] 30 | self.count: int = 0 31 | 32 | def set_filename(self, fname: str): 33 | self.filename = fname 34 | 35 | def to_camel(self, s: str) -> str: 36 | parts = s.split('_') 37 | return parts[0] + ''.join(word.capitalize() for word in parts[1:]) 38 | 39 | def process_frontmatter(self, meta: pf.MetaMap): 40 | for k, v in meta.items(): 41 | camel_key = self.to_camel(k) 42 | val = [pf.stringify(item) for item in v] if isinstance(v, pf.MetaList) else pf.stringify(v) 43 | self.meta[camel_key] = val 44 | self.meta[k] = val # Keep original snake_case as well 45 | logger.debug(f"Frontmatter: {self.meta}") 46 | 47 | 48 | def new_section(self, title: str, level: int, primary: bool = False): 49 | if self.current and self.buffer: 50 | self.current['content'] = '\n\n'.join(self.buffer).strip() 51 | self.sections.append(self.current) 52 | self.buffer = [] 53 | self.count += 1 54 | sid = f"{slugify(self.filename)}-sec-{self.count}-{slugify(title)}" 55 | self.current = { 56 | '@type': 'Section', 57 | '@id': sid, 58 | 'title': title, 59 | 'level': level, 60 | 'content': '', 61 | 'primary': primary 62 | } 63 | logger.debug(f"New section: {title}") 64 | 65 | def add_text(self, txt: str): 66 | txt = txt.strip() 67 | if txt: 68 | self.buffer.append(txt) 69 | logger.debug(f"Buffer: {txt[:30]}...") 70 | 71 | def build(self) -> Dict[str, Any]: 72 | if self.current and self.buffer: 73 | self.current['content'] = '\n\n'.join(self.buffer).strip() 74 | self.sections.append(self.current) 75 | 76 | doc_node: Dict[str, Any] = { 77 | '@type': 'Document', 78 | '@id': self.meta.get('id', slugify(self.filename)), 79 | 'filename': self.filename, 80 | 'title': self.meta.get('title', self.filename), 81 | 'description': self.meta.get('description', ''), 82 | 'dateCreated': self.meta.get('created', ''), 83 | 'author': self.meta.get('author', ''), 84 | 'version': self.meta.get('version', ''), 85 | 'category': self.meta.get('category', ''), 86 | 'keywords': self.meta.get('keywords', []), 87 | 'trainingQuestions': self.meta.get('trainingQuestions', self.meta.get('training_questions', [])), 88 | 'relatedProducts': self.meta.get('relatedProducts', self.meta.get('related_products', [])), 89 | 'topics': self.meta.get('topics', []) 90 | # 🔸 Do not include 'sections': self.sections 91 | } 92 | 93 | for sec in self.sections: 94 | if sec.get('primary'): 95 | doc_node['mainEntity'] = sec['@id'] 96 | break 97 | 98 | context = { 99 | '@vocab': 'https://schema.org/', 100 | 'mainEntity': {'@id': 'schema:mainEntity', '@type': '@id'}, 101 | 'trainingQuestions': {'@container': '@list'}, 102 | 'relatedProducts': {'@container': '@list'}, 103 | 'topics': {'@container': '@list'}, 104 | 'keywords': {'@container': '@list'} 105 | } 106 | 107 | # Return doc + sections as individual graph nodes 108 | return { 109 | '@context': context, 110 | '@graph': [doc_node] + self.sections 111 | } 112 | 113 | 114 | 115 | def prepare(doc): 116 | md = MarkdownToJSONLD() 117 | doc.md2jsonld = md 118 | fname = getattr(doc, 'filename', None) 119 | md.set_filename(fname or 'unknown') 120 | if doc.metadata: 121 | md.process_frontmatter(doc.metadata) 122 | md.new_section('Document Introduction', 1) 123 | logger.info(f"Parsed frontmatter keys: {list(doc.md2jsonld.meta.keys())}") 124 | return doc 125 | 126 | 127 | def action(elem, doc): 128 | md = doc.md2jsonld 129 | 130 | if isinstance(elem, pf.Header): 131 | title = pf.stringify(elem) 132 | lvl = elem.level 133 | is_primary = elem.attributes.get('primary', 'false').lower() == 'true' 134 | if lvl <= 2: 135 | md.new_section(title, lvl, primary=is_primary) 136 | else: 137 | md.add_text('#' * lvl + ' ' + title) 138 | 139 | elif isinstance(elem, pf.Para): 140 | md.add_text(pf.stringify(elem)) 141 | elif isinstance(elem, pf.CodeBlock): 142 | lang = elem.classes[0] if elem.classes else '' 143 | md.add_text(f"```{lang}\n{elem.text}\n```") 144 | elif isinstance(elem, pf.Table): 145 | md.add_text(pf.stringify(elem)) 146 | elif isinstance(elem, pf.Image): 147 | alt = pf.stringify(elem) 148 | md.add_text(f"![{alt}]({elem.url})") 149 | elif isinstance(elem, (pf.BulletList, pf.OrderedList)): 150 | md.add_text(pf.stringify(elem)) 151 | elif isinstance(elem, pf.BlockQuote): 152 | quote_lines = pf.stringify(elem).splitlines() 153 | md.add_text('\n'.join(f"> {line}" for line in quote_lines)) 154 | 155 | return None 156 | 157 | 158 | def finalize(doc): 159 | jsonld = { 160 | "@context": { 161 | "@vocab": "https://schema.org/", 162 | "sections": {"@container": "@list"}, 163 | "mainEntity": {"@id": "schema:mainEntity", "@type": "@id"}, 164 | "trainingQuestions": {"@container": "@list"}, 165 | "relatedProducts": {"@container": "@list"}, 166 | "topics": {"@container": "@list"}, 167 | "keywords": {"@container": "@list"}, 168 | }, 169 | "@graph": doc.md2jsonld.build()["@graph"] 170 | } 171 | 172 | return pf.RawBlock(json.dumps(jsonld, indent=2), format="json") 173 | 174 | 175 | 176 | def main(doc=None): 177 | logger.info('Running filter') 178 | return pf.run_filter(action, prepare=prepare, finalize=finalize, doc=doc) 179 | 180 | 181 | if __name__ == '__main__': 182 | main() 183 | -------------------------------------------------------------------------------- /processed/api.ast.json: -------------------------------------------------------------------------------- 1 | {"pandoc-api-version":[1,23,1],"meta":{"author":{"t":"MetaInlines","c":[{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"Team"}]},"category":{"t":"MetaInlines","c":[{"t":"Str","c":"api"}]},"created":{"t":"MetaInlines","c":[{"t":"Str","c":"2024-01-20"}]},"description":{"t":"MetaInlines","c":[{"t":"Str","c":"Complete"},{"t":"Space"},{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"reference"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"client"},{"t":"Space"},{"t":"Str","c":"integration"}]},"id":{"t":"MetaInlines","c":[{"t":"Str","c":"rest_api_doc"}]},"keywords":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"api"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"rest"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"jwt"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"authentication"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"pagination"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"error-handling"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"client-integration"}]}]},"relatedProducts":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"Platform"},{"t":"Space"},{"t":"Str","c":"v1.0"}]}]},"title":{"t":"MetaInlines","c":[{"t":"Str","c":"REST"},{"t":"Space"},{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"Documentation"}]},"topics":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"REST"},{"t":"Space"},{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"Design"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Secure"},{"t":"Space"},{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"Access"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Client"},{"t":"Space"},{"t":"Str","c":"Development"}]}]},"trainingQuestions":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"How"},{"t":"Space"},{"t":"Str","c":"do"},{"t":"Space"},{"t":"Str","c":"I"},{"t":"Space"},{"t":"Str","c":"authenticate"},{"t":"Space"},{"t":"Str","c":"using"},{"t":"Space"},{"t":"Str","c":"JWT"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"API?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"How"},{"t":"Space"},{"t":"Str","c":"can"},{"t":"Space"},{"t":"Str","c":"I"},{"t":"Space"},{"t":"Str","c":"retrieve"},{"t":"Space"},{"t":"Str","c":"a"},{"t":"Space"},{"t":"Str","c":"paginated"},{"t":"Space"},{"t":"Str","c":"list"},{"t":"Space"},{"t":"Str","c":"of"},{"t":"Space"},{"t":"Str","c":"items?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"What"},{"t":"Space"},{"t":"Str","c":"does"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"login"},{"t":"Space"},{"t":"Str","c":"endpoint"},{"t":"Space"},{"t":"Str","c":"return?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"How"},{"t":"Space"},{"t":"Str","c":"does"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"handle"},{"t":"Space"},{"t":"Str","c":"input"},{"t":"Space"},{"t":"Str","c":"validation"},{"t":"Space"},{"t":"Str","c":"errors?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"What"},{"t":"Space"},{"t":"Str","c":"rate"},{"t":"Space"},{"t":"Str","c":"limits"},{"t":"Space"},{"t":"Str","c":"are"},{"t":"Space"},{"t":"Str","c":"enforced"},{"t":"Space"},{"t":"Str","c":"per"},{"t":"Space"},{"t":"Str","c":"user?"}]}]},"version":{"t":"MetaInlines","c":[{"t":"Str","c":"1.0"}]}},"blocks":[{"t":"Header","c":[1,["rest-api-documentation",[],[]],[{"t":"Str","c":"REST"},{"t":"Space"},{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"Documentation"}]]},{"t":"Para","c":[{"t":"Str","c":"This"},{"t":"Space"},{"t":"Str","c":"document"},{"t":"Space"},{"t":"Str","c":"provides"},{"t":"Space"},{"t":"Str","c":"comprehensive"},{"t":"Space"},{"t":"Str","c":"documentation"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"our"},{"t":"Space"},{"t":"Str","c":"REST"},{"t":"Space"},{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"endpoints."}]},{"t":"Header","c":[2,["authentication",[],[]],[{"t":"Str","c":"Authentication"}]]},{"t":"Para","c":[{"t":"Str","c":"All"},{"t":"Space"},{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"endpoints"},{"t":"Space"},{"t":"Str","c":"require"},{"t":"Space"},{"t":"Str","c":"authentication"},{"t":"Space"},{"t":"Str","c":"using"},{"t":"Space"},{"t":"Str","c":"JWT"},{"t":"Space"},{"t":"Str","c":"tokens."},{"t":"Space"},{"t":"Str","c":"Include"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"token"},{"t":"Space"},{"t":"Str","c":"in"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"Authorization"},{"t":"Space"},{"t":"Str","c":"header:"}]},{"t":"CodeBlock","c":[["",[],[]],"Authorization: Bearer "]},{"t":"Header","c":[2,["user-endpoints",[],[]],[{"t":"Str","c":"User"},{"t":"Space"},{"t":"Str","c":"Endpoints"}]]},{"t":"Header","c":[3,["post-apiusersregister",[],[]],[{"t":"Str","c":"POST"},{"t":"Space"},{"t":"Str","c":"/api/users/register"}]]},{"t":"Para","c":[{"t":"Str","c":"Register"},{"t":"Space"},{"t":"Str","c":"a"},{"t":"Space"},{"t":"Str","c":"new"},{"t":"Space"},{"t":"Str","c":"user"},{"t":"Space"},{"t":"Str","c":"account."}]},{"t":"Para","c":[{"t":"Strong","c":[{"t":"Str","c":"Request"},{"t":"Space"},{"t":"Str","c":"Body:"}]}]},{"t":"CodeBlock","c":[["",["json"],[]],"{\n \"email\": \"user@example.com\",\n \"password\": \"securePassword123\",\n \"name\": \"John Doe\"\n}"]},{"t":"Para","c":[{"t":"Strong","c":[{"t":"Str","c":"Response:"}]}]},{"t":"CodeBlock","c":[["",["json"],[]],"{\n \"id\": \"user_123\",\n \"email\": \"user@example.com\",\n \"name\": \"John Doe\",\n \"createdAt\": \"2024-01-20T10:00:00Z\"\n}"]},{"t":"Header","c":[3,["post-apiuserslogin",[],[]],[{"t":"Str","c":"POST"},{"t":"Space"},{"t":"Str","c":"/api/users/login"}]]},{"t":"Para","c":[{"t":"Str","c":"Authenticate"},{"t":"Space"},{"t":"Str","c":"user"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"receive"},{"t":"Space"},{"t":"Str","c":"JWT"},{"t":"Space"},{"t":"Str","c":"token."}]},{"t":"Para","c":[{"t":"Strong","c":[{"t":"Str","c":"Request"},{"t":"Space"},{"t":"Str","c":"Body:"}]}]},{"t":"CodeBlock","c":[["",["json"],[]],"{\n \"email\": \"user@example.com\",\n \"password\": \"securePassword123\"\n}"]},{"t":"Para","c":[{"t":"Strong","c":[{"t":"Str","c":"Response:"}]}]},{"t":"CodeBlock","c":[["",["json"],[]],"{\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...\",\n \"expiresIn\": 3600,\n \"user\": {\n \"id\": \"user_123\",\n \"email\": \"user@example.com\",\n \"name\": \"John Doe\"\n }\n}"]},{"t":"Header","c":[2,["data-endpoints",[],[]],[{"t":"Str","c":"Data"},{"t":"Space"},{"t":"Str","c":"Endpoints"}]]},{"t":"Header","c":[3,["get-apidataitems",[],[]],[{"t":"Str","c":"GET"},{"t":"Space"},{"t":"Str","c":"/api/data/items"}]]},{"t":"Para","c":[{"t":"Str","c":"Retrieve"},{"t":"Space"},{"t":"Str","c":"paginated"},{"t":"Space"},{"t":"Str","c":"list"},{"t":"Space"},{"t":"Str","c":"of"},{"t":"Space"},{"t":"Str","c":"items."}]},{"t":"Para","c":[{"t":"Strong","c":[{"t":"Str","c":"Query"},{"t":"Space"},{"t":"Str","c":"Parameters:"}]},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Code","c":[["",[],[]],"page"]},{"t":"Str","c":":"},{"t":"Space"},{"t":"Str","c":"Page"},{"t":"Space"},{"t":"Str","c":"number"},{"t":"Space"},{"t":"Str","c":"(default:"},{"t":"Space"},{"t":"Str","c":"1)"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Code","c":[["",[],[]],"limit"]},{"t":"Str","c":":"},{"t":"Space"},{"t":"Str","c":"Items"},{"t":"Space"},{"t":"Str","c":"per"},{"t":"Space"},{"t":"Str","c":"page"},{"t":"Space"},{"t":"Str","c":"(default:"},{"t":"Space"},{"t":"Str","c":"20,"},{"t":"Space"},{"t":"Str","c":"max:"},{"t":"Space"},{"t":"Str","c":"100)"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Code","c":[["",[],[]],"sort"]},{"t":"Str","c":":"},{"t":"Space"},{"t":"Str","c":"Sort"},{"t":"Space"},{"t":"Str","c":"field"},{"t":"Space"},{"t":"Str","c":"(id,"},{"t":"Space"},{"t":"Str","c":"name,"},{"t":"Space"},{"t":"Str","c":"createdAt)"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Code","c":[["",[],[]],"order"]},{"t":"Str","c":":"},{"t":"Space"},{"t":"Str","c":"Sort"},{"t":"Space"},{"t":"Str","c":"order"},{"t":"Space"},{"t":"Str","c":"(asc,"},{"t":"Space"},{"t":"Str","c":"desc)"}]},{"t":"Para","c":[{"t":"Strong","c":[{"t":"Str","c":"Response:"}]}]},{"t":"CodeBlock","c":[["",["json"],[]],"{\n \"items\": [\n {\n \"id\": \"item_1\",\n \"name\": \"Sample Item\",\n \"description\": \"A sample item\",\n \"createdAt\": \"2024-01-20T10:00:00Z\"\n }\n ],\n \"pagination\": {\n \"page\": 1,\n \"limit\": 20,\n \"total\": 150,\n \"pages\": 8\n }\n}"]},{"t":"Header","c":[3,["post-apidataitems",[],[]],[{"t":"Str","c":"POST"},{"t":"Space"},{"t":"Str","c":"/api/data/items"}]]},{"t":"Para","c":[{"t":"Str","c":"Create"},{"t":"Space"},{"t":"Str","c":"a"},{"t":"Space"},{"t":"Str","c":"new"},{"t":"Space"},{"t":"Str","c":"item."}]},{"t":"Para","c":[{"t":"Strong","c":[{"t":"Str","c":"Request"},{"t":"Space"},{"t":"Str","c":"Body:"}]}]},{"t":"CodeBlock","c":[["",["json"],[]],"{\n \"name\": \"New Item\",\n \"description\": \"Description of the new item\",\n \"category\": \"electronics\"\n}"]},{"t":"Header","c":[2,["error-handling",[],[]],[{"t":"Str","c":"Error"},{"t":"Space"},{"t":"Str","c":"Handling"}]]},{"t":"Para","c":[{"t":"Str","c":"The"},{"t":"Space"},{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"uses"},{"t":"Space"},{"t":"Str","c":"standard"},{"t":"Space"},{"t":"Str","c":"HTTP"},{"t":"Space"},{"t":"Str","c":"status"},{"t":"Space"},{"t":"Str","c":"codes"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"returns"},{"t":"Space"},{"t":"Str","c":"error"},{"t":"Space"},{"t":"Str","c":"details"},{"t":"Space"},{"t":"Str","c":"in"},{"t":"Space"},{"t":"Str","c":"JSON"},{"t":"Space"},{"t":"Str","c":"format:"}]},{"t":"CodeBlock","c":[["",["json"],[]],"{\n \"error\": {\n \"code\": \"VALIDATION_ERROR\",\n \"message\": \"Invalid input data\",\n \"details\": [\n {\n \"field\": \"email\",\n \"message\": \"Invalid email format\"\n }\n ]\n }\n}"]},{"t":"Header","c":[2,["rate-limiting",[],[]],[{"t":"Str","c":"Rate"},{"t":"Space"},{"t":"Str","c":"Limiting"}]]},{"t":"Para","c":[{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"requests"},{"t":"Space"},{"t":"Str","c":"are"},{"t":"Space"},{"t":"Str","c":"limited"},{"t":"Space"},{"t":"Str","c":"to"},{"t":"Space"},{"t":"Str","c":"1000"},{"t":"Space"},{"t":"Str","c":"requests"},{"t":"Space"},{"t":"Str","c":"per"},{"t":"Space"},{"t":"Str","c":"hour"},{"t":"Space"},{"t":"Str","c":"per"},{"t":"Space"},{"t":"Str","c":"user."},{"t":"Space"},{"t":"Str","c":"Rate"},{"t":"Space"},{"t":"Str","c":"limit"},{"t":"Space"},{"t":"Str","c":"information"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"included"},{"t":"Space"},{"t":"Str","c":"in"},{"t":"Space"},{"t":"Str","c":"response"},{"t":"Space"},{"t":"Str","c":"headers:"}]},{"t":"CodeBlock","c":[["",[],[]],"X-RateLimit-Limit: 1000\nX-RateLimit-Remaining: 999\nX-RateLimit-Reset: 1642694400"]}]} 2 | -------------------------------------------------------------------------------- /processed/architecture.ast.json: -------------------------------------------------------------------------------- 1 | {"pandoc-api-version":[1,23,1],"meta":{"author":{"t":"MetaInlines","c":[{"t":"Str","c":"Engineering"},{"t":"Space"},{"t":"Str","c":"Team"}]},"category":{"t":"MetaInlines","c":[{"t":"Str","c":"architecture"}]},"created":{"t":"MetaInlines","c":[{"t":"Str","c":"2024-01-15"}]},"description":{"t":"MetaInlines","c":[{"t":"Str","c":"Overall"},{"t":"Space"},{"t":"Str","c":"system"},{"t":"Space"},{"t":"Str","c":"architecture"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"core"},{"t":"Space"},{"t":"Str","c":"components"}]},"id":{"t":"MetaInlines","c":[{"t":"Str","c":"system-architecture"}]},"keywords":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"system-architecture"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"microservices"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"api-gateway"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"kubernetes"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"docker"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"jwt-authentication"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"cloud-native"}]}]},"relatedProducts":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"Core"},{"t":"Space"},{"t":"Str","c":"Platform"},{"t":"Space"},{"t":"Str","c":"v2.0"}]}]},"title":{"t":"MetaInlines","c":[{"t":"Str","c":"System"},{"t":"Space"},{"t":"Str","c":"Architecture"},{"t":"Space"},{"t":"Str","c":"Design"}]},"topics":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"Software"},{"t":"Space"},{"t":"Str","c":"Architecture"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Distributed"},{"t":"Space"},{"t":"Str","c":"Systems"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Cloud-Native"},{"t":"Space"},{"t":"Str","c":"Design"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"DevOps"},{"t":"Space"},{"t":"Str","c":"Practices"}]}]},"trainingQuestions":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"What"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"role"},{"t":"Space"},{"t":"Str","c":"of"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"Gateway"},{"t":"Space"},{"t":"Str","c":"in"},{"t":"Space"},{"t":"Str","c":"this"},{"t":"Space"},{"t":"Str","c":"architecture?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"How"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"authentication"},{"t":"Space"},{"t":"Str","c":"managed"},{"t":"Space"},{"t":"Str","c":"across"},{"t":"Space"},{"t":"Str","c":"services?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"What"},{"t":"Space"},{"t":"Str","c":"principles"},{"t":"Space"},{"t":"Str","c":"drive"},{"t":"Space"},{"t":"Str","c":"this"},{"t":"Space"},{"t":"Str","c":"system"},{"t":"Space"},{"t":"Str","c":"architecture?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"What"},{"t":"Space"},{"t":"Str","c":"are"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"core"},{"t":"Space"},{"t":"Str","c":"services"},{"t":"Space"},{"t":"Str","c":"in"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"design?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"How"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"deployment"},{"t":"Space"},{"t":"Str","c":"managed"},{"t":"Space"},{"t":"Str","c":"using"},{"t":"Space"},{"t":"Str","c":"Kubernetes?"}]}]},"version":{"t":"MetaInlines","c":[{"t":"Str","c":"1.0"}]}},"blocks":[{"t":"Header","c":[1,["system-architecture-design",[],[]],[{"t":"Str","c":"System"},{"t":"Space"},{"t":"Str","c":"Architecture"},{"t":"Space"},{"t":"Str","c":"Design"}]]},{"t":"Para","c":[{"t":"Str","c":"This"},{"t":"Space"},{"t":"Str","c":"document"},{"t":"Space"},{"t":"Str","c":"outlines"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"high-level"},{"t":"Space"},{"t":"Str","c":"architecture"},{"t":"Space"},{"t":"Str","c":"of"},{"t":"Space"},{"t":"Str","c":"our"},{"t":"Space"},{"t":"Str","c":"distributed"},{"t":"Space"},{"t":"Str","c":"system."}]},{"t":"Header","c":[2,["overview",[],[]],[{"t":"Str","c":"Overview"}]]},{"t":"Para","c":[{"t":"Str","c":"Our"},{"t":"Space"},{"t":"Str","c":"system"},{"t":"Space"},{"t":"Str","c":"follows"},{"t":"Space"},{"t":"Str","c":"a"},{"t":"Space"},{"t":"Str","c":"microservices"},{"t":"Space"},{"t":"Str","c":"architecture"},{"t":"Space"},{"t":"Str","c":"pattern"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"clear"},{"t":"Space"},{"t":"Str","c":"separation"},{"t":"Space"},{"t":"Str","c":"of"},{"t":"Space"},{"t":"Str","c":"concerns."},{"t":"Space"},{"t":"Str","c":"The"},{"t":"Space"},{"t":"Str","c":"architecture"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"designed"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"scalability,"},{"t":"Space"},{"t":"Str","c":"maintainability,"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"fault"},{"t":"Space"},{"t":"Str","c":"tolerance."}]},{"t":"Para","c":[{"t":"Str","c":"Key"},{"t":"Space"},{"t":"Str","c":"principles:"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Microservices"},{"t":"Space"},{"t":"Str","c":"architecture"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Event-driven"},{"t":"Space"},{"t":"Str","c":"communication"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"API-first"},{"t":"Space"},{"t":"Str","c":"design"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Cloud-native"},{"t":"Space"},{"t":"Str","c":"deployment"}]},{"t":"Header","c":[2,["core-components",[],[]],[{"t":"Str","c":"Core"},{"t":"Space"},{"t":"Str","c":"Components"}]]},{"t":"Header","c":[3,["api-gateway",[],[]],[{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"Gateway"}]]},{"t":"Para","c":[{"t":"Str","c":"The"},{"t":"Space"},{"t":"Str","c":"API"},{"t":"Space"},{"t":"Str","c":"Gateway"},{"t":"Space"},{"t":"Str","c":"serves"},{"t":"Space"},{"t":"Str","c":"as"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"single"},{"t":"Space"},{"t":"Str","c":"entry"},{"t":"Space"},{"t":"Str","c":"point"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"all"},{"t":"Space"},{"t":"Str","c":"client"},{"t":"Space"},{"t":"Str","c":"requests."},{"t":"Space"},{"t":"Str","c":"It"},{"t":"Space"},{"t":"Str","c":"handles:"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Request"},{"t":"Space"},{"t":"Str","c":"routing"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"load"},{"t":"Space"},{"t":"Str","c":"balancing"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Authentication"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"authorization"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Rate"},{"t":"Space"},{"t":"Str","c":"limiting"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"throttling"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Request/response"},{"t":"Space"},{"t":"Str","c":"transformation"}]},{"t":"CodeBlock","c":[["",["yaml"],[]],"apiGateway:\n port: 8080\n timeout: 30s\n rateLimit: 1000/min\n auth:\n type: JWT\n secret: ${JWT_SECRET}"]},{"t":"Header","c":[3,["user-service",[],[]],[{"t":"Str","c":"User"},{"t":"Space"},{"t":"Str","c":"Service"}]]},{"t":"Para","c":[{"t":"Str","c":"Manages"},{"t":"Space"},{"t":"Str","c":"user"},{"t":"Space"},{"t":"Str","c":"accounts,"},{"t":"Space"},{"t":"Str","c":"profiles,"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"authentication:"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"User"},{"t":"Space"},{"t":"Str","c":"registration"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"login"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Profile"},{"t":"Space"},{"t":"Str","c":"management"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Password"},{"t":"Space"},{"t":"Str","c":"reset"},{"t":"Space"},{"t":"Str","c":"functionality"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Social"},{"t":"Space"},{"t":"Str","c":"authentication"},{"t":"Space"},{"t":"Str","c":"integration"}]},{"t":"Header","c":[3,["data-service",[],[]],[{"t":"Str","c":"Data"},{"t":"Space"},{"t":"Str","c":"Service"}]]},{"t":"Para","c":[{"t":"Str","c":"Handles"},{"t":"Space"},{"t":"Str","c":"all"},{"t":"Space"},{"t":"Str","c":"data"},{"t":"Space"},{"t":"Str","c":"operations:"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"CRUD"},{"t":"Space"},{"t":"Str","c":"operations"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"business"},{"t":"Space"},{"t":"Str","c":"entities"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Data"},{"t":"Space"},{"t":"Str","c":"validation"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"transformation"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Caching"},{"t":"Space"},{"t":"Str","c":"layer"},{"t":"Space"},{"t":"Str","c":"integration"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Database"},{"t":"Space"},{"t":"Str","c":"connection"},{"t":"Space"},{"t":"Str","c":"pooling"}]},{"t":"Header","c":[2,["database-schema",[],[]],[{"t":"Str","c":"Database"},{"t":"Space"},{"t":"Str","c":"Schema"}]]},{"t":"Table","c":[["",[],[]],[null,[]],[[{"t":"AlignDefault"},{"t":"ColWidthDefault"}],[{"t":"AlignDefault"},{"t":"ColWidthDefault"}],[{"t":"AlignDefault"},{"t":"ColWidthDefault"}]],[["",[],[]],[[["",[],[]],[[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"Table"}]}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"Purpose"}]}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"Key"},{"t":"Space"},{"t":"Str","c":"Fields"}]}]]]]]],[[["",[],[]],0,[],[[["",[],[]],[[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"users"}]}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"User"},{"t":"Space"},{"t":"Str","c":"accounts"}]}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"id,"},{"t":"Space"},{"t":"Str","c":"email,"},{"t":"Space"},{"t":"Str","c":"password_hash"}]}]]]],[["",[],[]],[[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"profiles"}]}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"User"},{"t":"Space"},{"t":"Str","c":"profiles"}]}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"user_id,"},{"t":"Space"},{"t":"Str","c":"name,"},{"t":"Space"},{"t":"Str","c":"avatar_url"}]}]]]],[["",[],[]],[[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"sessions"}]}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"Active"},{"t":"Space"},{"t":"Str","c":"sessions"}]}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"t":"Plain","c":[{"t":"Str","c":"id,"},{"t":"Space"},{"t":"Str","c":"user_id,"},{"t":"Space"},{"t":"Str","c":"expires_at"}]}]]]]]]],[["",[],[]],[]]]},{"t":"Header","c":[2,["deployment-architecture",[],[]],[{"t":"Str","c":"Deployment"},{"t":"Space"},{"t":"Str","c":"Architecture"}]]},{"t":"Para","c":[{"t":"Str","c":"The"},{"t":"Space"},{"t":"Str","c":"system"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"deployed"},{"t":"Space"},{"t":"Str","c":"using"},{"t":"Space"},{"t":"Str","c":"Docker"},{"t":"Space"},{"t":"Str","c":"containers"},{"t":"Space"},{"t":"Str","c":"orchestrated"},{"t":"Space"},{"t":"Str","c":"by"},{"t":"Space"},{"t":"Str","c":"Kubernetes:"}]},{"t":"CodeBlock","c":[["",["dockerfile"],[]],"FROM node:16-alpine\nWORKDIR /app\nCOPY package*.json ./\nRUN npm ci --only=production\nCOPY . .\nEXPOSE 3000\nCMD [\"npm\", \"start\"]"]}]} 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RAG Network Documentation Toolkit 2 | 3 | This repository provides a complete pipeline for processing Markdown-based network documentation, converting it into JSON-LD, indexing content for semantic search, and offering an interactive RAG (Retrieval-Augmented Generation) chat interface. By emitting JSON-LD, our documentation becomes immediately graph‑ready: you can ingest the output into any graph database (e.g., Neo4j, TigerGraph, Amazon Neptune) to perform advanced network analyses, visualize topology, and drive next‑generation knowledge applications. 4 | 5 | --- 6 | 7 | ## Table of Contents 8 | 9 | 1. [Why JSON‑LD for Network Docs?](#why-json-ld-for-network-docs) 10 | 2. [Key Features](#key-features) 11 | 3. [Architecture Overview](#architecture-overview) 12 | 4. [Project Structure](#project-structure) 13 | 5. [Installation](#installation) 14 | 6. [Usage Guide](#usage-guide) 15 | 16 | * [1. Prepare Markdown Files](#1-prepare-markdown-files) 17 | * [2. Convert to JSON‑LD](#2-convert-to-json-ld) 18 | * [3. Build FAISS Index](#3-build-faiss-index) 19 | * [4. Launch Chat Interface](#4-launch-chat-interface) 20 | 7. [JSON‑LD Output & Graph Import](#json-ld-output--graph-import) 21 | 22 | * [Sample JSON‑LD Document](#sample-json-ld-document) 23 | * [Ingesting into Neo4j](#ingesting-into-neo4j) 24 | 8. [Customization & Extensions](#customization--extensions) 25 | 9. [Troubleshooting & FAQs](#troubleshooting--faqs) 26 | 10. [Contributing](#contributing) 27 | 11. [License](#license) 28 | 29 | --- 30 | 31 | ## Why JSON‑LD for Network Docs? 32 | 33 | Network documentation often consists of device lists, topologies, configuration snippets, and conceptual diagrams—scattered across multiple files. Traditional formats (plain Markdown, PDF, Word) lack standardized structure for machine processing. JSON‑LD (JSON for Linking Data) provides: 34 | 35 | * **Semantic Structure**: An explicit graph model (`@context`, `@graph`) ties entities (devices, interfaces, subnets) to vocabularies (e.g., [schema.org](https://schema.org/), [NetworkVocabulary](https://example.org/network#)). 36 | * **Interoperability**: JSON‑LD is supported by RDF tools, SPARQL engines, and graph databases. 37 | * **Ease of Authoring**: Markdown authors can write in familiar syntax; our Panflute filter lifts semantics into JSON‑LD. 38 | * **Graph-Ready**: Outputs map directly to nodes/relationships—no ETL gymnastics. 39 | 40 | ## Key Features 41 | 42 | * **Panflute Filter (`md2jsonld.py`)** converts Markdown to JSON‑LD, preserving frontmatter metadata, sections, code blocks, tables, images, and lists. 43 | * **Chunk Extraction & FAISS Indexing** (`build_index.py`): Breaks JSON‑LD sections into text chunks, computes embeddings with SentenceTransformers, and builds a FAISS vector index for semantic retrieval. 44 | * **Interactive RAG Chat** (`rag_chat.py`): Gradio-based UI to ask natural language questions about your network docs, retrieving relevant chunks and synthesizing answers via OpenAI or local LLMs. 45 | * **Graph Database Integration**: JSON‑LD outputs are ready for Cypher, Gremlin, or SPARQL imports with minimal transformation. 46 | 47 | ## Architecture Overview 48 | 49 | ```text 50 | +-----------------+ +----------------+ +----------------------+ +----------------+ 51 | | Markdown Files | → | md2jsonld.py | → | JSON‑LD Documents | → | Chunk Extractor| 52 | | (network.md) | +----------------+ +----------------------+ +----------------+ 53 | | - frontmatter | 54 | | - sections | 55 | +-----------------+ | 56 | ▼ 57 | +----------------+ 58 | | VectorIndex | 59 | +------>| Builder | 60 | | +----------------+ 61 | | 62 | ▼ 63 | +-----------------+ 64 | | FAISS Index | 65 | +-----------------+ 66 | | 67 | ▼ 68 | +------------------+ 69 | | Gradio Chat UI | 70 | | (RAG System) | 71 | +------------------+ 72 | | 73 | ▼ 74 | +---------------------+ 75 | | Graph DB Ingestion | 76 | | (Neo4j, etc.) | 77 | +---------------------+ 78 | ``` 79 | 80 | ## Project Structure 81 | 82 | ``` 83 | ├── md2jsonld.py ← Panflute filter: Markdown → JSON‑LD 84 | ├── build_index.py ← Processes JSON‑LD → text chunks → FAISS index 85 | ├── rag_chat.py ← Gradio RAG chat interface over FAISS index 86 | ├── output/ ← Your raw `.md` network documentation 87 | ├── processed/ ← Generated `.jsonld`, `.ast.json` files 88 | ├── index/ ← Saved FAISS index, metadata, and info 89 | └── README.md ← This documentation 90 | ``` 91 | 92 | ## Installation 93 | 94 | 1. **Clone the repo**: 95 | 96 | ```bash 97 | git clone https://github.com/your-org/network-docs-rag.git 98 | cd network-docs-rag 99 | ``` 100 | 101 | 2. **Python & venv**: 102 | 103 | ```bash 104 | python3 -m venv .venv 105 | source .venv/bin/activate 106 | pip install --upgrade pip 107 | ``` 108 | 109 | 3. **Dependencies**: 110 | 111 | ```bash 112 | pip install -r requirements.txt 113 | ``` 114 | 115 | > *requirements.txt should include:* 116 | > 117 | > ```text 118 | > panflute 119 | > pandoc 120 | > sentence-transformers 121 | > faiss-cpu 122 | > gradio 123 | > openai 124 | > requests 125 | > ``` 126 | 127 | 4. **Pandoc & Panflute**: 128 | 129 | * Ensure `pandoc` is installed and on your `$PATH`. 130 | * Confirm `md2jsonld.py` is executable: 131 | 132 | ```bash 133 | chmod +x md2jsonld.py 134 | ``` 135 | 136 | ## Usage Guide 137 | 138 | ### 1. Prepare Markdown Files 139 | 140 | Place all your network documentation in Markdown under the `output/` directory. Example frontmatter: 141 | 142 | ```markdown 143 | --- 144 | id: junos_gnmimd 145 | title: "GNMI without Certificates on Juniper" 146 | description: "Config guide to run JunOS GNMI in insecure mode without certs" 147 | created: 2024-01-20 148 | author: "Network Automation Team" 149 | version: "1.0" 150 | category: "network-knowledge-base" 151 | keywords: 152 | - gnmi 153 | - juniper 154 | - grpc 155 | - insecure-mode 156 | training_questions: 157 | - How do I configure JunOS GNMI without certificates? 158 | - What port does JunOS use for insecure GNMI? 159 | related_products: 160 | - vMX 22.3R1.11 161 | - vQFX 19.4R1.10 162 | topics: 163 | - Network Telemetry 164 | - Juniper Configuration 165 | --- 166 | ``` 167 | 168 | ### 2. Convert to JSON‑LD 169 | 170 | Run the Panflute filter and generate AST to catch errors: 171 | 172 | ```bash 173 | python3 build_index.py 174 | ``` 175 | 176 | > This step invokes `md2jsonld.py` internally, producing JSON-LD (`processed/*.jsonld`) and AST dumps (`processed/*.ast.json`). 177 | 178 | ### 3. Build FAISS Index 179 | 180 | The same `build_index.py` script will: 181 | 182 | 1. Read each `.jsonld` file. 183 | 2. Extract text chunks per section. 184 | 3. Compute embeddings and build a FAISS index. 185 | 4. Save index, metadata, and `info.json` under `index/`. 186 | 187 | ### 4. Launch Chat Interface 188 | 189 | Interactively query your docs: 190 | 191 | ```bash 192 | python3 rag_chat.py 193 | ``` 194 | 195 | * **OpenAI**: Set `OPENAI_API_KEY` env var to use OpenAI. 196 | * **Local LLM**: Set `LOCAL_LLM_URL` & `LOCAL_LLM_MODEL` to point at Ollama/LocalAI. 197 | 198 | Access the Gradio URL shown in terminal to ask natural-language questions and receive source‑cited answers. 199 | 200 | ## JSON‑LD Output & Graph Import 201 | 202 | Your `processed/*.jsonld` files follow this structure: 203 | 204 | ```jsonld 205 | { 206 | "@context": { 207 | "@vocab": "https://schema.org/", 208 | "mainEntity": { 209 | "@id": "schema:mainEntity", 210 | "@type": "@id" 211 | }, 212 | "trainingQuestions": { 213 | "@container": "@list" 214 | }, 215 | "relatedProducts": { 216 | "@container": "@list" 217 | }, 218 | "topics": { 219 | "@container": "@list" 220 | }, 221 | "keywords": { 222 | "@container": "@list" 223 | } 224 | }, 225 | "@graph": [ 226 | { 227 | "@type": "Document", 228 | "@id": "junos_gnmimd", 229 | "filename": "junos_gnmi.md", 230 | "title": "GNMI without Certificates on Juniper", 231 | "description": "Config guide to run JunOS GNMI in insecure mode without certs", 232 | "dateCreated": "2024-01-20", 233 | "author": "Network Automation Team", 234 | "version": "1.0", 235 | "category": "network-knowledge-base", 236 | "keywords": [ 237 | "gnmi", 238 | "juniper", 239 | "grpc", 240 | "insecure-mode" 241 | ], 242 | "trainingQuestions": [ 243 | "How do I configure JunOS GNMI without certificates?", 244 | "What port does JunOS use for insecure GNMI?" 245 | ], 246 | "relatedProducts": [ 247 | "vMX 22.3R1.11", 248 | "vQFX 19.4R1.10" 249 | ], 250 | "topics": [ 251 | "Network Telemetry", 252 | "Juniper Configuration" 253 | ], 254 | "mainEntity": "junos_gnmimd-sec-3-how-to-setup-a-junos-device-for-gnmi-without-certificates" 255 | }, 256 | } 257 | ``` 258 | 259 | ### Ingesting into Neo4j 260 | 261 | 1. **Install APOC** plugin. 262 | 2. **Load JSON-LD** via Cypher: 263 | 264 | ```cypher 265 | CALL apoc.load.json("file:///processed/network.jsonld") YIELD value 266 | UNWIND value['@graph'] AS doc 267 | MERGE (d:Document {id: doc['@id']}) 268 | SET d.title = doc.title, d.description = doc.description 269 | 270 | UNWIND doc.sections AS sec 271 | MERGE (s:Section {id: sec['@id']}) 272 | SET s.title = sec.title, s.content = sec.content 273 | MERGE (d)-[:HAS_SECTION]->(s); 274 | ``` 275 | 276 | 3. **Explore**: Run graph queries, visualize topologies, or connect sections to device nodes in your network graph. 277 | 278 | ## Customization & Extensions 279 | 280 | - **Custom Context**: Modify `@context` in `md2jsonld.py` to map to your network ontology (e.g., Cisco IOS, `netconf:Interface`). 281 | - **Additional Elements**: Extend `action()` to handle custom Panflute elements (e.g., diagrams, YAML code blocks). 282 | - **Alternative Embeddings**: Swap out the SentenceTransformer model in `build_index.py` for domain‑specific embeddings. 283 | - **Graph DB Plugins**: Provide scripts for Amazon Neptune's bulk loader or JanusGraph's TinkerPop loader. 284 | 285 | ## Troubleshooting & FAQs 286 | 287 | - **JSON-LD generation fails**: Check `processed/*.ast.json` for pandoc errors. 288 | - **No chunks indexed**: Ensure your sections contain non-empty content. 289 | - **LLM errors**: Verify your API key or local LLM endpoint is reachable. 290 | - **Graph import issues**: Confirm file paths and APOC plugin availability. 291 | 292 | ## Contributing 293 | 294 | 1. Fork the repo. 295 | 2. Create a feature branch (`git checkout -b feature/my-feature`). 296 | 3. Commit your changes (`git commit -m 'Add new feature'`). 297 | 4. Push to the branch (`git push origin feature/my-feature`). 298 | 5. Open a Pull Request. 299 | 300 | Please adhere to our code style, include tests for new functionality, and update documentation accordingly. 301 | 302 | ## License 303 | 304 | This project is licensed under the **MIT License**. See [LICENSE](LICENSE) for details. 305 | -------------------------------------------------------------------------------- /rag_chat.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | RAG Chat Interface using Gradio. 4 | This script loads the pre-built FAISS index and provides a chat interface 5 | for querying design documents with semantic search and LLM synthesis. 6 | """ 7 | import os 8 | import logging 9 | from pathlib import Path 10 | from typing import List, Dict, Any, Tuple, Protocol 11 | 12 | import gradio as gr 13 | import faiss 14 | import pickle 15 | import requests 16 | from sentence_transformers import SentenceTransformer 17 | import openai 18 | 19 | # ----------------------------------------------------------------------------- 20 | # Configure logging 21 | # ----------------------------------------------------------------------------- 22 | logging.basicConfig( 23 | level=logging.INFO, 24 | format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" 25 | ) 26 | logger = logging.getLogger(__name__) 27 | 28 | # ----------------------------------------------------------------------------- 29 | # Custom Exceptions 30 | # ----------------------------------------------------------------------------- 31 | class RAGError(Exception): 32 | """Base exception for RAG system errors.""" 33 | pass 34 | 35 | class IndexNotFoundError(RAGError): 36 | """Raised when the FAISS index or metadata file is missing.""" 37 | pass 38 | 39 | class LLMClientError(RAGError): 40 | """Raised when LLM API calls fail.""" 41 | pass 42 | 43 | # ----------------------------------------------------------------------------- 44 | # Abstractions (Interface Segregation & Dependency Inversion) 45 | # ----------------------------------------------------------------------------- 46 | class LLMClient(Protocol): 47 | """Protocol for LLM client implementations.""" 48 | def generate(self, system_prompt: str, user_prompt: str) -> str: 49 | ... 50 | 51 | # ----------------------------------------------------------------------------- 52 | # Concrete LLM Clients 53 | # ----------------------------------------------------------------------------- 54 | class OpenAIClient: 55 | def __init__(self, api_key: str, model: str = "gpt-3.5-turbo"): 56 | import openai 57 | openai.api_key = api_key 58 | self.model = model 59 | 60 | def generate(self, system_prompt: str, user_prompt: str) -> str: 61 | import openai 62 | try: 63 | resp = openai.chat.completions.create( 64 | model=self.model, 65 | messages=[ 66 | {"role": "system", "content": system_prompt}, 67 | {"role": "user", "content": user_prompt}, 68 | ], 69 | max_tokens=1000, 70 | temperature=0.7, 71 | ) 72 | return resp.choices[0].message.content.strip() 73 | except Exception as e: 74 | logger.error("OpenAI API call failed: %s", e) 75 | raise LLMClientError("OpenAI generation error") from e 76 | 77 | 78 | class LocalLLMClient: 79 | """Client for local LLM endpoint (e.g., Ollama, LocalAI).""" 80 | def __init__(self, url: str, model: str) -> None: 81 | self.url = url.rstrip('/') 82 | self.model = model 83 | 84 | def generate(self, system_prompt: str, user_prompt: str) -> str: 85 | payload = { 86 | "model": self.model, 87 | "messages": [ 88 | {"role": "system", "content": system_prompt}, 89 | {"role": "user", "content": user_prompt}, 90 | ], 91 | "stream": False, 92 | "options": {"temperature": 0.7, "num_predict": 1000}, 93 | } 94 | try: 95 | resp = requests.post(f"{self.url}/chat/completions", json=payload, timeout=30) 96 | resp.raise_for_status() 97 | data = resp.json() 98 | return data["choices"][0]["message"]["content"].strip() 99 | 100 | except requests.RequestException as e: 101 | logger.error("Local LLM connection failed: %s", e) 102 | raise LLMClientError("Local LLM generation error") from e 103 | 104 | # ----------------------------------------------------------------------------- 105 | # RAG System Components 106 | # ----------------------------------------------------------------------------- 107 | class EmbeddingModel: 108 | """Wrapper around SentenceTransformer.""" 109 | def __init__(self, model_name: str): 110 | logger.info("Loading sentence transformer model: %s", model_name) 111 | self.model = SentenceTransformer(model_name) 112 | 113 | def encode(self, texts: List[str]) -> Any: 114 | return self.model.encode(texts, convert_to_numpy=True) 115 | 116 | class IndexStore: 117 | """Handles FAISS index and associated metadata.""" 118 | def __init__(self, index_dir: Path): 119 | self.index_dir = index_dir 120 | self.index = self._load_faiss() 121 | self.metadata = self._load_metadata() 122 | 123 | def _load_faiss(self) -> faiss.Index: 124 | path = self.index_dir / "faiss_index.bin" 125 | if not path.exists(): 126 | logger.error("FAISS index file missing: %s", path) 127 | raise IndexNotFoundError(f"Missing index file: {path}") 128 | logger.info("Loading FAISS index from %s", path) 129 | idx = faiss.read_index(str(path)) 130 | logger.info("FAISS index loaded; total vectors=%d", idx.ntotal) 131 | return idx 132 | 133 | def _load_metadata(self) -> List[Dict[str, Any]]: 134 | path = self.index_dir / "metadata.pkl" 135 | if not path.exists(): 136 | logger.error("Metadata file missing: %s", path) 137 | raise IndexNotFoundError(f"Missing metadata file: {path}") 138 | logger.info("Loading metadata from %s", path) 139 | with open(path, 'rb') as f: 140 | meta = pickle.load(f) 141 | logger.info("Metadata loaded; total chunks=%d", len(meta)) 142 | return meta 143 | 144 | class RetrievalService: 145 | """Performs semantic search over the FAISS index.""" 146 | def __init__(self, embed_model: EmbeddingModel, store: IndexStore): 147 | self.embed_model = embed_model 148 | self.store = store 149 | 150 | def retrieve(self, query: str, top_k: int = 5) -> List[Dict[str, Any]]: 151 | # Convert query to embedding 152 | emb = self.embed_model.encode([query]).astype('float32') 153 | distances, indices = self.store.index.search(emb, top_k) 154 | results = [] 155 | for rank, (dist, idx) in enumerate(zip(distances[0], indices[0]), start=1): 156 | if 0 <= idx < len(self.store.metadata): 157 | chunk = dict(self.store.metadata[idx]) 158 | chunk.update(distance=float(dist), rank=rank) 159 | results.append(chunk) 160 | return results 161 | 162 | # ----------------------------------------------------------------------------- 163 | # RAG System Orchestrator 164 | # ----------------------------------------------------------------------------- 165 | class RAGSystem: 166 | """Coordinates retrieval and LLM synthesis for user queries.""" 167 | def __init__( 168 | self, 169 | index_dir: Path, 170 | embedding_model: EmbeddingModel, 171 | retrieval_service: RetrievalService, 172 | llm_client: LLMClient, 173 | ): 174 | self.store = retrieval_service.store 175 | self.retrieval = retrieval_service 176 | self.llm = llm_client 177 | logger.info("RAGSystem initialized with backend=%s", type(llm_client).__name__) 178 | 179 | def generate_response( 180 | self, query: str, top_k: int = 5 181 | ) -> Tuple[str, List[Dict[str, Any]]]: 182 | # Validate input 183 | if not query or not query.strip(): 184 | raise ValueError("Query must be a non-empty string.") 185 | 186 | # Retrieve relevant chunks 187 | chunks = self.retrieval.retrieve(query, top_k) 188 | if not chunks: 189 | return "No relevant documents found for your query.", [] 190 | 191 | # Assemble context 192 | context = "\n\n---\n\n".join( 193 | f"[{c['filename']} - {c['section_title']}]\n{c['text']}" for c in chunks 194 | ) 195 | 196 | system_prompt = ( 197 | "You are a helpful assistant that answers questions about design documents. " 198 | "Use the provided context... Always cite sources." 199 | ) 200 | user_prompt = f"Context:\n{context}\n\nQuestion: {query}" # concise prompt 201 | 202 | # Generate answer 203 | try: 204 | answer = self.llm.generate(system_prompt, user_prompt) 205 | except LLMClientError as e: 206 | logger.error("LLM generation failed: %s", e) 207 | answer = f"Error generating response: {e}" 208 | 209 | return answer, chunks 210 | 211 | # ----------------------------------------------------------------------------- 212 | # Gradio Interface 213 | # ----------------------------------------------------------------------------- 214 | class GradioInterface: 215 | """Web UI for interacting with the RAG system via Gradio.""" 216 | def __init__(self, rag: RAGSystem): 217 | self.rag = rag 218 | self.chat_history: List[Dict[str, Any]] = [] 219 | 220 | def process(self, query: str, top_k: int) -> Tuple[str, str, str]: 221 | if not query.strip(): 222 | return "Please enter a question.", "", "" 223 | try: 224 | response, chunks = self.rag.generate_response(query, top_k) 225 | self.chat_history.append({"query": query, "chunks": len(chunks)}) 226 | return response, self._format_context(chunks), self._format_details(chunks) 227 | except Exception as e: 228 | logger.error("Processing error: %s", e) 229 | return f"Error: {e}", "", "" 230 | 231 | def _format_context(self, chunks: List[Dict[str, Any]]) -> str: 232 | if not chunks: 233 | return "No context retrieved." 234 | lines = [f"{i+1}. {c['filename']} - {c['section_title']}" for i, c in enumerate(chunks)] 235 | return "**Retrieved Context:**\n" + "\n".join(lines) 236 | 237 | def _format_details(self, chunks: List[Dict[str, Any]]) -> str: 238 | if not chunks: 239 | return "" 240 | parts = [] 241 | for i, c in enumerate(chunks, start=1): 242 | parts.append( 243 | f"**Chunk {i}:** {c['filename']} ({c['section_title']}) - " 244 | f"Score: {c['distance']:.3f}\n{c['text'][:150]}..." 245 | ) 246 | return "\n\n".join(parts) 247 | 248 | def launch(self) -> None: 249 | """Build and start the Gradio app.""" 250 | with gr.Blocks(title="RAG Design Document Chat") as demo: 251 | gr.Markdown("# 🔍 RAG Design Document Chat") 252 | # Input components 253 | query = gr.Textbox(label="Your Question", lines=2) 254 | top_k = gr.Slider(minimum=1, maximum=10, step=1, value=5, label="Top K") 255 | submit = gr.Button("Ask") 256 | 257 | # Output components 258 | response = gr.Textbox(label="AI Response", interactive=False) 259 | context = gr.Markdown(label="Retrieved Context") 260 | details = gr.Markdown(label="Retrieval Details") 261 | 262 | submit.click(self.process, [query, top_k], [response, context, details]) 263 | query.submit(self.process, [query, top_k], [response, context, details]) 264 | 265 | demo.launch(server_name="0.0.0.0", server_port=7860, debug=False) 266 | 267 | # ----------------------------------------------------------------------------- 268 | # Entry Point 269 | # ----------------------------------------------------------------------------- 270 | def main(): 271 | index_dir = Path("index") 272 | if not index_dir.exists(): 273 | raise IndexNotFoundError("Index directory does not exist.") 274 | 275 | # Initialize components with dependency injection 276 | embed_model = EmbeddingModel(model_name=os.getenv("EMBED_MODEL", "all-MiniLM-L6-v2")) 277 | store = IndexStore(index_dir) 278 | retrieval = RetrievalService(embed_model, store) 279 | 280 | # Choose LLM client based on environment 281 | api_key = os.getenv("OPENAI_API_KEY") 282 | if api_key: 283 | llm_client = OpenAIClient(api_key) 284 | else: 285 | local_url = os.getenv("LOCAL_LLM_URL", "http://localhost:11434/v1") 286 | local_model = os.getenv("LOCAL_LLM_MODEL", "llama2") 287 | llm_client = LocalLLMClient(local_url, local_model) 288 | 289 | # Compose RAG system and launch UI 290 | rag_system = RAGSystem(index_dir, embed_model, retrieval, llm_client) 291 | GradioInterface(rag_system).launch() 292 | 293 | 294 | if __name__ == "__main__": 295 | main() 296 | -------------------------------------------------------------------------------- /processed/security.ast.json: -------------------------------------------------------------------------------- 1 | {"pandoc-api-version":[1,23,1],"meta":{"author":{"t":"MetaInlines","c":[{"t":"Str","c":"Security"},{"t":"Space"},{"t":"Str","c":"Team"}]},"category":{"t":"MetaInlines","c":[{"t":"Str","c":"security"}]},"created":{"t":"MetaInlines","c":[{"t":"Str","c":"2024-01-25"}]},"description":{"t":"MetaBlocks","c":[{"t":"Para","c":[{"t":"Str","c":"Security"},{"t":"Space"},{"t":"Str","c":"best"},{"t":"Space"},{"t":"Str","c":"practices"},{"t":"Space"},{"t":"Str","c":"covering"},{"t":"Space"},{"t":"Str","c":"authentication,"},{"t":"Space"},{"t":"Str","c":"encryption,"},{"t":"Space"},{"t":"Str","c":"input"},{"t":"Space"},{"t":"Str","c":"validation,"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"compliance"},{"t":"Space"},{"t":"Str","c":"controls."}]}]},"id":{"t":"MetaInlines","c":[{"t":"Str","c":"security-guidelines"}]},"keywords":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"JWT"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Password"},{"t":"Space"},{"t":"Str","c":"Policy"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"XSS"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"SQL"},{"t":"Space"},{"t":"Str","c":"Injection"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"TLS"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Encryption"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"GDPR"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"SOC"},{"t":"Space"},{"t":"Str","c":"2"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Logging"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Incident"},{"t":"Space"},{"t":"Str","c":"Response"}]}]},"relatedStandards":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"GDPR"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"SOC"},{"t":"Space"},{"t":"Str","c":"2"},{"t":"Space"},{"t":"Str","c":"Type"},{"t":"Space"},{"t":"Str","c":"II"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"NIST"},{"t":"Space"},{"t":"Str","c":"SP"},{"t":"Space"},{"t":"Str","c":"800-53"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"OWASP"},{"t":"Space"},{"t":"Str","c":"Top"},{"t":"Space"},{"t":"Str","c":"10"}]}]},"reviewed":{"t":"MetaInlines","c":[{"t":"Str","c":"2024-01-30"}]},"status":{"t":"MetaInlines","c":[{"t":"Str","c":"approved"}]},"title":{"t":"MetaInlines","c":[{"t":"Str","c":"Security"},{"t":"Space"},{"t":"Str","c":"Guidelines"}]},"topics":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"Authentication"},{"t":"Space"},{"t":"Str","c":"&"},{"t":"Space"},{"t":"Str","c":"Authorization"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Secure"},{"t":"Space"},{"t":"Str","c":"Coding"},{"t":"Space"},{"t":"Str","c":"Practices"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Encryption"},{"t":"Space"},{"t":"Str","c":"at"},{"t":"Space"},{"t":"Str","c":"Rest"},{"t":"Space"},{"t":"Str","c":"&"},{"t":"Space"},{"t":"Str","c":"in"},{"t":"Space"},{"t":"Str","c":"Transit"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Security"},{"t":"Space"},{"t":"Str","c":"Monitoring"},{"t":"Space"},{"t":"Str","c":"&"},{"t":"Space"},{"t":"Str","c":"Logging"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Regulatory"},{"t":"Space"},{"t":"Str","c":"Compliance"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"Incident"},{"t":"Space"},{"t":"Str","c":"Response"},{"t":"Space"},{"t":"Str","c":"Planning"}]}]},"trainingQuestions":{"t":"MetaList","c":[{"t":"MetaInlines","c":[{"t":"Str","c":"How"},{"t":"Space"},{"t":"Str","c":"should"},{"t":"Space"},{"t":"Str","c":"JWT"},{"t":"Space"},{"t":"Str","c":"tokens"},{"t":"Space"},{"t":"Str","c":"be"},{"t":"Space"},{"t":"Str","c":"configured"},{"t":"Space"},{"t":"Str","c":"securely?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"What"},{"t":"Space"},{"t":"Str","c":"password"},{"t":"Space"},{"t":"Str","c":"hashing"},{"t":"Space"},{"t":"Str","c":"algorithm"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"rotation"},{"t":"Space"},{"t":"Str","c":"policy"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"recommended?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"How"},{"t":"Space"},{"t":"Str","c":"do"},{"t":"Space"},{"t":"Str","c":"you"},{"t":"Space"},{"t":"Str","c":"mitigate"},{"t":"Space"},{"t":"Str","c":"XSS"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"SQL"},{"t":"Space"},{"t":"Str","c":"injection"},{"t":"Space"},{"t":"Str","c":"risks?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"What"},{"t":"Space"},{"t":"Str","c":"logging"},{"t":"Space"},{"t":"Str","c":"events"},{"t":"Space"},{"t":"Str","c":"are"},{"t":"Space"},{"t":"Str","c":"critical"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"security"},{"t":"Space"},{"t":"Str","c":"auditing?"}]},{"t":"MetaInlines","c":[{"t":"Str","c":"What"},{"t":"Space"},{"t":"Str","c":"controls"},{"t":"Space"},{"t":"Str","c":"are"},{"t":"Space"},{"t":"Str","c":"required"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"GDPR"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"SOC"},{"t":"Space"},{"t":"Str","c":"2"},{"t":"Space"},{"t":"Str","c":"compliance?"}]}]},"type":{"t":"MetaInlines","c":[{"t":"Str","c":"http://example.com/security#SecurityPolicyDocument"}]},"version":{"t":"MetaInlines","c":[{"t":"Str","c":"1.0"}]}},"blocks":[{"t":"Header","c":[1,["security-guidelines",[],[]],[{"t":"Str","c":"Security"},{"t":"Space"},{"t":"Str","c":"Guidelines"}]]},{"t":"Para","c":[{"t":"Str","c":"This"},{"t":"Space"},{"t":"Str","c":"document"},{"t":"Space"},{"t":"Str","c":"outlines"},{"t":"Space"},{"t":"Str","c":"security"},{"t":"Space"},{"t":"Str","c":"best"},{"t":"Space"},{"t":"Str","c":"practices"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"implementation"},{"t":"Space"},{"t":"Str","c":"guidelines"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"our"},{"t":"Space"},{"t":"Str","c":"system."}]},{"t":"Header","c":[2,["authentication-authorization",[],[]],[{"t":"Str","c":"Authentication"},{"t":"Space"},{"t":"Str","c":"&"},{"t":"Space"},{"t":"Str","c":"Authorization"}]]},{"t":"Header","c":[3,["jwt-token-security",[],[]],[{"t":"Str","c":"JWT"},{"t":"Space"},{"t":"Str","c":"Token"},{"t":"Space"},{"t":"Str","c":"Security"}]]},{"t":"Para","c":[{"t":"Str","c":"JSON"},{"t":"Space"},{"t":"Str","c":"Web"},{"t":"Space"},{"t":"Str","c":"Tokens"},{"t":"Space"},{"t":"Str","c":"(JWT)"},{"t":"Space"},{"t":"Str","c":"are"},{"t":"Space"},{"t":"Str","c":"used"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"stateless"},{"t":"Space"},{"t":"Str","c":"authentication:"}]},{"t":"BulletList","c":[[{"t":"Plain","c":[{"t":"Str","c":"Tokens"},{"t":"Space"},{"t":"Str","c":"expire"},{"t":"Space"},{"t":"Str","c":"after"},{"t":"Space"},{"t":"Str","c":"1"},{"t":"Space"},{"t":"Str","c":"hour"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"security"}]}],[{"t":"Plain","c":[{"t":"Str","c":"Refresh"},{"t":"Space"},{"t":"Str","c":"tokens"},{"t":"Space"},{"t":"Str","c":"are"},{"t":"Space"},{"t":"Str","c":"valid"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"30"},{"t":"Space"},{"t":"Str","c":"days"}]}],[{"t":"Plain","c":[{"t":"Str","c":"Use"},{"t":"Space"},{"t":"Str","c":"strong,"},{"t":"Space"},{"t":"Str","c":"random"},{"t":"Space"},{"t":"Str","c":"secrets"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"token"},{"t":"Space"},{"t":"Str","c":"signing"}]}],[{"t":"Plain","c":[{"t":"Str","c":"Implement"},{"t":"Space"},{"t":"Str","c":"token"},{"t":"Space"},{"t":"Str","c":"blacklisting"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"logout"}]}]]},{"t":"CodeBlock","c":[["",["javascript"],[]],"const jwt = require('jsonwebtoken');\n\nconst generateToken = (user) => {\n return jwt.sign(\n { id: user.id, email: user.email },\n process.env.JWT_SECRET,\n { expiresIn: '1h' }\n );\n};"]},{"t":"Header","c":[3,["password-security",[],[]],[{"t":"Str","c":"Password"},{"t":"Space"},{"t":"Str","c":"Security"}]]},{"t":"Para","c":[{"t":"Str","c":"Password"},{"t":"Space"},{"t":"Str","c":"handling"},{"t":"Space"},{"t":"Str","c":"requirements:"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Minimum"},{"t":"Space"},{"t":"Str","c":"8"},{"t":"Space"},{"t":"Str","c":"characters"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"mixed"},{"t":"Space"},{"t":"Str","c":"case,"},{"t":"Space"},{"t":"Str","c":"numbers,"},{"t":"Space"},{"t":"Str","c":"symbols"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Hash"},{"t":"Space"},{"t":"Str","c":"passwords"},{"t":"Space"},{"t":"Str","c":"using"},{"t":"Space"},{"t":"Str","c":"bcrypt"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"salt"},{"t":"Space"},{"t":"Str","c":"rounds"},{"t":"Space"},{"t":"Str","c":"≥"},{"t":"Space"},{"t":"Str","c":"12"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Implement"},{"t":"Space"},{"t":"Str","c":"password"},{"t":"Space"},{"t":"Str","c":"history"},{"t":"Space"},{"t":"Str","c":"to"},{"t":"Space"},{"t":"Str","c":"prevent"},{"t":"Space"},{"t":"Str","c":"reuse"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Enforce"},{"t":"Space"},{"t":"Str","c":"password"},{"t":"Space"},{"t":"Str","c":"rotation"},{"t":"Space"},{"t":"Str","c":"every"},{"t":"Space"},{"t":"Str","c":"90"},{"t":"Space"},{"t":"Str","c":"days"}]},{"t":"Header","c":[2,["input-validation",[],[]],[{"t":"Str","c":"Input"},{"t":"Space"},{"t":"Str","c":"Validation"}]]},{"t":"Header","c":[3,["sql-injection-prevention",[],[]],[{"t":"Str","c":"SQL"},{"t":"Space"},{"t":"Str","c":"Injection"},{"t":"Space"},{"t":"Str","c":"Prevention"}]]},{"t":"Para","c":[{"t":"Str","c":"Always"},{"t":"Space"},{"t":"Str","c":"use"},{"t":"Space"},{"t":"Str","c":"parameterized"},{"t":"Space"},{"t":"Str","c":"queries"},{"t":"Space"},{"t":"Str","c":"or"},{"t":"Space"},{"t":"Str","c":"ORMs:"}]},{"t":"CodeBlock","c":[["",["sql"],[]],"-- Bad: Direct string concatenation\nSELECT * FROM users WHERE email = '\" + userInput + \"'\n\n-- Good: Parameterized query\nSELECT * FROM users WHERE email = ?"]},{"t":"Header","c":[3,["xss-prevention",[],[]],[{"t":"Str","c":"XSS"},{"t":"Space"},{"t":"Str","c":"Prevention"}]]},{"t":"Para","c":[{"t":"Str","c":"Sanitize"},{"t":"Space"},{"t":"Str","c":"all"},{"t":"Space"},{"t":"Str","c":"user"},{"t":"Space"},{"t":"Str","c":"inputs:"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Escape"},{"t":"Space"},{"t":"Str","c":"HTML"},{"t":"Space"},{"t":"Str","c":"entities"},{"t":"Space"},{"t":"Str","c":"in"},{"t":"Space"},{"t":"Str","c":"output"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Use"},{"t":"Space"},{"t":"Str","c":"Content"},{"t":"Space"},{"t":"Str","c":"Security"},{"t":"Space"},{"t":"Str","c":"Policy"},{"t":"Space"},{"t":"Str","c":"(CSP)"},{"t":"Space"},{"t":"Str","c":"headers"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Validate"},{"t":"Space"},{"t":"Str","c":"input"},{"t":"Space"},{"t":"Str","c":"on"},{"t":"Space"},{"t":"Str","c":"both"},{"t":"Space"},{"t":"Str","c":"client"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"server"},{"t":"Space"},{"t":"Str","c":"side"}]},{"t":"Header","c":[2,["data-protection",[],[]],[{"t":"Str","c":"Data"},{"t":"Space"},{"t":"Str","c":"Protection"}]]},{"t":"Header","c":[3,["encryption-at-rest",[],[]],[{"t":"Str","c":"Encryption"},{"t":"Space"},{"t":"Str","c":"at"},{"t":"Space"},{"t":"Str","c":"Rest"}]]},{"t":"Para","c":[{"t":"Str","c":"Sensitive"},{"t":"Space"},{"t":"Str","c":"data"},{"t":"Space"},{"t":"Str","c":"must"},{"t":"Space"},{"t":"Str","c":"be"},{"t":"Space"},{"t":"Str","c":"encrypted"},{"t":"Space"},{"t":"Str","c":"using"},{"t":"Space"},{"t":"Str","c":"AES-256:"}]},{"t":"CodeBlock","c":[["",["python"],[]],"from cryptography.fernet import Fernet\n\ndef encrypt_sensitive_data(data, key):\n cipher = Fernet(key)\n encrypted_data = cipher.encrypt(data.encode())\n return encrypted_data"]},{"t":"Header","c":[3,["encryption-in-transit",[],[]],[{"t":"Str","c":"Encryption"},{"t":"Space"},{"t":"Str","c":"in"},{"t":"Space"},{"t":"Str","c":"Transit"}]]},{"t":"Para","c":[{"t":"Str","c":"All"},{"t":"Space"},{"t":"Str","c":"communications"},{"t":"Space"},{"t":"Str","c":"must"},{"t":"Space"},{"t":"Str","c":"use"},{"t":"Space"},{"t":"Str","c":"TLS"},{"t":"Space"},{"t":"Str","c":"1.2"},{"t":"Space"},{"t":"Str","c":"or"},{"t":"Space"},{"t":"Str","c":"higher:"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"HTTPS"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"web"},{"t":"Space"},{"t":"Str","c":"traffic"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"TLS"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"database"},{"t":"Space"},{"t":"Str","c":"connections"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"mTLS"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"service-to-service"},{"t":"Space"},{"t":"Str","c":"communication"}]},{"t":"Header","c":[2,["monitoring-logging",[],[]],[{"t":"Str","c":"Monitoring"},{"t":"Space"},{"t":"Str","c":"&"},{"t":"Space"},{"t":"Str","c":"Logging"}]]},{"t":"Header","c":[3,["security-event-logging",[],[]],[{"t":"Str","c":"Security"},{"t":"Space"},{"t":"Str","c":"Event"},{"t":"Space"},{"t":"Str","c":"Logging"}]]},{"t":"Para","c":[{"t":"Str","c":"Log"},{"t":"Space"},{"t":"Str","c":"all"},{"t":"Space"},{"t":"Str","c":"security-relevant"},{"t":"Space"},{"t":"Str","c":"events:"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Authentication"},{"t":"Space"},{"t":"Str","c":"attempts"},{"t":"Space"},{"t":"Str","c":"(success/failure)"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Authorization"},{"t":"Space"},{"t":"Str","c":"failures"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Data"},{"t":"Space"},{"t":"Str","c":"access"},{"t":"Space"},{"t":"Str","c":"patterns"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Admin"},{"t":"Space"},{"t":"Str","c":"actions"}]},{"t":"Header","c":[3,["incident-response",[],[]],[{"t":"Str","c":"Incident"},{"t":"Space"},{"t":"Str","c":"Response"}]]},{"t":"Para","c":[{"t":"Str","c":"Incident"},{"t":"Space"},{"t":"Str","c":"response"},{"t":"Space"},{"t":"Str","c":"procedures:"},{"t":"SoftBreak"},{"t":"Str","c":"1."},{"t":"Space"},{"t":"Str","c":"Immediate"},{"t":"Space"},{"t":"Str","c":"containment"},{"t":"SoftBreak"},{"t":"Str","c":"2."},{"t":"Space"},{"t":"Str","c":"Impact"},{"t":"Space"},{"t":"Str","c":"assessment"},{"t":"SoftBreak"},{"t":"Str","c":"3."},{"t":"Space"},{"t":"Str","c":"Evidence"},{"t":"Space"},{"t":"Str","c":"collection"},{"t":"SoftBreak"},{"t":"Str","c":"4."},{"t":"Space"},{"t":"Str","c":"System"},{"t":"Space"},{"t":"Str","c":"recovery"},{"t":"SoftBreak"},{"t":"Str","c":"5."},{"t":"Space"},{"t":"Str","c":"Post-incident"},{"t":"Space"},{"t":"Str","c":"review"}]},{"t":"Header","c":[2,["compliance-requirements",[],[]],[{"t":"Str","c":"Compliance"},{"t":"Space"},{"t":"Str","c":"Requirements"}]]},{"t":"Header","c":[3,["gdpr-compliance",[],[]],[{"t":"Str","c":"GDPR"},{"t":"Space"},{"t":"Str","c":"Compliance"}]]},{"t":"Para","c":[{"t":"Str","c":"Data"},{"t":"Space"},{"t":"Str","c":"protection"},{"t":"Space"},{"t":"Str","c":"measures:"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Right"},{"t":"Space"},{"t":"Str","c":"to"},{"t":"Space"},{"t":"Str","c":"be"},{"t":"Space"},{"t":"Str","c":"forgotten"},{"t":"Space"},{"t":"Str","c":"implementation"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Data"},{"t":"Space"},{"t":"Str","c":"portability"},{"t":"Space"},{"t":"Str","c":"features"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Consent"},{"t":"Space"},{"t":"Str","c":"management"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Data"},{"t":"Space"},{"t":"Str","c":"minimization"},{"t":"Space"},{"t":"Str","c":"principles"}]},{"t":"Header","c":[3,["soc-2-type-ii",[],[]],[{"t":"Str","c":"SOC"},{"t":"Space"},{"t":"Str","c":"2"},{"t":"Space"},{"t":"Str","c":"Type"},{"t":"Space"},{"t":"Str","c":"II"}]]},{"t":"Para","c":[{"t":"Str","c":"Control"},{"t":"Space"},{"t":"Str","c":"objectives:"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Security"},{"t":"Space"},{"t":"Str","c":"controls"},{"t":"Space"},{"t":"Str","c":"testing"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Availability"},{"t":"Space"},{"t":"Str","c":"monitoring"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Processing"},{"t":"Space"},{"t":"Str","c":"integrity"},{"t":"Space"},{"t":"Str","c":"validation"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Confidentiality"},{"t":"Space"},{"t":"Str","c":"protection"},{"t":"SoftBreak"},{"t":"Str","c":"-"},{"t":"Space"},{"t":"Str","c":"Privacy"},{"t":"Space"},{"t":"Str","c":"safeguards"}]}]} 2 | -------------------------------------------------------------------------------- /output/evpn_design.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: "evpn_leaf_spine_design" 3 | title: "EVPN Leaf-Spine Network Design" 4 | description: > 5 | Scalable BGP-EVPN-based data center fabric with VXLAN overlay and multi-tenant segmentation. 6 | author: "Gary Woodward" 7 | created: "2025-06-24" 8 | version: "1.0" 9 | category: "network-design" 10 | type: "http://example.com/network-design#NetworkDesignDocument" 11 | keywords: 12 | - EVPN 13 | - VXLAN 14 | - Leaf-Spine 15 | - BGP 16 | - DataCenter 17 | - Multitenancy 18 | - Underlay 19 | - Overlay 20 | - Automation 21 | topics: 22 | - EVPN Architecture 23 | - BGP Control Plane 24 | - Data Center Fabric Design 25 | - VXLAN Overlay Networks 26 | - Network Security 27 | - Infrastructure as Code 28 | relatedProducts: 29 | - "DataCorp Fabric v1.0" 30 | trainingQuestions: 31 | - "What role does EVPN play in this architecture?" 32 | - "How are BGP ASNs structured for underlay and overlay?" 33 | - "What security features are applied at the tunnel level?" 34 | - "How does the VXLAN VNI allocation strategy support scalability?" 35 | - "What are the benefits of using L3VNIs in this fabric?" 36 | - "How is automation integrated with the design?" 37 | complianceStandards: 38 | - PCI DSS 39 | - SOC 2 Type II 40 | - NIST CSF 41 | status: "approved" 42 | reviewed: "2025-06-26" 43 | --- 44 | 45 | # EVPN Leaf-Spine Network Design Document 46 | 47 | ## Executive Summary 48 | 49 | This document presents the network architecture design for DataCorp's new data center infrastructure utilizing Ethernet VPN (EVPN) technology in a leaf-spine topology. The design addresses the organization's requirements for scalable multi-tenancy, Layer 2 extension capabilities, and modern data center networking practices while maintaining operational simplicity and robust security posture. 50 | 51 | ## Introduction 52 | 53 | Modern data center networks require architectures that can scale horizontally while providing consistent low-latency connectivity and supporting virtualized workloads. Traditional spanning tree-based designs have given way to more sophisticated approaches that leverage BGP-based control planes and VXLAN data planes to achieve these goals. 54 | 55 | Our EVPN leaf-spine design represents a significant evolution from legacy three-tier architectures, providing several key advantages: 56 | 57 | **Architectural Benefits:** 58 | - **Horizontal Scalability**: The spine-leaf topology allows linear scaling by adding leaf switches without redesigning the core network 59 | - **Predictable Performance**: Every leaf switch is exactly two hops away from any other leaf, ensuring consistent latency characteristics 60 | - **Loop-Free Design**: BGP-based control plane eliminates the need for Spanning Tree Protocol in the underlay network 61 | - **Multi-Tenancy Support**: EVPN provides native support for VRF-based tenant isolation with flexible policy enforcement 62 | 63 | **Technical Innovation:** 64 | The design leverages EVPN Type-2 and Type-5 routes to provide both Layer 2 and Layer 3 VPN services over a single unified infrastructure. VXLAN encapsulation enables overlay networks that are completely independent of the physical underlay topology, allowing for seamless virtual machine mobility and simplified network provisioning. 65 | 66 | **Business Alignment:** 67 | This architecture directly supports DataCorp's strategic initiatives around cloud-first infrastructure, DevOps automation, and multi-tenant service delivery. The programmable nature of EVPN networks enables infrastructure-as-code practices and rapid service deployment cycles that align with modern application development methodologies. 68 | 69 | ## Network Topology Overview 70 | 71 | ### Physical Architecture 72 | 73 | The network implements a standard two-tier leaf-spine architecture optimized for east-west traffic patterns typical in modern data centers: 74 | 75 | ``` 76 | ┌─────────────┐ ┌─────────────┐ 77 | │ Spine-1 │ │ Spine-2 │ 78 | │ 10.0.0.11 │ │ 10.0.0.12 │ 79 | └─────────────┘ └─────────────┘ 80 | │ │ 81 | ┌──────┼──────────────────┼──────┐ 82 | │ │ │ │ 83 | ┌─────────┐ │ ┌─────────┐ │ 84 | │ Leaf1 │ │ ... │ Leaf6 │ │ 85 | │ AS65001 │ │ │ AS65003 │ │ 86 | └─────────┘ │ └─────────┘ │ 87 | │ │ 88 | ┌─────────────────────────────────┐ 89 | │ Host Networks │ 90 | │ VLAN 10: 172.16.10.0/24 │ 91 | │ VLAN 20: 172.16.20.0/24 │ 92 | └─────────────────────────────────┘ 93 | ``` 94 | 95 | ### Addressing Scheme 96 | 97 | The design utilizes a hierarchical addressing structure that separates underlay infrastructure from overlay tenant networks: 98 | 99 | **Underlay Networks:** 100 | - Loopback Addresses: `10.0.0.0/24` (BGP Router IDs) 101 | - VTEP Addresses: `10.100.100.0/24` (VXLAN Tunnel Endpoints) 102 | - Point-to-Point Links: `10.1.0.0/16` and `10.2.0.0/16` (Spine-1 and Spine-2 respectively) 103 | - Management Network: `192.168.0.0/24` 104 | 105 | **Overlay Networks:** 106 | - VLAN 10: `172.16.10.0/24` (Production Environment) 107 | - VLAN 20: `172.16.20.0/24` (Development Environment) 108 | 109 | ## Design Decisions 110 | 111 | ### BGP AS Number Strategy 112 | 113 | The design implements a hub-and-spoke BGP topology using distinct Autonomous System numbers: 114 | 115 | ```bash 116 | # Spine switches (Route Reflectors) 117 | router bgp 65000 118 | 119 | # Leaf switches (unique AS per leaf) 120 | # Leaf6 configuration 121 | router bgp 65003 122 | ``` 123 | 124 | **Rationale:** Using unique AS numbers per leaf switch enables: 125 | - Simplified route filtering and policy application 126 | - Clear administrative boundaries for troubleshooting 127 | - Compliance with BGP best practices for EVPN deployments 128 | - Future flexibility for complex multi-site scenarios 129 | 130 | ### VXLAN Network Identifier (VNI) Allocation 131 | 132 | VNI assignment follows a structured approach that embeds VLAN information: 133 | 134 | ```bash 135 | # VLAN-to-VNI mapping 136 | vxlan vlan 10 vni 1000010 # Pattern: 10000 + VLAN ID 137 | vxlan vlan 20 vni 1000020 138 | vxlan vrf CLIENTS vni 1000000 # L3VNI for inter-VLAN routing 139 | ``` 140 | 141 | **Design Considerations:** 142 | - Predictable VNI allocation simplifies network operations 143 | - 24-bit VNI space provides ample room for future growth 144 | - L3VNI separation enables efficient inter-VLAN routing 145 | - Consistent numbering across all leaf switches 146 | 147 | ### Redundancy and High Availability 148 | 149 | Physical redundancy is achieved through: 150 | 151 | ```bash 152 | # Dual-homed spine connectivity 153 | interface Port-Channel20 154 | description to_Spine-1 155 | ip address 10.1.6.1/30 156 | 157 | interface Port-Channel10 158 | description to_Spine-2 159 | ip address 10.2.6.1/30 160 | ``` 161 | 162 | **Link Aggregation Benefits:** 163 | - Increased bandwidth utilization (2x 10GbE = 20GbE effective) 164 | - Sub-second failover through LACP 165 | - Load distribution across physical links 166 | - Simplified configuration management 167 | 168 | ### MTU Optimization 169 | 170 | Jumbo frame configuration across the fabric: 171 | 172 | ```bash 173 | # 9214-byte MTU on all fabric interfaces 174 | interface Port-Channel20 175 | mtu 9214 176 | interface Ethernet1 177 | mtu 9214 178 | ``` 179 | 180 | **Justification:** 181 | - Accommodates VXLAN overhead (50 bytes) while maintaining 9000-byte payload 182 | - Reduces packet fragmentation and improves throughput 183 | - Industry standard for data center fabrics 184 | - Future-proofs for additional encapsulation requirements 185 | 186 | ## Security Architecture 187 | 188 | ### Network Segmentation Strategy 189 | 190 | The security architecture implements defense-in-depth principles through multiple isolation mechanisms: 191 | 192 | **VRF-Based Tenant Isolation:** 193 | ```bash 194 | vrf instance CLIENTS 195 | description Clients networks 196 | 197 | # VRF-aware interfaces 198 | interface Vlan10 199 | vrf CLIENTS 200 | ip address virtual 172.16.10.1/24 201 | ``` 202 | 203 | This provides complete routing table separation between tenant networks, ensuring that traffic cannot traverse between VRFs without explicit policy configuration. 204 | 205 | **VXLAN Tunnel Security:** 206 | ```bash 207 | interface Vxlan1 208 | vxlan learn-restrict any 209 | ``` 210 | 211 | The `learn-restrict any` configuration prevents dynamic MAC learning, requiring all endpoint information to be distributed through the BGP EVPN control plane. This eliminates flood-and-learn behavior that could be exploited for network reconnaissance. 212 | 213 | ### Access Control Framework 214 | 215 | **Port Security Implementation:** 216 | ```bash 217 | interface Ethernet3 218 | description to_host2 219 | switchport mode trunk 220 | spanning-tree portfast 221 | ``` 222 | 223 | Host-facing interfaces utilize trunk mode with explicit VLAN assignments, preventing VLAN hopping attacks while supporting virtualized environments. 224 | 225 | **BGP Route Filtering:** 226 | ```bash 227 | neighbor evpn maximum-routes 12000 warning-only 228 | neighbor underlay maximum-routes 12000 warning-only 229 | ``` 230 | 231 | Route limiting protects against route table exhaustion attacks and provides early warning of misconfigurations that could impact network stability. 232 | 233 | ### Cryptographic Controls 234 | 235 | **Management Plane Security:** 236 | ```bash 237 | username admin privilege 15 role network-admin secret sha512 $6$aCD32ZXIHf.MwRbY$LQXzjVJGmGQUtNlOcX4hhu0eU6fy5/onI3uwuXKruHOTnuK3SssP82E6/naU6clcGufhIxpoomQl.KGndzfvb0 238 | ``` 239 | 240 | Administrative access utilizes SHA-512 hashed passwords with role-based access control, ensuring strong authentication mechanisms. 241 | 242 | **Data Plane Considerations:** 243 | While the current implementation utilizes unencrypted VXLAN tunnels for performance optimization, the architecture supports future implementation of: 244 | - IPSec encryption for VXLAN tunnels 245 | - MACsec for physical link encryption 246 | - Integration with external key management systems 247 | 248 | ### Monitoring and Compliance 249 | 250 | **Security Event Logging:** 251 | The design incorporates comprehensive logging capabilities for security event correlation: 252 | - BGP session state changes 253 | - MAC learning events 254 | - VXLAN tunnel establishment 255 | - Administrative access attempts 256 | 257 | **Compliance Framework:** 258 | The architecture aligns with industry security frameworks: 259 | - PCI DSS network segmentation requirements 260 | - SOC 2 Type II access controls 261 | - NIST Cybersecurity Framework implementation 262 | 263 | ## Operational Support Systems (OSS) 264 | 265 | ### Network Automation and Orchestration 266 | 267 | **Infrastructure as Code Implementation:** 268 | The standardized configuration structure enables full automation through tools like Ansible, Terraform, and custom Python scripts: 269 | 270 | ```python 271 | # Example automation template structure 272 | leaf_config = { 273 | 'hostname': 'leaf6', 274 | 'loopback0': '10.0.0.6/32', 275 | 'vtep_ip': '10.100.100.6/32', 276 | 'asn': '65003', 277 | 'spine_connections': [ 278 | {'spine': 'spine-1', 'ip': '10.1.6.1/30'}, 279 | {'spine': 'spine-2', 'ip': '10.2.6.1/30'} 280 | ] 281 | } 282 | ``` 283 | 284 | **Configuration Management:** 285 | - Git-based version control for all network configurations 286 | - Automated compliance checking against security baselines 287 | - Rollback capabilities for rapid issue resolution 288 | - Integration with CI/CD pipelines for network changes 289 | 290 | ### Monitoring and Observability 291 | 292 | **Telemetry Collection Strategy:** 293 | ```bash 294 | # Key metrics for collection 295 | - BGP session status and route counts 296 | - VXLAN tunnel state and traffic statistics 297 | - Interface utilization and error rates 298 | - EVPN route advertisement/withdrawal events 299 | ``` 300 | 301 | **SNMP and Streaming Telemetry:** 302 | The Arista EOS platform provides comprehensive telemetry capabilities: 303 | - Real-time streaming telemetry for sub-second visibility 304 | - Traditional SNMP for integration with existing NMS platforms 305 | - gNMI support for modern network automation tools 306 | - Custom EOS SDK applications for specialized monitoring 307 | 308 | ### Fault Management 309 | 310 | **Proactive Monitoring:** 311 | - BGP session monitoring with automatic alerting 312 | - Interface utilization trending and capacity planning 313 | - EVPN route table analysis for optimization opportunities 314 | - Predictive analytics for hardware failure prevention 315 | 316 | **Incident Response Framework:** 317 | - Automated fault isolation through BGP route withdrawal 318 | - Maintenance mode procedures for planned outages 319 | - Documentation of common troubleshooting procedures 320 | - Integration with enterprise ITSM platforms 321 | 322 | ### Performance Management 323 | 324 | **Capacity Planning Metrics:** 325 | - East-west traffic matrix analysis 326 | - VTEP CPU and memory utilization tracking 327 | - BGP control plane scaling metrics 328 | - Tenant network growth projections 329 | 330 | **Quality of Service (QoS):** 331 | Future implementation will include: 332 | - Application-aware traffic classification 333 | - Dynamic bandwidth allocation per tenant 334 | - Priority queuing for critical applications 335 | - Network slice implementation for 5G services 336 | 337 | ## Configuration Examples 338 | 339 | ### Leaf Switch Base Configuration 340 | 341 | ```bash 342 | # Hostname and basic services 343 | hostname leaf6 344 | service routing protocols model multi-agent 345 | transceiver qsfp default-mode 4x10G 346 | 347 | # VRF definition for tenant isolation 348 | vrf instance CLIENTS 349 | description Clients networks 350 | 351 | # VLAN definitions with descriptive names 352 | vlan 10 353 | name Network_172.16.10.0 354 | vlan 20 355 | name Network_172.16.20.0 356 | ``` 357 | 358 | ### Underlay Network Configuration 359 | 360 | ```bash 361 | # Spine-1 connectivity with port channeling 362 | interface Port-Channel20 363 | description to_Spine-1 364 | no switchport 365 | mtu 9214 366 | ip address 10.1.6.1/30 367 | 368 | interface Ethernet1 369 | description to_Spine-1-link1 370 | channel-group 20 mode active 371 | no switchport 372 | mtu 9214 373 | 374 | # Spine-2 connectivity with redundant links 375 | interface Port-Channel10 376 | description to_Spine-2 377 | no switchport 378 | mtu 9214 379 | ip address 10.2.6.1/30 380 | 381 | interface Ethernet2 382 | description to_Spine-2-link1 383 | channel-group 10 mode active 384 | no switchport 385 | mtu 9214 386 | 387 | interface Ethernet4 388 | description to_Spine-2-link2 389 | channel-group 10 mode active 390 | no switchport 391 | mtu 9214 392 | ``` 393 | 394 | ### EVPN and VXLAN Configuration 395 | 396 | ```bash 397 | # Loopback interfaces for BGP and VXLAN 398 | interface Loopback0 399 | description BGP EVPN peering 400 | ip address 10.0.0.6/32 401 | 402 | interface Loopback1 403 | description VXLAN VTEP 404 | ip address 10.100.100.6/32 405 | 406 | # VXLAN tunnel interface 407 | interface Vxlan1 408 | vxlan source-interface Loopback1 409 | vxlan virtual-router encapsulation mac-address local 410 | vxlan udp-port 4789 411 | vxlan vlan 10 vni 1000010 412 | vxlan vlan 20 vni 1000020 413 | vxlan vrf CLIENTS vni 1000000 414 | vxlan learn-restrict any 415 | 416 | # Virtual gateway configuration 417 | ip virtual-router mac-address c0:01:ca:fe:ba:be 418 | 419 | # SVI configurations for tenant networks 420 | interface Vlan10 421 | vrf CLIENTS 422 | ip address virtual 172.16.10.1/24 423 | 424 | interface Vlan20 425 | vrf CLIENTS 426 | ip address virtual 172.16.20.1/24 427 | ``` 428 | 429 | ### BGP EVPN Configuration 430 | 431 | ```bash 432 | router bgp 65003 433 | router-id 10.0.0.6 434 | no bgp default ipv4-unicast 435 | distance bgp 20 200 200 436 | maximum-paths 4 ecmp 64 437 | 438 | # EVPN peer group for spine connections 439 | neighbor evpn peer-group 440 | neighbor evpn remote-as 65000 441 | neighbor evpn update-source Loopback0 442 | neighbor evpn ebgp-multihop 3 443 | neighbor evpn send-community extended 444 | neighbor evpn maximum-routes 12000 warning-only 445 | 446 | # Underlay peer group for IP fabric 447 | neighbor underlay peer-group 448 | neighbor underlay remote-as 65000 449 | neighbor underlay maximum-routes 12000 warning-only 450 | 451 | # Specific neighbor definitions 452 | neighbor 10.0.0.11 peer-group evpn 453 | neighbor 10.0.0.12 peer-group evpn 454 | neighbor 10.1.6.2 peer-group underlay 455 | neighbor 10.2.6.2 peer-group underlay 456 | 457 | # Address family configurations 458 | address-family evpn 459 | neighbor evpn activate 460 | 461 | address-family ipv4 462 | neighbor underlay activate 463 | network 10.0.0.6/32 464 | network 10.100.100.6/32 465 | 466 | # VRF-specific BGP configuration 467 | vrf CLIENTS 468 | rd 65003:1000000 469 | route-target import evpn 1:1000000 470 | route-target export evpn 1:1000000 471 | redistribute connected 472 | ``` 473 | 474 | ## Testing and Validation 475 | 476 | ### Pre-Deployment Testing 477 | 478 | **Lab Environment Validation:** 479 | - Full topology simulation using containerized Arista vEOS 480 | - Traffic generation and performance testing 481 | - Failover scenario validation 482 | - Configuration drift detection 483 | 484 | ### Deployment Validation Procedures 485 | 486 | **Connectivity Testing:** 487 | ```bash 488 | # Underlay reachability verification 489 | ping 10.0.0.11 source 10.0.0.6 490 | ping 10.0.0.12 source 10.0.0.6 491 | 492 | # BGP session validation 493 | show bgp evpn summary 494 | show bgp ipv4 unicast summary 495 | 496 | # VXLAN tunnel verification 497 | show vxlan vtep 498 | show vxlan vni 499 | ``` 500 | 501 | **Data Path Validation:** 502 | - Inter-VLAN routing functionality 503 | - MAC learning and aging behavior 504 | - Multicast replication efficiency 505 | - QoS marking preservation 506 | 507 | ## Conclusion 508 | 509 | This EVPN leaf-spine network design provides DataCorp with a robust, scalable, and secure foundation for modern data center operations. The architecture successfully addresses the key requirements of multi-tenancy, high availability, and operational simplicity while positioning the organization for future growth and technology adoption. 510 | 511 | The implementation of industry-standard protocols and best practices ensures long-term supportability and vendor independence, while the comprehensive security framework provides the necessary controls for regulatory compliance and risk management. 512 | 513 | Future enhancements will focus on advanced automation capabilities, enhanced telemetry integration, and potential expansion to multi-site deployments using EVPN Type-5 routes for DCI connectivity. -------------------------------------------------------------------------------- /processed/evpn_design.jsonld: -------------------------------------------------------------------------------- 1 | { 2 | "@context": { 3 | "@vocab": "https://schema.org/", 4 | "mainEntity": { 5 | "@id": "schema:mainEntity", 6 | "@type": "@id" 7 | }, 8 | "trainingQuestions": { 9 | "@container": "@list" 10 | }, 11 | "relatedProducts": { 12 | "@container": "@list" 13 | }, 14 | "topics": { 15 | "@container": "@list" 16 | }, 17 | "keywords": { 18 | "@container": "@list" 19 | } 20 | }, 21 | "@graph": [ 22 | { 23 | "@type": "Document", 24 | "@id": "evpn_leaf_spine_design", 25 | "filename": "evpn_design.md", 26 | "title": "EVPN Leaf-Spine Network Design", 27 | "description": "Scalable BGP-EVPN-based data center fabric with VXLAN overlay and multi-tenant segmentation.\n\n", 28 | "dateCreated": "2025-06-24", 29 | "author": "Gary Woodward", 30 | "version": "1.0", 31 | "category": "network-design", 32 | "keywords": [ 33 | "EVPN", 34 | "VXLAN", 35 | "Leaf-Spine", 36 | "BGP", 37 | "DataCenter", 38 | "Multitenancy", 39 | "Underlay", 40 | "Overlay", 41 | "Automation" 42 | ], 43 | "trainingQuestions": [ 44 | "What role does EVPN play in this architecture?", 45 | "How are BGP ASNs structured for underlay and overlay?", 46 | "What security features are applied at the tunnel level?", 47 | "How does the VXLAN VNI allocation strategy support scalability?", 48 | "What are the benefits of using L3VNIs in this fabric?", 49 | "How is automation integrated with the design?" 50 | ], 51 | "relatedProducts": [ 52 | "DataCorp Fabric v1.0" 53 | ], 54 | "topics": [ 55 | "EVPN Architecture", 56 | "BGP Control Plane", 57 | "Data Center Fabric Design", 58 | "VXLAN Overlay Networks", 59 | "Network Security", 60 | "Infrastructure as Code" 61 | ] 62 | }, 63 | { 64 | "@type": "Section", 65 | "@id": "evpn_designmd-sec-1-document-introduction", 66 | "title": "Document Introduction", 67 | "level": 1, 68 | "content": "Scalable BGP-EVPN-based data center fabric with VXLAN overlay and multi-tenant segmentation.", 69 | "primary": false 70 | }, 71 | { 72 | "@type": "Section", 73 | "@id": "evpn_designmd-sec-3-executive-summary", 74 | "title": "Executive Summary", 75 | "level": 2, 76 | "content": "This document presents the network architecture design for DataCorp\u2019s new data center infrastructure utilizing Ethernet VPN (EVPN) technology in a leaf-spine topology. The design addresses the organization\u2019s requirements for scalable multi-tenancy, Layer 2 extension capabilities, and modern data center networking practices while maintaining operational simplicity and robust security posture.", 77 | "primary": false 78 | }, 79 | { 80 | "@type": "Section", 81 | "@id": "evpn_designmd-sec-4-introduction", 82 | "title": "Introduction", 83 | "level": 2, 84 | "content": "Modern data center networks require architectures that can scale horizontally while providing consistent low-latency connectivity and supporting virtualized workloads. Traditional spanning tree-based designs have given way to more sophisticated approaches that leverage BGP-based control planes and VXLAN data planes to achieve these goals.\n\nOur EVPN leaf-spine design represents a significant evolution from legacy three-tier architectures, providing several key advantages:\n\nArchitectural Benefits: - Horizontal Scalability: The spine-leaf topology allows linear scaling by adding leaf switches without redesigning the core network - Predictable Performance: Every leaf switch is exactly two hops away from any other leaf, ensuring consistent latency characteristics - Loop-Free Design: BGP-based control plane eliminates the need for Spanning Tree Protocol in the underlay network - Multi-Tenancy Support: EVPN provides native support for VRF-based tenant isolation with flexible policy enforcement\n\nTechnical Innovation: The design leverages EVPN Type-2 and Type-5 routes to provide both Layer 2 and Layer 3 VPN services over a single unified infrastructure. VXLAN encapsulation enables overlay networks that are completely independent of the physical underlay topology, allowing for seamless virtual machine mobility and simplified network provisioning.\n\nBusiness Alignment: This architecture directly supports DataCorp\u2019s strategic initiatives around cloud-first infrastructure, DevOps automation, and multi-tenant service delivery. The programmable nature of EVPN networks enables infrastructure-as-code practices and rapid service deployment cycles that align with modern application development methodologies.", 85 | "primary": false 86 | }, 87 | { 88 | "@type": "Section", 89 | "@id": "evpn_designmd-sec-5-network-topology-overview", 90 | "title": "Network Topology Overview", 91 | "level": 2, 92 | "content": "### Physical Architecture\n\nThe network implements a standard two-tier leaf-spine architecture optimized for east-west traffic patterns typical in modern data centers:\n\n```\n \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n \u2502 Spine-1 \u2502 \u2502 Spine-2 \u2502\n \u2502 10.0.0.11 \u2502 \u2502 10.0.0.12 \u2502\n \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n \u2502 \u2502\n \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n \u2502 \u2502 \u2502 \u2502\n \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502\n \u2502 Leaf1 \u2502 \u2502 ... \u2502 Leaf6 \u2502 \u2502\n \u2502 AS65001 \u2502 \u2502 \u2502 AS65003 \u2502 \u2502\n \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502\n \u2502 \u2502\n \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n \u2502 Host Networks \u2502\n \u2502 VLAN 10: 172.16.10.0/24 \u2502\n \u2502 VLAN 20: 172.16.20.0/24 \u2502\n \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n```\n\n### Addressing Scheme\n\nThe design utilizes a hierarchical addressing structure that separates underlay infrastructure from overlay tenant networks:\n\nUnderlay Networks: - Loopback Addresses: 10.0.0.0/24 (BGP Router IDs) - VTEP Addresses: 10.100.100.0/24 (VXLAN Tunnel Endpoints) - Point-to-Point Links: 10.1.0.0/16 and 10.2.0.0/16 (Spine-1 and Spine-2 respectively) - Management Network: 192.168.0.0/24\n\nOverlay Networks: - VLAN 10: 172.16.10.0/24 (Production Environment) - VLAN 20: 172.16.20.0/24 (Development Environment)", 93 | "primary": false 94 | }, 95 | { 96 | "@type": "Section", 97 | "@id": "evpn_designmd-sec-6-design-decisions", 98 | "title": "Design Decisions", 99 | "level": 2, 100 | "content": "### BGP AS Number Strategy\n\nThe design implements a hub-and-spoke BGP topology using distinct Autonomous System numbers:\n\n```bash\n# Spine switches (Route Reflectors)\nrouter bgp 65000\n\n# Leaf switches (unique AS per leaf)\n# Leaf6 configuration\nrouter bgp 65003\n```\n\nRationale: Using unique AS numbers per leaf switch enables: - Simplified route filtering and policy application - Clear administrative boundaries for troubleshooting - Compliance with BGP best practices for EVPN deployments - Future flexibility for complex multi-site scenarios\n\n### VXLAN Network Identifier (VNI) Allocation\n\nVNI assignment follows a structured approach that embeds VLAN information:\n\n```bash\n# VLAN-to-VNI mapping\nvxlan vlan 10 vni 1000010 # Pattern: 10000 + VLAN ID\nvxlan vlan 20 vni 1000020\nvxlan vrf CLIENTS vni 1000000 # L3VNI for inter-VLAN routing\n```\n\nDesign Considerations: - Predictable VNI allocation simplifies network operations - 24-bit VNI space provides ample room for future growth - L3VNI separation enables efficient inter-VLAN routing - Consistent numbering across all leaf switches\n\n### Redundancy and High Availability\n\nPhysical redundancy is achieved through:\n\n```bash\n# Dual-homed spine connectivity\ninterface Port-Channel20\n description to_Spine-1\n ip address 10.1.6.1/30\n\ninterface Port-Channel10\n description to_Spine-2\n ip address 10.2.6.1/30\n```\n\nLink Aggregation Benefits: - Increased bandwidth utilization (2x 10GbE = 20GbE effective) - Sub-second failover through LACP - Load distribution across physical links - Simplified configuration management\n\n### MTU Optimization\n\nJumbo frame configuration across the fabric:\n\n```bash\n# 9214-byte MTU on all fabric interfaces\ninterface Port-Channel20\n mtu 9214\ninterface Ethernet1\n mtu 9214\n```\n\nJustification: - Accommodates VXLAN overhead (50 bytes) while maintaining 9000-byte payload - Reduces packet fragmentation and improves throughput - Industry standard for data center fabrics - Future-proofs for additional encapsulation requirements", 101 | "primary": false 102 | }, 103 | { 104 | "@type": "Section", 105 | "@id": "evpn_designmd-sec-7-security-architecture", 106 | "title": "Security Architecture", 107 | "level": 2, 108 | "content": "### Network Segmentation Strategy\n\nThe security architecture implements defense-in-depth principles through multiple isolation mechanisms:\n\nVRF-Based Tenant Isolation:\n\n```bash\nvrf instance CLIENTS\n description Clients networks\n\n# VRF-aware interfaces\ninterface Vlan10\n vrf CLIENTS\n ip address virtual 172.16.10.1/24\n```\n\nThis provides complete routing table separation between tenant networks, ensuring that traffic cannot traverse between VRFs without explicit policy configuration.\n\nVXLAN Tunnel Security:\n\n```bash\ninterface Vxlan1\n vxlan learn-restrict any\n```\n\nThe learn-restrict any configuration prevents dynamic MAC learning, requiring all endpoint information to be distributed through the BGP EVPN control plane. This eliminates flood-and-learn behavior that could be exploited for network reconnaissance.\n\n### Access Control Framework\n\nPort Security Implementation:\n\n```bash\ninterface Ethernet3\n description to_host2\n switchport mode trunk\n spanning-tree portfast\n```\n\nHost-facing interfaces utilize trunk mode with explicit VLAN assignments, preventing VLAN hopping attacks while supporting virtualized environments.\n\nBGP Route Filtering:\n\n```bash\nneighbor evpn maximum-routes 12000 warning-only\nneighbor underlay maximum-routes 12000 warning-only\n```\n\nRoute limiting protects against route table exhaustion attacks and provides early warning of misconfigurations that could impact network stability.\n\n### Cryptographic Controls\n\nManagement Plane Security:\n\n```bash\nusername admin privilege 15 role network-admin secret sha512 $6$aCD32ZXIHf.MwRbY$LQXzjVJGmGQUtNlOcX4hhu0eU6fy5/onI3uwuXKruHOTnuK3SssP82E6/naU6clcGufhIxpoomQl.KGndzfvb0\n```\n\nAdministrative access utilizes SHA-512 hashed passwords with role-based access control, ensuring strong authentication mechanisms.\n\nData Plane Considerations: While the current implementation utilizes unencrypted VXLAN tunnels for performance optimization, the architecture supports future implementation of: - IPSec encryption for VXLAN tunnels - MACsec for physical link encryption - Integration with external key management systems\n\n### Monitoring and Compliance\n\nSecurity Event Logging: The design incorporates comprehensive logging capabilities for security event correlation: - BGP session state changes - MAC learning events - VXLAN tunnel establishment - Administrative access attempts\n\nCompliance Framework: The architecture aligns with industry security frameworks: - PCI DSS network segmentation requirements - SOC 2 Type II access controls - NIST Cybersecurity Framework implementation", 109 | "primary": false 110 | }, 111 | { 112 | "@type": "Section", 113 | "@id": "evpn_designmd-sec-8-operational-support-systems-oss", 114 | "title": "Operational Support Systems (OSS)", 115 | "level": 2, 116 | "content": "### Network Automation and Orchestration\n\nInfrastructure as Code Implementation: The standardized configuration structure enables full automation through tools like Ansible, Terraform, and custom Python scripts:\n\n```python\n# Example automation template structure\nleaf_config = {\n 'hostname': 'leaf6',\n 'loopback0': '10.0.0.6/32',\n 'vtep_ip': '10.100.100.6/32',\n 'asn': '65003',\n 'spine_connections': [\n {'spine': 'spine-1', 'ip': '10.1.6.1/30'},\n {'spine': 'spine-2', 'ip': '10.2.6.1/30'}\n ]\n}\n```\n\nConfiguration Management: - Git-based version control for all network configurations - Automated compliance checking against security baselines - Rollback capabilities for rapid issue resolution - Integration with CI/CD pipelines for network changes\n\n### Monitoring and Observability\n\nTelemetry Collection Strategy:\n\n```bash\n# Key metrics for collection\n- BGP session status and route counts\n- VXLAN tunnel state and traffic statistics \n- Interface utilization and error rates\n- EVPN route advertisement/withdrawal events\n```\n\nSNMP and Streaming Telemetry: The Arista EOS platform provides comprehensive telemetry capabilities: - Real-time streaming telemetry for sub-second visibility - Traditional SNMP for integration with existing NMS platforms - gNMI support for modern network automation tools - Custom EOS SDK applications for specialized monitoring\n\n### Fault Management\n\nProactive Monitoring: - BGP session monitoring with automatic alerting - Interface utilization trending and capacity planning - EVPN route table analysis for optimization opportunities - Predictive analytics for hardware failure prevention\n\nIncident Response Framework: - Automated fault isolation through BGP route withdrawal - Maintenance mode procedures for planned outages - Documentation of common troubleshooting procedures - Integration with enterprise ITSM platforms\n\n### Performance Management\n\nCapacity Planning Metrics: - East-west traffic matrix analysis - VTEP CPU and memory utilization tracking - BGP control plane scaling metrics - Tenant network growth projections\n\nQuality of Service (QoS): Future implementation will include: - Application-aware traffic classification - Dynamic bandwidth allocation per tenant - Priority queuing for critical applications - Network slice implementation for 5G services", 117 | "primary": false 118 | }, 119 | { 120 | "@type": "Section", 121 | "@id": "evpn_designmd-sec-9-configuration-examples", 122 | "title": "Configuration Examples", 123 | "level": 2, 124 | "content": "### Leaf Switch Base Configuration\n\n```bash\n# Hostname and basic services\nhostname leaf6\nservice routing protocols model multi-agent\ntransceiver qsfp default-mode 4x10G\n\n# VRF definition for tenant isolation\nvrf instance CLIENTS\n description Clients networks\n\n# VLAN definitions with descriptive names\nvlan 10\n name Network_172.16.10.0\nvlan 20\n name Network_172.16.20.0\n```\n\n### Underlay Network Configuration\n\n```bash\n# Spine-1 connectivity with port channeling\ninterface Port-Channel20\n description to_Spine-1\n no switchport\n mtu 9214\n ip address 10.1.6.1/30\n\ninterface Ethernet1\n description to_Spine-1-link1\n channel-group 20 mode active\n no switchport\n mtu 9214\n\n# Spine-2 connectivity with redundant links\ninterface Port-Channel10\n description to_Spine-2\n no switchport\n mtu 9214\n ip address 10.2.6.1/30\n\ninterface Ethernet2\n description to_Spine-2-link1\n channel-group 10 mode active\n no switchport\n mtu 9214\n\ninterface Ethernet4\n description to_Spine-2-link2\n channel-group 10 mode active\n no switchport\n mtu 9214\n```\n\n### EVPN and VXLAN Configuration\n\n```bash\n# Loopback interfaces for BGP and VXLAN\ninterface Loopback0\n description BGP EVPN peering\n ip address 10.0.0.6/32\n\ninterface Loopback1\n description VXLAN VTEP\n ip address 10.100.100.6/32\n\n# VXLAN tunnel interface\ninterface Vxlan1\n vxlan source-interface Loopback1\n vxlan virtual-router encapsulation mac-address local\n vxlan udp-port 4789\n vxlan vlan 10 vni 1000010\n vxlan vlan 20 vni 1000020\n vxlan vrf CLIENTS vni 1000000\n vxlan learn-restrict any\n\n# Virtual gateway configuration\nip virtual-router mac-address c0:01:ca:fe:ba:be\n\n# SVI configurations for tenant networks\ninterface Vlan10\n vrf CLIENTS\n ip address virtual 172.16.10.1/24\n\ninterface Vlan20\n vrf CLIENTS\n ip address virtual 172.16.20.1/24\n```\n\n### BGP EVPN Configuration\n\n```bash\nrouter bgp 65003\n router-id 10.0.0.6\n no bgp default ipv4-unicast\n distance bgp 20 200 200\n maximum-paths 4 ecmp 64\n\n # EVPN peer group for spine connections\n neighbor evpn peer-group\n neighbor evpn remote-as 65000\n neighbor evpn update-source Loopback0\n neighbor evpn ebgp-multihop 3\n neighbor evpn send-community extended\n neighbor evpn maximum-routes 12000 warning-only\n\n # Underlay peer group for IP fabric\n neighbor underlay peer-group\n neighbor underlay remote-as 65000\n neighbor underlay maximum-routes 12000 warning-only\n\n # Specific neighbor definitions\n neighbor 10.0.0.11 peer-group evpn\n neighbor 10.0.0.12 peer-group evpn\n neighbor 10.1.6.2 peer-group underlay\n neighbor 10.2.6.2 peer-group underlay\n\n # Address family configurations\n address-family evpn\n neighbor evpn activate\n\n address-family ipv4\n neighbor underlay activate\n network 10.0.0.6/32\n network 10.100.100.6/32\n\n # VRF-specific BGP configuration\n vrf CLIENTS\n rd 65003:1000000\n route-target import evpn 1:1000000\n route-target export evpn 1:1000000\n redistribute connected\n```", 125 | "primary": false 126 | }, 127 | { 128 | "@type": "Section", 129 | "@id": "evpn_designmd-sec-10-testing-and-validation", 130 | "title": "Testing and Validation", 131 | "level": 2, 132 | "content": "### Pre-Deployment Testing\n\nLab Environment Validation: - Full topology simulation using containerized Arista vEOS - Traffic generation and performance testing - Failover scenario validation - Configuration drift detection\n\n### Deployment Validation Procedures\n\nConnectivity Testing:\n\n```bash\n# Underlay reachability verification\nping 10.0.0.11 source 10.0.0.6\nping 10.0.0.12 source 10.0.0.6\n\n# BGP session validation\nshow bgp evpn summary\nshow bgp ipv4 unicast summary\n\n# VXLAN tunnel verification\nshow vxlan vtep\nshow vxlan vni\n```\n\nData Path Validation: - Inter-VLAN routing functionality - MAC learning and aging behavior - Multicast replication efficiency - QoS marking preservation", 133 | "primary": false 134 | }, 135 | { 136 | "@type": "Section", 137 | "@id": "evpn_designmd-sec-11-conclusion", 138 | "title": "Conclusion", 139 | "level": 2, 140 | "content": "This EVPN leaf-spine network design provides DataCorp with a robust, scalable, and secure foundation for modern data center operations. The architecture successfully addresses the key requirements of multi-tenancy, high availability, and operational simplicity while positioning the organization for future growth and technology adoption.\n\nThe implementation of industry-standard protocols and best practices ensures long-term supportability and vendor independence, while the comprehensive security framework provides the necessary controls for regulatory compliance and risk management.\n\nFuture enhancements will focus on advanced automation capabilities, enhanced telemetry integration, and potential expansion to multi-site deployments using EVPN Type-5 routes for DCI connectivity.", 141 | "primary": false 142 | } 143 | ] 144 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------