C D S UeLog 处理RNTI,ENBID,CELLID的方法_bruce_wang_janet的博客-程序员秘密

技术标签: Perl 沙漠之舟  

思路根据目前的导出log格式,进行补充 3个信息

 

 

#!perl -w
use strict;
use Data::Dumper;
use File::Basename;

my $BinPath =  (map{s#\n##g;$_} `cd`)[0];
$BinPath .= "\\";
my $OutPutDir = $BinPath."..\\result\\";
my $InFileHandle;
my $OutFileHandle;
my %ColName2Index;
my @SignalingArray;
my @SCELL_CArray;
my @RNTI_CArray;
my @IndexArray;
my @TimeArray;		
my @SignalingDataArray;
my @UETimeStampArray;
my $FileLineNum = 0;
#####################################
my $SignalingName = "Signaling";
my $RNTI_CName = "RNTI_C";	
my $SCELL_CName ="SCell ID";
my $IndexName ="Index";
my $TimeName ="Time";
my $SignalingDataName = "Signaling Data"; 
my $UETimeStampName = "UE Timestamp";
#####################################
&main();

sub main()
{
	&ProcessADir();
}

sub ProcessADir(){
	my @AllFiles = <..\\data\\*>;
	my @AProcessFiles = grep {m/csv$/ && !m$~$} @AllFiles;
	my $AFile;
	foreach $AFile (@AProcessFiles)
	{
		print "\nProcess $AFile \n";
		&ProcessAFile($BinPath."\\".$AFile);
	}
}

sub ProcessAFile(){
	my $InFilePath = shift @_;
	open($InFileHandle,"<",$InFilePath) or die "can't open file $InFilePath for $!\n";
	my $FirstLine = <$InFileHandle>;
	$FirstLine =~ s#\r##g;
	$FirstLine =~ s#\n##g;	
	%ColName2Index = () ;
	@SignalingArray = ();
	@SCELL_CArray =();
	@RNTI_CArray = ();
	@IndexArray = ();
	@TimeArray = ();		
	@SignalingDataArray = ();
	@UETimeStampArray = ();
	
	&GetColumnName($FirstLine);
#	print Dumper %ColName2Index;
	my $Line;
	my $SignalingIndex = $ColName2Index{$SignalingName};
	my $RNTI_CIndex = $ColName2Index{$RNTI_CName};	
	my $SCELL_CIndex = $ColName2Index{$SCELL_CName};
	my $IndexIndex = $ColName2Index{$IndexName};
	my $TimeIndex = $ColName2Index{$TimeName};	
	my $SignalingDataIndex = $ColName2Index{$SignalingDataName};
	my $UETimeStampNameIndex = $ColName2Index{$UETimeStampName};	
 
	#print "ColIndex : $IndexIndex,$TimeIndex,$SignalingDataIndex,$SignalingIndex,$RNTI_CIndex,$SCELL_CIndex \n";
 
	unless (defined ($SignalingIndex) && defined($RNTI_CIndex) && defined($SCELL_CIndex) &&
		defined ($IndexIndex) && defined($TimeIndex) && defined($SignalingDataIndex && defined($UETimeStampNameIndex))
		){
		die "cant 't find $SignalingName,$RNTI_CName,$SCELL_CName,$IndexName,$TimeName,$SignalingDataName.\n";
	}
	my $Signaling; my $RNTI_C; my $SCELL_C;my $UETimeStamp; my $Time;my $SignalingData;
	while(defined($Line = <$InFileHandle>)){
	
		$Line =~ s#\r##g;
		$Line =~ s#\n##g;	
		
		if ($Line =~ /log$/){
			next;
		}			
		unless (defined($Line) and $Line ne ""){
			next;
		}
		#print "$Line \n";
		my @AllDataCols = split /,/,$Line;
		
		($UETimeStamp,$Time,$SignalingData,$Signaling,$RNTI_C,$SCELL_C) = 
			@AllDataCols[$UETimeStampNameIndex ,$TimeIndex,$SignalingDataIndex,$SignalingIndex,$RNTI_CIndex,$SCELL_CIndex];
		

		
		$RNTI_C = ""  unless defined($RNTI_C);
		$SCELL_C = ""  unless defined($SCELL_C);		
		#print "$Signaling,$RNTI_C,$SCELL_C \n";
		
		push @SignalingArray,$Signaling;
		push @RNTI_CArray,$RNTI_C;		
		push @SCELL_CArray,$SCELL_C;	
		push @UETimeStampArray,$UETimeStamp;
		push @TimeArray,$Time;		
		push @SignalingDataArray,$SignalingData;			
		
	}
	$FileLineNum = scalar (@SignalingArray);
	print "File Line : $FileLineNum\n";
	&ProcessRNTI();
	&ProcessSCellID();	
	&OutPutFile($InFilePath);

}

sub OutPutFile(){
	my $OutFilePath = shift @_;
	$OutFilePath = $OutPutDir.basename($OutFilePath);
	#$OutFilePath =~ s#csv#txt#;
	open($OutFileHandle,">",$OutFilePath) or die "can't open file $OutFilePath for $!\n";
	my $IndexScan = 0;
	print $OutFileHandle  "Time1,Time2,MsgName,EnbId,CellId,Rnti,SignalingData\n";
	while($IndexScan < $FileLineNum) {

		print $OutFileHandle "2014-02-27 $TimeArray[$IndexScan],";	
		print $OutFileHandle "$UETimeStampArray[$IndexScan],";
		print $OutFileHandle "$SignalingArray[$IndexScan],";
		
		my $SCellValue = $SCELL_CArray[$IndexScan]; my $ENID="";my $CellID="";
	#	print "SCellValue : $SCellValue\n";
		if (defined($SCellValue) and  $SCellValue ne ""){
			if($SCellValue =~ /\((\d+)-(\d+)\)/){
			$ENID = $1;
			$CellID = $2;
			}
		}
		print $OutFileHandle "$ENID,";
		print $OutFileHandle "$CellID,";	
		my $RntiValue = $RNTI_CArray[$IndexScan];
		$RntiValue = hex($RntiValue);
		print $OutFileHandle "$RntiValue,";
		my $SSignalingData = $SignalingDataArray[$IndexScan];
		#$SSignalingData  =~ s#\s+##g;
		print $OutFileHandle "$SSignalingData";		
		print $OutFileHandle  "\n";
		$IndexScan++;
	}
}
 

sub ProcessSCellIDMessageAnalysis(){
	my ($BeginNO,$EndNO) = @_;
	my $BeginSCELLIDValue = $SCELL_CArray[$BeginNO];
	my $EndSCELLIDValue = $SCELL_CArray[$EndNO];	
	my  $Index = $BeginNO+1;
	my $LastIndex = $EndNO+2;
	if ($LastIndex >= $FileLineNum){
		$LastIndex = $FileLineNum;
	}
	my $ARangeMessageName = join ",",  (@SignalingArray)[$Index..$LastIndex];
#	print "RangeMessage: $ARangeMessageName \n";
	my $SingalName = $SignalingArray[$Index];
	if ( $ARangeMessageName =~ /RRCConnectionRequest/  || 
			 $ARangeMessageName =~ /RRCConnectionRelease/ ||
			 $ARangeMessageName =~ /RRCConnectionReestablishmentRequest/ ||
			 $ARangeMessageName =~ /RRCConnectionReestablishment/)
	{
		return;
	}
	if ( $ARangeMessageName =~ /(.*)RRCConnectionReconfigurationComplete,MasterInformationBlock/){
#		print "compare before value: $1 \n";
		my $BeforeMessageJoinInfo = $1;
		if ($BeforeMessageJoinInfo =~ /(.*)RRCConnectionReconfigurationComplete,MasterInformationBlock/){
			return;
		}
		my @BeforeMessageNames = split /,/,$1;
		my $FillBeginCount = scalar(@BeforeMessageNames);
	#	print "$FillBeginCount \n";
		my  $SmallIndex = $BeginNO+1;
		while ($SmallIndex<=$BeginNO+$FillBeginCount){
			$SCELL_CArray[$SmallIndex] = $BeginSCELLIDValue;
			$SmallIndex++;
		}
		while ($SmallIndex<$EndNO){
			$SCELL_CArray[$SmallIndex] = $EndSCELLIDValue;
			$SmallIndex++;
		}		
		
	}
	else{
		return;
	}
}
sub ProcessSCellRange(){
	my ($BeginNO,$EndNO) = @_;
	my $BeginSCELLIDValue = $SCELL_CArray[$BeginNO];
	my $EndSCELLIDValue = $SCELL_CArray[$EndNO];
	if ($BeginSCELLIDValue  eq  $EndSCELLIDValue){
		my  $Index = $BeginNO+1;
		while ($Index<$EndNO){
			$SCELL_CArray[$Index] = $BeginSCELLIDValue;
			$Index++;
		}
	}
	else{
		&ProcessSCellIDMessageAnalysis($BeginNO,$EndNO);
	}
}
sub ProcessSCellID()
{
	my $BeginNO = -1;
	my $CurSCellID = "";
	my $CurNO = 0;
	foreach $CurSCellID (@SCELL_CArray){
		if ($CurSCellID eq "" || $CurSCellID eq "0"){
			 
		}else{
			 #处理之上为空的
			unless ($BeginNO ==-1 || $BeginNO==($CurNO-1)){
	#			print "will process $BeginNO,$CurNO \n";
				&ProcessSCellRange($BeginNO,$CurNO);	
			}
			$BeginNO = $CurNO;
		}
		$CurNO++;
	}
#	print "SCellID:\n";
#	print Dumper @SCELL_CArray;
}

sub ProcessMessageAnalysis(){
	my ($BeginNO,$EndNO) = @_;
	my $BeginRNTIValue = $RNTI_CArray[$BeginNO];
	my $EndRNTIValue = $RNTI_CArray[$EndNO];
	my  $Index = $BeginNO+1;
	my $LastIndex = $EndNO+2;
	if ($LastIndex >= $FileLineNum){
		$LastIndex = $FileLineNum;
	}
	my $ARangeMessageName = join ",",  (@SignalingArray)[$Index..$LastIndex];
#	print "RangeMessage: $ARangeMessageName \n";
	my $SingalName = $SignalingArray[$Index];
	if ( $ARangeMessageName =~ /RRCConnectionRequest/  || 
			 $ARangeMessageName =~ /RRCConnectionRelease/ ||
			 $ARangeMessageName =~ /RRCConnectionReestablishmentRequest/ ||
			 $ARangeMessageName =~ /RRCConnectionReestablishment/)
	{
		return;
	}
	if ( $ARangeMessageName =~ /(.*)RRCConnectionReconfigurationComplete,MasterInformationBlock/){
	#	print "compare before value: $1 \n";
		my @BeforeMessageNames = split /,/,$1;
		my $FillBeginCount = scalar(@BeforeMessageNames);
	#	print "$FillBeginCount \n";
		my  $SmallIndex = $BeginNO+1;
		while ($SmallIndex<=$BeginNO+$FillBeginCount){
			$RNTI_CArray[$SmallIndex] = $BeginRNTIValue;
			$SmallIndex++;
		}
		while ($SmallIndex<$EndNO){
			$RNTI_CArray[$SmallIndex] = $EndRNTIValue;
			$SmallIndex++;
		}		
		
	}
	else{
		return;
	}
}
sub ProcessRNTIRange(){
	my ($BeginNO,$EndNO) = @_;
	my $BeginRNTIValue = $RNTI_CArray[$BeginNO];
	my $EndRNTIValue = $RNTI_CArray[$EndNO];
	if ($BeginRNTIValue  eq  $EndRNTIValue){
		my  $Index = $BeginNO+1;
		while ($Index<$EndNO){
			$RNTI_CArray[$Index] = $BeginRNTIValue;
			$Index++;
		}
	
	}
	else{
		&ProcessMessageAnalysis($BeginNO,$EndNO);
	}

}
sub ProcessRNTI(){
	my $BeginNO = -1;
	my $CurRNTI = "";
	my $CurNO = 0;
	foreach $CurRNTI (@RNTI_CArray){
		if ($CurRNTI eq "" || $CurRNTI eq "0"){
			 
		}else{
			 #处理之上为空的
			unless ($BeginNO ==-1 || $BeginNO==($CurNO-1)){
			#	print "will process $BeginNO,$CurNO \n";
				&ProcessRNTIRange($BeginNO,$CurNO);	
			}
			$BeginNO = $CurNO;
		}
		$CurNO++;
	}
	#print "CNTI:\n";
	#print Dumper @RNTI_CArray;
}

sub GetColumnName($){
	my $FirstLine = shift @_;
	my @ColumnName = split /,/,$FirstLine;
	my $AColName;
	my $ColIndex = 0;
	foreach $AColName (@ColumnName){
		$ColName2Index{$AColName} = $ColIndex;
		$ColIndex++;
	}
}


 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/bruce_wang_janet/article/details/20135465

智能推荐

一文了解地理数据和三维地理信息系统_mouruikeji2021的博客-程序员秘密

一、地理数据地理数据是各种地理特征和现象之间关系的符号化表示,包括空间位置、属性特征(简称属性)及时域特征。(1)空间位置描述地物所在位置,既可以根据大地参照系定义,也可以定义为地物间的相对位置,如空间上的相邻、包含等。(2)属性特征又称非空间数据,是描述特定地理要素特征的定性或定量指标。(3)时域特征指的是地理数据采集或地理现象发生的时刻或时段。可以说,空间位置、属性以及时间时地理空间分析的三大基本要素。二、地理信息系统1.定义地理信息系统(Geographic Informati

9 年云原生实践全景揭秘|《阿里巴巴云原生实践 15 讲》正式开放下载_cihuixun5247的博客-程序员秘密

以容器、服务网格、微服务、Serverless 为代表的云原生技术,带来一种全新的方式来构建应用。同时,云原生也在拓展云计算的边界,一方面是多云、混合云推动无边界云计算,一方面云边端的协同。在云的趋势下,越来越多的企业开始将业务与技术向“云原生”演进。在这个演进过程中,企业都或多或少都面对一...

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.tran_yijiaodingqiankun的博客-程序员秘密

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.&amp;gt; com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.Ex...

iOS Frame与Bounds的区别和使用_敛柒的博客-程序员秘密

官方文档:Frame:The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.This rectangle defines the size and position of the view in its superview’s coordin...

运维笔记_Young_svg的博客-程序员秘密

什么是运维术语名词IDC–(Internet Data Center)互联网数据中心,主要服务包括整机租用、服务器托管、机柜租用、机房租用、专线接入和网络管理服务等。广义上的IDC业务,实际上就是数据中心所提供的一切服务。客户租用数据中心的服务器和带宽,并利用数据中心的技术力量,来实现自己对软、硬件的要求,搭建自己的互联网平台,享用数据中心所提供的一系列服务。ISP–(Internet Service Provider)互联网服务提供商,即向广大用户综合提供互联网接入业务、信息业务、和增值业务的电信

vue-cli中less文件内图片引入问题_cichenhai9250的博客-程序员秘密

在lees文件中直接拼接地址 background-image: url("../../components/header/@{url}@2x.png"); 当在其他文件中引入less文件时,会以less文件所在位置为基准去寻找图片文件; 而以 background-image: ~"ur...

随便推点

Google Earth Engine(GEE)—geemap 区域之的统计_此星光明的博客-程序员秘密

# !pip install geemapimport eeimport geemapimport os创建交互式地图Map = geemap.Map()Map加载数据# 加载Earth Engine 数据dem = ee.Image('USGS/SRTMGL1_003')#设置视觉参数dem_vis = { 'min': 0, 'max': 4000, 'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', .

程序员必定会爱上的10款软件_程序员爱上的软件_cxx0710163com的博客-程序员秘密

程序员必定会爱上的10款软件第一款:TrueCryptTrueCrypt可能很多人没用过,它是一个加密软件,能够对磁盘进行加密。还在担心自己电脑中的重要文件、私密档案被人查看。什么,你以为把文件设置了隐藏属性别人就看不到了?:) :)快来用TrueCrypt ,你必定会爱上它的。特点:对某一磁盘分区进行加密,开启计算机后,如果你没有打开TrueCrypt 这个软件,这个

J2EE基础教程(1):简介和windows下环境配置_define_us的博客-程序员秘密

(1)相关概念我们以前在linux操作系统初级教程中,介绍过LAMP架构服务器技术。现在,我们来介绍J2EE。 通过J2EE开发的应用程序属于分布式多层应用程序,包括 (1)客户层:客户应用,web浏览器的动态网页(含applet) (2)web层: jsp,servlet (3)业务层:EJB (4)企业信息系统层 : 数据库J2EE包含如下构件:运行中,客户端有本地JVM运行,其可以直

Java SE 8新功能导览:Java开发世界中的重大变化_dnc8371的博客-程序员秘密

与其他专业团队成员一样,我是采用OpenJDK的成员之一,但是从最近8个月开始加入,我们经历了Java SE 8 开发,编译,编码,讨论等各个阶段,直到将其付诸实践为止。 。 它于2014年3月18日发布,现在可供您使用。 我很高兴宣布本系列“ Java SE 8新功能之旅 ”,我将在其中编写示例,以简化Java SE 8知识的获取,开发经验,新功能以及将利用您的知识的API,增强您的编...

Objective-C 对象进阶:Objective-C 中单例的概念和使用_objective-c 进阶_chinahaerbin的博客-程序员秘密

基本概念:      一个类始终只有一个实例。  创建单例设计模式的基本步骤     1> 声明一个单件对象的静态实例,并初始化为nil。     2> 创建一个类的工厂方法,生成一个该类的实例,当且仅当这个类的实例为nil时。     3> 覆盖 allocWithZone:类方法,确保用户在直接分配和初始化对象时,不会产生另一个对象。

android中接入twitter进行第三方登录_chipiqiao3947的博客-程序员秘密

在应用中接入Twitter进行第三方登录时,开发人员遇到了一点问题,主要是概念有点混乱,这里把经验记录一下,帮助遇到同样问题的朋友。 一、注册应用并配置登录权限 这一步比较简单,就不多说了,直接去官网添加应用,给读写权限就行了。 网址:https://dev.twitter.com/app...