From 3029c9b79d058738a010e5c7ab7f1fe43d4438d2 Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Wed, 4 Dec 2024 11:57:00 +0100 Subject: [PATCH] Add n1n2, and refactor --- jsonapi/control_uri.go | 3 +- jsonapi/message.go | 3 +- jsonapi/message_with_error.go | 38 ++++++++++++-- jsonapi/n1n2/RadioPeerMsg.go | 18 +++++++ jsonapi/n1n2/doc.go | 7 +++ jsonapi/n1n2/n2_pdu_session_req_msg.go | 22 +++++++++ jsonapi/n1n2/n2_pdu_session_resp_msg.go | 17 +++++++ jsonapi/n1n2/pdu_session_estab_accept_msg.go | 15 ++++++ jsonapi/n1n2/pdu_session_estab_req_msg.go | 16 ++++++ jsonapi/{ => n4tosrv6}/action.go | 5 +- jsonapi/{ => n4tosrv6}/backbone_ip.go | 5 +- jsonapi/n4tosrv6/doc.go | 7 +++ jsonapi/{ => n4tosrv6}/gtp_header.go | 5 +- jsonapi/{ => n4tosrv6}/locator.go | 5 +- jsonapi/{ => n4tosrv6}/match.go | 5 +- jsonapi/{ => n4tosrv6}/nexthop.go | 5 +- jsonapi/{ => n4tosrv6}/payload.go | 5 +- jsonapi/n4tosrv6/router.go | 16 ++++++ jsonapi/{ => n4tosrv6}/router_map.go | 5 +- jsonapi/{ => n4tosrv6}/rule.go | 5 +- jsonapi/{ => n4tosrv6}/rule_map.go | 5 +- jsonapi/{ => n4tosrv6}/segment.go | 5 +- jsonapi/{ => n4tosrv6}/srh.go | 5 +- jsonapi/router.go | 11 ----- jsonapi_test/control_uri_test.go | 3 +- jsonapi_test/message_with_error_test.go | 49 +++++++++++++++++++ .../{ => n4tosrv6_test}/backbone_ip_test.go | 9 ++-- .../{ => n4tosrv6_test}/locator_test.go | 9 ++-- .../{ => n4tosrv6_test}/segment_test.go | 21 ++++---- jsonapi_test/{ => n4tosrv6_test}/srh_test.go | 12 ++--- 30 files changed, 271 insertions(+), 65 deletions(-) create mode 100644 jsonapi/n1n2/RadioPeerMsg.go create mode 100644 jsonapi/n1n2/doc.go create mode 100644 jsonapi/n1n2/n2_pdu_session_req_msg.go create mode 100644 jsonapi/n1n2/n2_pdu_session_resp_msg.go create mode 100644 jsonapi/n1n2/pdu_session_estab_accept_msg.go create mode 100644 jsonapi/n1n2/pdu_session_estab_req_msg.go rename jsonapi/{ => n4tosrv6}/action.go (63%) rename jsonapi/{ => n4tosrv6}/backbone_ip.go (80%) create mode 100644 jsonapi/n4tosrv6/doc.go rename jsonapi/{ => n4tosrv6}/gtp_header.go (80%) rename jsonapi/{ => n4tosrv6}/locator.go (82%) rename jsonapi/{ => n4tosrv6}/match.go (73%) rename jsonapi/{ => n4tosrv6}/nexthop.go (85%) rename jsonapi/{ => n4tosrv6}/payload.go (67%) create mode 100644 jsonapi/n4tosrv6/router.go rename jsonapi/{ => n4tosrv6}/router_map.go (66%) rename jsonapi/{ => n4tosrv6}/rule.go (69%) rename jsonapi/{ => n4tosrv6}/rule_map.go (65%) rename jsonapi/{ => n4tosrv6}/segment.go (86%) rename jsonapi/{ => n4tosrv6}/srh.go (85%) delete mode 100644 jsonapi/router.go create mode 100644 jsonapi_test/message_with_error_test.go rename jsonapi_test/{ => n4tosrv6_test}/backbone_ip_test.go (82%) rename jsonapi_test/{ => n4tosrv6_test}/locator_test.go (82%) rename jsonapi_test/{ => n4tosrv6_test}/segment_test.go (75%) rename jsonapi_test/{ => n4tosrv6_test}/srh_test.go (73%) diff --git a/jsonapi/control_uri.go b/jsonapi/control_uri.go index 4ca3bd9..61c4a16 100644 --- a/jsonapi/control_uri.go +++ b/jsonapi/control_uri.go @@ -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 ( diff --git a/jsonapi/message.go b/jsonapi/message.go index 52ff3e2..fa0280b 100644 --- a/jsonapi/message.go +++ b/jsonapi/message.go @@ -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 { diff --git a/jsonapi/message_with_error.go b/jsonapi/message_with_error.go index 13c149c..ac654a0 100644 --- a/jsonapi/message_with_error.go +++ b/jsonapi/message_with_error.go @@ -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(), + }) } diff --git a/jsonapi/n1n2/RadioPeerMsg.go b/jsonapi/n1n2/RadioPeerMsg.go new file mode 100644 index 0000000..15c0bd0 --- /dev/null +++ b/jsonapi/n1n2/RadioPeerMsg.go @@ -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"` +} diff --git a/jsonapi/n1n2/doc.go b/jsonapi/n1n2/doc.go new file mode 100644 index 0000000..79fe8f2 --- /dev/null +++ b/jsonapi/n1n2/doc.go @@ -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 diff --git a/jsonapi/n1n2/n2_pdu_session_req_msg.go b/jsonapi/n1n2/n2_pdu_session_req_msg.go new file mode 100644 index 0000000..eab8118 --- /dev/null +++ b/jsonapi/n1n2/n2_pdu_session_req_msg.go @@ -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"` +} diff --git a/jsonapi/n1n2/n2_pdu_session_resp_msg.go b/jsonapi/n1n2/n2_pdu_session_resp_msg.go new file mode 100644 index 0000000..0b8e5d3 --- /dev/null +++ b/jsonapi/n1n2/n2_pdu_session_resp_msg.go @@ -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"` +} diff --git a/jsonapi/n1n2/pdu_session_estab_accept_msg.go b/jsonapi/n1n2/pdu_session_estab_accept_msg.go new file mode 100644 index 0000000..17b0147 --- /dev/null +++ b/jsonapi/n1n2/pdu_session_estab_accept_msg.go @@ -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 +} diff --git a/jsonapi/n1n2/pdu_session_estab_req_msg.go b/jsonapi/n1n2/pdu_session_estab_req_msg.go new file mode 100644 index 0000000..6485d4e --- /dev/null +++ b/jsonapi/n1n2/pdu_session_estab_req_msg.go @@ -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"` +} diff --git a/jsonapi/action.go b/jsonapi/n4tosrv6/action.go similarity index 63% rename from jsonapi/action.go rename to jsonapi/n4tosrv6/action.go index c576237..fd027f5 100644 --- a/jsonapi/action.go +++ b/jsonapi/n4tosrv6/action.go @@ -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"` diff --git a/jsonapi/backbone_ip.go b/jsonapi/n4tosrv6/backbone_ip.go similarity index 80% rename from jsonapi/backbone_ip.go rename to jsonapi/n4tosrv6/backbone_ip.go index 22e97d7..3cfe243 100644 --- a/jsonapi/backbone_ip.go +++ b/jsonapi/n4tosrv6/backbone_ip.go @@ -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" diff --git a/jsonapi/n4tosrv6/doc.go b/jsonapi/n4tosrv6/doc.go new file mode 100644 index 0000000..3791499 --- /dev/null +++ b/jsonapi/n4tosrv6/doc.go @@ -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 diff --git a/jsonapi/gtp_header.go b/jsonapi/n4tosrv6/gtp_header.go similarity index 80% rename from jsonapi/gtp_header.go rename to jsonapi/n4tosrv6/gtp_header.go index 8eb0de2..92b7d3c 100644 --- a/jsonapi/gtp_header.go +++ b/jsonapi/n4tosrv6/gtp_header.go @@ -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" diff --git a/jsonapi/locator.go b/jsonapi/n4tosrv6/locator.go similarity index 82% rename from jsonapi/locator.go rename to jsonapi/n4tosrv6/locator.go index 8cac35a..6d9eed5 100644 --- a/jsonapi/locator.go +++ b/jsonapi/n4tosrv6/locator.go @@ -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" diff --git a/jsonapi/match.go b/jsonapi/n4tosrv6/match.go similarity index 73% rename from jsonapi/match.go rename to jsonapi/n4tosrv6/match.go index 6d95558..4486ce4 100644 --- a/jsonapi/match.go +++ b/jsonapi/n4tosrv6/match.go @@ -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"` diff --git a/jsonapi/nexthop.go b/jsonapi/n4tosrv6/nexthop.go similarity index 85% rename from jsonapi/nexthop.go rename to jsonapi/n4tosrv6/nexthop.go index 3373a82..59efed2 100644 --- a/jsonapi/nexthop.go +++ b/jsonapi/n4tosrv6/nexthop.go @@ -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" diff --git a/jsonapi/payload.go b/jsonapi/n4tosrv6/payload.go similarity index 67% rename from jsonapi/payload.go rename to jsonapi/n4tosrv6/payload.go index 0c0b772..266ded9 100644 --- a/jsonapi/payload.go +++ b/jsonapi/n4tosrv6/payload.go @@ -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" diff --git a/jsonapi/n4tosrv6/router.go b/jsonapi/n4tosrv6/router.go new file mode 100644 index 0000000..0cc5425 --- /dev/null +++ b/jsonapi/n4tosrv6/router.go @@ -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 +} diff --git a/jsonapi/router_map.go b/jsonapi/n4tosrv6/router_map.go similarity index 66% rename from jsonapi/router_map.go rename to jsonapi/n4tosrv6/router_map.go index 203fe08..3370d94 100644 --- a/jsonapi/router_map.go +++ b/jsonapi/n4tosrv6/router_map.go @@ -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" diff --git a/jsonapi/rule.go b/jsonapi/n4tosrv6/rule.go similarity index 69% rename from jsonapi/rule.go rename to jsonapi/n4tosrv6/rule.go index a6c3f9d..e1ced70 100644 --- a/jsonapi/rule.go +++ b/jsonapi/n4tosrv6/rule.go @@ -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 diff --git a/jsonapi/rule_map.go b/jsonapi/n4tosrv6/rule_map.go similarity index 65% rename from jsonapi/rule_map.go rename to jsonapi/n4tosrv6/rule_map.go index d37565a..ab9394f 100644 --- a/jsonapi/rule_map.go +++ b/jsonapi/n4tosrv6/rule_map.go @@ -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" diff --git a/jsonapi/segment.go b/jsonapi/n4tosrv6/segment.go similarity index 86% rename from jsonapi/segment.go rename to jsonapi/n4tosrv6/segment.go index ac7e1e7..ec25ed6 100644 --- a/jsonapi/segment.go +++ b/jsonapi/n4tosrv6/segment.go @@ -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" diff --git a/jsonapi/srh.go b/jsonapi/n4tosrv6/srh.go similarity index 85% rename from jsonapi/srh.go rename to jsonapi/n4tosrv6/srh.go index 0b9f8db..afceae8 100644 --- a/jsonapi/srh.go +++ b/jsonapi/n4tosrv6/srh.go @@ -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" diff --git a/jsonapi/router.go b/jsonapi/router.go deleted file mode 100644 index 9c9ca97..0000000 --- a/jsonapi/router.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2024 Louis Royer and the NextMN-json-api 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 Router struct { - Locator Locator `json:"locator"` // locator (ipv6 prefix) - Backbone BackboneIP `json:"backbone"` // data plane backbone ipv6 address - Control ControlURI `json:"control"` // url used for control -} diff --git a/jsonapi_test/control_uri_test.go b/jsonapi_test/control_uri_test.go index 677df8c..6ad570f 100644 --- a/jsonapi_test/control_uri_test.go +++ b/jsonapi_test/control_uri_test.go @@ -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 ( diff --git a/jsonapi_test/message_with_error_test.go b/jsonapi_test/message_with_error_test.go new file mode 100644 index 0000000..cbf7821 --- /dev/null +++ b/jsonapi_test/message_with_error_test.go @@ -0,0 +1,49 @@ +// 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 ( + "bytes" + "encoding/json" + "fmt" + "testing" + + "github.com/nextmn/json-api/jsonapi" +) + +func TestMessageWithError(t *testing.T) { + const ( + msg_test = "Example of message" + err_test = "Example of error" + ) + j2, err := json.Marshal(map[string]string{ + "message": msg_test, + "error": err_test, + }) + if err != nil { + t.Fatalf("Could not marshal map to json") + } + + u := &jsonapi.MessageWithError{ + Message: msg_test, + Error: fmt.Errorf(err_test), + } + + j1, err := json.Marshal(u) + if err != nil { + t.Errorf("Could not marshal MessageWithError to json") + } + fmt.Println(string(j1)) + + if !bytes.Equal(j1, j2) { + t.Errorf("Result of marshaling MessageWithError to json is incorrect") + } + + unm := &jsonapi.MessageWithError{} + if err := unm.UnmarshalJSON(j1); err == nil { + t.Errorf("Unmarshal of MessageWithError failed") + } +} diff --git a/jsonapi_test/backbone_ip_test.go b/jsonapi_test/n4tosrv6_test/backbone_ip_test.go similarity index 82% rename from jsonapi_test/backbone_ip_test.go rename to jsonapi_test/n4tosrv6_test/backbone_ip_test.go index 3e42b98..7a24444 100644 --- a/jsonapi_test/backbone_ip_test.go +++ b/jsonapi_test/n4tosrv6_test/backbone_ip_test.go @@ -1,17 +1,18 @@ -// 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 + +package n4tosrv6_test import ( "testing" - "github.com/nextmn/json-api/jsonapi" + "github.com/nextmn/json-api/jsonapi/n4tosrv6" ) func TestBackboneIP(t *testing.T) { - b := &jsonapi.BackboneIP{} + b := &n4tosrv6.BackboneIP{} if err := b.UnmarshalText([]byte("192.168.0.0/24")); err == nil { t.Errorf("BackboneIP should be an IPv6 Address, not an IPv4 Prefix") } diff --git a/jsonapi_test/locator_test.go b/jsonapi_test/n4tosrv6_test/locator_test.go similarity index 82% rename from jsonapi_test/locator_test.go rename to jsonapi_test/n4tosrv6_test/locator_test.go index 8983429..952a1d9 100644 --- a/jsonapi_test/locator_test.go +++ b/jsonapi_test/n4tosrv6_test/locator_test.go @@ -1,17 +1,18 @@ -// 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 + +package n4tosrv6_test import ( "testing" - "github.com/nextmn/json-api/jsonapi" + "github.com/nextmn/json-api/jsonapi/n4tosrv6" ) func TestLocator(t *testing.T) { - l := &jsonapi.Locator{} + l := &n4tosrv6.Locator{} if err := l.UnmarshalText([]byte("192.168.0.0/24")); err == nil { t.Errorf("Locator should be an IPv6 Prefix, not an IPv4 Prefix") } diff --git a/jsonapi_test/segment_test.go b/jsonapi_test/n4tosrv6_test/segment_test.go similarity index 75% rename from jsonapi_test/segment_test.go rename to jsonapi_test/n4tosrv6_test/segment_test.go index 2689a8e..69fffc9 100644 --- a/jsonapi_test/segment_test.go +++ b/jsonapi_test/n4tosrv6_test/segment_test.go @@ -1,18 +1,19 @@ -// 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_test import ( "encoding/json" "testing" - "github.com/nextmn/json-api/jsonapi" + "github.com/nextmn/json-api/jsonapi/n4tosrv6" ) func TestSegment(t *testing.T) { - s := &jsonapi.Segment{} + s := &n4tosrv6.Segment{} if err := s.UnmarshalText([]byte("192.168.0.0/24")); err == nil { t.Errorf("Segment should be an IPv6 Address, not an IPv4 Prefix") } @@ -31,7 +32,7 @@ func TestSegment(t *testing.T) { } func TestNewSegment(t *testing.T) { - if seg0, err := jsonapi.NewSegment("::"); err == nil { + if seg0, err := n4tosrv6.NewSegment("::"); err == nil { if seg0J, err := json.Marshal(seg0); err == nil { if string(seg0J) != "\"::\"" { t.Errorf("Marshal of '::' is wrong: %s", seg0J) @@ -42,7 +43,7 @@ func TestNewSegment(t *testing.T) { } else { t.Errorf("Could not create segment '::'") } - if seg1, err := jsonapi.NewSegment("fd00::"); err == nil { + if seg1, err := n4tosrv6.NewSegment("fd00::"); err == nil { if seg1J, err := json.Marshal(seg1); err == nil { if string(seg1J) != "\"fd00::\"" { t.Errorf("Marshal of 'fd00::' is wrong: %s", seg1J) @@ -53,16 +54,16 @@ func TestNewSegment(t *testing.T) { } else { t.Errorf("Could not create segment 'fd00::'") } - if _, err := jsonapi.NewSegment("10.0.0.0"); err == nil { + if _, err := n4tosrv6.NewSegment("10.0.0.0"); err == nil { t.Errorf("NewSegment should error with string '10.0.0.0'") } - if _, err := jsonapi.NewSegment(""); err == nil { + if _, err := n4tosrv6.NewSegment(""); err == nil { t.Errorf("NewSegment should error with empty string") } - if _, err := jsonapi.NewSegment("fd00::/128"); err == nil { + if _, err := n4tosrv6.NewSegment("fd00::/128"); err == nil { t.Errorf("NewSegment should error with IPv6 Prefix") } - if _, err := jsonapi.NewSegment("10.0.0.0/32"); err == nil { + if _, err := n4tosrv6.NewSegment("10.0.0.0/32"); err == nil { t.Errorf("NewSegment should error with IPv4 Prefix") } } diff --git a/jsonapi_test/srh_test.go b/jsonapi_test/n4tosrv6_test/srh_test.go similarity index 73% rename from jsonapi_test/srh_test.go rename to jsonapi_test/n4tosrv6_test/srh_test.go index 5ba84d9..8944762 100644 --- a/jsonapi_test/srh_test.go +++ b/jsonapi_test/n4tosrv6_test/srh_test.go @@ -1,19 +1,19 @@ -// 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 ( - "testing" +package n4tosrv6_test +import ( "net/netip" + "testing" - "github.com/nextmn/json-api/jsonapi" + "github.com/nextmn/json-api/jsonapi/n4tosrv6" ) func TestNewSRH(t *testing.T) { - if srh, err := jsonapi.NewSRH([]string{"::", "fd00::"}); err == nil { + if srh, err := n4tosrv6.NewSRH([]string{"::", "fd00::"}); err == nil { if len(*srh) != 2 { t.Errorf("Length of SRH should me 2, but is %d", len(*srh)) }