当前位置:文档之家› SIP实验报告

SIP实验报告

南京邮电大学综合实验(软交换)SIP注册实验姓名:学号:班级:日期:2013年10月13日内容与要求:设计流程①熟悉环境◊②用自己用户登入,SIP配置实验)◊③学习协议流程(至少包括注册、正常呼叫、对端忙、重定向)◊④学习消息参数(请求、相应消息所包含的头域,各个头中携带的参数)◊⑥选定程序设计题目设计实现方案◊⑦开源协议栈学习+ 题目实现◊⑧自己编程◊⑨测试◊综合实验程序设计(开源代码基础上)一、完善UA功能(使用SS1B测试)1、完整正常主叫信令流程2、完善UA配置、使用界面二、完成服务器部分功能(使用multiphone测试)3、注册服务器4、无状态代理服务器三、自拟题目综合实验(软交换)注意事项:1、关于资料实验室客户端有协议原文、技术手册、学习资料、开源代码、使用手册和例子。

其它资料需自己准备。

2、设计方案每组一个设计方案,建议题目中任选一个或自己拟定都可以,组中同学要有各自侧重点和分工。

3、编程语言编译器不限,VC 、BCB 、DELPHI 、.NET. 语言 c 、c++、delphi开源代码,实验室提供OSIP (C 语言编写),也可以自己下载其它开源代码SIP 架构:程序测试:下载VC++6.0更新SDK 获得这两个API 文件。

再编译osip2,eXosip2和 osipparser2得到加入到VC 和WINDOWS 的相应文件夹中,编译过程中需要以下2个库文件 界面如下:抓包显示注册,注销,呼叫以及挂断的消息。

文本的SIP 消息:思考题:软交换设备 设备名称 设备型号 数量 备注软交换控制设备 ZXSS10 SS1b 1 硬件5万用户容量,软件200线用户license, 480线中继license 中继信令合一网关 ZXMSG7200 1 16E1,2 条64K 信令 link UP10业务平台 UP10 1 Web 客户端和业务服务器合一 媒体服务器 Mes 1综合网管系统ZXNMS 011网管客户端和网管服务器合一,包含40个网管客户端License界 面 /配置数据UDP 通信模块协议消息解析业务流程控制SIP 终端(代理)2、什么叫状态机,给出SIP协议中一个状态机的例子,并说明。

在开始一个线程的时候,就会开始一个状态机,当一个事件发生的时候,就会转到相应的状态上去。

如sip注册:(UA)空闲状态-----(发送注册信息)-→待机状态等待响应-----(收到成功响应)--→已注册状态| |(未收到响应) --(收到注册失败响应)-→空闲状态|空闲状态3、设计一个SIP终端或代理服务器,给出主要软件模块构成。

UAC UAS4、分析SIP相关开源代码,说明SIP消息处理的方法。

以纯文本的方式在UA与server之间按照固定顺序发送消息,根据消息进行相应处理。

附录#include <eXosip2/eXosip.h>#include <stdio.h>#include <stdlib.h>#include <windows.h>#include <sys/types.h>/*void cb_rcv4xx(sipevent_t * se,transaction_t * tr);void cb_rcv4xx(sipevent_t * se,transaction_t * tr){printf("rcv 4xx msg do nothing");}*/intmain (int argc, char *argv[]){eXosip_event_t *je;osip_message_t *reg = NULL;osip_message_t *invite = NULL;osip_message_t *ack = NULL;osip_message_t *info = NULL;osip_message_t *message = NULL;FILE *writefile;int call_id, dialog_id;int i,flag;int flag1 = 1;int id;char *identity = "sip:@";char *registerer = "sip:";char *source_call = "sip:@";char *dest_call = "sip:@";char *con = "sip:";char command;char tmp[4096];char localip[128] = "";printf("r 向服务器注册\n\n");printf("c 取消注册\n\n");printf("i 发起呼叫请求\n\n");printf("h 挂断\n\n");printf("q 退出程序\n\n");printf("s 执行方法INFO\n\n");printf("m 执行方法MESSAGE\n\n");//初始化i = eXosip_init ();if (i != 0){printf (" Couldn't initialize eXosip!\n");return -1;}else{printf ("eXosip_init successfully!\n");}writefile = fopen("log.txt","w");osip_trace_initialize (8, writefile);OSIP_TRACE (osip_trace(__FILE__, __LINE__, OSIP_ERROR, NULL,"eXosip: already listening somewhere\n"));i = eXosip_listen_addr (IPPROTO_UDP, NULL, 5060, AF_INET, 0); // osip_setcb_rcv4xx(cf,&cb_rcv4xx);if (i != 0){eXosip_quit ();fprintf (stderr, "Couldn't initialize transport layer!\n");return -1;}flag = 1;while (flag){printf ("please input the comand:\n");fflush(stdin);scanf ("%c", &command);//getchar ();switch (command){case 'h':printf ("Holded !\n");eXosip_lock ();eXosip_call_terminate (call_id, dialog_id);eXosip_unlock ();break;case 'c':eXosip_lock ();i = eXosip_register_build_register (id, 0, &reg);if (i < 0){eXosip_unlock ();printf("注销失败!\n");}else{eXosip_register_send_register (id, reg);printf("注销成功!\n");eXosip_unlock ();}break;case 's'://传输INFO方法eXosip_call_build_info (dialog_id, &info);snprintf (tmp , 4096,"hello,rainfish");osip_message_set_body (info, tmp, strlen(tmp));//格式可以任意设定,text/plain代表文本信息osip_message_set_content_type (info, "text/plain");eXosip_call_send_request (dialog_id, info);break;case 'm'://传输MESSAGE方法,也就是即时消息,和INFO方法相比,我认为主要区别,是MESSAGE不用建立连接,直接传输信息,而INFO必须//在建立INVITE的基础上传输。

