首页 > 代码库 > loadrunner rtsp协议模拟

loadrunner rtsp协议模拟

  1. RTSP 实时流传输协议, 是TCP/IP协议体系中的一个应用层协议, 该协议定义了一对多应用程序如何有效地通过IP网络传送多媒体数据. RTSP在体系结构上位于RTP和RTCP之上, 它使用TCP或RTP完成数据传输.
  2. RTSP信令交互过程

    C表示rtsp客户端, S表示rtsp服务端

        1. C->S:OPTION request //询问S有哪些方法可用
        1. S->C:OPTION response //S回应信息中包括提供的所有可用方法
        
        2. C->S:DESCRIBE request //要求得到S提供的媒体初始化描述信息
        2. S->C:DESCRIBE response //S回应媒体初始化描述信息, 主要是sdp
        
        3. C->S:SETUP request //设置会话的属性, 以及传输模式, 提醒S建立会话
        3. S->C:SETUP response //S建立会话, 返回会话标识符, 以及会话相关信息
        
        4. C->S:PLAY request //C请求播放
        4. S->C:PLAY response //S回应该请求的信息
        
        S->C:发送流媒体数据
        
        5. C->S:TEARDOWN request //C请求关闭会话
        5. S->C:TEARDOWN response //S回应该请求
  3. 通过ffmpeg播放视频。

  技术分享

  

  4.使用wireshark抓包。作为rtsp报文的基准数据。

       技术分享

 

   5.使用loadrunner新建win socket action。编辑脚本内容如下:

    

#include "lrs.h"


Action() { 


    int rc = 0;
    
    rc = lrs_create_socket("socket1", "TCP", "LocalHost=0", "RemoteHost=192.168.1.51:554", LrsLastArg);

    if (rc==0)

        lr_output_message("Socket was successfully created ");

    else

        lr_output_message("An error occurred while creating the socket, Error Code: %d", rc);



     lrs_send("socket1", "option", "TargetSocket=rtsp://192.168.1.51:554/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj RTSP/1.0",LrsLastArg  );

     lrs_receive("socket1", "option200",  LrsLastArg); 


     lrs_send("socket1", "describe", "TargetSocket=rtsp://192.168.1.51:554/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj RTSP/1.0",LrsLastArg  );

     lrs_receive("socket1", "describe200", LrsLastArg); 

    //setup
     lrs_send("socket1", "setup", "TargetSocket=rtsp://192.168.1.51:554/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj RTSP/1.0",LrsLastArg  );

     lrs_receive("socket1", "setup200", LrsLastArg); 
     lrs_save_param("socket1", NULL, "session", 155, 8);
     lr_output_message ("session: %s", lr_eval_string("<<session>>")); 
    // lr_save_string("{session}", "session1"); 
    //play

     lrs_send("socket1", "play", "TargetSocket=rtsp://192.168.1.51:554/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj RTSP/1.0",LrsLastArg  );
     lrs_receive_ex("socket1", "play200", "NumberOfBytesToRecv=8000", LrsLastArg);
     //lrs_receive("socket1", "play200",  LrsLastArg); 

     //lr_think_time(20);

     //lrs_send("socket1", "pause", "TargetSocket=rtsp://192.168.1.51:554/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj RTSP/1.0",LrsLastArg  );
     //lrs_receive_ex("socket1", "pause200","NumberOfBytesToRecv=1000", LrsLastArg);

  

    //teardown
     lrs_send("socket1", "teardown", "TargetSocket=rtsp://192.168.1.51:554/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj RTSP/1.0",LrsLastArg  );

     lrs_receive_ex("socket1", "teardown200","NumberOfBytesToRecv=500",  LrsLastArg); 




    
     lrs_close_socket("socket1"); 


    return 0;
}

  

  6.编辑工程data.ws文件,写入如下内容(信令消息来源于上一步抓包内容):

;WSRData 2 1

