From cc037e905d7d820c6f448ad5695cbf13056e09df Mon Sep 17 00:00:00 2001 From: Jaehwan Lee Date: Fri, 4 Nov 2022 15:22:10 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9B=90=EB=B2=88=ED=98=B8=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- icspacketparser/icssipparser.go | 7 +++- icssessionmanager/agentoperator.go | 62 +++++++++++++++--------------- icssessionmanager/icssession.go | 12 +++--- sipasm/siptemplt.go | 3 ++ 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/icspacketparser/icssipparser.go b/icspacketparser/icssipparser.go index c0f8876..98e0294 100644 --- a/icspacketparser/icssipparser.go +++ b/icspacketparser/icssipparser.go @@ -81,8 +81,9 @@ type SIP struct { ResType string - XAICall string - Media string + XAICall string + XAICallNumber string + Media string // direction bool @@ -343,6 +344,8 @@ func (s *SIP) setSipStruct(name string, value string) (icserr *icserror.IcsError return nil case "X-AICALL": s.XAICall = value + case "X-AINUMBER": + s.XAICallNumber = value case "MEDIA": s.Media = value default: diff --git a/icssessionmanager/agentoperator.go b/icssessionmanager/agentoperator.go index 2a97cb0..4482018 100644 --- a/icssessionmanager/agentoperator.go +++ b/icssessionmanager/agentoperator.go @@ -1,8 +1,9 @@ package icssessionmanager import ( - "io/ioutil" "fmt" + "io/ioutil" + // "net" "math/rand" "runtime/debug" @@ -298,7 +299,7 @@ func (s *IcsSession) RequestInvite(inviteto string) { // postfix := "192.168.0.83" var callid string now := time.Now().UnixNano() - callid = fmt.Sprintf("%d%s2@%s", now, s.AgentName,ip) + callid = fmt.Sprintf("%d%s2@%s", now, s.AgentName, ip) // s.callID = uuid.New().String() s.m.Lock() s.callID = callid @@ -334,6 +335,7 @@ func (s *IcsSession) RequestInvite(inviteto string) { reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, cseq) reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact) reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAICALL, s.referto) + reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAINUMBER, s.xaiNumber) //reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_EXPIRES, expires) reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent) reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow) @@ -356,7 +358,6 @@ func (s *IcsSession) RequestInvite(inviteto string) { } else { s.SetAgentStatus(STATUS_AGENT_CALLING) } - l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s", wlen, @@ -396,7 +397,7 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError { via := fmt.Sprintf("SIP/2.0/UDP %s;rport;branch=%s", ip, sipasm.GenerateBranch()) maxforwards := "70" agentName := s.AgentName - agentSplit := agentName[len(agentName)-2:len(agentName)] + agentSplit := agentName[len(agentName)-2 : len(agentName)] cust1 := strings.SplitN(sip.From, "@", 2) cust2 := strings.SplitN(cust1[0], ":", 2) @@ -408,13 +409,14 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError { l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri) s.referto = sip.XAICall + s.xaiNumber = sip.XAICallNumber to := fmt.Sprintf("", "AISB", ip) //to := fmt.Sprintf("", s.AgentName, ip) // postfix := fmt.Sprintf("@%s", ip) var callid string // callid = uuid.New().String() now := time.Now().UnixNano() - callid = fmt.Sprintf("%d%s2@%s", now, agentName,ip) + callid = fmt.Sprintf("%d%s2@%s", now, agentName, ip) // if len(s.callID) != 0 { // callid = s.callID // //if len(s.regiCallID) != 0 { @@ -436,7 +438,7 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError { formats := strings.Split(format, " ") reqInvite.SDP = sipasm.NewSDPMessage(ip, mediaPort, formats[:], 0) sdpLength := fmt.Sprintf("%d", len(reqInvite.SDP.String())) - // fmt.Println("###### X-AICALL ", sip.XAICall) + //fmt.Println("###### X-AINUMBER ", sip.XAICall) // refer := strings.Split(sip.XAICall, "@")[0] reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_VIA, via) @@ -447,6 +449,7 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError { reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, cseq) reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact) reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAICALL, sip.XAICall) + reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAINUMBER, s.xaiNumber) //reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_EXPIRES, expires) reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent) reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow) @@ -455,10 +458,10 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError { reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, sdpLength) reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR) - l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send INVITE! [%s] -> [%s] \r\n %+v\r\n", - (*s.sipNeter).LocalAddr().String(), - (*s.sipNeter).RemoteAddr().String(), - reqInvite) + l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send INVITE! [%s] -> [%s] \r\n %+v\r\n", + (*s.sipNeter).LocalAddr().String(), + (*s.sipNeter).RemoteAddr().String(), + reqInvite) // sendINVITE := fmt.Sprintf("%+v",sip) _, werr := (*s.sipNeter).WriteSIP([]byte(reqInvite.String())) @@ -473,13 +476,13 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError { s1 := icspacketparser.NewSIP() err := s1.SipParser([]byte(reqInvite.String())) if err != nil { - // fmt.Printf("########### ererererrererer %s \r\n %+v\r\n", reqInvite.String(), s.InviteSIP) + // fmt.Printf("########### ererererrererer %s \r\n %+v\r\n", reqInvite.String(), s.InviteSIP) } else { s.InviteSIP = &s1 // fmt.Printf("########### %+v\r\n",s1) // fmt.Printf("########### %s, \r\n %+v\r\n",reqInvite.String(), s.InviteSIP) } - + // s.RemoveSession() return nil } @@ -555,7 +558,7 @@ func (s *IcsSession) ProcInvite(sip *icspacketparser.SIP) *icserror.IcsError { remoteAddr := icsnet.NewNetAddrWithIPAddr(remoteAddrs) //connect to remote RTP s.rtpMediaNeter.SetRemoteAddr(&remoteAddr) - + l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set media remote address - %s(%s)", remoteAddr, s.rtpMediaNeter.RemoteAddr()) /* cerr := s.rtpMediaNeter.Connect(nil, &remoteAddr) @@ -895,7 +898,7 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError transport := conf.SIPConfig.Transport format := conf.AgentConfig[s.ID].MediaConfig.Format - if conf.Representative.Value {// 대표번호일때 강제로 콜링으로 변환 + if conf.Representative.Value { // 대표번호일때 강제로 콜링으로 변환 s.SetAgentStatus(STATUS_AGENT_CALLING) } status := s.GetAgentStatus() @@ -1055,7 +1058,6 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError // s.rtpMediaNeter.SetRemoteAddr(&remoteAddr) // l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set media remote address - %s(%s)", remoteAddr, s.rtpMediaNeter.RemoteAddr()) - /////////////////////////////////////////// /////////////////////////////////////////// // send call signal @@ -1294,11 +1296,11 @@ func (s *IcsSession) SendRequestInvite() { // fmt.Printf("Send Call Start Sip(%s) count %d!!!!!!!", s.AgentName, s.simLoopCount) if s.simLoopCount < conf.SimLoopCount { l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) count %d!!!!!!!\r\n", s.AgentName, s.simLoopCount) - time.Sleep(time.Second*1) + time.Sleep(time.Second * 1) s.RequestInvite(s.CustID) s.simLoopCount += 1 } else { - l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) END %d !!!!!!!\r\n", s.AgentName, s.simLoopCount) + l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) END %d !!!!!!!\r\n", s.AgentName, s.simLoopCount) s.simLoopCount = 1 } } @@ -1373,7 +1375,7 @@ func (s *IcsSession) ProcSIP20Bye(sip *icspacketparser.SIP) *icserror.IcsError { s.RequestInvite(s.CustID) s.simLoopCount += 1 } else { - l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) END!!!!!!!\r\n", s.AgentName, s.simLoopCount) + l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send Call Start Sip(%s) END!!!!!!!\r\n", s.AgentName, s.simLoopCount) } return nil @@ -1419,7 +1421,6 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) { // ts := s.rtpTS // seq := s.rtpSeq - // voiceFilePath := "/home/leejj9612/sim/voice/9001-RX-1648533187911907029.pcm" voiceFilePath := "/home/icsvsim/voice/Sample.pcm" readPcmData, ferr := ioutil.ReadFile(voiceFilePath) @@ -1429,7 +1430,6 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) { return } // l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "############ readPcmData %d", readPcmData) - s.m.Lock() // pcmDataLen := len(s.tts) @@ -1466,14 +1466,14 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) { // s.rrData.Clear() l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## Stoped sendrtpCB[%d] ") return - case <- t.GetTick(): + case <-t.GetTick(): if pcmDataLen < offset+psize { break } /* - uplus에서 샘플 음성으로 pcma를 사용(이미 인코딩 되있는 음성파일이라 읽어서 160씩 보내주면됨) - - 인코딩 할 필요 없는 파일이라 인코딩 제거 - - pcma여서 160으로 고정해서 전송(다른 경우는 추후 진행) + uplus에서 샘플 음성으로 pcma를 사용(이미 인코딩 되있는 음성파일이라 읽어서 160씩 보내주면됨) + - 인코딩 할 필요 없는 파일이라 인코딩 제거 + - pcma여서 160으로 고정해서 전송(다른 경우는 추후 진행) */ payload := pcmData[offset : offset+psize] @@ -1731,7 +1731,7 @@ func (s *IcsSession) ReadRTP() { } // func (s *IcsSession)ExpiredRTP(t *icscbtimer.IcsCBTimer) { -func (s *IcsSession)ExpiredRTP(t time.Ticker) { +func (s *IcsSession) ExpiredRTP(t time.Ticker) { s.mychannel = make(chan bool) // fmt.Println("### timer start") // valCheckTimer := time.NewTicker(time.Second) @@ -1740,9 +1740,9 @@ func (s *IcsSession)ExpiredRTP(t time.Ticker) { select { case <-s.mychannel: return - case tm := <- t.C: + case tm := <-t.C: if s.expCheck { - fmt.Println("agent : ", s.AgentName , " ", tm) + fmt.Println("agent : ", s.AgentName, " ", tm) } else if !s.expCheck { if time.Now().Sub(s.expRead) > time.Second { // fmt.Printf("### session expired %s\n", s.AgentName) @@ -2138,10 +2138,10 @@ func (s *IcsSession) Res486Ack(sip *icspacketparser.SIP) *icserror.IcsError { return werr } l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s", - wlen, - (*s.sipNeter).LocalAddr().String(), - (*s.sipNeter).RemoteAddr().String(), - reqAck.String()) + wlen, + (*s.sipNeter).LocalAddr().String(), + (*s.sipNeter).RemoteAddr().String(), + reqAck.String()) return nil } diff --git a/icssessionmanager/icssession.go b/icssessionmanager/icssession.go index 7509084..bdba434 100644 --- a/icssessionmanager/icssession.go +++ b/icssessionmanager/icssession.go @@ -2,10 +2,10 @@ package icssessionmanager import ( "fmt" + "net" "strings" "sync" "time" - "net" "gitlab.com/ics_cinnamon/joy4/format" "gitlab.com/ics_cinnamon/voicegateway/icscbtimer" @@ -55,7 +55,7 @@ type IcsSession struct { RTPCBStatus int //TTS data tts []byte - + remoteSIPAddr *net.UDPAddr //call info @@ -135,15 +135,15 @@ type IcsSession struct { // botStatus BotStatus uint32 //tmp refer to - referto string + referto string simLoopCount int + xaiNumber string // ExpTimer *icscbtimer.IcsCBTimer - expRead time.Time + expRead time.Time readTimer time.Ticker - expCheck bool + expCheck bool mychannel chan bool - m *sync.Mutex } diff --git a/sipasm/siptemplt.go b/sipasm/siptemplt.go index 3b78acd..5e36772 100644 --- a/sipasm/siptemplt.go +++ b/sipasm/siptemplt.go @@ -45,6 +45,7 @@ const ( ICSSIP_HEADER_CSEQ ICSSIP_HEADER_CONTACT ICSSIP_HEADER_XAICALL + ICSSIP_HEADER_XAINUMBER ICSSIP_HEADER_ACCEPT ICSSIP_HEADER_ACCEPT_ENCODING ICSSIP_HEADER_ACCEPT_LANGUAGE @@ -182,6 +183,7 @@ func initHeaderString() { ICSSIP_HEADER_STRING[ICSSIP_HEADER_CALL_INFO] = "Call-Info: %s\r\n" ICSSIP_HEADER_STRING[ICSSIP_HEADER_CONTACT] = "Contact: %s\r\n" ICSSIP_HEADER_STRING[ICSSIP_HEADER_XAICALL] = "X-AICALL: %s\r\n" + ICSSIP_HEADER_STRING[ICSSIP_HEADER_XAINUMBER] = "X-AINUMBER: %s\r\n" ICSSIP_HEADER_STRING[ICSSIP_HEADER_CONTENT_DISPOSITION] = "Content-Disposition: %s\r\n" ICSSIP_HEADER_STRING[ICSSIP_HEADER_CONTENT_ENCODING] = "Content-Encoding: %s\r\n" ICSSIP_HEADER_STRING[ICSSIP_HEADER_CONTENT_LANGUAGE] = "Content-Language: %s\r\n" @@ -233,6 +235,7 @@ func initHeaderString() { ICSSIP_HEADER_STRING2TYPE["CALL-INFO"] = ICSSIP_HEADER_CALL_INFO ICSSIP_HEADER_STRING2TYPE["CONTACT"] = ICSSIP_HEADER_CONTACT ICSSIP_HEADER_STRING2TYPE["XAICALL"] = ICSSIP_HEADER_XAICALL + ICSSIP_HEADER_STRING2TYPE["XAINUMBER"] = ICSSIP_HEADER_XAINUMBER ICSSIP_HEADER_STRING2TYPE["CONTENT-DISPOSITION"] = ICSSIP_HEADER_CONTENT_DISPOSITION ICSSIP_HEADER_STRING2TYPE["CONTENT-ENCODING"] = ICSSIP_HEADER_CONTENT_ENCODING ICSSIP_HEADER_STRING2TYPE["CONTENT-LANGUAGE"] = ICSSIP_HEADER_CONTENT_LANGUAGE