feat: add packet filter management tool for GNS3-Copilot fault injection

Add comprehensive packet filter management functionality to GNS3-Copilot,
enabling AI-powered fault injection scenarios with network simulation
capabilities like latency, packet loss, and corruption.

## Changes

### New Features
- **GNS3PacketFilterTool**: New LangChain tool for managing packet filters
  on GNS3 links with support for delay, packet loss, corruption,
  frequency_drop, and BPF filtering
  - Actions: get_available, set, get, clear
  - Integrated into troubleshooting_injection mode for fault scenarios

### API Integration
- **Link.available_filters()**: Added method to custom_gns3fy.py Link class
  - Queries available filter types for specific links
  - API v3+ only (raises ValueError for v2 connectors)
  - Returns filter definitions with parameters and constraints

### Tool Integration
- Added GNS3PacketFilterTool to TROUBLESHOOTING_INJECTION_MODE_TOOLS
- Positioned as 3rd tool in fault injection workflow
- Optimized for troubleshooting practice scenarios

## Files Modified
- gns3server/agent/gns3_copilot/agent/gns3_copilot.py
- gns3server/agent/gns3_copilot/gns3_client/custom_gns3fy.py
- gns3server/agent/gns3_copilot/tools_v2/__init__.py

## Files Added
- gns3server/agent/gns3_copilot/tools_v2/gns3_packet_filter.py

## Testing
- All validation tests passed
- Version checking verified (v3+ only)
- Tool integration confirmed in troubleshooting mode
This commit is contained in:
YueGuobin committed 2026-05-24 22:31:28 +08:00
1 parent 279ea9eed3
commit 8ba1f064d2
4 files changed
+431

No files matched your search

@@ -1042,6 +1042,66 @@ class Link:
# Update object
self._update(_response.json())
@verify_connector_and_id
def available_filters(self) -> list[dict[str, Any]]:
"""
Gets the list of available packet filters for this link.
**NOTE:** This endpoint is only available in GNS3 API v3 or later.
Attempting to call this method with a v2 connector will raise an error.
**Required Attributes:**
- `project_id`
- `connector` (must be API v3 or later)
- `link_id`
**Returns:**
List of available filter types with their parameters (e.g., frequency_drop,
packet_loss, delay, corrupt, bpf).
**Example:**
```python
>>> link = Link(project_id=<pr_id>, link_id=<link_id>, connector=<connector>)
>>> filters = link.available_filters()
>>> print(filters)
[
{
"type": "frequency_drop",
"name": "Frequency drop",
"description": "It will drop everything with a -1 frequency...",
"parameters": [...]
},
...
]
```
"""
_conn = self.connector
_project_id = self.project_id
if _conn is None:
raise ValueError("Gns3Connector not assigned under 'connector'")
if _project_id is None:
raise ValueError("Need to submit project_id")
# Check API version - available_filters endpoint is only available in v3+
if not hasattr(_conn, "api_version") or _conn.api_version < 3:
raise ValueError(
"The available_filters() method requires GNS3 API v3 or later. "
f"Current connector version: v{getattr(_conn, 'api_version', 2)}. "
"Please use api_version=3 when creating the Gns3Connector."
)
_url = (
f"{_conn.base_url}/projects/{_project_id}/links/{self.link_id}/"
"available_filters"
)
_response = _conn.http_call("get", _url)
return cast(list[dict[str, Any]], _response.json())
@dataclass(config=config)
class Node: