Segment Routing กับ Technical Debt Management —
Segment Routing สำหรับ Modern Networks

Segment Routing เป็น Network Architecture ที่ทำให้ Traffic Engineering ง่ายขึ้นมาก ใช้ Segments กำหนดเส้นทาง ไม่ต้อง Maintain State ที่ทุก Node ลด Complexity ของ Network
เนื้อหาเกี่ยวข้อง — บทความที่เกี่ยวข้อง: Midjourney Prompt Post-mortem Analysis
Technical Debt ใน Network สะสมจาก Manual Configuration, Legacy Protocols และ Quick Fixes การใช้ Segment Routing ร่วมกับ Automation ช่วยลด Technical Debt และทำให้ Network Maintainable
เนื้อหาเกี่ยวข้อง — บทความที่เกี่ยวข้อง: Web Design Portfolio — สร้าง Portfolio
Segment Routing Configuration
# === Segment Routing Configuration ===
# 1. SR-MPLS บน Cisco IOS-XR
# -----------------------------------------------
# Router R1 — Enable Segment Routing
# router isis CORE
# is-type level-2-only
# net 49.0001.0000.0000.0001.00
# address-family ipv4 unicast
# metric-style wide
# segment-routing mpls
# !
# interface Loopback0
# passive
# address-family ipv4 unicast
# prefix-sid index 1
# !
# interface GigabitEthernet0/0/0/0
# point-to-point
# address-family ipv4 unicast
# metric 10
# !
# interface GigabitEthernet0/0/0/1
# point-to-point
# address-family ipv4 unicast
# metric 10
# 2. SR-TE Policy (Traffic Engineering)
# segment-routing
# traffic-eng
# policy SR-POLICY-1
# color 100 end-point ipv4 10.0.0.5
# candidate-paths
# preference 200
# explicit segment-list SL-VIA-R3
# preference 100
# dynamic
# pcep
# metric
# type igp
# !
# !
# segment-list SL-VIA-R3
# index 10 mpls label 16003
# index 20 mpls label 16005
# 3. SRv6 Configuration
# segment-routing
# srv6
# locators
# locator MAIN
# prefix fc00:0:1::/48
# !
# !
# !
# router isis CORE
# address-family ipv6 unicast
# segment-routing srv6
# locator MAIN
# 4. TI-LFA (Topology Independent Loop-Free Alternate)
# router isis CORE
# interface GigabitEthernet0/0/0/0
# address-family ipv4 unicast
# fast-reroute per-prefix
# fast-reroute per-prefix ti-lfa
# 5. Flex-Algo (Flexible Algorithm)
# router isis CORE
# flex-algo 128
# metric-type delay
# advertise-definition
# !
# interface Loopback0
# address-family ipv4 unicast
# prefix-sid algorithm 128 index 101
# Verification Commands
# show isis segment-routing label table
# show segment-routing traffic-eng policy all
# show segment-routing srv6 locator
# show isis fast-reroute summary
# show isis flex-algo 128
echo "Segment Routing configured"
echo " SR-MPLS: Prefix-SID, SR-TE Policy"
echo " SRv6: Locator fc00:0:1::/48"
echo " Protection: TI-LFA"
echo " Optimization: Flex-Algo 128 (delay)"
Network Automation สำหรับลด Technical Debt