printf ("the mothed :MESSAGE\n");eXosip_message_build_request (&message, "MESSAGE", dest_call, source_call, NULL); snprintf (tmp, 4096,"hello,rainfish");osip_message_set_body (message, tmp, strlen(tmp));//假设格式是xmlosip_message_set_content_type (message, "text/xml");eXosip_message_send_request (message);break;case 'q':eXosip_quit ();printf ("Exit the SIPphone!\n");flag = 0;break;case 'r':id=eXosip_register_build_initial_register(source_call, registerer, con,1000,&reg); eXosip_lock ();eXosip_clear_authentication_info(); //去除上次加入的错误认证信息//添加认证信息if (eXosip_add_authentication_info("", "", "1340", "md5", NULL)){printf("--Add_authentication_info failed\n");eXosip_unlock();return -4;}i = eXosip_register_send_register (id, reg) ;eXosip_unlock ();printf ("send reg commpleted!\n");flag1 = 1;while (flag1){// je = eXosip_event_wait (0, 200);je = eXosip_event_wait (0, 500);//协议栈带有此语句,具体作用未知eXosip_lock ();eXosip_default_action (je);eXosip_automatic_refresh ();eXosip_unlock ();if (je == NULL){printf ("No response or the time is over!\n");break;}switch (je->type){case EXOSIP_REGISTRATION_FAILURE:printf ("a 4xx rcved !\n");id=eXosip_register_build_register (je->rid, 2000, &reg);i = eXosip_register_send_register (id, reg);printf("send a new regesiter\r\n");break;case EXOSIP_REGISTRATION_SUCCESS:printf("reg success!\r\n");break;default:printf("unexpect event %d",je->type);break;}eXosip_event_free (je);break;}break;case 'i':/* INVITE */i = eXosip_call_build_initial_invite (&invite, dest_call, source_call, NULL, "This si a call for a conversation");if (i != 0){printf ("Intial INVITE failed!\n");break;}//符合SDP格式,其中属性a是自定义格式,也就是说可以存放自己的信息,但是只能是两列,比如帐户信息//但是经测试,格式:v o t必不可少,原因未知,估计是协议栈在传输时需要检查的snprintf (tmp, 4096,"v=0\r\n""o=anonymous 0 0 IN IP4 ""t=1 10\r\n""a=username:rainfish\r\n""a=password:123\r\n");osip_message_set_body (invite, tmp, strlen(tmp));osip_message_set_content_type (invite, "application/sdp");eXosip_lock ();i = eXosip_call_send_initial_invite (invite);eXosip_unlock ();flag1 = 1;while (flag1){je = eXosip_event_wait (0, 200);if (je == NULL){printf ("No response or the time is over!\n");break;}switch (je->type){case EXOSIP_CALL_INVITE:printf ("a new invite reveived!\n");break;case EXOSIP_CALL_PROCEEDING:printf ("proceeding!\n");break;case EXOSIP_CALL_RINGING:printf ("ringing!\n");// call_id = je->cid;// dialog_id = je->did;printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did);break;case EXOSIP_CALL_ANSWERED:printf ("ok! connected!\n");call_id = je->cid;dialog_id = je->did;printf ("call_id is %d, dialog_id is %d \n", je->cid, je->did);eXosip_call_build_ack (je->did, &ack);eXosip_call_send_ack (je->did, ack);flag1 = 0;break;case EXOSIP_CALL_CLOSED:printf ("the other sid closed!\n");break;case EXOSIP_CALL_ACK:printf ("ACK received!\n");break;default:printf ("other response!\n");break;}eXosip_event_free (je);}break;}}return (0); }。

相关主题