go-diameter icon indicating copy to clipboard operation
go-diameter copied to clipboard

CER/CEA Session ID mismatch

Open AbdulBasitAlvi opened this issue 4 years ago • 2 comments

When creating a simple server to respond to CER/CEA messages, the CEA message generated has the wrong session ID which makes the client give an error saying "Unexpected (no scenario found) call with session-id [xxxxxxxxx]"


  • DIAMETER
  • cmd=Capabilities-Exchange Request(257) flags=R--- appl=Diameter Common Messages(0) h2h=0 e2e=0 |

  • DIAMETER
  • cmd=Capabilities-Exchange Answer(257) flags=---- appl=Diameter Common Messages(0) h2h=85681811 e2e=6d510f37 |

I am using seagul to generate client side traffic.

My server code:

package main

import (
	"flag"
	"log"
	"net/http"

	_ "net/http/pprof"

	"github.com/fiorix/go-diameter/v4/diam"
	"github.com/fiorix/go-diameter/v4/diam/datatype"
	"github.com/fiorix/go-diameter/v4/diam/dict"
	"github.com/fiorix/go-diameter/v4/diam/sm"
)

func main() {
	serverAddress := flag.String("serverAddress", "192.168.1.1:3868", "address in the form of ip:port to listen on")
	ppaddr := flag.String("pprof_addr", ":9000", "address in form of ip:port for the pprof server")
	host := flag.String("diam_host", "hssemulator.mnc001.mcc001.3gppnetwork.org", "diameter identity host")
	realm := flag.String("diam_realm", "ims.mnc001.mcc001.3gppnetwork.org", "diameter identity realm")
	certFile := flag.String("cert_file", "", "tls certificate file (optional)")
	keyFile := flag.String("key_file", "", "tls key file (optional)")
	//silent := flag.Bool("s", false, "silent mode, useful for benchmarks")
	flag.Parse()

	// Load our custom dictionary on top of the default one, which
	// always have the Base Protocol (RFC6733) and Credit Control
	// Application (RFC4006).
	err := dict.Default.LoadFile("base_cx.xml")
	if err != nil {
		log.Fatal(err)
	}

	settings := &sm.Settings{
		OriginHost:       datatype.DiameterIdentity(*host),
		OriginRealm:      datatype.DiameterIdentity(*realm),
		VendorID:         10415,
		ProductName:      "hss-emulator",
		FirmwareRevision: 1,
	}

	// Create the state machine (mux) and set its message handlers.
	mux := sm.New(settings)
	mux.HandleFunc("ALL", handleALL) // Catch all.

	// Print error reports.
	go printErrors(mux.ErrorReports())

	if len(*ppaddr) > 0 {
		go func() { log.Fatal(http.ListenAndServe(*ppaddr, nil)) }()
	}

	err = listen(*serverAddress, *certFile, *keyFile, mux)
	if err != nil {
		log.Fatal(err)
	}
}

func printErrors(ec <-chan *diam.ErrorReport) {
	for err := range ec {
		log.Println(err)
	}
}

func listen(addr, cert, key string, handler diam.Handler) error {
	// Start listening for connections.
	if len(cert) > 0 && len(key) > 0 {
		log.Println("Starting secure diameter server on", addr)
		return diam.ListenAndServeTLS(addr, cert, key, handler, nil)
	}
	log.Println("Starting diameter server on", addr)
	return diam.ListenAndServe(addr, handler, nil)
}


func handleALL(c diam.Conn, m *diam.Message) {
	log.Printf("Received unexpected message from %s:\n%s", c.RemoteAddr(), m)
}

AbdulBasitAlvi avatar Apr 29 '20 08:04 AbdulBasitAlvi

I am seeing similar problem. When I run the server example directly from this repo, all works fine, CER/CEA is successful. However, if I create my own module (consisting of this exact server example) and import this repo as a module, CER/CEA fails with "no common capabilities" error. I will try to troubleshoot this further, however being total golang beginner not sure from where to start.

aivisol avatar May 23 '20 11:05 aivisol

This is because if hopbyhop and endtoend are zero, random numbers are assigned to them. https://github.com/fiorix/go-diameter/blob/master/diam/message.go#L166

sheldonlyr avatar Sep 22 '22 12:09 sheldonlyr