# network_automation.py — Network Automation ด้วย Nornir
# pip install nornir nornir-netmiko nornir-utils pyyaml jinja2
from dataclasses import dataclass, field
from typing import List, Dict, Optional
import yaml
import json
from datetime import datetime
@dataclass
class NetworkDevice:
hostname: str
ip: str
platform: str # ios, iosxr, junos, eos
role: str # spine, leaf, pe, p, ce
sr_enabled: bool = False
prefix_sid: int = 0
flex_algos: List[int] = field(default_factory=list)
@dataclass
class TechnicalDebtItem:
id: str
category: str # config, protocol, security, documentation
severity: str # critical, high, medium, low
description: str
device: str
remediation: str
created: str = ""
resolved: bool = False
class NetworkDebtManager:
"""จัดการ Technical Debt ใน Network"""
def __init__(self):
self.devices: List[NetworkDevice] = []
self.debt_items: List[TechnicalDebtItem] = []
self.audit_results: Dict = {}
def add_device(self, device: NetworkDevice):
self.devices.append(device)
def audit_device(self, device: NetworkDevice) -> List[TechnicalDebtItem]:
"""ตรวจสอบ Technical Debt บน Device"""
items = []
# Check: SR not enabled
if not device.sr_enabled:
items.append(TechnicalDebtItem(
id=f"TD-{len(self.debt_items)+len(items)+1:04d}",
category="protocol",
severity="high",
description=f"Segment Routing not enabled on {device.hostname}",
device=device.hostname,
remediation="Enable SR-MPLS or SRv6 and assign Prefix-SID",
created=datetime.now().strftime("%Y-%m-%d"),
))
# Check: No Flex-Algo
if device.sr_enabled and not device.flex_algos:
items.append(TechnicalDebtItem(
id=f"TD-{len(self.debt_items)+len(items)+1:04d}",
category="config",
severity="medium",
description=f"No Flex-Algo configured on {device.hostname}",
device=device.hostname,
remediation="Configure Flex-Algo 128 (delay) for latency-sensitive traffic",
created=datetime.now().strftime("%Y-%m-%d"),
))
# Check: Missing TI-LFA
if device.role in ["pe", "p", "spine"]:
items.append(TechnicalDebtItem(
id=f"TD-{len(self.debt_items)+len(items)+1:04d}",
category="config",
severity="high",
description=f"TI-LFA not verified on {device.hostname}",
device=device.hostname,
remediation="Enable TI-LFA on all ISIS/OSPF interfaces",
created=datetime.now().strftime("%Y-%m-%d"),
))
self.debt_items.extend(items)
return items
def audit_all(self):
"""Audit ทุก Devices"""
total_items = []
for device in self.devices:
items = self.audit_device(device)
total_items.extend(items)
self.audit_results = {
"total_devices": len(self.devices),
"total_debt": len(total_items),
"by_severity": {},
"by_category": {},
}
for item in total_items:
self.audit_results["by_severity"][item.severity] = \
self.audit_results["by_severity"].get(item.severity, 0) + 1
self.audit_results["by_category"][item.category] = \
self.audit_results["by_category"].get(item.category, 0) + 1
return self.audit_results
def print_report(self):
"""แสดง Technical Debt Report"""
results = self.audit_all()
print(f"\n{'='*60}")
print(f"Network Technical Debt Report")
print(f"{'='*60}")
print(f" Devices: {results['total_devices']}")
print(f" Total Debt Items: {results['total_debt']}")
print(f"\n By Severity:")
for sev, count in sorted(results["by_severity"].items()):
print(f" {sev:>10}: {count}")
print(f"\n By Category:")
for cat, count in sorted(results["by_category"].items()):
print(f" {cat:>15}: {count}")
print(f"\n Top Items:")
critical = [d for d in self.debt_items if d.severity in ["critical", "high"]]
for item in critical[:10]:
print(f" [{item.severity:>8}] {item.device}: {item.description}")
# ตัวอย่าง
manager = NetworkDebtManager()
devices = [
NetworkDevice("PE1", "10.0.0.1", "iosxr", "pe", True, 1, [128]),
NetworkDevice("PE2", "10.0.0.2", "iosxr", "pe", True, 2, []),
NetworkDevice("P1", "10.0.0.3", "iosxr", "p", True, 3, [128]),
NetworkDevice("P2", "10.0.0.4", "iosxr", "p", False, 0, []),
NetworkDevice("CE1", "10.0.0.5", "ios", "ce", False, 0, []),
]
for d in devices:
manager.add_device(d)
manager.print_report()
CI/CD Pipeline สำหรับ Network Changes
# === GitHub Actions — Network CI/CD Pipeline ===
# .github/workflows/network-cicd.yml
name: Network Change Pipeline
on:
pull_request:
paths: ["network/**"]
push:
branches: [main]
paths: ["network/**"]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Dependencies
run: pip install yamllint jsonschema netaddr jinja2
- name: Lint YAML
run: yamllint network/configs/
- name: Validate Schema
run: |
python -c "
import yaml, jsonschema, glob
schema = yaml.safe_load(open('network/schema.yaml'))
for f in glob.glob('network/configs/*.yaml'):
data = yaml.safe_load(open(f))
jsonschema.validate(data, schema)
print(f' OK: {f}')
print('All configs validated')
"
- name: Check Prefix-SID Conflicts
run: |
python -c "
import yaml, glob
sids = {}
for f in glob.glob('network/configs/*.yaml'):
data = yaml.safe_load(open(f))
sid = data.get('prefix_sid', 0)
host = data.get('hostname', f)
if sid in sids:
print(f'CONFLICT: SID {sid} on {host} and {sids[sid]}')
exit(1)
sids[sid] = host
print(f'No SID conflicts ({len(sids)} devices)')
"
test-in-lab:
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy to Lab
run: |
echo "Deploying to lab environment..."
# ansible-playbook -i inventory/lab deploy.yaml
- name: Run Tests
run: |
echo "Running network tests..."
# pytest tests/network/ -v
- name: Verify SR Paths
run: |
echo "Verifying Segment Routing paths..."
# python verify_sr_paths.py --env lab
deploy-production:
needs: test-in-lab
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
environment: production
steps:
- uses: actions/checkout@v4
- name: Deploy to Production
run: |
echo "Deploying to production..."
# ansible-playbook -i inventory/prod deploy.yaml --check
# ansible-playbook -i inventory/prod deploy.yaml
- name: Verify
run: |
echo "Verifying production..."
# python verify_sr_paths.py --env production
- name: Notify
run: |
echo "Network change deployed successfully"
Best Practices
- Prefix-SID Planning: วางแผน Prefix-SID Range ล่วงหน้า ใช้ Convention เช่น Node Index = Last Octet
- TI-LFA ทุก Interface: เปิด TI-LFA สำหรับ Sub-50ms Failover โดยไม่ต้อง RSVP-TE
- Flex-Algo: ใช้ Flex-Algo แยก Traffic ตาม Constraint เช่น Delay, Affinity
- IaC สำหรับ Network: เก็บ Config ทั้งหมดใน Git ใช้ Templates + Variables
- Regular Audit: ตรวจสอบ Technical Debt อย่างน้อยทุกไตรมาส
- Lab Testing: ทดสอบทุก Change ใน Lab ก่อน Deploy Production
Segment Routing คืออะไร
Network Architecture ใช้ Segments กำหนดเส้นทาง Packets Stateless ไม่ต้อง Maintain State ทุก Node มี SR-MPLS และ SRv6 ง่ายกว่า RSVP-TE Traditional MPLS
แนะนำเพิ่มเติม — คู่มือเทรดจาก SiamCafeBook
เนื้อหาเกี่ยวข้อง — Feature Store Feast Machine Learning Pipeline —





