Skip to content

Commit

Permalink
Update go-pfcp-networking
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Dec 4, 2024
1 parent 1563ff0 commit 85a92ab
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/adrg/xdg v0.5.3
github.com/gin-gonic/gin v1.10.0
github.com/gofrs/uuid v4.4.0+incompatible
github.com/nextmn/go-pfcp-networking v0.0.38
github.com/nextmn/go-pfcp-networking v0.0.39
github.com/nextmn/json-api v0.0.14
github.com/nextmn/logrus-formatter v0.0.1
github.com/nextmn/rfc9433 v0.0.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/nextmn/go-pfcp-networking v0.0.38 h1:C7HgLh6UUbqfoTHl/uvUcYNZUBPSur68rOHdLUnpx9Q=
github.com/nextmn/go-pfcp-networking v0.0.38/go.mod h1:KYoKLiltDmHL2YMU5mz2k/E1xMoz4TpmzTz6Nr5u5gA=
github.com/nextmn/go-pfcp-networking v0.0.39 h1:8LDz3O0pjQ3PPLGDnds3z369mB7xBEkTtLqAzMMrtFE=
github.com/nextmn/go-pfcp-networking v0.0.39/go.mod h1:KYoKLiltDmHL2YMU5mz2k/E1xMoz4TpmzTz6Nr5u5gA=
github.com/nextmn/json-api v0.0.14 h1:m4uHOVcXsxkXoxbrhqemLTRG4T86eYkejjirew1nDUU=
github.com/nextmn/json-api v0.0.14/go.mod h1:CQXeNPj9MDGsEExtnqJFIGjLgZAKsmOoO2fy+mep7Ak=
github.com/nextmn/logrus-formatter v0.0.1 h1:Bsf78jjiEESc+rV8xE6IyKj4frDPGMwXFNrLQzm6A1E=
Expand Down
8 changes: 5 additions & 3 deletions internal/app/http.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright 2023 Louis Royer and the NextMN-SRv6-ctrl contributors. All rights reserved.
// Copyright 2023 Louis Royer and the NextMN contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT

package app

