-
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
08cd8b5
commit 2cec65a
Showing
13 changed files
with
306 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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 amf | ||
|
||
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" | ||
) | ||
|
||
func (amf *Amf) HandoverNotify(c *gin.Context) { | ||
var m n1n2.HandoverNotify | ||
if err := c.BindJSON(&m); 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": m.UeCtrl.String(), | ||
"gnb-target": m.TargetGnb.String(), | ||
}).Info("New Handover Confirm") | ||
go amf.HandleHandoverNotify(m) | ||
c.JSON(http.StatusAccepted, jsonapi.Message{Message: "please refer to logs for more information"}) | ||
} | ||
|
||
func (amf *Amf) HandleHandoverNotify(m n1n2.HandoverNotify) { | ||
// TODO: | ||
// 1. update upf-i with pdu-session-n3.NextDownlinkFteid | ||
// 2. update pdu-session-n3 with Downlink NextDownlinkFteid, and remove the NextDownlinkFteid field | ||
|
||
logrus.Error("Handover Notify: Not implemented") | ||
} |
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 amf | ||
|
||
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 (amf *Amf) HandoverRequestAck(c *gin.Context) { | ||
var m n1n2.HandoverRequestAck | ||
if err := c.BindJSON(&m); 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": m.UeCtrl.String(), | ||
"gnb-source": m.SourcegNB.String(), | ||
"gnb-target": m.TargetgNB.String(), | ||
}).Info("New Handover Request Ack") | ||
go amf.HandleHandoverRequestAck(m) | ||
c.JSON(http.StatusAccepted, jsonapi.Message{Message: "please refer to logs for more information"}) | ||
} | ||
|
||
func (amf *Amf) HandleHandoverRequestAck(m n1n2.HandoverRequestAck) { | ||
// TODO: if UPF-i change, push new DL rules | ||
|
||
// send handover command to source with forwarding rule to targetGNB | ||
sessions := make([]n1n2.Session, len(m.Sessions)) | ||
for i, s := range m.Sessions { | ||
dl, err := amf.smf.GetSessionDownlinkFteid(m.UeCtrl, s.Addr, s.Dnn) | ||
if err != nil { | ||
// TODO: notify of failure | ||
continue | ||
} | ||
sessions[i] = n1n2.Session{ | ||
Addr: s.Addr, | ||
Dnn: s.Dnn, | ||
UplinkFteid: s.UplinkFteid, | ||
DownlinkFteid: dl, | ||
ForwardDownlinkFteid: s.DownlinkFteid, | ||
} | ||
if err := amf.smf.StoreNextDownlinkFteid(m.UeCtrl, s.Addr, s.Dnn, s.DownlinkFteid); err != nil { | ||
// TODO: notify of failure | ||
continue | ||
} | ||
} | ||
|
||
resp := n1n2.HandoverCommand{ | ||
Cp: m.Cp, | ||
TargetGnb: m.TargetgNB, | ||
SourceGnb: m.SourcegNB, | ||
UeCtrl: m.UeCtrl, | ||
Sessions: sessions, | ||
} | ||
ctx := amf.Context() | ||
reqBody, err := json.Marshal(resp) | ||
if err != nil { | ||
logrus.WithError(err).Error("Could not marshal n1n2.HandoverRequest") | ||
return | ||
} | ||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, m.SourcegNB.JoinPath("ps/handover-command").String(), bytes.NewBuffer(reqBody)) | ||
if err != nil { | ||
logrus.WithError(err).Error("Could not create request for ps/handover-command") | ||
return | ||
} | ||
req.Header.Set("User-Agent", amf.userAgent) | ||
req.Header.Set("Content-Type", "application/json; charset=UTF-8") | ||
if _, err := amf.client.Do(req); err != nil { | ||
logrus.WithError(err).Error("Could not send ps/handover-command") | ||
} | ||
} |
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,85 @@ | ||
// 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 amf | ||
|
||
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 (amf *Amf) HandoverRequired(c *gin.Context) { | ||
var m n1n2.HandoverRequired | ||
if err := c.BindJSON(&m); 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": m.Ue.String(), | ||
"gnb-source": m.SourcegNB.String(), | ||
"gnb-target": m.TargetgNB.String(), | ||
}).Info("New Handover Required") | ||
go amf.HandleHandoverRequired(m) | ||
c.JSON(http.StatusAccepted, jsonapi.Message{Message: "please refer to logs for more information"}) | ||
} | ||
|
||
func (amf *Amf) HandleHandoverRequired(m n1n2.HandoverRequired) { | ||
// TODO: if UPF-i change, push new UL rules | ||
|
||
// send handover-request to target with UPF-i FTEID | ||
ctx := amf.Context() | ||
|
||
sessions := make([]n1n2.Session, len(m.Sessions)) | ||
for i, s := range m.Sessions { | ||
uplinkfteid, err := amf.smf.GetSessionUplinkFteid(m.Ue, s.Addr, s.Dnn) | ||
if err != nil { | ||
// TODO: notify gnb of failure | ||
logrus.WithError(err).WithFields(logrus.Fields{ | ||
"ue": s.Addr, | ||
"dnn": s.Dnn, | ||
}).Error("Could not find Uplink FTEID for handover") | ||
continue | ||
} | ||
sessions[i] = n1n2.Session{ | ||
Addr: s.Addr, | ||
Dnn: s.Dnn, | ||
UplinkFteid: uplinkfteid, | ||
} | ||
|
||
} | ||
// send PseAccept to UE | ||
resp := n1n2.HandoverRequest{ | ||
// Header | ||
UeCtrl: m.Ue, | ||
Cp: m.Cp, | ||
TargetgNB: m.TargetgNB, | ||
|
||
// Handover Request | ||
Sessions: sessions, | ||
} | ||
reqBody, err := json.Marshal(resp) | ||
if err != nil { | ||
logrus.WithError(err).Error("Could not marshal n1n2.HandoverRequest") | ||
return | ||
} | ||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, m.TargetgNB.JoinPath("ps/handover-request").String(), bytes.NewBuffer(reqBody)) | ||
if err != nil { | ||
logrus.WithError(err).Error("Could not create request for ps/handover-request") | ||
return | ||
} | ||
req.Header.Set("User-Agent", amf.userAgent) | ||
req.Header.Set("Content-Type", "application/json; charset=UTF-8") | ||
if _, err := amf.client.Do(req); err != nil { | ||
logrus.WithError(err).Error("Could not send ps/handover-request") | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.