p4 spec v1.1 (1185620), страница 17
Текст из файла (страница 17)
. . // Reads if mtag valid; drop or copy to CPU}////////////////////////////////////////////////////////////////// identify_port table://Check if up or down facing port as programmed at run time.////////////////////////////////////////////////////////////////table identify_port {. . . // Read ingress_port; call common_set_port_type.}////////////////////////////////////////////////////////////////// Actions to copy the proper field from mtag into the egress specaction use_mtag_up1() { // This is actually never used on agg switchesmodify_field(standard_metadata.egress_spec, mtag.up1);}action use_mtag_up2() {modify_field(standard_metadata.egress_spec, mtag.up2);}action use_mtag_down1() {modify_field(standard_metadata.egress_spec, mtag.down1);}action use_mtag_down2() {modify_field(standard_metadata.egress_spec, mtag.down2);10717.6 Examples17 APPENDICES}// Table to select output spec from mtagtable select_output_port {reads {local_metadata.port_type: exact; // Up, down, level 1 or 2.}actions {use_mtag_up1;use_mtag_up2;use_mtag_down1;use_mtag_down2;// If port type is not recognized, previous policy appliedno_op;}max_size : 4; // Only need one entry per port type}////////////////////////////////////////////////////////////////// Control function definitions////////////////////////////////////////////////////////////////// The ingress control functioncontrol ingress {// Verify mTag state and port are consistentapply(check_mtag);apply(identify_port);apply(select_output_port);}// No egress function used in the mtag-agg example.The following is an example header file that might be used with the mtag exampleabove.
This shows the following:• Type definitions for port types (mtag_port_type_t) meter levels(mtag_meter_levels_t) and a table entry handle (entry_handle_t).• An example function to add an entry to the identify_port table,table_identify_port_add_with_set_port_type. The action to use with the entry is indicated at the end of the function name: set_port_type.• Functions to set the default action for the identify_port table:10817.6 Examples17 APPENDICEStable_indentify_port_default_common_drop_pkt andtable_indentify_port_default_common_set_port_type.• A function to add an entry to the mTag table:table_mTag_table_add_with_add_mTag• A function to get a counter associated with the meter table:counter_per_color_drops_get./*** Run time header file example for CCR mTag example*/#ifndef MTAG_RUN_TIME_H#define MTAG_RUN_TIME_H/*** @brief Port types required for the mtag example** Indicates the port types for both edge and aggregation* switches.*/typedef enum mtag_port_type_e {MTAG_PORT_UNKNOWN,MTAG_PORT_LOCAL,MTAG_PORT_EDGE_TO_AG1,MTAG_PORT_AG1_TO_AG2,MTAG_PORT_AG2_TO_AG1,MTAG_PORT_AG1_TO_EDGE,MTAG_PORT_ILLEGAL,/* Uninitialized port type *//* Locally switch port for edge *//* Up1: edge to agg layer 1 *//* Up2: Agg layer 1 to agg layer 2 *//* Down2: Agg layer 2 to agg layer 1 *//* Down1: Agg layer 1 to edge *//* Illegal value */MTAG_PORT_COUNT} mtag_port_type_t;/*** @brief Colors for metering** The edge switch supports metering from local ports up to the* aggregation layer.*/typedef enum mtag_meter_levels_e {10917.6 Examples17 APPENDICESMTAG_METER_COLOR_GREEN,/* No congestion indicated */MTAG_METER_COLOR_YELLOW, /* Above low water mark */MTAG_METER_COLOR_RED,/* Above high water mark */MTAG_METER_COUNT} mtag_meter_levels_t;typedef uint32_t entry_handle_t;/* mTag table *//*** @brief Add an entry to the edge identify port table* @param ingress_port The port number being identified* @param port_type The port type associated with the port* @param ingress_error The value to use for the error indication*/entry_handle_t table_identify_port_add_with_set_port_type(uint32_t ingress_port,mtag_port_type_t port_type,uint8_t ingress_error);/*** @brief Set the default action of the identify port* table to send the packet to the CPU.* @param do_copy Set to 1 if should send copy to the CPU* @param cpu_code If do_copy, this is the code used* @param bad_packet Set to 1 to flag packet as bad** This allows the programmer to say: If port type is not* set, this is an error; let me see the packet.** Also allows just a drop of the packet.*/int table_indentify_port_default_common_drop_pkt(uint8_t do_copy,uint16_t cpu_code,uint8_t bad_packet);/*** @brief Set the default action of the identify port11017.6 Examples17 APPENDICES* table to set to the given value* @param port_type The port type associated with the port* @param ingress_error The value to use for the error indication** This allows the programmer to say "default port type is local"*/int table_indentify_port_default_common_set_port_type(mtag_port_type_t port_type,uint8_t ingress_error);/*** @brief Add an entry to the add mtag table* @param dst_addr The L2 destination MAC for matching* @param vid The VLAN ID used for matching* @param up1 The up1 value to use in the mTag* @param up2 The up2 value to use in the mTag* @param down1 The down1 value to use in the mTag* @param down2 The down2 value to use in the mTag*/entry_handle_t table_mTag_table_add_with_add_mTag(mac_addr_t dst_addr, uint16_t vid,uint8_t up1, uint8_t up2, uint8_t down1, uint8_t down2);/*** @brief Get the number of drops by ingress port and color* @param ingress_port The ingress port being queried.* @param color The color being queried.* @param count (output) The current value of the parameter.* @returns 0 on success.*/int counter_per_color_drops_get(uint32_t ingress_port,mtag_meter_levels_t color,uint64_t *count);#endif /* MTAG_RUN_TIME_H */11117.6 Examples17 APPENDICES17.6.2 Adding Hysteresis to mTag Metering with RegistersIn the previous section, the mtag-edge switch used metering between local ports andthe aggregation layer.
Suppose that network simulation indicated a benefit if hysteresiscould be used with the meters. That is, once the meter was red, packets are discardeduntil the meter returned to green (not just to yellow). This can be achieved by adding aregister set parallel to the meters. Each cell in the register set holds the "previous" colorof the meter.Here are the changes to support this feature. The meter index is stored in local metadatafor convenience.//////////////////////////////////////////////////////////////////// headers.p4:Add the meter index to the local metadata.//////////////////////////////////////////////////////////////////header_type local_metadata_t {fields {bit<16> cpu_code;// Code for packet going to CPUbit<4> port_type;// Type of port: up, down, local...bit ingress_error;// An error in ingress port checkbit was_mtagged;// Track if pkt was mtagged on ingrbit copy_to_cpu;// Special code resulting in copy to CPUbit bad_packet;// Other error indicationbit<8> color;// For meteringbit<8> prev_color;// For metering hysteresisbit<16> meter_idx;// Index used for metering}}////////////////////////////////////////////////////////////////// mtag-edge.p4:Declare registers and add table to update them////////////////////////////////////////////////////////////////// The register stores the "previous" state of the color.// Index is the same as that used by the meter.register prev_color {width : 8;// paired w/ meters aboveinstance_count : PORT_COUNT * PORT_COUNT;11217.6 Examples17 APPENDICES}// Action: Update the color saved in the registeraction update_prev_color(in bit<8> new_color) {modify_field(prev_color[local_metadata.meter_idx], new_color);}// Action: Override packet color with that from the parameteraction mark_pkt(in bit<8> color) {modify_field(local_metadata.color, color);}// Update meter packet action to save dataaction meter_pkt(in int<12> meter_idx) {// Save index and previous color in packet metadatamodify_field(local_metadata.meter_idx, meter_idx);modify_field(local_metadata.prev_color, prev_color[meter_idx]);execute_meter(per_dest_by_source, meter_idx, local_metadata.color);}//// This table is statically populated with the following rules://color: green,prev_color: red==> update_prev_color(green)//color: red,prev_color: green==> update_prev_color(red)//color: yellow, prev_color: red==> mark_pkt(red)// Otherwise, no-op.//table hysteresis_check {reads {local_metadata.color : exact;local_metadata.prev_color : exact;}actions {update_prev_color;mark_pkt;no_op;}size : 4;}////////////////////////////////////////////////////////////////11317.6 Examples17 APPENDICES// In the egress control function, check for hysteresis////////////////////////////////////////////////////////////////control egress {// Check for unknown egress state or bad retagging with mTag.apply(egress_check);apply(egress_meter) {hit {apply(hysteresis_check);apply(meter_policy);}}}17.6.3 ECMP Selection ExampleThis example shows how ECMP can be implemented using an action profile with actionselector.table ipv4_routing {reads {ipv4.dstAddr: lpm;}action_profile : ecmp_action_profile;size : 16384;// 16K possible IPv4 prefixes}action_profile ecmp_action_profile {actions {nhop_set;no_op;}size : 4096;// 4K possible next hopsdynamic_action_selection : ecmp_selector;}// list of fields used to determine the ECMP next hopfield_list l3_hash_fields {ipv4.srcAddr;ipv4.dstAddr;ipv4.protocol;11417.7 Addendum for Version 1.1.017 APPENDICESipv4.protocol;tcp.sport;tcp.dport;}field_list_calculation ecmp_hash {input {l3_hash_fields;}algorithm : crc16;output_width : 16;}action_selector ecmp_selector {selection_key : ecmp_hash;}17.7 Addendum for Version 1.1.0This addendum captures some of the technical discussions going on in the P4 LanguageDesign working group, for information about possible future directions.
It does not contain any official specifications of the P4 language. The working group may or may nottake the technical ideas proposed here into a future P4 specification.17.7.1 Architecture-language separationThe current P4 specification defines the language relative to an abstract forwardingmodel with a specific architecture, as described in Section 1.1. The P4 Language Design group is working towards the separation of language features from architecturefeatures, and this addendum gives a summary preview of ideas under consideration.The aim is to ensure that the P4 language specification itself is no longer bound to a particular target architecture.