Fixed newline characters throughout the code
[com/gs-lite.git] / src / lib / gscphost / lfta.c
1 /* ------------------------------------------------
2  Copyright 2014 AT&T Intellectual Property
3  Licensed under the Apache License, Version 2.0 (the "License");
4  you may not use this file except in compliance with the License.
5  You may obtain a copy of the License at
6  
7  http://www.apache.org/licenses/LICENSE-2.0
8  
9  Unless required by applicable law or agreed to in writing, software
10  distributed under the License is distributed on an "AS IS" BASIS,
11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  See the License for the specific language governing permissions and
13  limitations under the License.
14  ------------------------------------------- */
15 #include <gsconfig.h>
16 #include <fta.h>
17 #include <callbackregistries.h>
18 #include <ipcencoding.h>
19 #include <stdio.h>
20 #include "rdtsc.h"
21 #include "packet.h"
22 #include "gscpipc.h"
23
24 // new
25 //gs_uint64_t lfta_prefilter(struct packet * p);
26 extern gs_uint64_t (*lfta_prefilter)(void *pkt);
27
28 struct pr_stats {
29         gs_uint64_t process;
30         gs_uint64_t packets;
31 };
32
33 void rts_fta_process_packet(struct packet * p)
34 {
35     struct FTA * f;
36         gs_uint64_t prefilter;
37         static gs_uint32_t t=0;
38         static struct pr_stats s = {0};
39         gs_uint64_t s1;
40         gs_uint64_t s2;
41     prefilter=(*lfta_prefilter)(p);
42     
43     if (ftaexec_start()<0) {
44         gslog(LOG_EMERG,"GSCPRTS::error::could not init "
45               "FTA list itteration\n");
46         return;
47     }
48     s1=rdtsc();
49     while ((f=ftaexec_next())!=0) {
50         //              fprintf(stderr,"%llu %llu %llu\n",f->prefilter,prefilter,~( (prefilter&(f->prefilter)) | (~(f->prefilter)) ));
51                 if (~( (prefilter&(f->prefilter)) | (~(f->prefilter)) ) == 0)
52                         f->accept_packet(f,0,p,0);
53     }
54     s2=rdtsc();
55     s.process+=(s2-s1);
56     s.packets++;
57     intuple++;
58     cycles+=(s2-s1);
59 }
60
61 void rts_fta_done()
62 {
63     struct FTA * f;
64     if (ftaexec_start()<0) {
65         gslog(LOG_EMERG,"GSCPRTS::error::could not init "
66               "FTA list itteration\n");
67         return;
68     }
69     while ((f=ftaexec_next())!=0) {
70         f->control_fta(f,FTA_COMMAND_FILE_DONE,0,0);
71     }
72 }