我编写了以下awk脚本来计算NS2.35中路由协议的平均吞吐量。我的示例代码如下所示。
BEGIN {
recvdSize = 0
startTime = 400
stopTime = 0
}
{
event = $1
time = $2
node_id = $3
pkt_size = $8
level = $4
# Store start time
if (level == "AGT" && event == "s" && pkt_size >= 512) {
if (time < startTime) {
startTime = time
}
}
# Update total received packets' size and store packets arrival time
if (level == "AGT" && event == "r" && pkt_size >= 512) {
if (time > stopTime) {
stopTime = time
}
# Rip off the header
#hdr_size = pkt_size % 512
#pkt_size -= hdr_size
# Store received packet's size
recvdSize += pkt_size
}
}
END {
printf("Average Throughput[kbps] = %.2f\t\t StartTime=%.2f\tStopTime=%.2f\n",(recvdSize/(stopTime-startTime))*(8/1000),startTime,stopTime)
}
现在我只想计算 CBR数据包(TCP)的吞吐量以及平均吞吐量并显示它。我需要在代码中添加哪些附加内容?
答案 0 :(得分:1)
您可以尝试阅读ns2的其他默认吞吐量脚本:awk#perl#python__scripts-10.2015.tar.gz
中有大约22个thr * .awk文件,有些perl脚本文件* .pl:$ ls | grep -i thr
链接https://drive.google.com/file/d/0B7S255p3kFXNOUIteTVSWjdzQU0/view?usp=sharing
包中的专用tcp脚本是calc_tcp_goodput.awk,show_tcp_con,show_tcp_con.awk。
答案 1 :(得分:0)
BEGIN {
JavaFX Application Thread
}
{
@Configuration
@EnableAsync
@EnableScheduling
@EnableCaching
// Component scanning for JavaFX Nodes
@ComponentScan("path.to.view.nodes")
public class MyConfiguration {
// bean definitiions here
}
public class MyApplication extends Application {
private ConfigurableApplicationContext configurableApplicationContext;
@Autowired
private RootPane rootPane;
@Override
public void init() throws Exception {
SpringApplication application;
application = new SpringApplication();
application.getSources().add(MyConfiguration.class);
application.setWebEnvironment(false);
application.setShowBanner(false);
application.setRegisterShutdownHook(true);
configurableApplicationContext = application.run();
ConfigurableListableBeanFactory beanFactory;
beanFactory = configurableApplicationContext.getBeanFactory();
beanFactory.registerSingleton(getClass().getSimpleName(), this);
beanFactory.autowireBean(this);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(rootPane));
primaryStage.centerOnScreen();
primaryStage.show();
}
@Override
public void stop() throws Exception {
configurableApplicationContext.close();
}
public static void main(String... args) {
Application.launch(MyApplication.class, args);
}
}
@Component
public class RootPane extends BorderPane {
@PostConstruct
public void init() {
setRight(new Button("Click me"));
}
}
#Store start time
if(level ==“MAC”&amp;&amp; event ==“s”&amp;&amp; pkt_size&gt; = 300){
recvdSize = 0
startTime = 400
stopTime = 0
#更新总收到数据包的大小并存储数据包到达时间
if(level ==“MAC”&amp;&amp; event ==“r”&amp;&amp; pkt_size&gt; = 300){
event = $1
time = $2
node_id = $3
pkt_size = $8
level = $4
}
结束{ 打印“+ =============================================== ======================== + \ n“个;
if (time < startTime) {
startTime = time
}
}
打印“\ n + ============================================= ============================ + \ n“个;
}
执行命令:
awk -f throughput.awk out.tr(tracefile name)