Skip to content

Commit

Permalink
Add n1n2, and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Dec 4, 2024
1 parent 9c4fb6c commit 3029c9b
Show file tree
Hide file tree
Showing 30 changed files with 271 additions and 65 deletions.
3 changes: 2 additions & 1 deletion jsonapi/control_uri.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

import (
Expand Down
3 changes: 2 additions & 1 deletion jsonapi/message.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

type Message struct {
Expand Down
38 changes: 35 additions & 3 deletions jsonapi/message_with_error.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

import (
"encoding/json"
"fmt"
)

type MessageWithError struct {
Message string
Error error
Message string `json:"message"`
Error error `json:"error"`
}

func (u *MessageWithError) UnmarshalJSON(data []byte) error {
a := make(map[string]string)
err := json.Unmarshal(data, a)
if err != nil {
return err
}
msg, ok := a["message"]
if !ok {
return fmt.Errorf("Missing key `message` while unmarshaling MessageWithError")
}
u.Message = msg
e, ok := a["error"]
if !ok {
return fmt.Errorf("Missing key `error` while unmarshaling MessageWithError")
}
u.Error = fmt.Errorf(e)
return nil
}

func (u MessageWithError) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]string{
"message": u.Message,
"error": u.Error.Error(),
})
}
18 changes: 18 additions & 0 deletions jsonapi/n1n2/RadioPeerMsg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 n1n2

import (
"net/netip"

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

// RadioPeerMsg is used to discover UEs/gNBs "radio" peers.
type RadioPeerMsg struct {
Control jsonapi.ControlURI `json:"control"`
Data netip.AddrPort `json:"data"`
}
7 changes: 7 additions & 0 deletions jsonapi/n1n2/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// 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 n1n2 allow to simulate N1/N2 interface using a REST API.
package n1n2
22 changes: 22 additions & 0 deletions jsonapi/n1n2/n2_pdu_session_req_msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 n1n2

import (
"net/netip"

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

// N2PduSessionReqMsg is sent by the CP to the gNB to establish a PDU Session.
type N2PduSessionReqMsg struct {
Cp jsonapi.ControlURI `json:"cp"`
UeInfo PduSessionEstabAcceptMsg `json:"ue-info"` // information to forward to the UE

// Uplink FTEID: the gNB will establish an Uplink GTP Tunnel using the following
Upf netip.Addr `json:"upf"`
UplinkTeid uint32 `json:"uplink-teid"`
}
17 changes: 17 additions & 0 deletions jsonapi/n1n2/n2_pdu_session_resp_msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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 n1n2

import "net/netip"

// N2PduSessionRespMsg is sent to the CP by the gNB as a response of N2PduSessionReqMsg.
type N2PduSessionRespMsg struct {
UeInfo PduSessionEstabAcceptMsg `json:"ue-info"` // used to identify the PDU Session

// Downlink FTEID: the CP will use this to configure a downlink GTP Tunnel in Upf-i
DownlinkTeid uint32 `json:"downlink-teid"`
Gnb netip.Addr `json:"gnb"`
}
15 changes: 15 additions & 0 deletions jsonapi/n1n2/pdu_session_estab_accept_msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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 n1n2

import "net/netip"

// PduSessionEstabAcceptMsg is sent to the UE by the gNB
// when the PDU Session establishment is accepted.
type PduSessionEstabAcceptMsg struct {
Header PduSessionEstabReqMsg `json:"header"` // copy of the PDU Session Establishment Request Message
Addr netip.Addr `json:"address"` // IP Address attributed to the UE for this PDU Session
}
16 changes: 16 additions & 0 deletions jsonapi/n1n2/pdu_session_estab_req_msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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 n1n2

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

// PduSessionEstabReqMessage is sent by the UE to the gNB (then forwarded by the gNB to the CP)
// to start the PDU Session Establishment Procedure.
type PduSessionEstabReqMsg struct {
Ue jsonapi.ControlURI `json:"ue"`
Gnb jsonapi.ControlURI `json:"gnb"`
Dnn string `json:"dnn"`
}
5 changes: 3 additions & 2 deletions jsonapi/action.go → jsonapi/n4tosrv6/action.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

type Action struct {
SRH SRH `json:"srh"`
Expand Down
5 changes: 3 additions & 2 deletions jsonapi/backbone_ip.go → jsonapi/n4tosrv6/backbone_ip.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

import (
"fmt"
Expand Down
7 changes: 7 additions & 0 deletions jsonapi/n4tosrv6/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// 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 n4tosrv6 allow to translate PFCP Rules into SRv6.
package n4tosrv6
5 changes: 3 additions & 2 deletions jsonapi/gtp_header.go → jsonapi/n4tosrv6/gtp_header.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

import "net/netip"

Expand Down
5 changes: 3 additions & 2 deletions jsonapi/locator.go → jsonapi/n4tosrv6/locator.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

import (
"fmt"
Expand Down
5 changes: 3 additions & 2 deletions jsonapi/match.go → jsonapi/n4tosrv6/match.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

type Match struct {
Header *GtpHeader `json:"gtp,omitempty"`
Expand Down
5 changes: 3 additions & 2 deletions jsonapi/nexthop.go → jsonapi/n4tosrv6/nexthop.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

import (
"fmt"
Expand Down
5 changes: 3 additions & 2 deletions jsonapi/payload.go → jsonapi/n4tosrv6/payload.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

import "net/netip"

Expand Down
16 changes: 16 additions & 0 deletions jsonapi/n4tosrv6/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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 n4tosrv6

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

type Router struct {
Control jsonapi.ControlURI `json:"control"` // url used for control
Locator Locator `json:"locator"` // locator (ipv6 prefix)
Backbone BackboneIP `json:"backbone"` // data plane backbone ipv6 address
}
5 changes: 3 additions & 2 deletions jsonapi/router_map.go → jsonapi/n4tosrv6/router_map.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

import "github.com/gofrs/uuid"

Expand Down
5 changes: 3 additions & 2 deletions jsonapi/rule.go → jsonapi/n4tosrv6/rule.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

type Rule struct {
Enabled bool
Expand Down
5 changes: 3 additions & 2 deletions jsonapi/rule_map.go → jsonapi/n4tosrv6/rule_map.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

import "github.com/gofrs/uuid"

Expand Down
5 changes: 3 additions & 2 deletions jsonapi/segment.go → jsonapi/n4tosrv6/segment.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

import (
"fmt"
Expand Down
5 changes: 3 additions & 2 deletions jsonapi/srh.go → jsonapi/n4tosrv6/srh.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi

package n4tosrv6

import (
"fmt"
Expand Down
11 changes: 0 additions & 11 deletions jsonapi/router.go

This file was deleted.

3 changes: 2 additions & 1 deletion jsonapi_test/control_uri_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2024 Louis Royer and the NextMN-json-api 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 jsonapi_test

import (
Expand Down
Loading

0 comments on commit 3029c9b

Please sign in to comment.