import (
"context"
"fmt"
"net"
"net/http"
"net/netip"
"sync"
"time"

Expand All @@ -32,7 +34,7 @@ type RouterRegistry struct {
pfcpSrv *pfcp_networking.PFCPEntityUP
}

func NewHttpServerEntity(httpAddr string, pfcp *pfcp_networking.PFCPEntityUP) *HttpServerEntity {
func NewHttpServerEntity(httpAddr netip.AddrPort, pfcp *pfcp_networking.PFCPEntityUP) *HttpServerEntity {
rr := RouterRegistry{
routers: make(n4tosrv6.RouterMap),
pfcpSrv: pfcp,
Expand All @@ -48,7 +50,7 @@ func NewHttpServerEntity(httpAddr string, pfcp *pfcp_networking.PFCPEntityUP) *H
e := HttpServerEntity{
routers: &rr,
srv: &http.Server{
Addr: httpAddr,
Addr: httpAddr.String(),
Handler: r,
},
}
Expand Down
22 changes: 12 additions & 10 deletions internal/app/rules-pusher.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2024 Louis Royer and the NextMN-SRv6-ctrl contributors. All rights reserved.
// Copyright 2024 Louis Royer and the NextMN contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT

package app

import (
Expand All @@ -13,15 +14,16 @@ import (
"net/netip"
"sync"

"github.com/sirupsen/logrus"
"github.com/wmnsk/go-pfcp/ie"

pfcp_networking "github.com/nextmn/go-pfcp-networking/pfcp"
pfcpapi "github.com/nextmn/go-pfcp-networking/pfcp/api"
"github.com/nextmn/go-pfcp-networking/pfcputil"
"github.com/nextmn/json-api/jsonapi"
"github.com/nextmn/json-api/jsonapi/n4tosrv6"
"github.com/nextmn/rfc9433/encoding"
"github.com/nextmn/srv6-ctrl/internal/config"

"github.com/sirupsen/logrus"
"github.com/wmnsk/go-pfcp/ie"
)

const UserAgent = "go-github-nextmn-srv6-ctrl"
Expand All @@ -48,8 +50,8 @@ func NewRulesPusher(config *config.CtrlConfig) *RulesPusher {
}
}

func (pusher *RulesPusher) pushSingleRule(client http.Client, uri string, data []byte) error {
req, err := http.NewRequest(http.MethodPost, uri+"/rules", bytes.NewBuffer(data))
func (pusher *RulesPusher) pushSingleRule(ctx context.Context, client http.Client, uri jsonapi.ControlURI, data []byte) error {
req, err := http.NewRequestWithContext(ctx, http.MethodPost, uri.JoinPath("rules").String(), bytes.NewBuffer(data))
if err != nil {
logrus.WithError(err).Error("could not create http request")
return err
Expand All @@ -76,7 +78,7 @@ func (pusher *RulesPusher) pushSingleRule(client http.Client, uri string, data [
return nil
}

func (pusher *RulesPusher) pushRTRRule(ue_ip string) error {
func (pusher *RulesPusher) pushRTRRule(ctx context.Context, ue_ip string) error {
i, ok := pusher.ues.Load(ue_ip)
infos := i.(*ueInfos)
infos.Lock()
Expand Down Expand Up @@ -137,7 +139,7 @@ func (pusher *RulesPusher) pushRTRRule(ue_ip string) error {
wg.Add(1)
go func() error {
defer wg.Done()
return pusher.pushSingleRule(client, r.ControlURI, rule_json)
return pusher.pushSingleRule(ctx, client, r.ControlURI, rule_json)
}()

}
Expand Down Expand Up @@ -191,7 +193,7 @@ func (pusher *RulesPusher) pushRTRRule(ue_ip string) error {
wg.Add(1)
go func() error {
defer wg.Done()
return pusher.pushSingleRule(client, r.ControlURI, rule_json)
return pusher.pushSingleRule(ctx, client, r.ControlURI, rule_json)
}()

}
Expand Down Expand Up @@ -317,7 +319,7 @@ func (pusher *RulesPusher) updateRoutersRules(ctx context.Context, msgType pfcpu
wg.Add(1)
go func() {
defer wg.Done()
pusher.pushRTRRule(ip.(string))
pusher.pushRTRRule(ctx, ip.(string))
// TODO: check pushRTRRule return code and send pfcp error on failure
}()
return true
Expand Down
3 changes: 2 additions & 1 deletion internal/app/setup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2024 Louis Royer and the NextMN-SRv6-ctrl contributors. All rights reserved.
// Copyright 2024 Louis Royer and the NextMN contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT

package app

import (
Expand Down
3 changes: 2 additions & 1 deletion internal/app/upf.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2023 Louis Royer and the NextMN-SRv6-ctrl contributors. All rights reserved.
// Copyright 2023 Louis Royer and the NextMN contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT

package app

import (
Expand Down
4 changes: 3 additions & 1 deletion internal/config/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
package config

import (
"net/netip"

"github.com/nextmn/json-api/jsonapi"
)

type Control struct {
Uri jsonapi.ControlURI `yaml:"uri"` // may contain domain name instead of ip address
BindAddr string `yaml:"bind-addr"` // in the form `ip:port`
BindAddr netip.AddrPort `yaml:"bind-addr"` // in the form `ip:port`
}
10 changes: 7 additions & 3 deletions internal/config/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

package config

import (
"github.com/nextmn/json-api/jsonapi"
)

type Rule struct {
ControlURI string `yaml:"control-uri"` // e.g. http://srgw.local:8080
Enabled bool `yaml:"enabled"`
SegmentsList []string `yaml:"segments-list"` // Segment[0] is the ultimate node, Segment[n-1] is the next hop ; Segment[0] can be a prefix (for downlink)
ControlURI jsonapi.ControlURI `yaml:"control-uri"` // e.g. http://srgw.local:8080
Enabled bool `yaml:"enabled"`
SegmentsList []string `yaml:"segments-list"` // Segment[0] is the ultimate node, Segment[n-1] is the next hop ; Segment[0] can be a prefix (for downlink)
}
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2023 Louis Royer and the NextMN-SRv6-ctrl contributors. All rights reserved.
// Copyright 2023 Louis Royer and the NextMN contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT

package main

import (
Expand Down

0 comments on commit 85a92ab

Please sign in to comment.