-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d412e64
commit 2ba4003
Showing
13 changed files
with
407 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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 cli | ||
|
||
import ( | ||
"github.com/nextmn/gnb-lite/internal/radio" | ||
"github.com/nextmn/gnb-lite/internal/session" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type Cli struct { | ||
Radio *radio.Radio | ||
PduSessions *session.PduSessions | ||
} | ||
|
||
func NewCli(r *radio.Radio, p *session.PduSessions) *Cli { | ||
return &Cli{ | ||
Radio: r, | ||
PduSessions: p, | ||
} | ||
} | ||
|
||
func (cli *Cli) Register(e *gin.Engine) { | ||
e.POST("/cli/ps/handover", cli.PsHandover) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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 cli | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/nextmn/json-api/jsonapi" | ||
"github.com/nextmn/json-api/jsonapi/n1n2" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type PsHandover struct { | ||
UeCtrl jsonapi.ControlURI `json:"ue-ctrl"` | ||
GNBTarget jsonapi.ControlURI `json:"gnb-target"` | ||
Sessions []n1n2.Session `json:"sessions"` | ||
} | ||
|
||
func (cli *Cli) PsHandover(c *gin.Context) { | ||
var ps PsHandover | ||
if err := c.BindJSON(&ps); err != nil { | ||
logrus.WithError(err).Error("could not deserialize") | ||
c.JSON(http.StatusBadRequest, jsonapi.MessageWithError{Message: "could not deserialize", Error: err}) | ||
} | ||
go cli.HandlePsHandover(ps) | ||
c.Status(http.StatusNotImplemented) | ||
} | ||
|
||
func (cli *Cli) HandlePsHandover(ps PsHandover) { | ||
ctx := cli.PduSessions.Context() | ||
hr := n1n2.HandoverRequired{ | ||
SourcegNB: cli.PduSessions.Control, | ||
Ue: ps.UeCtrl, | ||
} | ||
reqBody, err := json.Marshal(hr) | ||
if err != nil { | ||
logrus.WithError(err).Error("Could not marshal n1n2.HandoverRequired") | ||
return | ||
} | ||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, cli.PduSessions.Cp.JoinPath("ps/handover-required").String(), bytes.NewBuffer(reqBody)) | ||
if err != nil { | ||
logrus.WithError(err).Error("Could not create ps/handover-required") | ||
return | ||
} | ||
req.Header.Set("User-Agent", cli.PduSessions.UserAgent) | ||
req.Header.Set("Content-Type", "application/json; charset=UTF-8") | ||
if _, err := cli.PduSessions.Client.Do(req); err != nil { | ||
logrus.WithError(err).Error("Could not send ps/handover-required") | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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 session | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/nextmn/json-api/jsonapi" | ||
"github.com/nextmn/json-api/jsonapi/n1n2" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (s *PduSessions) HandoverCommand(c *gin.Context) { | ||
var ps n1n2.HandoverCommand | ||
if err := c.BindJSON(&ps); err != nil { | ||
logrus.WithError(err).Error("could not deserialize") | ||
c.JSON(http.StatusBadRequest, jsonapi.MessageWithError{Message: "could not deserialize", Error: err}) | ||
return | ||
} | ||
logrus.WithFields(logrus.Fields{ | ||
"ue": ps.UeCtrl.String(), | ||
}).Info("New Handover Command") | ||
go s.HandleHandoverCommand(ps) | ||
c.JSON(http.StatusAccepted, jsonapi.Message{Message: "please refer to logs for more information"}) | ||
} | ||
|
||
func (s *PduSessions) HandleHandoverCommand(ps n1n2.HandoverCommand) { | ||
// Add forwarder for downlink | ||
for _, session := range ps.Sessions { | ||
if session.ForwardDownlinkFteid == nil || session.DownlinkFteid == nil { | ||
// TODO: notify CP of error | ||
continue | ||
} | ||
s.manager.ForwardDownlink[session.DownlinkFteid.Teid] = session.ForwardDownlinkFteid | ||
// TODO: remove downlink forward with a timer | ||
// TODO: remove pdu session after a timer | ||
} | ||
|
||
ctx := s.Context() | ||
// Forward to UE | ||
reqBody, err := json.Marshal(ps) | ||
if err != nil { | ||
logrus.WithError(err).Error("Could not marshal n1n2.HandoverCommand") | ||
return | ||
} | ||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, ps.UeCtrl.JoinPath("ps/handover-command").String(), bytes.NewBuffer(reqBody)) | ||
if err != nil { | ||
logrus.WithError(err).Error("Could not create ps/handover-command") | ||
return | ||
} | ||
req.Header.Set("User-Agent", s.UserAgent) | ||
req.Header.Set("Content-Type", "application/json; charset=UTF-8") | ||
if _, err := s.Client.Do(req); err != nil { | ||
logrus.WithError(err).Error("Could not send ps/handover-command") | ||
return | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// 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 session | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/nextmn/json-api/jsonapi" | ||
"github.com/nextmn/json-api/jsonapi/n1n2" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (s *PduSessions) HandoverConfirm(c *gin.Context) { | ||
var ps n1n2.HandoverConfirm | ||
if err := c.BindJSON(&ps); err != nil { | ||
logrus.WithError(err).Error("could not deserialize") | ||
c.JSON(http.StatusBadRequest, jsonapi.MessageWithError{Message: "could not deserialize", Error: err}) | ||
return | ||
} | ||
logrus.WithFields(logrus.Fields{ | ||
"ue": ps.UeCtrl.String(), | ||
}).Info("New Handover Confirm") | ||
go s.HandleHandoverConfirm(ps) | ||
c.JSON(http.StatusAccepted, jsonapi.Message{Message: "please refer to logs for more information"}) | ||
} | ||
|
||
func (s *PduSessions) HandleHandoverConfirm(ps n1n2.HandoverConfirm) { | ||
ctx := s.Context() | ||
// forward to CP | ||
resp := n1n2.HandoverNotify{ | ||
// Header | ||
UeCtrl: ps.UeCtrl, | ||
Cp: ps.Cp, | ||
TargetGnb: ps.TargetGnb, | ||
// Handover Notify | ||
Sessions: ps.Sessions, | ||
SourceGnb: ps.SourceGnb, | ||
} | ||
reqBody, err := json.Marshal(resp) | ||
if err != nil { | ||
logrus.WithError(err).Error("Could not marshal n1n2.HandoverNotify") | ||
return | ||
} | ||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, s.Cp.JoinPath("ps/handover-notify").String(), bytes.NewBuffer(reqBody)) | ||
if err != nil { | ||
logrus.WithError(err).Error("Could not create ps/handover-notify") | ||
return | ||
} | ||
req.Header.Set("User-Agent", s.UserAgent) | ||
req.Header.Set("Content-Type", "application/json; charset=UTF-8") | ||
if _, err := s.Client.Do(req); err != nil { | ||
logrus.WithError(err).Error("Could not send ps/handover-notify") | ||
return | ||
} | ||
} |
Oops, something went wrong.