-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Is your feature request related to a problem? Please describe.
Half a dozen of the functions in TdiTableManager perform specialized processing for specific meter or counter types. In each case, the function calls a method grafted into P4InfoManager to obtain the "resource type" for the object it is processing. It uses a series of if/then/else blocks (the equivalent of a switch statement) to determine what to do, based on the resource type.
This construct -- repeatedly switching on a type in order to select the processing to be done on an object -- cries out for the use of polymorphism. (See heuristic G23 in Clean Code, "Prefer Polymorphism to If/Else or Switch/Case".)
Some (if not all) of the code depends on a customized version of P4Runtime. TdiTableManager is common to all TDI targets, so all targets are subject to a dependency that may not apply to them. This is also undesirable.
Describe the solution you'd like
Proposed solution:
Processing is as follows:
TdiTableManagercreates aTdiResourceManagerand registers it withP4InfoManager.- If a
P4ResourceManageris registered,P4InfoManagerinvokes itsRegisterResource()method for each P4 object it processes. TdiResourceManagercreates a singleTdiResourceTypeinstance for each unique resource type it encounters. It stores a pointer to the object in a hash map whose key is the resource identifier.- Each method in
TdiTableManagerthat needs to perform resource-specific processing on an object callsTdiResourceManager::FindResourceTypeByID()to obtain a pointer to the associatedTdiResourceType. If the pointer is null, the method does nothing. Otherwise, it invokes the ResourceType method associated with the TableManager method. - The TableManager creates a
TdiResourceFactoryobject using aTdiTableFactory, and passes it toTdiResourceManager, allowing each target to support its own set of resource types.
Nothing in the design constrains TdiResourceManager to using the same instance of TdiResourceType for all resources in that class. If there's a compelling need to store instance-specific information, or to maintain instance-specific state, this can be implemented in TdiTableFactory with no impact on the ResourceManager.
Describe alternatives you've considered
A less general solution has been proposed to deal with the ES2K-specific packet meters. See issue #290 for details.
