Skip to content

Commit

Permalink
Merge pull request #31 from wmnsk/cleanup-improvements
Browse files Browse the repository at this point in the history
Support all params & add XUDT
  • Loading branch information
wmnsk authored Jan 4, 2025
2 parents 207398e + e54e25a commit f421b06
Show file tree
Hide file tree
Showing 20 changed files with 3,647 additions and 651 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Run `go mod tidy` to download the dependency, and you're ready to start developi
| Reset confirm | RSC | 4.15 | - |
| Protocol data unit error | ERR | 4.16 | - |
| Inactivity test | IT | 4.17 | - |
| Extended unitdata | XUDT | 4.18 | - |
| Extended unitdata | XUDT | 4.18 | Yes |
| Extended unitdata service | XUDTS | 4.19 | - |
| Long unitdata | LUDT | 4.20 | - |
| Long unitdata service | LUDTS | 4.21 | - |
Expand All @@ -46,30 +46,30 @@ Run `go mod tidy` to download the dependency, and you're ready to start developi

| Parameter name | Reference | Supported? |
| --------------------------- | --------- | ---------- |
| End of optional parameters | 3.1 | |
| Destination local reference | 3.2 | |
| Source local reference | 3.3 | |
| End of optional parameters | 3.1 | Yes |
| Destination local reference | 3.2 | Yes |
| Source local reference | 3.3 | Yes |
| Called party address | 3.4 | Yes |
| Calling party address | 3.5 | Yes |
| Protocol class | 3.6 | Yes |
| Segmenting/reassembling | 3.7 | |
| Receive sequence number | 3.8 | |
| Sequencing/segmenting | 3.9 | |
| Credit | 3.10 | |
| Release cause | 3.11 | |
| Return cause | 3.12 | |
| Reset cause | 3.13 | |
| Error cause | 3.14 | |
| Refusal cause | 3.15 | |
| Segmenting/reassembling | 3.7 | Yes |
| Receive sequence number | 3.8 | Yes |
| Sequencing/segmenting | 3.9 | Yes |
| Credit | 3.10 | Yes |
| Release cause | 3.11 | Yes |
| Return cause | 3.12 | Yes |
| Reset cause | 3.13 | Yes |
| Error cause | 3.14 | Yes |
| Refusal cause | 3.15 | Yes |
| Data | 3.16 | Yes |
| Segmentation | 3.17 | |
| Hop counter | 3.18 | |
| Importance | 3.19 | |
| Long data | 3.20 | |
| Segmentation | 3.17 | Yes |
| Hop counter | 3.18 | Yes |
| Importance | 3.19 | Yes |
| Long data | 3.20 | Yes |

## Author(s)

