-
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.
- Loading branch information
1 parent
bbe3e25
commit e5410d2
Showing
12 changed files
with
236 additions
and
145 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
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
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,35 @@ | ||
// 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 ( | ||
"net/http" | ||
|
||
"github.com/nextmn/json-api/jsonapi" | ||
"github.com/nextmn/json-api/jsonapi/n1n2" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// get status of the controller | ||
func (p *PduSessions) EstablishmentAccept(c *gin.Context) { | ||
var ps n1n2.PduSessionEstabAcceptMsg | ||
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{ | ||
"gnb": ps.Header.Gnb.String(), | ||
"ip-addr": ps.Addr, | ||
}).Info("New PDU Session") | ||
|
||
go p.CreatePduSession(ps.Addr, ps.Header.Gnb) | ||
|
||
c.JSON(http.StatusAccepted, jsonapi.Message{Message: "please refer to logs for more information"}) | ||
} |
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,83 @@ | ||
// 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 (p *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{ | ||
"gnb-source": ps.SourceGnb.String(), | ||
"gnb-target": ps.TargetGnb.String(), | ||
}).Info("New Handover Command") | ||
|
||
go p.HandleHandoverCommand(ps) | ||
|
||
c.JSON(http.StatusAccepted, jsonapi.Message{Message: "please refer to logs for more information"}) | ||
} | ||
|
||
func (p *PduSessions) HandleHandoverCommand(m n1n2.HandoverCommand) { | ||
ctx := p.Context() | ||
if m.SourceGnb == m.TargetGnb { | ||
logrus.WithFields(logrus.Fields{ | ||
"gnb": m.SourceGnb.String(), | ||
}).Error("Handover Command: source and target gNBs are not different.") | ||
// TODO: notify gNB/CP of failure? | ||
return | ||
} | ||
|
||
sessions := make([]n1n2.Session, len(m.Sessions)) | ||
// TODO: update pdu sessions atomically | ||
for i, session := range m.Sessions { | ||
if err := p.UpdatePduSession(session.Addr, m.SourceGnb, m.TargetGnb); err != nil { | ||
// TODO: notify gNB/CP of failure? | ||
continue | ||
} | ||
sessions[i] = n1n2.Session{ | ||
Addr: session.Addr, | ||
Dnn: session.Dnn, | ||
} | ||
} | ||
|
||
// Send Handover Notify | ||
resp := n1n2.HandoverNotify{ | ||
UeCtrl: m.UeCtrl, | ||
Cp: m.Cp, | ||
TargetGnb: m.TargetGnb, | ||
Sessions: sessions, | ||
} | ||
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, m.TargetGnb.JoinPath("ps/handover-confirm").String(), bytes.NewBuffer(reqBody)) | ||
if err != nil { | ||
logrus.WithError(err).Error("Could not create request for ps/handover-confirm") | ||
return | ||
} | ||
req.Header.Set("User-Agent", p.UserAgent) | ||
req.Header.Set("Content-Type", "application/json; charset=UTF-8") | ||
if _, err := p.Client.Do(req); err != nil { | ||
logrus.WithError(err).Error("Could not send ps/handover-confirm") | ||
} | ||
} |
Oops, something went wrong.