# udm_api_server_demo **Repository Path**: router_gao/udm_api_server_demo ## Basic Information - **Project Name**: udm_api_server_demo - **Description**: No description available - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-07-07 - **Last Updated**: 2025-07-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # UDM API Server Demo A simple demo mobile core UDM (Unified Data Management) API server that provides subscription information for different MSISDNs. ## Features - RESTful API endpoint for UDM subscription queries - Support for multiple MSISDNs with predefined demo data stored in separate JSON files - Dynamic generation of demo data for unknown MSISDNs - Docker containerization for easy deployment - Health check endpoint - Comprehensive mobile core subscription information - Clean, modular code structure ## Project Structure ``` udm_api_server_demo/ ├── app.py # Main Flask application (simplified) ├── data_loader.py # Data loading and management module ├── data/ # MSISDN data files │ ├── 8613764010195.json # Predefined MSISDN data │ ├── 8613764010196.json # Predefined MSISDN data │ └── 8613764010197.json # Predefined MSISDN data ├── requirements.txt # Python dependencies ├── Dockerfile # Docker configuration ├── docker-compose.yml # Docker Compose configuration ├── test_api.py # Python test script ├── test.sh # Shell test script └── README.md # This file ``` ## API Endpoints ### 1. UDM Subscription Query ``` GET /service/user/UdmSubscription?number= ``` **Parameters:** - `number` (required): MSISDN number to query **Example:** ```bash curl "http://localhost:81/service/user/UdmSubscription?number=8613764010195" ``` **Response Format:** ```json { "code": 200, "message": "操作成功", "result": { "records": [ { "regUdm": "UDM007", "imsi": "460004052635798", "msisdn": "8613764010195", "gprsLock": "FALSE", "epsLock": "FALSE", // ... comprehensive subscription data } ], "total": 1, "size": 10, "current": 1, "pages": 1 } } ``` ### 2. Health Check ``` GET /health ``` Returns service health status. ### 3. Root Information ``` GET / ``` Returns API information and available endpoints. ### 4. List Available MSISDNs ``` GET /msisdns ``` Returns list of all predefined MSISDNs. ## Predefined MSISDNs The server includes demo data for the following MSISDNs (stored in separate JSON files): - `8613764010195` - Prepaid user with comprehensive services - `8613764010196` - Postpaid user with enhanced features - `8613764010197` - Prepaid user with GPRS lock For any other MSISDN, the server will generate random demo data dynamically. ## Adding New MSISDN Data You can easily add new MSISDN data by: 1. **Creating a new JSON file** in the `data/` directory: ```bash # Create data/8613764010198.json with your UDM data ``` 2. **Using the data loader programmatically**: ```python from data_loader import UDMDataLoader loader = UDMDataLoader() new_data = { "regUdm": "UDM010", "imsi": "460004052635801", "msisdn": "8613764010198", # ... other UDM fields } loader.add_msisdn_data("8613764010198", new_data) ``` ## Installation and Deployment ### Using Docker Compose (Recommended) 1. Clone the repository: ```bash git clone cd udm_api_server_demo ``` 2. Build and run with Docker Compose: ```bash docker-compose up -d ``` 3. The API server will be available at `http://localhost:81` ### Using Docker directly 1. Build the Docker image: ```bash docker build -t udm-api-server . ``` 2. Run the container: ```bash docker run -d -p 81:81 --name udm-api-server-demo udm-api-server ``` ### Local Development 1. Install Python dependencies: ```bash pip install -r requirements.txt ``` 2. Run the application: ```bash python app.py ``` The server will start on port 81. ## Testing the API ### Test with predefined MSISDNs: ```bash # Test with MSISDN 8613764010195 curl "http://localhost:81/service/user/UdmSubscription?number=8613764010195" # Test with MSISDN 8613764010196 curl "http://localhost:81/service/user/UdmSubscription?number=8613764010196" # Test with MSISDN 8613764010197 curl "http://localhost:81/service/user/UdmSubscription?number=8613764010197" ``` ### Test with random MSISDN: ```bash curl "http://localhost:81/service/user/UdmSubscription?number=8613764010198" ``` ### Health check: ```bash curl "http://localhost:81/health" ``` ### List available MSISDNs: ```bash curl "http://localhost:81/msisdns" ``` ### Using test scripts: ```bash # Python test script python test_api.py # Shell test script (requires jq) chmod +x test.sh ./test.sh ``` ## Data Structure The API returns comprehensive mobile core subscription information including: - **Basic Information**: IMSI, MSISDN, IMEI - **Service Status**: GPRS/EPS locks, telephony services - **Call Forwarding**: CFU, CFB, CFNRY, etc. - **Charging**: Prepaid/Postpaid status - **Network Configuration**: APN settings, QoS parameters - **5G Core**: AMF/SMF registration, session management - **Dynamic Data**: Current network status, registration times ## Configuration The server can be configured through environment variables: - `PORT`: Server port (default: 81) ## Logs View container logs: ```bash docker-compose logs -f udm-api-server ``` ## Stopping the Service ```bash docker-compose down ``` ## Code Architecture The application is now organized in a clean, modular structure: - **`app.py`**: Main Flask application with API endpoints (simplified from 500+ lines to ~80 lines) - **`data_loader.py`**: Handles loading MSISDN data from JSON files and generating random data - **`data/`**: Directory containing individual JSON files for each MSISDN - **Separation of concerns**: Data management is separated from API logic ## License This project is licensed under the MIT License.