From: David Lide Date: Wed, 22 Feb 2012 16:12:50 +0000 (-0500) Subject: added classifier to netcp_cfg.c X-Git-Tag: DEV.NETAPI.01.00.00.01~4 X-Git-Url: https://git.ti.com/gitweb?p=keystone-rtos%2Fnetapi.git;a=commitdiff_plain;h=fe6372473b632c17e493def5c217dc641ba33b39 added classifier to netcp_cfg.c --- diff --git a/ti/runtime/netapi/netapi_tune.h b/ti/runtime/netapi/netapi_tune.h index bfd651d..858e68a 100644 --- a/ti/runtime/netapi/netapi_tune.h +++ b/ti/runtime/netapi/netapi_tune.h @@ -123,7 +123,7 @@ #define TUNE_NETAPI_CONFIG_MAX_SA_TO_PA_DESC 16 #define TUNE_NETAPI_MAX_NUM_MAC 2 //2 'logical' mac addresses -#define TUNE_NETAPI_MAX_NUM_IP 2 //2 ip addresses +#define TUNE_NETAPI_MAX_NUM_IP 4 //2 ip addresses #define TUNE_NETAPI_MAX_NUM_PORTS_PER_CORE 4 //udp/tcp ports -> for lUT2 ) #define TUNE_NETAPI_MAX_NUM_PORTS (TUNE_NETAPI_MAX_NUM_PORTS_PER_CORE * (TUNE_NETAPI_NUM_CORES)) diff --git a/ti/runtime/netapi/netcp_cfg.h b/ti/runtime/netapi/netcp_cfg.h index ae07c6d..ce16af8 100644 --- a/ti/runtime/netapi/netcp_cfg.h +++ b/ti/runtime/netapi/netcp_cfg.h @@ -89,7 +89,8 @@ void netcp_cfgDelRoute(NETAPI_T , NETCP_CFG_ROUTE_HANDLE_T, int *err ); // NWAL "AP ids" for PA Rules that are added #define NETAPI_NETCP_MATCH_GENERIC_MAC 0x10000000 //lower byte==interface #define NETAPI_NETCP_MATCH_GENERIC_IP 0x20000000 //lower byte==interface -#define NETAPI_NETCP_MATCH_CLASS 0x80000000 //or' in classifier #, lower byte==interface +#define NETAPI_NETCP_MATCH_CLASS 0x80000000 //FULL MATCH or' in classifier #, lower byte==interface +#define NETAPI_NETCP_MATCH_CLASS_L3 0x40000000 //MATCHED L3 but not L4. lower byte==interface /*---------MAC APPID------------------*/ @@ -207,13 +208,14 @@ typedef struct NETCP_CFG_CLASS_L3_L4_Tag { //which mac interface pkt is from, int iface; -#define NETCP_CFG_CLASS_IFACE_ANY 255 //don't care - //iP address: IP type, destination addr, qualifiers - //ip_addr=NULL => don't care + //L3 - iP address: IP type, destination addr, qualifiers nwal_IpType ipType; nwalIpAddr_t * ip_addr; nwalIpOpt_t * ip_qualifiers; + NETCP_CFG_ROUTE_HANDLE_T p_fail_route; //what to do if L3 matches but L4 fails AND L3 is a + // new rule.(if exisitng rule, then existing fail + //route will be used. //L4 (port) nwal_appProtoType_t proto; //L4 proto (-1 for don't care) @@ -237,9 +239,9 @@ typedef struct NETCP_CFG_CLASSIFIER_Tag //Instert a classifier. NETCP_CFG_CLASS_T netcp_cfgAddClass(NETAPI_T h, - NETCP_CFG_CLASSIFIER_T *p_class, - NETCP_CFG_ROUTE_HANDLE_T p_route, - int action, int * err); + NETCP_CFG_CLASSIFIER_T *p_class, + NETCP_CFG_ROUTE_HANDLE_T p_route, + int action, int * err); //delete classifier void netcp_cfgDelClass(NETAPI_T h, NETCP_CFG_CLASS_T classId, diff --git a/ti/runtime/netapi/src/netcp_cfg.c b/ti/runtime/netapi/src/netcp_cfg.c old mode 100644 new mode 100755 index 4dbb1ce..4b07528 --- a/ti/runtime/netapi/src/netcp_cfg.c +++ b/ti/runtime/netapi/src/netcp_cfg.c @@ -225,6 +225,7 @@ static void netcp_cfgp_delete_class( //internal: insert a classifier into list static void netcp_cfgp_insert_class(NETAPI_NWAL_GLOBAL_CONTEXT_T *p, int class_slot, //we 'reserved it already' + int class_type, void * L2_handle, void * L3_handle, void * L4_handle) @@ -233,6 +234,7 @@ static void netcp_cfgp_insert_class(NETAPI_NWAL_GLOBAL_CONTEXT_T *p, p->classi[class_slot].nwal_L2_handle = L2_handle; p->classi[class_slot].nwal_L3_handle = L3_handle; p->classi[class_slot].nwal_L4_handle = L4_handle; + p->classi[class_slot].class_type = class_type; return; } @@ -425,17 +427,17 @@ void netcp_cfgDelMac(NETAPI_T h,int iface_no, int *err) /*****************************************************************/ -/***************Add IP to MAC interface****************************/ +/***************Add IP to MAC interface (internal)****************/ /*****************************************************************/ -NETCP_CFG_IP_T netcp_cfgAddIp( +static NETCP_CFG_IP_T netcp_cfgAddIpInternal( NETAPI_T h, int iface_no, nwal_IpType ipType, - nwalIpAddr_t * ip_addr, - nwalIpOpt_t * ip_qualifiers, + nwalIpAddr_t * ip_addr, + nwalIpOpt_t * ip_qualifiers, NETCP_CFG_ROUTE_HANDLE_T route, //NULL for default - int * err - ) + int * err, + int flag) //TRUE: add IP to iface. False: add IP as part of classifier { NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h; void * n_handle; @@ -453,6 +455,7 @@ NetapiNwalTransInfo_t *pTransInfo; nwal_TransID_t trans_id; int ip_slot=-1; NETCP_CFG_IP_T ip_rule_id; +NETCP_CFG_IP_T temp; //verify that iface has been configurred if ((iface_no<0) || (iface_no>= TUNE_NETAPI_MAX_INTERFACES)) {*err = NETAPI_ERR_BAD_INPUT; return -1;} @@ -466,12 +469,17 @@ NETCP_CFG_IP_T ip_rule_id; *err = NETAPI_ERR_BAD_INPUT; return -1; } - //find free slot for IP & reserve - ip_slot= netcp_cfgp_find_ip_slot(&netapi_get_global()->nwal_context, - iface_no); - if (ip_slot <0) + + if (flag) //if adding IP to MAC then reserve a slot to save info { - *err= NETAPI_ERR_NOMEM; //no room + //find free slot for IP & reserve + ip_slot= netcp_cfgp_find_ip_slot(&netapi_get_global()->nwal_context, + iface_no); + if (ip_slot <0) + { + *err= NETAPI_ERR_NOMEM; //no room + return -1; + } } //get a transaction object for config action @@ -494,7 +502,11 @@ NETCP_CFG_IP_T ip_rule_id; memset(&nwalIpParam.ipOpt,0, sizeof(nwalIpOpt_t)); //build the rule id that will be returned when a packet matches - ip_rule_id = NETAPI_NETCP_MATCH_GENERIC_IP | iface_no | ((ip_slot&&0xff)<<8); + if (flag) + ip_rule_id = NETAPI_NETCP_MATCH_GENERIC_IP | iface_no | ((ip_slot&&0xff)<<8); + else + ip_rule_id = (NETAPI_NETCP_MATCH_CLASS_L3 | iface_no); + //perform config action pTransInfo->state == NETAPI_NWAL_HANDLE_STATE_OPEN_PENDING; retValue = nwal_setIPAddr( netapi_get_global()->nwal_context.nwalInstHandle, @@ -511,10 +523,12 @@ NETCP_CFG_IP_T ip_rule_id; retValue); pTransInfo->inUse = nwal_FALSE; //zap the entry - netcp_cfgp_delete_ip(&netapi_get_global()->nwal_context, + if (flag) + { + netcp_cfgp_delete_ip(&netapi_get_global()->nwal_context, iface_no, ip_slot); - + } return -1; } //wait here until its done since scheduler isn't running yet most likely.. @@ -529,13 +543,34 @@ NETCP_CFG_IP_T ip_rule_id; nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL); } } - printf (">netcp cfg: IP added to interface %d (slot%d)\n", iface_no, ip_slot); - netcp_cfgp_insert_ip(&netapi_get_global()->nwal_context, ipType, + if (flag) + { + printf (">netcp cfg: IP added to interface %d (slot%d)\n", iface_no, ip_slot); + netcp_cfgp_insert_ip(&netapi_get_global()->nwal_context, ipType, ip_addr, ip_qualifiers, iface_no, ip_slot, pTransInfo->handle); + } pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_IDLE; + temp = (NETCP_CFG_IP_T) pTransInfo->handle; pTransInfo->inUse = nwal_FALSE; - return (ip_rule_id); + return (flag ? ip_rule_id: temp); +} +/*****************************************************************/ +/***************Add IP to MAC interface **************************/ +/*****************************************************************/ +NETCP_CFG_IP_T netcp_cfgAddIp( + NETAPI_T h, + int iface_no, + nwal_IpType ipType, + nwalIpAddr_t * ip_addr, + nwalIpOpt_t * ip_qualifiers, + NETCP_CFG_ROUTE_HANDLE_T route, //NULL for default + int * err + ) +{ + return netcp_cfgAddIpInternal( + h, iface_no, ipType, ip_addr, ip_qualifiers, route, err, + 1); } /*****************************************************************/ @@ -612,13 +647,13 @@ NETCP_CFG_CLASS_T netcp_cfgAddClass(NETAPI_T h, int action, int * err) { NETAPI_HANDLE_T * n = (NETAPI_HANDLE_T *) h; -void * l3_handle; //ip handle +void * l3_handle=NULL; //ip handle nwal_RetValue retValue; NetapiNwalTransInfo_t *pTransInfo; nwal_TransID_t trans_id; int class_slot=-1; -int iface; -int ip_slot; +int iface_no; +int ip_slot=-1; NETCP_CFG_CLASS_T classHandle; //returned by us nwal_appProtoType_t proto; nwalLocConnCfg_t tempCfg={ @@ -636,22 +671,74 @@ switch(p_class->classType) default: printf(">netcp_cfg : classifier type %d not supported\n",p_class->classType); break; - +case(NETCP_CFG_CLASS_TYPE_L3_L4): case(NETCP_CFG_CLASS_TYPE_L4): //assume just type l4 only (L2, L3 defined by iface, l3 id ) - iface = p_class->u.c_l4.iface; - ip_slot = (p_class->u.c_l4.ip>>8)&0xff; + iface_no = p_class->u.c_l4.iface; + if (p_class->classType== NETCP_CFG_CLASS_TYPE_L4) + { + ip_slot = (p_class->u.c_l4.ip>>8)&0xff; + } //verify that iface has been configured - if(!netapi_get_global()->nwal_context.interfaces[iface].in_use) + if(!netapi_get_global()->nwal_context.interfaces[iface_no].in_use) { *err = NETAPI_ERR_BAD_INPUT; return -1; } - //verify that ip has been configured and get its handle - l3_handle = netcp_cfgp_get_ip_handle( - &netapi_get_global()->nwal_context, iface, + + if (p_class->classType== NETCP_CFG_CLASS_TYPE_L4) + { + //verify that ip has been configured and get its handle + l3_handle = netcp_cfgp_get_ip_handle( + &netapi_get_global()->nwal_context, iface_no, ip_slot ); + } + else + { + nwalIpParam_t tempParam={ + pa_IPV4, /* IP Type */ + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* Dest IP */ + { 0x0,0,0,0},/* IP Options */ + NWAL_MATCH_ACTION_CONTINUE_NEXT_ROUTE, /* Continue parsing to next route for match */ + NWAL_NEXT_ROUTE_FAIL_ACTION_HOST, /* For next route fail action by default is route to host */ + CPPI_PARAM_NOT_SPECIFIED, /* Use default flow configured to NWAL if packet is routed to host */ + QMSS_PARAM_NOT_SPECIFIED /* Use default queue configured to NWAL if packet is routed to host */ + }; + //build nwalIpParam + memcpy(&tempParam.locIpAddr,p_class->u.c_l3_l4.ip_addr, sizeof(nwalIpAddr_t)); + tempParam.ipType=p_class->u.c_l3_l4.ipType; + //use nwal defauls for route + if (p_class->u.c_l3_l4.ip_qualifiers) + memcpy(&tempParam.ipOpt,p_class->u.c_l3_l4.ip_qualifiers, sizeof(nwalIpOpt_t)); + else + memset(&tempParam.ipOpt,0, sizeof(nwalIpOpt_t)); + + + //find if we have a matching L3 handle for IP classifier; if not create it + retValue = nwal_getIPAddr (((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle, + &tempParam, + netcp_cfgp_get_mac_handle(&netapi_get_global()->nwal_context, iface_no ), + &l3_handle); + if (retValue != nwal_TRUE) + { + int ret; + //**NEW IP RULE + //need to attach this IP RULE to the MAC + l3_handle= (void *) netcp_cfgAddIpInternal( + h, iface_no, + p_class->u.c_l3_l4.ipType, + p_class->u.c_l3_l4.ip_addr, + p_class->u.c_l3_l4.ip_qualifiers, + p_class->u.c_l3_l4.p_fail_route, + &ret, + FALSE); + if(!ret) + { + l3_handle=NULL; + } + } + } if(!l3_handle) {*err = NETAPI_ERR_BAD_INPUT; return -1 ;} @@ -659,17 +746,26 @@ case(NETCP_CFG_CLASS_TYPE_L4): //find free slot for CLASS & reserve class_slot= netcp_cfgp_find_class_slot(&netapi_get_global()->nwal_context); if(class_slot<0) {*err = NETAPI_ERR_NOMEM; return -1;} - classHandle = NETAPI_NETCP_MATCH_CLASS | (class_slot<<8) | (iface&0xff); + classHandle = NETAPI_NETCP_MATCH_CLASS | (class_slot<<8) | (iface_no&0xff); //build request from template tempCfg.inHandle=l3_handle; - memcpy(&tempCfg.appProto,&p_class->u.c_l4.appProto,sizeof(nwalAppProto_t)); + if (p_class->classType== NETCP_CFG_CLASS_TYPE_L4) + { + memcpy(&tempCfg.appProto,&p_class->u.c_l4.appProto,sizeof(nwalAppProto_t)); + proto = p_class->u.c_l4.proto; + } + else + { + memcpy(&tempCfg.appProto,&p_class->u.c_l3_l4.appProto,sizeof(nwalAppProto_t)); + proto = p_class->u.c_l3_l4.proto; + } + tempCfg.matchAction = (action==NETCP_CFG_ACTION_TO_SW) ? NWAL_MATCH_ACTION_HOST : NWAL_MATCH_ACTION_DISCARD; - proto = p_class->u.c_l4.proto; //todo: flowid and route //get a transaction id pTransInfo = netapi_GetFreeTransInfo((NETAPI_GLOBAL_T *) n->global, &trans_id); if (!pTransInfo) { *err = NETAPI_ERR_BUSY; return -1 ;} - pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_IP; + pTransInfo->transType = NETAPI_NWAL_HANDLE_TRANS_IP; /* todo: fix this to TRANS_L4*/ pTransInfo->netapi_handle = h; //issue request retValue = nwal_addConn(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle, @@ -700,16 +796,15 @@ case(NETCP_CFG_CLASS_TYPE_L4): nwal_pollCtl(((NETAPI_GLOBAL_T*) (n->global))->nwal_context.nwalInstHandle,NULL,NULL); } } - printf (">netcp cfg: L4 Classifer added to interface %d ip %d (slot%d)\n", iface, ip_slot, class_slot); + printf (">netcp cfg: L4 Classifer added to interface %d ip %d (slot%d)\n", iface_no, ip_slot, class_slot); netcp_cfgp_insert_class(&netapi_get_global()->nwal_context, class_slot, + p_class->classType, NULL, //L2 we have - NULL, //L3 we have + (p_class->classType== NETCP_CFG_CLASS_TYPE_L3_L4? l3_handle : NULL), pTransInfo->handle); pTransInfo->state = NETAPI_NWAL_HANDLE_STATE_IDLE; - - - return classHandle; + return classHandle; } //end switch return -1; } diff --git a/ti/runtime/netapi/test/net_test.c b/ti/runtime/netapi/test/net_test.c index 2073b43..7d933b7 100755 --- a/ti/runtime/netapi/test/net_test.c +++ b/ti/runtime/netapi/test/net_test.c @@ -191,6 +191,7 @@ typedef struct stats_t long n_new; long n_class0_rx; //count of pkts classified long n_class1_rx; //count of pkts classified + long n_class2_rx; //count of pkts classified long n_t1; long n_t2; long n_t3; @@ -214,6 +215,8 @@ unsigned char mac0[]={0x00,0x01,0x02,0x03,0x04,0x05}; //interface 0 unsigned char mac1[]={0x00,0x01,0x02,0x03,0x04,0x06}; //interface 1 nwalIpAddr_t OurIp0={ 10, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; nwalIpAddr_t OurIp1={ 10, 0, 1, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +nwalIpAddr_t OurIp2={ 10, 0, 2, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + #if 1 //goes with real tx (to laptop) unsigned char real_mac_header[]={0xd4,0xbe,0xd9,0x00,0xd3,0x7e, @@ -271,6 +274,7 @@ NETCP_CFG_IP_T ip_rule0; NETCP_CFG_IP_T ip_rule1; NETCP_CFG_CLASS_T class_0; NETCP_CFG_CLASS_T class_1; +NETCP_CFG_CLASS_T class_2; NETCP_CFG_CLASSIFIER_T class_0_cfg= { @@ -288,6 +292,15 @@ NETCP_CFG_CLASSIFIER_T class_1_cfg= } }; +NETCP_CFG_CLASSIFIER_T class_2_cfg= +{ + NETCP_CFG_CLASS_TYPE_L3_L4, + { + {0, 4 ,0/*fill in below*/ , NULL, NULL, //L2/L3 + NWAL_APP_PLOAD_PROTO_UDP, {2504}} //L4 + } +}; + PKTIO_CONTROL_T zap_channel_control={PKTIO_CLEAR, NULL}; /*************************END NETAPI OBJECTS***********************/ @@ -398,8 +411,9 @@ lpInfo.l4csum = (p_meta->u.rx_meta->rxFlag1 & NWAL_RX_FLAG1_L4_CHKSUM_VERIFY_MAS if ((unsigned int)p_meta->u.rx_meta->appId & NETAPI_NETCP_MATCH_CLASS) { int c= ((unsigned int)p_meta->u.rx_meta->appId >>8)&0xffff; - if (c==0) stats.n_class0_rx +=1; + if (c==0) stats.n_class0_rx +=1; else if (c==1) stats.n_class1_rx +=1; + else if (c==2) stats.n_class2_rx +=1; else printf("**NET_TEST RX -unknown class: %x\n", p_meta->u.rx_meta->appId); } } @@ -853,6 +867,13 @@ class_1 = netcp_cfgAddClass(netapi_handle, if (err) {printf("addclass1 failed %d\n",err); exit(1);} +class_2_cfg.u.c_l3_l4.ip_addr = &OurIp2; +class_2 = netcp_cfgAddClass(netapi_handle, + &class_2_cfg, + NULL, + NETCP_CFG_ACTION_TO_SW, + &err); +if (err) {printf("addclass2 failed %d\n",err); exit(1);} #endif ourTimerBlock = netapi_TimerGroupCreate( @@ -929,6 +950,7 @@ our_stats_cb(netapi_handle, NULL); //delete Classifiers netcp_cfgDelClass(netapi_handle, class_0, &err); netcp_cfgDelClass(netapi_handle, class_1, &err); +netcp_cfgDelClass(netapi_handle, class_2, &err); //delete IPs and MAC Interfacess netcp_cfgDelIp(netapi_handle, 0, 0, NULL, NULL, ip_rule0, &err);