基于ODL Genius架构申请交换机表空间以实现应用共存的技术咨询
Great question! Let me break down how to properly request table space from ODL Genius for your application, so you can achieve app coexistence without relying on hardcoded table structures—since you already know the core issue is shared table space leading to interference (and that Netvirt is already using a portion of it).
1. Understand Genius' Table Resource Management
Genius uses a Table Resource Manager component to dynamically allocate and coordinate table space across all applications running on the switch. This eliminates the need for hardcoding because it handles conflict resolution and ensures each app gets a dedicated, non-overlapping set of tables.
2. Add Genius Dependencies to Your Project
First, make sure your ODL application includes the necessary Genius modules in your pom.xml to access its API:
<dependencies> <!-- Genius Core --> <dependency> <groupId>org.opendaylight.genius</groupId> <artifactId>genius-core</artifactId> <version>${genius.version}</version> </dependency> <!-- Table Resource Manager --> <dependency> <groupId>org.opendaylight.genius</groupId> <artifactId>genius-table-resource-manager</artifactId> <version>${genius.version}</version> </dependency> </dependencies>
(Replace ${genius.version} with the version matching your ODL environment.)
3. Implement the Table Space Request Logic
You’ll need to interact with Genius' TableResourceManagerService to request table space. Here’s a step-by-step implementation:
Step 3.1: Inject the Service
First, inject the TableResourceManagerService into your application component (using OSGi dependency injection or Spring, depending on your setup):
import org.opendaylight.genius.tablemanager.TableResourceManagerService; import javax.inject.Inject; public class YourAppTableManager { private final TableResourceManagerService tableResourceManagerService; @Inject public YourAppTableManager(TableResourceManagerService tableResourceManagerService) { this.tableResourceManagerService = tableResourceManagerService; } }
Step 3.2: Send a Table Resource Request
Define your application’s table needs (type, quantity) and send a request to Genius:
import org.opendaylight.genius.tablemanager.model.TableResourceRequest; import org.opendaylight.genius.tablemanager.model.TableType; import org.opendaylight.genius.tablemanager.model.TableResourceAllocation; import java.util.List; import java.util.concurrent.CompletableFuture; public void requestTableSpace() { // Build the request with your app's unique name, table type, and desired count TableResourceRequest request = TableResourceRequest.builder() .appName("your-unique-app-name") // Critical: Use a unique name to track your app's resources .tableType(TableType.L2) // Choose L2, L3, or other type based on your use case .numTables(2) // Request 2 tables (adjust based on your needs) .build(); // Send the request and handle the result asynchronously CompletableFuture<TableResourceAllocation> allocationFuture = tableResourceManagerService.allocateTableResource(request); allocationFuture.thenAccept(allocation -> { // On success, get the allocated table IDs List<Integer> allocatedTableIds = allocation.getTableIds(); // Store these IDs in your app's state for later use (e.g., in flow rules) saveAllocatedTableIds(allocatedTableIds); System.out.println("Successfully allocated tables: " + allocatedTableIds); }).exceptionally(ex -> { // Handle allocation failures (e.g., insufficient table space) System.err.println("Failed to allocate table space: " + ex.getMessage()); return null; }); }
4. Use the Allocated Table Space
Once you have the dynamically assigned table IDs, use them in your OpenFlow flow rules instead of hardcoded values. For example, when building a flow rule:
// Use one of your allocated table IDs instead of a hardcoded number like 5 FlowBuilder flowBuilder = new FlowBuilder() .setTableId(allocatedTableIds.get(0)) // ... rest of your flow rule configuration
5. Release Table Space (When Done)
It’s good practice to release table space when your application stops or no longer needs the tables. This frees up resources for other apps like Netvirt:
import org.opendaylight.genius.tablemanager.model.TableResourceDeallocationRequest; public void releaseTableSpace(List<Integer> allocatedTableIds) { TableResourceDeallocationRequest deallocRequest = TableResourceDeallocationRequest.builder() .appName("your-unique-app-name") .tableIds(allocatedTableIds) .build(); tableResourceManagerService.deallocateTableResource(deallocRequest); System.out.println("Released tables: " + allocatedTableIds); }
Key Notes to Avoid Issues
- Unique App Name: Always use a distinct application name—Genius uses this to track which tables belong to which app.
- Request Only What You Need: Don’t over-request tables; this helps keep the shared table space efficient for all apps.
- Handle Failures Gracefully: If Genius can’t allocate the requested tables (e.g., switch has no free space), implement fallback logic (like reducing the number of tables requested).
- Never Hardcode Table IDs: Stick to using the dynamically allocated IDs to avoid conflicts with other apps like Netvirt.
内容的提问来源于stack exchange,提问作者LostInTheFrequencyDomain