Yoshiyuki Kurauchi ([Website](https://wmnsk.com/))
Yoshiyuki Kurauchi ([Website](https://wmnsk.com/)) and [contributors](https://github.com/wmnsk/go-sccp/graphs/contributors).

## LICENSE

Expand Down
66 changes: 66 additions & 0 deletions constant_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// UnsupportedTypeError indicates the value in Version field is invalid.
type UnsupportedTypeError byte
type UnsupportedTypeError uint8

// Error returns the type of receiver and some additional message.
func (e UnsupportedTypeError) Error() string {
Expand Down
53 changes: 36 additions & 17 deletions examples/client/simple-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,51 +72,60 @@ func main() {
log.Fatal(err)
}

cd, err := utils.EncodeBCD("1234567890123456")
if err != nil {
log.Fatal(err)
}
cg, err := utils.EncodeBCD("9876543210")
if err != nil {
log.Fatal(err)
}

gti := params.GTITTNPESNAI
ai := params.NewAddressIndicator(false, true, false, gti)
cdPA := params.NewPartyAddressTyped(
cdPA := params.NewCalledPartyAddress(
ai, 0, 6, params.NewGlobalTitle(
gti,
params.TranslationType(0),
params.NPISDNTelephony,
params.ESBCDOdd,
params.NAIInternationalNumber,
cd,
utils.MustBCDEncode("1234567890123456"),
),
)
cgPA := params.NewPartyAddressTyped(
cgPA := params.NewCallingPartyAddress(
ai, 0, 7, params.NewGlobalTitle(
gti,
params.TranslationType(1),
params.NPISDNMobile,
params.ESBCDOdd,
params.NAIInternationalNumber,
cg,
utils.MustBCDEncode("9876543210"),
),
)
// create UDT message with CdPA, CgPA and payload
udt, err := sccp.NewUDT(
udt := sccp.NewUDT(
1, // Protocol Class
true, // Message handling
cdPA,
cgPA,
payload, // payload
).MarshalBinary()
)
u, err := udt.MarshalBinary()
if err != nil {
log.Fatal(err)
}

xudt := sccp.NewXUDT(
1, // Protocol Class
true, // Message handling
2, // Hop Counter
cdPA,
cgPA,
payload, // payload
params.NewSegmentation(true, 1, 2, 0x123456),
params.NewImportance(10),
)
x, err := xudt.MarshalBinary()
if err != nil {
log.Fatal(err)
}

// send once
if _, err := m3conn.Write(udt); err != nil {
i := 1
log.Printf("Sending %04d: %v", i, udt)
if _, err := m3conn.Write(u); err != nil {
log.Fatal(err)
}

Expand All @@ -129,7 +138,17 @@ func main() {
ticker.Stop()
os.Exit(1)
case <-ticker.C:
if _, err := m3conn.Write(udt); err != nil {
i++

var msg sccp.Message = udt
b := u
if i%2 == 0 {
msg = xudt
b = x
}

log.Printf("Sending %04d: %v", i, msg)
if _, err := m3conn.Write(b); err != nil {
log.Fatal(err)
}
}
Expand Down
108 changes: 108 additions & 0 deletions examples/server/receiver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright 2018-2024 go-sccp authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.

/*
Command receiver receives SCCP messages from the client and prints them out.
*/
package main

import (
"context"
"errors"
"flag"
"io"
"log"
"net"
"time"

"github.com/wmnsk/go-m3ua/messages/params"
"github.com/wmnsk/go-sccp"

"github.com/ishidawataru/sctp"
"github.com/wmnsk/go-m3ua"
)

func serve(conn *m3ua.Conn) {
defer conn.Close()

buf := make([]byte, 1500)
for {
n, err := conn.Read(buf)
if err != nil {
if errors.Is(err, io.EOF) || errors.Is(err, net.ErrClosed) {
log.Printf("Closed M3UA conn with: %s, waiting to come back on", conn.RemoteAddr())
return
}
log.Printf("Error reading from M3UA conn: %s", err)
return
}

b := make([]byte, n)
copy(b, buf[:n])
go func() {
msg, err := sccp.ParseMessage(b)
if err != nil {
log.Printf("Failed to parse SCCP message: %s, %x", err, b)
return
}

log.Printf("Received SCCP message: %v", msg)
}()
}
}

func main() {
var (
addr = flag.String("addr", "127.0.0.1:2905", "Source IP and Port listen.")
)
flag.Parse()

// see go-m3ua for the details of the configuration.
// https://github.com/wmnsk/go-m3ua
config := m3ua.NewServerConfig(
&m3ua.HeartbeatInfo{
Enabled: true,
Interval: 0,
Timer: time.Duration(5 * time.Second),
},
0x22222222, // OriginatingPointCode
0x11111111, // DestinationPointCode
1, // AspIdentifier
params.TrafficModeLoadshare, // TrafficModeType
0, // NetworkAppearance
0, // CorrelationID
[]uint32{1, 2}, // RoutingContexts
params.ServiceIndSCCP, // ServiceIndicator
0, // NetworkIndicator
0, // MessagePriority
1, // SignalingLinkSelection
)
config.AspIdentifier = nil
config.CorrelationID = nil

laddr, err := sctp.ResolveSCTPAddr("sctp", *addr)
if err != nil {
log.Fatalf("Failed to resolve SCTP address: %s", err)
}

listener, err := m3ua.Listen("m3ua", laddr, config)
if err != nil {
log.Fatalf("Failed to listen: %s", err)
}
log.Printf("Waiting for connection on: %s", listener.Addr())

ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()

for {
conn, err := listener.Accept(ctx)
if err != nil {
log.Fatalf("Failed to accept M3UA: %s", err)
}
log.Printf("Connected with: %s", conn.RemoteAddr())

go serve(conn)
}
}
Loading

0 comments on commit f421b06

Please sign in to comment.