RoutingTests.cpp 188 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181
  1. /*
  2. * Copyright (c) 2017-2018,2020 The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * Changes from Qualcomm Innovation Center are provided under the following license:
  30. *
  31. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  32. *
  33. * Redistribution and use in source and binary forms, with or without
  34. * modification, are permitted (subject to the limitations in the
  35. * disclaimer below) provided that the following conditions are met:
  36. *
  37. * * Redistributions of source code must retain the above copyright
  38. * notice, this list of conditions and the following disclaimer.
  39. *
  40. * * Redistributions in binary form must reproduce the above
  41. * copyright notice, this list of conditions and the following
  42. * disclaimer in the documentation and/or other materials provided
  43. * with the distribution.
  44. *
  45. * * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
  46. * contributors may be used to endorse or promote products derived
  47. * from this software without specific prior written permission.
  48. *
  49. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  50. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
  51. * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  52. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  53. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  54. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  55. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  56. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  57. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  58. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  59. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  60. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  61. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  62. */
  63. #include <stdio.h>
  64. #include <stdlib.h>
  65. #include <unistd.h>
  66. #include <string.h>
  67. #include <stdint.h>
  68. #include "hton.h" // for htonl
  69. #include "InterfaceAbstraction.h"
  70. #include "Constants.h"
  71. #include "Logger.h"
  72. #include "TestsUtils.h"
  73. #include "linux/msm_ipa.h"
  74. #include "RoutingDriverWrapper.h"
  75. #include "Filtering.h"
  76. #include "IPAFilteringTable.h"
  77. #define TOS_FIELD_OFFSET (1)
  78. #define IPV4_TTL_OFFSET (8)
  79. #define IPV4_CSUM_OFFSET (10)
  80. #define DST_ADDR_LSB_OFFSET_IPV4 (19)
  81. #define SRC_ADDR_LSB_OFFSET_IPV4 (15)
  82. #define DST_ADDR_MSB_OFFSET_IPV6 (24)
  83. #define DST_ADDR_LSB_OFFSET_IPV6 (39)
  84. #define TRAFFIC_CLASS_MSB_OFFSET_IPV6 (0)
  85. #define TRAFFIC_CLASS_LSB_OFFSET_IPV6 (1)
  86. #define FLOW_CLASS_MSB_OFFSET_IPV6 (1)
  87. #define FLOW_CLASS_MB_OFFSET_IPV6 (2)
  88. #define FLOW_CLASS_LSB_OFFSET_IPV6 (3)
  89. #define HOP_LIMIT_OFFSET_IPV6 (7)
  90. #define IPV4_DST_PORT_OFFSET (20+2)
  91. #define IPV6_SRC_PORT_OFFSET (40)
  92. #define IPV6_DST_PORT_OFFSET (40+2)
  93. #define IPv4_TCP_FLAGS_OFFSET (20+13)
  94. #define IPv6_TCP_FLAGS_OFFSET (40+13)
  95. #define TCP_ACK_FLAG_MASK (0x10)
  96. extern Logger g_Logger;
  97. class IpaRoutingBlockTestFixture:public TestBase
  98. {
  99. public:
  100. IpaRoutingBlockTestFixture():
  101. m_sendSize (BUFF_MAX_SIZE),
  102. m_sendSize2 (BUFF_MAX_SIZE),
  103. m_sendSize3 (BUFF_MAX_SIZE),
  104. m_IpaIPType(IPA_IP_v4)
  105. {
  106. memset(m_sendBuffer, 0, sizeof(m_sendBuffer));
  107. memset(m_sendBuffer2, 0, sizeof(m_sendBuffer2));
  108. memset(m_sendBuffer3, 0, sizeof(m_sendBuffer3));
  109. m_testSuiteName.push_back("Routing");
  110. }
  111. static int SetupKernelModule(bool en_status = false)
  112. {
  113. int retval;
  114. struct ipa_channel_config from_ipa_channels[3];
  115. struct test_ipa_ep_cfg from_ipa_cfg[3];
  116. struct ipa_channel_config to_ipa_channels[1];
  117. struct test_ipa_ep_cfg to_ipa_cfg[1];
  118. struct ipa_test_config_header header = {0};
  119. struct ipa_channel_config *to_ipa_array[1];
  120. struct ipa_channel_config *from_ipa_array[3];
  121. /* From ipa configurations - 3 pipes */
  122. memset(&from_ipa_cfg[0], 0, sizeof(from_ipa_cfg[0]));
  123. prepare_channel_struct(&from_ipa_channels[0],
  124. header.from_ipa_channels_num++,
  125. IPA_CLIENT_TEST2_CONS,
  126. (void *)&from_ipa_cfg[0],
  127. sizeof(from_ipa_cfg[0]), en_status);
  128. from_ipa_array[0] = &from_ipa_channels[0];
  129. memset(&from_ipa_cfg[1], 0, sizeof(from_ipa_cfg[1]));
  130. prepare_channel_struct(&from_ipa_channels[1],
  131. header.from_ipa_channels_num++,
  132. IPA_CLIENT_TEST3_CONS,
  133. (void *)&from_ipa_cfg[1],
  134. sizeof(from_ipa_cfg[1]), en_status);
  135. from_ipa_array[1] = &from_ipa_channels[1];
  136. memset(&from_ipa_cfg[2], 0, sizeof(from_ipa_cfg[2]));
  137. prepare_channel_struct(&from_ipa_channels[2],
  138. header.from_ipa_channels_num++,
  139. IPA_CLIENT_TEST4_CONS,
  140. (void *)&from_ipa_cfg[2],
  141. sizeof(from_ipa_cfg[2]), en_status);
  142. from_ipa_array[2] = &from_ipa_channels[2];
  143. /* To ipa configurations - 1 pipes */
  144. memset(&to_ipa_cfg[0], 0, sizeof(to_ipa_cfg[0]));
  145. prepare_channel_struct(&to_ipa_channels[0],
  146. header.to_ipa_channels_num++,
  147. IPA_CLIENT_TEST_PROD,
  148. (void *)&to_ipa_cfg[0],
  149. sizeof(to_ipa_cfg[0]));
  150. to_ipa_array[0] = &to_ipa_channels[0];
  151. prepare_header_struct(&header, from_ipa_array, to_ipa_array);
  152. retval = GenericConfigureScenario(&header);
  153. return retval;
  154. }
  155. bool Setup(bool en_status)
  156. {
  157. bool bRetVal = true;
  158. bRetVal = SetupKernelModule(en_status);
  159. if (bRetVal != true) {
  160. return bRetVal;
  161. }
  162. m_producer.Open(INTERFACE0_TO_IPA_DATA_PATH, INTERFACE0_FROM_IPA_DATA_PATH);
  163. m_consumer.Open(INTERFACE1_TO_IPA_DATA_PATH, INTERFACE1_FROM_IPA_DATA_PATH);
  164. m_consumer2.Open(INTERFACE2_TO_IPA_DATA_PATH, INTERFACE2_FROM_IPA_DATA_PATH);
  165. m_defaultConsumer.Open(INTERFACE3_TO_IPA_DATA_PATH, INTERFACE3_FROM_IPA_DATA_PATH);
  166. if (!m_routing.DeviceNodeIsOpened()) {
  167. printf("Routing block is not ready for immediate commands!\n");
  168. return false;
  169. }
  170. if (!m_filtering.DeviceNodeIsOpened()) {
  171. printf("Filtering block is not ready for immediate commands!\n");
  172. return false;
  173. }
  174. m_routing.Reset(IPA_IP_v4);
  175. m_routing.Reset(IPA_IP_v6);
  176. return true;
  177. } /* Setup()*/
  178. bool Setup()
  179. {
  180. return Setup(false);
  181. }
  182. bool Teardown()
  183. {
  184. if (!m_routing.DeviceNodeIsOpened()) {
  185. printf("Routing block is not ready for immediate commands!\n");
  186. return false;
  187. }
  188. if (!m_filtering.DeviceNodeIsOpened()) {
  189. printf("Filtering block is not ready for immediate commands!\n");
  190. return false;
  191. }
  192. m_producer.Close();
  193. m_consumer.Close();
  194. m_consumer2.Close();
  195. m_defaultConsumer.Close();
  196. return true;
  197. } /* Teardown() */
  198. bool LoadFiles(enum ipa_ip_type ip)
  199. {
  200. string fileName;
  201. if (IPA_IP_v4 == ip) {
  202. fileName = "Input/IPv4_1";
  203. } else {
  204. fileName = "Input/IPv6";
  205. }
  206. if (!LoadDefaultPacket(ip, m_sendBuffer, m_sendSize)) {
  207. LOG_MSG_ERROR("Failed loading default Packet");
  208. return false;
  209. }
  210. if (!LoadDefaultPacket(ip, m_sendBuffer2, m_sendSize2)) {
  211. LOG_MSG_ERROR("Failed loading default Packet");
  212. return false;
  213. }
  214. if (!LoadDefaultPacket(ip, m_sendBuffer3, m_sendSize3)) {
  215. LOG_MSG_ERROR("Failed loading default Packet");
  216. return false;
  217. }
  218. return true;
  219. }
  220. bool ReceivePacketAndCompareFrom(InterfaceAbstraction& cons, Byte* send,
  221. size_t send_sz, bool shouldBeHit)
  222. {
  223. size_t receivedSize = 0;
  224. bool isSuccess = true;
  225. /* Receive results*/
  226. Byte *rxBuff1 = new Byte[0x400];
  227. if (NULL == rxBuff1)
  228. {
  229. printf("Memory allocation error.\n");
  230. return false;
  231. }
  232. receivedSize = cons.ReceiveData(rxBuff1, 0x400);
  233. printf("Received %zu bytes on %s.\n", receivedSize, cons.m_fromChannelName.c_str());
  234. // Compare results
  235. isSuccess &= CompareResultVsGolden_w_Status(send, send_sz, rxBuff1, receivedSize);
  236. if (shouldBeHit) {
  237. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  238. IsCacheHit_v5_0(send_sz, receivedSize, rxBuff1) : IsCacheHit(send_sz, receivedSize, rxBuff1);
  239. }
  240. else
  241. {
  242. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  243. IsCacheMiss_v5_0(send_sz, receivedSize, rxBuff1) : IsCacheMiss(send_sz, receivedSize, rxBuff1);
  244. }
  245. size_t recievedBufferSize = receivedSize * 3;
  246. size_t sentBufferSize = m_sendSize * 3;
  247. char *recievedBuffer = new char[recievedBufferSize];
  248. char *sentBuffer = new char[sentBufferSize];
  249. // char * p = recievedBuffer;
  250. size_t j;
  251. for(j = 0; j < m_sendSize; j++)
  252. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", send[j]);
  253. for(j = 0; j < receivedSize; j++)
  254. // recievedBuffer += sprintf(recievedBuffer, "%02X", rxBuff1[i]);
  255. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff1[j]);
  256. printf("Expected Value (%zu)\n%s\n, Received Value1(%zu)\n%s\n",send_sz,sentBuffer,receivedSize,recievedBuffer);
  257. delete[] rxBuff1;
  258. delete[] recievedBuffer;
  259. delete[] sentBuffer;
  260. return isSuccess;
  261. }
  262. bool ReceivePacketsAndCompare()
  263. {
  264. size_t receivedSize = 0;
  265. size_t receivedSize2 = 0;
  266. size_t receivedSize3 = 0;
  267. bool pkt1_cmp_succ, pkt2_cmp_succ, pkt3_cmp_succ;
  268. // Receive results
  269. Byte *rxBuff1 = new Byte[0x400];
  270. Byte *rxBuff2 = new Byte[0x400];
  271. Byte *rxBuff3 = new Byte[0x400];
  272. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  273. {
  274. printf("Memory allocation error.\n");
  275. return false;
  276. }
  277. memset(rxBuff1, 0, 0x400);
  278. memset(rxBuff2, 0, 0x400);
  279. memset(rxBuff3, 0, 0x400);
  280. receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400);
  281. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  282. receivedSize2 = m_consumer2.ReceiveData(rxBuff2, 0x400);
  283. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer2.m_fromChannelName.c_str());
  284. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  285. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  286. /* Compare results */
  287. pkt1_cmp_succ = CompareResultVsGolden(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  288. pkt2_cmp_succ = CompareResultVsGolden(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  289. pkt3_cmp_succ = CompareResultVsGolden(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  290. size_t recievedBufferSize =
  291. MAX3(receivedSize, receivedSize2, receivedSize3) * 3;
  292. size_t sentBufferSize =
  293. MAX3(m_sendSize, m_sendSize2, m_sendSize3) * 3;
  294. char *recievedBuffer = new char[recievedBufferSize];
  295. char *sentBuffer = new char[sentBufferSize];
  296. if (NULL == recievedBuffer || NULL == sentBuffer) {
  297. printf("Memory allocation error\n");
  298. return false;
  299. }
  300. size_t j;
  301. memset(recievedBuffer, 0, recievedBufferSize);
  302. memset(sentBuffer, 0, sentBufferSize);
  303. for(j = 0; j < m_sendSize; j++)
  304. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer[j]);
  305. for(j = 0; j < receivedSize; j++)
  306. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff1[j]);
  307. printf("Expected Value1(%zu)\n%s\n, Received Value1(%zu)\n%s\n-->Value1 %s\n",
  308. m_sendSize,sentBuffer,receivedSize,recievedBuffer,
  309. pkt1_cmp_succ?"Match":"no Match");
  310. memset(recievedBuffer, 0, recievedBufferSize);
  311. memset(sentBuffer, 0, sentBufferSize);
  312. for(j = 0; j < m_sendSize2; j++)
  313. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer2[j]);
  314. for(j = 0; j < receivedSize2; j++)
  315. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff2[j]);
  316. printf("Expected Value2 (%zu)\n%s\n, Received Value2(%zu)\n%s\n-->Value2 %s\n",
  317. m_sendSize2,sentBuffer,receivedSize2,recievedBuffer,
  318. pkt2_cmp_succ?"Match":"no Match");
  319. memset(recievedBuffer, 0, recievedBufferSize);
  320. memset(sentBuffer, 0, sentBufferSize);
  321. for(j = 0; j < m_sendSize3; j++)
  322. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer3[j]);
  323. for(j = 0; j < receivedSize3; j++)
  324. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff3[j]);
  325. printf("Expected Value3 (%zu)\n%s\n, Received Value3(%zu)\n%s\n-->Value3 %s\n",
  326. m_sendSize3,sentBuffer,receivedSize3,recievedBuffer,
  327. pkt3_cmp_succ?"Match":"no Match");
  328. delete[] recievedBuffer;
  329. delete[] sentBuffer;
  330. delete[] rxBuff1;
  331. delete[] rxBuff2;
  332. delete[] rxBuff3;
  333. return pkt1_cmp_succ && pkt2_cmp_succ && pkt3_cmp_succ;
  334. }
  335. void print_packets(size_t receivedSize, size_t m_sendSize, size_t recievedBufferSize, size_t sentBufferSize, Byte *rxBuff, Byte *m_sendBuffer, char *recievedBuffer, char *sentBuffer)
  336. {
  337. size_t j;
  338. for(j = 0; j < m_sendSize; j++) {
  339. snprintf(&sentBuffer[3 * j], sentBufferSize - 3 * j,
  340. " %02X", m_sendBuffer[j]);
  341. }
  342. for(j = 0; j < receivedSize; j++) {
  343. snprintf(&recievedBuffer[3 * j], recievedBufferSize- 3 * j,
  344. " %02X", rxBuff[j]);
  345. }
  346. printf("Expected Value (%zu)\n%s\n, Received Value(%zu)\n%s\n",m_sendSize,sentBuffer,receivedSize,recievedBuffer);
  347. }
  348. ~IpaRoutingBlockTestFixture()
  349. {
  350. m_sendSize = 0;
  351. m_sendSize2 = 0;
  352. m_sendSize3 = 0;
  353. }
  354. void InitFilteringBlock()
  355. {
  356. IPAFilteringTable fltTable;
  357. struct ipa_ioc_get_rt_tbl st_rt_tbl;
  358. struct ipa_flt_rule_add flt_rule_entry;
  359. memset(&st_rt_tbl, 0, sizeof(st_rt_tbl));
  360. memset(&flt_rule_entry, 0, sizeof(flt_rule_entry));
  361. strlcpy(st_rt_tbl.name, "LAN", sizeof(st_rt_tbl.name));
  362. st_rt_tbl.ip = m_IpaIPType;
  363. fltTable.Init(m_IpaIPType, IPA_CLIENT_TEST_PROD, false, 1);
  364. m_routing.GetRoutingTable(&st_rt_tbl);
  365. flt_rule_entry.rule.rt_tbl_hdl = st_rt_tbl.hdl;
  366. fltTable.AddRuleToTable(flt_rule_entry);
  367. m_filtering.AddFilteringRule(fltTable.GetFilteringTable());
  368. }
  369. inline bool VerifyStatusReceived(size_t SendSize, size_t RecvSize)
  370. {
  371. size_t stts_size = sizeof(struct ipa3_hw_pkt_status);
  372. if (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) {
  373. stts_size = sizeof(struct ipa3_hw_pkt_status_hw_v5_0);
  374. }
  375. if ((RecvSize <= SendSize) ||
  376. ((RecvSize - SendSize) != stts_size)){
  377. printf("received buffer size does not match! sent:receive [%zu]:[%zu]\n",SendSize,RecvSize);
  378. return false;
  379. }
  380. return true;
  381. }
  382. inline bool IsCacheHit(size_t SendSize, size_t RecvSize, void *Buff)
  383. {
  384. struct ipa3_hw_pkt_status *pStatus = (struct ipa3_hw_pkt_status *)Buff;
  385. if (VerifyStatusReceived(SendSize,RecvSize) == false){
  386. return false;
  387. }
  388. if((bool)pStatus->route_hash){
  389. printf ("%s::cache hit!! \n",__FUNCTION__);
  390. return true;
  391. }
  392. printf ("%s::cache miss!! \n",__FUNCTION__);
  393. return false;
  394. }
  395. inline bool IsCacheHit_v5_0(size_t SendSize, size_t RecvSize, void *Buff)
  396. {
  397. struct ipa3_hw_pkt_status_hw_v5_0 *pStatus = (struct ipa3_hw_pkt_status_hw_v5_0 *)Buff;
  398. if (VerifyStatusReceived(SendSize,RecvSize) == false){
  399. return false;
  400. }
  401. if((bool)pStatus->route_hash){
  402. printf ("%s::cache hit!! \n",__FUNCTION__);
  403. return true;
  404. }
  405. printf ("%s::cache miss!! \n",__FUNCTION__);
  406. return false;
  407. }
  408. inline bool IsCacheMiss(size_t SendSize, size_t RecvSize, void *Buff)
  409. {
  410. struct ipa3_hw_pkt_status *pStatus = (struct ipa3_hw_pkt_status *)Buff;
  411. if (VerifyStatusReceived(SendSize,RecvSize) == false){
  412. return false;
  413. }
  414. if(!((bool)pStatus->route_hash)){
  415. printf ("%s::cache miss!! \n",__FUNCTION__);
  416. return true;
  417. }
  418. printf ("%s::cache hit!! \n",__FUNCTION__);
  419. return false;
  420. }
  421. inline bool IsCacheMiss_v5_0(size_t SendSize, size_t RecvSize, void *Buff)
  422. {
  423. struct ipa3_hw_pkt_status_hw_v5_0 *pStatus = (struct ipa3_hw_pkt_status_hw_v5_0 *)Buff;
  424. if (VerifyStatusReceived(SendSize,RecvSize) == false){
  425. return false;
  426. }
  427. if(!((bool)pStatus->route_hash)){
  428. printf ("%s::cache miss!! \n",__FUNCTION__);
  429. return true;
  430. }
  431. printf ("%s::cache hit!! \n",__FUNCTION__);
  432. return false;
  433. }
  434. inline bool IsTTLUpdated_v5_5(size_t SendSize, size_t RecvSize, void *Buff)
  435. {
  436. struct ipa3_hw_pkt_status_hw_v5_5 *pStatus = (struct ipa3_hw_pkt_status_hw_v5_5 *)Buff;
  437. if (VerifyStatusReceived(SendSize,RecvSize) == false){
  438. return false;
  439. }
  440. if(!((bool)pStatus->ttl_dec)){
  441. printf ("%s::cache miss!! \n",__FUNCTION__);
  442. return true;
  443. }
  444. printf ("%s::cache hit!! \n",__FUNCTION__);
  445. return false;
  446. }
  447. static RoutingDriverWrapper m_routing;
  448. static Filtering m_filtering;
  449. static const size_t BUFF_MAX_SIZE = 1024;
  450. InterfaceAbstraction m_producer;
  451. InterfaceAbstraction m_consumer;
  452. InterfaceAbstraction m_consumer2;
  453. InterfaceAbstraction m_defaultConsumer;
  454. Byte m_sendBuffer[BUFF_MAX_SIZE]; // First input file / IP packet
  455. Byte m_sendBuffer2[BUFF_MAX_SIZE]; // Second input file / IP packet
  456. Byte m_sendBuffer3[BUFF_MAX_SIZE]; // Third input file (default) / IP packet
  457. size_t m_sendSize;
  458. size_t m_sendSize2;
  459. size_t m_sendSize3;
  460. enum ipa_ip_type m_IpaIPType;
  461. private:
  462. };
  463. RoutingDriverWrapper IpaRoutingBlockTestFixture::m_routing;
  464. Filtering IpaRoutingBlockTestFixture::m_filtering;
  465. /*---------------------------------------------------------------------------*/
  466. /* Test1: Tests routing by destination address */
  467. /*---------------------------------------------------------------------------*/
  468. class IpaRoutingBlockTest1 : public IpaRoutingBlockTestFixture
  469. {
  470. public:
  471. IpaRoutingBlockTest1()
  472. {
  473. m_name = "IpaRoutingBlockTest1";
  474. m_description =" \
  475. Routing block test 001 - Destination address exact match\1. Generate and commit a single routing tables. \
  476. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  477. All DST_IP == (192.169.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  478. All DST_IP == (192.168.2.255 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  479. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  480. m_IpaIPType = IPA_IP_v4;
  481. Register(*this);
  482. }
  483. bool Run()
  484. {
  485. bool res = false;
  486. bool isSuccess = false;
  487. // Add the relevant routing rules
  488. res = AddRules();
  489. if (false == res) {
  490. printf("Failed adding routing rules.\n");
  491. return false;
  492. }
  493. // Load input data (IP packet) from file
  494. res = LoadFiles(IPA_IP_v4);
  495. if (false == res) {
  496. printf("Failed loading files.\n");
  497. return false;
  498. }
  499. // Send first packet
  500. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xFF;
  501. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  502. if (false == isSuccess)
  503. {
  504. printf("SendData failure.\n");
  505. return false;
  506. }
  507. // Send second packet
  508. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  509. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  510. if (false == isSuccess)
  511. {
  512. printf("SendData failure.\n");
  513. return false;
  514. }
  515. // Send third packet
  516. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  517. if (false == isSuccess)
  518. {
  519. printf("SendData failure.\n");
  520. return false;
  521. }
  522. // Receive packets from the channels and compare results
  523. isSuccess = ReceivePacketsAndCompare();
  524. return isSuccess;
  525. } // Run()
  526. bool AddRules()
  527. {
  528. struct ipa_ioc_add_rt_rule *rt_rule;
  529. struct ipa_rt_rule_add *rt_rule_entry;
  530. const int NUM_RULES = 3;
  531. rt_rule = (struct ipa_ioc_add_rt_rule *)
  532. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  533. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  534. if(!rt_rule) {
  535. printf("Failed memory allocation for rt_rule\n");
  536. return false;
  537. }
  538. rt_rule->commit = 1;
  539. rt_rule->num_rules = NUM_RULES;
  540. rt_rule->ip = IPA_IP_v4;
  541. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  542. rt_rule_entry = &rt_rule->rules[0];
  543. rt_rule_entry->at_rear = 0;
  544. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  545. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  546. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  547. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802FF;
  548. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  549. rt_rule_entry = &rt_rule->rules[1];
  550. rt_rule_entry->at_rear = 0;
  551. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  552. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  553. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  554. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA;
  555. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  556. rt_rule_entry = &rt_rule->rules[2];
  557. rt_rule_entry->at_rear = 1;
  558. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  559. if (false == m_routing.AddRoutingRule(rt_rule))
  560. {
  561. printf("Routing rule addition failed!\n");
  562. return false;
  563. }
  564. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  565. free(rt_rule);
  566. InitFilteringBlock();
  567. return true;
  568. }
  569. };
  570. /*---------------------------------------------------------------------------*/
  571. /* Test2: Tests routing by destination address with a subnet (mask) */
  572. /*---------------------------------------------------------------------------*/
  573. class IpaRoutingBlockTest2 : IpaRoutingBlockTestFixture
  574. {
  575. public:
  576. IpaRoutingBlockTest2()
  577. {
  578. m_name = "IpaRoutingBlockTest2";
  579. m_description =" \
  580. Routing block test 002 - Destination address subnet match \
  581. 1. Generate and commit a single routing tables. \
  582. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  583. All DST_IP == (192.169.170.0 & 255.255.255.0)traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  584. All DST_IP == (192.168.255.0 & 255.255.255.0)traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  585. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  586. m_IpaIPType = IPA_IP_v4;
  587. Register(*this);
  588. }
  589. bool Run()
  590. {
  591. bool res = false;
  592. bool isSuccess = false;
  593. printf("ENTRY: IpaRoutingBlockTest2::Run()\n");
  594. // Add the relevant routing rules
  595. res = AddRules();
  596. if (false == res) {
  597. printf("Failed adding routing rules.\n");
  598. return false;
  599. }
  600. // Load input data (IP packet) from file
  601. res = LoadFiles(IPA_IP_v4);
  602. if (false == res) {
  603. printf("Failed loading files.\n");
  604. return false;
  605. }
  606. // Send first packet
  607. m_sendBuffer[18] = 0xFF;
  608. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  609. if (false == isSuccess)
  610. {
  611. printf("SendData failure.\n");
  612. return false;
  613. }
  614. // Send second packet
  615. m_sendBuffer2[18] = 0xAA;
  616. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  617. if (false == isSuccess)
  618. {
  619. printf("SendData failure.\n");
  620. return false;
  621. }
  622. // Send third packet
  623. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  624. if (false == isSuccess)
  625. {
  626. printf("SendData failure.\n");
  627. return false;
  628. }
  629. // Receive packets from the channels and compare results
  630. isSuccess = ReceivePacketsAndCompare();
  631. return isSuccess;
  632. } // Run()
  633. bool AddRules()
  634. {
  635. struct ipa_ioc_add_rt_rule *rt_rule;
  636. struct ipa_rt_rule_add *rt_rule_entry;
  637. const int NUM_RULES = 3;
  638. printf("ENTRY: IpaRoutingBlockTest2::AddRules()\n");
  639. rt_rule = (struct ipa_ioc_add_rt_rule *)
  640. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  641. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  642. if(!rt_rule) {
  643. printf("fail\n");
  644. return false;
  645. }
  646. rt_rule->commit = 1;
  647. rt_rule->num_rules = NUM_RULES;
  648. rt_rule->ip = IPA_IP_v4;
  649. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  650. rt_rule_entry = &rt_rule->rules[0];
  651. rt_rule_entry->at_rear = 0;
  652. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  653. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  654. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  655. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A8FF00;
  656. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFF00;
  657. rt_rule_entry = &rt_rule->rules[1];
  658. rt_rule_entry->at_rear = 0;
  659. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  660. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  661. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  662. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A8AA00;
  663. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFF00;
  664. rt_rule_entry = &rt_rule->rules[2];
  665. rt_rule_entry->at_rear = 1;
  666. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  667. printf("Before calling m_routing.AddRoutingRule()\n");
  668. printf("m_routing = %p\n", &m_routing);
  669. if (false == m_routing.AddRoutingRule(rt_rule))
  670. {
  671. printf("Routing rule addition failed!\n");
  672. return false;
  673. }
  674. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  675. free(rt_rule);
  676. InitFilteringBlock();
  677. return true;
  678. }
  679. };
  680. /*---------------------------------------------------------------------------*/
  681. /* Test3: Tests routing by TOS (Type Of Service) */
  682. /*---------------------------------------------------------------------------*/
  683. class IpaRoutingBlockTest3 : IpaRoutingBlockTestFixture
  684. {
  685. public:
  686. IpaRoutingBlockTest3()
  687. {
  688. m_name = "IpaRoutingBlockTest3";
  689. m_description = " \
  690. Routing block test 003 - TOS exact match\
  691. 1. Generate and commit a single routing tables. \
  692. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  693. All TOS == 0xBF traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  694. All TOS == 0x3A traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  695. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  696. m_IpaIPType = IPA_IP_v4;
  697. Register(*this);
  698. }
  699. bool Run()
  700. {
  701. bool res = false;
  702. bool isSuccess = false;
  703. // Add the relevant routing rules
  704. res = AddRules();
  705. if (false == res) {
  706. printf("Failed adding routing rules.\n");
  707. return false;
  708. }
  709. // Load input data (IP packet) from file
  710. res = LoadFiles(IPA_IP_v4);
  711. if (false == res) {
  712. printf("Failed loading files.\n");
  713. return false;
  714. }
  715. // Send first packet
  716. m_sendBuffer[TOS_FIELD_OFFSET] = 0xBF;
  717. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  718. if (false == isSuccess)
  719. {
  720. printf("SendData failure.\n");
  721. return false;
  722. }
  723. // Send second packet
  724. m_sendBuffer2[TOS_FIELD_OFFSET] = 0x3A;
  725. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  726. if (false == isSuccess)
  727. {
  728. printf("SendData failure.\n");
  729. return false;
  730. }
  731. // Send third packet
  732. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  733. if (false == isSuccess)
  734. {
  735. printf("SendData failure.\n");
  736. return false;
  737. }
  738. // Receive packets from the channels and compare results
  739. isSuccess = ReceivePacketsAndCompare();
  740. return isSuccess;
  741. } // Run()
  742. bool AddRules()
  743. {
  744. struct ipa_ioc_add_rt_rule *rt_rule;
  745. struct ipa_rt_rule_add *rt_rule_entry;
  746. const int NUM_RULES = 3;
  747. rt_rule = (struct ipa_ioc_add_rt_rule *)
  748. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  749. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  750. if (!rt_rule) {
  751. printf("fail\n");
  752. return false;
  753. }
  754. rt_rule->commit = 1;
  755. rt_rule->num_rules = NUM_RULES;
  756. rt_rule->ip = IPA_IP_v4;
  757. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  758. rt_rule_entry = &rt_rule->rules[0];
  759. rt_rule_entry->at_rear = 0;
  760. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  761. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl;
  762. // gidons, there is no support for header insertion / removal yet.
  763. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_TOS;
  764. rt_rule_entry->rule.attrib.u.v4.tos = 0xBF;
  765. rt_rule_entry = &rt_rule->rules[1];
  766. rt_rule_entry->at_rear = 0;
  767. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  768. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  769. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_TOS;
  770. rt_rule_entry->rule.attrib.u.v4.tos = 0x3A;
  771. rt_rule_entry = &rt_rule->rules[2];
  772. rt_rule_entry->at_rear = 1;
  773. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  774. if (false == m_routing.AddRoutingRule(rt_rule))
  775. {
  776. printf("Routing rule addition failed!\n");
  777. return false;
  778. }
  779. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  780. free(rt_rule);
  781. InitFilteringBlock();
  782. return true;
  783. }
  784. };
  785. /*---------------------------------------------------------------------------*/
  786. /* Test4: Destination address exact match and TOS exact match */
  787. /*---------------------------------------------------------------------------*/
  788. class IpaRoutingBlockTest4 : IpaRoutingBlockTestFixture
  789. {
  790. public:
  791. IpaRoutingBlockTest4()
  792. {
  793. m_name = "IpaRoutingBlockTest4";
  794. m_description =" \
  795. Routing block test 004 - Source and Destination address and TOS exact match \
  796. 1. Generate and commit a single routing tables. \
  797. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  798. All DST_IP == (192.169.2.255 & 255.255.255.255) and TOS == 0xFF traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  799. All DST_IP == (192.168.2.170 & 255.255.255.255) and TOS == 0xAA traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  800. All DST_IP == (192.168.2.85 & 255.255.255.255) and SRC_IP == (192.168.2.241 & 255.255.255.255) TOS == 0x24 traffic goes to pipe IPA_CLIENT_TEST3_CONS";
  801. m_IpaIPType = IPA_IP_v4;
  802. Register(*this);
  803. }
  804. bool Run()
  805. {
  806. bool res = false;
  807. bool isSuccess = false;
  808. // Add the relevant routing rules
  809. res = AddRules();
  810. if (false == res) {
  811. printf("Failed adding routing rules.\n");
  812. return false;
  813. }
  814. // Load input data (IP packet) from file
  815. res = LoadFiles(IPA_IP_v4);
  816. if (false == res) {
  817. printf("Failed loading files.\n");
  818. return false;
  819. }
  820. // Send first packet
  821. m_sendBuffer[TOS_FIELD_OFFSET] = 0xFF;
  822. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xFF;
  823. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  824. if (false == isSuccess)
  825. {
  826. printf("SendData failure.\n");
  827. return false;
  828. }
  829. // Send second packet
  830. m_sendBuffer2[TOS_FIELD_OFFSET] = 0xAA;
  831. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  832. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  833. if (false == isSuccess)
  834. {
  835. printf("SendData failure.\n");
  836. return false;
  837. }
  838. // Send third packet
  839. m_sendBuffer3[TOS_FIELD_OFFSET] = 0x24;
  840. m_sendBuffer3[DST_ADDR_LSB_OFFSET_IPV4] = 0x55;
  841. m_sendBuffer3[SRC_ADDR_LSB_OFFSET_IPV4] = 0xF1;
  842. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  843. if (false == isSuccess)
  844. {
  845. printf("SendData failure.\n");
  846. return false;
  847. }
  848. // Receive packets from the channels and compare results
  849. isSuccess = ReceivePacketsAndCompare();
  850. return isSuccess;
  851. } // Run()
  852. bool AddRules()
  853. {
  854. struct ipa_ioc_add_rt_rule *rt_rule;
  855. struct ipa_rt_rule_add *rt_rule_entry;
  856. const int NUM_RULES = 3;
  857. rt_rule = (struct ipa_ioc_add_rt_rule *)
  858. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  859. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  860. if(!rt_rule) {
  861. printf("fail\n");
  862. return false;
  863. }
  864. rt_rule->commit = 1;
  865. rt_rule->num_rules = NUM_RULES;
  866. rt_rule->ip = IPA_IP_v4;
  867. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  868. rt_rule_entry = &rt_rule->rules[0];
  869. rt_rule_entry->at_rear = 0;
  870. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  871. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_TOS | IPA_FLT_DST_ADDR;
  872. rt_rule_entry->rule.attrib.u.v4.tos = 0xFF;
  873. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802FF;
  874. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  875. rt_rule_entry = &rt_rule->rules[1];
  876. rt_rule_entry->at_rear = 0;
  877. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  878. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_TOS | IPA_FLT_DST_ADDR;
  879. rt_rule_entry->rule.attrib.u.v4.tos = 0xAA;
  880. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA;
  881. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  882. rt_rule_entry = &rt_rule->rules[2];
  883. rt_rule_entry->at_rear = 1;
  884. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  885. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_TOS | IPA_FLT_DST_ADDR | IPA_FLT_SRC_ADDR;
  886. rt_rule_entry->rule.attrib.u.v4.tos = 0x24;
  887. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A80255;
  888. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  889. rt_rule_entry->rule.attrib.u.v4.src_addr = 0xC0A802F1;
  890. rt_rule_entry->rule.attrib.u.v4.src_addr_mask = 0xFFFFFFFF;
  891. if (false == m_routing.AddRoutingRule(rt_rule))
  892. {
  893. printf("Routing rule addition failed!\n");
  894. return false;
  895. }
  896. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  897. free(rt_rule);
  898. InitFilteringBlock();
  899. return true;
  900. }
  901. };
  902. /*---------------------------------------------------------------------------*/
  903. /* Test5: IPv6 - Tests routing by destination address */
  904. /*---------------------------------------------------------------------------*/
  905. class IpaRoutingBlockTest5 : public IpaRoutingBlockTestFixture
  906. {
  907. public:
  908. IpaRoutingBlockTest5()
  909. {
  910. m_name = "IpaRoutingBlockTest5";
  911. m_description =" \
  912. Routing block test 005 - IPv6 Destination address exact match \
  913. 1. Generate and commit a single routing tables. \
  914. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  915. All DST_IP == 0XFF020000 \
  916. 0x00000000 \
  917. 0x00000000 \
  918. 0X000000FF \
  919. traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  920. All DST_IP == 0XFF020000 \
  921. 0x00000000 \
  922. 0x00000000 \
  923. 0X000000FF \
  924. traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  925. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  926. m_IpaIPType = IPA_IP_v6;
  927. Register(*this);
  928. }
  929. bool Run()
  930. {
  931. bool res = false;
  932. bool isSuccess = false;
  933. // Add the relevant routing rules
  934. res = AddRules();
  935. if (false == res) {
  936. printf("Failed adding routing rules.\n");
  937. return false;
  938. }
  939. // Load input data (IP packet) from file
  940. res = LoadFiles(IPA_IP_v6);
  941. if (false == res) {
  942. printf("Failed loading files.\n");
  943. return false;
  944. }
  945. // Send first packet
  946. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  947. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  948. if (false == isSuccess)
  949. {
  950. printf("SendData failure.\n");
  951. return false;
  952. }
  953. // Send second packet
  954. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xAA;
  955. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  956. if (false == isSuccess)
  957. {
  958. printf("SendData failure.\n");
  959. return false;
  960. }
  961. // Send third packet
  962. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  963. if (false == isSuccess)
  964. {
  965. printf("SendData failure.\n");
  966. return false;
  967. }
  968. // Receive packets from the channels and compare results
  969. isSuccess = ReceivePacketsAndCompare();
  970. return isSuccess;
  971. } // Run()
  972. bool AddRules()
  973. {
  974. struct ipa_ioc_add_rt_rule *rt_rule;
  975. struct ipa_rt_rule_add *rt_rule_entry;
  976. const int NUM_RULES = 3;
  977. rt_rule = (struct ipa_ioc_add_rt_rule *)
  978. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  979. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  980. if(!rt_rule) {
  981. printf("fail\n");
  982. return false;
  983. }
  984. rt_rule->commit = 1;
  985. rt_rule->num_rules = NUM_RULES;
  986. rt_rule->ip = IPA_IP_v6;
  987. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  988. rt_rule_entry = &rt_rule->rules[0];
  989. rt_rule_entry->at_rear = 0;
  990. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  991. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  992. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  993. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  994. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  995. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  996. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  997. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  998. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  999. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  1000. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  1001. rt_rule_entry = &rt_rule->rules[1];
  1002. rt_rule_entry->at_rear = 0;
  1003. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  1004. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  1005. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  1006. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  1007. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  1008. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  1009. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000AA;
  1010. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  1011. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  1012. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  1013. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  1014. rt_rule_entry = &rt_rule->rules[2];
  1015. rt_rule_entry->at_rear = 1;
  1016. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  1017. if (false == m_routing.AddRoutingRule(rt_rule))
  1018. {
  1019. printf("Routing rule addition failed!\n");
  1020. return false;
  1021. }
  1022. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  1023. free(rt_rule);
  1024. InitFilteringBlock();
  1025. return true;
  1026. }
  1027. };
  1028. /*---------------------------------------------------------------------------*/
  1029. /* Test6: IPv6 - Tests routing by destination address */
  1030. /*---------------------------------------------------------------------------*/
  1031. class IpaRoutingBlockTest006 : public IpaRoutingBlockTestFixture
  1032. {
  1033. public:
  1034. IpaRoutingBlockTest006()
  1035. {
  1036. m_name = "IpaRoutingBlockTest006";
  1037. m_description =" \
  1038. Routing block test 006 - IPv6 Destination address Subnet match \
  1039. 1. Generate and commit a single routing tables. \
  1040. 2. Generate and commit Three routing rules: (DST & Mask Match 0xFFFFFFFF,0xFFFFFFFF,0x00000000,0x0000000). \
  1041. All DST_IP == 0X11020000 \
  1042. 0x00000000 \
  1043. 0x00000000 \
  1044. 0X0000000C \
  1045. traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  1046. All DST_IP == 0X22020000 \
  1047. 0x00000000 \
  1048. 0x00000000 \
  1049. 0X0000000C \
  1050. traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  1051. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  1052. m_IpaIPType = IPA_IP_v6;
  1053. Register(*this);
  1054. }
  1055. bool Run()
  1056. {
  1057. bool res = false;
  1058. bool isSuccess = false;
  1059. // Add the relevant routing rules
  1060. res = AddRules();
  1061. if (false == res) {
  1062. printf("Failed adding routing rules.\n");
  1063. return false;
  1064. }
  1065. // Load input data (IP packet) from file
  1066. res = LoadFiles(IPA_IP_v6);
  1067. if (false == res) {
  1068. printf("Failed loading files.\n");
  1069. return false;
  1070. }
  1071. // Send first packet
  1072. m_sendBuffer[DST_ADDR_MSB_OFFSET_IPV6] = 0x11;
  1073. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  1074. if (false == isSuccess)
  1075. {
  1076. printf("SendData failure.\n");
  1077. return false;
  1078. }
  1079. // Send second packet
  1080. m_sendBuffer2[DST_ADDR_MSB_OFFSET_IPV6] = 0x22;
  1081. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  1082. if (false == isSuccess)
  1083. {
  1084. printf("SendData failure.\n");
  1085. return false;
  1086. }
  1087. // Send third packet
  1088. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  1089. if (false == isSuccess)
  1090. {
  1091. printf("SendData failure.\n");
  1092. return false;
  1093. }
  1094. // Receive packets from the channels and compare results
  1095. isSuccess = ReceivePacketsAndCompare();
  1096. return isSuccess;
  1097. } // Run()
  1098. bool AddRules()
  1099. {
  1100. struct ipa_ioc_add_rt_rule *rt_rule;
  1101. struct ipa_rt_rule_add *rt_rule_entry;
  1102. const int NUM_RULES = 3;
  1103. rt_rule = (struct ipa_ioc_add_rt_rule *)
  1104. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  1105. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  1106. if(!rt_rule) {
  1107. printf("fail\n");
  1108. return false;
  1109. }
  1110. rt_rule->commit = 1;
  1111. rt_rule->num_rules = NUM_RULES;
  1112. rt_rule->ip = IPA_IP_v6;
  1113. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  1114. rt_rule_entry = &rt_rule->rules[0];
  1115. rt_rule_entry->at_rear = 0;
  1116. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  1117. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // TODO: Header Insertion gidons, there is no support for header insertion / removal yet.
  1118. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  1119. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0X11020000;
  1120. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  1121. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  1122. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X0000000C;
  1123. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  1124. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  1125. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0x00000000;
  1126. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0x00000000;
  1127. rt_rule_entry = &rt_rule->rules[1];
  1128. rt_rule_entry->at_rear = 0;
  1129. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  1130. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // TODO: Header Insertion gidons, there is no support for header insertion / removal yet.
  1131. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  1132. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0X22020000;
  1133. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  1134. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  1135. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X0000000C;
  1136. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  1137. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  1138. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0x00000000;
  1139. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0x00000000;
  1140. rt_rule_entry = &rt_rule->rules[2];
  1141. rt_rule_entry->at_rear = 1;
  1142. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  1143. if (false == m_routing.AddRoutingRule(rt_rule))
  1144. {
  1145. printf("Routing rule addition failed!\n");
  1146. return false;
  1147. }
  1148. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  1149. free(rt_rule);
  1150. InitFilteringBlock();
  1151. return true;
  1152. }
  1153. };
  1154. /*---------------------------------------------------------------------------*/
  1155. /* Test7: IPv6 - Tests routing by destination address */
  1156. /*---------------------------------------------------------------------------*/
  1157. class IpaRoutingBlockTest007 : public IpaRoutingBlockTestFixture
  1158. {
  1159. public:
  1160. IpaRoutingBlockTest007()
  1161. {
  1162. m_name = "IpaRoutingBlockTest007";
  1163. m_description = " \
  1164. Routing block test 007 - IPv6 Exact Traffic Class Match \
  1165. 1. Generate and commit a single routing tables. \
  1166. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  1167. All Traffic Class == 0xAA traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  1168. All Traffic Class == 0xBB traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  1169. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  1170. m_IpaIPType = IPA_IP_v6;
  1171. Register(*this);
  1172. }
  1173. bool Run()
  1174. {
  1175. bool res = false;
  1176. bool isSuccess = false;
  1177. // Add the relevant routing rules
  1178. res = AddRules();
  1179. if (false == res) {
  1180. printf("Failed adding routing rules.\n");
  1181. return false;
  1182. }
  1183. // Load input data (IP packet) from file
  1184. res = LoadFiles(IPA_IP_v6);
  1185. if (false == res) {
  1186. printf("Failed loading files.\n");
  1187. return false;
  1188. }
  1189. // Send first packet
  1190. m_sendBuffer[TRAFFIC_CLASS_MSB_OFFSET_IPV6] &= 0xF0;
  1191. m_sendBuffer[TRAFFIC_CLASS_MSB_OFFSET_IPV6] |= 0x0A;
  1192. m_sendBuffer[TRAFFIC_CLASS_LSB_OFFSET_IPV6] &= 0x0F;
  1193. m_sendBuffer[TRAFFIC_CLASS_LSB_OFFSET_IPV6] |= 0xA0;
  1194. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  1195. if (false == isSuccess)
  1196. {
  1197. printf("SendData failure.\n");
  1198. return false;
  1199. }
  1200. // Send second packet
  1201. m_sendBuffer2[TRAFFIC_CLASS_MSB_OFFSET_IPV6] &= 0xF0;
  1202. m_sendBuffer2[TRAFFIC_CLASS_MSB_OFFSET_IPV6] |= 0x0B;
  1203. m_sendBuffer2[TRAFFIC_CLASS_LSB_OFFSET_IPV6] &= 0x0F;
  1204. m_sendBuffer2[TRAFFIC_CLASS_LSB_OFFSET_IPV6] |= 0xB0;
  1205. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  1206. if (false == isSuccess)
  1207. {
  1208. printf("SendData failure.\n");
  1209. return false;
  1210. }
  1211. // Send third packet
  1212. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  1213. if (false == isSuccess)
  1214. {
  1215. printf("SendData failure.\n");
  1216. return false;
  1217. }
  1218. // Receive packets from the channels and compare results
  1219. isSuccess = ReceivePacketsAndCompare();
  1220. return isSuccess;
  1221. } // Run()
  1222. bool AddRules()
  1223. {
  1224. struct ipa_ioc_add_rt_rule *rt_rule;
  1225. struct ipa_rt_rule_add *rt_rule_entry;
  1226. const int NUM_RULES = 3;
  1227. rt_rule = (struct ipa_ioc_add_rt_rule *)
  1228. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  1229. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  1230. if(!rt_rule) {
  1231. printf("fail\n");
  1232. return false;
  1233. }
  1234. rt_rule->commit = 1;
  1235. rt_rule->num_rules = NUM_RULES;
  1236. rt_rule->ip = IPA_IP_v6;
  1237. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  1238. rt_rule_entry = &rt_rule->rules[0];
  1239. rt_rule_entry->at_rear = 0;
  1240. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  1241. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // TODO: Header Insertion gidons, there is no support for header insertion / removal yet.
  1242. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_TC;
  1243. rt_rule_entry->rule.attrib.u.v6.tc = 0xAA;
  1244. rt_rule_entry = &rt_rule->rules[1];
  1245. rt_rule_entry->at_rear = 0;
  1246. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  1247. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // TODO: Header Insertion gidons, there is no support for header insertion / removal yet.
  1248. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_TC;
  1249. rt_rule_entry->rule.attrib.u.v6.tc = 0xBB;
  1250. rt_rule_entry = &rt_rule->rules[2];
  1251. rt_rule_entry->at_rear = 1;
  1252. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  1253. if (false == m_routing.AddRoutingRule(rt_rule))
  1254. {
  1255. printf("Routing rule addition failed!\n");
  1256. return false;
  1257. }
  1258. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  1259. free(rt_rule);
  1260. InitFilteringBlock();
  1261. return true;
  1262. }
  1263. };
  1264. /*---------------------------------------------------------------------------*/
  1265. /* Test8: IPv6 - Tests routing by destination address */
  1266. /*---------------------------------------------------------------------------*/
  1267. class IpaRoutingBlockTest008 : public IpaRoutingBlockTestFixture
  1268. {
  1269. public:
  1270. IpaRoutingBlockTest008()
  1271. {
  1272. m_name = "IpaRoutingBlockTest008";
  1273. m_description = " \
  1274. Routing block test 008 - IPv6 Destination address exact match and Traffic Class Match \
  1275. 1. Generate and commit a single routing tables. \
  1276. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  1277. All Traffic Class == 0xAA & IPv6 DST Addr 0xFF020000...00AA traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  1278. All Traffic Class == 0xBB & IPv6 DST Addr 0xFF020000...00BB traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  1279. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  1280. m_IpaIPType = IPA_IP_v6;
  1281. Register(*this);
  1282. }
  1283. bool Run()
  1284. {
  1285. bool res = false;
  1286. bool isSuccess = false;
  1287. // Add the relevant routing rules
  1288. res = AddRules();
  1289. if (false == res) {
  1290. printf("Failed adding routing rules.\n");
  1291. return false;
  1292. }
  1293. // Load input data (IP packet) from file
  1294. res = LoadFiles(IPA_IP_v6);
  1295. if (false == res) {
  1296. printf("Failed loading files.\n");
  1297. return false;
  1298. }
  1299. // Send first packet
  1300. m_sendBuffer[TRAFFIC_CLASS_MSB_OFFSET_IPV6] &= 0xF0;
  1301. m_sendBuffer[TRAFFIC_CLASS_MSB_OFFSET_IPV6] |= 0x0A;
  1302. m_sendBuffer[TRAFFIC_CLASS_LSB_OFFSET_IPV6] &= 0x0F;
  1303. m_sendBuffer[TRAFFIC_CLASS_LSB_OFFSET_IPV6] |= 0xA0;
  1304. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  1305. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  1306. if (false == isSuccess)
  1307. {
  1308. printf("SendData failure.\n");
  1309. return false;
  1310. }
  1311. // Send second packet
  1312. m_sendBuffer2[TRAFFIC_CLASS_MSB_OFFSET_IPV6] &= 0xF0;
  1313. m_sendBuffer2[TRAFFIC_CLASS_MSB_OFFSET_IPV6] |= 0x0B;
  1314. m_sendBuffer2[TRAFFIC_CLASS_LSB_OFFSET_IPV6] &= 0x0F;
  1315. m_sendBuffer2[TRAFFIC_CLASS_LSB_OFFSET_IPV6] |= 0xB0;
  1316. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xAA;
  1317. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  1318. if (false == isSuccess)
  1319. {
  1320. printf("SendData failure.\n");
  1321. return false;
  1322. }
  1323. // Send third packet
  1324. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  1325. if (false == isSuccess)
  1326. {
  1327. printf("SendData failure.\n");
  1328. return false;
  1329. }
  1330. // Receive packets from the channels and compare results
  1331. isSuccess = ReceivePacketsAndCompare();
  1332. return isSuccess;
  1333. } // Run()
  1334. bool AddRules()
  1335. {
  1336. struct ipa_ioc_add_rt_rule *rt_rule;
  1337. struct ipa_rt_rule_add *rt_rule_entry;
  1338. const int NUM_RULES = 3;
  1339. rt_rule = (struct ipa_ioc_add_rt_rule *)
  1340. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  1341. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  1342. if(!rt_rule) {
  1343. printf("fail\n");
  1344. return false;
  1345. }
  1346. rt_rule->commit = 1;
  1347. rt_rule->num_rules = NUM_RULES;
  1348. rt_rule->ip = IPA_IP_v6;
  1349. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  1350. rt_rule_entry = &rt_rule->rules[0];
  1351. rt_rule_entry->at_rear = 0;
  1352. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  1353. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  1354. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR | IPA_FLT_TC;
  1355. rt_rule_entry->rule.attrib.u.v6.tc = 0xAA;
  1356. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  1357. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  1358. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  1359. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  1360. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  1361. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  1362. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  1363. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  1364. rt_rule_entry = &rt_rule->rules[1];
  1365. rt_rule_entry->at_rear = 0;
  1366. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  1367. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  1368. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR | IPA_FLT_TC;
  1369. rt_rule_entry->rule.attrib.u.v6.tc = 0xBB;
  1370. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  1371. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  1372. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  1373. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000AA;
  1374. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  1375. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  1376. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  1377. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  1378. rt_rule_entry = &rt_rule->rules[2];
  1379. rt_rule_entry->at_rear = 1;
  1380. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  1381. if (false == m_routing.AddRoutingRule(rt_rule))
  1382. {
  1383. printf("Routing rule addition failed!\n");
  1384. return false;
  1385. }
  1386. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  1387. free(rt_rule);
  1388. InitFilteringBlock();
  1389. return true;
  1390. }
  1391. };
  1392. /*---------------------------------------------------------------------------*/
  1393. /* Test9: IPv6 - Tests routing by destination address */
  1394. /*---------------------------------------------------------------------------*/
  1395. class IpaRoutingBlockTest009 : public IpaRoutingBlockTestFixture
  1396. {
  1397. public:
  1398. IpaRoutingBlockTest009()
  1399. {
  1400. m_name = "IpaRoutingBlockTest009";
  1401. m_description = " \
  1402. Routing block test 009 - IPv6 Exact Flow Label Match \
  1403. 1. Generate and commit a single routing tables. \
  1404. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  1405. All Flow Label == 0xABCDE traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  1406. All Flow Label == 0x12345 traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  1407. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  1408. m_IpaIPType = IPA_IP_v6;
  1409. Register(*this);
  1410. }
  1411. bool Run()
  1412. {
  1413. bool res = false;
  1414. bool isSuccess = false;
  1415. // Add the relevant routing rules
  1416. res = AddRules();
  1417. if (false == res) {
  1418. printf("Failed adding routing rules.\n");
  1419. return false;
  1420. }
  1421. // Load input data (IP packet) from file
  1422. res = LoadFiles(IPA_IP_v6);
  1423. if (false == res) {
  1424. printf("Failed loading files.\n");
  1425. return false;
  1426. }
  1427. // Send first packet
  1428. m_sendBuffer[FLOW_CLASS_MSB_OFFSET_IPV6] &= 0xF0;
  1429. m_sendBuffer[FLOW_CLASS_MSB_OFFSET_IPV6] |= 0x0A;
  1430. m_sendBuffer[FLOW_CLASS_MB_OFFSET_IPV6] = 0xBC;
  1431. m_sendBuffer[FLOW_CLASS_LSB_OFFSET_IPV6] = 0xDE;
  1432. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  1433. if (false == isSuccess)
  1434. {
  1435. printf("SendData failure.\n");
  1436. return false;
  1437. }
  1438. // Send second packet
  1439. m_sendBuffer2[FLOW_CLASS_MSB_OFFSET_IPV6] &= 0xF0;
  1440. m_sendBuffer2[FLOW_CLASS_MSB_OFFSET_IPV6] |= 0x01;
  1441. m_sendBuffer2[FLOW_CLASS_MB_OFFSET_IPV6] = 0x23;
  1442. m_sendBuffer2[FLOW_CLASS_LSB_OFFSET_IPV6] = 0x45;
  1443. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  1444. if (false == isSuccess)
  1445. {
  1446. printf("SendData failure.\n");
  1447. return false;
  1448. }
  1449. // Send third packet
  1450. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  1451. if (false == isSuccess)
  1452. {
  1453. printf("SendData failure.\n");
  1454. return false;
  1455. }
  1456. // Receive packets from the channels and compare results
  1457. isSuccess = ReceivePacketsAndCompare();
  1458. return isSuccess;
  1459. } // Run()
  1460. bool AddRules()
  1461. {
  1462. struct ipa_ioc_add_rt_rule *rt_rule;
  1463. struct ipa_rt_rule_add *rt_rule_entry;
  1464. const int NUM_RULES = 3;
  1465. rt_rule = (struct ipa_ioc_add_rt_rule *)
  1466. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  1467. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  1468. if(!rt_rule) {
  1469. printf("fail\n");
  1470. return false;
  1471. }
  1472. rt_rule->commit = 1;
  1473. rt_rule->num_rules = NUM_RULES;
  1474. rt_rule->ip = IPA_IP_v6;
  1475. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  1476. rt_rule_entry = &rt_rule->rules[0];
  1477. rt_rule_entry->at_rear = 0;
  1478. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  1479. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  1480. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_FLOW_LABEL;
  1481. rt_rule_entry->rule.attrib.u.v6.flow_label = 0xABCDE;
  1482. rt_rule_entry = &rt_rule->rules[1];
  1483. rt_rule_entry->at_rear = 0;
  1484. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  1485. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  1486. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_FLOW_LABEL;
  1487. rt_rule_entry->rule.attrib.u.v6.flow_label = 0x12345;
  1488. rt_rule_entry = &rt_rule->rules[2];
  1489. rt_rule_entry->at_rear = 1;
  1490. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  1491. if (false == m_routing.AddRoutingRule(rt_rule))
  1492. {
  1493. printf("Routing rule addition failed!\n");
  1494. return false;
  1495. }
  1496. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  1497. free(rt_rule);
  1498. InitFilteringBlock();
  1499. return true;
  1500. }
  1501. };
  1502. /*--------------------------------------------------------------------------*/
  1503. /* Test10: IPv4 - Tests routing hashable vs non hashable priorities */
  1504. /*--------------------------------------------------------------------------*/
  1505. class IpaRoutingBlockTest010 : public IpaRoutingBlockTestFixture
  1506. {
  1507. public:
  1508. IpaRoutingBlockTest010()
  1509. {
  1510. m_name = "IpaRoutingBlockTest10";
  1511. m_description =" \
  1512. Routing block test 010 - Destination address exact match non hashable priority higher than hashable \
  1513. both match the packet but only non hashable should hit\
  1514. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  1515. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  1516. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  1517. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  1518. m_IpaIPType = IPA_IP_v4;
  1519. m_minIPAHwType = IPA_HW_v3_0;
  1520. Register(*this);
  1521. }
  1522. bool AddRules()
  1523. {
  1524. struct ipa_ioc_add_rt_rule *rt_rule;
  1525. struct ipa_rt_rule_add *rt_rule_entry;
  1526. const int NUM_RULES = 3;
  1527. rt_rule = (struct ipa_ioc_add_rt_rule *)
  1528. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  1529. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  1530. if(!rt_rule) {
  1531. printf("fail\n");
  1532. return false;
  1533. }
  1534. rt_rule->commit = 1;
  1535. rt_rule->num_rules = NUM_RULES;
  1536. rt_rule->ip = IPA_IP_v4;
  1537. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  1538. rt_rule_entry = &rt_rule->rules[0];
  1539. rt_rule_entry->at_rear = 1;
  1540. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  1541. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  1542. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  1543. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  1544. rt_rule_entry->rule.hashable = 0; // non hashable
  1545. rt_rule_entry = &rt_rule->rules[1];
  1546. rt_rule_entry->at_rear = 1;
  1547. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  1548. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  1549. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  1550. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  1551. rt_rule_entry->rule.hashable = 1; // hashable
  1552. rt_rule_entry = &rt_rule->rules[2];
  1553. rt_rule_entry->at_rear = 1;
  1554. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  1555. if (false == m_routing.AddRoutingRule(rt_rule))
  1556. {
  1557. printf("Routing rule addition failed!\n");
  1558. return false;
  1559. }
  1560. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  1561. free(rt_rule);
  1562. InitFilteringBlock();
  1563. return true;
  1564. }
  1565. bool Run()
  1566. {
  1567. bool res = false;
  1568. bool isSuccess = false;
  1569. // Add the relevant routing rules
  1570. res = AddRules();
  1571. if (false == res) {
  1572. printf("Failed adding routing rules.\n");
  1573. return false;
  1574. }
  1575. // Load input data (IP packet) from file
  1576. res = LoadFiles(IPA_IP_v4);
  1577. if (false == res) {
  1578. printf("Failed loading files.\n");
  1579. return false;
  1580. }
  1581. // Send first packet
  1582. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  1583. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  1584. if (false == isSuccess)
  1585. {
  1586. printf("SendData failure.\n");
  1587. return false;
  1588. }
  1589. // Send second packet
  1590. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  1591. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  1592. if (false == isSuccess)
  1593. {
  1594. printf("SendData failure.\n");
  1595. return false;
  1596. }
  1597. // Send third packet
  1598. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  1599. if (false == isSuccess)
  1600. {
  1601. printf("SendData failure.\n");
  1602. return false;
  1603. }
  1604. // Receive packets from the channels and compare results
  1605. isSuccess = ReceivePacketsAndCompare();
  1606. return isSuccess;
  1607. } // Run()
  1608. bool ReceivePacketsAndCompare()
  1609. {
  1610. size_t receivedSize = 0;
  1611. size_t receivedSize2 = 0;
  1612. size_t receivedSize3 = 0;
  1613. bool isSuccess = true;
  1614. // Receive results
  1615. Byte *rxBuff1 = new Byte[0x400];
  1616. Byte *rxBuff2 = new Byte[0x400];
  1617. Byte *rxBuff3 = new Byte[0x400];
  1618. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  1619. {
  1620. printf("Memory allocation error.\n");
  1621. return false;
  1622. }
  1623. receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400);
  1624. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  1625. receivedSize2 = m_consumer.ReceiveData(rxBuff2, 0x400);
  1626. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer2.m_fromChannelName.c_str());
  1627. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  1628. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  1629. /* Compare results */
  1630. isSuccess &= CompareResultVsGolden(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  1631. isSuccess &= CompareResultVsGolden(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  1632. isSuccess &= CompareResultVsGolden(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  1633. size_t recievedBufferSize = receivedSize * 3;
  1634. size_t sentBufferSize = m_sendSize * 3;
  1635. char *recievedBuffer = new char[recievedBufferSize];
  1636. char *sentBuffer = new char[sentBufferSize];
  1637. memset(recievedBuffer, 0, recievedBufferSize);
  1638. memset(sentBuffer, 0, sentBufferSize);
  1639. print_packets(receivedSize, m_sendSize, recievedBufferSize, sentBufferSize, rxBuff1, m_sendBuffer, recievedBuffer, sentBuffer);
  1640. print_packets(receivedSize2, m_sendSize2, recievedBufferSize, sentBufferSize, rxBuff2, m_sendBuffer2, recievedBuffer, sentBuffer);
  1641. print_packets(receivedSize3, m_sendSize3, recievedBufferSize, sentBufferSize, rxBuff3, m_sendBuffer3, recievedBuffer, sentBuffer);
  1642. delete[] recievedBuffer;
  1643. delete[] sentBuffer;
  1644. delete[] rxBuff1;
  1645. delete[] rxBuff2;
  1646. delete[] rxBuff3;
  1647. return isSuccess;
  1648. }
  1649. };
  1650. /*--------------------------------------------------------------------------*/
  1651. /* Test11: IPv4 - Tests routing hashable vs non hashable priorities */
  1652. /*--------------------------------------------------------------------------*/
  1653. class IpaRoutingBlockTest011 : public IpaRoutingBlockTestFixture
  1654. {
  1655. public:
  1656. IpaRoutingBlockTest011()
  1657. {
  1658. m_name = "IpaRoutingBlockTest011";
  1659. m_description =" \
  1660. Routing block test 011 - Destination address exact match hashable priority higher than non hashable \
  1661. both match the packet but only hashable should hit, second packet should get cache hit\
  1662. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  1663. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  1664. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  1665. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  1666. m_IpaIPType = IPA_IP_v4;
  1667. m_minIPAHwType = IPA_HW_v3_0;
  1668. Register(*this);
  1669. }
  1670. bool Setup()
  1671. {
  1672. return IpaRoutingBlockTestFixture:: Setup(true);
  1673. }
  1674. bool AddRules()
  1675. {
  1676. struct ipa_ioc_add_rt_rule *rt_rule;
  1677. struct ipa_rt_rule_add *rt_rule_entry;
  1678. const int NUM_RULES = 3;
  1679. rt_rule = (struct ipa_ioc_add_rt_rule *)
  1680. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  1681. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  1682. if(!rt_rule) {
  1683. printf("fail\n");
  1684. return false;
  1685. }
  1686. rt_rule->commit = 1;
  1687. rt_rule->num_rules = NUM_RULES;
  1688. rt_rule->ip = IPA_IP_v4;
  1689. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  1690. rt_rule_entry = &rt_rule->rules[0];
  1691. rt_rule_entry->at_rear = 1;
  1692. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  1693. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  1694. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  1695. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  1696. rt_rule_entry->rule.hashable = 1; // hashable
  1697. rt_rule_entry = &rt_rule->rules[1];
  1698. rt_rule_entry->at_rear = 1;
  1699. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  1700. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  1701. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  1702. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  1703. rt_rule_entry->rule.hashable = 0; // non hashable
  1704. rt_rule_entry = &rt_rule->rules[2];
  1705. rt_rule_entry->at_rear = 1;
  1706. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  1707. if (false == m_routing.AddRoutingRule(rt_rule))
  1708. {
  1709. printf("Routing rule addition failed!\n");
  1710. return false;
  1711. }
  1712. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  1713. free(rt_rule);
  1714. InitFilteringBlock();
  1715. return true;
  1716. }
  1717. bool Run()
  1718. {
  1719. bool res = false;
  1720. bool isSuccess = false;
  1721. // Add the relevant routing rules
  1722. res = AddRules();
  1723. if (false == res) {
  1724. printf("Failed adding routing rules.\n");
  1725. return false;
  1726. }
  1727. // Load input data (IP packet) from file
  1728. res = LoadFiles(IPA_IP_v4);
  1729. if (false == res) {
  1730. printf("Failed loading files.\n");
  1731. return false;
  1732. }
  1733. // Send first packet
  1734. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  1735. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  1736. if (false == isSuccess)
  1737. {
  1738. printf("SendData failure.\n");
  1739. return false;
  1740. }
  1741. // Send second packet
  1742. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  1743. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  1744. if (false == isSuccess)
  1745. {
  1746. printf("SendData failure.\n");
  1747. return false;
  1748. }
  1749. // Send third packet
  1750. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  1751. if (false == isSuccess)
  1752. {
  1753. printf("SendData failure.\n");
  1754. return false;
  1755. }
  1756. // Receive packets from the channels and compare results
  1757. isSuccess = ReceivePacketsAndCompare();
  1758. return isSuccess;
  1759. } // Run()
  1760. bool ReceivePacketsAndCompare()
  1761. {
  1762. size_t receivedSize = 0;
  1763. size_t receivedSize2 = 0;
  1764. size_t receivedSize3 = 0;
  1765. bool isSuccess = true;
  1766. // Receive results
  1767. Byte *rxBuff1 = new Byte[0x400];
  1768. Byte *rxBuff2 = new Byte[0x400];
  1769. Byte *rxBuff3 = new Byte[0x400];
  1770. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  1771. {
  1772. printf("Memory allocation error.\n");
  1773. return false;
  1774. }
  1775. receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400);
  1776. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  1777. receivedSize2 = m_consumer.ReceiveData(rxBuff2, 0x400);
  1778. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer2.m_fromChannelName.c_str());
  1779. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  1780. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  1781. /* Compare results */
  1782. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  1783. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  1784. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  1785. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  1786. IsCacheMiss_v5_0(m_sendSize, receivedSize, rxBuff1) : IsCacheMiss(m_sendSize,receivedSize,rxBuff1);
  1787. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  1788. IsCacheHit_v5_0(m_sendSize2, receivedSize2, rxBuff2) : IsCacheHit(m_sendSize2,receivedSize2,rxBuff2);
  1789. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  1790. IsCacheMiss_v5_0(m_sendSize3, receivedSize3, rxBuff3) : IsCacheMiss(m_sendSize3,receivedSize3,rxBuff3);
  1791. size_t recievedBufferSize = receivedSize * 3;
  1792. size_t sentBufferSize = m_sendSize * 3;
  1793. char *recievedBuffer = new char[recievedBufferSize];
  1794. char *sentBuffer = new char[sentBufferSize];
  1795. memset(recievedBuffer, 0, recievedBufferSize);
  1796. memset(sentBuffer, 0, sentBufferSize);
  1797. print_packets(receivedSize, m_sendSize, recievedBufferSize, sentBufferSize, rxBuff1, m_sendBuffer, recievedBuffer, sentBuffer);
  1798. print_packets(receivedSize2, m_sendSize2, recievedBufferSize, sentBufferSize, rxBuff2, m_sendBuffer2, recievedBuffer, sentBuffer);
  1799. print_packets(receivedSize3, m_sendSize3, recievedBufferSize, sentBufferSize, rxBuff3, m_sendBuffer3, recievedBuffer, sentBuffer);
  1800. delete[] recievedBuffer;
  1801. delete[] sentBuffer;
  1802. delete[] rxBuff1;
  1803. delete[] rxBuff2;
  1804. delete[] rxBuff3;
  1805. return isSuccess;
  1806. }
  1807. };
  1808. /*--------------------------------------------------------------------------*/
  1809. /* Test12: IPv4 - Tests routing hashable vs non hashable priorities */
  1810. /*--------------------------------------------------------------------------*/
  1811. class IpaRoutingBlockTest012 : public IpaRoutingBlockTestFixture
  1812. {
  1813. public:
  1814. IpaRoutingBlockTest012()
  1815. {
  1816. m_name = "IpaRoutingBlockTest012";
  1817. m_description =" \
  1818. Routing block test 012 - Destination address exact match hashable priority lower than non hashable \
  1819. no match on non hashable rule (with higher priority), match on hashable rule. two packets with\
  1820. different tuple are sent (but match the rule) cache miss expected\
  1821. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  1822. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  1823. All DST_IP == (192.168.2.171 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  1824. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  1825. m_IpaIPType = IPA_IP_v4;
  1826. m_minIPAHwType = IPA_HW_v3_0;
  1827. Register(*this);
  1828. }
  1829. bool Setup()
  1830. {
  1831. return IpaRoutingBlockTestFixture:: Setup(true);
  1832. }
  1833. bool AddRules()
  1834. {
  1835. struct ipa_ioc_add_rt_rule *rt_rule;
  1836. struct ipa_rt_rule_add *rt_rule_entry;
  1837. const int NUM_RULES = 3;
  1838. rt_rule = (struct ipa_ioc_add_rt_rule *)
  1839. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  1840. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  1841. if(!rt_rule) {
  1842. printf("fail\n");
  1843. return false;
  1844. }
  1845. rt_rule->commit = 1;
  1846. rt_rule->num_rules = NUM_RULES;
  1847. rt_rule->ip = IPA_IP_v4;
  1848. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  1849. rt_rule_entry = &rt_rule->rules[0];
  1850. rt_rule_entry->at_rear = 1;
  1851. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  1852. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  1853. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AB; //192.168.02.171
  1854. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  1855. rt_rule_entry->rule.hashable = 0; // non hashable
  1856. rt_rule_entry = &rt_rule->rules[1];
  1857. rt_rule_entry->at_rear = 1;
  1858. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  1859. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  1860. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  1861. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  1862. rt_rule_entry->rule.hashable = 1; // hashable
  1863. rt_rule_entry = &rt_rule->rules[2];
  1864. rt_rule_entry->at_rear = 1;
  1865. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  1866. if (false == m_routing.AddRoutingRule(rt_rule))
  1867. {
  1868. printf("Routing rule addition failed!\n");
  1869. return false;
  1870. }
  1871. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  1872. free(rt_rule);
  1873. InitFilteringBlock();
  1874. return true;
  1875. }
  1876. bool Run()
  1877. {
  1878. bool res = false;
  1879. bool isSuccess = false;
  1880. unsigned short port;
  1881. // Add the relevant routing rules
  1882. res = AddRules();
  1883. if (false == res) {
  1884. printf("Failed adding routing rules.\n");
  1885. return false;
  1886. }
  1887. // Load input data (IP packet) from file
  1888. res = LoadFiles(IPA_IP_v4);
  1889. if (false == res) {
  1890. printf("Failed loading files.\n");
  1891. return false;
  1892. }
  1893. // Send first packet
  1894. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  1895. port = ntohs(547);//DHCP Client Port
  1896. memcpy (&m_sendBuffer[IPV4_DST_PORT_OFFSET], &port, sizeof(port));
  1897. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  1898. if (false == isSuccess)
  1899. {
  1900. printf("SendData failure.\n");
  1901. return false;
  1902. }
  1903. // Send second packet
  1904. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  1905. port = ntohs(546);//DHCP Client Port
  1906. memcpy (&m_sendBuffer2[IPV4_DST_PORT_OFFSET], &port, sizeof(port));
  1907. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  1908. if (false == isSuccess)
  1909. {
  1910. printf("SendData failure.\n");
  1911. return false;
  1912. }
  1913. // Send third packet
  1914. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  1915. if (false == isSuccess)
  1916. {
  1917. printf("SendData failure.\n");
  1918. return false;
  1919. }
  1920. // Receive packets from the channels and compare results
  1921. isSuccess = ReceivePacketsAndCompare();
  1922. return isSuccess;
  1923. } // Run()
  1924. bool ReceivePacketsAndCompare()
  1925. {
  1926. size_t receivedSize = 0;
  1927. size_t receivedSize2 = 0;
  1928. size_t receivedSize3 = 0;
  1929. bool isSuccess = true;
  1930. // Receive results
  1931. Byte *rxBuff1 = new Byte[0x400];
  1932. Byte *rxBuff2 = new Byte[0x400];
  1933. Byte *rxBuff3 = new Byte[0x400];
  1934. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  1935. {
  1936. printf("Memory allocation error.\n");
  1937. return false;
  1938. }
  1939. receivedSize = m_consumer2.ReceiveData(rxBuff1, 0x400);
  1940. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer2.m_fromChannelName.c_str());
  1941. receivedSize2 = m_consumer2.ReceiveData(rxBuff2, 0x400);
  1942. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer2.m_fromChannelName.c_str());
  1943. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  1944. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  1945. /* Compare results */
  1946. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  1947. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  1948. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  1949. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  1950. IsCacheMiss_v5_0(m_sendSize, receivedSize, rxBuff1) : IsCacheMiss(m_sendSize,receivedSize,rxBuff1);
  1951. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  1952. IsCacheMiss_v5_0(m_sendSize2, receivedSize2, rxBuff2) : IsCacheMiss(m_sendSize2,receivedSize2,rxBuff2);
  1953. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  1954. IsCacheMiss_v5_0(m_sendSize3, receivedSize3, rxBuff3) : IsCacheMiss(m_sendSize3,receivedSize3,rxBuff3);
  1955. size_t recievedBufferSize = receivedSize * 3;
  1956. size_t sentBufferSize = m_sendSize * 3;
  1957. char *recievedBuffer = new char[recievedBufferSize];
  1958. char *sentBuffer = new char[sentBufferSize];
  1959. memset(recievedBuffer, 0, recievedBufferSize);
  1960. memset(sentBuffer, 0, sentBufferSize);
  1961. print_packets(receivedSize, m_sendSize, recievedBufferSize, sentBufferSize, rxBuff1, m_sendBuffer, recievedBuffer, sentBuffer);
  1962. print_packets(receivedSize2, m_sendSize2, recievedBufferSize, sentBufferSize, rxBuff2, m_sendBuffer2, recievedBuffer, sentBuffer);
  1963. print_packets(receivedSize3, m_sendSize3, recievedBufferSize, sentBufferSize, rxBuff3, m_sendBuffer3, recievedBuffer, sentBuffer);
  1964. delete[] recievedBuffer;
  1965. delete[] sentBuffer;
  1966. delete[] rxBuff1;
  1967. delete[] rxBuff2;
  1968. delete[] rxBuff3;
  1969. return isSuccess;
  1970. }
  1971. };
  1972. /*--------------------------------------------------------------------------*/
  1973. /* Test13: IPv4 - Tests routing hashable vs non hashable priorities */
  1974. /*--------------------------------------------------------------------------*/
  1975. class IpaRoutingBlockTest013 : public IpaRoutingBlockTestFixture
  1976. {
  1977. public:
  1978. IpaRoutingBlockTest013()
  1979. {
  1980. m_name = "IpaRoutingBlockTest013";
  1981. m_description =" \
  1982. Routing block test 013 - Destination address exact match \
  1983. no match on non hashable rule (with lower priority), match on hashable rule. two packets with\
  1984. different tuple are sent (but match the rule) cache miss expected\
  1985. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  1986. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  1987. All DST_IP == (192.168.2.171 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  1988. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  1989. m_IpaIPType = IPA_IP_v4;
  1990. m_minIPAHwType = IPA_HW_v3_0;
  1991. Register(*this);
  1992. }
  1993. bool Setup()
  1994. {
  1995. return IpaRoutingBlockTestFixture:: Setup(true);
  1996. }
  1997. bool AddRules()
  1998. {
  1999. struct ipa_ioc_add_rt_rule *rt_rule;
  2000. struct ipa_rt_rule_add *rt_rule_entry;
  2001. const int NUM_RULES = 3;
  2002. rt_rule = (struct ipa_ioc_add_rt_rule *)
  2003. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  2004. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  2005. if(!rt_rule) {
  2006. printf("fail\n");
  2007. return false;
  2008. }
  2009. rt_rule->commit = 1;
  2010. rt_rule->num_rules = NUM_RULES;
  2011. rt_rule->ip = IPA_IP_v4;
  2012. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  2013. rt_rule_entry = &rt_rule->rules[0];
  2014. rt_rule_entry->at_rear = 1;
  2015. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  2016. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  2017. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  2018. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  2019. rt_rule_entry->rule.hashable = 1; // hashable
  2020. rt_rule_entry = &rt_rule->rules[1];
  2021. rt_rule_entry->at_rear = 1;
  2022. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  2023. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  2024. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AB; //192.168.02.171
  2025. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  2026. rt_rule_entry->rule.hashable = 0; // non hashable
  2027. rt_rule_entry = &rt_rule->rules[2];
  2028. rt_rule_entry->at_rear = 1;
  2029. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  2030. if (false == m_routing.AddRoutingRule(rt_rule))
  2031. {
  2032. printf("Routing rule addition failed!\n");
  2033. return false;
  2034. }
  2035. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  2036. free(rt_rule);
  2037. InitFilteringBlock();
  2038. return true;
  2039. }
  2040. bool Run()
  2041. {
  2042. bool res = false;
  2043. bool isSuccess = false;
  2044. unsigned short port;
  2045. // Add the relevant routing rules
  2046. res = AddRules();
  2047. if (false == res) {
  2048. printf("Failed adding routing rules.\n");
  2049. return false;
  2050. }
  2051. // Load input data (IP packet) from file
  2052. res = LoadFiles(IPA_IP_v4);
  2053. if (false == res) {
  2054. printf("Failed loading files.\n");
  2055. return false;
  2056. }
  2057. // Send first packet
  2058. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2059. port = ntohs(547);//DHCP Client Port
  2060. memcpy (&m_sendBuffer[IPV4_DST_PORT_OFFSET], &port, sizeof(port));
  2061. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  2062. if (false == isSuccess)
  2063. {
  2064. printf("SendData failure.\n");
  2065. return false;
  2066. }
  2067. // Send second packet
  2068. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2069. port = ntohs(546);//DHCP Client Port
  2070. memcpy (&m_sendBuffer2[IPV4_DST_PORT_OFFSET], &port, sizeof(port));
  2071. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  2072. if (false == isSuccess)
  2073. {
  2074. printf("SendData failure.\n");
  2075. return false;
  2076. }
  2077. // Send third packet
  2078. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  2079. if (false == isSuccess)
  2080. {
  2081. printf("SendData failure.\n");
  2082. return false;
  2083. }
  2084. // Receive packets from the channels and compare results
  2085. isSuccess = ReceivePacketsAndCompare();
  2086. return isSuccess;
  2087. } // Run()
  2088. bool ReceivePacketsAndCompare()
  2089. {
  2090. size_t receivedSize = 0;
  2091. size_t receivedSize2 = 0;
  2092. size_t receivedSize3 = 0;
  2093. bool isSuccess = true;
  2094. // Receive results
  2095. Byte *rxBuff1 = new Byte[0x400];
  2096. Byte *rxBuff2 = new Byte[0x400];
  2097. Byte *rxBuff3 = new Byte[0x400];
  2098. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  2099. {
  2100. printf("Memory allocation error.\n");
  2101. return false;
  2102. }
  2103. receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400);
  2104. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  2105. receivedSize2 = m_consumer.ReceiveData(rxBuff2, 0x400);
  2106. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer.m_fromChannelName.c_str());
  2107. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  2108. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  2109. /* Compare results */
  2110. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  2111. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  2112. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  2113. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  2114. IsCacheMiss_v5_0(m_sendSize, receivedSize, rxBuff1) : IsCacheMiss(m_sendSize,receivedSize,rxBuff1);
  2115. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  2116. IsCacheMiss_v5_0(m_sendSize2, receivedSize2, rxBuff2) : IsCacheMiss(m_sendSize2,receivedSize2,rxBuff2);
  2117. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  2118. IsCacheMiss_v5_0(m_sendSize3, receivedSize3, rxBuff3) : IsCacheMiss(m_sendSize3,receivedSize3,rxBuff3);
  2119. size_t recievedBufferSize = receivedSize * 3;
  2120. size_t sentBufferSize = m_sendSize * 3;
  2121. char *recievedBuffer = new char[recievedBufferSize];
  2122. char *sentBuffer = new char[sentBufferSize];
  2123. memset(recievedBuffer, 0, recievedBufferSize);
  2124. memset(sentBuffer, 0, sentBufferSize);
  2125. print_packets(receivedSize, m_sendSize, recievedBufferSize, sentBufferSize, rxBuff1, m_sendBuffer, recievedBuffer, sentBuffer);
  2126. print_packets(receivedSize2, m_sendSize2, recievedBufferSize, sentBufferSize, rxBuff2, m_sendBuffer2, recievedBuffer, sentBuffer);
  2127. print_packets(receivedSize3, m_sendSize3, recievedBufferSize, sentBufferSize, rxBuff3, m_sendBuffer3, recievedBuffer, sentBuffer);
  2128. delete[] recievedBuffer;
  2129. delete[] sentBuffer;
  2130. delete[] rxBuff1;
  2131. delete[] rxBuff2;
  2132. delete[] rxBuff3;
  2133. return isSuccess;
  2134. }
  2135. };
  2136. /*--------------------------------------------------------------------------*/
  2137. /* Test14: IPv4 - Tests routing hashable vs non hashable priorities */
  2138. /*--------------------------------------------------------------------------*/
  2139. class IpaRoutingBlockTest014 : public IpaRoutingBlockTestFixture
  2140. {
  2141. public:
  2142. IpaRoutingBlockTest014()
  2143. {
  2144. m_name = "IpaRoutingBlockTest014";
  2145. m_description =" \
  2146. Routing block test 014 - Destination address exact match \
  2147. no match on non hashable rule(with higher priority) , match on hashable rule. two identical\
  2148. packets are sent cache hit expected on the second one\
  2149. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  2150. All DST_IP == (192.168.2.171 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  2151. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  2152. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  2153. m_IpaIPType = IPA_IP_v4;
  2154. m_minIPAHwType = IPA_HW_v3_0;
  2155. Register(*this);
  2156. }
  2157. bool Setup()
  2158. {
  2159. return IpaRoutingBlockTestFixture:: Setup(true);
  2160. }
  2161. bool AddRules()
  2162. {
  2163. struct ipa_ioc_add_rt_rule *rt_rule;
  2164. struct ipa_rt_rule_add *rt_rule_entry;
  2165. const int NUM_RULES = 3;
  2166. rt_rule = (struct ipa_ioc_add_rt_rule *)
  2167. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  2168. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  2169. if(!rt_rule) {
  2170. printf("Failed memory allocation for rt_rule\n");
  2171. return false;
  2172. }
  2173. rt_rule->commit = 1;
  2174. rt_rule->num_rules = NUM_RULES;
  2175. rt_rule->ip = IPA_IP_v4;
  2176. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  2177. rt_rule_entry = &rt_rule->rules[0];
  2178. rt_rule_entry->at_rear = 1;
  2179. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  2180. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  2181. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AB; //192.168.02.171
  2182. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  2183. rt_rule_entry->rule.hashable = 0; // non hashable
  2184. rt_rule_entry = &rt_rule->rules[1];
  2185. rt_rule_entry->at_rear = 1;
  2186. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  2187. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  2188. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  2189. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  2190. rt_rule_entry->rule.hashable = 1; // hashable
  2191. rt_rule_entry = &rt_rule->rules[2];
  2192. rt_rule_entry->at_rear = 1;
  2193. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  2194. if (false == m_routing.AddRoutingRule(rt_rule))
  2195. {
  2196. printf("Routing rule addition failed!\n");
  2197. free(rt_rule);
  2198. return false;
  2199. }
  2200. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  2201. free(rt_rule);
  2202. InitFilteringBlock();
  2203. return true;
  2204. }
  2205. bool Run()
  2206. {
  2207. bool res = false;
  2208. bool isSuccess = false;
  2209. // Add the relevant routing rules
  2210. res = AddRules();
  2211. if (false == res) {
  2212. printf("Failed adding routing rules.\n");
  2213. return false;
  2214. }
  2215. // Load input data (IP packet) from file
  2216. res = LoadFiles(IPA_IP_v4);
  2217. if (false == res) {
  2218. printf("Failed loading files.\n");
  2219. return false;
  2220. }
  2221. // Send first packet
  2222. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2223. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  2224. if (false == isSuccess)
  2225. {
  2226. printf("SendData failure.\n");
  2227. return false;
  2228. }
  2229. // Send second packet
  2230. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2231. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  2232. if (false == isSuccess)
  2233. {
  2234. printf("SendData failure.\n");
  2235. return false;
  2236. }
  2237. // Send third packet
  2238. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  2239. if (false == isSuccess)
  2240. {
  2241. printf("SendData failure.\n");
  2242. return false;
  2243. }
  2244. // Receive packets from the channels and compare results
  2245. isSuccess = ReceivePacketsAndCompare();
  2246. return isSuccess;
  2247. } // Run()
  2248. bool ReceivePacketsAndCompare()
  2249. {
  2250. size_t receivedSize = 0;
  2251. size_t receivedSize2 = 0;
  2252. size_t receivedSize3 = 0;
  2253. bool isSuccess = true;
  2254. // Receive results
  2255. Byte *rxBuff1 = new Byte[0x400];
  2256. Byte *rxBuff2 = new Byte[0x400];
  2257. Byte *rxBuff3 = new Byte[0x400];
  2258. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  2259. {
  2260. printf("Memory allocation error.\n");
  2261. return false;
  2262. }
  2263. receivedSize = m_consumer2.ReceiveData(rxBuff1, 0x400);
  2264. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer2.m_fromChannelName.c_str());
  2265. receivedSize2 = m_consumer2.ReceiveData(rxBuff2, 0x400);
  2266. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer2.m_fromChannelName.c_str());
  2267. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  2268. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  2269. /* Compare results */
  2270. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  2271. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  2272. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  2273. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  2274. IsCacheMiss_v5_0(m_sendSize, receivedSize, rxBuff1) : IsCacheMiss(m_sendSize,receivedSize,rxBuff1);
  2275. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  2276. IsCacheHit_v5_0(m_sendSize2, receivedSize2, rxBuff2) : IsCacheHit(m_sendSize2,receivedSize2,rxBuff2);
  2277. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  2278. IsCacheMiss_v5_0(m_sendSize3, receivedSize3, rxBuff3) : IsCacheMiss(m_sendSize3,receivedSize3,rxBuff3);
  2279. size_t recievedBufferSize = receivedSize * 3;
  2280. size_t sentBufferSize = m_sendSize * 3;
  2281. char *recievedBuffer = new char[recievedBufferSize];
  2282. char *sentBuffer = new char[sentBufferSize];
  2283. memset(recievedBuffer, 0, recievedBufferSize);
  2284. memset(sentBuffer, 0, sentBufferSize);
  2285. print_packets(receivedSize, m_sendSize, recievedBufferSize, sentBufferSize, rxBuff1, m_sendBuffer, recievedBuffer, sentBuffer);
  2286. print_packets(receivedSize2, m_sendSize2, recievedBufferSize, sentBufferSize, rxBuff2, m_sendBuffer2, recievedBuffer, sentBuffer);
  2287. print_packets(receivedSize3, m_sendSize3, recievedBufferSize, sentBufferSize, rxBuff3, m_sendBuffer3, recievedBuffer, sentBuffer);
  2288. delete[] recievedBuffer;
  2289. delete[] sentBuffer;
  2290. delete[] rxBuff1;
  2291. delete[] rxBuff2;
  2292. delete[] rxBuff3;
  2293. return isSuccess;
  2294. }
  2295. };
  2296. /*--------------------------------------------------------------------------*/
  2297. /* Test15: IPv4 - Tests routing hashable vs non hashable priorities */
  2298. /*--------------------------------------------------------------------------*/
  2299. class IpaRoutingBlockTest015 : public IpaRoutingBlockTestFixture
  2300. {
  2301. public:
  2302. IpaRoutingBlockTest015()
  2303. {
  2304. m_name = "IpaRoutingBlockTest015";
  2305. m_description =" \
  2306. Routing block test 015 - Destination address exact match \
  2307. no match on non hashable rule(with lower priority) , match on hashable rule. two identical\
  2308. packets are sent cache hit expected on the second one\
  2309. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  2310. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  2311. All DST_IP == (192.168.2.171 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  2312. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  2313. m_IpaIPType = IPA_IP_v4;
  2314. m_minIPAHwType = IPA_HW_v3_0;
  2315. Register(*this);
  2316. }
  2317. bool Setup()
  2318. {
  2319. return IpaRoutingBlockTestFixture:: Setup(true);
  2320. }
  2321. bool AddRules()
  2322. {
  2323. struct ipa_ioc_add_rt_rule *rt_rule;
  2324. struct ipa_rt_rule_add *rt_rule_entry;
  2325. const int NUM_RULES = 3;
  2326. rt_rule = (struct ipa_ioc_add_rt_rule *)
  2327. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  2328. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  2329. if(!rt_rule) {
  2330. printf("Failed memory allocation for rt_rule\n");
  2331. return false;
  2332. }
  2333. rt_rule->commit = 1;
  2334. rt_rule->num_rules = NUM_RULES;
  2335. rt_rule->ip = IPA_IP_v4;
  2336. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  2337. rt_rule_entry = &rt_rule->rules[0];
  2338. rt_rule_entry->at_rear = 1;
  2339. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  2340. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  2341. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  2342. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  2343. rt_rule_entry->rule.hashable = 1; // hashable
  2344. rt_rule_entry = &rt_rule->rules[1];
  2345. rt_rule_entry->at_rear = 1;
  2346. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  2347. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  2348. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AB; //192.168.02.171
  2349. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  2350. rt_rule_entry->rule.hashable = 0; // non hashable
  2351. rt_rule_entry = &rt_rule->rules[2];
  2352. rt_rule_entry->at_rear = 1;
  2353. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  2354. if (false == m_routing.AddRoutingRule(rt_rule))
  2355. {
  2356. printf("Routing rule addition failed!\n");
  2357. return false;
  2358. }
  2359. for (int i = 0; i < rt_rule->num_rules; i++) {
  2360. uRtRuleHdl[i] = rt_rule->rules[i].rt_rule_hdl;
  2361. }
  2362. uNumRtRules = rt_rule->num_rules;
  2363. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  2364. free(rt_rule);
  2365. InitFilteringBlock();
  2366. return true;
  2367. }
  2368. bool RemoveLastRule(enum ipa_ip_type ipType)
  2369. {
  2370. struct ipa_ioc_del_rt_rule *ruleTable;
  2371. ruleTable = (struct ipa_ioc_del_rt_rule *)
  2372. calloc(1, sizeof(struct ipa_ioc_del_rt_rule) +
  2373. sizeof(struct ipa_rt_rule_del));
  2374. ruleTable->commit = 1;
  2375. ruleTable->ip = ipType;
  2376. ruleTable->num_hdls = 1;
  2377. ruleTable->hdl[0].hdl = uRtRuleHdl[uNumRtRules - 1];
  2378. ruleTable->hdl[0].status = 0;
  2379. if (false == m_routing.DeleteRoutingRule(ruleTable))
  2380. {
  2381. printf("Routing rule deletion failed!\n");
  2382. return false;
  2383. }
  2384. return true;
  2385. }
  2386. bool Run()
  2387. {
  2388. bool res = false;
  2389. bool isSuccess = false;
  2390. // Add the relevant routing rules
  2391. res = AddRules();
  2392. if (false == res) {
  2393. printf("Failed adding routing rules.\n");
  2394. return false;
  2395. }
  2396. // Load input data (IP packet) from file
  2397. res = LoadFiles(IPA_IP_v4);
  2398. if (false == res) {
  2399. printf("Failed loading files.\n");
  2400. return false;
  2401. }
  2402. // Send first packet
  2403. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2404. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  2405. if (false == isSuccess)
  2406. {
  2407. printf("SendData failure.\n");
  2408. return false;
  2409. }
  2410. // Send second packet
  2411. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2412. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  2413. if (false == isSuccess)
  2414. {
  2415. printf("SendData failure.\n");
  2416. return false;
  2417. }
  2418. // Send third packet
  2419. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  2420. if (false == isSuccess)
  2421. {
  2422. printf("SendData failure.\n");
  2423. return false;
  2424. }
  2425. // Receive packets from the channels and compare results
  2426. isSuccess = ReceivePacketsAndCompare();
  2427. return isSuccess;
  2428. } // Run()
  2429. bool ReceivePacketsAndCompare()
  2430. {
  2431. size_t receivedSize = 0;
  2432. size_t receivedSize2 = 0;
  2433. size_t receivedSize3 = 0;
  2434. bool isSuccess = true;
  2435. // Receive results
  2436. Byte *rxBuff1 = new Byte[0x400];
  2437. Byte *rxBuff2 = new Byte[0x400];
  2438. Byte *rxBuff3 = new Byte[0x400];
  2439. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  2440. {
  2441. printf("Memory allocation error.\n");
  2442. return false;
  2443. }
  2444. receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400);
  2445. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  2446. receivedSize2 = m_consumer.ReceiveData(rxBuff2, 0x400);
  2447. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer.m_fromChannelName.c_str());
  2448. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  2449. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  2450. /* Compare results */
  2451. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  2452. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  2453. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  2454. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  2455. IsCacheMiss_v5_0(m_sendSize, receivedSize, rxBuff1) : IsCacheMiss(m_sendSize,receivedSize,rxBuff1);
  2456. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  2457. IsCacheHit_v5_0(m_sendSize2, receivedSize2, rxBuff2) : IsCacheHit(m_sendSize2,receivedSize2,rxBuff2);
  2458. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  2459. IsCacheMiss_v5_0(m_sendSize3, receivedSize3, rxBuff3) : IsCacheMiss(m_sendSize3,receivedSize3,rxBuff3);
  2460. size_t recievedBufferSize = receivedSize * 3;
  2461. size_t sentBufferSize = m_sendSize * 3;
  2462. char *recievedBuffer = new char[recievedBufferSize];
  2463. char *sentBuffer = new char[sentBufferSize];
  2464. memset(recievedBuffer, 0, recievedBufferSize);
  2465. memset(sentBuffer, 0, sentBufferSize);
  2466. print_packets(receivedSize, m_sendSize, recievedBufferSize, sentBufferSize, rxBuff1, m_sendBuffer, recievedBuffer, sentBuffer);
  2467. print_packets(receivedSize2, m_sendSize2, recievedBufferSize, sentBufferSize, rxBuff2, m_sendBuffer2, recievedBuffer, sentBuffer);
  2468. print_packets(receivedSize3, m_sendSize3, recievedBufferSize, sentBufferSize, rxBuff3, m_sendBuffer3, recievedBuffer, sentBuffer);
  2469. delete[] recievedBuffer;
  2470. delete[] sentBuffer;
  2471. delete[] rxBuff1;
  2472. delete[] rxBuff2;
  2473. delete[] rxBuff3;
  2474. return isSuccess;
  2475. }
  2476. bool ReceivePacketsAndCompareSpecial()
  2477. {
  2478. size_t receivedSize = 0;
  2479. bool isSuccess = true;
  2480. // Receive results
  2481. Byte *rxBuff1 = new Byte[0x400];
  2482. if (NULL == rxBuff1)
  2483. {
  2484. printf("Memory allocation error.\n");
  2485. return false;
  2486. }
  2487. receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400);
  2488. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  2489. /* Compare results */
  2490. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  2491. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  2492. IsCacheMiss_v5_0(m_sendSize, receivedSize, rxBuff1) : IsCacheMiss(m_sendSize,receivedSize,rxBuff1);
  2493. size_t recievedBufferSize = receivedSize * 3;
  2494. size_t sentBufferSize = m_sendSize * 3;
  2495. char *recievedBuffer = new char[recievedBufferSize];
  2496. char *sentBuffer = new char[sentBufferSize];
  2497. size_t j;
  2498. for(j = 0; j < m_sendSize; j++)
  2499. snprintf(&sentBuffer[3 * j], sentBufferSize - 3 * j,
  2500. " %02X", m_sendBuffer[j]);
  2501. for(j = 0; j < receivedSize; j++)
  2502. snprintf(&recievedBuffer[3 * j], recievedBufferSize - 3 * j,
  2503. " %02X", rxBuff1[j]);
  2504. printf("Expected Value1 (%zu)\n%s\n, Received Value1(%zu)\n%s\n",m_sendSize,sentBuffer,receivedSize,recievedBuffer);
  2505. delete[] rxBuff1;
  2506. return isSuccess;
  2507. }
  2508. protected:
  2509. uint32_t uRtRuleHdl[3];
  2510. uint8_t uNumRtRules;
  2511. };
  2512. /*--------------------------------------------------------------------------*/
  2513. /* Test16: IPv4 - Tests routing hashable vs non hashable priorities */
  2514. /*--------------------------------------------------------------------------*/
  2515. class IpaRoutingBlockTest016 : public IpaRoutingBlockTestFixture
  2516. {
  2517. public:
  2518. IpaRoutingBlockTest016()
  2519. {
  2520. m_name = "IpaRoutingBlockTest016";
  2521. m_description =" \
  2522. Routing block test 016 - Destination address exact match max priority for non hashable \
  2523. match on both rule, non hashable rule should win because max priority\
  2524. packets are sent. No cache hit is expected\
  2525. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  2526. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  2527. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  2528. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  2529. m_IpaIPType = IPA_IP_v4;
  2530. m_minIPAHwType = IPA_HW_v3_0;
  2531. Register(*this);
  2532. }
  2533. bool AddRules()
  2534. {
  2535. struct ipa_ioc_add_rt_rule *rt_rule;
  2536. struct ipa_rt_rule_add *rt_rule_entry;
  2537. const int NUM_RULES = 3;
  2538. rt_rule = (struct ipa_ioc_add_rt_rule *)
  2539. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  2540. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  2541. if(!rt_rule) {
  2542. printf("Failed memory allocation for rt_rule\n");
  2543. return false;
  2544. }
  2545. rt_rule->commit = 1;
  2546. rt_rule->num_rules = NUM_RULES;
  2547. rt_rule->ip = IPA_IP_v4;
  2548. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  2549. rt_rule_entry = &rt_rule->rules[0];
  2550. rt_rule_entry->at_rear = 1;
  2551. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  2552. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  2553. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  2554. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  2555. rt_rule_entry->rule.hashable = 1; // hashable
  2556. rt_rule_entry = &rt_rule->rules[1];
  2557. rt_rule_entry->at_rear = 1;
  2558. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  2559. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  2560. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  2561. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  2562. rt_rule_entry->rule.hashable = 0; // non hashable
  2563. rt_rule_entry->rule.max_prio = 1; // max priority
  2564. rt_rule_entry = &rt_rule->rules[2];
  2565. rt_rule_entry->at_rear = 1;
  2566. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  2567. if (false == m_routing.AddRoutingRule(rt_rule))
  2568. {
  2569. printf("Routing rule addition failed!\n");
  2570. return false;
  2571. }
  2572. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  2573. free(rt_rule);
  2574. InitFilteringBlock();
  2575. return true;
  2576. }
  2577. bool Run()
  2578. {
  2579. bool res = false;
  2580. bool isSuccess = false;
  2581. // Add the relevant routing rules
  2582. res = AddRules();
  2583. if (false == res) {
  2584. printf("Failed adding routing rules.\n");
  2585. return false;
  2586. }
  2587. // Load input data (IP packet) from file
  2588. res = LoadFiles(IPA_IP_v4);
  2589. if (false == res) {
  2590. printf("Failed loading files.\n");
  2591. return false;
  2592. }
  2593. // Send first packet
  2594. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2595. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  2596. if (false == isSuccess)
  2597. {
  2598. printf("SendData failure.\n");
  2599. return false;
  2600. }
  2601. // Send second packet
  2602. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2603. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  2604. if (false == isSuccess)
  2605. {
  2606. printf("SendData failure.\n");
  2607. return false;
  2608. }
  2609. // Send third packet
  2610. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  2611. if (false == isSuccess)
  2612. {
  2613. printf("SendData failure.\n");
  2614. return false;
  2615. }
  2616. // Receive packets from the channels and compare results
  2617. isSuccess = ReceivePacketsAndCompare();
  2618. return isSuccess;
  2619. } // Run()
  2620. bool ReceivePacketsAndCompare()
  2621. {
  2622. size_t receivedSize = 0;
  2623. size_t receivedSize2 = 0;
  2624. size_t receivedSize3 = 0;
  2625. bool isSuccess = true;
  2626. // Receive results
  2627. Byte *rxBuff1 = new Byte[0x400];
  2628. Byte *rxBuff2 = new Byte[0x400];
  2629. Byte *rxBuff3 = new Byte[0x400];
  2630. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  2631. {
  2632. printf("Memory allocation error.\n");
  2633. return false;
  2634. }
  2635. receivedSize = m_consumer2.ReceiveData(rxBuff1, 0x400);
  2636. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  2637. receivedSize2 = m_consumer2.ReceiveData(rxBuff2, 0x400);
  2638. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer.m_fromChannelName.c_str());
  2639. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  2640. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  2641. /* Compare results */
  2642. isSuccess &= CompareResultVsGolden(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  2643. isSuccess &= CompareResultVsGolden(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  2644. isSuccess &= CompareResultVsGolden(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  2645. size_t recievedBufferSize = receivedSize * 3;
  2646. size_t sentBufferSize = m_sendSize * 3;
  2647. char *recievedBuffer = new char[recievedBufferSize];
  2648. char *sentBuffer = new char[sentBufferSize];
  2649. memset(recievedBuffer, 0, recievedBufferSize);
  2650. memset(sentBuffer, 0, sentBufferSize);
  2651. print_packets(receivedSize, m_sendSize, recievedBufferSize, sentBufferSize, rxBuff1, m_sendBuffer, recievedBuffer, sentBuffer);
  2652. print_packets(receivedSize2, m_sendSize2, recievedBufferSize, sentBufferSize, rxBuff2, m_sendBuffer2, recievedBuffer, sentBuffer);
  2653. print_packets(receivedSize3, m_sendSize3, recievedBufferSize, sentBufferSize, rxBuff3, m_sendBuffer3, recievedBuffer, sentBuffer);
  2654. delete[] recievedBuffer;
  2655. delete[] sentBuffer;
  2656. delete[] rxBuff1;
  2657. delete[] rxBuff2;
  2658. delete[] rxBuff3;
  2659. return isSuccess;
  2660. }
  2661. };
  2662. /*--------------------------------------------------------------------------*/
  2663. /* Test17: IPv4 - Tests routing hashable, non hashable, */
  2664. /* cache/hash invalidation test on rule addition */
  2665. /*--------------------------------------------------------------------------*/
  2666. class IpaRoutingBlockTest017 : public IpaRoutingBlockTest015
  2667. {
  2668. public:
  2669. IpaRoutingBlockTest017()
  2670. {
  2671. m_name = "IpaRoutingBlockTest017";
  2672. m_description =" \
  2673. Routing block test 017 - this test perform test 015 and then commits another rule\
  2674. another identical packet is sent: DST_IP == 192.168.02.170 and expected to get cache miss";
  2675. }
  2676. bool Run()
  2677. {
  2678. bool res = false;
  2679. bool isSuccess = false;
  2680. // Add the relevant routing rules
  2681. res = AddRules();
  2682. if (false == res) {
  2683. printf("Failed adding routing rules.\n");
  2684. return false;
  2685. }
  2686. // Load input data (IP packet) from file
  2687. res = LoadFiles(IPA_IP_v4);
  2688. if (false == res) {
  2689. printf("Failed loading files.\n");
  2690. return false;
  2691. }
  2692. // Send first packet
  2693. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2694. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  2695. if (false == isSuccess)
  2696. {
  2697. printf("SendData failure.\n");
  2698. return false;
  2699. }
  2700. // Send second packet
  2701. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2702. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  2703. if (false == isSuccess)
  2704. {
  2705. printf("SendData failure.\n");
  2706. return false;
  2707. }
  2708. // Send third packet
  2709. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  2710. if (false == isSuccess)
  2711. {
  2712. printf("SendData failure.\n");
  2713. return false;
  2714. }
  2715. // Receive packets from the channels and compare results
  2716. isSuccess = ReceivePacketsAndCompare();
  2717. if (false == isSuccess)
  2718. {
  2719. printf("ReceivePacketsAndCompare failure.\n");
  2720. return false;
  2721. }
  2722. // until here test 15 was run, now we test hash invalidation
  2723. // commit the rules again to clear the cache
  2724. res = AddRules();
  2725. if (false == res) {
  2726. printf("Failed adding routing rules.\n");
  2727. return false;
  2728. }
  2729. // send the packet again
  2730. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  2731. if (false == isSuccess)
  2732. {
  2733. printf("SendData failure.\n");
  2734. return false;
  2735. }
  2736. // validate we got cache miss
  2737. isSuccess = ReceivePacketsAndCompareSpecial();
  2738. if (false == isSuccess)
  2739. {
  2740. printf("ReceivePacketsAndCompareSpecial failure.\n");
  2741. }
  2742. return isSuccess;
  2743. } // Run()
  2744. };
  2745. /*--------------------------------------------------------------------------*/
  2746. /* Test18: IPv4 - Tests routing hashable, non hashable, */
  2747. /* cache/hash invalidation test on rule delition */
  2748. /*--------------------------------------------------------------------------*/
  2749. class IpaRoutingBlockTest018 : public IpaRoutingBlockTest015
  2750. {
  2751. public:
  2752. IpaRoutingBlockTest018()
  2753. {
  2754. m_name = "IpaRoutingBlockTest018";
  2755. m_description =" \
  2756. Routing block test 018 - this test perform test 015 and then removes last rule\
  2757. another identical packet is sent: DST_IP == 192.168.02.170 and expected to get cache miss";
  2758. }
  2759. bool Run()
  2760. {
  2761. bool res = false;
  2762. bool isSuccess = false;
  2763. // Add the relevant routing rules
  2764. res = AddRules();
  2765. if (false == res) {
  2766. printf("Failed adding routing rules.\n");
  2767. return false;
  2768. }
  2769. // Load input data (IP packet) from file
  2770. res = LoadFiles(IPA_IP_v4);
  2771. if (false == res) {
  2772. printf("Failed loading files.\n");
  2773. return false;
  2774. }
  2775. // Send first packet
  2776. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2777. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  2778. if (false == isSuccess)
  2779. {
  2780. printf("SendData failure.\n");
  2781. return false;
  2782. }
  2783. // Send second packet
  2784. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  2785. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  2786. if (false == isSuccess)
  2787. {
  2788. printf("SendData failure.\n");
  2789. return false;
  2790. }
  2791. // Send third packet
  2792. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  2793. if (false == isSuccess)
  2794. {
  2795. printf("SendData failure.\n");
  2796. return false;
  2797. }
  2798. // Receive packets from the channels and compare results
  2799. isSuccess = ReceivePacketsAndCompare();
  2800. if (false == isSuccess)
  2801. {
  2802. printf("ReceivePacketsAndCompare failure.\n");
  2803. return false;
  2804. }
  2805. // until here test 15 was run, now we test hash invalidation
  2806. // delete the last rule, this should clear the cache
  2807. res = RemoveLastRule(IPA_IP_v4);
  2808. if (false == res) {
  2809. printf("Failed removing filtering rules.\n");
  2810. return false;
  2811. }
  2812. // send the packet again
  2813. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  2814. if (false == isSuccess)
  2815. {
  2816. printf("SendData failure.\n");
  2817. return false;
  2818. }
  2819. // validate we got cache miss
  2820. isSuccess = ReceivePacketsAndCompareSpecial();
  2821. if (false == isSuccess)
  2822. {
  2823. printf("ReceivePacketsAndCompareSpecial failure.\n");
  2824. }
  2825. return isSuccess;
  2826. } // Run()
  2827. };
  2828. /*--------------------------------------------------------------------------*/
  2829. /* Test20: IPv6 - Tests routing hashable vs non hashable priorities */
  2830. /*--------------------------------------------------------------------------*/
  2831. class IpaRoutingBlockTest020 : public IpaRoutingBlockTest010
  2832. {
  2833. public:
  2834. IpaRoutingBlockTest020()
  2835. {
  2836. m_name = "IpaRoutingBlockTest20";
  2837. m_description =" \
  2838. Routing block test 020 - Destination address exact match non hashable priority higher than hashable \
  2839. both match the packet but only non hashable should hit\
  2840. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  2841. All DST_IP == 0XFF020000 \
  2842. 0x00000000 \
  2843. 0x00000000 \
  2844. 0X000000FF \
  2845. traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  2846. All DST_IP == 0XFF020000 \
  2847. 0x00000000 \
  2848. 0x00000000 \
  2849. 0X000000FF \
  2850. traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  2851. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  2852. m_IpaIPType = IPA_IP_v6;
  2853. m_minIPAHwType = IPA_HW_v3_0;
  2854. }
  2855. bool AddRules()
  2856. {
  2857. struct ipa_ioc_add_rt_rule *rt_rule;
  2858. struct ipa_rt_rule_add *rt_rule_entry;
  2859. const int NUM_RULES = 3;
  2860. rt_rule = (struct ipa_ioc_add_rt_rule *)
  2861. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  2862. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  2863. if(!rt_rule) {
  2864. printf("Failed memory allocation for rt_rule\n");
  2865. return false;
  2866. }
  2867. rt_rule->commit = 1;
  2868. rt_rule->num_rules = NUM_RULES;
  2869. rt_rule->ip = IPA_IP_v6;
  2870. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  2871. rt_rule_entry = &rt_rule->rules[0];
  2872. rt_rule_entry->at_rear = 1;
  2873. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  2874. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  2875. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  2876. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  2877. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  2878. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  2879. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  2880. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  2881. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  2882. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  2883. rt_rule_entry->rule.hashable = 0; // non hashable
  2884. rt_rule_entry = &rt_rule->rules[1];
  2885. rt_rule_entry->at_rear = 1;
  2886. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  2887. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  2888. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  2889. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  2890. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  2891. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  2892. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  2893. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  2894. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  2895. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  2896. rt_rule_entry->rule.hashable = 1; // hashable
  2897. rt_rule_entry = &rt_rule->rules[2];
  2898. rt_rule_entry->at_rear = 1;
  2899. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  2900. rt_rule_entry->rule.hashable = 0; // non hashable
  2901. if (false == m_routing.AddRoutingRule(rt_rule))
  2902. {
  2903. printf("Routing rule addition failed!\n");
  2904. free(rt_rule);
  2905. return false;
  2906. }
  2907. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  2908. free(rt_rule);
  2909. InitFilteringBlock();
  2910. return true;
  2911. }
  2912. bool Run()
  2913. {
  2914. bool res = false;
  2915. bool isSuccess = false;
  2916. // Add the relevant routing rules
  2917. res = AddRules();
  2918. if (false == res) {
  2919. printf("Failed adding routing rules.\n");
  2920. return false;
  2921. }
  2922. // Load input data (IP packet) from file
  2923. res = LoadFiles(IPA_IP_v6);
  2924. if (false == res) {
  2925. printf("Failed loading files.\n");
  2926. return false;
  2927. }
  2928. // Send first packet
  2929. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  2930. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  2931. if (false == isSuccess)
  2932. {
  2933. printf("SendData failure.\n");
  2934. return false;
  2935. }
  2936. // Send second packet
  2937. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  2938. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  2939. if (false == isSuccess)
  2940. {
  2941. printf("SendData failure.\n");
  2942. return false;
  2943. }
  2944. // Send third packet
  2945. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  2946. if (false == isSuccess)
  2947. {
  2948. printf("SendData failure.\n");
  2949. return false;
  2950. }
  2951. // Receive packets from the channels and compare results
  2952. isSuccess = ReceivePacketsAndCompare();
  2953. return isSuccess;
  2954. } // Run()
  2955. };
  2956. /*--------------------------------------------------------------------------*/
  2957. /* Test21: IPv6 - Tests routing hashable vs non hashable priorities */
  2958. /*--------------------------------------------------------------------------*/
  2959. class IpaRoutingBlockTest021 : public IpaRoutingBlockTest011
  2960. {
  2961. public:
  2962. IpaRoutingBlockTest021()
  2963. {
  2964. m_name = "IpaRoutingBlockTest021";
  2965. m_description =" \
  2966. Routing block test 021 - Destination address exact match hashable priority higher than non hashable \
  2967. both match the packet but only hashable should hit, second packet should get cache hit\
  2968. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  2969. All DST_IP == 0XFF020000 \
  2970. 0x00000000 \
  2971. 0x00000000 \
  2972. 0X000000FF - hashable\
  2973. All DST_IP == 0XFF020000 \
  2974. 0x00000000 \
  2975. 0x00000000 \
  2976. 0X000000FF - non hahsable \
  2977. traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  2978. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  2979. m_IpaIPType = IPA_IP_v6;
  2980. m_minIPAHwType = IPA_HW_v3_0;
  2981. }
  2982. bool AddRules()
  2983. {
  2984. struct ipa_ioc_add_rt_rule *rt_rule;
  2985. struct ipa_rt_rule_add *rt_rule_entry;
  2986. const int NUM_RULES = 3;
  2987. rt_rule = (struct ipa_ioc_add_rt_rule *)
  2988. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  2989. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  2990. if(!rt_rule) {
  2991. printf("Failed memory allocation for rt_rule\n");
  2992. return false;
  2993. }
  2994. rt_rule->commit = 1;
  2995. rt_rule->num_rules = NUM_RULES;
  2996. rt_rule->ip = IPA_IP_v6;
  2997. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  2998. rt_rule_entry = &rt_rule->rules[0];
  2999. rt_rule_entry->at_rear = 1;
  3000. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  3001. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3002. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3003. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3004. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3005. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  3006. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3007. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3008. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3009. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3010. rt_rule_entry->rule.hashable = 1; // hashable
  3011. rt_rule_entry = &rt_rule->rules[1];
  3012. rt_rule_entry->at_rear = 1;
  3013. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  3014. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3015. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3016. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3017. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3018. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  3019. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3020. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3021. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3022. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3023. rt_rule_entry->rule.hashable = 0; // non hashable
  3024. rt_rule_entry = &rt_rule->rules[2];
  3025. rt_rule_entry->at_rear = 1;
  3026. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  3027. rt_rule_entry->rule.hashable = 0; // non hashable
  3028. if (false == m_routing.AddRoutingRule(rt_rule))
  3029. {
  3030. printf("Routing rule addition failed!\n");
  3031. free(rt_rule);
  3032. return false;
  3033. }
  3034. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  3035. free(rt_rule);
  3036. InitFilteringBlock();
  3037. return true;
  3038. }
  3039. bool Run()
  3040. {
  3041. bool res = false;
  3042. bool isSuccess = false;
  3043. // Add the relevant routing rules
  3044. res = AddRules();
  3045. if (false == res) {
  3046. printf("Failed adding routing rules.\n");
  3047. return false;
  3048. }
  3049. // Load input data (IP packet) from file
  3050. res = LoadFiles(IPA_IP_v6);
  3051. if (false == res) {
  3052. printf("Failed loading files.\n");
  3053. return false;
  3054. }
  3055. // Send first packet
  3056. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3057. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  3058. if (false == isSuccess)
  3059. {
  3060. printf("SendData failure.\n");
  3061. return false;
  3062. }
  3063. // Send second packet
  3064. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3065. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  3066. if (false == isSuccess)
  3067. {
  3068. printf("SendData failure.\n");
  3069. return false;
  3070. }
  3071. // Send third packet
  3072. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  3073. if (false == isSuccess)
  3074. {
  3075. printf("SendData failure.\n");
  3076. return false;
  3077. }
  3078. // Receive packets from the channels and compare results
  3079. isSuccess = ReceivePacketsAndCompare();
  3080. return isSuccess;
  3081. } // Run()
  3082. };
  3083. /*--------------------------------------------------------------------------*/
  3084. /* Test22: IPv6 - Tests routing hashable vs non hashable priorities */
  3085. /*--------------------------------------------------------------------------*/
  3086. class IpaRoutingBlockTest022 : public IpaRoutingBlockTest012
  3087. {
  3088. public:
  3089. IpaRoutingBlockTest022()
  3090. {
  3091. m_name = "IpaRoutingBlockTest022";
  3092. m_description =" \
  3093. Routing block test 022 - Destination address exact match hashable priority higher than non hashable \
  3094. no match on non hashable rule (with higher priority), match on hashable rule. two packets with\
  3095. different tuple are sent (but match the rule) cache miss expected\
  3096. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  3097. All DST_IP == 0XFF020000 \
  3098. 0x00000000 \
  3099. 0x00000000 \
  3100. 0X000000AA - non hashable\
  3101. All DST_IP == 0XFF020000 \
  3102. 0x00000000 \
  3103. 0x00000000 \
  3104. 0X000000FF - hahsable \
  3105. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  3106. m_IpaIPType = IPA_IP_v6;
  3107. m_minIPAHwType = IPA_HW_v3_0;
  3108. }
  3109. bool AddRules()
  3110. {
  3111. struct ipa_ioc_add_rt_rule *rt_rule;
  3112. struct ipa_rt_rule_add *rt_rule_entry;
  3113. const int NUM_RULES = 3;
  3114. rt_rule = (struct ipa_ioc_add_rt_rule *)
  3115. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  3116. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  3117. if(!rt_rule) {
  3118. printf("Failed memory allocation for rt_rule\n");
  3119. return false;
  3120. }
  3121. rt_rule->commit = 1;
  3122. rt_rule->num_rules = NUM_RULES;
  3123. rt_rule->ip = IPA_IP_v6;
  3124. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  3125. rt_rule_entry = &rt_rule->rules[0];
  3126. rt_rule_entry->at_rear = 1;
  3127. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  3128. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3129. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3130. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3131. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3132. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000AA;
  3133. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3134. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3135. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3136. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3137. rt_rule_entry->rule.hashable = 0; // non hashable
  3138. rt_rule_entry = &rt_rule->rules[1];
  3139. rt_rule_entry->at_rear = 1;
  3140. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  3141. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3142. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3143. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3144. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3145. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  3146. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3147. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3148. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3149. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3150. rt_rule_entry->rule.hashable = 1; // hashable
  3151. rt_rule_entry = &rt_rule->rules[2];
  3152. rt_rule_entry->at_rear = 1;
  3153. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  3154. rt_rule_entry->rule.hashable = 0; // non hashable
  3155. if (false == m_routing.AddRoutingRule(rt_rule))
  3156. {
  3157. printf("Routing rule addition failed!\n");
  3158. free(rt_rule);
  3159. return false;
  3160. }
  3161. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  3162. free(rt_rule);
  3163. InitFilteringBlock();
  3164. return true;
  3165. }
  3166. bool Run()
  3167. {
  3168. bool res = false;
  3169. bool isSuccess = false;
  3170. unsigned short port;
  3171. // Add the relevant routing rules
  3172. res = AddRules();
  3173. if (false == res) {
  3174. printf("Failed adding routing rules.\n");
  3175. return false;
  3176. }
  3177. // Load input data (IP packet) from file
  3178. res = LoadFiles(IPA_IP_v6);
  3179. if (false == res) {
  3180. printf("Failed loading files.\n");
  3181. return false;
  3182. }
  3183. // Send first packet
  3184. port = ntohs(546);//DHCP Client Port
  3185. memcpy (&m_sendBuffer[IPV6_DST_PORT_OFFSET], &port, sizeof(port));
  3186. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3187. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  3188. if (false == isSuccess)
  3189. {
  3190. printf("SendData failure.\n");
  3191. return false;
  3192. }
  3193. // Send second packet
  3194. port = ntohs(547);//DHCP Client Port
  3195. memcpy (&m_sendBuffer2[IPV6_DST_PORT_OFFSET], &port, sizeof(port));
  3196. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3197. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  3198. if (false == isSuccess)
  3199. {
  3200. printf("SendData failure.\n");
  3201. return false;
  3202. }
  3203. // Send third packet
  3204. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  3205. if (false == isSuccess)
  3206. {
  3207. printf("SendData failure.\n");
  3208. return false;
  3209. }
  3210. // Receive packets from the channels and compare results
  3211. isSuccess = ReceivePacketsAndCompare();
  3212. return isSuccess;
  3213. } // Run()
  3214. };
  3215. /*--------------------------------------------------------------------------*/
  3216. /* Test23: IPv6 - Tests routing hashable vs non hashable priorities */
  3217. /*--------------------------------------------------------------------------*/
  3218. class IpaRoutingBlockTest023 : public IpaRoutingBlockTest013
  3219. {
  3220. public:
  3221. IpaRoutingBlockTest023()
  3222. {
  3223. m_name = "IpaRoutingBlockTest023";
  3224. m_description =" \
  3225. Routing block test 023 - Destination address exact match \
  3226. no match on non hashable rule (with lower priority), match on hashable rule. two packets with\
  3227. different tuple are sent (but match the rule) cache miss expected\
  3228. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  3229. All DST_IP == 0XFF020000 \
  3230. 0x00000000 \
  3231. 0x00000000 \
  3232. 0X000000FF - hashable\
  3233. traffic goes to pipe IPA_CLIENT_TEST2_CONS\
  3234. All DST_IP == 0XFF020000 \
  3235. 0x00000000 \
  3236. 0x00000000 \
  3237. 0X000000AA - non hahsable \
  3238. traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  3239. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  3240. m_IpaIPType = IPA_IP_v6;
  3241. m_minIPAHwType = IPA_HW_v3_0;
  3242. }
  3243. bool AddRules()
  3244. {
  3245. struct ipa_ioc_add_rt_rule *rt_rule;
  3246. struct ipa_rt_rule_add *rt_rule_entry;
  3247. const int NUM_RULES = 3;
  3248. rt_rule = (struct ipa_ioc_add_rt_rule *)
  3249. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  3250. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  3251. if(!rt_rule) {
  3252. printf("Failed memory allocation for rt_rule\n");
  3253. return false;
  3254. }
  3255. rt_rule->commit = 1;
  3256. rt_rule->num_rules = NUM_RULES;
  3257. rt_rule->ip = IPA_IP_v6;
  3258. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  3259. rt_rule_entry = &rt_rule->rules[0];
  3260. rt_rule_entry->at_rear = 1;
  3261. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  3262. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3263. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3264. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3265. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3266. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  3267. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3268. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3269. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3270. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3271. rt_rule_entry->rule.hashable = 1; // hashable
  3272. rt_rule_entry = &rt_rule->rules[1];
  3273. rt_rule_entry->at_rear = 1;
  3274. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  3275. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3276. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3277. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3278. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3279. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000AA;
  3280. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3281. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3282. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3283. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3284. rt_rule_entry->rule.hashable = 0; // non hashable
  3285. rt_rule_entry = &rt_rule->rules[2];
  3286. rt_rule_entry->at_rear = 1;
  3287. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  3288. rt_rule_entry->rule.hashable = 0; // non hashable
  3289. if (false == m_routing.AddRoutingRule(rt_rule))
  3290. {
  3291. printf("Routing rule addition failed!\n");
  3292. free(rt_rule);
  3293. return false;
  3294. }
  3295. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  3296. free(rt_rule);
  3297. InitFilteringBlock();
  3298. return true;
  3299. }
  3300. bool Run()
  3301. {
  3302. bool res = false;
  3303. bool isSuccess = false;
  3304. unsigned short port;
  3305. // Add the relevant routing rules
  3306. res = AddRules();
  3307. if (false == res) {
  3308. printf("Failed adding routing rules.\n");
  3309. return false;
  3310. }
  3311. // Load input data (IP packet) from file
  3312. res = LoadFiles(IPA_IP_v6);
  3313. if (false == res) {
  3314. printf("Failed loading files.\n");
  3315. return false;
  3316. }
  3317. // Send first packet
  3318. port = ntohs(546);//DHCP Client Port
  3319. memcpy (&m_sendBuffer[IPV6_DST_PORT_OFFSET], &port, sizeof(port));
  3320. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3321. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  3322. if (false == isSuccess)
  3323. {
  3324. printf("SendData failure.\n");
  3325. return false;
  3326. }
  3327. // Send second packet
  3328. port = ntohs(547);//DHCP Client Port
  3329. memcpy (&m_sendBuffer2[IPV6_DST_PORT_OFFSET], &port, sizeof(port));
  3330. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3331. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  3332. if (false == isSuccess)
  3333. {
  3334. printf("SendData failure.\n");
  3335. return false;
  3336. }
  3337. // Send third packet
  3338. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  3339. if (false == isSuccess)
  3340. {
  3341. printf("SendData failure.\n");
  3342. return false;
  3343. }
  3344. // Receive packets from the channels and compare results
  3345. isSuccess = ReceivePacketsAndCompare();
  3346. return isSuccess;
  3347. } // Run()
  3348. };
  3349. /*--------------------------------------------------------------------------*/
  3350. /* Test24: IPv6 - Tests routing hashable vs non hashable priorities */
  3351. /*--------------------------------------------------------------------------*/
  3352. class IpaRoutingBlockTest024 : public IpaRoutingBlockTest014
  3353. {
  3354. public:
  3355. IpaRoutingBlockTest024()
  3356. {
  3357. m_name = "IpaRoutingBlockTest024";
  3358. m_description =" \
  3359. Routing block test 024 - Destination address exact match \
  3360. no match on non hashable rule(with higher priority) , match on hashable rule. two identical\
  3361. packets are sent cache hit expected on the second one\
  3362. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  3363. All DST_IP == 0XFF020000 \
  3364. 0x00000000 \
  3365. 0x00000000 \
  3366. 0X000000AA - non hashable\
  3367. traffic goes to pipe IPA_CLIENT_TEST2_CONS\
  3368. All DST_IP == 0XFF020000 \
  3369. 0x00000000 \
  3370. 0x00000000 \
  3371. 0X000000FF - hahsable \
  3372. traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  3373. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  3374. m_IpaIPType = IPA_IP_v6;
  3375. m_minIPAHwType = IPA_HW_v3_0;
  3376. }
  3377. bool AddRules()
  3378. {
  3379. struct ipa_ioc_add_rt_rule *rt_rule;
  3380. struct ipa_rt_rule_add *rt_rule_entry;
  3381. const int NUM_RULES = 3;
  3382. rt_rule = (struct ipa_ioc_add_rt_rule *)
  3383. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  3384. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  3385. if(!rt_rule) {
  3386. printf("Failed memory allocation for rt_rule\n");
  3387. return false;
  3388. }
  3389. rt_rule->commit = 1;
  3390. rt_rule->num_rules = NUM_RULES;
  3391. rt_rule->ip = IPA_IP_v6;
  3392. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  3393. rt_rule_entry = &rt_rule->rules[0];
  3394. rt_rule_entry->at_rear = 1;
  3395. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  3396. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3397. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3398. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3399. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3400. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000AA;
  3401. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3402. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3403. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3404. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3405. rt_rule_entry->rule.hashable = 0; // non hashable
  3406. rt_rule_entry = &rt_rule->rules[1];
  3407. rt_rule_entry->at_rear = 1;
  3408. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  3409. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3410. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3411. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3412. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3413. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  3414. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3415. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3416. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3417. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3418. rt_rule_entry->rule.hashable = 1; // hashable
  3419. rt_rule_entry = &rt_rule->rules[2];
  3420. rt_rule_entry->at_rear = 1;
  3421. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  3422. rt_rule_entry->rule.hashable = 0; // non hashable
  3423. if (false == m_routing.AddRoutingRule(rt_rule))
  3424. {
  3425. printf("Routing rule addition failed!\n");
  3426. free(rt_rule);
  3427. return false;
  3428. }
  3429. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  3430. free(rt_rule);
  3431. InitFilteringBlock();
  3432. return true;
  3433. }
  3434. bool Run()
  3435. {
  3436. bool res = false;
  3437. bool isSuccess = false;
  3438. // Add the relevant routing rules
  3439. res = AddRules();
  3440. if (false == res) {
  3441. printf("Failed adding routing rules.\n");
  3442. return false;
  3443. }
  3444. // Load input data (IP packet) from file
  3445. res = LoadFiles(IPA_IP_v6);
  3446. if (false == res) {
  3447. printf("Failed loading files.\n");
  3448. return false;
  3449. }
  3450. // Send first packet
  3451. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3452. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  3453. if (false == isSuccess)
  3454. {
  3455. printf("SendData failure.\n");
  3456. return false;
  3457. }
  3458. // Send second packet
  3459. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3460. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  3461. if (false == isSuccess)
  3462. {
  3463. printf("SendData failure.\n");
  3464. return false;
  3465. }
  3466. // Send third packet
  3467. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  3468. if (false == isSuccess)
  3469. {
  3470. printf("SendData failure.\n");
  3471. return false;
  3472. }
  3473. // Receive packets from the channels and compare results
  3474. isSuccess = ReceivePacketsAndCompare();
  3475. return isSuccess;
  3476. } // Run()
  3477. };
  3478. /*--------------------------------------------------------------------------*/
  3479. /* Test25: IPv6 - Tests routing hashable vs non hashable priorities */
  3480. /*--------------------------------------------------------------------------*/
  3481. class IpaRoutingBlockTest025 : public IpaRoutingBlockTest015
  3482. {
  3483. public:
  3484. IpaRoutingBlockTest025()
  3485. {
  3486. m_name = "IpaRoutingBlockTest025";
  3487. m_description =" \
  3488. Routing block test 025 - Destination address exact match \
  3489. no match on non hashable rule(with lower priority) , match on hashable rule. two identical\
  3490. packets are sent cache hit expected on the second one\
  3491. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  3492. All DST_IP == 0XFF020000 \
  3493. 0x00000000 \
  3494. 0x00000000 \
  3495. 0X000000FF - hashable\
  3496. traffic goes to pipe IPA_CLIENT_TEST2_CONS\
  3497. All DST_IP == 0XFF020000 \
  3498. 0x00000000 \
  3499. 0x00000000 \
  3500. 0X000000AA - non hahsable \
  3501. traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  3502. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  3503. m_IpaIPType = IPA_IP_v6;
  3504. m_minIPAHwType = IPA_HW_v3_0;
  3505. }
  3506. bool AddRules()
  3507. {
  3508. struct ipa_ioc_add_rt_rule *rt_rule;
  3509. struct ipa_rt_rule_add *rt_rule_entry;
  3510. const int NUM_RULES = 3;
  3511. rt_rule = (struct ipa_ioc_add_rt_rule *)
  3512. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  3513. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  3514. if(!rt_rule) {
  3515. printf("Failed memory allocation for rt_rule\n");
  3516. return false;
  3517. }
  3518. rt_rule->commit = 1;
  3519. rt_rule->num_rules = NUM_RULES;
  3520. rt_rule->ip = IPA_IP_v6;
  3521. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  3522. rt_rule_entry = &rt_rule->rules[0];
  3523. rt_rule_entry->at_rear = 1;
  3524. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  3525. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3526. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3527. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3528. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3529. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  3530. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3531. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3532. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3533. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3534. rt_rule_entry->rule.hashable = 1; // hashable
  3535. rt_rule_entry = &rt_rule->rules[1];
  3536. rt_rule_entry->at_rear = 1;
  3537. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  3538. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3539. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3540. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3541. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3542. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000AA;
  3543. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3544. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3545. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3546. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3547. rt_rule_entry->rule.hashable = 0; // non hashable
  3548. rt_rule_entry = &rt_rule->rules[2];
  3549. rt_rule_entry->at_rear = 1;
  3550. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  3551. rt_rule_entry->rule.hashable = 0; // non hashable
  3552. if (false == m_routing.AddRoutingRule(rt_rule))
  3553. {
  3554. printf("Routing rule addition failed!\n");
  3555. free(rt_rule);
  3556. return false;
  3557. }
  3558. for (int i = 0; i < rt_rule->num_rules; i++) {
  3559. uRtRuleHdl[i] = rt_rule->rules[i].rt_rule_hdl;
  3560. }
  3561. uNumRtRules = rt_rule->num_rules;
  3562. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  3563. free(rt_rule);
  3564. InitFilteringBlock();
  3565. return true;
  3566. }
  3567. bool Run()
  3568. {
  3569. bool res = false;
  3570. bool isSuccess = false;
  3571. // Add the relevant routing rules
  3572. res = AddRules();
  3573. if (false == res) {
  3574. printf("Failed adding routing rules.\n");
  3575. return false;
  3576. }
  3577. // Load input data (IP packet) from file
  3578. res = LoadFiles(IPA_IP_v6);
  3579. if (false == res) {
  3580. printf("Failed loading files.\n");
  3581. return false;
  3582. }
  3583. // Send first packet
  3584. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3585. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  3586. if (false == isSuccess)
  3587. {
  3588. printf("SendData failure.\n");
  3589. return false;
  3590. }
  3591. // Send second packet
  3592. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3593. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  3594. if (false == isSuccess)
  3595. {
  3596. printf("SendData failure.\n");
  3597. return false;
  3598. }
  3599. // Send third packet
  3600. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  3601. if (false == isSuccess)
  3602. {
  3603. printf("SendData failure.\n");
  3604. return false;
  3605. }
  3606. // Receive packets from the channels and compare results
  3607. isSuccess = ReceivePacketsAndCompare();
  3608. return isSuccess;
  3609. } // Run()
  3610. };
  3611. /*--------------------------------------------------------------------------*/
  3612. /* Test26: IPv6 - Tests routing hashable vs non hashable priorities */
  3613. /*--------------------------------------------------------------------------*/
  3614. class IpaRoutingBlockTest026 : public IpaRoutingBlockTest016
  3615. {
  3616. public:
  3617. IpaRoutingBlockTest026()
  3618. {
  3619. m_name = "IpaRoutingBlockTest026";
  3620. m_description =" \
  3621. Routing block test 026 - Destination address exact match max priority for non hashable \
  3622. match on both rule, non hashable rule should win because max priority\
  3623. packets are sent cache hit expected on the second one\
  3624. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  3625. All DST_IP == 0XFF020000 \
  3626. 0x00000000 \
  3627. 0x00000000 \
  3628. 0X000000FF - hashable\
  3629. traffic goes to pipe IPA_CLIENT_TEST2_CONS\
  3630. All DST_IP == 0XFF020000 \
  3631. 0x00000000 \
  3632. 0x00000000 \
  3633. 0X000000FF - non hahsable max prio \
  3634. traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  3635. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  3636. m_IpaIPType = IPA_IP_v6;
  3637. m_minIPAHwType = IPA_HW_v3_0;
  3638. }
  3639. bool AddRules()
  3640. {
  3641. struct ipa_ioc_add_rt_rule *rt_rule;
  3642. struct ipa_rt_rule_add *rt_rule_entry;
  3643. const int NUM_RULES = 3;
  3644. rt_rule = (struct ipa_ioc_add_rt_rule *)
  3645. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  3646. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  3647. if(!rt_rule) {
  3648. printf("Failed memory allocation for rt_rule\n");
  3649. return false;
  3650. }
  3651. rt_rule->commit = 1;
  3652. rt_rule->num_rules = NUM_RULES;
  3653. rt_rule->ip = IPA_IP_v6;
  3654. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  3655. rt_rule_entry = &rt_rule->rules[0];
  3656. rt_rule_entry->at_rear = 1;
  3657. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  3658. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3659. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3660. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3661. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3662. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  3663. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3664. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3665. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3666. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3667. rt_rule_entry->rule.hashable = 1; // hashable
  3668. rt_rule_entry = &rt_rule->rules[1];
  3669. rt_rule_entry->at_rear = 1;
  3670. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  3671. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  3672. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  3673. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  3674. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  3675. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  3676. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  3677. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  3678. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  3679. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  3680. rt_rule_entry->rule.hashable = 0; // non hashable
  3681. rt_rule_entry->rule.max_prio = 1; // max prio
  3682. rt_rule_entry = &rt_rule->rules[2];
  3683. rt_rule_entry->at_rear = 1;
  3684. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  3685. rt_rule_entry->rule.hashable = 0; // non hashable
  3686. if (false == m_routing.AddRoutingRule(rt_rule))
  3687. {
  3688. printf("Routing rule addition failed!\n");
  3689. free(rt_rule);
  3690. return false;
  3691. }
  3692. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  3693. free(rt_rule);
  3694. InitFilteringBlock();
  3695. return true;
  3696. }
  3697. bool Run()
  3698. {
  3699. bool res = false;
  3700. bool isSuccess = false;
  3701. // Add the relevant routing rules
  3702. res = AddRules();
  3703. if (false == res) {
  3704. printf("Failed adding routing rules.\n");
  3705. return false;
  3706. }
  3707. // Load input data (IP packet) from file
  3708. res = LoadFiles(IPA_IP_v6);
  3709. if (false == res) {
  3710. printf("Failed loading files.\n");
  3711. return false;
  3712. }
  3713. // Send first packet
  3714. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3715. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  3716. if (false == isSuccess)
  3717. {
  3718. printf("SendData failure.\n");
  3719. return false;
  3720. }
  3721. // Send second packet
  3722. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3723. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  3724. if (false == isSuccess)
  3725. {
  3726. printf("SendData failure.\n");
  3727. return false;
  3728. }
  3729. // Send third packet
  3730. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  3731. if (false == isSuccess)
  3732. {
  3733. printf("SendData failure.\n");
  3734. return false;
  3735. }
  3736. // Receive packets from the channels and compare results
  3737. isSuccess = ReceivePacketsAndCompare();
  3738. return isSuccess;
  3739. } // Run()
  3740. };
  3741. /*--------------------------------------------------------------------------*/
  3742. /* Test27: IPv6 - Tests routing hashable, non hashable, */
  3743. /* cache/hash invalidation test on rule addition */
  3744. /*--------------------------------------------------------------------------*/
  3745. class IpaRoutingBlockTest027 : public IpaRoutingBlockTest025
  3746. {
  3747. public:
  3748. IpaRoutingBlockTest027()
  3749. {
  3750. m_name = "IpaRoutingBlockTest027";
  3751. m_description =" \
  3752. Routing block test 027 - this test perform test 025 and then commits another rule\
  3753. another identical packet is sent: DST_IP == 192.168.02.170 and expected to get cache miss";
  3754. }
  3755. bool Run()
  3756. {
  3757. bool res = false;
  3758. bool isSuccess = false;
  3759. // Add the relevant routing rules
  3760. res = AddRules();
  3761. if (false == res) {
  3762. printf("Failed adding routing rules.\n");
  3763. return false;
  3764. }
  3765. // Load input data (IP packet) from file
  3766. res = LoadFiles(IPA_IP_v6);
  3767. if (false == res) {
  3768. printf("Failed loading files.\n");
  3769. return false;
  3770. }
  3771. // Send first packet
  3772. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3773. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  3774. if (false == isSuccess)
  3775. {
  3776. printf("SendData failure.\n");
  3777. return false;
  3778. }
  3779. // Send second packet
  3780. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3781. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  3782. if (false == isSuccess)
  3783. {
  3784. printf("SendData failure.\n");
  3785. return false;
  3786. }
  3787. // Send third packet
  3788. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  3789. if (false == isSuccess)
  3790. {
  3791. printf("SendData failure.\n");
  3792. return false;
  3793. }
  3794. // Receive packets from the channels and compare results
  3795. isSuccess = ReceivePacketsAndCompare();
  3796. if (false == isSuccess)
  3797. {
  3798. printf("ReceivePacketsAndCompare failure.\n");
  3799. return false;
  3800. }
  3801. // until here test 25 was run, now we test hash invalidation
  3802. // commit the rules again to clear the cache
  3803. res = AddRules();
  3804. if (false == res) {
  3805. printf("Failed adding routing rules.\n");
  3806. return false;
  3807. }
  3808. // send the packet again
  3809. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  3810. if (false == isSuccess)
  3811. {
  3812. printf("SendData failure.\n");
  3813. return false;
  3814. }
  3815. // validate we got cache miss
  3816. isSuccess = ReceivePacketsAndCompareSpecial();
  3817. if (false == isSuccess)
  3818. {
  3819. printf("ReceivePacketsAndCompareSpecial failure.\n");
  3820. }
  3821. return isSuccess;
  3822. } // Run()
  3823. };
  3824. /*--------------------------------------------------------------------------*/
  3825. /* Test28: IPv6 - Tests routing hashable, non hashable, */
  3826. /* cache/hash invalidation test on rule delition */
  3827. /*--------------------------------------------------------------------------*/
  3828. class IpaRoutingBlockTest028 : public IpaRoutingBlockTest025
  3829. {
  3830. public:
  3831. IpaRoutingBlockTest028()
  3832. {
  3833. m_name = "IpaRoutingBlockTest028";
  3834. m_description =" \
  3835. Routing block test 028 - this test perform test 025 and then deletes last rule\
  3836. another identical packet is sent: DST_IP == 192.168.02.170 and expected to get cache miss";
  3837. }
  3838. bool Run()
  3839. {
  3840. bool res = false;
  3841. bool isSuccess = false;
  3842. // Add the relevant routing rules
  3843. res = AddRules();
  3844. if (false == res) {
  3845. printf("Failed adding routing rules.\n");
  3846. return false;
  3847. }
  3848. // Load input data (IP packet) from file
  3849. res = LoadFiles(IPA_IP_v6);
  3850. if (false == res) {
  3851. printf("Failed loading files.\n");
  3852. return false;
  3853. }
  3854. // Send first packet
  3855. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3856. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  3857. if (false == isSuccess)
  3858. {
  3859. printf("SendData failure.\n");
  3860. return false;
  3861. }
  3862. // Send second packet
  3863. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  3864. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  3865. if (false == isSuccess)
  3866. {
  3867. printf("SendData failure.\n");
  3868. return false;
  3869. }
  3870. // Send third packet
  3871. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  3872. if (false == isSuccess)
  3873. {
  3874. printf("SendData failure.\n");
  3875. return false;
  3876. }
  3877. // Receive packets from the channels and compare results
  3878. isSuccess = ReceivePacketsAndCompare();
  3879. if (false == isSuccess)
  3880. {
  3881. printf("ReceivePacketsAndCompare failure.\n");
  3882. return false;
  3883. }
  3884. // until here test 25 was run, now we test hash invalidation
  3885. // delete the last rule, this should clear the cache
  3886. res = RemoveLastRule(IPA_IP_v6);
  3887. if (false == res) {
  3888. printf("Failed removing filtering rules.\n");
  3889. return false;
  3890. }
  3891. // send the packet again
  3892. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  3893. if (false == isSuccess)
  3894. {
  3895. printf("SendData failure.\n");
  3896. return false;
  3897. }
  3898. // validate we got cache miss
  3899. isSuccess = ReceivePacketsAndCompareSpecial();
  3900. if (false == isSuccess)
  3901. {
  3902. printf("ReceivePacketsAndCompareSpecial failure.\n");
  3903. }
  3904. return isSuccess;
  3905. } // Run()
  3906. };
  3907. /*--------------------------------------------------------------------------*/
  3908. /* Test30: Pure ack packet matching */
  3909. /*--------------------------------------------------------------------------*/
  3910. class IpaRoutingBlockTest030 : IpaRoutingBlockTestFixture
  3911. {
  3912. public:
  3913. IpaRoutingBlockTest030()
  3914. {
  3915. m_name = "IpaRoutingBlockTest030";
  3916. m_description =" \
  3917. Routing block test 030 - Pure Ack packet matching \
  3918. 1. Generate and commit a single routing table. \
  3919. 2. Generate and commit Three routing rules: \
  3920. All TCP pure ack traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  3921. All DST_IP == (192.168.2.200 & 255.255.255.255) traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  3922. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  3923. m_IpaIPType = IPA_IP_v4;
  3924. m_minIPAHwType = IPA_HW_v4_5;
  3925. Register(*this);
  3926. }
  3927. bool LoadPackets()
  3928. {
  3929. if (!LoadNoPayloadPacket(m_IpaIPType, m_sendBuffer, m_sendSize)) {
  3930. LOG_MSG_ERROR("Failed loading No Payload Packet");
  3931. return false;
  3932. }
  3933. if (!LoadDefaultPacket(m_IpaIPType, m_sendBuffer2, m_sendSize2)) {
  3934. LOG_MSG_ERROR("Failed loading default Packet");
  3935. return false;
  3936. }
  3937. if (!LoadDefaultPacket(m_IpaIPType, m_sendBuffer3, m_sendSize3)) {
  3938. LOG_MSG_ERROR("Failed loading default Packet");
  3939. return false;
  3940. }
  3941. return true;
  3942. }
  3943. bool Run()
  3944. {
  3945. bool res = false;
  3946. bool isSuccess = false;
  3947. // Add the relevant routing rules
  3948. res = AddRules();
  3949. if (false == res) {
  3950. printf("Failed adding routing rules.\n");
  3951. return false;
  3952. }
  3953. // Load IP packets
  3954. res = LoadPackets();
  3955. if (false == res) {
  3956. printf("Failed loading packets\n");
  3957. return false;
  3958. }
  3959. // Send first packet
  3960. m_sendBuffer[IPv4_TCP_FLAGS_OFFSET] |= TCP_ACK_FLAG_MASK;
  3961. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xC8;
  3962. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  3963. if (false == isSuccess)
  3964. {
  3965. printf("SendData failure.\n");
  3966. return false;
  3967. }
  3968. // Send second packet
  3969. m_sendBuffer2[IPv4_TCP_FLAGS_OFFSET] |= TCP_ACK_FLAG_MASK;
  3970. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xC8;
  3971. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  3972. if (false == isSuccess)
  3973. {
  3974. printf("SendData failure.\n");
  3975. return false;
  3976. }
  3977. // Send third packet
  3978. m_sendBuffer3[IPv4_TCP_FLAGS_OFFSET] |= TCP_ACK_FLAG_MASK;
  3979. m_sendBuffer3[DST_ADDR_LSB_OFFSET_IPV4] = 0x64;
  3980. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  3981. if (false == isSuccess)
  3982. {
  3983. printf("SendData failure.\n");
  3984. return false;
  3985. }
  3986. // Receive packets from the channels and compare results
  3987. isSuccess = ReceivePacketsAndCompare();
  3988. return isSuccess;
  3989. } // Run()
  3990. bool AddRules()
  3991. {
  3992. struct ipa_ioc_add_rt_rule *rt_rule;
  3993. struct ipa_rt_rule_add *rt_rule_entry;
  3994. const int NUM_RULES = 3;
  3995. rt_rule = (struct ipa_ioc_add_rt_rule *)
  3996. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  3997. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  3998. if(!rt_rule) {
  3999. printf("fail\n");
  4000. return false;
  4001. }
  4002. rt_rule->commit = 1;
  4003. rt_rule->num_rules = NUM_RULES;
  4004. rt_rule->ip = IPA_IP_v4;
  4005. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  4006. rt_rule_entry = &rt_rule->rules[0];
  4007. rt_rule_entry->at_rear = 0;
  4008. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  4009. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_IS_PURE_ACK;
  4010. rt_rule_entry = &rt_rule->rules[1];
  4011. rt_rule_entry->at_rear = 1;
  4012. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  4013. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  4014. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802C8;
  4015. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  4016. rt_rule_entry = &rt_rule->rules[2];
  4017. rt_rule_entry->at_rear = 1;
  4018. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  4019. if (false == m_routing.AddRoutingRule(rt_rule))
  4020. {
  4021. printf("Routing rule addition failed!\n");
  4022. return false;
  4023. }
  4024. free(rt_rule);
  4025. InitFilteringBlock();
  4026. return true;
  4027. }
  4028. };
  4029. /*--------------------------------------------------------------------------*/
  4030. /* Test31: IPv6 Pure ack packet matching */
  4031. /*--------------------------------------------------------------------------*/
  4032. class IpaRoutingBlockTest031 : public IpaRoutingBlockTestFixture
  4033. {
  4034. public:
  4035. IpaRoutingBlockTest031()
  4036. {
  4037. m_name = "IpaRoutingBlockTest031";
  4038. m_description =" \
  4039. Routing block test 031 - IPv6 Pure Ack packet matching \
  4040. 1. Generate and commit a single routing table. \
  4041. 2. Generate and commit Three routing rules: \
  4042. All TCP pure ack traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  4043. All DST_IP == 0XFF020000 \
  4044. 0x00000000 \
  4045. 0x00000000 \
  4046. 0X000000F5 \
  4047. traffic goes to pipe IPA_CLIENT_TEST3_CONS \
  4048. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS";
  4049. m_IpaIPType = IPA_IP_v6;
  4050. m_minIPAHwType = IPA_HW_v4_5;
  4051. Register(*this);
  4052. }
  4053. bool LoadPackets()
  4054. {
  4055. if (!LoadNoPayloadPacket(m_IpaIPType, m_sendBuffer, m_sendSize)) {
  4056. LOG_MSG_ERROR("Failed loading No Payload Packet");
  4057. return false;
  4058. }
  4059. if (!LoadNoPayloadPacket(m_IpaIPType, m_sendBuffer2, m_sendSize2)) {
  4060. LOG_MSG_ERROR("Failed loading default Packet");
  4061. return false;
  4062. }
  4063. if (!LoadNoPayloadPacket(m_IpaIPType, m_sendBuffer3, m_sendSize3)) {
  4064. LOG_MSG_ERROR("Failed loading default Packet");
  4065. return false;
  4066. }
  4067. return true;
  4068. }
  4069. bool Run()
  4070. {
  4071. bool res = false;
  4072. bool isSuccess = false;
  4073. // Add the relevant routing rules
  4074. res = AddRules();
  4075. if (false == res) {
  4076. printf("Failed adding routing rules.\n");
  4077. return false;
  4078. }
  4079. // Load input data (IP packet)
  4080. res = LoadPackets();
  4081. if (false == res) {
  4082. printf("Failed loading packets\n");
  4083. return false;
  4084. }
  4085. // Send first packet
  4086. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xF5;
  4087. m_sendBuffer[IPv6_TCP_FLAGS_OFFSET] |= TCP_ACK_FLAG_MASK;
  4088. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  4089. if (false == isSuccess)
  4090. {
  4091. printf("SendData failure.\n");
  4092. return false;
  4093. }
  4094. // Send second packet
  4095. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xF5;
  4096. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  4097. if (false == isSuccess)
  4098. {
  4099. printf("SendData failure.\n");
  4100. return false;
  4101. }
  4102. // Send third packet
  4103. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  4104. if (false == isSuccess)
  4105. {
  4106. printf("SendData failure.\n");
  4107. return false;
  4108. }
  4109. // Receive packets from the channels and compare results
  4110. isSuccess = ReceivePacketsAndCompare();
  4111. return isSuccess;
  4112. } // Run()
  4113. bool AddRules()
  4114. {
  4115. struct ipa_ioc_add_rt_rule *rt_rule;
  4116. struct ipa_rt_rule_add *rt_rule_entry;
  4117. const int NUM_RULES = 3;
  4118. rt_rule = (struct ipa_ioc_add_rt_rule *)
  4119. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  4120. NUM_RULES*sizeof(struct ipa_rt_rule_add));
  4121. if(!rt_rule) {
  4122. printf("fail\n");
  4123. return false;
  4124. }
  4125. rt_rule->commit = 1;
  4126. rt_rule->num_rules = NUM_RULES;
  4127. rt_rule->ip = IPA_IP_v6;
  4128. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  4129. rt_rule_entry = &rt_rule->rules[0];
  4130. rt_rule_entry->at_rear = 0;
  4131. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  4132. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_IS_PURE_ACK;
  4133. rt_rule_entry = &rt_rule->rules[1];
  4134. rt_rule_entry->at_rear = 1;
  4135. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  4136. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  4137. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  4138. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  4139. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  4140. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000F5;
  4141. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  4142. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  4143. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  4144. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  4145. rt_rule_entry = &rt_rule->rules[2];
  4146. rt_rule_entry->at_rear = 1;
  4147. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  4148. if (false == m_routing.AddRoutingRule(rt_rule))
  4149. {
  4150. printf("Routing rule addition failed!\n");
  4151. return false;
  4152. }
  4153. free(rt_rule);
  4154. InitFilteringBlock();
  4155. return true;
  4156. }
  4157. };
  4158. /*---------------------------------------------------------------------------*/
  4159. /* Test100: Cache LRU behavior test */
  4160. /*---------------------------------------------------------------------------*/
  4161. #define CHACHE_ENTRIES 64
  4162. #define CHACHE_PLUS_ONE (CHACHE_ENTRIES +1)
  4163. class IpaRoutingBlockTest040 : public IpaRoutingBlockTestFixture
  4164. {
  4165. public:
  4166. IpaRoutingBlockTest040()
  4167. {
  4168. m_name = "IpaRoutingBlockTest040";
  4169. m_description = " \
  4170. Routing block test 40 - Cache LRU behavior test \
  4171. 1. Preload the cache by sending 64 packets for different connections \
  4172. 2. Send another packet for 65th connection \
  4173. 3. Send packets for first 64 connections \
  4174. 4. Verify that 1st connection’s entry was reclaimed";
  4175. m_IpaIPType = IPA_IP_v4;
  4176. m_minIPAHwType = IPA_HW_v4_0;
  4177. Register(*this);
  4178. }
  4179. bool Setup()
  4180. {
  4181. return IpaRoutingBlockTestFixture:: Setup(true);
  4182. }
  4183. virtual bool AddRules()
  4184. {
  4185. struct ipa_ioc_add_rt_rule *rt_rule;
  4186. struct ipa_rt_rule_add *rt_rule_entry;
  4187. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  4188. rt_rule = (struct ipa_ioc_add_rt_rule *)
  4189. calloc(1, sizeof(struct ipa_ioc_add_rt_rule) +
  4190. CHACHE_PLUS_ONE * sizeof(struct ipa_rt_rule_add));
  4191. if(!rt_rule) {
  4192. printf("Failed memory allocation for rt_rule\n");
  4193. return false;
  4194. }
  4195. rt_rule->commit = 1;
  4196. rt_rule->num_rules = CHACHE_PLUS_ONE;
  4197. rt_rule->ip = IPA_IP_v4;
  4198. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  4199. for (int i = 0; i < CHACHE_PLUS_ONE; i++) {
  4200. rt_rule_entry = &rt_rule->rules[i];
  4201. rt_rule_entry->at_rear = 1;
  4202. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  4203. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  4204. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A80101 + i; // DST_IP == 192.168.1.(1+i)
  4205. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  4206. rt_rule_entry->rule.hashable = 1;
  4207. }
  4208. // The last rule has to be catch all, otherwize no rule will work
  4209. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0x0;
  4210. if (false == m_routing.AddRoutingRule(rt_rule))
  4211. {
  4212. printf("Routing rule addition failed!\n");
  4213. return false;
  4214. }
  4215. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  4216. free(rt_rule);
  4217. InitFilteringBlock();
  4218. printf("Leaving %s, %s()\n",__FUNCTION__, __FILE__);
  4219. return true;
  4220. }
  4221. bool Run()
  4222. {
  4223. bool res = false;
  4224. bool isSuccess = false;
  4225. printf("Entering %s, %s()\n", __FUNCTION__, __FILE__);
  4226. // Add the relevant filtering rules
  4227. res = AddRules();
  4228. if (false == res) {
  4229. printf("Failed adding filtering rules.\n");
  4230. return false;
  4231. }
  4232. // Load input data (IP packet) from file
  4233. res = LoadFiles(IPA_IP_v4);
  4234. if (false == res) {
  4235. printf("Failed loading files.\n");
  4236. return false;
  4237. }
  4238. // Send the first CHACHE_ENTRIES packets
  4239. // Receive packets from the channels and compare results
  4240. // All rules should be cache miss
  4241. for (int i = 0; i < CHACHE_ENTRIES; i++) {
  4242. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0x1 + i;
  4243. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  4244. if (false == isSuccess)
  4245. {
  4246. printf("SendData failure.\n");
  4247. return false;
  4248. }
  4249. isSuccess = ReceivePacketAndCompareFrom(m_consumer, m_sendBuffer, m_sendSize, false);
  4250. if (false == isSuccess) {
  4251. printf("%s:%d: ReceivePacketAndCompareFrom failure.\n", __FUNCTION__, __LINE__);
  4252. return false;
  4253. }
  4254. }
  4255. // Send again the first CHACHE_ENTRIES packets
  4256. // Receive packets from the channels and compare results
  4257. // All rules should be cache hit
  4258. for (int i = 0; i < CHACHE_ENTRIES; i++) {
  4259. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0x1 + i;
  4260. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  4261. if (false == isSuccess)
  4262. {
  4263. printf("SendData failure.\n");
  4264. return false;
  4265. }
  4266. isSuccess = ReceivePacketAndCompareFrom(m_consumer, m_sendBuffer, m_sendSize, true);
  4267. if (false == isSuccess) {
  4268. printf("%s:%d: ReceivePacketAndCompareFrom failure.\n", __FUNCTION__, __LINE__);
  4269. return false;
  4270. }
  4271. }
  4272. // Send a packet to a new filter entry, this should trigger the LRU clear
  4273. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0x1 + CHACHE_ENTRIES;
  4274. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  4275. if (false == isSuccess) {
  4276. printf("SendData failure.\n");
  4277. return false;
  4278. }
  4279. // receive and verify that cache was missed
  4280. isSuccess = ReceivePacketAndCompareFrom(m_consumer, m_sendBuffer, m_sendSize, false);
  4281. if (false == isSuccess) {
  4282. printf("%s:%d: ReceivePacketAndCompareFrom failure.\n", __FUNCTION__, __LINE__);
  4283. return false;
  4284. }
  4285. // send the first packet again
  4286. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0x1;
  4287. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  4288. if (false == isSuccess) {
  4289. printf("SendData failure.\n");
  4290. return false;
  4291. }
  4292. // receive and verify that cache was missed
  4293. isSuccess = ReceivePacketAndCompareFrom(m_consumer, m_sendBuffer, m_sendSize, false);
  4294. if (false == isSuccess) {
  4295. printf("%s:%d: ReceivePacketAndCompareFrom failure.\n", __FUNCTION__, __LINE__);
  4296. return false;
  4297. }
  4298. printf("Leaving %s, %s(), Returning %d\n",__FUNCTION__, __FILE__, isSuccess);
  4299. return isSuccess;
  4300. } // Run()
  4301. };
  4302. /*---------------------------------------------------------------------------*/
  4303. /* Test50: Test TTL update by routing to a destination address */
  4304. /*---------------------------------------------------------------------------*/
  4305. class IpaRoutingBlockTest050 : public IpaRoutingBlockTestFixture
  4306. {
  4307. public:
  4308. IpaRoutingBlockTest050()
  4309. {
  4310. m_name = "IpaRoutingBlockTest050";
  4311. m_description =" \
  4312. Routing block test 050 - Destination address exact match\1. Generate and commit a single routing tables. \
  4313. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  4314. All DST_IP == (192.169.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  4315. All DST_IP == (192.168.2.255 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  4316. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS \
  4317. 3. Check if TTL is updated. ";
  4318. m_IpaIPType = IPA_IP_v4;
  4319. m_minIPAHwType = IPA_HW_v5_5;
  4320. Register(*this);
  4321. }
  4322. bool Setup()
  4323. {
  4324. return IpaRoutingBlockTestFixture:: Setup(true);
  4325. }
  4326. bool AddRules()
  4327. {
  4328. struct ipa_ioc_add_rt_rule_v2 *rt_rule;
  4329. struct ipa_rt_rule_add_v2 *rt_rule_entry;
  4330. const int NUM_RULES = 3;
  4331. rt_rule = (struct ipa_ioc_add_rt_rule_v2 *)
  4332. calloc(1, sizeof(struct ipa_ioc_add_rt_rule_v2));
  4333. if(!rt_rule) {
  4334. printf("fail\n");
  4335. return false;
  4336. }
  4337. rt_rule->rules = (uint64_t)calloc(3, sizeof(struct ipa_rt_rule_add_v2));
  4338. if(!rt_rule->rules) {
  4339. printf("fail\n");
  4340. return false;
  4341. }
  4342. rt_rule->commit = 1;
  4343. rt_rule->num_rules = NUM_RULES;
  4344. rt_rule->ip = IPA_IP_v4;
  4345. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  4346. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[0]);
  4347. rt_rule_entry->at_rear = 0;
  4348. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  4349. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  4350. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802FF;
  4351. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  4352. rt_rule_entry->rule.ttl_update = 1;
  4353. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[1]);
  4354. rt_rule_entry->at_rear = 0;
  4355. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  4356. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  4357. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA;
  4358. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  4359. rt_rule_entry->rule.ttl_update = 1;
  4360. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[2]);
  4361. rt_rule_entry->at_rear = 1;
  4362. rt_rule_entry->rule.ttl_update = 0;
  4363. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  4364. if (false == m_routing.AddRoutingRule(rt_rule))
  4365. {
  4366. printf("Routing rule addition failed!\n");
  4367. return false;
  4368. }
  4369. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  4370. free(rt_rule);
  4371. InitFilteringBlock();
  4372. return true;
  4373. }
  4374. virtual bool Run()
  4375. {
  4376. bool res = false;
  4377. bool isSuccess = false;
  4378. // Add the relevant routing rules
  4379. res = AddRules();
  4380. if (false == res) {
  4381. printf("Failed adding routing rules.\n");
  4382. return false;
  4383. }
  4384. // Load input data (IP packet) from file
  4385. res = LoadFiles(IPA_IP_v4);
  4386. if (false == res) {
  4387. printf("Failed loading files.\n");
  4388. return false;
  4389. }
  4390. // Send first packet
  4391. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xFF;
  4392. m_sendBuffer[IPV4_TTL_OFFSET] = 5;
  4393. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  4394. if (false == isSuccess)
  4395. {
  4396. printf("SendData failure.\n");
  4397. return false;
  4398. }
  4399. // Send second packet
  4400. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  4401. m_sendBuffer2[IPV4_TTL_OFFSET] = 4;
  4402. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  4403. if (false == isSuccess)
  4404. {
  4405. printf("SendData failure.\n");
  4406. return false;
  4407. }
  4408. // Send third packet
  4409. m_sendBuffer3[IPV4_TTL_OFFSET] = 3;
  4410. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  4411. if (false == isSuccess)
  4412. {
  4413. printf("SendData failure.\n");
  4414. return false;
  4415. }
  4416. // Receive packets from the channels and compare results
  4417. isSuccess = ReceivePacketsAndCompare();
  4418. return isSuccess;
  4419. } // Run()
  4420. bool ReceivePacketsAndCompare()
  4421. {
  4422. size_t receivedSize = 0;
  4423. size_t receivedSize2 = 0;
  4424. size_t receivedSize3 = 0;
  4425. bool pkt1_cmp_succ, pkt2_cmp_succ, pkt3_cmp_succ;
  4426. uint16_t csum = 0;
  4427. // Receive results
  4428. Byte *rxBuff1 = new Byte[0x400];
  4429. Byte *rxBuff2 = new Byte[0x400];
  4430. Byte *rxBuff3 = new Byte[0x400];
  4431. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  4432. {
  4433. printf("Memory allocation error.\n");
  4434. return false;
  4435. }
  4436. memset(rxBuff1, 0, 0x400);
  4437. memset(rxBuff2, 0, 0x400);
  4438. memset(rxBuff3, 0, 0x400);
  4439. receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400);
  4440. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  4441. receivedSize2 = m_consumer2.ReceiveData(rxBuff2, 0x400);
  4442. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer2.m_fromChannelName.c_str());
  4443. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  4444. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  4445. /* Update TTL values. */
  4446. m_sendBuffer[IPV4_TTL_OFFSET] = 4;
  4447. m_sendBuffer2[IPV4_TTL_OFFSET] = 3;
  4448. /* Update Checksum.*/
  4449. csum = *((uint16_t *)(m_sendBuffer + IPV4_CSUM_OFFSET));
  4450. csum += 1;
  4451. *((uint16_t *)(m_sendBuffer+ IPV4_CSUM_OFFSET)) = csum;
  4452. csum = *((uint16_t *)(m_sendBuffer2 + IPV4_CSUM_OFFSET));
  4453. csum += 1;
  4454. *((uint16_t *)(m_sendBuffer2 + IPV4_CSUM_OFFSET)) = csum;
  4455. /* Compare results */
  4456. pkt1_cmp_succ = CompareResultVsGolden(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  4457. pkt2_cmp_succ = CompareResultVsGolden(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  4458. pkt3_cmp_succ = CompareResultVsGolden(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  4459. size_t recievedBufferSize =
  4460. MAX3(receivedSize, receivedSize2, receivedSize3) * 3;
  4461. size_t sentBufferSize =
  4462. MAX3(m_sendSize, m_sendSize2, m_sendSize3) * 3;
  4463. char *recievedBuffer = new char[recievedBufferSize];
  4464. char *sentBuffer = new char[sentBufferSize];
  4465. if (NULL == recievedBuffer || NULL == sentBuffer) {
  4466. printf("Memory allocation error\n");
  4467. return false;
  4468. }
  4469. size_t j;
  4470. memset(recievedBuffer, 0, recievedBufferSize);
  4471. memset(sentBuffer, 0, sentBufferSize);
  4472. for(j = 0; j < m_sendSize; j++)
  4473. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer[j]);
  4474. for(j = 0; j < receivedSize; j++)
  4475. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff1[j]);
  4476. printf("Expected Value1(%zu)\n%s\n, Received Value1(%zu)\n%s\n-->Value1 %s\n",
  4477. m_sendSize,sentBuffer,receivedSize,recievedBuffer,
  4478. pkt1_cmp_succ?"Match":"no Match");
  4479. memset(recievedBuffer, 0, recievedBufferSize);
  4480. memset(sentBuffer, 0, sentBufferSize);
  4481. for(j = 0; j < m_sendSize2; j++)
  4482. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer2[j]);
  4483. for(j = 0; j < receivedSize2; j++)
  4484. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff2[j]);
  4485. printf("Expected Value2 (%zu)\n%s\n, Received Value2(%zu)\n%s\n-->Value2 %s\n",
  4486. m_sendSize2,sentBuffer,receivedSize2,recievedBuffer,
  4487. pkt2_cmp_succ?"Match":"no Match");
  4488. memset(recievedBuffer, 0, recievedBufferSize);
  4489. memset(sentBuffer, 0, sentBufferSize);
  4490. for(j = 0; j < m_sendSize3; j++)
  4491. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer3[j]);
  4492. for(j = 0; j < receivedSize3; j++)
  4493. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff3[j]);
  4494. printf("Expected Value3 (%zu)\n%s\n, Received Value3(%zu)\n%s\n-->Value3 %s\n",
  4495. m_sendSize3,sentBuffer,receivedSize3,recievedBuffer,
  4496. pkt3_cmp_succ?"Match":"no Match");
  4497. delete[] recievedBuffer;
  4498. delete[] sentBuffer;
  4499. delete[] rxBuff1;
  4500. delete[] rxBuff2;
  4501. delete[] rxBuff3;
  4502. return pkt1_cmp_succ && pkt2_cmp_succ && pkt3_cmp_succ;
  4503. }
  4504. };
  4505. /*--------------------------------------------------------------------------*/
  4506. /* Test51: IPv4 - Tests routing hashable vs non hashable priorities */
  4507. /*--------------------------------------------------------------------------*/
  4508. class IpaRoutingBlockTest051 : public IpaRoutingBlockTestFixture
  4509. {
  4510. public:
  4511. IpaRoutingBlockTest051()
  4512. {
  4513. m_name = "IpaRoutingBlockTest051";
  4514. m_description =" \
  4515. Routing block test 051 - Destination address exact match hashable priority higher than non hashable \
  4516. both match the packet but only hashable should hit, second packet should get cache hit, \
  4517. Check if TTL is updated.\
  4518. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  4519. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  4520. All DST_IP == (192.168.2.170 & 255.255.255.255)traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  4521. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS \
  4522. 3. Check if TTL is updated.";
  4523. m_IpaIPType = IPA_IP_v4;
  4524. m_minIPAHwType = IPA_HW_v5_5;
  4525. Register(*this);
  4526. }
  4527. bool Setup()
  4528. {
  4529. return IpaRoutingBlockTestFixture:: Setup(true);
  4530. }
  4531. bool AddRules()
  4532. {
  4533. struct ipa_ioc_add_rt_rule_v2 *rt_rule;
  4534. struct ipa_rt_rule_add_v2 *rt_rule_entry;
  4535. const int NUM_RULES = 3;
  4536. rt_rule = (struct ipa_ioc_add_rt_rule_v2 *)
  4537. calloc(1, sizeof(struct ipa_ioc_add_rt_rule_v2));
  4538. if(!rt_rule) {
  4539. printf("fail\n");
  4540. return false;
  4541. }
  4542. rt_rule->rules = (uint64_t)calloc(3, sizeof(struct ipa_rt_rule_add_v2));
  4543. if(!rt_rule->rules) {
  4544. printf("fail\n");
  4545. return false;
  4546. }
  4547. rt_rule->commit = 1;
  4548. rt_rule->num_rules = NUM_RULES;
  4549. rt_rule->ip = IPA_IP_v4;
  4550. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  4551. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[0]);
  4552. rt_rule_entry->at_rear = 1;
  4553. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  4554. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  4555. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  4556. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  4557. rt_rule_entry->rule.hashable = 1; // hashable
  4558. rt_rule_entry->rule.ttl_update = 1; // TTL Update
  4559. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[1]);
  4560. rt_rule_entry->at_rear = 1;
  4561. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  4562. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  4563. rt_rule_entry->rule.attrib.u.v4.dst_addr = 0xC0A802AA; //192.168.02.170
  4564. rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0xFFFFFFFF;
  4565. rt_rule_entry->rule.hashable = 0; // non hashable
  4566. rt_rule_entry->rule.ttl_update = 1; // TTL Update
  4567. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[2]);
  4568. rt_rule_entry->at_rear = 1;
  4569. rt_rule_entry->rule.ttl_update = 0; // TTL Update
  4570. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  4571. if (false == m_routing.AddRoutingRule(rt_rule))
  4572. {
  4573. printf("Routing rule addition failed!\n");
  4574. return false;
  4575. }
  4576. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  4577. free(rt_rule);
  4578. InitFilteringBlock();
  4579. return true;
  4580. }
  4581. bool Run()
  4582. {
  4583. bool res = false;
  4584. bool isSuccess = false;
  4585. // Add the relevant routing rules
  4586. res = AddRules();
  4587. if (false == res) {
  4588. printf("Failed adding routing rules.\n");
  4589. return false;
  4590. }
  4591. // Load input data (IP packet) from file
  4592. res = LoadFiles(IPA_IP_v4);
  4593. if (false == res) {
  4594. printf("Failed loading files.\n");
  4595. return false;
  4596. }
  4597. // Send first packet
  4598. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  4599. m_sendBuffer[IPV4_TTL_OFFSET] = 5;
  4600. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  4601. if (false == isSuccess)
  4602. {
  4603. printf("SendData failure.\n");
  4604. return false;
  4605. }
  4606. // Send second packet
  4607. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV4] = 0xAA;
  4608. m_sendBuffer2[IPV4_TTL_OFFSET] = 4;
  4609. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize2);
  4610. if (false == isSuccess)
  4611. {
  4612. printf("SendData failure.\n");
  4613. return false;
  4614. }
  4615. // Send third packet
  4616. m_sendBuffer3[IPV4_TTL_OFFSET] = 3;
  4617. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  4618. if (false == isSuccess)
  4619. {
  4620. printf("SendData failure.\n");
  4621. return false;
  4622. }
  4623. // Receive packets from the channels and compare results
  4624. isSuccess = ReceivePacketsAndCompare();
  4625. return isSuccess;
  4626. } // Run()
  4627. bool ReceivePacketsAndCompare()
  4628. {
  4629. size_t receivedSize = 0;
  4630. size_t receivedSize2 = 0;
  4631. size_t receivedSize3 = 0;
  4632. bool isSuccess = true;
  4633. uint16_t csum = 0;
  4634. // Receive results
  4635. Byte *rxBuff1 = new Byte[0x400];
  4636. Byte *rxBuff2 = new Byte[0x400];
  4637. Byte *rxBuff3 = new Byte[0x400];
  4638. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  4639. {
  4640. printf("Memory allocation error.\n");
  4641. return false;
  4642. }
  4643. receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400);
  4644. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  4645. receivedSize2 = m_consumer.ReceiveData(rxBuff2, 0x400);
  4646. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer2.m_fromChannelName.c_str());
  4647. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  4648. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  4649. /* Update TTL values. */
  4650. m_sendBuffer[IPV4_TTL_OFFSET] = 4;
  4651. m_sendBuffer2[IPV4_TTL_OFFSET] = 3;
  4652. /* Update Checksum.*/
  4653. csum = *((uint16_t *)(m_sendBuffer + IPV4_CSUM_OFFSET));
  4654. csum += 1;
  4655. *((uint16_t *)(m_sendBuffer+ IPV4_CSUM_OFFSET)) = csum;
  4656. csum = *((uint16_t *)(m_sendBuffer2 + IPV4_CSUM_OFFSET));
  4657. csum += 1;
  4658. *((uint16_t *)(m_sendBuffer2 + IPV4_CSUM_OFFSET)) = csum;
  4659. /* Compare results */
  4660. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  4661. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  4662. isSuccess &= CompareResultVsGolden_w_Status(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  4663. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  4664. IsCacheMiss_v5_0(m_sendSize, receivedSize, rxBuff1) : IsCacheMiss(m_sendSize,receivedSize,rxBuff1);
  4665. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  4666. IsCacheHit_v5_0(m_sendSize2, receivedSize2, rxBuff2) : IsCacheHit(m_sendSize2,receivedSize2,rxBuff2);
  4667. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_0) ?
  4668. IsCacheMiss_v5_0(m_sendSize3, receivedSize3, rxBuff3) : IsCacheMiss(m_sendSize3,receivedSize3,rxBuff3);
  4669. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_5) ?
  4670. IsTTLUpdated_v5_5(m_sendSize, receivedSize, rxBuff1) : true;
  4671. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_5) ?
  4672. IsTTLUpdated_v5_5(m_sendSize2, receivedSize2, rxBuff2) : true;
  4673. isSuccess &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_5) ?
  4674. !IsTTLUpdated_v5_5(m_sendSize3, receivedSize3, rxBuff3) : true;
  4675. size_t recievedBufferSize = receivedSize * 3;
  4676. size_t sentBufferSize = m_sendSize * 3;
  4677. char *recievedBuffer = new char[recievedBufferSize];
  4678. char *sentBuffer = new char[sentBufferSize];
  4679. memset(recievedBuffer, 0, recievedBufferSize);
  4680. memset(sentBuffer, 0, sentBufferSize);
  4681. print_packets(receivedSize, m_sendSize, recievedBufferSize, sentBufferSize, rxBuff1, m_sendBuffer, recievedBuffer, sentBuffer);
  4682. print_packets(receivedSize2, m_sendSize2, recievedBufferSize, sentBufferSize, rxBuff2, m_sendBuffer2, recievedBuffer, sentBuffer);
  4683. print_packets(receivedSize3, m_sendSize3, recievedBufferSize, sentBufferSize, rxBuff3, m_sendBuffer3, recievedBuffer, sentBuffer);
  4684. delete[] recievedBuffer;
  4685. delete[] sentBuffer;
  4686. delete[] rxBuff1;
  4687. delete[] rxBuff2;
  4688. delete[] rxBuff3;
  4689. return isSuccess;
  4690. }
  4691. };
  4692. /*---------------------------------------------------------------------------*/
  4693. /* Test52: IPv6 - Test TTL update by routing to destination address */
  4694. /*---------------------------------------------------------------------------*/
  4695. class IpaRoutingBlockTest052 : public IpaRoutingBlockTestFixture
  4696. {
  4697. public:
  4698. IpaRoutingBlockTest052()
  4699. {
  4700. m_name = "IpaRoutingBlockTest052";
  4701. m_description =" \
  4702. Routing block test 052 - IPv6 Destination address exact match and check if TTL is updated \
  4703. 1. Generate and commit a single routing tables. \
  4704. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  4705. All DST_IP == 0XFF020000 \
  4706. 0x00000000 \
  4707. 0x00000000 \
  4708. 0X000000FF \
  4709. traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  4710. All DST_IP == 0XFF020000 \
  4711. 0x00000000 \
  4712. 0x00000000 \
  4713. 0X000000FF \
  4714. traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  4715. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS \
  4716. 3. Check if TTL is updated.";
  4717. m_IpaIPType = IPA_IP_v6;
  4718. m_minIPAHwType = IPA_HW_v5_5;
  4719. Register(*this);
  4720. }
  4721. bool Run()
  4722. {
  4723. bool res = false;
  4724. bool isSuccess = false;
  4725. // Add the relevant routing rules
  4726. res = AddRules();
  4727. if (false == res) {
  4728. printf("Failed adding routing rules.\n");
  4729. return false;
  4730. }
  4731. // Load input data (IP packet) from file
  4732. res = LoadFiles(IPA_IP_v6);
  4733. if (false == res) {
  4734. printf("Failed loading files.\n");
  4735. return false;
  4736. }
  4737. // Send first packet
  4738. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  4739. m_sendBuffer[HOP_LIMIT_OFFSET_IPV6] = 5;
  4740. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  4741. if (false == isSuccess)
  4742. {
  4743. printf("SendData failure.\n");
  4744. return false;
  4745. }
  4746. // Send second packet
  4747. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xAA;
  4748. m_sendBuffer2[HOP_LIMIT_OFFSET_IPV6] = 4;
  4749. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  4750. if (false == isSuccess)
  4751. {
  4752. printf("SendData failure.\n");
  4753. return false;
  4754. }
  4755. // Send third packet
  4756. m_sendBuffer3[HOP_LIMIT_OFFSET_IPV6] = 3;
  4757. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  4758. if (false == isSuccess)
  4759. {
  4760. printf("SendData failure.\n");
  4761. return false;
  4762. }
  4763. // Receive packets from the channels and compare results
  4764. isSuccess = ReceivePacketsAndCompare();
  4765. return isSuccess;
  4766. } // Run()
  4767. bool ReceivePacketsAndCompare()
  4768. {
  4769. size_t receivedSize = 0;
  4770. size_t receivedSize2 = 0;
  4771. size_t receivedSize3 = 0;
  4772. bool pkt1_cmp_succ, pkt2_cmp_succ, pkt3_cmp_succ;
  4773. // Receive results
  4774. Byte *rxBuff1 = new Byte[0x400];
  4775. Byte *rxBuff2 = new Byte[0x400];
  4776. Byte *rxBuff3 = new Byte[0x400];
  4777. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  4778. {
  4779. printf("Memory allocation error.\n");
  4780. return false;
  4781. }
  4782. memset(rxBuff1, 0, 0x400);
  4783. memset(rxBuff2, 0, 0x400);
  4784. memset(rxBuff3, 0, 0x400);
  4785. receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400);
  4786. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  4787. receivedSize2 = m_consumer2.ReceiveData(rxBuff2, 0x400);
  4788. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer2.m_fromChannelName.c_str());
  4789. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  4790. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  4791. /* Update TTL values. */
  4792. m_sendBuffer[HOP_LIMIT_OFFSET_IPV6] = 4;
  4793. m_sendBuffer2[HOP_LIMIT_OFFSET_IPV6] = 3;
  4794. /* Compare results */
  4795. pkt1_cmp_succ = CompareResultVsGolden(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  4796. pkt2_cmp_succ = CompareResultVsGolden(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  4797. pkt3_cmp_succ = CompareResultVsGolden(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  4798. size_t recievedBufferSize =
  4799. MAX3(receivedSize, receivedSize2, receivedSize3) * 3;
  4800. size_t sentBufferSize =
  4801. MAX3(m_sendSize, m_sendSize2, m_sendSize3) * 3;
  4802. char *recievedBuffer = new char[recievedBufferSize];
  4803. char *sentBuffer = new char[sentBufferSize];
  4804. if (NULL == recievedBuffer || NULL == sentBuffer) {
  4805. printf("Memory allocation error\n");
  4806. return false;
  4807. }
  4808. size_t j;
  4809. memset(recievedBuffer, 0, recievedBufferSize);
  4810. memset(sentBuffer, 0, sentBufferSize);
  4811. for(j = 0; j < m_sendSize; j++)
  4812. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer[j]);
  4813. for(j = 0; j < receivedSize; j++)
  4814. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff1[j]);
  4815. printf("Expected Value1(%zu)\n%s\n, Received Value1(%zu)\n%s\n-->Value1 %s\n",
  4816. m_sendSize,sentBuffer,receivedSize,recievedBuffer,
  4817. pkt1_cmp_succ?"Match":"no Match");
  4818. memset(recievedBuffer, 0, recievedBufferSize);
  4819. memset(sentBuffer, 0, sentBufferSize);
  4820. for(j = 0; j < m_sendSize2; j++)
  4821. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer2[j]);
  4822. for(j = 0; j < receivedSize2; j++)
  4823. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff2[j]);
  4824. printf("Expected Value2 (%zu)\n%s\n, Received Value2(%zu)\n%s\n-->Value2 %s\n",
  4825. m_sendSize2,sentBuffer,receivedSize2,recievedBuffer,
  4826. pkt2_cmp_succ?"Match":"no Match");
  4827. memset(recievedBuffer, 0, recievedBufferSize);
  4828. memset(sentBuffer, 0, sentBufferSize);
  4829. for(j = 0; j < m_sendSize3; j++)
  4830. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer3[j]);
  4831. for(j = 0; j < receivedSize3; j++)
  4832. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff3[j]);
  4833. printf("Expected Value3 (%zu)\n%s\n, Received Value3(%zu)\n%s\n-->Value3 %s\n",
  4834. m_sendSize3,sentBuffer,receivedSize3,recievedBuffer,
  4835. pkt3_cmp_succ?"Match":"no Match");
  4836. delete[] recievedBuffer;
  4837. delete[] sentBuffer;
  4838. delete[] rxBuff1;
  4839. delete[] rxBuff2;
  4840. delete[] rxBuff3;
  4841. return pkt1_cmp_succ && pkt2_cmp_succ && pkt3_cmp_succ;
  4842. }
  4843. bool AddRules()
  4844. {
  4845. struct ipa_ioc_add_rt_rule_v2 *rt_rule;
  4846. struct ipa_rt_rule_add_v2 *rt_rule_entry;
  4847. const int NUM_RULES = 3;
  4848. rt_rule = (struct ipa_ioc_add_rt_rule_v2 *)
  4849. calloc(1, sizeof(struct ipa_ioc_add_rt_rule_v2));
  4850. if(!rt_rule) {
  4851. printf("fail\n");
  4852. return false;
  4853. }
  4854. rt_rule->rules = (uint64_t)calloc(3, sizeof(struct ipa_rt_rule_add_v2));
  4855. if(!rt_rule->rules) {
  4856. printf("fail\n");
  4857. return false;
  4858. }
  4859. rt_rule->commit = 1;
  4860. rt_rule->num_rules = NUM_RULES;
  4861. rt_rule->ip = IPA_IP_v6;
  4862. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  4863. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[0]);
  4864. rt_rule_entry->at_rear = 0;
  4865. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  4866. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  4867. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  4868. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  4869. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  4870. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  4871. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  4872. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  4873. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  4874. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  4875. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  4876. rt_rule_entry->rule.ttl_update = 1; // TTL Update
  4877. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[1]);
  4878. rt_rule_entry->at_rear = 0;
  4879. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  4880. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  4881. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  4882. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  4883. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  4884. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  4885. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000AA;
  4886. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  4887. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  4888. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  4889. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  4890. rt_rule_entry->rule.ttl_update = 1; // TTL Update
  4891. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[2]);
  4892. rt_rule_entry->at_rear = 1;
  4893. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  4894. rt_rule_entry->rule.ttl_update = 0; // TTL Update
  4895. if (false == m_routing.AddRoutingRule(rt_rule))
  4896. {
  4897. printf("Routing rule addition failed!\n");
  4898. return false;
  4899. }
  4900. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  4901. free(rt_rule);
  4902. InitFilteringBlock();
  4903. return true;
  4904. }
  4905. };
  4906. /*---------------------------------------------------------------------------------------*/
  4907. /* Test53: IPv6 - Test TTL update by routing to destination address and check for status */
  4908. /*---------------------------------------------------------------------------------------*/
  4909. class IpaRoutingBlockTest053 : public IpaRoutingBlockTestFixture
  4910. {
  4911. public:
  4912. IpaRoutingBlockTest053()
  4913. {
  4914. m_name = "IpaRoutingBlockTest053";
  4915. m_description =" \
  4916. Routing block test 053 - IPv6 Destination address exact match and check if TTL is updated \
  4917. 1. Generate and commit a single routing tables. \
  4918. 2. Generate and commit Three routing rules: (DST & Mask Match). \
  4919. All DST_IP == 0XFF020000 \
  4920. 0x00000000 \
  4921. 0x00000000 \
  4922. 0X000000FF \
  4923. traffic goes to pipe IPA_CLIENT_TEST2_CONS \
  4924. All DST_IP == 0XFF020000 \
  4925. 0x00000000 \
  4926. 0x00000000 \
  4927. 0X000000FF \
  4928. traffic goes to pipe IPA_CLIENT_TEST3_CONS\
  4929. All other traffic goes to pipe IPA_CLIENT_TEST4_CONS \
  4930. 3. Check if TTL is updated and also the status has TTL bit updated.";
  4931. m_IpaIPType = IPA_IP_v6;
  4932. m_minIPAHwType = IPA_HW_v5_5;
  4933. Register(*this);
  4934. }
  4935. bool Setup()
  4936. {
  4937. return IpaRoutingBlockTestFixture:: Setup(true);
  4938. }
  4939. bool Run()
  4940. {
  4941. bool res = false;
  4942. bool isSuccess = false;
  4943. // Add the relevant routing rules
  4944. res = AddRules();
  4945. if (false == res) {
  4946. printf("Failed adding routing rules.\n");
  4947. return false;
  4948. }
  4949. // Load input data (IP packet) from file
  4950. res = LoadFiles(IPA_IP_v6);
  4951. if (false == res) {
  4952. printf("Failed loading files.\n");
  4953. return false;
  4954. }
  4955. // Send first packet
  4956. m_sendBuffer[DST_ADDR_LSB_OFFSET_IPV6] = 0xFF;
  4957. m_sendBuffer[HOP_LIMIT_OFFSET_IPV6] = 5;
  4958. isSuccess = m_producer.SendData(m_sendBuffer, m_sendSize);
  4959. if (false == isSuccess)
  4960. {
  4961. printf("SendData failure.\n");
  4962. return false;
  4963. }
  4964. // Send second packet
  4965. m_sendBuffer2[DST_ADDR_LSB_OFFSET_IPV6] = 0xAA;
  4966. m_sendBuffer2[HOP_LIMIT_OFFSET_IPV6] = 4;
  4967. isSuccess = m_producer.SendData(m_sendBuffer2, m_sendSize);
  4968. if (false == isSuccess)
  4969. {
  4970. printf("SendData failure.\n");
  4971. return false;
  4972. }
  4973. // Send third packet
  4974. m_sendBuffer3[HOP_LIMIT_OFFSET_IPV6] = 3;
  4975. isSuccess = m_producer.SendData(m_sendBuffer3, m_sendSize3);
  4976. if (false == isSuccess)
  4977. {
  4978. printf("SendData failure.\n");
  4979. return false;
  4980. }
  4981. // Receive packets from the channels and compare results
  4982. isSuccess = ReceivePacketsAndCompare();
  4983. return isSuccess;
  4984. } // Run()
  4985. bool ReceivePacketsAndCompare()
  4986. {
  4987. size_t receivedSize = 0;
  4988. size_t receivedSize2 = 0;
  4989. size_t receivedSize3 = 0;
  4990. bool pkt1_cmp_succ, pkt2_cmp_succ, pkt3_cmp_succ;
  4991. // Receive results
  4992. Byte *rxBuff1 = new Byte[0x400];
  4993. Byte *rxBuff2 = new Byte[0x400];
  4994. Byte *rxBuff3 = new Byte[0x400];
  4995. if (NULL == rxBuff1 || NULL == rxBuff2 || NULL == rxBuff3)
  4996. {
  4997. printf("Memory allocation error.\n");
  4998. return false;
  4999. }
  5000. memset(rxBuff1, 0, 0x400);
  5001. memset(rxBuff2, 0, 0x400);
  5002. memset(rxBuff3, 0, 0x400);
  5003. receivedSize = m_consumer.ReceiveData(rxBuff1, 0x400);
  5004. printf("Received %zu bytes on %s.\n", receivedSize, m_consumer.m_fromChannelName.c_str());
  5005. receivedSize2 = m_consumer2.ReceiveData(rxBuff2, 0x400);
  5006. printf("Received %zu bytes on %s.\n", receivedSize2, m_consumer2.m_fromChannelName.c_str());
  5007. receivedSize3 = m_defaultConsumer.ReceiveData(rxBuff3, 0x400);
  5008. printf("Received %zu bytes on %s.\n", receivedSize3, m_defaultConsumer.m_fromChannelName.c_str());
  5009. /* Update TTL values. */
  5010. m_sendBuffer[HOP_LIMIT_OFFSET_IPV6] = 4;
  5011. m_sendBuffer2[HOP_LIMIT_OFFSET_IPV6] = 3;
  5012. /* Compare results */
  5013. pkt1_cmp_succ = CompareResultVsGolden_w_Status(m_sendBuffer, m_sendSize, rxBuff1, receivedSize);
  5014. pkt2_cmp_succ = CompareResultVsGolden_w_Status(m_sendBuffer2, m_sendSize2, rxBuff2, receivedSize2);
  5015. pkt3_cmp_succ = CompareResultVsGolden_w_Status(m_sendBuffer3, m_sendSize3, rxBuff3, receivedSize3);
  5016. pkt1_cmp_succ &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_5) ?
  5017. IsTTLUpdated_v5_5(m_sendSize, receivedSize, rxBuff1) : true;
  5018. pkt2_cmp_succ &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_5) ?
  5019. IsTTLUpdated_v5_5(m_sendSize2, receivedSize2, rxBuff2) : true;
  5020. pkt3_cmp_succ &= (TestManager::GetInstance()->GetIPAHwType() >= IPA_HW_v5_5) ?
  5021. !IsTTLUpdated_v5_5(m_sendSize3, receivedSize3, rxBuff3) : true;
  5022. size_t recievedBufferSize =
  5023. MAX3(receivedSize, receivedSize2, receivedSize3) * 3;
  5024. size_t sentBufferSize =
  5025. MAX3(m_sendSize, m_sendSize2, m_sendSize3) * 3;
  5026. char *recievedBuffer = new char[recievedBufferSize];
  5027. char *sentBuffer = new char[sentBufferSize];
  5028. if (NULL == recievedBuffer || NULL == sentBuffer) {
  5029. printf("Memory allocation error\n");
  5030. return false;
  5031. }
  5032. size_t j;
  5033. memset(recievedBuffer, 0, recievedBufferSize);
  5034. memset(sentBuffer, 0, sentBufferSize);
  5035. for(j = 0; j < m_sendSize; j++)
  5036. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer[j]);
  5037. for(j = 0; j < receivedSize; j++)
  5038. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff1[j]);
  5039. printf("Expected Value1(%zu)\n%s\n, Received Value1(%zu)\n%s\n-->Value1 %s\n",
  5040. m_sendSize,sentBuffer,receivedSize,recievedBuffer,
  5041. pkt1_cmp_succ?"Match":"no Match");
  5042. memset(recievedBuffer, 0, recievedBufferSize);
  5043. memset(sentBuffer, 0, sentBufferSize);
  5044. for(j = 0; j < m_sendSize2; j++)
  5045. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer2[j]);
  5046. for(j = 0; j < receivedSize2; j++)
  5047. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff2[j]);
  5048. printf("Expected Value2 (%zu)\n%s\n, Received Value2(%zu)\n%s\n-->Value2 %s\n",
  5049. m_sendSize2,sentBuffer,receivedSize2,recievedBuffer,
  5050. pkt2_cmp_succ?"Match":"no Match");
  5051. memset(recievedBuffer, 0, recievedBufferSize);
  5052. memset(sentBuffer, 0, sentBufferSize);
  5053. for(j = 0; j < m_sendSize3; j++)
  5054. snprintf(&sentBuffer[3 * j], sentBufferSize - (3 * j + 1), " %02X", m_sendBuffer3[j]);
  5055. for(j = 0; j < receivedSize3; j++)
  5056. snprintf(&recievedBuffer[3 * j], recievedBufferSize - (3 * j + 1), " %02X", rxBuff3[j]);
  5057. printf("Expected Value3 (%zu)\n%s\n, Received Value3(%zu)\n%s\n-->Value3 %s\n",
  5058. m_sendSize3,sentBuffer,receivedSize3,recievedBuffer,
  5059. pkt3_cmp_succ?"Match":"no Match");
  5060. delete[] recievedBuffer;
  5061. delete[] sentBuffer;
  5062. delete[] rxBuff1;
  5063. delete[] rxBuff2;
  5064. delete[] rxBuff3;
  5065. return pkt1_cmp_succ && pkt2_cmp_succ && pkt3_cmp_succ;
  5066. }
  5067. bool AddRules()
  5068. {
  5069. struct ipa_ioc_add_rt_rule_v2 *rt_rule;
  5070. struct ipa_rt_rule_add_v2 *rt_rule_entry;
  5071. const int NUM_RULES = 3;
  5072. rt_rule = (struct ipa_ioc_add_rt_rule_v2 *)
  5073. calloc(1, sizeof(struct ipa_ioc_add_rt_rule_v2));
  5074. if(!rt_rule) {
  5075. printf("fail\n");
  5076. return false;
  5077. }
  5078. rt_rule->rules = (uint64_t)calloc(3, sizeof(struct ipa_rt_rule_add_v2));
  5079. if(!rt_rule->rules) {
  5080. printf("fail\n");
  5081. return false;
  5082. }
  5083. rt_rule->commit = 1;
  5084. rt_rule->num_rules = NUM_RULES;
  5085. rt_rule->ip = IPA_IP_v6;
  5086. strlcpy(rt_rule->rt_tbl_name, "LAN", sizeof(rt_rule->rt_tbl_name));
  5087. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[0]);
  5088. rt_rule_entry->at_rear = 0;
  5089. rt_rule_entry->rule.dst = IPA_CLIENT_TEST2_CONS;
  5090. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  5091. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  5092. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  5093. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  5094. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  5095. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000FF;
  5096. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  5097. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  5098. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  5099. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  5100. rt_rule_entry->rule.ttl_update = 1; // TTL Update
  5101. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[1]);
  5102. rt_rule_entry->at_rear = 0;
  5103. rt_rule_entry->rule.dst = IPA_CLIENT_TEST3_CONS;
  5104. // rt_rule_entry->rule.hdr_hdl = hdr_entry->hdr_hdl; // gidons, there is no support for header insertion / removal yet.
  5105. rt_rule_entry->rule.attrib.attrib_mask = IPA_FLT_DST_ADDR;
  5106. rt_rule_entry->rule.attrib.u.v6.dst_addr[0] = 0XFF020000;
  5107. rt_rule_entry->rule.attrib.u.v6.dst_addr[1] = 0x00000000;
  5108. rt_rule_entry->rule.attrib.u.v6.dst_addr[2] = 0x00000000;
  5109. rt_rule_entry->rule.attrib.u.v6.dst_addr[3] = 0X000000AA;
  5110. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[0] = 0xFFFFFFFF;
  5111. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[1] = 0xFFFFFFFF;
  5112. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF;
  5113. rt_rule_entry->rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF;
  5114. rt_rule_entry->rule.ttl_update = 1; // TTL Update
  5115. rt_rule_entry = &(((struct ipa_rt_rule_add_v2 *)rt_rule->rules)[2]);
  5116. rt_rule_entry->at_rear = 1;
  5117. rt_rule_entry->rule.dst = IPA_CLIENT_TEST4_CONS;
  5118. rt_rule_entry->rule.ttl_update = 0; // TTL Update
  5119. if (false == m_routing.AddRoutingRule(rt_rule))
  5120. {
  5121. printf("Routing rule addition failed!\n");
  5122. return false;
  5123. }
  5124. printf("rt rule hdl1=%x\n", rt_rule_entry->rt_rule_hdl);
  5125. free(rt_rule);
  5126. InitFilteringBlock();
  5127. return true;
  5128. }
  5129. };
  5130. static class IpaRoutingBlockTest1 ipaRoutingBlockTest1;
  5131. static class IpaRoutingBlockTest2 ipaRoutingBlockTest2;
  5132. static class IpaRoutingBlockTest3 ipaRoutingBlockTest3;
  5133. static class IpaRoutingBlockTest4 ipaRoutingBlockTest4;
  5134. static class IpaRoutingBlockTest5 ipaRoutingBlockTest5;
  5135. static class IpaRoutingBlockTest006 ipaRoutingBlockTest006;
  5136. static class IpaRoutingBlockTest007 ipaRoutingBlockTest007;
  5137. static class IpaRoutingBlockTest008 ipaRoutingBlockTest008;
  5138. static class IpaRoutingBlockTest009 ipaRoutingBlockTest009;
  5139. static class IpaRoutingBlockTest010 ipaRoutingBlockTest010;
  5140. static class IpaRoutingBlockTest011 ipaRoutingBlockTest011;
  5141. static class IpaRoutingBlockTest012 ipaRoutingBlockTest012;
  5142. static class IpaRoutingBlockTest013 ipaRoutingBlockTest013;
  5143. static class IpaRoutingBlockTest014 ipaRoutingBlockTest014;
  5144. static class IpaRoutingBlockTest015 ipaRoutingBlockTest015;
  5145. static class IpaRoutingBlockTest016 ipaRoutingBlockTest016;
  5146. static class IpaRoutingBlockTest017 ipaRoutingBlockTest017;
  5147. static class IpaRoutingBlockTest018 ipaRoutingBlockTest018;
  5148. static class IpaRoutingBlockTest020 ipaRoutingBlockTest020;
  5149. static class IpaRoutingBlockTest021 ipaRoutingBlockTest021;
  5150. static class IpaRoutingBlockTest022 ipaRoutingBlockTest022;
  5151. static class IpaRoutingBlockTest023 ipaRoutingBlockTest023;
  5152. static class IpaRoutingBlockTest024 ipaRoutingBlockTest024;
  5153. static class IpaRoutingBlockTest025 ipaRoutingBlockTest025;
  5154. static class IpaRoutingBlockTest026 ipaRoutingBlockTest026;
  5155. static class IpaRoutingBlockTest027 ipaRoutingBlockTest027;
  5156. static class IpaRoutingBlockTest028 ipaRoutingBlockTest028;
  5157. static class IpaRoutingBlockTest030 ipaRoutingBlockTest030;
  5158. static class IpaRoutingBlockTest031 ipaRoutingBlockTest031;
  5159. static class IpaRoutingBlockTest040 ipaRoutingBlockTest040;
  5160. static class IpaRoutingBlockTest050 ipaRoutingBlockTest050;
  5161. static class IpaRoutingBlockTest051 ipaRoutingBlockTest051;
  5162. static class IpaRoutingBlockTest052 ipaRoutingBlockTest052;
  5163. static class IpaRoutingBlockTest053 ipaRoutingBlockTest053;