fiorix / go-diameter

Diameter stack and Base Protocol (RFC 6733) for the Go programming language
Other
244 stars 142 forks source link

CER/CEA Session ID mismatch #132

Open AbdulBasitAlvi opened 4 years ago

AbdulBasitAlvi commented 4 years ago

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]"



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)
}
aivisol commented 4 years ago

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.

sheldonlyr commented 1 year ago

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