ACN Mod-Pkt Analysis
import java.io.*;
import java.util.*;
class PAnalysis
{
static int nt=0;
static int nu=0;
static int pckt=0;
static int pcku=0;
static int szt=0;
static int szu=0;
public static void main(String args[]) throws Exception
{
FileReader fr=new FileReader(“input.txt”);
BufferedReader br=new BufferedReader(fr);
String s,s1;
while((s=br.readLine())!=null)
{
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)==’\t’)
{
check(s,i+1);
break;
}
}
}
System.out.println(“No of TCP Connection: “+nt);
System.out.println(“No of TCP packets: “+pckt);
System.out.println(“Total size of TCP packets received: “+szt);
System.out.println(“********************************************”);
System.out.println(“No of UDP Connection: “+nu);
System.out.println(“No of UDP packets: “+pcku);
System.out.println(“Total size of UDP packets received: “+szu);
fr.close();
}
public static void check(String s,int pos)
{
String s1=s.substring(pos,pos+3);
if(s1.equals(“TCP”))
{
nt++;
cal(s,true);
}
else
{
nu++;
cal(s,false);
}
}
public static void cal(String s,boolean flag)
{
StringTokenizer st=new StringTokenizer(s,”\t “);
String temp;
for(int k=0;k<7;k++)
temp=st.nextToken();
int no=Integer.parseInt(st.nextToken());
int size=Integer.parseInt(st.nextToken());
if(flag)
{
szt+=size;
pckt+=no;
}
else
{
szu+=size;
pcku+=no;
}
}
}