main
Jaehwan Lee 2 months ago
parent cc037e905d
commit a33de701b0

@ -1,6 +1,6 @@
module gitlab.com/ics_cinnamon/voicegateway
go 1.16
go 1.20
require (
github.com/google/uuid v1.3.0 // indirect

@ -193,7 +193,7 @@ func (u *IcsUDPNet) WriteRTP(b []byte) (int, *icserror.IcsError) {
IP: u.raddr.IPv4,
Port: u.raddr.Port,
}
//fmt.Println("Write addr ", raddr)
// fmt.Println("Write addr ", raddr)
//wsize, err := u.conn.ICSUDPConn.WriteTo(b, raddr)
wsize, err := u.conn.ICSUDPConn.WriteToUDP(b, raddr)
//wsize, err := u.conn.ICSUDPConn.Write(b)

@ -2,6 +2,7 @@ package icspacketparser
import (
"fmt"
"regexp"
"strconv"
"strings"
@ -82,6 +83,7 @@ type SIP struct {
ResType string
XAICall string
Diversion string
XAICallNumber string
Media string
@ -344,6 +346,16 @@ func (s *SIP) setSipStruct(name string, value string) (icserr *icserror.IcsError
return nil
case "X-AICALL":
s.XAICall = value
case "DIVERSION":
re := regexp.MustCompile(`<tel:(.*?)>`)
match := re.FindStringSubmatch(strings.TrimSpace(value))
if len(match) >= 2 {
s.Diversion = match[1]
} else {
//에러 추가 필요 디버전에 대한
s.Diversion = ""
return icserror.ICSERRSIPHeader
}
case "X-AINUMBER":
s.XAICallNumber = value
case "MEDIA":

@ -1,6 +1,7 @@
package icssessionmanager
import (
"encoding/binary"
"fmt"
"io/ioutil"
@ -27,6 +28,11 @@ import (
"gitlab.com/ics_cinnamon/voicegateway/sipasm"
)
const (
REFER = 0
RANGE = 10000
)
func (s *IcsSession) SetRegisterStatus(status int) int {
s.registerStatus = status
@ -275,15 +281,23 @@ func (s *IcsSession) RequestInvite(inviteto string) {
transport := conf.SIPConfig.Transport
format := conf.AgentConfig[s.ID].MediaConfig.Format
agentString := func() string {
rand.Seed(time.Now().UnixNano())
index := rand.Intn(1)
list := []string{"07012345678"}
return list[index]
}()
fmt.Println(agentString)
//sim
inviteMethod := fmt.Sprintf("sip:%s@172.31.29.47;transport=%s", s.AgentName, transport) // nlb(DNS)를 한번 갔다온 ip를 넣어줘야함.
s.uri = fmt.Sprintf("sip:%s@%s", s.AgentName, ip)
to := fmt.Sprintf("<sip:%s@%s;user=phone>", s.AgentName, ip)
from := fmt.Sprintf("<sip:%s@%s>;tag=%s", inviteto, ip, sipasm.GenerateTag())
if conf.Representative.Value {
inviteMethod = fmt.Sprintf("sip:%s@%s;transport=%s", "AISB", ip, transport)
s.uri = fmt.Sprintf("sip:%s@%s", "AISB", ip)
to = fmt.Sprintf("<sip:%s@%s;user=phone>", "AISB", ip)
inviteMethod = fmt.Sprintf("sip:%s@%s;transport=%s", agentString, ip, transport)
s.uri = fmt.Sprintf("sip:%s@%s", agentString, ip)
to = fmt.Sprintf("<sip:%s@%s;user=phone>", agentString, ip)
// agentName := s.AgentName
// agentSplit := agentName[len(agentName)-2:len(agentName)]
// telNo := fmt.Sprintf("010243427%s", agentSplit)
@ -334,9 +348,11 @@ func (s *IcsSession) RequestInvite(inviteto string) {
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, callid)
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, cseq)
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
if agentString == "AISB" {
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)
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_SUPPORTED, supported)
@ -344,15 +360,12 @@ func (s *IcsSession) RequestInvite(inviteto string) {
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, sdpLength)
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
s.inviteDuration = time.Now()
wlen, werr := (*s.sipNeter).WriteSIP([]byte(reqInvite.String()))
if werr != nil {
l.Print(icslog.LOG_LEVEL_FATAL, s.ID, werr.GetMessage())
return
}
// s.callID = callid
// s.callID = uuid.New().String()
if conf.Representative.Value {
s.SetAgentStatus(STATUS_AGENT_READY)
} else {
@ -365,6 +378,7 @@ func (s *IcsSession) RequestInvite(inviteto string) {
(*s.sipNeter).RemoteAddr().String(),
reqInvite.String())
}
inviteFunc()
}
@ -373,6 +387,12 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
l := icslog.GetIcsLog()
conf := icsconf.GetIcsConfig()
agentString := func() string {
rand.Seed(time.Now().UnixNano())
index := rand.Intn(1)
list := []string{"07012345678"}
return list[index]
}()
// TODO - send bye
defer func() {
if err := recover(); err != nil {
@ -391,26 +411,36 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
transport := conf.SIPConfig.Transport
format := conf.AgentConfig[s.ID].MediaConfig.Format
inviteMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "AISB", proxy, transport)
inviteMethod := fmt.Sprintf("sip:%s@%s;transport=%s", agentString, proxy, transport)
reqInvite := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_INVITE, inviteMethod)
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)-1:]
_, atoiErr := strconv.Atoi(agentSplit)
if atoiErr != nil {
agentSplit = fmt.Sprint("0", agentSplit[1:])
}
cust1 := strings.SplitN(sip.From, "@", 2)
cust2 := strings.SplitN(cust1[0], ":", 2)
telNo := fmt.Sprintf("%s%s", cust2[1][0:9], agentSplit)
telNo := fmt.Sprintf("%s%s", cust2[1][0:8], agentSplit)
s.CustID = telNo
fmt.Println(s.CustID)
from := fmt.Sprintf("<sip:%s@%s:5090>;tag=%s", telNo, ip, sipasm.GenerateTag())
fmt.Println(telNo)
fmt.Println(from)
s.uri = fmt.Sprintf("sip:%s@%s", s.AgentName, ip)
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
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>", agentString, ip)
//to := fmt.Sprintf("<sip:%s@%s>", s.AgentName, ip)
// postfix := fmt.Sprintf("@%s", ip)
var callid string
@ -429,7 +459,7 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
s.m.Unlock()
cseq := fmt.Sprintf("%d INVITE", s.Cseq)
s.Cseq++
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", "AISB", ip, port, transport)
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", agentString, ip, port, transport)
//expires := fmt.Sprintf("%d", conf.AgentConfig[s.ID].RegisterConfig.RegisterExpire)
userAgent := conf.InfoConfig.Product
allow := "REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE"
@ -448,14 +478,19 @@ func (s *IcsSession) PassInvite(sip *icspacketparser.SIP) *icserror.IcsError {
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CALL_ID, callid)
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CSEQ, cseq)
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTACT, contact)
if agentString == "AISB" {
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)
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_SUPPORTED, supported)
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_TYPE, "application/sdp")
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_CONTENT_LENGTH, sdpLength)
if agentString != "AISB" {
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_DIVERSION, "07077399939")
}
reqInvite.AddSIPHeader(sipasm.ICSSIP_HEADER_TERMINATOR)
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Send INVITE! [%s] -> [%s] \r\n %+v\r\n",
@ -856,6 +891,8 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError
conf := icsconf.GetIcsConfig()
// s.InviteSIP = sip
inviteDuration := time.Since(s.inviteDuration)
l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "####INVITE <-> INVITE ACK => %+v", inviteDuration)
///////////////////////////////////////////
///////////////////////////////////////////
// set agentinfo
@ -916,7 +953,7 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
from := fmt.Sprintf("<sip:%s@%s:5090>;tag=%s", s.CustID, ip, sipasm.GenerateTag())
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "AISB", ip)
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "07012345678", ip)
// if s.InviteSIP != nil {
// from = s.InviteSIP.From
// to = s.InviteSIP.To
@ -1102,6 +1139,7 @@ func (s *IcsSession) ProcACKInvite(sip *icspacketparser.SIP) *icserror.IcsError
///////////////////////////////////////////
// fmt.Println(s)
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent Data(%d) [%s]->[%s]>\n%s",
wlen,
(*s.sipNeter).LocalAddr().String(),
@ -1422,20 +1460,30 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
// seq := s.rtpSeq
// voiceFilePath := "/home/leejj9612/sim/voice/9001-RX-1648533187911907029.pcm"
voiceFilePath := "/home/icsvsim/voice/Sample.pcm"
voiceFilePath := "/home/icsvsim/voice/tvoice.wav"
readPcmData, ferr := ioutil.ReadFile(voiceFilePath)
if ferr != nil {
// fmt.Println("Read Voice File error ", ferr)
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "VoiceFile Read ERROR")
return
}
// l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "############ readPcmData %d", readPcmData)
s.m.Lock()
// pcmDataLen := len(s.tts)
pcmDataLen := len(readPcmData)
//ljhwan
// pcmDataLen := len(readPcmData)
// pcmData := make([]byte, pcmDataLen*46)
// for count := 0; count < 46; count++ {
// copy(pcmData[(pcmDataLen-44)*count:], readPcmData[44:]) //cut off wave header
// }
pcmDataLen := len(readPcmData) - 44
pcmData := make([]byte, pcmDataLen)
copy(pcmData, readPcmData[44:]) //cut off wave header
// pcmData := make([]byte, pcmDataLen)
//copy(pcmData, readPcmData) //cut off wave header
// fmt.Printf("@@@@@ Read Data len: %d\r\n@@@@@ data: %+v\r\n@@@@@ copyData: %+v \r\n\r\n", pcmDataLen, readPcmData, pcmData)
//pcmData := s.tts[44:] //cut off wave header
//fmt.Println("pcmData len>>>", pcmDataLen, len(s.tts))
@ -1458,96 +1506,122 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
}
var rtp *icsrtp.RTP
if conf.CallEndInfo.Value {
if !conf.CallEndInfo.Value {
// for {
// // fmt.Printf("@@@@@@@@@@@@@@@@@@@@@@ %d ", lc)
// select {
// case <-t.STOP:
// // s.rrData.Clear()
// l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## Stoped sendrtpCB[%d] ")
// return
// case <-t.GetTick():
// if s.TTSFlag.Load().(bool) {
// iter = 0
// totalSentLen = 0
// offset = 0
// psize = icspacketparser.RTPPayloadInfo[s.payloadType].PSize
// ts = s.rtpTS
// seq = s.rtpSeq
// } else {
// offset = pcmDataLen
// }
// if pcmDataLen < offset+psize {
// continue
// }
// payload := pcmData[offset : offset+psize]
// if iter == 0 {
// if offset+psize >= pcmDataLen {
// offset = 0
// }
// rtp = icsrtp.NewRTP(1, //set mark bit
// int(s.payloadType),
// int(seq),
// int(ts),
// int(s.rtpSSRC),
// payload)
// totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
// offset += psize
// } else {
// if offset+psize >= pcmDataLen {
// offset = 0
// }
// rtp = icsrtp.NewRTP(0,
// int(s.payloadType),
// int(seq),
// int(ts),
// int(s.rtpSSRC),
// payload)
// totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
// offset += psize
// }
// iter++
// ts += uint32(psize)
// seq++
// s.txCnt++
// wlen, werr := s.rtpMediaNeter.WriteRTP(rtp.Byte())
// if werr != nil {
// fmt.Println(wlen, werr)
// }
// }
// // time.Sleep(time.Second)
// }
// s.RequestBYE(s.InviteSIP)
} else {
// iter := 0
// totalSentLen := 0
// offset := pcmDataLen
// psize := icspacketparser.RTPPayloadInfo[s.payloadType].PSize
// ts := s.rtpTS
// seq := s.rtpSeq
// s.PreTTSFlag = true
for {
// fmt.Printf("@@@@@@@@@@@@@@@@@@@@@@ %d ", lc)
select {
case <-t.STOP:
// s.rrData.Clear()
l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## Stoped sendrtpCB[%d] ")
return
case <-t.GetTick():
if pcmDataLen < offset+psize {
break
}
/*
uplus pcma ( 160 )
-
- pcma 160 ( )
*/
payload := pcmData[offset : offset+psize]
if iter == 0 {
if offset+psize >= pcmDataLen {
epd := s.epd
if epd == 2 {
if s.preepd == 1 {
l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## SEND TTS ")
iter = 0
totalSentLen = 0
offset = 0
psize = icspacketparser.RTPPayloadInfo[s.payloadType].PSize
ts = s.rtpTS
seq = s.rtpSeq
}
rtp = icsrtp.NewRTP(1, //set mark bit
int(s.payloadType),
int(seq),
int(ts),
int(s.rtpSSRC),
payload)
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
offset += psize
} else {
if offset+psize >= pcmDataLen {
offset = 0
} else if epd == 1 {
if s.preepd == 0 {
l.Printf(icslog.LOG_LEVEL_DEBUG, s.ID, "######## STOP TTS ")
offset = pcmDataLen
}
rtp = icsrtp.NewRTP(0,
int(s.payloadType),
int(seq),
int(ts),
int(s.rtpSSRC),
payload)
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
offset += psize
}
iter++
ts += uint32(psize)
seq++
s.txCnt++
wlen, werr := s.rtpMediaNeter.WriteRTP(rtp.Byte())
if werr != nil {
fmt.Println(wlen, werr)
}
s.preepd = epd
data := make([]byte, 0)
if pcmDataLen < offset+psize*2 || epd != 2 {
data = make([]byte, psize*2)
for index, _ := range data {
data[index] = 0x00
}
// time.Sleep(time.Second)
}
// s.RequestBYE(s.InviteSIP)
} else {
for {
iter := 0
totalSentLen := 0
offset := 0
psize := icspacketparser.RTPPayloadInfo[s.payloadType].PSize
ts := s.rtpTS
seq := s.rtpSeq
for t1 := range t.GetTick() {
if pcmDataLen < offset+psize*2 {
break
data = pcmData[offset : offset+psize*2]
}
payload, convErr := s.TxConverter.Encode(pcmData[offset : offset+psize*2])
payload, convErr := s.TxConverter.Encode(data)
if convErr != nil {
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Encoding Error - %s", convErr.GetError())
return
}
//fmt.Printf("1048@@@@ %+v\n", s.rtpMediaNeter)
/*
wflen, wferr := ttsfile1.Write(payload)
if wferr != nil {
fmt.Println("file.write error", wferr, wflen)
os.Exit(1)
}
ttsfile1.Sync()
*/
if iter == 0 {
if offset+psize >= pcmDataLen {
//if offset+psize >= alawDataLen {
offset = 0
}
rtp = icsrtp.NewRTP(1, //set mark bit
int(s.payloadType),
int(seq),
@ -1557,12 +1631,7 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
offset += psize * 2
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
} else {
if offset+psize >= pcmDataLen {
//if offset+psize >= alawDataLen {
offset = 0
}
rtp = icsrtp.NewRTP(0,
int(s.payloadType),
int(seq),
@ -1572,32 +1641,30 @@ func (s *IcsSession) SendRTPCB(t *icscbtimer.IcsCBTimer) {
//alawData[offset:offset+icspacketparser.RTPPayloadInfo[s.payloadType].PSize])
totalSentLen += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
offset += psize * 2
//offset += icspacketparser.RTPPayloadInfo[s.payloadType].PSize
}
iter++
ts += uint32(psize)
seq++
s.txCnt++
//fmt.Printf("1095@@@@ %+v\n", s.rtpMediaNeter)
wlen, werr := s.rtpMediaNeter.WriteRTP(rtp.Byte())
if werr != nil {
fmt.Println(t1, wlen, werr)
fmt.Println(wlen, werr)
}
//fmt.Printf("wlen: %d\r", totalSentLen)
//l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent RTP(%d) to %s", wlen, s.rtpMediaNeter.RemoteAddr().String())
}
// fmt.Printf("Sent RTP(%d) to [%s] [%s]\r\n", totalSentLen, s.rtpMediaNeter.RemoteAddr().String(), s.AgentName )
// l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Sent RTP(%d) to %s", totalSentLen, s.rtpMediaNeter.RemoteAddr().String())
time.Sleep(time.Second)
// s.RequestBYE(s.InviteSIP)
}
}
}
func (s *IcsSession) ReadRTP() {
l := icslog.GetIcsLog()
defer func() {
if r := recover(); r != nil {
fmt.Println("ReadRTP Panic", r)
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "ReadRTP Panic - %s", r)
}
}()
svc := icssvc.GetServiceStatus()
conf := icsconf.GetIcsConfig()
@ -1620,15 +1687,12 @@ func (s *IcsSession) ReadRTP() {
// s.ExpTimer.Start()
// go s.ExpiredRTP(s.readTimer)
for !svc.GetExit() || !svc.GetStop() {
//fmt.Println(">>>", s.ID, s.rtpMediaNeter.LocalAddr().String())
if s.rtpMediaNeter == nil {
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "######### media neter nil!!!")
break
}
data, _, rlen, rerr := s.rtpMediaNeter.ReadRTP()
//data, raddr, rlen, rerr := s.rtpMediaNeter.ReadRTP()
if rerr != nil {
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "%s-%s", rerr.GetMessage(), rerr.GetError())
break
@ -1642,7 +1706,6 @@ func (s *IcsSession) ReadRTP() {
continue
}
RPT := rtp.GetPayloadType()
if RPT == icspacketparser.PayloadType(101) { //rfc2833
///////////////
//dtmf
@ -1688,6 +1751,37 @@ func (s *IcsSession) ReadRTP() {
// fmt.Println("Recev 21 TTS!!!")
s.expRead = time.Now()
s.expCheck = false
pcm, cerr := s.RxConverter.Decode(rtp.Payload)
if cerr != nil {
l.Print(icslog.LOG_LEVEL_ERROR, s.ID, cerr.GetMessage())
continue
}
average, _ := calAverage(pcm)
if average > REFER+RANGE {
s.vaildcnt++
if s.vaildcnt > 5 {
s.silencecnt = 0
}
} else {
s.silencecnt++
if s.silencecnt > 50 {
s.vaildcnt = 0
}
}
if s.silencecnt > 200 {
if s.epd == 1 {
s.epd = 2
s.silencecnt = 0
} else if s.epd == 2 {
s.epd = 0
}
} else if s.vaildcnt > 10 {
if s.epd == 0 {
s.epd = 1
}
}
} else {
//rtp decoding
pcm, cerr := s.RxConverter.Decode(rtp.Payload)
@ -1730,6 +1824,25 @@ func (s *IcsSession) ReadRTP() {
}
}
func calAverage(target []byte) (int, error) {
var sum uint32 = 0
var err error = nil
length := len(target)
if length != 0 {
for i := 0; i < length; i += 2 {
if i+1 < length {
data := []byte{target[i+1], target[i]}
sum = sum + uint32(binary.BigEndian.Uint16(data))
}
}
} else {
err = fmt.Errorf("Error: integer divide by zero %+v", target)
}
return int(int(sum) / (length / 2)), err
}
// func (s *IcsSession)ExpiredRTP(t *icscbtimer.IcsCBTimer) {
func (s *IcsSession) ExpiredRTP(t time.Ticker) {
s.mychannel = make(chan bool)
@ -1956,7 +2069,7 @@ func (s *IcsSession) RequestBYESIM() {
// contactName := strings.SplitN(contactName1[1], "@", 2)
optfunc := func() {
optMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "AISB", conf.SIPConfig.SIPProxy, transport)
optMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "07012345678", conf.SIPConfig.SIPProxy, transport)
reqOpt := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_BYE, optMethod)
via := fmt.Sprintf("SIP/2.0/UDP %s:%d;branch=%s", ip, port, sipasm.GenerateBranch())
@ -2025,7 +2138,7 @@ func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) {
// contactName := strings.SplitN(contactName1[1], "@", 2)
optfunc := func() {
optMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "AISB", conf.SIPConfig.SIPProxy, transport)
optMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "07012345678", conf.SIPConfig.SIPProxy, transport)
reqOpt := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_BYE, optMethod)
via := fmt.Sprintf("SIP/2.0/UDP %s:%d;branch=%s", ip, port, sipasm.GenerateBranch())
@ -2034,10 +2147,10 @@ func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) {
// from := strings.SplitN(inviteSIP.From, ": ", 2)
//from := fmt.Sprintf("<sip:%s@%s>;tag=%s", s.AgentName, ip, sipasm.GenerateTag())
s.uri = fmt.Sprintf("sip:%s@%s", "AISB", ip)
s.uri = fmt.Sprintf("sip:%s@%s", "07012345678", ip)
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Set URI [%s]", s.uri)
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "AISB", ip)
to := fmt.Sprintf("<sip:%s@%s;user=phone>", "07012345678", ip)
if s.InviteSIP != nil {
from = s.InviteSIP.From
// to = s.InviteSIP.To
@ -2048,7 +2161,7 @@ func (s *IcsSession) RequestBYE(inviteSIP *icspacketparser.SIP) {
cseq := fmt.Sprintf("%d BYE", s.Cseq)
s.Cseq++
//referto := fmt.Sprintf("<sip:01025670081@192.168.0.221>")
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", "AISB", ip, port, transport)
contact := fmt.Sprintf("<sip:%s@%s:%d;transport=%s>", "07012345678", ip, port, transport)
userAgent := conf.InfoConfig.Product
allow := "REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE"
supported := "timer,path,replaces"

@ -5,8 +5,8 @@ Call Signal Processor
package icssessionmanager
import (
"time"
"strings"
"time"
"gitlab.com/ics_cinnamon/voicegateway/icsconf"
"gitlab.com/ics_cinnamon/voicegateway/icserror"
@ -32,8 +32,6 @@ func (s *IcsSession) Processing(sip *parser.SIP) *icserror.IcsError {
//return nil
return s.PassInvite(sip)
// return s.ProcInvite(sip)
case parser.ICS_SIP_METHOD_PUBLISH:
case parser.ICS_SIP_METHOD_OPTIONS:
case parser.ICS_SIP_METHOD_INFO:
case parser.ICS_SIP_METHOD_UPDATE:
@ -77,8 +75,8 @@ func (s *IcsSession) Processing(sip *parser.SIP) *icserror.IcsError {
//////// for simul //////////////
//////////////////////////////////
// send 83 to reg200
l.Printf(icslog.LOG_LEVEL_ERROR, s.ID, "Start Sim!!!")
time.Sleep(time.Second)
l.Printf(icslog.LOG_LEVEL_INFO, s.ID, "Start Sim!!!")
time.Sleep(time.Second * 1)
s.SendRequestInvite()
//////////////////////////////////
//////////////////////////////////

@ -5,6 +5,8 @@ import (
"net"
"strings"
"sync"
"sync/atomic"
"time"
"gitlab.com/ics_cinnamon/joy4/format"
@ -143,6 +145,13 @@ type IcsSession struct {
readTimer time.Ticker
expCheck bool
mychannel chan bool
inviteDuration time.Time
TTSFlag atomic.Value
PreTTSFlag bool
silencecnt int
vaildcnt int
epd int
preepd int
m *sync.Mutex
}
@ -182,6 +191,7 @@ func (s *IcsSession) Init() *icserror.IcsError {
//conf := icsconf.GetIcsConfig()
s.RTPCBStatus = 0
s.TTSFlag.Store(false)
/*
s.AgentName = s.AgentConf.Name

@ -8,6 +8,7 @@ import (
"strings"
"sync"
"time"
// "strconv"
"gitlab.com/ics_cinnamon/voicegateway/icscbtimer"
@ -259,6 +260,8 @@ func (sm *SessionManager) Run() (icserr *icserror.IcsError) {
sip := icspacketparser.NewSIP()
sip.SipParser(data)
fmt.Println(sip.Diversion)
if icspacketparser.ICS_SIP_METHOD_NOT_FOUND == sip.Method { //not found sip. maybe abnormal use
l.Printf(icslog.LOG_LEVEL_INFO, -1, "icspacketparser.ICS_SIP_METHOD_NOT_FOUND-%s", string(data))
continue
@ -275,7 +278,6 @@ func (sm *SessionManager) Run() (icserr *icserror.IcsError) {
// // }
// // }()
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "sip 내용 전달! %+v", sip)
// // ip := strings.Split(conf.SIPConfig.SIPProxy, ":")[0]
// // port, cerr := strconv.Atoi(strings.Split(conf.SIPConfig.SIPProxy, ":")[1])
@ -284,7 +286,6 @@ func (sm *SessionManager) Run() (icserr *icserror.IcsError) {
// // }
// // iport := fmt.Sprintf("%s:%d", ip, port)
// // fmt.Println(ip, port)
// sipPort := conf.SIPConfig.Port
@ -335,7 +336,7 @@ func (sm *SessionManager) Run() (icserr *icserror.IcsError) {
// localAddr := icsnet.NewNetAddrWithIPAddr(localAddrStr)
//////////////////////////////////////////////
ip := conf.InfoConfig.ServerIP
ackMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "192.168.0.222:5090", "AISB",transport)
ackMethod := fmt.Sprintf("sip:%s@%s;transport=%s", "192.168.0.222:5090", "AISB", transport)
reqAck := sipasm.NewSIPMessage(sipasm.ICSSIP_METHOD_ACK, ackMethod)
maxforwards := "70"
// s.uri = fmt.Sprintf("sip:%s@%s", conf.Representative.Name, ip)

@ -367,13 +367,11 @@ func (s *IcsSession) RemoveSession() *icserror.IcsError {
s.rtcpMediaNeter.Close()
s.rtcpMediaNeter = nil
}
}
e := &IcsSession{}
s.m.Lock()
s.eventSystem.ClearJob()
/*
s.AgentConf = nil
s.AgentInfo = nil
@ -408,7 +406,6 @@ func (s *IcsSession) RemoveSession() *icserror.IcsError {
s.SetRegisterStatus(STATUS_REGISTER_READY)
// fmt.Println("REMOVE SESSION STATUS: ", s.GetAgentStatus())
s.m.Unlock()
return nil
}

@ -86,6 +86,7 @@ const (
ICSSIP_HEADER_CONTENT_ENCODING
ICSSIP_HEADER_CONTENT_LANGUAGE
ICSSIP_HEADER_CONTENT_LENGTH
ICSSIP_HEADER_DIVERSION
ICSSIP_HEADER_TERMINATOR
ICSSIP_HEADER_NOT_DEFINED
ICSSIP_HEADER_MAX
@ -222,6 +223,7 @@ func initHeaderString() {
ICSSIP_HEADER_STRING[ICSSIP_HEADER_WARNING] = "Warning: %s\r\n"
ICSSIP_HEADER_STRING[ICSSIP_HEADER_WWW_AUTHENTICATE] = "WWW-Authenticate: %s\r\n"
ICSSIP_HEADER_STRING[ICSSIP_HEADER_TERMINATOR] = "\r\n"
ICSSIP_HEADER_STRING[ICSSIP_HEADER_DIVERSION] = "Diversion: <tel: %s>; reason=unknown; counter=1\r\n"
ICSSIP_HEADER_STRING2TYPE = make(map[string]ICSSIP_HEADER_TYPE)
ICSSIP_HEADER_STRING2TYPE["ACCEPT"] = ICSSIP_HEADER_ACCEPT
@ -272,6 +274,7 @@ func initHeaderString() {
ICSSIP_HEADER_STRING2TYPE["VIA"] = ICSSIP_HEADER_VIA
ICSSIP_HEADER_STRING2TYPE["WARNING"] = ICSSIP_HEADER_WARNING
ICSSIP_HEADER_STRING2TYPE["WWW-AUTHENTICATE"] = ICSSIP_HEADER_WWW_AUTHENTICATE
ICSSIP_HEADER_STRING2TYPE["Diversion"] = ICSSIP_HEADER_DIVERSION
}
func initStatusCodeString() {

@ -0,0 +1,4 @@
#!/usr/bin/sh
BIN=$ICSVG_ROOT/bin
msg=`$BIN/loader`
echo $msg
Loading…
Cancel
Save