|
| 1 | +// Copyright 2025 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +#ifndef PINS_INFRA_P4RT_APP_P4RUNTIME_UPDATE_H_ |
| 15 | +#define PINS_INFRA_P4RT_APP_P4RUNTIME_UPDATE_H_ |
| 16 | + |
| 17 | +#include <cstdint> |
| 18 | +#include <optional> |
| 19 | +#include <string> |
| 20 | + |
| 21 | +#include "p4/v1/p4runtime.pb.h" |
| 22 | +#include "p4_pdpi/entity_keys.h" |
| 23 | +#include "p4_pdpi/ir.pb.h" |
| 24 | +#include "p4rt_app/sonic/app_db_manager.h" |
| 25 | + |
| 26 | +namespace p4rt_app { |
| 27 | + |
| 28 | +// This file defines data structures for managing individual update requests |
| 29 | +// from P4. |
| 30 | + |
| 31 | +// Action profiles are used to model things like WCMP where we can have multiple |
| 32 | +// actions with different weights. Resource accounting can be measured either |
| 33 | +// against the total number of actions, or the sum total of all the action |
| 34 | +// weights. |
| 35 | +struct ActionProfileResources { |
| 36 | + std::string name; |
| 37 | + int32_t number_of_actions = 0; |
| 38 | + int64_t total_weight = 0; |
| 39 | +}; |
| 40 | + |
| 41 | +// Each table resource usually only counts as 1 (i.e. one table entry), but |
| 42 | +// depending on the table they may include an action profile (e.g. WCMP). |
| 43 | +struct TableResources { |
| 44 | + std::string name; |
| 45 | + std::optional<ActionProfileResources> action_profile; |
| 46 | +}; |
| 47 | + |
| 48 | +// This struct holds all the information needed to process a P4 update in P4RT. |
| 49 | +struct EntityUpdate { |
| 50 | + // The IR translation of the PI request. |
| 51 | + pdpi::IrEntity entry; |
| 52 | + |
| 53 | + // Specifies if this request is an INSERT MODIFY or DELETE. |
| 54 | + p4::v1::Update::Type update_type; |
| 55 | + |
| 56 | + // Normalized PI entities. Note this will be semantically the same as the |
| 57 | + // original request, but does not have to be syntactically the same. |
| 58 | + p4::v1::Entity pi_entity; |
| 59 | + |
| 60 | + // A unique hash of the entries match fields. Used to identify duplicates and |
| 61 | + // any caching of entries. |
| 62 | + pdpi::EntityKey entity_key; |
| 63 | + |
| 64 | + // The net utilization change for table entries with group actions. If the |
| 65 | + // update_type is an insert then this value will simply be the resources for |
| 66 | + // the entry. If the update_type is a modify then this value is the difference |
| 67 | + // between the new and old entries. If the update_type is a delete then this |
| 68 | + // value is the resources of the old entry. |
| 69 | + // Note: This is only relevant at the moment for tables with action profiles. |
| 70 | + TableResources resource_utilization_change; |
| 71 | + |
| 72 | + // The AppDb format of for this update. |
| 73 | + sonic::AppDbUpdate app_db_update; |
| 74 | + |
| 75 | + // A pointer to the response in the IrWriteResponse for this update. |
| 76 | + pdpi::IrUpdateStatus* status; |
| 77 | +}; |
| 78 | + |
| 79 | +} // namespace p4rt_app |
| 80 | + |
| 81 | +#endif // PINS_INFRA_P4RT_APP_P4RUNTIME_UPDATE_H_ |
0 commit comments