diff options
| author | songyanchao <[email protected]> | 2023-06-16 08:48:48 +0000 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2023-06-16 08:48:48 +0000 |
| commit | dbf6eb19c7736124f0c67520bc811dfe03e5f449 (patch) | |
| tree | b23ae88b6519002a5f175524733a353a576088cc | |
| parent | 7265a8d2e3a49e18b16cd0aa43d6680c6ad838a7 (diff) | |
✨ feat(DPISDN-10): Classifier rule api support ef_id and vwire_idv4.6.27-20230616
Classifier rule api support ef_id and vwire_id
| -rw-r--r-- | include/internal/mrb_define.h | 4 | ||||
| -rw-r--r-- | service/include/sc_node_common.h | 10 | ||||
| -rw-r--r-- | service/src/node_classifier.c | 448 | ||||
| -rw-r--r-- | service/src/node_etherfabric.c | 4 | ||||
| -rw-r--r-- | service/src/node_vwire.c | 8 |
5 files changed, 295 insertions, 179 deletions
diff --git a/include/internal/mrb_define.h b/include/internal/mrb_define.h index e9013f5..08533eb 100644 --- a/include/internal/mrb_define.h +++ b/include/internal/mrb_define.h @@ -23,10 +23,10 @@ struct mrb_metadata uint8_t link_id : 6; uint8_t is_ctrlbuf : 1; - uint8_t service_type : 2; + uint8_t adapter_type : 2; uint8_t un_used : 5; - uint16_t service_id; + uint16_t adapter_id; uint16_t payload_offset; uint16_t user_0; diff --git a/service/include/sc_node_common.h b/service/include/sc_node_common.h index 6c25282..cfbb04a 100644 --- a/service/include/sc_node_common.h +++ b/service/include/sc_node_common.h @@ -22,12 +22,12 @@ enum FORWARDER_TYPE_MAX }; -/* Service type */ +/* Adapter type */ enum { - SERVICE_TYPE_EF = 1, - SERVICE_TYPE_VWIRE, - SERVICE_TYPE_MAX + ADAPTER_TYPE_EF = 1, + ADAPTER_TYPE_VWIRE, + ADAPTER_TYPE_MAX }; /* Ip Version */ @@ -75,4 +75,4 @@ extern int insert_sid(struct mrb_metadata * private_ctrlzone, uint8_t nr_insert_ extern unsigned int ef_get_max_rule_num(); extern unsigned int vwire_get_max_rule_num(); extern int ef_adapter_id_check(uint32_t ef_adapter_id); -extern int vwire_service_id_check(uint32_t vwire_service_id); +extern int vwire_adapter_id_check(uint32_t vwire_adapter_id); diff --git a/service/src/node_classifier.c b/service/src/node_classifier.c index ee57751..4270ef7 100644 --- a/service/src/node_classifier.c +++ b/service/src/node_classifier.c @@ -71,6 +71,8 @@ #define MR_CLASSIFIER_CJSON_KEY_PRIORITY "Priority" #define MR_CLASSIFIER_CJSON_KEY_CATEGORY "Category" #define MR_CLASSIFIER_CJSON_KEY_SID "Sid" +#define MR_CLASSIFIER_CJSON_KEY_VWIRE_ID "VwireId" +#define MR_CLASSIFIER_CJSON_KEY_EF_ID "EfId" #define CLASSIFIER_STAT_ADD(st, graph_id, counter, value) \ do \ @@ -100,12 +102,12 @@ enum CLASSIFIER_TABLE_TYPE_MAX }; -/* Table service type */ +/* Table adapter type */ enum { - CLASSIFIER_TABLE_SERVICE_EF = 0, - CLASSIFIER_TABLE_SERVICE_VWIRE, - CLASSIFIER_TABLE_SERVICE_MAX + CLASSIFIER_TABLE_ADAPTER_EF = 0, + CLASSIFIER_TABLE_ADAPTER_VWIRE, + CLASSIFIER_TABLE_ADAPTER_MAX }; /* IPv4 field index enum */ @@ -202,6 +204,9 @@ enum CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V6, CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V4, CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V6, + CLASSIFIER_RULE_ADD_ERR_VWIRE_AND_EF_ID_CONFICT, + CLASSIFIER_RULE_ADD_ERR_EF_ID_INVALID, + CLASSIFIER_RULE_ADD_ERR_VWIRE_ID_INVALID, }; /* Rule parse */ @@ -609,8 +614,8 @@ static __rte_always_inline uint16_t classifier_node_process(struct rte_graph * g /* Initialization is required */ uint8_t nr_sid = 0; struct classifier_stat stat = {}; - uint8_t service_type = 0; - uint16_t service_id = 0xffff; + uint8_t adapter_type = 0; + uint16_t adapter_id = 0xffff; uint16_t fast_match = 0; /* Single packet processing */ @@ -624,20 +629,20 @@ static __rte_always_inline uint16_t classifier_node_process(struct rte_graph * g struct mrb_metadata * mrb_metadata = mrbuf_cz_data(mbuf0, MR_NODE_CTRLZONE_ID); struct pkt_parser_result * _pkt_parser_result = &mrb_metadata->pkt_parser_result; - if ((service_type != mrb_metadata->service_type) || (service_id != mrb_metadata->service_id)) + if ((adapter_type != mrb_metadata->adapter_type) || (adapter_id != mrb_metadata->adapter_id)) { - switch (mrb_metadata->service_type) + switch (mrb_metadata->adapter_type) { - case SERVICE_TYPE_EF: - service_type = SERVICE_TYPE_EF; - service_id = mrb_metadata->service_id; - _classifier_table = __ef_table[mrb_metadata->service_id]; + case ADAPTER_TYPE_EF: + adapter_type = ADAPTER_TYPE_EF; + adapter_id = mrb_metadata->adapter_id; + _classifier_table = __ef_table[mrb_metadata->adapter_id]; fast_match = _classifier_table->fast_match; break; - case SERVICE_TYPE_VWIRE: - service_type = SERVICE_TYPE_VWIRE; - service_id = mrb_metadata->service_id; - _classifier_table = __vwire_table[mrb_metadata->service_id]; + case ADAPTER_TYPE_VWIRE: + adapter_type = ADAPTER_TYPE_VWIRE; + adapter_id = mrb_metadata->adapter_id; + _classifier_table = __vwire_table[mrb_metadata->adapter_id]; fast_match = _classifier_table->fast_match; break; default: @@ -930,28 +935,28 @@ int classifier_rule_check_v6(struct classifier_table_entity * _table_v6, struct return RT_SUCCESS; } -/* Add rule for service id */ -int add_rule_for_service_id(struct classifier_management * _classifier_management, char * _str_rule_name, - struct rule_parse * _rule_parse, uint32_t service_id, uint8_t service_type) +/* Add rule for adapter id */ +int add_rule_for_adapter_id(struct classifier_management * _classifier_management, char * _str_rule_name, + struct rule_parse * _rule_parse, uint32_t adapter_id, uint8_t adapter_type) { struct classifier_table * _classifier_table = NULL; - switch (service_type) + switch (adapter_type) { - case CLASSIFIER_TABLE_SERVICE_EF: - _classifier_table = _classifier_management->__ef_table[service_id]; + case CLASSIFIER_TABLE_ADAPTER_EF: + _classifier_table = _classifier_management->__ef_table[adapter_id]; break; - case CLASSIFIER_TABLE_SERVICE_VWIRE: - _classifier_table = _classifier_management->__vwire_table[service_id]; + case CLASSIFIER_TABLE_ADAPTER_VWIRE: + _classifier_table = _classifier_management->__vwire_table[adapter_id]; break; } if (_classifier_table == NULL) { MR_ERROR( - "The classifier rule name: %s, service type: %u, service id: %u, rule id: %u,the classifier table is null.", - _str_rule_name, service_type, service_id, _rule_parse->rule_id); + "The classifier rule name: %s, adapter type: %u, adapter id: %u, rule id: %u,the classifier table is null.", + _str_rule_name, adapter_type, adapter_id, _rule_parse->rule_id); return CLASSIFIER_RULE_ADD_ERR_TABLE_IS_NULL; } @@ -964,9 +969,9 @@ int add_rule_for_service_id(struct classifier_management * _classifier_managemen uint32_t rule_item_id = get_free_rule_item_id(_table_v4->classifier_action_v4); if (rule_item_id == MR_CLASSIFIER_RULE_INVALID_FLAG) { - MR_ERROR("The classifier rule name: %s, service type: %u, service id: %u, rule id: %u, no free ipv4 rule " + MR_ERROR("The classifier rule name: %s, adapter type: %u, adapter id: %u, rule id: %u, no free ipv4 rule " "Item . ", - _str_rule_name, service_type, service_id, _rule_parse->rule_id); + _str_rule_name, adapter_type, adapter_id, _rule_parse->rule_id); return CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V4; } @@ -1003,9 +1008,9 @@ int add_rule_for_service_id(struct classifier_management * _classifier_managemen if (classifier_rule_check_v4(_table_v4, rule, action) == RT_ERR) { MR_ERROR( - "The classifier rule name: %s, service type: %u, service id: %u, rule id: %u, the ipv4 rule already " + "The classifier rule name: %s, adapter type: %u, adapter id: %u, rule id: %u, the ipv4 rule already " "exists .", - _str_rule_name, service_type, service_id, _rule_parse->rule_id); + _str_rule_name, adapter_type, adapter_id, _rule_parse->rule_id); return CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V4; } @@ -1023,9 +1028,9 @@ int add_rule_for_service_id(struct classifier_management * _classifier_managemen int32_t rule_item_id = get_free_rule_item_id(_table_v6->classifier_action_v6); if (rule_item_id == MR_CLASSIFIER_RULE_INVALID_FLAG) { - MR_ERROR("The classifier rule name: %s, service type: %u, service id: %u, rule id: %u, no free ipv6 rule " + MR_ERROR("The classifier rule name: %s, adapter type: %u, adapter id: %u, rule id: %u, no free ipv6 rule " "Item . ", - _str_rule_name, service_type, service_id, _rule_parse->rule_id); + _str_rule_name, adapter_type, adapter_id, _rule_parse->rule_id); return CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V6; } @@ -1084,9 +1089,9 @@ int add_rule_for_service_id(struct classifier_management * _classifier_managemen if (classifier_rule_check_v6(_table_v6, rule, action) == RT_ERR) { MR_ERROR( - "The classifier rule name: %s, service type: %u, service id: %u, rule id: %u, the ipv6 rule already " + "The classifier rule name: %s, adapter type: %u, adapter id: %u, rule id: %u, the ipv6 rule already " "exists .", - _str_rule_name, service_type, service_id, _rule_parse->rule_id); + _str_rule_name, adapter_type, adapter_id, _rule_parse->rule_id); return CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V6; } @@ -1122,12 +1127,12 @@ struct classifier_management * create_classifier_management() } /* Malloc vwire table */ - for (uint32_t vwire_service_id = 0; vwire_service_id < nr_vwire_tables; vwire_service_id++) + for (uint32_t vwire_adapter_id = 0; vwire_adapter_id < nr_vwire_tables; vwire_adapter_id++) { - if (vwire_service_id_check(vwire_service_id) == RT_ERR) + if (vwire_adapter_id_check(vwire_adapter_id) == RT_ERR) continue; - _classifier_management->__vwire_table[vwire_service_id] = ZMALLOC(sizeof(struct classifier_table)); - MR_VERIFY_MALLOC(_classifier_management->__vwire_table[vwire_service_id]); + _classifier_management->__vwire_table[vwire_adapter_id] = ZMALLOC(sizeof(struct classifier_table)); + MR_VERIFY_MALLOC(_classifier_management->__vwire_table[vwire_adapter_id]); } return _classifier_management; } @@ -1135,9 +1140,9 @@ struct classifier_management * create_classifier_management() /* Free management */ void free_classifier_management(struct classifier_management * _classifier_management) { - for (uint32_t service_id = 0; service_id < _classifier_management->nr_ef_tables; service_id++) + for (uint32_t adapter_id = 0; adapter_id < _classifier_management->nr_ef_tables; adapter_id++) { - struct classifier_table * _ef_table = _classifier_management->__ef_table[service_id]; + struct classifier_table * _ef_table = _classifier_management->__ef_table[adapter_id]; if (_ef_table == NULL) continue; /* Free acx */ @@ -1148,9 +1153,9 @@ void free_classifier_management(struct classifier_management * _classifier_manag FREE(_ef_table); } - for (uint32_t service_id = 0; service_id < _classifier_management->nr_vwire_tables; service_id++) + for (uint32_t adapter_id = 0; adapter_id < _classifier_management->nr_vwire_tables; adapter_id++) { - struct classifier_table * _vwire_table = _classifier_management->__vwire_table[service_id]; + struct classifier_table * _vwire_table = _classifier_management->__vwire_table[adapter_id]; if (_vwire_table == NULL) continue; /* Free acx */ @@ -1182,8 +1187,8 @@ int get_category(uint32_t category_mask) } /* Dump single ipv4 classifier rule */ -void dump_classifier_rule_v4(struct classifier_rule_v4 * rule, struct classifier_action * action, char * _service_type, - uint32_t service_id) +void dump_classifier_rule_v4(struct classifier_rule_v4 * rule, struct classifier_action * action, char * _adapter_type, + uint32_t adapter_id) { char str_rule_info[2048] = {}; struct in_addr src_addr, dst_addr; @@ -1191,8 +1196,8 @@ void dump_classifier_rule_v4(struct classifier_rule_v4 * rule, struct classifier dst_addr.s_addr = htonl(rule->field[CLASSIFIER_IPV4_FIELD_DST_IP].value.u32); int len = 0; - len = snprintf(str_rule_info, sizeof(str_rule_info), "Classifier %s:%u, ipv4 rule, id=%u", _service_type, - service_id, action->rule_id); + len = snprintf(str_rule_info, sizeof(str_rule_info), "Classifier %s:%u, ipv4 rule, id=%u", _adapter_type, + adapter_id, action->rule_id); len += snprintf(str_rule_info + len, sizeof(str_rule_info) - len - len, ", item_index=%u", rule->data.userdata); len += snprintf(str_rule_info + len, sizeof(str_rule_info) - len - len, ", priority=%u", rule->data.priority); len += snprintf(str_rule_info + len, sizeof(str_rule_info) - len - len, ", category=%u", @@ -1226,14 +1231,14 @@ void dump_classifier_rule_v4(struct classifier_rule_v4 * rule, struct classifier } /* Dump single ipv6 classifier rule */ -void dump_classifier_rule_v6(struct classifier_rule_v6 * rule, struct classifier_action * action, char * _service_type, - uint32_t service_id) +void dump_classifier_rule_v6(struct classifier_rule_v6 * rule, struct classifier_action * action, char * _adapter_type, + uint32_t adapter_id) { char str_rule_info[2048] = {}; int len = 0; - len = snprintf(str_rule_info, sizeof(str_rule_info), "Classifier %s:%u, ipv6 rule, id=%u", _service_type, - service_id, action->rule_id); + len = snprintf(str_rule_info, sizeof(str_rule_info), "Classifier %s:%u, ipv6 rule, id=%u", _adapter_type, + adapter_id, action->rule_id); len += snprintf(str_rule_info + len, sizeof(str_rule_info) - len, ", item_index=%u", rule->data.userdata); len += snprintf(str_rule_info + len, sizeof(str_rule_info) - len, ", priority=%u", rule->data.priority); len += snprintf(str_rule_info + len, sizeof(str_rule_info) - len, ", category=%u", @@ -1359,7 +1364,7 @@ void check_fast_match_condition(struct classifier_table * _table) void classifier_fast_match_check(struct classifier_management * _classifier_management) { - /* Check all table for ef service */ + /* Check all table for ef adapter */ for (uint32_t ef_adapter_id = 0; ef_adapter_id < _classifier_management->nr_ef_tables; ef_adapter_id++) { struct classifier_table * _ef_table = _classifier_management->__ef_table[ef_adapter_id]; @@ -1368,10 +1373,10 @@ void classifier_fast_match_check(struct classifier_management * _classifier_mana check_fast_match_condition(_ef_table); } - /* Check all table forvwire service */ - for (uint32_t vwire_service_id = 0; vwire_service_id < _classifier_management->nr_ef_tables; vwire_service_id++) + /* Check all table forvwire adapter */ + for (uint32_t vwire_adapter_id = 0; vwire_adapter_id < _classifier_management->nr_ef_tables; vwire_adapter_id++) { - struct classifier_table * _vwire_table = _classifier_management->__vwire_table[vwire_service_id]; + struct classifier_table * _vwire_table = _classifier_management->__vwire_table[vwire_adapter_id]; if (_vwire_table == NULL) continue; check_fast_match_condition(_vwire_table); @@ -1381,9 +1386,9 @@ void classifier_fast_match_check(struct classifier_management * _classifier_mana /* Dump all classifier rule table */ void dump_classifier_tables(struct classifier_management * _classifier_management) { - for (uint32_t service_id = 0; service_id < _classifier_management->nr_ef_tables; service_id++) + for (uint32_t adapter_id = 0; adapter_id < _classifier_management->nr_ef_tables; adapter_id++) { - struct classifier_table * _ef_table = _classifier_management->__ef_table[service_id]; + struct classifier_table * _ef_table = _classifier_management->__ef_table[adapter_id]; if (_ef_table == NULL) continue; @@ -1392,7 +1397,7 @@ void dump_classifier_tables(struct classifier_management * _classifier_managemen { if (_table_v4->classifier_action_v4[i].rule_id != MR_CLASSIFIER_RULE_INVALID_FLAG) dump_classifier_rule_v4(&_table_v4->classifier_rules_v4[i], &_table_v4->classifier_action_v4[i], "ef", - service_id); + adapter_id); } struct classifier_table_entity * _table_v6 = &_ef_table->table[CLASSIFIER_TABLE_TYPE_V6]; @@ -1400,13 +1405,13 @@ void dump_classifier_tables(struct classifier_management * _classifier_managemen { if (_table_v6->classifier_action_v6[i].rule_id != MR_CLASSIFIER_RULE_INVALID_FLAG) dump_classifier_rule_v6(&_table_v6->classifier_rules_v6[i], &_table_v6->classifier_action_v6[i], "ef", - service_id); + adapter_id); } } - for (uint32_t service_id = 0; service_id < _classifier_management->nr_vwire_tables; service_id++) + for (uint32_t adapter_id = 0; adapter_id < _classifier_management->nr_vwire_tables; adapter_id++) { - struct classifier_table * _vwire_table = _classifier_management->__vwire_table[service_id]; + struct classifier_table * _vwire_table = _classifier_management->__vwire_table[adapter_id]; if (_vwire_table == NULL) continue; @@ -1415,7 +1420,7 @@ void dump_classifier_tables(struct classifier_management * _classifier_managemen { if (_table_v4->classifier_action_v4[i].rule_id != MR_CLASSIFIER_RULE_INVALID_FLAG) dump_classifier_rule_v4(&_table_v4->classifier_rules_v4[i], &_table_v4->classifier_action_v4[i], - "vwire", service_id); + "vwire", adapter_id); } struct classifier_table_entity * _table_v6 = &_vwire_table->table[CLASSIFIER_TABLE_TYPE_V6]; @@ -1423,7 +1428,7 @@ void dump_classifier_tables(struct classifier_management * _classifier_managemen { if (_table_v6->classifier_action_v6[i].rule_id != MR_CLASSIFIER_RULE_INVALID_FLAG) dump_classifier_rule_v6(&_table_v6->classifier_rules_v6[i], &_table_v6->classifier_action_v6[i], - "vwire", service_id); + "vwire", adapter_id); } } } @@ -1526,7 +1531,7 @@ setup_err: } /* Setup classifier table */ -int setup_classifier_table_for_service(struct classifier_table * _ef_table, char * _str_service, uint32_t service_id, +int setup_classifier_table_for_adapter(struct classifier_table * _ef_table, char * _str_adapter, uint32_t adapter_id, uint8_t table_name_flg) { /* Get table name */ @@ -1534,16 +1539,16 @@ int setup_classifier_table_for_service(struct classifier_table * _ef_table, char char table_name_v6[MR_STRING_MAX] = {}; if (table_name_flg == CLASSIFIER_TABLE_A) { - snprintf(table_name_v4, sizeof(table_name_v4), "classifier-%s-%u-%s", _str_service, service_id, + snprintf(table_name_v4, sizeof(table_name_v4), "classifier-%s-%u-%s", _str_adapter, adapter_id, MR_CLASSIFIER_IPV4_TABLE_NAME_A); - snprintf(table_name_v6, sizeof(table_name_v6), "classifier-%s-%u-%s", _str_service, service_id, + snprintf(table_name_v6, sizeof(table_name_v6), "classifier-%s-%u-%s", _str_adapter, adapter_id, MR_CLASSIFIER_IPV6_TABLE_NAME_A); } else { - snprintf(table_name_v4, sizeof(table_name_v4), "classifier-%s-%u-%s", _str_service, service_id, + snprintf(table_name_v4, sizeof(table_name_v4), "classifier-%s-%u-%s", _str_adapter, adapter_id, MR_CLASSIFIER_IPV4_TABLE_NAME_B); - snprintf(table_name_v6, sizeof(table_name_v6), "classifier-%s-%u-%s", _str_service, service_id, + snprintf(table_name_v6, sizeof(table_name_v6), "classifier-%s-%u-%s", _str_adapter, adapter_id, MR_CLASSIFIER_IPV6_TABLE_NAME_B); } @@ -1575,23 +1580,23 @@ int setup_classifier_table_for_service(struct classifier_table * _ef_table, char int setup_all_classifier_table(struct classifier_management * _classifier_management) { - /* Setup all classifier table for ef service */ + /* Setup all classifier table for ef adapter */ for (uint32_t ef_adapter_id = 0; ef_adapter_id < _classifier_management->nr_ef_tables; ef_adapter_id++) { struct classifier_table * _ef_table = _classifier_management->__ef_table[ef_adapter_id]; if (_ef_table == NULL) continue; - if (setup_classifier_table_for_service(_ef_table, "ef", ef_adapter_id, table_name_flg) == RT_ERR) + if (setup_classifier_table_for_adapter(_ef_table, "ef", ef_adapter_id, table_name_flg) == RT_ERR) return RT_ERR; } - /* Setup all classifier table for vwire service */ - for (uint32_t vwire_service_id = 0; vwire_service_id < _classifier_management->nr_ef_tables; vwire_service_id++) + /* Setup all classifier table for vwire adapter */ + for (uint32_t vwire_adapter_id = 0; vwire_adapter_id < _classifier_management->nr_ef_tables; vwire_adapter_id++) { - struct classifier_table * _vwire_table = _classifier_management->__vwire_table[vwire_service_id]; + struct classifier_table * _vwire_table = _classifier_management->__vwire_table[vwire_adapter_id]; if (_vwire_table == NULL) continue; - if (setup_classifier_table_for_service(_vwire_table, "vwire", vwire_service_id, table_name_flg) == RT_ERR) + if (setup_classifier_table_for_adapter(_vwire_table, "vwire", vwire_adapter_id, table_name_flg) == RT_ERR) return RT_ERR; } @@ -1667,6 +1672,10 @@ int parse_classifier_rule_remote(struct classifier_management * _classifier_mana cJSON * cj_category = cJSON_GetObjectItem(c_rule, MR_CLASSIFIER_CJSON_KEY_CATEGORY); /* Sid */ cJSON * cj_sid = cJSON_GetObjectItem(c_rule, MR_CLASSIFIER_CJSON_KEY_SID); + /* Vwire id */ + cJSON * cj_vwire_id = cJSON_GetObjectItem(c_rule, MR_CLASSIFIER_CJSON_KEY_VWIRE_ID); + /* Ef id */ + cJSON * cj_ef_id = cJSON_GetObjectItem(c_rule, MR_CLASSIFIER_CJSON_KEY_EF_ID); /* Check necessary rule field: rule id */ if (cj_rule_id == NULL) @@ -1697,6 +1706,46 @@ int parse_classifier_rule_remote(struct classifier_management * _classifier_mana return CLASSIFIER_RULE_ADD_SID_INVALID; } + /* Check ef id and vwire id */ + if ((cj_vwire_id != NULL) && (cj_ef_id != NULL)) + { + snprintf(_str_error_reason, sz_error_reason, + "Classifier rule add error,rule id '%u','ef_id' and 'vwire_id' only one can be configured .", + rule_parse.rule_id); + MR_ERROR("%s", _str_error_reason); + return CLASSIFIER_RULE_ADD_ERR_VWIRE_AND_EF_ID_CONFICT; + } + + /* Check ef id */ + uint32_t ef_adapter_id = 0xFFFFFFFF; + if (cj_ef_id != NULL) + { + ef_adapter_id = cj_ef_id->valuedouble; + if (ef_adapter_id_check(ef_adapter_id) == RT_ERR) + { + snprintf(_str_error_reason, sz_error_reason, + "Classifier rule add error,rule id '%u','ef_id = %u' is invalid.", rule_parse.rule_id, + ef_adapter_id); + MR_ERROR("%s", _str_error_reason); + return CLASSIFIER_RULE_ADD_ERR_EF_ID_INVALID; + } + } + + /* Check vwire id */ + uint32_t vwire_adapter_id = 0xFFFFFFFF; + if (cj_vwire_id != NULL) + { + vwire_adapter_id = cj_vwire_id->valuedouble; + if (vwire_adapter_id_check(vwire_adapter_id) == RT_ERR) + { + snprintf(_str_error_reason, sz_error_reason, + "Classifier rule add error,rule id '%u','vwire_id = %u' is invalid.", rule_parse.rule_id, + vwire_adapter_id); + MR_ERROR("%s", _str_error_reason); + return CLASSIFIER_RULE_ADD_ERR_VWIRE_ID_INVALID; + } + } + /* Save the category */ rule_parse.category = (uint16_t)cj_category->valuedouble; @@ -1987,73 +2036,140 @@ int parse_classifier_rule_remote(struct classifier_management * _classifier_mana return CLASSIFIER_RULE_ADD_SID_INVALID; } - /* Add the rule for all table */ - /* Add the rule for all ef tables */ - for (uint32_t service_id = 0; service_id < _classifier_management->nr_ef_tables; service_id++) + // ############################################################################ + /* Add the rule fo ef tables */ + if (cj_ef_id != NULL) { - if (ef_adapter_id_check(service_id) == RT_ERR) - continue; - /* Fill The rule field for service id */ - int ret = add_rule_for_service_id(_classifier_management, "remote full update", &rule_parse, service_id, - CLASSIFIER_TABLE_SERVICE_EF); - if (ret == CLASSIFIER_RULE_ADD_SUCCESS) - continue; - int len = snprintf(_str_error_reason, sz_error_reason, - "Classifier rule add error, service_type:ef, service_id:%u, rule_id:%u", service_id, - rule_parse.rule_id); - switch (ret) + /* Fill The rule field for adapter id */ + int ret = add_rule_for_adapter_id(_classifier_management, "remote full update", &rule_parse, ef_adapter_id, + CLASSIFIER_TABLE_ADAPTER_EF); + if (ret != CLASSIFIER_RULE_ADD_SUCCESS) { - case CLASSIFIER_RULE_ADD_ERR_TABLE_IS_NULL: - snprintf(_str_error_reason + len, sz_error_reason - len, ",the classifier table is null."); - break; - case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V4: - snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 table already full ."); - break; - case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V6: - snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 table already full ."); - break; - case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V4: - snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 rule already exists ."); - break; - case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V6: - snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 rule already exists ."); - break; + int len = snprintf(_str_error_reason, sz_error_reason, + "Classifier rule add error, adapter_type:ef, adapter_id:%u, rule_id:%u", ef_adapter_id, + rule_parse.rule_id); + switch (ret) + { + case CLASSIFIER_RULE_ADD_ERR_TABLE_IS_NULL: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the classifier table is null."); + break; + case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V4: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 table already full ."); + break; + case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V6: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 table already full ."); + break; + case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V4: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 rule already exists ."); + break; + case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V6: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 rule already exists ."); + break; + } + return ret; } - return ret; } - - /* Add the rule for all vwire tables */ - for (uint32_t service_id = 0; service_id < _classifier_management->nr_vwire_tables; service_id++) + else if (cj_vwire_id != NULL) { - if (vwire_service_id_check(service_id) == RT_ERR) - continue; - /* Fill The rule field for service id */ - int ret = add_rule_for_service_id(_classifier_management, "remote full update", &rule_parse, service_id, - CLASSIFIER_TABLE_SERVICE_VWIRE); - if (ret == CLASSIFIER_RULE_ADD_SUCCESS) - continue; - int len = snprintf(_str_error_reason, sz_error_reason, - "Classifier rule add error, service_type:vwire, service_id:%u, rule_id:%u", service_id, - rule_parse.rule_id); - switch (ret) + /* Fill The rule field for adapter id */ + int ret = add_rule_for_adapter_id(_classifier_management, "remote full update", &rule_parse, vwire_adapter_id, + CLASSIFIER_TABLE_ADAPTER_VWIRE); + if (ret != CLASSIFIER_RULE_ADD_SUCCESS) { - case CLASSIFIER_RULE_ADD_ERR_TABLE_IS_NULL: - snprintf(_str_error_reason + len, sz_error_reason - len, ",the classifier table is null."); - break; - case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V4: - snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 table already full ."); - break; - case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V6: - snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 table already full ."); - break; - case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V4: - snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 rule already exists ."); - break; - case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V6: - snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 rule already exists ."); - break; + int len = snprintf(_str_error_reason, sz_error_reason, + "Classifier rule add error, adapter_type:vwire, adapter_id:%u, rule_id:%u", + vwire_adapter_id, rule_parse.rule_id); + switch (ret) + { + case CLASSIFIER_RULE_ADD_ERR_TABLE_IS_NULL: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the classifier table is null."); + break; + case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V4: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 table already full ."); + break; + case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V6: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 table already full ."); + break; + case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V4: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 rule already exists ."); + break; + case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V6: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 rule already exists ."); + break; + } + return ret; + } + } + else + { + /* Add the rule for all table */ + /* Add the rule for all ef tables */ + for (uint32_t adapter_id = 0; adapter_id < _classifier_management->nr_ef_tables; adapter_id++) + { + if (ef_adapter_id_check(adapter_id) == RT_ERR) + continue; + /* Fill The rule field for adapter id */ + int ret = add_rule_for_adapter_id(_classifier_management, "remote full update", &rule_parse, adapter_id, + CLASSIFIER_TABLE_ADAPTER_EF); + if (ret == CLASSIFIER_RULE_ADD_SUCCESS) + continue; + int len = snprintf(_str_error_reason, sz_error_reason, + "Classifier rule add error, adapter_type:ef, adapter_id:%u, rule_id:%u", adapter_id, + rule_parse.rule_id); + switch (ret) + { + case CLASSIFIER_RULE_ADD_ERR_TABLE_IS_NULL: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the classifier table is null."); + break; + case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V4: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 table already full ."); + break; + case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V6: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 table already full ."); + break; + case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V4: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 rule already exists ."); + break; + case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V6: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 rule already exists ."); + break; + } + return ret; + } + + /* Add the rule for all vwire tables */ + for (uint32_t adapter_id = 0; adapter_id < _classifier_management->nr_vwire_tables; adapter_id++) + { + if (vwire_adapter_id_check(adapter_id) == RT_ERR) + continue; + /* Fill The rule field for adapter id */ + int ret = add_rule_for_adapter_id(_classifier_management, "remote full update", &rule_parse, adapter_id, + CLASSIFIER_TABLE_ADAPTER_VWIRE); + if (ret == CLASSIFIER_RULE_ADD_SUCCESS) + continue; + int len = snprintf(_str_error_reason, sz_error_reason, + "Classifier rule add error, adapter_type:vwire, adapter_id:%u, rule_id:%u", adapter_id, + rule_parse.rule_id); + switch (ret) + { + case CLASSIFIER_RULE_ADD_ERR_TABLE_IS_NULL: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the classifier table is null."); + break; + case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V4: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 table already full ."); + break; + case CLASSIFIER_RULE_ADD_ERR_NO_FREE_RULE_ITEM_V6: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 table already full ."); + break; + case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V4: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv4 rule already exists ."); + break; + case CLASSIFIER_RULE_ADD_ERR_ALREADY_EXISTS_V6: + snprintf(_str_error_reason + len, sz_error_reason - len, ",the ipv6 rule already exists ."); + break; + } + return ret; } - return ret; } return CLASSIFIER_RULE_ADD_SUCCESS; @@ -2471,22 +2587,22 @@ int parser_classifier_rule_local(struct sc_main * sc, struct classifier_manageme } rule_parse.category = (uint16_t)category; - /* Get etherfabric service id */ + /* Get etherfabric adapter id */ uint32_t ef_adapter_id = 0xFFFFFFFF; - int ef_service_ret = MESA_load_profile_uint_nodef(sc->local_cfgfile, str_section, "ef_id", &ef_adapter_id); + int ef_adapter_ret = MESA_load_profile_uint_nodef(sc->local_cfgfile, str_section, "ef_id", &ef_adapter_id); - /* Get etherfabric service id */ - uint32_t vwire_service_id = 0xFFFFFFFF; - int vwire_service_ret = - MESA_load_profile_uint_nodef(sc->local_cfgfile, str_section, "vwire_id", &vwire_service_id); - if ((ef_service_ret >= 0) && (vwire_service_ret >= 0)) + /* Get etherfabric adapter id */ + uint32_t vwire_adapter_id = 0xFFFFFFFF; + int vwire_adapter_ret = + MESA_load_profile_uint_nodef(sc->local_cfgfile, str_section, "vwire_id", &vwire_adapter_id); + if ((ef_adapter_ret >= 0) && (vwire_adapter_ret >= 0)) { - MR_ERROR("The classifier rule name : %s ,'ef_adapter_id' and 'vwire_service_id' only one can be configured", + MR_ERROR("The classifier rule name : %s ,'ef_adapter_id' and 'vwire_adapter_id' only one can be configured", str_section); return RT_ERR; } - if (ef_service_ret >= 0) + if (ef_adapter_ret >= 0) { if (ef_adapter_id_check(ef_adapter_id) == RT_ERR) { @@ -2494,27 +2610,27 @@ int parser_classifier_rule_local(struct sc_main * sc, struct classifier_manageme return RT_ERR; } - /* Fill The rule field for service id */ - int ret = add_rule_for_service_id(_classifier_management, str_section, &rule_parse, ef_adapter_id, - CLASSIFIER_TABLE_SERVICE_EF); + /* Fill The rule field for adapter id */ + int ret = add_rule_for_adapter_id(_classifier_management, str_section, &rule_parse, ef_adapter_id, + CLASSIFIER_TABLE_ADAPTER_EF); if (ret != CLASSIFIER_RULE_ADD_SUCCESS) { MR_ERROR("The classifier rule name : %s ,add rule err.", str_section); return RT_ERR; } } - else if (vwire_service_ret >= 0) + else if (vwire_adapter_ret >= 0) { - if (vwire_service_id_check(vwire_service_id) == RT_ERR) + if (vwire_adapter_id_check(vwire_adapter_id) == RT_ERR) { - MR_ERROR("The classifier rule name : %s ,vwire_service_id = %u is invalid.", str_section, - vwire_service_id); + MR_ERROR("The classifier rule name : %s ,vwire_adapter_id = %u is invalid.", str_section, + vwire_adapter_id); return RT_ERR; } - /* Fill The rule field for service id */ - int ret = add_rule_for_service_id(_classifier_management, str_section, &rule_parse, vwire_service_id, - CLASSIFIER_TABLE_SERVICE_VWIRE); + /* Fill The rule field for adapter id */ + int ret = add_rule_for_adapter_id(_classifier_management, str_section, &rule_parse, vwire_adapter_id, + CLASSIFIER_TABLE_ADAPTER_VWIRE); if (ret != CLASSIFIER_RULE_ADD_SUCCESS) { MR_ERROR("The classifier rule name : %s ,add rule err.", str_section); @@ -2525,33 +2641,33 @@ int parser_classifier_rule_local(struct sc_main * sc, struct classifier_manageme { /* Add the rule for all table */ /* Add the rule for all ef tables */ - for (uint32_t service_id = 0; service_id < _classifier_management->nr_ef_tables; service_id++) + for (uint32_t adapter_id = 0; adapter_id < _classifier_management->nr_ef_tables; adapter_id++) { - if (ef_adapter_id_check(service_id) == RT_ERR) + if (ef_adapter_id_check(adapter_id) == RT_ERR) continue; - /* Fill The rule field for service id */ - int ret = add_rule_for_service_id(_classifier_management, str_section, &rule_parse, service_id, - CLASSIFIER_TABLE_SERVICE_EF); + /* Fill The rule field for adapter id */ + int ret = add_rule_for_adapter_id(_classifier_management, str_section, &rule_parse, adapter_id, + CLASSIFIER_TABLE_ADAPTER_EF); if (ret != CLASSIFIER_RULE_ADD_SUCCESS) { - MR_ERROR("The classifier rule name : %s,service type is:%u, service id is :%u, add rule err.", - str_section, CLASSIFIER_TABLE_SERVICE_EF, service_id); + MR_ERROR("The classifier rule name : %s,adapter type is:%u, adapter id is :%u, add rule err.", + str_section, CLASSIFIER_TABLE_ADAPTER_EF, adapter_id); return RT_ERR; } } /* Add the rule for all vwire tables */ - for (uint32_t service_id = 0; service_id < _classifier_management->nr_vwire_tables; service_id++) + for (uint32_t adapter_id = 0; adapter_id < _classifier_management->nr_vwire_tables; adapter_id++) { - if (vwire_service_id_check(service_id) == RT_ERR) + if (vwire_adapter_id_check(adapter_id) == RT_ERR) continue; - /* Fill The rule field for service id */ - int ret = add_rule_for_service_id(_classifier_management, str_section, &rule_parse, service_id, - CLASSIFIER_TABLE_SERVICE_VWIRE); + /* Fill The rule field for adapter id */ + int ret = add_rule_for_adapter_id(_classifier_management, str_section, &rule_parse, adapter_id, + CLASSIFIER_TABLE_ADAPTER_VWIRE); if (ret != CLASSIFIER_RULE_ADD_SUCCESS) { - MR_ERROR("The classifier rule name : %s,service type is:%u, service id is :%u, add rule err.", - str_section, CLASSIFIER_TABLE_SERVICE_VWIRE, service_id); + MR_ERROR("The classifier rule name : %s,adapter type is:%u, adapter id is :%u, add rule err.", + str_section, CLASSIFIER_TABLE_ADAPTER_VWIRE, adapter_id); return RT_ERR; } } diff --git a/service/src/node_etherfabric.c b/service/src/node_etherfabric.c index 08130fa..3726f38 100644 --- a/service/src/node_etherfabric.c +++ b/service/src/node_etherfabric.c @@ -503,8 +503,8 @@ static __rte_always_inline uint16_t etherfabric_ingress_node_process(struct rte_ } /* Fill peer index and dir */ - private_ctrlzone->service_type = SERVICE_TYPE_EF; - private_ctrlzone->service_id = adapter_id; + private_ctrlzone->adapter_type = ADAPTER_TYPE_EF; + private_ctrlzone->adapter_id = adapter_id; private_ctrlzone->link_id = outer_g_vxlan_hdr->link_id; private_ctrlzone->dir = outer_g_vxlan_hdr->dir; private_ctrlzone->peer_index = (uint16_t)peer_index; diff --git a/service/src/node_vwire.c b/service/src/node_vwire.c index 11903ab..33c9687 100644 --- a/service/src/node_vwire.c +++ b/service/src/node_vwire.c @@ -78,9 +78,9 @@ unsigned int vwire_get_max_rule_num() } /* Vwire service id check */ -int vwire_service_id_check(uint32_t vwire_service_id) +int vwire_adapter_id_check(uint32_t vwire_adapter_id) { - if (vwire_service_id >= p_vwire_node_main->nr_forward_rules) + if (vwire_adapter_id >= p_vwire_node_main->nr_forward_rules) return RT_ERR; return RT_SUCCESS; } @@ -128,8 +128,8 @@ static __rte_always_inline uint16_t vwire_ingress_node_process(struct rte_graph insert_sid(priv_data, 1, sids); /* Save vwire id */ - priv_data->service_type = SERVICE_TYPE_VWIRE; - priv_data->service_id = map_result->rule_object->vwire_id; + priv_data->adapter_type = ADAPTER_TYPE_VWIRE; + priv_data->adapter_id = map_result->rule_object->vwire_id; /* Save dir */ priv_data->dir = map_result->is_ext_to_int_dir; |
