|
|
@ -1,8 +1,9 @@
|
|
|
|
package icssessionmanager
|
|
|
|
package icssessionmanager
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
|
|
|
|
// "net"
|
|
|
|
// "net"
|
|
|
|
"math/rand"
|
|
|
|
"math/rand"
|
|
|
|
"runtime/debug"
|
|
|
|
"runtime/debug"
|
|
|
@ -298,7 +299,7 @@ func (s *IcsSession) RequestInvite(inviteto string) {
|
|
|
|
// postfix := "192.168.0.83"
|
|
|
|
// postfix := "192.168.0.83"
|
|
|
|
var callid string
|
|
|
|
var callid string
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
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.callID = uuid.New().String()
|
|
|
|
s.m.Lock()
|
|
|
|
s.m.Lock()
|
|
|
|
s.callID = callid
|
|
|
|
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_CSEQ, cseq)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAICALL, s.referto)
|
|
|
|
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_EXPIRES, expires)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
@ -357,7 +359,6 @@ func (s *IcsSession) RequestInvite(inviteto string) {
|
|
|
|
s.SetAgentStatus(STATUS_AGENT_CALLING)
|
|
|
|
s.SetAgentStatus(STATUS_AGENT_CALLING)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
wlen,
|
|
|
|
wlen,
|
|
|
|
(*s.sipNeter).LocalAddr().String(),
|
|
|
|
(*s.sipNeter).LocalAddr().String(),
|
|
|
@ -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())
|
|
|
|
via := fmt.Sprintf("SIP/2.0/UDP %s;rport;branch=%s", ip, sipasm.GenerateBranch())
|
|
|
|
maxforwards := "70"
|
|
|
|
maxforwards := "70"
|
|
|
|
agentName := s.AgentName
|
|
|
|
agentName := s.AgentName
|
|
|
|
agentSplit := agentName[len(agentName)-2:len(agentName)]
|
|
|
|
agentSplit := agentName[len(agentName)-2 : len(agentName)]
|
|
|
|
cust1 := strings.SplitN(sip.From, "@", 2)
|
|
|
|
cust1 := strings.SplitN(sip.From, "@", 2)
|
|
|
|
cust2 := strings.SplitN(cust1[0], ":", 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)
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
|
|
|
|
|
|
|
|
|
|
|
|
s.referto = sip.XAICall
|
|
|
|
s.referto = sip.XAICall
|
|
|
|
|
|
|
|
s.xaiNumber = sip.XAICallNumber
|
|
|
|
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "AISB", ip)
|
|
|
|
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "AISB", ip)
|
|
|
|
//to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip)
|
|
|
|
//to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip)
|
|
|
|
// postfix := fmt.Sprintf("@%s", ip)
|
|
|
|
// postfix := fmt.Sprintf("@%s", ip)
|
|
|
|
var callid string
|
|
|
|
var callid string
|
|
|
|
// callid = uuid.New().String()
|
|
|
|
// callid = uuid.New().String()
|
|
|
|
now := time.Now().UnixNano()
|
|
|
|
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 {
|
|
|
|
// if len(s.callID) != 0 {
|
|
|
|
// callid = s.callID
|
|
|
|
// callid = s.callID
|
|
|
|
// //if len(s.regiCallID) != 0 {
|
|
|
|
// //if len(s.regiCallID) != 0 {
|
|
|
@ -436,7 +438,7 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
formats := strings.Split(format, " ")
|
|
|
|
formats := strings.Split(format, " ")
|
|
|
|
reqInvite.SDP = sipasm.NewSDPMessage(ip, mediaPort, formats[:], 0)
|
|
|
|
reqInvite.SDP = sipasm.NewSDPMessage(ip, mediaPort, formats[:], 0)
|
|
|
|
sdpLength := fmt.Sprintf("%d", len(reqInvite.SDP.String()))
|
|
|
|
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]
|
|
|
|
// refer := strings.Split(sip.XAICall, "@")[0]
|
|
|
|
|
|
|
|
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_VIA, via)
|
|
|
|
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_CSEQ, cseq)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_XAICALL, sip.XAICall)
|
|
|
|
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_EXPIRES, expires)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_USER_AGENT, userAgent)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_ALLOW, allow)
|
|
|
@ -456,9 +459,9 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
|
|
|
|
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
|
|
|
|
|
|
|
|
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send INVITE! [%s] -> [%s] \r\n %+v\r\n",
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send INVITE! [%s] -> [%s] \r\n %+v\r\n",
|
|
|
|
(*s.sipNeter).LocalAddr().String(),
|
|
|
|
(*s.sipNeter).LocalAddr().String(),
|
|
|
|
(*s.sipNeter).RemoteAddr().String(),
|
|
|
|
(*s.sipNeter).RemoteAddr().String(),
|
|
|
|
reqInvite)
|
|
|
|
reqInvite)
|
|
|
|
|
|
|
|
|
|
|
|
// sendINVITE := fmt.Sprintf("%+v",sip)
|
|
|
|
// sendINVITE := fmt.Sprintf("%+v",sip)
|
|
|
|
_, werr := (*s.sipNeter).WriteSIP([]byte(reqInvite.String()))
|
|
|
|
_, werr := (*s.sipNeter).WriteSIP([]byte(reqInvite.String()))
|
|
|
@ -895,7 +898,7 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
transport := conf.SIPConfig.Transport
|
|
|
|
format := conf.AgentConfig[s.ID].MediaConfig.Format
|
|
|
|
format := conf.AgentConfig[s.ID].MediaConfig.Format
|
|
|
|
|
|
|
|
|
|
|
|
if conf.Representative.Value {// 대표번호일때 강제로 콜링으로 변환
|
|
|
|
if conf.Representative.Value { // 대표번호일때 강제로 콜링으로 변환
|
|
|
|
s.SetAgentStatus(STATUS_AGENT_CALLING)
|
|
|
|
s.SetAgentStatus(STATUS_AGENT_CALLING)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
status := s.GetAgentStatus()
|
|
|
|
status := s.GetAgentStatus()
|
|
|
@ -1055,7 +1058,6 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError
|
|
|
|
// s.rtpMediaNeter.SetRemoteAddr(&remoteAddr)
|
|
|
|
// s.rtpMediaNeter.SetRemoteAddr(&remoteAddr)
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set media remote address - %s(%s)", remoteAddr, s.rtpMediaNeter.RemoteAddr())
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set media remote address - %s(%s)", remoteAddr, s.rtpMediaNeter.RemoteAddr())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////
|
|
|
|
// send call signal
|
|
|
|
// send call signal
|
|
|
@ -1294,7 +1296,7 @@ func (s *IcsSession) SendRequestInvite() {
|
|
|
|
// fmt.Printf("Send Call Start Sip(%s) count %d!!!!!!!", s.AgentName, s.simLoopCount)
|
|
|
|
// fmt.Printf("Send Call Start Sip(%s) count %d!!!!!!!", s.AgentName, s.simLoopCount)
|
|
|
|
if s.simLoopCount < conf.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)
|
|
|
|
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.RequestInvite(s.CustID)
|
|
|
|
s.simLoopCount += 1
|
|
|
|
s.simLoopCount += 1
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -1419,7 +1421,6 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
|
|
|
|
// ts := s.rtpTS
|
|
|
|
// ts := s.rtpTS
|
|
|
|
// seq := s.rtpSeq
|
|
|
|
// seq := s.rtpSeq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// voiceFilePath := "/home/leejj9612/sim/voice/9001-RX-1648533187911907029.pcm"
|
|
|
|
// voiceFilePath := "/home/leejj9612/sim/voice/9001-RX-1648533187911907029.pcm"
|
|
|
|
voiceFilePath := "/home/icsvsim/voice/Sample.pcm"
|
|
|
|
voiceFilePath := "/home/icsvsim/voice/Sample.pcm"
|
|
|
|
readPcmData, ferr := ioutil.ReadFile(voiceFilePath)
|
|
|
|
readPcmData, ferr := ioutil.ReadFile(voiceFilePath)
|
|
|
@ -1430,7 +1431,6 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "############ readPcmData %d", readPcmData)
|
|
|
|
// l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "############ readPcmData %d", readPcmData)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s.m.Lock()
|
|
|
|
s.m.Lock()
|
|
|
|
// pcmDataLen := len(s.tts)
|
|
|
|
// pcmDataLen := len(s.tts)
|
|
|
|
pcmDataLen := len(readPcmData)
|
|
|
|
pcmDataLen := len(readPcmData)
|
|
|
@ -1466,14 +1466,14 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
|
|
|
|
// s.rrData.Clear()
|
|
|
|
// s.rrData.Clear()
|
|
|
|
l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## Stoped sendrtpCB[%d] ")
|
|
|
|
l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## Stoped sendrtpCB[%d] ")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
case <- t.GetTick():
|
|
|
|
case <-t.GetTick():
|
|
|
|
if pcmDataLen < offset+psize {
|
|
|
|
if pcmDataLen < offset+psize {
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
uplus에서 샘플 음성으로 pcma를 사용(이미 인코딩 되있는 음성파일이라 읽어서 160씩 보내주면됨)
|
|
|
|
uplus에서 샘플 음성으로 pcma를 사용(이미 인코딩 되있는 음성파일이라 읽어서 160씩 보내주면됨)
|
|
|
|
- 인코딩 할 필요 없는 파일이라 인코딩 제거
|
|
|
|
- 인코딩 할 필요 없는 파일이라 인코딩 제거
|
|
|
|
- pcma여서 160으로 고정해서 전송(다른 경우는 추후 진행)
|
|
|
|
- pcma여서 160으로 고정해서 전송(다른 경우는 추후 진행)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
payload := pcmData[offset : offset+psize]
|
|
|
|
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 *icscbtimer.IcsCBTimer) {
|
|
|
|
func (s *IcsSession)ExpiredRTP(t time.Ticker) {
|
|
|
|
func (s *IcsSession) ExpiredRTP(t time.Ticker) {
|
|
|
|
s.mychannel = make(chan bool)
|
|
|
|
s.mychannel = make(chan bool)
|
|
|
|
// fmt.Println("### timer start")
|
|
|
|
// fmt.Println("### timer start")
|
|
|
|
// valCheckTimer := time.NewTicker(time.Second)
|
|
|
|
// valCheckTimer := time.NewTicker(time.Second)
|
|
|
@ -1740,9 +1740,9 @@ func (s *IcsSession)ExpiredRTP(t time.Ticker) {
|
|
|
|
select {
|
|
|
|
select {
|
|
|
|
case <-s.mychannel:
|
|
|
|
case <-s.mychannel:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
case tm := <- t.C:
|
|
|
|
case tm := <-t.C:
|
|
|
|
if s.expCheck {
|
|
|
|
if s.expCheck {
|
|
|
|
fmt.Println("agent : ", s.AgentName , " ", tm)
|
|
|
|
fmt.Println("agent : ", s.AgentName, " ", tm)
|
|
|
|
} else if !s.expCheck {
|
|
|
|
} else if !s.expCheck {
|
|
|
|
if time.Now().Sub(s.expRead) > time.Second {
|
|
|
|
if time.Now().Sub(s.expRead) > time.Second {
|
|
|
|
// fmt.Printf("### session expired %s\n", s.AgentName)
|
|
|
|
// fmt.Printf("### session expired %s\n", s.AgentName)
|
|
|
@ -2138,10 +2138,10 @@ func (s *IcsSession) Res486Ack(sip *icspacketparser.SIP) *icserror.IcsError {
|
|
|
|
return werr
|
|
|
|
return werr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s",
|
|
|
|
wlen,
|
|
|
|
wlen,
|
|
|
|
(*s.sipNeter).LocalAddr().String(),
|
|
|
|
(*s.sipNeter).LocalAddr().String(),
|
|
|
|
(*s.sipNeter).RemoteAddr().String(),
|
|
|
|
(*s.sipNeter).RemoteAddr().String(),
|
|
|
|
reqAck.String())
|
|
|
|
reqAck.String())
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|