Overview
-
This project processes network request and VLAN CSV files to generate an output file that maps requests to device ports and VLANs. It supports both redundant and non-redundant requests and assigns VLANs based on predefined rules.
-
The script reads input CSV files, sorts VLAN data, applies request logic, and writes the final results to an output CSV file.
Input Files
requests.csv
Contains request details:
request_id,redundant
1,1
2,0
request_id: Unique request identifierredundant: 1 for redundant, 0 for non-redundant
vlans.csv
Contains VLAN availability:
device_id,port,vlan_id
101,0,1001
101,1,1002
device_id: Network device identifierport: Port number (0 or 1)vlan_id: VLAN identifier
Logic Summary
- VLANs are sorted by
vlan_id - Redundant requests require two ports (0 and 1) on the same device
- Non-redundant requests use only the primary port (port 1)
- Assigned VLANs are removed from the pool once used
Output
output.csv
Generated file format:
request_id,device_id,primary_port,vlan_id
How to Run
- Ensure Python 3 is installed
- Place input files in the csv/ directory
- Run:
python main.py
Dependencies
- Python 3.x
- Standard libraries only (csv, operator, logging, time)
Notes
- Input CSV values must be integers
- The script logs errors but continues execution
- Execution time is printed after completion