send option 518
    "OPTIONS rtsp://192.168.1.51:554/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj RTSP/1.0\r\n"
    "CSeq: 1\r\n"
    "User-Agent: Lavf57.51.103\r\n"
    "\r\n"

recv option200 152
    "RTSP/1.0 200 OK\r\n"
    "CSeq: 1\r\n"
    "Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER\r\n"

send describe 250
        "DESCRIBE rtsp://192.168.1.51:554/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj RTSP/1.0\r\n"
        "Accept: application/sdp\r\n"
        "CSeq: 2\r\n"
        "User-Agent: Lavf57.51.103\r\n"
        "\r\n"

recv describe200 637

    "RTSP/1.0 200 OK\r\n"
    "CSeq: 2\r\n"
    "Content-Base: rtsp://192.168.1.51:10754/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj/\r\n"
    "Content-Type: application/sdp\r\n"
    
    "v=0\r\n"
    "o=- 1490233027406551 1 IN IP4 192.168.1.51\r\n"
    "s=MPEG Transport Stream, streamed by the LIVE555 Media Server\r\n"
    "i=FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj\r\n"
    "t=0 0\r\n"
    "a=tool:LIVE555 Streaming Media v2016.09.22\r\n"
    "a=type:broadcast\r\n"
    "a=control:*\r\n"
    "a=range:npt=0-\r\n"
    "a=x-qt-text-nam:MPEG Transport Stream, streamed by the LIVE555 Media Server\r\n"
    "a=x-qt-text-inf:FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj\r\n"
    "m=video 0 RTP/AVP 33\r\n"
    "c=IN IP4 0.0.0.0\r\n"
    "b=AS:5000\r\n"
    "a=control:track1\r\n"

send setup 300
    "SETUP rtsp://192.168.1.51:10754/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj/ RTSP/1.0\r\n"
    "Transport: RTP/AVP/TCP;unicast;interleaved=0-1\r\n"
    "CSeq: 3\r\n"
    "User-Agent: Lavf57.51.103\r\n"
    "\r\n"
recv setup200 178
    "RTSP/1.0 200 OK\r\n"
    "CSeq: 3\r\n"
    "Transport: RTP/AVP/TCP;unicast;destination=0.0.0.0;source=0.0.0.0;interleaved=0-1\r\n"
    "\r\n"

send play 500
    "PLAY rtsp://192.168.1.51:10754/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj/ RTSP/1.0\r\n"
    "Range: npt=0.000-\r\n"
    "CSeq: 4\r\n"
    "User-Agent: Lavf57.51.103\r\n"
    "Session: <session>\r\n"
    "\r\n"

recv play200 200
    "RTSP/1.0 200 OK\r\n"
    "CSeq: 4\r\n"
    "Range: npt=0.000-\r\n"
    "RTP-Info: url=rtsp://192.168.1.51:10754/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj/track1\r\n"
    "\r\n"

send pause 200
    "PAUSE rtsp://192.168.1.51:10754/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj/ RTSP/1.0\r\n"
    "CSeq: 5\r\n"
    "User-Agent: Lavf57.51.103\r\n"
    "Session: <session>\r\n"
    "\r\n"
  

recv pause200 10018
    "RTSP/1.0 200 OK\r\n"
    "CSeq: 5\r\n"
    "Session: <session>\r\n"
    "\r\n"



send teardown 200
    "TEARDOWN rtsp://192.168.1.51:10754/FGElMXXgGRd8KKBSmV8JcJUWHQkYiwTfj/ RTSP/1.0\r\n"
    "CSeq: 6\r\n"
    "User-Agent: Lavf57.51.103\r\n"
    "Session: <session>\r\n"
    "\r\n"


recv teardown200 65
    "RTSP/1.0 200 OK\r\n"
    "CSeq: 6\r\n"
    "Session: <session>\r\n"
    "\r\n"
    



-1

 

  7.调试结果

 

技术分享

 

   也可以在调试的时候,抓包对比之前的抓包。验证消息的正确性

技术分享

 

loadrunner rtsp协议模拟