## upf mp2 限速 ### mp2 限速方式概述 `mp2` 背景下,命令行下发 `appid` 和 `rule id`(已改为u32整型),在相同的 `appid` 下生成 `rule id` 列表(按优先级排序),下发 `ip`、协议号、端口号在每个 `rule id` 下去生成 `table`(流模板)和 `entry`(流特征),下发带宽参数生成 `policer` ,相同的 `rule id` 共用一个 `policer` ;匹配策略变为:边缘流量先根据 `appid` 去找 `rule id` 列表,然后根据流特征去匹配 `table` 和 `entry`,能匹配到的话去找此 `rule id` 下的 `policer`,最后确定这个报文是转发还是丢弃。 ![speed_priority](../../../_static/speed_priority.png) ### 功能设计 #### 增加的数据结构 * 增加 `table` 的 `hash` 表: 新增 `hash_flow_table_ul_by_policer_name` 这个表项,可根据`policer_name`(下发的rule id)去找到对应上行流量的 `table_index` 向量;新增`hash_flow_table_dl_by_policer_name` 这个表项,同样根据 `policer_name` 去找到下行流量的 `table_index` 向量。 * 增加 `policer` 的 `hash` 表: 新增 `hash_policer_index_by_policer_name` 这个表项,可根据`policer_name` 去找到对应的 `policer_index`,进而找到唯一的 `policer`。 * 复用 `hash_mp2_by_appid` 的 `hash` 表存储配置信息: 在 `mp2_config` 结构体中增加`bandwidth_resolve` 这个变量,来存储命令行下发的配置,通过这个 `hash` 表可查到 `mp2_config`,进而找到 `bandwidth_resolve`,即可找到这个 `appid` 下的所有配置信息。 #### 新增命令行 ``` 注:fixedBWPriority的范围是1-255,值越小优先级越高。 #新增/更新 mp2 限速命令原型 upf mec-traffic bandwidth action appName bwAllocationRuleId [ueIp ] serverIp [uePort ] [serverPort ] [protocol ] fixedAllocati allocationDirection fixedBWPriority #新增一条限速策略(配置ip段) upf mec-traffic bandwidth action add appName 1030 bwAllocationRuleId 666 ueIp 172.20.231.1/24 serverIp 192.168.2.1/24 protocol 6 fixedAllocati 700 allocationDirection 01 fixedBWPriority 2 #更新一条限速策略(配置唯一ip) upf mec-traffic bandwidth action update appName 1030 bwAllocationRuleId 666 ueIp 172.20.231.2 serverIp 192.168.2.2 protocol 6 fixedAllocati 700 allocationDirection 01 fixedBWPriority 2 #删除 mp2 限速策略原型 upf mec-traffic bandwidth action appName [bwAllocationRuleId ] #删除指定appid下的所有策略 upf mec-traffic bandwidth appName 1030 action delete_by_appName #删除指定ruld id下的策略 upf mec-traffic bandwidth appName 1030 bwAllocationRuleId 666 action delete_by_bwAllocationRuleId #显示限速策略原型 show upf mec-traffic bandwidth [appName ] #显示所有策略 show upf mec-traffic bandwidth #显示指定appid下的策略 show upf mec-traffic bandwidth appName 1030 ``` **注:配置前,需要首先配置IP五元组分流规则** #### 新增匹配限速方式 ```c /* 确定是否为边缘流量 */ if (upf_buffer_opaque (b)->upf.mec_traffic) { /* 查询这个appid下的配置信息 */ if (is_ip4 && (mp2_p = check_table_mp2(pdr->pdi.app_index, um))) { /* 去匹配这个appid下所有的所有table,命中一个即去查询policer,然后确定转发或者丢弃 */ if (check_policer_mp2(um, b, vm, mp2_p, direction)) { CPT_DROP++; next = UPF_PROCESS_NEXT_DROP; goto trace; } } } ``` ### 处理流程 ![speed_limit](../../../_static/speed_limit.png) 注:此版本不能配置端口段,需后续升级支持。